Camino only - Bug 366358: When importing bookmarks from Firefox, use the most recently used Firefox profile. Patch by Sean Murphy <murph@seanmurph.com> r=me sr=smorgan
This commit is contained in:
Родитель
568e699c99
Коммит
fcb2cdb606
|
@ -42,6 +42,7 @@
|
|||
#import "MainController.h"
|
||||
#import "BrowserWindowController.h"
|
||||
#import "BookmarkViewController.h"
|
||||
#import "NSFileManager+Utils.h"
|
||||
|
||||
@interface BookmarkImportDlgController (Private)
|
||||
|
||||
|
@ -68,7 +69,8 @@
|
|||
[self buildAvailableFileList];
|
||||
}
|
||||
|
||||
// Check for common webbrower bookmark files and, if they exist, add import buttons.
|
||||
// Looks through known bookmark locations of other browsers and populates the import
|
||||
// choices with those found. Must be called when showing the dialog.
|
||||
- (void)buildAvailableFileList
|
||||
{
|
||||
NSString *mozPath;
|
||||
|
@ -137,21 +139,15 @@
|
|||
[self buildButtonForBrowser:@"OmniWeb 5" withPathArray:haveFiles];
|
||||
}
|
||||
|
||||
// Given a Mozilla-like profile, returns the bookmarks.html file in the salt directory,
|
||||
// or nil if no salt directory is found
|
||||
// Given a Mozilla-like profile, returns the bookmarks.html file in the salt directory
|
||||
// for the last modified profile, or nil on error
|
||||
- (NSString *)getSaltedBookmarkPathForProfile:(NSString *)aPath
|
||||
{
|
||||
NSFileManager *fm = [NSFileManager defaultManager];
|
||||
id aTempItem;
|
||||
NSString *fullPathString = [aPath stringByStandardizingPath];
|
||||
if ([fm fileExistsAtPath:fullPathString]) {
|
||||
NSArray *saltArray = [fm directoryContentsAtPath:fullPathString];
|
||||
NSEnumerator *enumerator = [saltArray objectEnumerator];
|
||||
while ((aTempItem = [enumerator nextObject])) {
|
||||
if (![aTempItem hasPrefix:@"."])
|
||||
return [fullPathString stringByAppendingFormat:@"/%@/bookmarks.html", aTempItem];
|
||||
}
|
||||
}
|
||||
// find the last modified profile
|
||||
NSString *lastModifiedSubDir = [[NSFileManager defaultManager] lastModifiedSubdirectoryAtPath:aPath];
|
||||
if (lastModifiedSubDir)
|
||||
return [lastModifiedSubDir stringByAppendingPathComponent:@"bookmarks.html"];
|
||||
|
||||
return nil;
|
||||
}
|
||||
|
||||
|
@ -172,7 +168,6 @@
|
|||
- (IBAction)cancel:(id)aSender
|
||||
{
|
||||
[[self window] orderOut:self];
|
||||
|
||||
}
|
||||
|
||||
- (IBAction)import:(id)aSender
|
||||
|
|
|
@ -49,4 +49,8 @@
|
|||
// (e.g. bookmarks.plist will be changed to "bookmarksSUFFIX-1.plist".
|
||||
- (NSString*)backupFileNameFromPath:(NSString*)inPath withSuffix:(NSString*)inFileSuffix;
|
||||
|
||||
// Finds the last modified subdirectory at the specified path. not recursive.
|
||||
// Ignores hidden directories and will return nil on failure.
|
||||
- (NSString *)lastModifiedSubdirectoryAtPath:(NSString *)path;
|
||||
|
||||
@end
|
||||
|
|
|
@ -102,4 +102,36 @@
|
|||
return newName;
|
||||
}
|
||||
|
||||
- (NSString *)lastModifiedSubdirectoryAtPath:(NSString *)inPath
|
||||
{
|
||||
inPath = [inPath stringByStandardizingPath];
|
||||
|
||||
NSFileManager* fileManager = [NSFileManager defaultManager];
|
||||
BOOL isDirectory = NO;
|
||||
if (!([fileManager fileExistsAtPath:inPath isDirectory:&isDirectory] && isDirectory))
|
||||
return nil;
|
||||
|
||||
NSDate* newestModificationDateFound = [NSDate distantPast];
|
||||
NSString* lastModifiedSubdirectory = nil;
|
||||
NSEnumerator* directoryContentsEnumerator = [[fileManager directoryContentsAtPath:inPath] objectEnumerator];
|
||||
NSString* subpath = nil;
|
||||
while ((subpath = [directoryContentsEnumerator nextObject])) {
|
||||
if ([subpath hasPrefix:@"."])
|
||||
continue;
|
||||
|
||||
subpath = [inPath stringByAppendingPathComponent:subpath];
|
||||
|
||||
if (!([fileManager fileExistsAtPath:subpath isDirectory:&isDirectory] && isDirectory))
|
||||
continue;
|
||||
|
||||
NSDate* currentFileModificationDate = [[fileManager fileAttributesAtPath:subpath
|
||||
traverseLink:NO] fileModificationDate];
|
||||
if ([currentFileModificationDate timeIntervalSinceDate:newestModificationDateFound] > 0) {
|
||||
newestModificationDateFound = currentFileModificationDate;
|
||||
lastModifiedSubdirectory = subpath;
|
||||
}
|
||||
}
|
||||
return lastModifiedSubdirectory;
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
Загрузка…
Ссылка в новой задаче