aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2012-07-20 23:36:36 -0400
committerTeddy Wing2012-07-20 23:36:36 -0400
commit8575b4fe4e7283383154dc5ac016fcfe042dcb56 (patch)
tree48b3b8591382a82a3b48cc84271cf03da56cdc16
parent7720dba1e726bdf91a6ae4191fe39285eeb1dee3 (diff)
downloadOn-Task-8575b4fe4e7283383154dc5ac016fcfe042dcb56.tar.bz2
New version of ApplicationSupport directory -finder.
-rw-r--r--Classes/NSFileManager+DirectoryLocations.h17
-rw-r--r--Classes/NSFileManager+DirectoryLocations.m18
-rw-r--r--On Task.xcodeproj/project.pbxproj16
-rw-r--r--vendor/NSFileManager+DirectoryLocations.h36
-rw-r--r--vendor/NSFileManager+DirectoryLocations.m161
5 files changed, 43 insertions, 205 deletions
diff --git a/Classes/NSFileManager+DirectoryLocations.h b/Classes/NSFileManager+DirectoryLocations.h
new file mode 100644
index 0000000..6c42204
--- /dev/null
+++ b/Classes/NSFileManager+DirectoryLocations.h
@@ -0,0 +1,17 @@
+// Based off of Matt Gallagher's 10.5+ category from:
+// http://cocoawithlove.com/2010/05/finding-or-creating-application-support.html
+//
+// Actual function code taken from Hasani Hunter:
+// http://www.cocoabuilder.com/archive/cocoa/190500-saving-to-application-support-folder.html#190506
+
+#import <Foundation/Foundation.h>
+
+//
+// DirectoryLocations is a set of global methods for finding the fixed location
+// directories.
+//
+@interface NSFileManager (DirectoryLocations)
+
+- (NSString *)applicationSupportDirectory;
+
+@end
diff --git a/Classes/NSFileManager+DirectoryLocations.m b/Classes/NSFileManager+DirectoryLocations.m
new file mode 100644
index 0000000..84cf307
--- /dev/null
+++ b/Classes/NSFileManager+DirectoryLocations.m
@@ -0,0 +1,18 @@
+#import "NSFileManager+DirectoryLocations.h"
+
+@implementation NSFileManager (DirectoryLocations)
+
+/**
+ Returns the support folder for the application, used to store the Core Data
+ store file. This code uses a folder named _ApplicationName_ for
+ the content, either in the NSApplicationSupportDirectory location or (if the
+ former cannot be found), the system's temporary directory.
+ */
+
+- (NSString *)applicationSupportDirectory {
+ NSArray *paths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES);
+ NSString *basePath = ([paths count] > 0) ? [paths objectAtIndex: 0] : NSTemporaryDirectory();
+ return [basePath stringByAppendingPathComponent:@"On Task"];
+}
+
+@end
diff --git a/On Task.xcodeproj/project.pbxproj b/On Task.xcodeproj/project.pbxproj
index 2bc3550..8e9ab61 100644
--- a/On Task.xcodeproj/project.pbxproj
+++ b/On Task.xcodeproj/project.pbxproj
@@ -10,8 +10,8 @@
8DD76F9A0486AA7600D96B5E /* On Task.m in Sources */ = {isa = PBXBuildFile; fileRef = 08FB7796FE84155DC02AAC07 /* On Task.m */; settings = {ATTRIBUTES = (); }; };
8DD76F9C0486AA7600D96B5E /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 08FB779EFE84155DC02AAC07 /* Foundation.framework */; };
8DD76F9F0486AA7600D96B5E /* On Task.1 in CopyFiles */ = {isa = PBXBuildFile; fileRef = C6859EA3029092ED04C91782 /* On Task.1 */; };
- D195B56D15BA4E46005D8C2E /* NSFileManager+DirectoryLocations.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = D195B56B15BA4E46005D8C2E /* NSFileManager+DirectoryLocations.h */; };
- D195B56E15BA4E46005D8C2E /* NSFileManager+DirectoryLocations.m in Sources */ = {isa = PBXBuildFile; fileRef = D195B56C15BA4E46005D8C2E /* NSFileManager+DirectoryLocations.m */; };
+ D17EB4E115BA572600A0FB10 /* NSFileManager+DirectoryLocations.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = D17EB4DF15BA572600A0FB10 /* NSFileManager+DirectoryLocations.h */; };
+ D17EB4E215BA572600A0FB10 /* NSFileManager+DirectoryLocations.m in Sources */ = {isa = PBXBuildFile; fileRef = D17EB4E015BA572600A0FB10 /* NSFileManager+DirectoryLocations.m */; };
/* End PBXBuildFile section */
/* Begin PBXCopyFilesBuildPhase section */
@@ -22,7 +22,7 @@
dstSubfolderSpec = 0;
files = (
8DD76F9F0486AA7600D96B5E /* On Task.1 in CopyFiles */,
- D195B56D15BA4E46005D8C2E /* NSFileManager+DirectoryLocations.h in CopyFiles */,
+ D17EB4E115BA572600A0FB10 /* NSFileManager+DirectoryLocations.h in CopyFiles */,
);
runOnlyForDeploymentPostprocessing = 1;
};
@@ -34,8 +34,8 @@
32A70AAB03705E1F00C91783 /* On Task_Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "On Task_Prefix.pch"; sourceTree = "<group>"; };
8DD76FA10486AA7600D96B5E /* On Task */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = "On Task"; sourceTree = BUILT_PRODUCTS_DIR; };
C6859EA3029092ED04C91782 /* On Task.1 */ = {isa = PBXFileReference; lastKnownFileType = text.man; path = "On Task.1"; sourceTree = "<group>"; };
- D195B56B15BA4E46005D8C2E /* NSFileManager+DirectoryLocations.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = "NSFileManager+DirectoryLocations.h"; path = "vendor/NSFileManager+DirectoryLocations.h"; sourceTree = "<group>"; };
- D195B56C15BA4E46005D8C2E /* NSFileManager+DirectoryLocations.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; name = "NSFileManager+DirectoryLocations.m"; path = "vendor/NSFileManager+DirectoryLocations.m"; sourceTree = "<group>"; };
+ D17EB4DF15BA572600A0FB10 /* NSFileManager+DirectoryLocations.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = "NSFileManager+DirectoryLocations.h"; path = "Classes/NSFileManager+DirectoryLocations.h"; sourceTree = "<group>"; };
+ D17EB4E015BA572600A0FB10 /* NSFileManager+DirectoryLocations.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; name = "NSFileManager+DirectoryLocations.m"; path = "Classes/NSFileManager+DirectoryLocations.m"; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@@ -64,8 +64,8 @@
08FB7795FE84155DC02AAC07 /* Source */ = {
isa = PBXGroup;
children = (
- D195B56B15BA4E46005D8C2E /* NSFileManager+DirectoryLocations.h */,
- D195B56C15BA4E46005D8C2E /* NSFileManager+DirectoryLocations.m */,
+ D17EB4DF15BA572600A0FB10 /* NSFileManager+DirectoryLocations.h */,
+ D17EB4E015BA572600A0FB10 /* NSFileManager+DirectoryLocations.m */,
32A70AAB03705E1F00C91783 /* On Task_Prefix.pch */,
08FB7796FE84155DC02AAC07 /* On Task.m */,
);
@@ -138,7 +138,7 @@
buildActionMask = 2147483647;
files = (
8DD76F9A0486AA7600D96B5E /* On Task.m in Sources */,
- D195B56E15BA4E46005D8C2E /* NSFileManager+DirectoryLocations.m in Sources */,
+ D17EB4E215BA572600A0FB10 /* NSFileManager+DirectoryLocations.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
diff --git a/vendor/NSFileManager+DirectoryLocations.h b/vendor/NSFileManager+DirectoryLocations.h
deleted file mode 100644
index 2ffd42a..0000000
--- a/vendor/NSFileManager+DirectoryLocations.h
+++ /dev/null
@@ -1,36 +0,0 @@
-//
-// NSFileManager+DirectoryLocations.h
-//
-// Created by Matt Gallagher on 06 May 2010
-//
-// This software is provided 'as-is', without any express or implied
-// warranty. In no event will the authors be held liable for any damages
-// arising from the use of this software. Permission is granted to anyone to
-// use this software for any purpose, including commercial applications, and to
-// alter it and redistribute it freely, subject to the following restrictions:
-//
-// 1. The origin of this software must not be misrepresented; you must not
-// claim that you wrote the original software. If you use this software
-// in a product, an acknowledgment in the product documentation would be
-// appreciated but is not required.
-// 2. Altered source versions must be plainly marked as such, and must not be
-// misrepresented as being the original software.
-// 3. This notice may not be removed or altered from any source
-// distribution.
-//
-
-#import <Foundation/Foundation.h>
-
-//
-// DirectoryLocations is a set of global methods for finding the fixed location
-// directoriess.
-//
-@interface NSFileManager (DirectoryLocations)
-
-- (NSString *)findOrCreateDirectory:(NSSearchPathDirectory)searchPathDirectory
- inDomain:(NSSearchPathDomainMask)domainMask
- appendPathComponent:(NSString *)appendComponent
- error:(NSError **)errorOut;
-- (NSString *)applicationSupportDirectory;
-
-@end
diff --git a/vendor/NSFileManager+DirectoryLocations.m b/vendor/NSFileManager+DirectoryLocations.m
deleted file mode 100644
index a21f021..0000000
--- a/vendor/NSFileManager+DirectoryLocations.m
+++ /dev/null
@@ -1,161 +0,0 @@
-//
-// NSFileManager+DirectoryLocations.m
-//
-// Created by Matt Gallagher on 06 May 2010
-//
-// This software is provided 'as-is', without any express or implied
-// warranty. In no event will the authors be held liable for any damages
-// arising from the use of this software. Permission is granted to anyone to
-// use this software for any purpose, including commercial applications, and to
-// alter it and redistribute it freely, subject to the following restrictions:
-//
-// 1. The origin of this software must not be misrepresented; you must not
-// claim that you wrote the original software. If you use this software
-// in a product, an acknowledgment in the product documentation would be
-// appreciated but is not required.
-// 2. Altered source versions must be plainly marked as such, and must not be
-// misrepresented as being the original software.
-// 3. This notice may not be removed or altered from any source
-// distribution.
-//
-
-#import "NSFileManager+DirectoryLocations.h"
-
-enum
-{
- DirectoryLocationErrorNoPathFound,
- DirectoryLocationErrorFileExistsAtLocation
-};
-
-NSString * const DirectoryLocationDomain = @"DirectoryLocationDomain";
-
-@implementation NSFileManager (DirectoryLocations)
-
-//
-// findOrCreateDirectory:inDomain:appendPathComponent:error:
-//
-// Method to tie together the steps of:
-// 1) Locate a standard directory by search path and domain mask
-// 2) Select the first path in the results
-// 3) Append a subdirectory to that path
-// 4) Create the directory and intermediate directories if needed
-// 5) Handle errors by emitting a proper NSError object
-//
-// Parameters:
-// searchPathDirectory - the search path passed to NSSearchPathForDirectoriesInDomains
-// domainMask - the domain mask passed to NSSearchPathForDirectoriesInDomains
-// appendComponent - the subdirectory appended
-// errorOut - any error from file operations
-//
-// returns the path to the directory (if path found and exists), nil otherwise
-//
-- (NSString *)findOrCreateDirectory:(NSSearchPathDirectory)searchPathDirectory
- inDomain:(NSSearchPathDomainMask)domainMask
- appendPathComponent:(NSString *)appendComponent
- error:(NSError **)errorOut
-{
- //
- // Search for the path
- //
- NSArray* paths = NSSearchPathForDirectoriesInDomains(
- searchPathDirectory,
- domainMask,
- YES);
- if ([paths count] == 0)
- {
- if (errorOut)
- {
- NSDictionary *userInfo =
- [NSDictionary dictionaryWithObjectsAndKeys:
- NSLocalizedStringFromTable(
- @"No path found for directory in domain.",
- @"Errors",
- nil),
- NSLocalizedDescriptionKey,
- [NSNumber numberWithInteger:searchPathDirectory],
- @"NSSearchPathDirectory",
- [NSNumber numberWithInteger:domainMask],
- @"NSSearchPathDomainMask",
- nil];
- *errorOut =
- [NSError
- errorWithDomain:DirectoryLocationDomain
- code:DirectoryLocationErrorNoPathFound
- userInfo:userInfo];
- }
- return nil;
- }
-
- //
- // Normally only need the first path returned
- //
- NSString *resolvedPath = [paths objectAtIndex:0];
-
- //
- // Append the extra path component
- //
- if (appendComponent)
- {
- resolvedPath = [resolvedPath
- stringByAppendingPathComponent:appendComponent];
- }
-
- //
- // Create the path if it doesn't exist
- //
- NSError *error = nil;
-#if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_4
- BOOL success = [self
- createDirectoryAtPath:resolvedPath
- withIntermediateDirectories:YES
- attributes:nil
- error:&error];
-#else
- BOOL success = [self
- createDirectoryAtPath:resolvedPath
- attributes:nil];
-#endif
- if (!success)
- {
- if (errorOut)
- {
- *errorOut = error;
- }
- return nil;
- }
-
- //
- // If we've made it this far, we have a success
- //
- if (errorOut)
- {
- *errorOut = nil;
- }
- return resolvedPath;
-}
-
-//
-// applicationSupportDirectory
-//
-// Returns the path to the applicationSupportDirectory (creating it if it doesn't
-// exist).
-//
-- (NSString *)applicationSupportDirectory
-{
- NSString *executableName =
- [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleExecutable"];
- NSError *error;
- NSString *result =
- [self
- findOrCreateDirectory:NSApplicationSupportDirectory
- inDomain:NSUserDomainMask
- appendPathComponent:executableName
- error:&error];
- if (!result)
- {
- NSLog(@"Unable to find or create application support directory:\n%@", error);
- }
- return result;
-}
-
-@end