From 49fa9c0182fd2e94f60a8cd45e5c421946df80f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jesu=CC=81s=20A=2E=20A=CC=81lvarez?= Date: Sat, 28 Apr 2018 13:05:20 +0200 Subject: [PATCH] copy opened files instead of moving --- Mini vMac/AppDelegate.m | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/Mini vMac/AppDelegate.m b/Mini vMac/AppDelegate.m index d54b1ca..9356fcc 100644 --- a/Mini vMac/AppDelegate.m +++ b/Mini vMac/AppDelegate.m @@ -304,7 +304,7 @@ NSString *DocumentsChangedNotification = @"documentsChanged"; 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]; @@ -322,7 +322,11 @@ NSString *DocumentsChangedNotification = @"documentsChanged"; 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 { @@ -337,16 +341,22 @@ NSString *DocumentsChangedNotification = @"documentsChanged"; - (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary *)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;