aboutsummaryrefslogtreecommitdiffstats
path: root/Classes/NSFileManager+DirectoryLocations.m
blob: 9d0363abb76c546e15e36b11b228559af6b1dfb8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#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();
	NSString *applicationSupportPath = [basePath stringByAppendingPathComponent:@"On Task"];
	
	if (![[NSFileManager defaultManager] fileExistsAtPath:applicationSupportPath]) {
		if (![[NSFileManager defaultManager] createDirectoryAtPath:applicationSupportPath attributes:nil]) {
			NSLog(@"Error: Could not create folder %@", applicationSupportPath);
		}
	}
	
    return applicationSupportPath;
}

@end