diff --git a/FlashlightApp/EasySIMBL/Flashlight-Info.plist b/FlashlightApp/EasySIMBL/Flashlight-Info.plist index b0864c22..64c0f2bd 100755 --- a/FlashlightApp/EasySIMBL/Flashlight-Info.plist +++ b/FlashlightApp/EasySIMBL/Flashlight-Info.plist @@ -32,11 +32,11 @@ CFBundlePackageType APPL CFBundleShortVersionString - 0.42 + 0.43 CFBundleSignature ???? CFBundleVersion - 8 + 9 LSApplicationCategoryType public.app-category.utilities LSMinimumSystemVersion diff --git a/FlashlightApp/EasySIMBL/PluginInstallTask.m b/FlashlightApp/EasySIMBL/PluginInstallTask.m index 2d5001d3..104ede06 100644 --- a/FlashlightApp/EasySIMBL/PluginInstallTask.m +++ b/FlashlightApp/EasySIMBL/PluginInstallTask.m @@ -19,35 +19,41 @@ - (id)initWithPlugin:(PluginModel *)plugin { return self; } - (void)startInstallationIntoPluginsDirectory:(NSString *)directory withCallback:(void(^)(BOOL success, NSError *error))callback { - [[[NSURLSession sharedSession] dataTaskWithURL:self.plugin.zipURL completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) { - if (data && !error) { - dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{ - NSError *zipError = nil; - ZZArchive *archive = [ZZArchive archiveWithData:data error:&zipError]; - if (archive && !zipError) { - for (ZZArchiveEntry *entry in archive.entries) { - zipError = nil; - NSData *entryData = [entry newDataWithError:&zipError]; - if (entryData && !zipError) { - NSString *writeToPath = [directory stringByAppendingPathComponent:entry.fileName]; - if (![[NSFileManager defaultManager] fileExistsAtPath:[writeToPath stringByDeletingLastPathComponent]]) { - [[NSFileManager defaultManager] createDirectoryAtPath:[writeToPath stringByDeletingLastPathComponent] withIntermediateDirectories:YES attributes:nil error:NO]; + if (self.plugin.zipURL) { + [[[NSURLSession sharedSession] dataTaskWithURL:self.plugin.zipURL completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) { + if (data && !error) { + dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{ + NSError *zipError = nil; + ZZArchive *archive = [ZZArchive archiveWithData:data error:&zipError]; + if (archive && !zipError) { + for (ZZArchiveEntry *entry in archive.entries) { + zipError = nil; + NSData *entryData = [entry newDataWithError:&zipError]; + if (entryData && !zipError) { + NSString *writeToPath = [directory stringByAppendingPathComponent:entry.fileName]; + if (![[NSFileManager defaultManager] fileExistsAtPath:[writeToPath stringByDeletingLastPathComponent]]) { + [[NSFileManager defaultManager] createDirectoryAtPath:[writeToPath stringByDeletingLastPathComponent] withIntermediateDirectories:YES attributes:nil error:NO]; + } + [entryData writeToFile:writeToPath atomically:YES]; + } else { + callback(NO, zipError); + return; } - [entryData writeToFile:writeToPath atomically:YES]; - } else { - callback(NO, zipError); - return; } + callback(YES, nil); + } else { + callback(NO, zipError); } - callback(YES, nil); - } else { - callback(NO, zipError); - } - }); - } else { - callback(NO, error); - } - }] resume]; + }); + } else { + callback(NO, error); + } + }] resume]; + } else if (self.plugin.disabledPluginPath) { + NSString *enabledPath = [[self.plugin.disabledPluginPath stringByDeletingPathExtension] stringByAppendingPathExtension:@"bundle"]; + [[NSFileManager defaultManager] moveItemAtPath:self.plugin.disabledPluginPath toPath:enabledPath error:nil]; + callback(YES, nil); + } } @end diff --git a/FlashlightApp/EasySIMBL/PluginListController.m b/FlashlightApp/EasySIMBL/PluginListController.m index 2ec864c0..638b8648 100644 --- a/FlashlightApp/EasySIMBL/PluginListController.m +++ b/FlashlightApp/EasySIMBL/PluginListController.m @@ -206,12 +206,17 @@ - (void)reloadFromDisk { NSArray *contents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:[self localPluginsPath] error:nil]; NSMutableArray *models = [NSMutableArray new]; for (NSString *itemName in contents) { - if ([[itemName pathExtension] isEqualToString:@"bundle"]) { + NSString *ext = [itemName pathExtension]; + if ([@[@"bundle", @"disabled-bundle"] containsObject:ext]) { NSData *data = [NSData dataWithContentsOfFile:[[[self localPluginsPath] stringByAppendingPathComponent:itemName] stringByAppendingPathComponent:@"info.json"]]; if (data) { NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil]; PluginModel *model = [PluginModel fromJson:json baseURL:nil]; - model.installed = YES; + if ([ext isEqualToString:@"bundle"]) { + model.installed = YES; + } else { + model.disabledPluginPath = [[self localPluginsPath] stringByAppendingPathComponent:itemName]; + } [models addObject:model]; } } @@ -253,7 +258,9 @@ - (void)installPlugin:(PluginModel *)plugin { - (void)uninstallPlugin:(PluginModel *)plugin { if ([self isPluginCurrentlyBeingInstalled:plugin]) return; - [[NSFileManager defaultManager] removeItemAtPath:[[self localPluginsPath] stringByAppendingPathComponent:[plugin.name stringByAppendingPathExtension:@"bundle"]] error:nil]; + NSString *path = [[self localPluginsPath] stringByAppendingPathComponent:[plugin.name stringByAppendingPathExtension:@"bundle"]]; + NSString *disabledPath = [[self localPluginsPath] stringByAppendingPathComponent:[plugin.name stringByAppendingPathExtension:@"disabled-bundle"]]; + [[NSFileManager defaultManager] moveItemAtPath:path toPath:disabledPath error:nil]; } @end diff --git a/FlashlightApp/EasySIMBL/PluginModel.h b/FlashlightApp/EasySIMBL/PluginModel.h index ebfe0e90..8cd97aaa 100644 --- a/FlashlightApp/EasySIMBL/PluginModel.h +++ b/FlashlightApp/EasySIMBL/PluginModel.h @@ -15,6 +15,7 @@ @property (nonatomic) BOOL installed; @property (nonatomic) BOOL installing; @property (nonatomic) NSURL *zipURL; +@property (nonatomic) NSString *disabledPluginPath; + (PluginModel *)fromJson:(NSDictionary *)json baseURL:(NSURL *)url; diff --git a/FlashlightApp/EasySIMBL/PluginModel.m b/FlashlightApp/EasySIMBL/PluginModel.m index 5bd65ee9..243d1d6c 100644 --- a/FlashlightApp/EasySIMBL/PluginModel.m +++ b/FlashlightApp/EasySIMBL/PluginModel.m @@ -18,6 +18,7 @@ - (id)copyWithZone:(NSZone *)zone { p.installed = self.installed; p.installing = self.installing; p.examples = self.examples; + p.disabledPluginPath = self.disabledPluginPath; return p; }