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 "MainController.h"
|
||||||
#import "BrowserWindowController.h"
|
#import "BrowserWindowController.h"
|
||||||
#import "BookmarkViewController.h"
|
#import "BookmarkViewController.h"
|
||||||
|
#import "NSFileManager+Utils.h"
|
||||||
|
|
||||||
@interface BookmarkImportDlgController (Private)
|
@interface BookmarkImportDlgController (Private)
|
||||||
|
|
||||||
|
@ -68,7 +69,8 @@
|
||||||
[self buildAvailableFileList];
|
[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
|
- (void)buildAvailableFileList
|
||||||
{
|
{
|
||||||
NSString *mozPath;
|
NSString *mozPath;
|
||||||
|
@ -137,21 +139,15 @@
|
||||||
[self buildButtonForBrowser:@"OmniWeb 5" withPathArray:haveFiles];
|
[self buildButtonForBrowser:@"OmniWeb 5" withPathArray:haveFiles];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Given a Mozilla-like profile, returns the bookmarks.html file in the salt directory,
|
// Given a Mozilla-like profile, returns the bookmarks.html file in the salt directory
|
||||||
// or nil if no salt directory is found
|
// for the last modified profile, or nil on error
|
||||||
- (NSString *)getSaltedBookmarkPathForProfile:(NSString *)aPath
|
- (NSString *)getSaltedBookmarkPathForProfile:(NSString *)aPath
|
||||||
{
|
{
|
||||||
NSFileManager *fm = [NSFileManager defaultManager];
|
// find the last modified profile
|
||||||
id aTempItem;
|
NSString *lastModifiedSubDir = [[NSFileManager defaultManager] lastModifiedSubdirectoryAtPath:aPath];
|
||||||
NSString *fullPathString = [aPath stringByStandardizingPath];
|
if (lastModifiedSubDir)
|
||||||
if ([fm fileExistsAtPath:fullPathString]) {
|
return [lastModifiedSubDir stringByAppendingPathComponent:@"bookmarks.html"];
|
||||||
NSArray *saltArray = [fm directoryContentsAtPath:fullPathString];
|
|
||||||
NSEnumerator *enumerator = [saltArray objectEnumerator];
|
|
||||||
while ((aTempItem = [enumerator nextObject])) {
|
|
||||||
if (![aTempItem hasPrefix:@"."])
|
|
||||||
return [fullPathString stringByAppendingFormat:@"/%@/bookmarks.html", aTempItem];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -172,7 +168,6 @@
|
||||||
- (IBAction)cancel:(id)aSender
|
- (IBAction)cancel:(id)aSender
|
||||||
{
|
{
|
||||||
[[self window] orderOut:self];
|
[[self window] orderOut:self];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (IBAction)import:(id)aSender
|
- (IBAction)import:(id)aSender
|
||||||
|
|
|
@ -49,4 +49,8 @@
|
||||||
// (e.g. bookmarks.plist will be changed to "bookmarksSUFFIX-1.plist".
|
// (e.g. bookmarks.plist will be changed to "bookmarksSUFFIX-1.plist".
|
||||||
- (NSString*)backupFileNameFromPath:(NSString*)inPath withSuffix:(NSString*)inFileSuffix;
|
- (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
|
@end
|
||||||
|
|
|
@ -102,4 +102,36 @@
|
||||||
return newName;
|
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
|
@end
|
||||||
|
|
Загрузка…
Ссылка в новой задаче