Oolite 1.91.0.7745-260117-205bce7
Loading...
Searching...
No Matches
NSFileManager(OOExtensions) Category Reference

#include <NSFileManagerOOExtensions.h>

Instance Methods

(NSArray *) - commanderContentsOfPath:
(NSString *) - defaultCommanderPath
(NSArray *) - oo_directoryContentsAtPath:
(BOOL) - oo_createDirectoryAtPath:attributes:
(NSDictionary *) - oo_fileAttributesAtPath:traverseLink:
(NSDictionary *) - oo_fileSystemAttributesAtPath:
(BOOL) - oo_removeItemAtPath:
(BOOL) - oo_moveItemAtPath:toPath:
(BOOL) - oo_oxzFileExistsAtPath:

Detailed Description

Definition at line 37 of file NSFileManagerOOExtensions.h.

Method Documentation

◆ commanderContentsOfPath:

- (NSArray *) commanderContentsOfPath: (NSString*) savePath

Definition at line 39 of file NSFileManagerOOExtensions.m.

39 :(NSString *)savePath
40{
41 BOOL pathIsDirectory = NO;
42 if ([[NSFileManager defaultManager] fileExistsAtPath:savePath isDirectory:&pathIsDirectory] && pathIsDirectory)
43 {
44 NSMutableArray *contents = [NSMutableArray arrayWithArray:[self oo_directoryContentsAtPath:savePath]];
45
46 // at this point we should strip out any files not loadable as Oolite saved games
47 unsigned i;
48 for (i = 0; i < [contents count]; i++)
49 {
50 NSString* path = [savePath stringByAppendingPathComponent: (NSString*)[contents objectAtIndex:i]];
51
52 // ensure it's not a directory
53 if (![[NSFileManager defaultManager] fileExistsAtPath:path isDirectory:&pathIsDirectory] && pathIsDirectory)
54 {
55
56 // check file extension
57 if (![[path pathExtension] isEqual:@"oolite-save"])
58 {
59 [contents removeObjectAtIndex: i--];
60 continue;
61 }
62
63 // check to see if we can parse the file okay
64 NSDictionary *cdr = OODictionaryFromFile(path);
65 if (!cdr)
66 {
67 OOLog(@"savedGame.read.fail.notDictionary", @">>>> %@ could not be parsed as a saved game.", path);
68 [contents removeObjectAtIndex: i--];
69 continue;
70 }
71 }
72
73 // all okay - we can use this path!
74 [contents replaceObjectAtIndex: i withObject: path];
75
76 }
77
78 return contents;
79 }
80 else
81 {
82 OOLogERR(@"savedGame.read.fail.fileNotFound", @"File at path '%@' could not be found.", savePath);
83 return nil;
84 }
85}
#define OOLogERR(class, format,...)
Definition OOLogging.h:112
#define OOLog(class, format,...)
Definition OOLogging.h:88
NSDictionary * OODictionaryFromFile(NSString *path)
return nil

References nil, oo_directoryContentsAtPath:, OODictionaryFromFile(), OOLog, and OOLogERR.

Here is the call graph for this function:

◆ defaultCommanderPath

- (NSString *) defaultCommanderPath

Definition at line 88 of file NSFileManagerOOExtensions.m.

89{
90 const char *savedirEnv = SDL_getenv("OO_SAVEDIR");
91 NSString *savedir;
92
93 if (savedirEnv)
94 {
95 savedir = [NSString stringWithUTF8String:savedirEnv];
96 }
97 else
98 {
99 savedir = [NSHomeDirectory() stringByAppendingPathComponent:@SAVEDIR];
100 }
101 BOOL pathIsDirectory = NO;
102
103 // does it exist?
104 if (![[NSFileManager defaultManager] fileExistsAtPath:savedir isDirectory:&pathIsDirectory])
105 {
106 // it doesn't exist.
107 if([self oo_createDirectoryAtPath:savedir attributes:nil])
108 {
109 return savedir;
110 }
111 else
112 {
113 OOLogERR(@"savedGame.defaultPath.create.failed", @"Unable to create '%@'. Saved games will go to the home directory.", savedir);
114 return NSHomeDirectory();
115 }
116 }
117
118 // is it a directory?
119 if (!pathIsDirectory)
120 {
121 OOLogERR(@"savedGame.defaultPath.notDirectory", @"'%@' is not a directory, saved games will go to the home directory.", savedir);
122 return NSHomeDirectory();
123 }
124
125 return savedir;
126}

References defaultCommanderPath, nil, and OOLogERR.

Referenced by defaultCommanderPath.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ oo_createDirectoryAtPath:attributes:

- (BOOL) oo_createDirectoryAtPath: (NSString *) path
attributes: (NSDictionary *) attributes 

Definition at line 137 of file NSFileManagerOOExtensions.m.

137 :(NSString *)path attributes:(NSDictionary *)attributes
138{
139 return [self createDirectoryAtPath:path withIntermediateDirectories:YES attributes:attributes error:NULL];
140}

◆ oo_directoryContentsAtPath:

- (NSArray *) oo_directoryContentsAtPath: (NSString *) path

