forked from alcatraz/Alcatraz
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ed99765
commit 7c5c742
Showing
10 changed files
with
120 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// | ||
// ATZXcodePrefsManager.h | ||
// Alcatraz | ||
// | ||
// Created by Guillaume Algis on 14/07/2015. | ||
// Copyright (c) 2015 supermar.in. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
@class ATZPackage; | ||
|
||
@interface ATZXcodePrefsManager : NSObject | ||
|
||
+ (instancetype)sharedManager; | ||
|
||
- (void)whitelistPackage:(ATZPackage *)package completion:(void(^)(NSError *error))completion; | ||
- (BOOL)isPackageBlacklisted:(ATZPackage *)package; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// | ||
// ATZXcodePrefsManager.m | ||
// Alcatraz | ||
// | ||
// Created by Guillaume Algis on 14/07/2015. | ||
// Copyright (c) 2015 supermar.in. All rights reserved. | ||
// | ||
|
||
#import "ATZXcodePrefsManager.h" | ||
#import "ATZPackage.h" | ||
#import "ATZInstaller.h" | ||
|
||
static NSString *const NON_APPLE_PLUGINS_KEY_FORMAT = @"DVTPlugInManagerNonApplePlugIns-Xcode-%@"; | ||
static NSString *const NON_APPLE_PLUGINS_WHITELISTED_KEY = @"allowed"; | ||
static NSString *const NON_APPLE_PLUGINS_BLACKLISTED_KEY = @"skipped"; | ||
|
||
@implementation ATZXcodePrefsManager | ||
|
||
#pragma mark - Singleton | ||
|
||
+ (instancetype)sharedManager { | ||
static ATZXcodePrefsManager *instance = nil; | ||
|
||
static dispatch_once_t onceToken; | ||
dispatch_once(&onceToken, ^{ | ||
instance = [[self alloc] init]; | ||
}); | ||
return instance; | ||
} | ||
|
||
#pragma mark - Public | ||
|
||
- (void)whitelistPackage:(ATZPackage *)package completion:(void(^)(NSError *error))completion { | ||
NSString *pluginManagerKey = [self xcodeDefaultsNonApplePluginsKey]; | ||
NSMutableDictionary *nonApplePlugins = [[[NSUserDefaults standardUserDefaults] dictionaryForKey:pluginManagerKey] mutableCopy]; | ||
NSMutableDictionary *whitelistedPlugins = [nonApplePlugins[NON_APPLE_PLUGINS_WHITELISTED_KEY] mutableCopy]; | ||
NSMutableDictionary *blacklistedPlugins = [nonApplePlugins[NON_APPLE_PLUGINS_BLACKLISTED_KEY] mutableCopy]; | ||
|
||
NSBundle *pluginBundle = [NSBundle bundleWithPath:[package.installer pathForInstalledPackage:package]]; | ||
NSString *pluginIdentifier = [pluginBundle bundleIdentifier]; | ||
|
||
NSDictionary *pluginEntry = blacklistedPlugins[pluginIdentifier]; | ||
[blacklistedPlugins removeObjectForKey:pluginIdentifier]; | ||
whitelistedPlugins[pluginIdentifier] = pluginEntry; | ||
|
||
nonApplePlugins[NON_APPLE_PLUGINS_WHITELISTED_KEY] = [whitelistedPlugins copy]; | ||
nonApplePlugins[NON_APPLE_PLUGINS_BLACKLISTED_KEY] = [blacklistedPlugins copy]; | ||
|
||
[[NSUserDefaults standardUserDefaults] setObject:[nonApplePlugins copy] forKey:pluginManagerKey]; | ||
BOOL synchronizedSuccessfully = [[NSUserDefaults standardUserDefaults] synchronize]; | ||
|
||
NSError *error; | ||
if (!synchronizedSuccessfully) { | ||
error = [NSError errorWithDomain:@"Could not update Xcode's preferences and whitelist plugin" code:666 userInfo:nil]; | ||
} | ||
|
||
completion(error); | ||
} | ||
|
||
- (BOOL)isPackageBlacklisted:(ATZPackage *)package { | ||
if (![package isInstalled]) { | ||
return NO; | ||
} | ||
|
||
NSString *pluginManagerKey = [self xcodeDefaultsNonApplePluginsKey]; | ||
NSDictionary *nonApplePlugins = [[NSUserDefaults standardUserDefaults] dictionaryForKey:pluginManagerKey]; | ||
NSArray *skippedPluginsIdentifiers = [nonApplePlugins[NON_APPLE_PLUGINS_BLACKLISTED_KEY] allKeys]; | ||
|
||
NSBundle *pluginBundle = [NSBundle bundleWithPath:[package.installer pathForInstalledPackage:package]]; | ||
|
||
return [skippedPluginsIdentifiers containsObject:[pluginBundle bundleIdentifier]]; | ||
} | ||
|
||
#pragma mark - Private | ||
|
||
- (NSString *)xcodeDefaultsNonApplePluginsKey { | ||
NSString *xcodeVersion = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"]; | ||
return [NSString stringWithFormat:NON_APPLE_PLUGINS_KEY_FORMAT, xcodeVersion]; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters