From f8726fccb0f667b2498731e8b3e45782c9fe52c8 Mon Sep 17 00:00:00 2001 From: lennardkittner Date: Sun, 4 Oct 2020 17:53:39 +0200 Subject: [PATCH 1/2] - App doesn't crash anymore when a file is shared to it. - A shared file is copied to /Documents/roms. --- ui/drivers/ui_cocoatouch.m | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/ui/drivers/ui_cocoatouch.m b/ui/drivers/ui_cocoatouch.m index e22d71c576..6b5040f15c 100644 --- a/ui/drivers/ui_cocoatouch.m +++ b/ui/drivers/ui_cocoatouch.m @@ -448,6 +448,28 @@ enum [self showGameView]; } +-(BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary *)options { + NSFileManager *manager = [NSFileManager defaultManager]; + NSError *error; + NSString *romPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/RetroArch/roms"]; + + if (![manager fileExistsAtPath:romPath]) + if (![manager createDirectoryAtPath:romPath withIntermediateDirectories:NO attributes:nil error:&error]) + NSLog(@"Error: Create folder failed %@", error); + + NSString *destination = [[romPath stringByAppendingString:@"/"] stringByAppendingString:(NSString*)url.path.lastPathComponent]; + + // copy file to roms directory if its not already in documents directory + if ([url startAccessingSecurityScopedResource]) { + if (![[url path] containsString:NSHomeDirectory()]) + if (![manager fileExistsAtPath:destination]) + if (![manager copyItemAtPath:[url path] toPath:destination error:&error]) + NSLog(@"Error: Copy of file failed %@", error); + [url stopAccessingSecurityScopedResource]; + } + return true; +} + -(BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation { NSString *filename = (NSString*)url.path.lastPathComponent; From 43245c0d9ffd60dd6513dd1a736807ec7e3063e1 Mon Sep 17 00:00:00 2001 From: lennardkittner Date: Mon, 5 Oct 2020 09:18:28 +0200 Subject: [PATCH 2/2] - Deleted deprecated openURL method - Now using self.documentsDirectory - ROMs are saved to documents directory --- ui/drivers/ui_cocoatouch.m | 30 ++++++------------------------ 1 file changed, 6 insertions(+), 24 deletions(-) diff --git a/ui/drivers/ui_cocoatouch.m b/ui/drivers/ui_cocoatouch.m index 6b5040f15c..e016820047 100644 --- a/ui/drivers/ui_cocoatouch.m +++ b/ui/drivers/ui_cocoatouch.m @@ -450,39 +450,21 @@ enum -(BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary *)options { NSFileManager *manager = [NSFileManager defaultManager]; - NSError *error; - NSString *romPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/RetroArch/roms"]; - - if (![manager fileExistsAtPath:romPath]) - if (![manager createDirectoryAtPath:romPath withIntermediateDirectories:NO attributes:nil error:&error]) - NSLog(@"Error: Create folder failed %@", error); - - NSString *destination = [[romPath stringByAppendingString:@"/"] stringByAppendingString:(NSString*)url.path.lastPathComponent]; + NSString *filename = (NSString*)url.path.lastPathComponent; + NSError *error = nil; + NSString *destination = [self.documentsDirectory stringByAppendingPathComponent:filename]; - // copy file to roms directory if its not already in documents directory + // copy file to documents directory if its not already inside of documents directory if ([url startAccessingSecurityScopedResource]) { - if (![[url path] containsString:NSHomeDirectory()]) + if (![[url path] containsString: self.documentsDirectory]) if (![manager fileExistsAtPath:destination]) if (![manager copyItemAtPath:[url path] toPath:destination error:&error]) - NSLog(@"Error: Copy of file failed %@", error); + printf("%s\n", [[error description] UTF8String]); [url stopAccessingSecurityScopedResource]; } return true; } --(BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation -{ - NSString *filename = (NSString*)url.path.lastPathComponent; - NSError *error = nil; - - [[NSFileManager defaultManager] moveItemAtPath:[url path] toPath:[self.documentsDirectory stringByAppendingPathComponent:filename] error:&error]; - - if (error) - printf("%s\n", [[error description] UTF8String]); - - return true; -} - - (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated { #if TARGET_OS_IOS