Oolite 1.91.0.7646-241128-10e222e
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 1 of file NSFileManagerOOExtensions.m.

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

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

◆ oo_createDirectoryAtPath:attributes:

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

Definition at line 1 of file NSFileManagerOOExtensions.m.

126 :(NSString *)path attributes:(NSDictionary *)attributes
127{
128 return [self createDirectoryAtPath:path withIntermediateDirectories:YES attributes:attributes error:NULL];
129}

◆ oo_directoryContentsAtPath:

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

Definition at line 1 of file NSFileManagerOOExtensions.m.

120 :(NSString *)path
121{
122 return [self contentsOfDirectoryAtPath:path error:NULL];
123}

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 1 of file NSFileManagerOOExtensions.m.

132 :(NSString *)path traverseLink:(BOOL)traverseLink
133{
134 if (traverseLink)
135 {
136 NSString *linkDest = nil;
137 do
138 {
139 linkDest = [self destinationOfSymbolicLinkAtPath:path error:NULL];
140 if (linkDest != nil) path = linkDest;
141 } while (linkDest != nil);
142 }
143
144 return [self attributesOfItemAtPath:path error:NULL];
145}

◆ oo_fileSystemAttributesAtPath:

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

Definition at line 1 of file NSFileManagerOOExtensions.m.

148 :(NSString *)path
149{
150 return [self attributesOfFileSystemForPath:path error:NULL];
151}

◆ oo_moveItemAtPath:toPath:

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

Definition at line 1 of file NSFileManagerOOExtensions.m.

160 :(NSString *)src toPath:(NSString *)dest
161{
162 return [self moveItemAtPath:src toPath:dest error:NULL];
163}

◆ oo_oxzFileExistsAtPath:

- (BOOL) oo_oxzFileExistsAtPath: (NSString *) path

Definition at line 1 of file NSFileManagerOOExtensions.m.

236 :(NSString *)path
237{
238 NSUInteger i, cl;
239 NSArray *components = [path pathComponents];
240 cl = [components count];
241 for (i = 0 ; i < cl ; i++)
242 {
243 NSString *component = [components objectAtIndex:i];
244 if ([[[component pathExtension] lowercaseString] isEqualToString:@"oxz"])
245 {
246 break;
247 }
248 }
249 // if i == cl then the path is entirely uncompressed
250 if (i == cl)
251 {
252 BOOL directory = NO;
253 BOOL result = [self fileExistsAtPath:path isDirectory:&directory];
254 if (directory)
255 {
256 return NO;
257 }
258 return result;
259 }
260
261 NSRange range;
262 range.location = 0; range.length = i+1;
263 NSString *zipFile = [NSString pathWithComponents:[components subarrayWithRange:range]];
264 range.location = i+1; range.length = cl-(i+1);
265 NSString *containedFile = [NSString pathWithComponents:[components subarrayWithRange:range]];
266
267 unzFile uf = NULL;
268 const char* zipname = [zipFile cStringUsingEncoding:NSUTF8StringEncoding];
269 if (zipname != NULL)
270 {
271 uf = unzOpen64(zipname);
272 }
273 if (uf == NULL)
274 {
275 // no such zip file
276 return NO;
277 }
278 const char* filename = [containedFile cStringUsingEncoding:NSUTF8StringEncoding];
279 // unzLocateFile(*, *, 1) = case-sensitive extract
280 BOOL result = YES;
281 if (unzLocateFile(uf, filename, 1) != UNZ_OK)
282 {
283 result = NO;
284 }
285 else
286 {
287 int err = UNZ_OK;
288 unz_file_info64 file_info = {0};
289 err = unzGetCurrentFileInfo64(uf, &file_info, NULL, 0, NULL, 0, NULL, 0);
290 if (err != UNZ_OK)
291 {
292 result = NO;
293 }
294 else
295 {
296
297
298 }
299 }
300 unzClose(uf);
301 return result;
302}
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
voidp unzFile
Definition unzip.h:70
#define UNZ_OK
Definition unzip.h:74

◆ oo_removeItemAtPath:

- (BOOL) oo_removeItemAtPath: (NSString *) path

Definition at line 1 of file NSFileManagerOOExtensions.m.

154 :(NSString *)path
155{
156 return [self removeItemAtPath:path error:NULL];
157}

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