diff options
author | Paul Gardiner <paul.gardiner@artifex.com> | 2014-04-21 18:31:36 +0100 |
---|---|---|
committer | Paul Gardiner <paul.gardiner@artifex.com> | 2014-04-24 10:05:42 +0100 |
commit | bbcfbe19d1a39db05b0aed88e191580c10b14857 (patch) | |
tree | bd2406670f9b826132099cccadda7620e17b5bc3 /platform/ios | |
parent | 4c0d6fe09c9f96419e5e622f8e22e5ab1eb6735a (diff) | |
download | mupdf-bbcfbe19d1a39db05b0aed88e191580c10b14857.tar.xz |
iOS: copy files from Inbox to Documents so that they can be altered
Diffstat (limited to 'platform/ios')
-rw-r--r-- | platform/ios/Classes/MuLibraryController.m | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/platform/ios/Classes/MuLibraryController.m b/platform/ios/Classes/MuLibraryController.m index 62ed05f6..c9e8840e 100644 --- a/platform/ios/Classes/MuLibraryController.m +++ b/platform/ios/Classes/MuLibraryController.m @@ -144,8 +144,44 @@ static void showAlert(NSString *msg, NSString *filename) [self openDocument: [files objectAtIndex: row]]; } +static NSString *alteredfilename(NSString *name, int i) +{ + if (i == 0) + return name; + + NSString *nam = [name stringByDeletingPathExtension]; + NSString *e = [name pathExtension]; + return [[[NSString alloc] initWithFormat:@"%@(%d)%@", nam, i, e] autorelease]; +} + +static NSString *moveOutOfInbox(NSString *docpath) +{ + if ([docpath hasPrefix:@"Inbox/"]) + { + NSFileManager *fileMan = [NSFileManager defaultManager]; + NSString *base = [docpath stringByReplacingOccurrencesOfString:@"Inbox/" withString:@""]; + + for (int i = 0; YES; i++) + { + NSString *newname = alteredfilename(base, i); + NSString *newfullpath = [NSString pathWithComponents:[NSArray arrayWithObjects:NSHomeDirectory(), @"Documents", newname, nil]]; + + if (![fileMan fileExistsAtPath:newfullpath]) + { + NSString *fullpath = [NSString pathWithComponents:[NSArray arrayWithObjects:NSHomeDirectory(), @"Documents", docpath, nil]]; + [fileMan copyItemAtPath:fullpath toPath:newfullpath error:nil]; + [fileMan removeItemAtPath:fullpath error:nil]; + return newname; + } + } + } + + return docpath; +} + - (void) openDocument: (NSString*)nsfilename { + nsfilename = moveOutOfInbox(nsfilename); NSString *nspath = [[NSArray arrayWithObjects:NSHomeDirectory(), @"Documents", nsfilename, nil] componentsJoinedByString:@"/"]; _filePath = malloc(strlen([nspath UTF8String])+1); |