Skip to content

Commit

Permalink
dont delete disabled plugins; give them a new ext. [Fixes #4]
Browse files Browse the repository at this point in the history
  • Loading branch information
nate-parrott committed Nov 12, 2014
1 parent 246f27d commit 6e286a1
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 31 deletions.
4 changes: 2 additions & 2 deletions FlashlightApp/EasySIMBL/Flashlight-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>0.42</string>
<string>0.43</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>8</string>
<string>9</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.utilities</string>
<key>LSMinimumSystemVersion</key>
Expand Down
58 changes: 32 additions & 26 deletions FlashlightApp/EasySIMBL/PluginInstallTask.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
13 changes: 10 additions & 3 deletions FlashlightApp/EasySIMBL/PluginListController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
}
Expand Down Expand Up @@ -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
1 change: 1 addition & 0 deletions FlashlightApp/EasySIMBL/PluginModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
1 change: 1 addition & 0 deletions FlashlightApp/EasySIMBL/PluginModel.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 6e286a1

Please sign in to comment.