From 5af64db1663377dbc40c655eada1216327d6135d Mon Sep 17 00:00:00 2001 From: Allan Odgaard Date: Mon, 10 Oct 2016 22:31:48 +0200 Subject: [PATCH] =?UTF-8?q?Ask=20user=20to=20move=20Avian=20bundles=20into?= =?UTF-8?q?=20TextMate=E2=80=99s=20application=20support?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BundlesManager/src/BundlesManager.mm | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/Frameworks/BundlesManager/src/BundlesManager.mm b/Frameworks/BundlesManager/src/BundlesManager.mm index bec6c707..bd4434bc 100644 --- a/Frameworks/BundlesManager/src/BundlesManager.mm +++ b/Frameworks/BundlesManager/src/BundlesManager.mm @@ -434,8 +434,63 @@ namespace } } +- (void)moveAvianBundles +{ + NSFileManager* fm = [NSFileManager defaultManager]; + + NSMutableArray* moves = [NSMutableArray array]; + NSMutableString* moveDescription = [NSMutableString string]; + + for(NSString* path in NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask|NSLocalDomainMask, YES)) + { + for(NSString* dir in @[ @"", @"Pristine Copy" ]) + { + NSString* textMateFolder = [NSString pathWithComponents:@[ path, @"TextMate", dir ]]; + NSString* avianFolder = [NSString pathWithComponents:@[ path, @"Avian", dir ]]; + NSString* src = [avianFolder stringByAppendingPathComponent:@"Bundles"]; + NSString* dst = [textMateFolder stringByAppendingPathComponent:@"Bundles"]; + + if([fm fileExistsAtPath:src] == NO) + continue; + + if([fm fileExistsAtPath:dst] == YES) + { + [moves addObject:@[ dst, [dst stringByAppendingString:@"-1.x"] ]]; + [moveDescription appendFormat:@"Rename “Bundles” at “%@” to “Bundles-1.x” (backup).\n", [textMateFolder stringByAbbreviatingWithTildeInPath]]; + } + + [moves addObject:@[ src, dst ]]; + [moveDescription appendFormat:@"Move “Bundles” at “%@” to “%@”.\n", [avianFolder stringByAbbreviatingWithTildeInPath], [textMateFolder stringByAbbreviatingWithTildeInPath]]; + } + } + + if(moves.count == 0) + return; + + NSAlert* alert = [[NSAlert alloc] init]; + alert.alertStyle = NSInformationalAlertStyle; + alert.messageText = @"Move Bundles?"; + alert.informativeText = [NSString stringWithFormat:@"Bundles are no longer read from the “Avian” folder. Would you like to move the following items:\n\n%@", moveDescription]; + [alert addButtonWithTitle:@"Move Bundles"]; + [alert addButtonWithTitle:@"Cancel"]; + if([alert runModal] != NSAlertFirstButtonReturn) + return; + + for(NSArray* move in moves) + { + NSError* err; + if([fm moveItemAtPath:move.firstObject toPath:move.lastObject error:&err] == YES) + continue; + [[NSAlert alertWithError:err] runModal]; + break; + } +} + - (void)loadBundlesIndex { + // LEGACY locations used by 2.0-beta.12.22 and earlier + [self moveAvianBundles]; + for(auto path : bundles::locations()) bundlesPaths.push_back(path::join(path, "Bundles")); bundlesIndexPath = path::join(path::home(), "Library/Caches/com.macromates.TextMate/BundlesIndex.binary");