-
Notifications
You must be signed in to change notification settings - Fork 0
/
Application.m
125 lines (84 loc) · 2.69 KB
/
Application.m
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
//
// Application.m
//
// Licensed by ruralcoder.com under the
// Creative Commons Attribution-ShareAlike 3.0 Unported License
#import "Application.h"
@implementation Application
+ (NSOperationQueue*)operationQueue
{
static NSOperationQueue* sOperationQueue = nil;
@synchronized(self)
{
if (sOperationQueue)
return sOperationQueue;
sOperationQueue = [[NSOperationQueue alloc] init];
return sOperationQueue;
}
}
+ (NSNotificationCenter*) notificationCenter
{
static NSNotificationCenter* sCenter = nil;
@synchronized(self)
{
if (sCenter)
return sCenter;
sCenter = [[NSNotificationCenter alloc] init];
return sCenter;
}
}
+ (NSString*) documentsFolder
{
return [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
}
+ (NSString*) cacheFolder
{
return [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) objectAtIndex:0];
}
+ (id) fileInCache:(id)filename
{
NSString *cachesPath = [Application cacheFolder];
return [cachesPath stringByAppendingPathComponent:filename];
}
+ (id) fileInBundle:(id)filename
{
return [[NSBundle mainBundle] pathForResource:filename ofType:nil];
}
+ (NSURL*) urlInCache:(NSString*)filename
{
return [NSURL fileURLWithPath:[Application fileInCache:filename]];
}
+ (id) fileInDocuments:(id)filename
{
NSString *documentsPath = [Application documentsFolder];
return [documentsPath stringByAppendingPathComponent:filename];
}
+ (NSURL*) urlInDocuments:(NSString*)filename
{
return [NSURL fileURLWithPath:[Application fileInDocuments:filename]];
}
+ (NSString*)version
{
id versionValue = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"];
return [NSString stringWithFormat:@"version: %@", versionValue];
}
+ (NSString*)versionClean
{
id buildValue = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"];
return [NSString stringWithFormat:@"%@", buildValue];
}
+ (void) registerDefaultValues
{
id absoluteFilename = [Application fileInBundle:@"Defaults.plist"];;
NSDictionary *defaultValues = [NSDictionary dictionaryWithContentsOfFile:absoluteFilename];
NSAssert(defaultValues != nil, @"Error: Missing file from bundle 'Defaults.plist'");
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
[userDefaults registerDefaults:defaultValues];
BOOL saved = [userDefaults synchronize];
if (saved == NO)
{
NSLog(@"Error: Unable to synchronize the user default settings");
exit(-1);
}
}
@end