OLD | NEW |
---|---|
1 /* | 1 /* |
2 Copyright (c) 2001-2010 Troy N. Stephens | 2 Copyright (c) 2001-2010 Troy N. Stephens |
3 | 3 |
4 Use and distribution of this source code is governed by the MIT License, who se terms are as follows. | 4 Use and distribution of this source code is governed by the MIT License, who se terms are as follows. |
5 | 5 |
6 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal i n the Software without restriction, including without limitation the rights to u se, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | 6 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal i n the Software without restriction, including without limitation the rights to u se, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: |
7 | 7 |
8 The above copyright notice and this permission notice shall be included in a ll copies or substantial portions of the Software. | 8 The above copyright notice and this permission notice shall be included in a ll copies or substantial portions of the Software. |
9 | 9 |
10 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR I MPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR C OPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | 10 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR I MPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR C OPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
11 */ | 11 */ |
12 | 12 |
13 #import "NSString+CarbonFSRefCreation.h" | 13 #import "NSString+CarbonFSRefCreation.h" |
14 | 14 |
15 @implementation NSString (CarbonFSRefCreation) | 15 @implementation NSString (CarbonFSRefCreation) |
16 | 16 |
17 - (BOOL) getFSRef:(FSRef*)fsRef createFileIfNecessary:(BOOL)createFile | 17 - (BOOL) getFSRef:(FSRef*)fsRef createFileIfNecessary:(BOOL)createFile |
18 { | 18 { |
19 NSFileManager* fileManager = [NSFileManager defaultManager]; | 19 NSFileManager* fileManager = [NSFileManager defaultManager]; |
20 CFURLRef urlRef; | 20 CFURLRef urlRef; |
21 Boolean gotFSRef; | 21 Boolean gotFSRef; |
22 | 22 |
23 // Check whether the file exists already. If not, create an empty file if r equested. | 23 // Check whether the file exists already. If not, create an empty file if r equested. |
24 if (![fileManager fileExistsAtPath:self]) { | 24 if (![fileManager fileExistsAtPath:self]) { |
25 if (createFile) { | 25 if (createFile) { |
26 if (![[NSData data] writeToFile:self atomically:YES]) { | 26 if (![(NSData*)[NSData data] writeToFile:self atomically:YES]) { |
Nico
2012/02/11 02:53:16
What's this needed for?
…nevermind. Ugh!
| |
27 return NO; | 27 return NO; |
28 } | 28 } |
29 } else { | 29 } else { |
30 return NO; | 30 return NO; |
31 } | 31 } |
32 } | 32 } |
33 | 33 |
34 // Create a CFURL with the specified POSIX path. | 34 // Create a CFURL with the specified POSIX path. |
35 urlRef = CFURLCreateWithFileSystemPath( kCFAllocatorDefault, | 35 urlRef = CFURLCreateWithFileSystemPath( kCFAllocatorDefault, |
36 (CFStringRef) self, | 36 (CFStringRef) self, |
(...skipping 12 matching lines...) Expand all Loading... | |
49 | 49 |
50 if (!gotFSRef) { | 50 if (!gotFSRef) { |
51 // printf( "** Couldn't get an FSRef for the file.\n" ); | 51 // printf( "** Couldn't get an FSRef for the file.\n" ); |
52 return NO; | 52 return NO; |
53 } | 53 } |
54 | 54 |
55 return YES; | 55 return YES; |
56 } | 56 } |
57 | 57 |
58 @end | 58 @end |
OLD | NEW |