aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--On Task.m11
-rw-r--r--On Task.xcodeproj/project.pbxproj8
-rw-r--r--vendor/NSFileManager+DirectoryLocations.h36
-rw-r--r--vendor/NSFileManager+DirectoryLocations.m161
4 files changed, 213 insertions, 3 deletions
diff --git a/On Task.m b/On Task.m
index 08675eb..412ce68 100644
--- a/On Task.m
+++ b/On Task.m
@@ -1,10 +1,15 @@
#import <Foundation/Foundation.h>
+#import "NSFileManager+DirectoryLocations.h"
+
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
-
- // insert code here...
- NSLog(@"Hello, World!");
+
+ NSString *supportPath = [[NSFileManager defaultManager] applicationSupportDirectory];
+
+ // Take screenshot
+ NSLog(@"%@", supportPath);
+
[pool release];
return 0;
}
diff --git a/On Task.xcodeproj/project.pbxproj b/On Task.xcodeproj/project.pbxproj
index d3bf789..2bc3550 100644
--- a/On Task.xcodeproj/project.pbxproj
+++ b/On Task.xcodeproj/project.pbxproj
@@ -10,6 +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 */; };
/* End PBXBuildFile section */
/* Begin PBXCopyFilesBuildPhase section */
@@ -20,6 +22,7 @@
dstSubfolderSpec = 0;
files = (
8DD76F9F0486AA7600D96B5E /* On Task.1 in CopyFiles */,
+ D195B56D15BA4E46005D8C2E /* NSFileManager+DirectoryLocations.h in CopyFiles */,
);
runOnlyForDeploymentPostprocessing = 1;
};
@@ -31,6 +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>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@@ -59,6 +64,8 @@
08FB7795FE84155DC02AAC07 /* Source */ = {
isa = PBXGroup;
children = (
+ D195B56B15BA4E46005D8C2E /* NSFileManager+DirectoryLocations.h */,
+ D195B56C15BA4E46005D8C2E /* NSFileManager+DirectoryLocations.m */,
32A70AAB03705E1F00C91783 /* On Task_Prefix.pch */,
08FB7796FE84155DC02AAC07 /* On Task.m */,
);
@@ -131,6 +138,7 @@
buildActionMask = 2147483647;
files = (
8DD76F9A0486AA7600D96B5E /* On Task.m in Sources */,
+ D195B56E15BA4E46005D8C2E /* NSFileManager+DirectoryLocations.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
diff --git a/vendor/NSFileManager+DirectoryLocations.h b/vendor/NSFileManager+DirectoryLocations.h
new file mode 100644
index 0000000..2ffd42a
--- /dev/null
+++ b/vendor/NSFileManager+DirectoryLocations.h
@@ -0,0 +1,36 @@
+//
+// 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
new file mode 100644
index 0000000..a21f021
--- /dev/null
+++ b/vendor/NSFileManager+DirectoryLocations.m
@@ -0,0 +1,161 @@
+//
+// 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