diff options
author | Bibiko <bibiko@eva.mpg.de> | 2010-08-19 13:57:15 +0000 |
---|---|---|
committer | Bibiko <bibiko@eva.mpg.de> | 2010-08-19 13:57:15 +0000 |
commit | 8915074c6393bdc5cbaa7900299122f0d4e365be (patch) | |
tree | 639dc351971b8b7661fa216ebfb41c9406fb2c0e | |
parent | 6cf7762d7ae11c75698c11ffee0822b3ead24932 (diff) | |
download | sequelpro-8915074c6393bdc5cbaa7900299122f0d4e365be.tar.gz sequelpro-8915074c6393bdc5cbaa7900299122f0d4e365be.tar.bz2 sequelpro-8915074c6393bdc5cbaa7900299122f0d4e365be.zip |
• added SPFileManagerAdditions
- [(NSString*)applicationSupportDirectoryForSubDirectory:error:]
Return the application support folder of the current application for 'subDirectory'. If this folder doesn't exist it will be created. If 'subDirectory' == nil it only returns the application support folder of the current application.
• added SPThemesSupportFolder constant
-rw-r--r-- | Resources/English.lproj/Credits.rtf | 6 | ||||
-rw-r--r-- | Source/SPAppController.m | 8 | ||||
-rw-r--r-- | Source/SPConstants.h | 4 | ||||
-rw-r--r-- | Source/SPConstants.m | 5 | ||||
-rw-r--r-- | Source/SPFileManagerAdditions.h | 32 | ||||
-rw-r--r-- | Source/SPFileManagerAdditions.m | 143 | ||||
-rw-r--r-- | Source/SPPreferenceController.m | 5 | ||||
-rw-r--r-- | sequel-pro.xcodeproj/project.pbxproj | 6 |
8 files changed, 203 insertions, 6 deletions
diff --git a/Resources/English.lproj/Credits.rtf b/Resources/English.lproj/Credits.rtf index c25dbb28..70cf5ae5 100644 --- a/Resources/English.lproj/Credits.rtf +++ b/Resources/English.lproj/Credits.rtf @@ -1,4 +1,4 @@ -{\rtf1\ansi\ansicpg1252\cocoartf1038\cocoasubrtf290 +{\rtf1\ansi\ansicpg1252\cocoartf1038\cocoasubrtf320 {\fonttbl\f0\fnil\fcharset0 LucidaGrande;} {\colortbl;\red255\green255\blue255;\red25\green25\blue25;\red0\green27\blue199;} \vieww9000\viewh8400\viewkind0 @@ -51,7 +51,9 @@ Matt Gemmell\ Joachim M\'e5rtensson, Allan Odgaard\ (TMDIncrementalPopUp)\ Ci\'e1ran Walsh, Allan Odgaard\ -(TMDHTMLtip) \ +(TMDHTMLtip)\ +Matt Gallagher\ +(NSFileManagerAddition)\ \ \b RegexKitLite diff --git a/Source/SPAppController.m b/Source/SPAppController.m index b03603bd..88890c46 100644 --- a/Source/SPAppController.m +++ b/Source/SPAppController.m @@ -424,14 +424,20 @@ [spfs release]; } else if([[[filename pathExtension] lowercaseString] isEqualToString:[SPColorThemeFileExtension lowercaseString]]) { + NSFileManager *fm = [NSFileManager defaultManager]; - NSString *themePath = [[NSString stringWithString:@"~/Library/Application Support/Sequel Pro/Themes"] stringByExpandingTildeInPath]; + + NSString *themePath = [[NSFileManager defaultManager] applicationSupportDirectoryForSubDirectory:SPThemesSupportFolder error:nil]; + + if(!themePath) return; + if(![fm fileExistsAtPath:themePath isDirectory:nil]) { if(![fm createDirectoryAtPath:themePath withIntermediateDirectories:YES attributes:nil error:nil]) { NSBeep(); return; } } + NSString *newPath = [NSString stringWithFormat:@"%@/%@", themePath, [filename lastPathComponent]]; if(![fm fileExistsAtPath:newPath isDirectory:nil]) { if(![fm copyItemAtPath:filename toPath:newPath error:nil]) { diff --git a/Source/SPConstants.h b/Source/SPConstants.h index 9086128a..1ee44264 100644 --- a/Source/SPConstants.h +++ b/Source/SPConstants.h @@ -224,11 +224,13 @@ extern NSString *SPFileExtensionSQL; extern NSString *SPBundleFileExtension; extern NSString *SPColorThemeFileExtension; -// Filenames +// File names extern NSString *SPHTMLPrintTemplate; extern NSString *SPHTMLTableInfoPrintTemplate; extern NSString *SPHTMLHelpTemplate; +// Folder names +extern NSString *SPThemesSupportFolder; // Preference key constants // General Prefpane diff --git a/Source/SPConstants.m b/Source/SPConstants.m index 8fa5aadd..dd6758b1 100644 --- a/Source/SPConstants.m +++ b/Source/SPConstants.m @@ -48,11 +48,14 @@ NSString *SPBundleFileExtension = @"spfs"; NSString *SPFileExtensionSQL = @"sql"; NSString *SPColorThemeFileExtension = @"spTheme"; -// Filenames +// File names NSString *SPHTMLPrintTemplate = @"sequel-pro-print-template"; NSString *SPHTMLTableInfoPrintTemplate = @"sequel-pro-table-info-print-template"; NSString *SPHTMLHelpTemplate = @"sequel-pro-mysql-help-template"; +// Folder names +NSString *SPThemesSupportFolder = @"Themes"; + // Preference key constants // General Prefpane NSString *SPDefaultFavorite = @"DefaultFavorite"; diff --git a/Source/SPFileManagerAdditions.h b/Source/SPFileManagerAdditions.h new file mode 100644 index 00000000..70de36f0 --- /dev/null +++ b/Source/SPFileManagerAdditions.h @@ -0,0 +1,32 @@ +// +// $Id$ +// +// SPFileManagerAdditions.h +// sequel-pro +// +// Created by Hans-Jörg Bibiko on August 19, 2010 +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// More info at <http://code.google.com/p/sequel-pro/> + +#import <Cocoa/Cocoa.h> +#import <Foundation/Foundation.h> + +@interface NSFileManager (SPFileManagerAdditions) + +- (NSString*)applicationSupportDirectoryForSubDirectory:(NSString*)subDirectory error:(NSError **)errorOut; + +@end diff --git a/Source/SPFileManagerAdditions.m b/Source/SPFileManagerAdditions.m new file mode 100644 index 00000000..179f33d7 --- /dev/null +++ b/Source/SPFileManagerAdditions.m @@ -0,0 +1,143 @@ +// +// $Id$ +// +// SPFileManagerAdditions.m +// sequel-pro +// +// Created by Hans-Jörg Bibiko on August 19, 2010 +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// More info at <http://code.google.com/p/sequel-pro/> + + +#import "SPFileManagerAdditions.h" + +enum +{ + DirectoryLocationErrorNoPathFound, + DirectoryLocationErrorFileExistsAtLocation +}; + +NSString* const DirectoryLocationDomain = @"DirectoryLocationDomain"; + + +@implementation NSFileManager (SPFileManagerAdditions) + +/* + * Return the application support folder of the current application for 'subDirectory'. + * If this folder doesn't exist it will be created. If 'subDirectory' == nil it only returns + * the application support folder of the current application. + */ +- (NSString*)applicationSupportDirectoryForSubDirectory:(NSString*)subDirectory error:(NSError **)errorOut +{ + // Based on Matt Gallagher on 06 May 2010 + // + // Permission is given to use this source code file, free of charge, in any + // project, commercial or otherwise, entirely at your risk, with the condition + // that any redistribution (in part or whole) of source code must retain + // this copyright and permission notice. Attribution in compiled projects is + // appreciated but not required. + // + + NSError *error; + + NSArray* paths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES); + + if (![paths count]) { + if (errorOut) { + NSDictionary *userInfo = + [NSDictionary dictionaryWithObjectsAndKeys: + NSLocalizedStringFromTable( + @"No path found for directory in domain.", + @"Errors", + nil), + NSLocalizedDescriptionKey, + [NSNumber numberWithInteger:NSApplicationSupportDirectory], + @"NSSearchPathDirectory", + [NSNumber numberWithInteger:NSUserDomainMask], + @"NSSearchPathDomainMask", + nil]; + *errorOut = [NSError + errorWithDomain:DirectoryLocationDomain + code:DirectoryLocationErrorNoPathFound + userInfo:userInfo]; + } + return nil; + } + + // Use only the first path returned + NSString *resolvedPath = [paths objectAtIndex:0]; + + // Append the application name + resolvedPath = [resolvedPath stringByAppendingPathComponent:[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleExecutable"]]; + + // Append the subdirectory if passed + if (subDirectory) + resolvedPath = [resolvedPath stringByAppendingPathComponent:subDirectory]; + + // Check if the path exists already + BOOL exists; + BOOL isDirectory; + exists = [self fileExistsAtPath:resolvedPath isDirectory:&isDirectory]; + if (!exists || !isDirectory) { + if (exists) { + if (errorOut) { + NSDictionary *userInfo = + [NSDictionary dictionaryWithObjectsAndKeys: + NSLocalizedStringFromTable( + @"File exists at requested directory location.", + @"Errors", + nil), + NSLocalizedDescriptionKey, + [NSNumber numberWithInteger:NSApplicationSupportDirectory], + @"NSSearchPathDirectory", + [NSNumber numberWithInteger:NSUserDomainMask], + @"NSSearchPathDomainMask", + nil]; + *errorOut = [NSError + errorWithDomain:DirectoryLocationDomain + code:DirectoryLocationErrorFileExistsAtLocation + userInfo:userInfo]; + } + return nil; + } + + // Create the path if it doesn't exist + NSError *error = nil; + BOOL success = [self createDirectoryAtPath:resolvedPath withIntermediateDirectories:YES attributes:nil error:&error]; + if (!success) { + if (errorOut) { + *errorOut = error; + } + return nil; + } + } + + if (errorOut) + *errorOut = nil; + + if (!resolvedPath) { + NSBeep(); + NSLog(@"Unable to find or create application support directory:\n%@", error); + } + + + return resolvedPath; + + +} + +@end diff --git a/Source/SPPreferenceController.m b/Source/SPPreferenceController.m index 79f18b62..2810eeb6 100644 --- a/Source/SPPreferenceController.m +++ b/Source/SPPreferenceController.m @@ -31,6 +31,7 @@ #import "SPConnectionController.h" #import "SPColorAdditions.h" #import "SPColorWellCell.h" +#import "SPFileManagerAdditions.h" @interface SPPreferenceController (PrivateAPI) @@ -65,8 +66,10 @@ [NSColor setIgnoresAlpha:NO]; - themePath = [[[NSString stringWithString:@"~/Library/Application Support/Sequel Pro/Themes"] stringByExpandingTildeInPath] retain]; + themePath = [[[NSFileManager defaultManager] applicationSupportDirectoryForSubDirectory:SPThemesSupportFolder error:nil] retain]; + editThemeListItems = [[NSArray arrayWithArray:[self getAvailableThemes]] retain]; + } return self; diff --git a/sequel-pro.xcodeproj/project.pbxproj b/sequel-pro.xcodeproj/project.pbxproj index 43c0719e..34cbcfd5 100644 --- a/sequel-pro.xcodeproj/project.pbxproj +++ b/sequel-pro.xcodeproj/project.pbxproj @@ -345,6 +345,7 @@ BC2C16D40FEBEDF10003993B /* SPDataAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = BC2C16D30FEBEDF10003993B /* SPDataAdditions.m */; }; BC2C8E220FA8C2DB008468C7 /* sequel-pro-mysql-help-template.html in Resources */ = {isa = PBXBuildFile; fileRef = BC2C8E210FA8C2DB008468C7 /* sequel-pro-mysql-help-template.html */; }; BC30C011111C98BD002701C9 /* DataMigrationDialog.xib in Resources */ = {isa = PBXBuildFile; fileRef = BC30C00F111C98BD002701C9 /* DataMigrationDialog.xib */; }; + BC32F242121D66260067305E /* SPFileManagerAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = BC32F241121D66260067305E /* SPFileManagerAdditions.m */; }; BC398A2D121D526200BE3EF4 /* SPCopyTable.m in Sources */ = {isa = PBXBuildFile; fileRef = BC398A2C121D526200BE3EF4 /* SPCopyTable.m */; }; BC4DF1981158FB280059FABD /* SPNavigatorOutlineView.m in Sources */ = {isa = PBXBuildFile; fileRef = BC4DF1971158FB280059FABD /* SPNavigatorOutlineView.m */; }; BC5AD7FF10FB262F008769E3 /* field-small-square.tiff in Resources */ = {isa = PBXBuildFile; fileRef = BC5AD7FE10FB262F008769E3 /* field-small-square.tiff */; }; @@ -978,6 +979,8 @@ BC2C16D30FEBEDF10003993B /* SPDataAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SPDataAdditions.m; sourceTree = "<group>"; }; BC2C8E210FA8C2DB008468C7 /* sequel-pro-mysql-help-template.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; name = "sequel-pro-mysql-help-template.html"; path = "Templates/sequel-pro-mysql-help-template.html"; sourceTree = "<group>"; }; BC30C010111C98BD002701C9 /* English */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = English; path = English.lproj/DataMigrationDialog.xib; sourceTree = "<group>"; }; + BC32F240121D66260067305E /* SPFileManagerAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPFileManagerAdditions.h; sourceTree = "<group>"; }; + BC32F241121D66260067305E /* SPFileManagerAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SPFileManagerAdditions.m; sourceTree = "<group>"; }; BC398A2B121D526200BE3EF4 /* SPCopyTable.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPCopyTable.h; sourceTree = "<group>"; }; BC398A2C121D526200BE3EF4 /* SPCopyTable.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SPCopyTable.m; sourceTree = "<group>"; }; BC4DF1961158FB280059FABD /* SPNavigatorOutlineView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPNavigatorOutlineView.h; sourceTree = "<group>"; }; @@ -2140,6 +2143,8 @@ 589582141154F8F400EDCC28 /* SPMainThreadTrampoline.m */, BC85F5CE12193B7D00E255B5 /* SPColorAdditions.h */, BC85F5CF12193B7D00E255B5 /* SPColorAdditions.m */, + BC32F240121D66260067305E /* SPFileManagerAdditions.h */, + BC32F241121D66260067305E /* SPFileManagerAdditions.m */, ); name = "Category Additions"; sourceTree = "<group>"; @@ -2755,6 +2760,7 @@ BC85F5D012193B7D00E255B5 /* SPColorAdditions.m in Sources */, BC878A71121A836F00AE5066 /* SPColorWellCell.m in Sources */, BC398A2D121D526200BE3EF4 /* SPCopyTable.m in Sources */, + BC32F242121D66260067305E /* SPFileManagerAdditions.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; |