Skip to content

Commit

Permalink
copy opened files instead of moving
Browse files Browse the repository at this point in the history
  • Loading branch information
zydeco committed Apr 28, 2018
1 parent f597a5a commit 49fa9c0
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions Mini vMac/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceAppl
return [self application:application openURL:url options:options];
}

- (BOOL)importFileToDocuments:(NSURL *)url {
- (BOOL)importFileToDocuments:(NSURL *)url copy:(BOOL)copy {
if (url.fileURL) {
// opening file
NSFileManager *fileManager = [NSFileManager defaultManager];
Expand All @@ -322,7 +322,11 @@ - (BOOL)importFileToDocuments:(NSURL *)url {
destinationPath = [self.documentsPath stringByAppendingPathComponent:newFileName];
tries++;
}
[fileManager moveItemAtPath:url.path toPath:destinationPath error:&error];
if (copy) {
[fileManager copyItemAtPath:url.path toPath:destinationPath error:&error];
} else {
[fileManager moveItemAtPath:url.path toPath:destinationPath error:&error];
}
if (error) {
[self showAlertWithTitle:fileName message:error.localizedFailureReason];
} else {
Expand All @@ -337,16 +341,22 @@ - (BOOL)importFileToDocuments:(NSURL *)url {
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
if (url.fileURL) {
// opening file
if ([url.path.stringByStandardizingPath hasPrefix:self.documentsPath]) {
NSString *inboxPath = [self.documentsPath stringByAppendingPathComponent:@"Inbox"];
if ([url.path.stringByStandardizingPath hasPrefix:inboxPath]) {
// pre-iOS 11 import through inbox
[url startAccessingSecurityScopedResource];
[self importFileToDocuments:url copy:NO];
[url stopAccessingSecurityScopedResource];
} else if ([url.path.stringByStandardizingPath hasPrefix:self.documentsPath]) {
// already in documents - mount
[sharedEmulator insertDisk:url.path];
} else if ([options[UIApplicationOpenURLOptionsOpenInPlaceKey] boolValue]) {
// not in documents - copy
[url startAccessingSecurityScopedResource];
[self importFileToDocuments:url];
[self importFileToDocuments:url copy:YES];
[url stopAccessingSecurityScopedResource];
} else {
return [self importFileToDocuments:url];
return [self importFileToDocuments:url copy:NO];
}
}
return YES;
Expand Down

0 comments on commit 49fa9c0

Please sign in to comment.