Overview
Comment: | Win32: Allow Unicode filenames in file operations. |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
94a9a181065b89bfe67684b11b1f685f |
User & Date: | js on 2013-01-08 03:13:34 |
Original User & Date: | js on 2013-01-08 03:13:35 |
Other Links: | manifest | tags |
Context
2013-01-08
| ||
03:13 | OFTCPSocket+SOCKS5: Don't send in native encoding. check-in: 6bd1d03cc1 user: js tags: trunk | |
03:13 | Win32: Allow Unicode filenames in file operations. check-in: 94a9a18106 user: js tags: trunk | |
03:13 | OFApplication: Get Unicode arguments on Win32. check-in: fb1f29bd30 user: js tags: trunk | |
Changes
Modified src/OFFile.m from [61775ac9b0] to [a86cf89293].
︙ | ︙ | |||
69 70 71 72 73 74 75 | #import "OFUnlockFailedException.h" #import "OFWriteFailedException.h" #import "autorelease.h" #import "macros.h" #ifdef _WIN32 | | > | 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | #import "OFUnlockFailedException.h" #import "OFWriteFailedException.h" #import "autorelease.h" #import "macros.h" #ifdef _WIN32 # include <windows.h> # include <wchar.h> #endif #ifndef O_BINARY # define O_BINARY 0 #endif #ifndef S_IRGRP |
︙ | ︙ | |||
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 | return [[[self alloc] initWithFileDescriptor: filedescriptor] autorelease]; } + (OFString*)currentDirectoryPath { OFString *ret; char *buffer = getcwd(NULL, 0); @try { ret = [OFString stringWithCString: buffer encoding: OF_STRING_ENCODING_NATIVE]; } @finally { free(buffer); } return ret; } + (BOOL)fileExistsAtPath: (OFString*)path { struct stat s; if (stat([path cStringUsingEncoding: OF_STRING_ENCODING_NATIVE], &s) == -1) return NO; if (S_ISREG(s.st_mode)) return YES; return NO; } + (BOOL)directoryExistsAtPath: (OFString*)path { struct stat s; if (stat([path cStringUsingEncoding: OF_STRING_ENCODING_NATIVE], &s) == -1) return NO; if (S_ISDIR(s.st_mode)) return YES; return NO; } + (void)createDirectoryAtPath: (OFString*)path { #ifndef _WIN32 if (mkdir([path cStringUsingEncoding: OF_STRING_ENCODING_NATIVE], DIR_MODE)) #else | > > > > > > > > > > > > > > > > > > > > > > | | 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 | return [[[self alloc] initWithFileDescriptor: filedescriptor] autorelease]; } + (OFString*)currentDirectoryPath { OFString *ret; #ifndef _WIN32 char *buffer = getcwd(NULL, 0); #else wchar_t *buffer = _wgetcwd(NULL, 0); #endif @try { #ifndef _WIN32 ret = [OFString stringWithCString: buffer encoding: OF_STRING_ENCODING_NATIVE]; #else ret = [OFString stringWithUTF16String: buffer]; #endif } @finally { free(buffer); } return ret; } + (BOOL)fileExistsAtPath: (OFString*)path { #ifndef _WIN32 struct stat s; if (stat([path cStringUsingEncoding: OF_STRING_ENCODING_NATIVE], &s) == -1) return NO; #else struct _stat s; if (_wstat([path UTF16String], &s) == -1) return NO; #endif if (S_ISREG(s.st_mode)) return YES; return NO; } + (BOOL)directoryExistsAtPath: (OFString*)path { #ifndef _WIN32 struct stat s; if (stat([path cStringUsingEncoding: OF_STRING_ENCODING_NATIVE], &s) == -1) return NO; #else struct _stat s; if (_wstat([path UTF16String], &s) == -1) return NO; #endif if (S_ISDIR(s.st_mode)) return YES; return NO; } + (void)createDirectoryAtPath: (OFString*)path { #ifndef _WIN32 if (mkdir([path cStringUsingEncoding: OF_STRING_ENCODING_NATIVE], DIR_MODE)) #else if (_wmkdir([path UTF16String])) #endif @throw [OFCreateDirectoryFailedException exceptionWithClass: self path: path]; } + (void)createDirectoryAtPath: (OFString*)path |
︙ | ︙ | |||
314 315 316 317 318 319 320 | } } @finally { closedir(dir); } #else void *pool = objc_autoreleasePoolPush(); HANDLE handle; | | | | | | | < < | > > > > | < | < > > > > > > > > > > > > | 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 | } } @finally { closedir(dir); } #else void *pool = objc_autoreleasePoolPush(); HANDLE handle; WIN32_FIND_DATAW fd; path = [path stringByAppendingString: @"\\*"]; if ((handle = FindFirstFileW([path UTF16String], &fd)) == INVALID_HANDLE_VALUE) @throw [OFOpenFileFailedException exceptionWithClass: self path: path mode: @"r"]; @try { do { void *pool2 = objc_autoreleasePoolPush(); OFString *file; if (!wcscmp(fd.cFileName, L".") || !wcscmp(fd.cFileName, L"..")) continue; file = [OFString stringWithUTF16String: fd.cFileName]; [files addObject: file]; objc_autoreleasePoolPop(pool2); } while (FindNextFileW(handle, &fd)); } @finally { FindClose(handle); } objc_autoreleasePoolPop(pool); #endif [files makeImmutable]; return files; } + (void)changeToDirectoryAtPath: (OFString*)path { #ifndef _WIN32 if (chdir([path cStringUsingEncoding: OF_STRING_ENCODING_NATIVE])) #else if (_wchdir([path UTF16String])) #endif @throw [OFChangeDirectoryFailedException exceptionWithClass: self path: path]; } #ifndef _PSP + (void)changeModeOfFileAtPath: (OFString*)path mode: (mode_t)mode { # ifndef _WIN32 if (chmod([path cStringUsingEncoding: OF_STRING_ENCODING_NATIVE], mode)) @throw [OFChangeFileModeFailedException exceptionWithClass: self path: path mode: mode]; # else DWORD attributes = GetFileAttributesW([path UTF16String]); if (attributes == INVALID_FILE_ATTRIBUTES) @throw [OFChangeFileModeFailedException exceptionWithClass: self path: path mode: mode]; if ((mode / 100) & 2) attributes &= ~FILE_ATTRIBUTE_READONLY; else attributes |= FILE_ATTRIBUTE_READONLY; if (!SetFileAttributesW([path UTF16String], attributes)) @throw [OFChangeFileModeFailedException exceptionWithClass: self path: path mode: mode]; # endif } #endif + (off_t)sizeOfFileAtPath: (OFString*)path { #ifndef _WIN32 struct stat s; if (stat([path cStringUsingEncoding: OF_STRING_ENCODING_NATIVE], &s) == -1) #else struct _stat s; if (_wstat([path UTF16String], &s) == -1) #endif /* FIXME: Maybe use another exception? */ @throw [OFOpenFileFailedException exceptionWithClass: self path: path mode: @"r"]; return s.st_size; } + (OFDate*)modificationDateOfFileAtPath: (OFString*)path { #ifndef _WIN32 struct stat s; if (stat([path cStringUsingEncoding: OF_STRING_ENCODING_NATIVE], &s) == -1) #else struct _stat s; if (_wstat([path UTF16String], &s) == -1) #endif /* FIXME: Maybe use another exception? */ @throw [OFOpenFileFailedException exceptionWithClass: self path: path mode: @"r"]; /* FIXME: We could be more precise on some OSes */ return [OFDate dateWithTimeIntervalSince1970: s.st_mtime]; |
︙ | ︙ | |||
559 560 561 562 563 564 565 | nil]; } #ifndef _WIN32 if (rename([source cStringUsingEncoding: OF_STRING_ENCODING_NATIVE], [destination cStringUsingEncoding: OF_STRING_ENCODING_NATIVE])) #else | < | | > > > > | 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 | nil]; } #ifndef _WIN32 if (rename([source cStringUsingEncoding: OF_STRING_ENCODING_NATIVE], [destination cStringUsingEncoding: OF_STRING_ENCODING_NATIVE])) #else if (!MoveFileW([source UTF16String], [destination UTF16String])) #endif @throw [OFRenameFileFailedException exceptionWithClass: self sourcePath: source destinationPath: destination]; objc_autoreleasePoolPop(pool); } + (void)deleteFileAtPath: (OFString*)path { #ifndef _WIN32 if (unlink([path cStringUsingEncoding: OF_STRING_ENCODING_NATIVE])) #else if (_wunlink([path UTF16String])) #endif @throw [OFDeleteFileFailedException exceptionWithClass: self path: path]; } + (void)deleteDirectoryAtPath: (OFString*)path { #ifndef _WIN32 if (rmdir([path cStringUsingEncoding: OF_STRING_ENCODING_NATIVE])) #else if (_wrmdir([path UTF16String])) #endif @throw [OFDeleteDirectoryFailedException exceptionWithClass: self path: path]; } #ifndef _WIN32 + (void)linkFileAtPath: (OFString*)source |
︙ | ︙ | |||
653 654 655 656 657 658 659 | mode: (OFString*)mode { self = [super init]; @try { int flags; | | < > > > > > | 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 | mode: (OFString*)mode { self = [super init]; @try { int flags; if ((flags = parse_mode([mode UTF8String])) == -1) @throw [OFInvalidArgumentException exceptionWithClass: [self class] selector: _cmd]; #ifndef _WIN32 if ((fd = open([path cStringUsingEncoding: OF_STRING_ENCODING_NATIVE], flags, DEFAULT_MODE)) == -1) #else if ((fd = _wopen([path UTF16String], flags, DEFAULT_MODE)) == -1) #endif @throw [OFOpenFileFailedException exceptionWithClass: [self class] path: path mode: mode]; closable = YES; } @catch (id e) { |
︙ | ︙ |
Modified src/OFPlugin.m from [260b8dfd9b] to [27e1ed9410].
︙ | ︙ | |||
27 28 29 30 31 32 33 | #import "OFString.h" #import "OFInitializationFailedException.h" #import "autorelease.h" #ifdef _WIN32 | < < < | > | > > > | 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | #import "OFString.h" #import "OFInitializationFailedException.h" #import "autorelease.h" #ifdef _WIN32 # define dlsym(handle, symbol) GetProcAddress(handle, symbol) # define dlclose(handle) FreeLibrary(handle) #endif @implementation OFPlugin + (id)pluginFromFile: (OFString*)path { void *pool = objc_autoreleasePoolPush(); of_plugin_handle_t handle; OFPlugin *(*initPlugin)(void); OFPlugin *plugin; path = [path stringByAppendingString: @PLUGIN_SUFFIX]; #ifndef _WIN32 if ((handle = dlopen([path cStringUsingEncoding: OF_STRING_ENCODING_NATIVE], RTLD_LAZY)) == NULL) #else if ((handle = LoadLibraryW([path UTF16String])) == NULL) #endif @throw [OFInitializationFailedException exceptionWithClass: self]; objc_autoreleasePoolPop(pool); initPlugin = (OFPlugin*(*)(void))dlsym(handle, "init_plugin"); if (initPlugin == NULL || (plugin = initPlugin()) == nil) { |
︙ | ︙ |