Skip to content

Commit

Permalink
[FIX]XCode 16 stores provisioning profiles in new location
Browse files Browse the repository at this point in the history
  • Loading branch information
shaojiankui committed Sep 19, 2024
1 parent 3c1c8c7 commit a4f7ca5
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 17 deletions.
2 changes: 1 addition & 1 deletion ProfilesManager/Base.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"Delete this profie item permanently,can't rollback!" = "Delete this profie item permanently,can't rollback!";
"Warning" = "Warning";
"Are you sure delete selected items from disk? After delete operation can't rollback!" = "Are you sure delete selected items from disk? After delete operation can't rollback!";
"Are you sure move selected items to trash?" = "Are you sure move selected items to trash?"
"Are you sure move selected items to trash?" = "Are you sure move selected items to trash?";
"The profile installed by double click fileaname format is 'uuid+ext',it‘s very hard identify.\nare you sure rename profile filename? this will take 5 seconds!\nthe new filename is: " = "The profile installed by double click fileaname format is 'uuid+ext',it‘s very hard identify.\nare you sure rename profile filename? this will take 5 seconds!\nthe new filename is: ";
"The filename no need beautify" = "the filename no need beautify";
"Export" = "Export";
Expand Down
3 changes: 2 additions & 1 deletion ProfilesManager/Controller/PreviewViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ - (void)checkUnzip:(NSTimer *)timer {
_profileDict = (NSMutableDictionary*)[PlistManager readPlist:[_appPath stringByAppendingPathComponent:@"embedded.mobileprovision"] plistString:&plistString];

_profileDict[@"filePath"] = _appPath;

_profileDict[@"baseDir"] = _appPath;


ProfilesNode *node = [[ProfilesNode alloc]initWithRootNode:nil originInfo:_profileDict key:@"Mobile Provisions"];

Expand Down
2 changes: 2 additions & 0 deletions ProfilesManager/Controller/ProfilesManagerViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
@interface ProfilesManagerViewController : NSViewController<NSOutlineViewDataSource,NSOutlineViewDelegate,NSMenuDelegate>
{
NSString *_profileDir;
NSString *_profileDir2;

NSString *_backupDir;

NSMenu *_itemMenu;
Expand Down
39 changes: 27 additions & 12 deletions ProfilesManager/Controller/ProfilesManagerViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,13 @@ - (void)viewDidLoad {

- (void)createDir {
_profileDir = [NSString stringWithFormat:@"%@/Library/MobileDevice/Provisioning Profiles/", [[NSFileManager defaultManager] realHomeDirectory]];
_profileDir2 = [NSString stringWithFormat:@"%@/Library/Developer/Xcode/UserData/Provisioning Profiles/", [[NSFileManager defaultManager] realHomeDirectory]];
_backupDir = [NSString stringWithFormat:@"%@/Library/MobileDevice/Provisioning Profiles Rename Backup/", [[NSFileManager defaultManager] realHomeDirectory]];

if (![[NSFileManager defaultManager] fileExistsAtPath:_backupDir]) {
[[NSFileManager defaultManager] createDirectoryAtPath:_backupDir withIntermediateDirectories:YES attributes:nil error:nil];
}

if (![[NSFileManager defaultManager] fileExistsAtPath:_profileDir]) {
[[NSFileManager defaultManager] createDirectoryAtPath:_profileDir withIntermediateDirectories:YES attributes:nil error:nil];
}
Expand Down Expand Up @@ -77,20 +80,18 @@ - (void)treeViewBuilder {
}
}];
}

- (void)loadProfileFilesWithSearchWord:(NSString *)searchWord {
_searchWord = searchWord;

NSArray *profileNames = [[[NSFileManager defaultManager] subpathsAtPath:_profileDir] pathsMatchingExtensions:@[@"mobileprovision", @"MOBILEPROVISION", @"provisionprofile", @"PROVISIONPROFILE"]];

-(NSDictionary *)scanProfiles:(NSString *)path searchWord:(NSString *)searchWord{
NSArray *profileNames = [[[NSFileManager defaultManager] subpathsAtPath:path] pathsMatchingExtensions:@[@"mobileprovision", @"MOBILEPROVISION", @"provisionprofile", @"PROVISIONPROFILE"]];
NSMutableDictionary *provisions = [NSMutableDictionary dictionary];

for (NSUInteger i=0;i<[profileNames count];i++) {
NSString *fileName = [profileNames objectAtIndex:i];

NSString *plistString;
NSMutableDictionary *dic = (NSMutableDictionary *)[PlistManager readPlist:[_profileDir stringByAppendingString:fileName?:@""] plistString:&plistString];
dic[@"filePath"] = [_profileDir stringByAppendingString:fileName?:@""];

NSMutableDictionary *dic = (NSMutableDictionary *)[PlistManager readPlist:[path stringByAppendingString:fileName?:@""] plistString:&plistString];
dic[@"filePath"] = [path stringByAppendingString:fileName?:@""];
dic[@"baseDir"] = path;


if (dic && fileName) {
if ([searchWord lowercaseString] && searchWord.length > 0) {
Expand All @@ -102,6 +103,20 @@ - (void)loadProfileFilesWithSearchWord:(NSString *)searchWord {
}
}
}
return provisions;
}
- (void)loadProfileFilesWithSearchWord:(NSString *)searchWord {
_searchWord = searchWord;


NSMutableDictionary *provisions = [NSMutableDictionary dictionary];

NSDictionary *dic1 = [self scanProfiles:_profileDir searchWord:searchWord];
NSDictionary *dic2 = [self scanProfiles:_profileDir2 searchWord:searchWord];

[provisions addEntriesFromDictionary:dic1];
[provisions addEntriesFromDictionary:dic2];

ProfilesNode *node = [[ProfilesNode alloc]initWithRootNode:nil originInfo:provisions key:@"Mobile Provisions"];
_rootNode = node;
[self.treeView reloadData];
Expand Down Expand Up @@ -463,7 +478,7 @@ - (void)renameItemClick:(id)sender {
iAlert *alert = [iAlert alertWithTitle:JKLocalizedString(@"Warning", nil) message:[NSString stringWithFormat:@"%@%@", msg, node.type] style:NSAlertStyleWarning];
[alert addCommonButtonWithTitle:JKLocalizedString(@"Ok", nil) handler:^(iAlertItem *item) {
if (index == -1) return;
NSString *newPath = [self renameFileAtPath:node.filePath toName:node.type];
NSString *newPath = [self renameFileAtPath:node.filePath toName:node.type basePath:node.baseDir];
if (newPath && newPath.length > 0) {
node.filePath = newPath;
node.key = [newPath lastPathComponent];
Expand Down Expand Up @@ -583,7 +598,7 @@ - (BOOL)deleteProfile:(NSString *)filePath option:(BOOL)completely {
return result;
}

- (NSString *)renameFileAtPath:(NSString *)oldPath toName:(NSString *)toName {
- (NSString *)renameFileAtPath:(NSString *)oldPath toName:(NSString *)toName basePath:(NSString *)basePath{
BOOL result = NO;
NSError *error = nil;

Expand All @@ -593,7 +608,7 @@ - (NSString *)renameFileAtPath:(NSString *)oldPath toName:(NSString *)toName {

NSString *toPath = [[[_backupDir stringByAppendingPathComponent:toName] stringByAppendingString:time] stringByAppendingPathExtension:ext];

NSString *newPath = [[_profileDir stringByAppendingPathComponent:toName] stringByAppendingPathExtension:ext];
NSString *newPath = [[basePath stringByAppendingPathComponent:toName] stringByAppendingPathExtension:ext];

result = [[NSFileManager defaultManager] moveItemAtPath:oldPath toPath:toPath error:&error];
//Provisioning Profiles文件比较特殊 直接改名会被系统自动删掉
Expand Down
1 change: 1 addition & 0 deletions ProfilesManager/Model/ProfilesNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
@property (nonatomic, copy)NSString *type;
@property (nonatomic, copy)NSString *uuid;
@property (nonatomic, copy)NSString *filePath;
@property (nonatomic, copy)NSString *baseDir;
@property (nonatomic, strong)NSDictionary *extra;
@property (nonatomic, strong)NSDate *expirationDate;
@property (nonatomic, strong)NSDate *creationDate;
Expand Down
15 changes: 12 additions & 3 deletions ProfilesManager/Model/ProfilesNode.m
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ - (id)initWithRootNode:(ProfilesNode *)rootNode originInfo:(id)info key:(NSStrin
_detail = [NSString stringWithFormat:@"%lu items", (unsigned long)[dict count]];
_uuid = [dict objectForKey:@"UUID"];
_filePath = [dict objectForKey:@"filePath"];

_baseDir = [dict objectForKey:@"baseDir"];

if(_uuid){
NSDate *expiration = [dict objectForKey:@"ExpirationDate"];
_detail = [[NSDate date] compare:expiration] == NSOrderedDescending ?JKLocalizedString(@"Expired",nil):JKLocalizedString(@"Valid",nil);
Expand All @@ -100,11 +101,19 @@ - (id)initWithRootNode:(ProfilesNode *)rootNode originInfo:(id)info key:(NSStrin

}else{
NSArray *keys = [dict allKeys];
NSString *bundleID = [[dict objectForKey:@"Entitlements"] objectForKey:@"application-identifier"];
for (int i=0;i<[keys count];i++) {
NSString *key = [keys objectAtIndex:i];
NSString *bundleID = [[[dict objectForKey:key] objectForKey:@"Entitlements"] objectForKey:@"application-identifier"];
NSString *realKey = key;

if([key hasSuffix:@"mobileprovision"]){
bundleID = [[[dict objectForKey:key] objectForKey:@"Entitlements"] objectForKey:@"application-identifier"];
realKey = bundleID;
}else{
realKey = key;
}

ProfilesNode *child = [[ProfilesNode alloc]initWithRootNode:self originInfo:dict[key] key:bundleID];
ProfilesNode *child = [[ProfilesNode alloc]initWithRootNode:self originInfo:dict[key] key:realKey];
[children addObject:child];
}
[children sortUsingComparator:^NSComparisonResult(ProfilesNode *obj1, ProfilesNode *obj2) {
Expand Down

0 comments on commit a4f7ca5

Please sign in to comment.