Definition at line 131 of file NSFileManagerOOExtensions.m.

131 :(NSString *)path
132{
133 return [self contentsOfDirectoryAtPath:path error:NULL];
134}

Referenced by commanderContentsOfPath:.

Here is the caller graph for this function:

◆ oo_fileAttributesAtPath:traverseLink:

- (NSDictionary *) oo_fileAttributesAtPath: (NSString *) path
traverseLink: (BOOL) yorn 

Definition at line 143 of file NSFileManagerOOExtensions.m.

143 :(NSString *)path traverseLink:(BOOL)traverseLink
144{
145 if (traverseLink)
146 {
147 NSString *linkDest = nil;
148 do
149 {
150 linkDest = [self destinationOfSymbolicLinkAtPath:path error:NULL];
151 if (linkDest != nil) path = linkDest;
152 } while (linkDest != nil);
153 }
154
155 return [self attributesOfItemAtPath:path error:NULL];
156}

References nil.

◆ oo_fileSystemAttributesAtPath:

- (NSDictionary *) oo_fileSystemAttributesAtPath: (NSString *) path

Definition at line 159 of file NSFileManagerOOExtensions.m.

159 :(NSString *)path
160{
161 return [self attributesOfFileSystemForPath:path error:NULL];
162}

◆ oo_moveItemAtPath:toPath:

- (BOOL) oo_moveItemAtPath: (NSString *) src
toPath: (NSString *) dest 

Definition at line 171 of file NSFileManagerOOExtensions.m.

171 :(NSString *)src toPath:(NSString *)dest
172{
173 return [self moveItemAtPath:src toPath:dest error:NULL];
174}

◆ oo_oxzFileExistsAtPath:

- (BOOL) oo_oxzFileExistsAtPath: (NSString *) path

Definition at line 257 of file NSFileManagerOOExtensions.m.

257 :(NSString *)path
258{
259 NSUInteger i, cl;
260 NSArray *components = [path pathComponents];
261 cl = [components count];
262 for (i = 0 ; i < cl ; i++)
263 {
264 NSString *component = [components objectAtIndex:i];
265 if ([[[component pathExtension] lowercaseString] isEqualToString:@"oxz"])
266 {
267 break;
268 }
269 }
270 // if i == cl then the path is entirely uncompressed
271 if (i == cl)
272 {
273 BOOL directory = NO;
274 BOOL result = [self fileExistsAtPath:path isDirectory:&directory];
275 if (directory)
276 {
277 return NO;
278 }
279 return result;
280 }
281
282 NSRange range;
283 range.location = 0; range.length = i+1;
284 NSString *zipFile = [NSString pathWithComponents:[components subarrayWithRange:range]];
285 range.location = i+1; range.length = cl-(i+1);
286 NSString *containedFile = [NSString pathWithComponents:[components subarrayWithRange:range]];
287
288 unzFile uf = NULL;
289 const char* zipname = [zipFile cStringUsingEncoding:NSUTF8StringEncoding];
290 if (zipname != NULL)
291 {
292 uf = unzOpen64(zipname);
293 }
294 if (uf == NULL)
295 {
296 // no such zip file
297 return NO;
298 }
299 const char* filename = [containedFile cStringUsingEncoding:NSUTF8StringEncoding];
300 // unzLocateFile(*, *, 1) = case-sensitive extract
301 BOOL result = YES;
302 if (unzLocateFile(uf, filename, 1) != UNZ_OK)
303 {
304 result = NO;
305 }
306 else
307 {
308 int err = UNZ_OK;
309 unz_file_info64 file_info = {0};
310 err = unzGetCurrentFileInfo64(uf, &file_info, NULL, 0, NULL, 0, NULL, 0);
311 if (err != UNZ_OK)
312 {
313 result = NO;
314 }
315 else
316 {
317
318
319 }
320 }
321 unzClose(uf);
322 return result;
323}
const char * filename
Definition ioapi.h:133
int ZEXPORT unzLocateFile(unzFile file, const char *szFileName, int iCaseSensitivity)
Definition unzip.c:1238
int ZEXPORT unzGetCurrentFileInfo64(unzFile file, unz_file_info64 *pfile_info, char *szFileName, uLong fileNameBufferSize, void *extraField, uLong extraFieldBufferSize, char *szComment, uLong commentBufferSize)
Definition unzip.c:1130
unzFile ZEXPORT unzOpen64(const void *path)
Definition unzip.c:801
int ZEXPORT unzClose(unzFile file)
Definition unzip.c:811
struct unz_file_info64_s unz_file_info64
voidp unzFile
Definition unzip.h:70
#define UNZ_OK
Definition unzip.h:74

References UNZ_OK, unzClose(), unzGetCurrentFileInfo64(), unzLocateFile(), and unzOpen64().

Here is the call graph for this function:

◆ oo_removeItemAtPath:

- (BOOL) oo_removeItemAtPath: (NSString *) path

Definition at line 165 of file NSFileManagerOOExtensions.m.

165 :(NSString *)path
166{
167 return [self removeItemAtPath:path error:NULL];
168}

The documentation for this category was generated from the following files: