Skip to content

Commit

Permalink
Bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
WilliamLCobb committed Apr 13, 2016
1 parent 37171a0 commit ed5e1a9
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 51 deletions.
30 changes: 15 additions & 15 deletions iNDS/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
#import "LZMAExtractor.h"
#import "ZAActivityBar.h"



#include <libkern/OSAtomic.h>
#include <execinfo.h>

Expand All @@ -27,7 +25,6 @@
#import <UnrarKit/UnrarKit.h>
#endif


@interface AppDelegate () {
BOOL backgroundProcessesStarted;
}
Expand Down Expand Up @@ -122,8 +119,8 @@ - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceAppl
}
return YES;
}
} else if (url.isFileURL && [[NSFileManager defaultManager] fileExistsAtPath:url.path] && ([url.path.stringByDeletingLastPathComponent.lastPathComponent isEqualToString:@"Inbox"] || [url.path.stringByDeletingLastPathComponent.lastPathComponent isEqualToString:@"tmp"])) {
NSLog(@"Zip File");
} else if (url.isFileURL && [[NSFileManager defaultManager] fileExistsAtPath:url.path]) {
NSLog(@"Zip File (maybe)");
NSFileManager *fm = [NSFileManager defaultManager];
NSError *err = nil;
if ([url.pathExtension.lowercaseString isEqualToString:@"zip"] || [url.pathExtension.lowercaseString isEqualToString:@"7z"] || [url.pathExtension.lowercaseString isEqualToString:@"rar"]) {
Expand All @@ -135,7 +132,7 @@ - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceAppl
NSLog(@"Could not create directory to expand zip: %@ %@", dstDir, err);
[fm removeItemAtURL:url error:NULL];
[self showError:@"Unable to extract archive file."];
[fm removeItemAtPath:[self.rootDocumentsPath stringByAppendingPathComponent:@"Inbox"] error:NULL];
[fm removeItemAtPath:url.path error:NULL];
return NO;
}

Expand All @@ -148,7 +145,7 @@ - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceAppl
if (![LZMAExtractor extract7zArchive:url.path tmpDirName:@"extract"]) {
NSLog(@"Unable to extract 7z");
[self showError:@"Unable to extract .7z file."];
[fm removeItemAtPath:[self.rootDocumentsPath stringByAppendingPathComponent:@"Inbox"] error:NULL];
[fm removeItemAtPath:url.path error:NULL];
return NO;
}
} else { //Rar
Expand All @@ -166,12 +163,12 @@ - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceAppl
if (error) {
NSLog(@"Unable to extract rar: %@", archiveError);
[self showError:@"Unable to extract .rar file."];
[fm removeItemAtPath:[self.rootDocumentsPath stringByAppendingPathComponent:@"Inbox"] error:NULL];
[fm removeItemAtPath:url.path error:NULL];
return NO;
}
#else
[self showError:@"Rar support has been disabled due to code singing issues."];
[fm removeItemAtPath:[self.rootDocumentsPath stringByAppendingPathComponent:@"Inbox"] error:NULL];
[self showError:@"Rar support has been disabled due to code singing issues. It will return in a future update."];
[fm removeItemAtPath:url.path error:NULL];
return NO;
#endif
}
Expand All @@ -183,12 +180,10 @@ - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceAppl
if ([path.pathExtension.lowercaseString isEqualToString:@"nds"] && ![[path.lastPathComponent substringToIndex:1] isEqualToString:@"."]) {
NSLog(@"found ROM in zip: %@", path);
[fm moveItemAtPath:[dstDir stringByAppendingPathComponent:path] toPath:[self.documentsPath stringByAppendingPathComponent:path.lastPathComponent] error:&error];
if (error) NSLog(@"%@", error);
[foundItems addObject:path.lastPathComponent];
} else if ([path.pathExtension.lowercaseString isEqualToString:@"dsv"]) {
NSLog(@"found save in zip: %@", path);
[fm moveItemAtPath:[dstDir stringByAppendingPathComponent:path] toPath:[self.batteryDir stringByAppendingPathComponent:path.lastPathComponent] error:&error];
if (error) NSLog(@"%@", error);
[foundItems addObject:path.lastPathComponent];
} else {
BOOL isDirectory;
Expand All @@ -198,6 +193,9 @@ - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceAppl
}
}
}
if (error) {
NSLog(@"Error searching archive: %@", error);
}
}
if (foundItems.count == 0) {
[self showError:@"No roms or saves found in archive. Make sure the zip contains a .nds file or a .dsv file"];
Expand All @@ -216,13 +214,15 @@ - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceAppl
} else {
NSLog(@"Invalid File!");
NSLog(@"%@", url.pathExtension.lowercaseString);
[fm removeItemAtPath:url.path error:NULL];
[self showError:@"Unable to open file: Unknown extension"];

}
// remove inbox (shouldn't be needed)
[fm removeItemAtPath:[self.rootDocumentsPath stringByAppendingPathComponent:@"Inbox"] error:NULL];

[fm removeItemAtPath:url.path error:NULL];
return YES;
} else {
[self showError:[NSString stringWithFormat:@"Unable to open file: Unknown Error (%i, %i, %@)", url.isFileURL, [[NSFileManager defaultManager] fileExistsAtPath:url.path], url]];
[[NSFileManager defaultManager] removeItemAtPath:url.path error:NULL];

}
return NO;
Expand Down
Loading

0 comments on commit ed5e1a9

Please sign in to comment.