From a4f7ca53df2a92e22a1ef0ab7234cee6004872ee Mon Sep 17 00:00:00 2001 From: Jakey <6077782@qq.com> Date: Thu, 19 Sep 2024 13:05:58 +0800 Subject: [PATCH] [FIX]XCode 16 stores provisioning profiles in new location --- .../Base.lproj/Localizable.strings | 2 +- .../Controller/PreviewViewController.m | 3 +- .../ProfilesManagerViewController.h | 2 + .../ProfilesManagerViewController.m | 39 +++++++++++++------ ProfilesManager/Model/ProfilesNode.h | 1 + ProfilesManager/Model/ProfilesNode.m | 15 +++++-- 6 files changed, 45 insertions(+), 17 deletions(-) diff --git a/ProfilesManager/Base.lproj/Localizable.strings b/ProfilesManager/Base.lproj/Localizable.strings index 0b0e503..59ac9d2 100644 --- a/ProfilesManager/Base.lproj/Localizable.strings +++ b/ProfilesManager/Base.lproj/Localizable.strings @@ -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"; diff --git a/ProfilesManager/Controller/PreviewViewController.m b/ProfilesManager/Controller/PreviewViewController.m index f586949..3b88c50 100644 --- a/ProfilesManager/Controller/PreviewViewController.m +++ b/ProfilesManager/Controller/PreviewViewController.m @@ -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"]; diff --git a/ProfilesManager/Controller/ProfilesManagerViewController.h b/ProfilesManager/Controller/ProfilesManagerViewController.h index 422bc95..653a700 100755 --- a/ProfilesManager/Controller/ProfilesManagerViewController.h +++ b/ProfilesManager/Controller/ProfilesManagerViewController.h @@ -15,6 +15,8 @@ @interface ProfilesManagerViewController : NSViewController { NSString *_profileDir; + NSString *_profileDir2; + NSString *_backupDir; NSMenu *_itemMenu; diff --git a/ProfilesManager/Controller/ProfilesManagerViewController.m b/ProfilesManager/Controller/ProfilesManagerViewController.m index a3b4573..625c08f 100755 --- a/ProfilesManager/Controller/ProfilesManagerViewController.m +++ b/ProfilesManager/Controller/ProfilesManagerViewController.m @@ -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]; } @@ -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) { @@ -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]; @@ -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]; @@ -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; @@ -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文件比较特殊 直接改名会被系统自动删掉 diff --git a/ProfilesManager/Model/ProfilesNode.h b/ProfilesManager/Model/ProfilesNode.h index c08d25a..00c6d69 100755 --- a/ProfilesManager/Model/ProfilesNode.h +++ b/ProfilesManager/Model/ProfilesNode.h @@ -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; diff --git a/ProfilesManager/Model/ProfilesNode.m b/ProfilesManager/Model/ProfilesNode.m index 1160db9..f1ba81c 100755 --- a/ProfilesManager/Model/ProfilesNode.m +++ b/ProfilesManager/Model/ProfilesNode.m @@ -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); @@ -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) {