31#define OOLITE_LEOPARD 1
36- (NSURL *) snapshotsURLCreatingIfNeeded:(BOOL)create;
55 if ((
self = [super
init]))
57 [NSBundle loadNibNamed:@"OODockTilePlugIn" owner:self];
73- (IBAction) showScreenShots:(
id)sender
75 [[NSWorkspace sharedWorkspace] openURL:[
self snapshotsURLCreatingIfNeeded:NO]];
79- (IBAction) showExpansionPacks:sender
84 for (NSString *path in paths) {
85 if ([
self addOnsExistAtPath:path]) {
92 for (NSString *path in paths) {
93 if ([
self isDirectoryAtPath:path]) {
100 [NSFileManager.defaultManager createDirectoryAtPath:paths[0]
101 withIntermediateDirectories:YES
104 [
self openPath:paths[0]];
108- (BOOL) isDirectoryAtPath:(NSString *)path
111 return [NSFileManager.defaultManager fileExistsAtPath:path isDirectory:&isDirectory] && isDirectory;
115- (BOOL) addOnsExistAtPath:(NSString *)path
117 if (![
self isDirectoryAtPath:path])
return NO;
119 NSWorkspace *workspace = NSWorkspace.sharedWorkspace;
120 for (NSString *subPath in [NSFileManager.defaultManager enumeratorAtPath:path]) {
121 subPath = [path stringByAppendingPathComponent:subPath];
122 NSString *type = [workspace typeOfFile:subPath error:NULL];
123 if ([workspace type:type conformsToType:
@"org.aegidian.oolite.expansion"])
return YES;
130- (void) openPath:(NSString *)path
132 [NSWorkspace.sharedWorkspace openURL:[NSURL fileURLWithPath:path]];
136- (IBAction) showLatestLog:(
id)sender
138 [[NSWorkspace sharedWorkspace] openURL:[NSURL fileURLWithPath:[
self latestLogPath]]];
142- (IBAction) showLogFolder:(
id)sender
144 [[NSWorkspace sharedWorkspace] openURL:[NSURL fileURLWithPath:[
self logFolderPath]]];
148- (BOOL) validateMenuItem:(NSMenuItem *)menuItem
150 SEL action = [menuItem action];
152 if (action ==
@selector(showScreenShots:))
154 return [[NSFileManager defaultManager] fileExistsAtPath:[[
self snapshotsURLCreatingIfNeeded:NO] path]];
156 else if (action ==
@selector(showLatestLog:))
158 return [[NSFileManager defaultManager] fileExistsAtPath:[
self latestLogPath]];
168 CFPropertyListRef value = CFPreferencesCopyAppValue((CFStringRef)key, CFSTR(
"org.aegidian.oolite"));
169 id result = [NSMakeCollectable(value) autorelease];
170 if (expectedClass != Nil && ![result isKindOfClass:expectedClass]) result =
nil;
178 CFPreferencesSetAppValue((CFStringRef)key, value, CFSTR(
"org.aegidian.oolite"));
188static NSString *
DESC(NSString *key)
190 static NSDictionary *descs =
nil;
194 NSURL *url = [[NSBundle bundleForClass:[
OODockTilePlugIn class]] bundleURL];
195 url = [NSURL URLWithString:@"../../Resources/Config/descriptions.plist" relativeToURL:url];
197 descs = [NSDictionary dictionaryWithContentsOfURL:url];
198 if (descs ==
nil) descs = [NSDictionary dictionary];
202 NSString *result = [descs objectForKey:key];
203 if (![result isKindOfClass:[NSString
class]]) result = key;
208#define kSnapshotsDirRefKey @"snapshots-directory-reference"
209#define kSnapshotsDirNameKey @"snapshots-directory-name"
211- (NSURL *) snapshotsURLCreatingIfNeeded:(BOOL)create
216 NSString *name =
DESC(
@"snapshots-directory-name-mac");
218 if (snapshotDirDict !=
nil)
223 NSString *existingName = [[url path] lastPathComponent];
224 if ([existingName compare:name options:NSCaseInsensitiveSearch] != 0)
228 if (originalOldName ==
nil || [existingName compare:originalOldName options:NSCaseInsensitiveSearch] != 0)
235 Boolean inTrash =
false;
236 const UInt8* utfPath = (UInt8*)[[url path] UTF8String];
238 OSStatus err = DetermineIfPathIsEnclosedByFolder(kOnAppropriateDisk, kTrashFolderType, utfPath,
false, &inTrash);
240 if (err == noErr && inTrash ==
true) url =
nil;
246 NSString *path =
nil;
247 NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSDesktopDirectory, NSUserDomainMask, YES);
248 if ([searchPaths
count] > 0)
250 path = [[searchPaths objectAtIndex:0] stringByAppendingPathComponent:name];
252 url = [NSURL fileURLWithPath:path];
259 NSFileManager *fmgr = [NSFileManager defaultManager];
260 if (![fmgr fileExistsAtPath:path])
263 [fmgr createDirectoryAtPath:path withIntermediateDirectories:YES attributes:nil error:NULL];
265 [fmgr createDirectoryAtPath:path attributes:nil];
275 if (snapshotDirDict !=
nil)
292 return [[
self logFolderPath] stringByAppendingPathComponent:@"Latest.log"];
307 static NSString *basePath =
nil;
312 basePath = [NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES) objectAtIndex:0];
313 basePath = [basePath stringByAppendingPathComponent:@"Logs"];
314 basePath = [basePath stringByAppendingPathComponent:@"Oolite"];
316 BOOL exists, directory;
317 NSFileManager *fmgr = [NSFileManager defaultManager];
319 exists = [fmgr fileExistsAtPath:basePath isDirectory:&directory];
329 if (![fmgr createDirectoryAtPath:basePath withIntermediateDirectories:YES attributes:
nil error:NULL])
345 return [NSArray arrayWithObjects:
346 [[[[NSHomeDirectory() stringByAppendingPathComponent:@"Library"]
347 stringByAppendingPathComponent:@"Application Support"]
348 stringByAppendingPathComponent:@"Oolite"]
349 stringByAppendingPathComponent:@"AddOns"],
350 [[[[NSBundle mainBundle] bundlePath]
351 stringByDeletingLastPathComponent]
352 stringByAppendingPathComponent:@"AddOns"],
354 stringByAppendingPathComponent:@".Oolite"]
355 stringByAppendingPathComponent:@"AddOns"],
#define kSnapshotsDirNameKey
#define kSnapshotsDirRefKey
@ kJAPersistentFileReferenceWithoutUI
@ kJAPersistentFileReferenceWithoutMounting
NSURL * JAURLFromPersistentFileReference(NSDictionary *fileRef, JAPersistentFileReferenceResolveFlags flags, BOOL *isStale)
NSDictionary * JAPersistentFileReferenceFromURL(NSURL *url)
static NSString * OOLogHandlerGetLogBasePath(void)
static NSArray * ResourceManagerRootPaths(void)
NSString * OOLogHandlerGetLogBasePath(void)
static void SetPreference(NSString *key, id value)
static NSString * DESC(NSString *key)
IBOutlet NSMenu * dockMenu
static id GetPreference(NSString *key, Class expectedClass)
static void RemovePreference(NSString *key)
NSString * latestLogPath()
NSString * logFolderPath()