From 603dcc0a7ebfd9a599fc676b95dbc4d9ff2964ee Mon Sep 17 00:00:00 2001 From: Jakey Date: Thu, 22 Nov 2018 13:25:53 +0800 Subject: [PATCH] Beautify Filename added --- .../Base.lproj/Localizable.strings | 2 + .../ProfilesManagerViewController.h | 3 +- .../ProfilesManagerViewController.m | 135 +++++++++++------- ProfilesManager/Info.plist | 2 +- .../Manager/DateManager/DateManager.h | 1 + .../Manager/DateManager/DateManager.m | 4 + ProfilesManager/en.lproj/Localizable.strings | 2 + .../zh-Hans.lproj/Localizable.strings | 2 + README.md | 11 +- 9 files changed, 103 insertions(+), 59 deletions(-) diff --git a/ProfilesManager/Base.lproj/Localizable.strings b/ProfilesManager/Base.lproj/Localizable.strings index 3b46314..11b1b76 100644 --- a/ProfilesManager/Base.lproj/Localizable.strings +++ b/ProfilesManager/Base.lproj/Localizable.strings @@ -21,6 +21,8 @@ "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?" +"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"; "Beautify Filename" = "Beautify Filename"; "Provision QuickLook Plug-in is already Installed" = "Provision QuickLook Plug-in is already Installed"; diff --git a/ProfilesManager/Controller/ProfilesManagerViewController.h b/ProfilesManager/Controller/ProfilesManagerViewController.h index 26e9dae..b3eae99 100755 --- a/ProfilesManager/Controller/ProfilesManagerViewController.h +++ b/ProfilesManager/Controller/ProfilesManagerViewController.h @@ -15,7 +15,8 @@ @interface ProfilesManagerViewController : NSViewController { NSString *_profileDir; - + NSString *_backupDir; + NSMenu *_itemMenu; NSMenu *_certificateMenu; NSMenu *_mainMenu; diff --git a/ProfilesManager/Controller/ProfilesManagerViewController.m b/ProfilesManager/Controller/ProfilesManagerViewController.m index f553bea..aaf2eea 100755 --- a/ProfilesManager/Controller/ProfilesManagerViewController.m +++ b/ProfilesManager/Controller/ProfilesManagerViewController.m @@ -13,7 +13,7 @@ #import "iAlert.h" #import "PreviewViewController.h" #import "PlistManager.h" - +#import "DateManager.h" //#include //#include //#include @@ -32,10 +32,20 @@ @implementation ProfilesManagerViewController - (void)viewDidLoad { [super viewDidLoad]; // Do view setup here. + [self createDir]; + [self treeViewBuilder]; +} +- (void)createDir{ _profileDir = [NSString stringWithFormat:@"%@/Library/MobileDevice/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]; } +} +- (void)treeViewBuilder{ //当拖拽窗口大小,NSOutlineView frame自动更改时,Column宽等比增减 [self.treeView setColumnAutoresizingStyle:NSTableViewUniformColumnAutoresizingStyle]; //最后一行自动宽等比增减 @@ -55,8 +65,8 @@ - (void)viewDidLoad { { [iAlert showMessage:[error localizedDescription] window:self.view.window completionHandler:^(NSModalResponse returnCode) { - - }]; + + }]; } } [self loadProfileFilesWithSearchWord:_searchWord]; @@ -66,9 +76,7 @@ - (void)viewDidLoad { [self presentViewControllerAsModalWindow:preview]; } }]; - } - - (void)loadProfileFilesWithSearchWord:(NSString*)searchWord { _searchWord = searchWord; @@ -287,14 +295,14 @@ - (void)menuWillOpen:(NSMenu *)menu [exportItem setTag:1003]; [menu addItem:exportItem]; } - // NSMenuItem *renameItem = [menu itemWithTag:1004]; - // if (!renameItem) - // { - // renameItem = [[NSMenuItem alloc] initWithTitle:JKLocalizedString(@"Beautify Filename",nil) action:@selector(renameItemClick:) keyEquivalent:@""]; - // [renameItem setTarget:self]; - // [renameItem setTag:1004]; - // [menu addItem:renameItem]; - // } + NSMenuItem *renameItem = [menu itemWithTag:1004]; + if (!renameItem) + { + renameItem = [[NSMenuItem alloc] initWithTitle:JKLocalizedString(@"Beautify Filename",nil) action:@selector(renameItemClick:) keyEquivalent:@""]; + [renameItem setTarget:self]; + [renameItem setTag:1004]; + [menu addItem:renameItem]; + } } if(menu == _mainMenu){ NSMenuItem *refreshItem = [menu itemWithTag:2000]; @@ -428,25 +436,38 @@ - (void)showInFinder:(id)sender NSArray *activateFileURLs =[self activateFileURLs]; [[NSWorkspace sharedWorkspace] activateFileViewerSelectingURLs:activateFileURLs]; } -////beautify filename -//- (void)renameItemClick:(id)sender{ -// NSInteger index = [self.treeView clickedRow]; -// ProfilesNode *node = [self.treeView itemAtRow:index]; -// -// iAlert *alert = [iAlert alertWithTitle:JKLocalizedString(@"Warning",nil) message:JKLocalizedString(@"are you sure rename profile filename ?",nil) style:NSAlertStyleWarning]; -// [alert addCommonButtonWithTitle:JKLocalizedString(@"Ok", nil) handler:^(iAlertItem *item) { -// -// if (index == -1) return; -// if ([self renameFileAtPath:node.filePath toName:node.type]) { -// [self.treeView beginUpdates]; -// [self.treeView reloadItem:node]; -// [self.treeView endUpdates]; -// } -// }]; -// -// [alert addButtonWithTitle:JKLocalizedString(@"Cancle", nil)]; -// [alert show:self.view.window]; -//} +//beautify filename +- (void)renameItemClick:(id)sender{ + NSInteger index = [self.treeView clickedRow]; + ProfilesNode *node = [self.treeView itemAtRow:index]; + + if([node.filePath.lastPathComponent hasPrefix:node.type]){ + [iAlert showMessage:JKLocalizedString(@"The filename no need beautify",nil) window:self.view.window completionHandler:^(NSModalResponse returnCode) { + + }]; + return; + } + + + NSString *msg = JKLocalizedString(@"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: ",nil); + + 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]; + if (newPath && newPath.length>0) { + node.filePath = newPath; + node.key = [newPath lastPathComponent]; + [self.treeView beginUpdates]; + [self.treeView reloadItem:node]; + [self.treeView endUpdates]; + } + }]; + + [alert addButtonWithTitle:JKLocalizedString(@"Cancle", nil)]; + [alert show:self.view.window]; +} //export Item to file - (void)exportItemClick:(id)sender { NSInteger index = [self.treeView clickedRow]; @@ -480,7 +501,7 @@ - (void)importItemClick:(id)sender{ NSOpenPanel *oPanel = [NSOpenPanel openPanel]; [oPanel setCanChooseDirectories:YES]; [oPanel setDirectoryURL:[NSURL URLWithString:NSHomeDirectory()]]; - [oPanel setAllowedFileTypes:@[@"mobileprovision", @"MOBILEPROVISION"]]; + [oPanel setAllowedFileTypes:@[@"mobileprovision", @"MOBILEPROVISION",@"provisionprofile"]]; if ([oPanel runModal] == NSModalResponseOK) { NSString *path =[[[oPanel URLs] objectAtIndex:0] path]; @@ -542,25 +563,33 @@ - (BOOL)deleteProfile:(NSString*)filePath option:(BOOL)completely { return result; } -//-(BOOL)renameFileAtPath:(NSString *)oldPath toName:(NSString *)toName { -// BOOL result = NO; -// NSError * error = nil; -// NSString *toPath = [[[oldPath stringByDeletingLastPathComponent] stringByAppendingPathComponent:toName] stringByAppendingPathExtension:@"mobileprovision"]; -// -// NSString *tempFolder = [[oldPath stringByDeletingLastPathComponent] stringByAppendingPathComponent:@"temp"]; -// if (![[NSFileManager defaultManager] fileExistsAtPath:tempFolder]) { -// [[NSFileManager defaultManager] createDirectoryAtPath:tempFolder withIntermediateDirectories:YES attributes:nil error:nil]; -// } -// NSString *tempPath = [tempFolder stringByAppendingPathComponent:oldPath.lastPathComponent]; -// -// result = [[NSFileManager defaultManager] copyItemAtURL:[NSURL fileURLWithPath:oldPath] toURL:[NSURL fileURLWithPath:tempPath] error:&error]; -// -// result = [[NSFileManager defaultManager] copyItemAtURL:[NSURL fileURLWithPath:tempPath] toURL:[NSURL fileURLWithPath:toPath] error:&error]; -// -// if (error){ NSLog(@"重命名失败:%@",[error localizedDescription]); -// -// } -// return result; -//} +-(NSString *)renameFileAtPath:(NSString *)oldPath toName:(NSString *)toName { + BOOL result = NO; + NSError * error = nil; + + NSString *ext = oldPath.pathExtension; + + NSString *time = [[DateManager sharedManager] stringConvert_Y_M_D_H_M_FromDate:[NSDate date]]; + + + NSString *toPath = [[[_backupDir stringByAppendingPathComponent:toName] stringByAppendingString:time] stringByAppendingPathExtension:ext]; + + + NSString *newPath = [[_profileDir stringByAppendingPathComponent:toName] stringByAppendingPathExtension:ext]; + + result = [[NSFileManager defaultManager] moveItemAtPath:oldPath toPath:toPath error:&error]; + //Provisioning Profiles文件比较特殊 直接改名会被系统自动删掉 + sleep(5); + result = [[NSFileManager defaultManager] copyItemAtURL:[NSURL fileURLWithPath:toPath] toURL:[NSURL fileURLWithPath:newPath] error:&error]; + + if (error){ + [iAlert showAlert:NSAlertStyleWarning title:@"" message:[error localizedDescription]]; + NSLog(@"重命名失败:%@",[error localizedDescription]); + } + if(result){ + return newPath; + } + return nil; +} @end diff --git a/ProfilesManager/Info.plist b/ProfilesManager/Info.plist index c3d6d09..a967f5c 100755 --- a/ProfilesManager/Info.plist +++ b/ProfilesManager/Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType APPL CFBundleShortVersionString - 2.3 + 2.4 CFBundleSignature ???? CFBundleVersion diff --git a/ProfilesManager/Manager/DateManager/DateManager.h b/ProfilesManager/Manager/DateManager/DateManager.h index 8c3f68a..3c3acbf 100644 --- a/ProfilesManager/Manager/DateManager/DateManager.h +++ b/ProfilesManager/Manager/DateManager/DateManager.h @@ -12,4 +12,5 @@ @interface DateManager : NSObject + (DateManager *)sharedManager; - (NSString *)stringConvert_YMDHM_FromDate:(NSDate *)date; +- (NSString *)stringConvert_Y_M_D_H_M_FromDate:(NSDate *)date; @end diff --git a/ProfilesManager/Manager/DateManager/DateManager.m b/ProfilesManager/Manager/DateManager/DateManager.m index f25201f..95d25cc 100644 --- a/ProfilesManager/Manager/DateManager/DateManager.m +++ b/ProfilesManager/Manager/DateManager/DateManager.m @@ -37,4 +37,8 @@ - (NSString *)stringConvert_YMDHM_FromDate:(NSDate *)date{ [_dateForrmatter setDateFormat:@"yyyy-MM-dd HH:mm"]; return [_dateForrmatter stringFromDate:date]; } +- (NSString *)stringConvert_Y_M_D_H_M_FromDate:(NSDate *)date{ + [_dateForrmatter setDateFormat:@"yyyy-MM-dd-HH-mm"]; + return [_dateForrmatter stringFromDate:date]; +} @end diff --git a/ProfilesManager/en.lproj/Localizable.strings b/ProfilesManager/en.lproj/Localizable.strings index a5a58c3..099906e 100644 --- a/ProfilesManager/en.lproj/Localizable.strings +++ b/ProfilesManager/en.lproj/Localizable.strings @@ -21,6 +21,8 @@ "Warning" = "Warning"; "Are you sure delete selected items from disk? After delete operation can't rollback!" = "Are you sure delete selceted 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?"; +"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"; "Beautify Filename" = "Beautify Filename"; "Provision QuickLook Plug-in is already Installed" = "Provision QuickLook Plug-in is already Installed"; diff --git a/ProfilesManager/zh-Hans.lproj/Localizable.strings b/ProfilesManager/zh-Hans.lproj/Localizable.strings index c4e8cd4..3c6abd9 100644 --- a/ProfilesManager/zh-Hans.lproj/Localizable.strings +++ b/ProfilesManager/zh-Hans.lproj/Localizable.strings @@ -21,6 +21,8 @@ "Warning" = "警告"; "Are you sure delete selected items from disk? After delete operation can't rollback!" = "确定将选中的所有文件从磁盘删除? 删除之后不可回滚!"; "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: " = "通过双击安装的Profie文件名格式为'uuid+ext',很难辨别。\n确定重命名配置文件么? 这将需要5秒!\n新文件名为:"; +"The filename no need beautify" = "文件名不需要美化"; "Export" = "导出"; "Beautify Filename" = "美化文件名"; "Provision QuickLook Plug-in is already Installed" = "描述文件快速查看插件已经安装"; diff --git a/README.md b/README.md index 0fc6626..3b82fa9 100755 --- a/README.md +++ b/README.md @@ -2,6 +2,9 @@ iOS Provisioning Profiles, .mobileprovision files manager tool for mac ## Features +### 2.4 +- Right-click Item Beautify Filename 右键美化物理文件名,通过双击安装的描述文件名都是UUID,美化过后与AppStore描述文件名一致。 + ### 2.3 - onekey uninstall or install quicklook plug-in,support view the .ipa/.xcarchive/.appex/.mobileprovision/.provisionprofile files directly use the the blank space key. 点击左上角的快速预览按钮,安装插件。插件可以直接预览后缀为.ipa/.xcarchive/.appex/.mobileprovision/.provisionprofile的文件,在文件上空格即可. @@ -15,11 +18,11 @@ iOS Provisioning Profiles, .mobileprovision files manager tool for mac ### 1.0 - tree look all profiles 树形查看电脑中所有描述文件 -- export cer from profile 从描述文件中导出cer证书文件 -- move to trash 移动到废纸篓 -- show in finder 在finder中显示 +- Right-click DeveloperCertificates field item export cer from profile 右键DeveloperCertificates字段里的内容从描述文件中导出cer证书文件 +- Right-click Item move to trash 右键移动到废纸篓 +- Right-click Item show in finder 右键在finder中显示 - drag muti files install 拖拽描述文件文件直接安装 -- export profile 导出描述文件 +- Right-click Item export profile 右键导出描述文件 - drag into and look ipa profile or plist directly 拖入ipa快速查看描述文件与info.plist信息