-
Notifications
You must be signed in to change notification settings - Fork 1
/
ApplicationSupport.m
80 lines (70 loc) · 2.6 KB
/
ApplicationSupport.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
//
// ApplicationSupport.m
// Add Folder Icons
//
// Created by Andrew Hodgkinson on 03/02/2011.
// Copyright 2011 Hipposoft. All rights reserved.
//
#import "ApplicationSupport.h"
@implementation ApplicationSupport
/******************************************************************************\
* -applicationSupportDirectory
*
* Return the path to the Application Support subdirectory for the current user
* identified by the name defined in 'APPLICATION_SUPPORT_DIRECTORY_FILENAME',
* or the user's temporary directory if no application support directory can be
* located.
*
* Out: ( NSString * )
* Full POSIX path of the support directory.
\******************************************************************************/
+ ( NSString * ) applicationSupportDirectory
{
return
[ self applicationSupportDirectoriesFor: APPLICATION_SUPPORT_DIRECTORY_FILENAME ][ 0 ];
}
/******************************************************************************\
* -applicationSupportDirectoriesFor:
*
* Distantly derived from boilerplate Core Data material generated by Interface
* Builder 3.2.5.
*
* Returns an array of support directories with the given leafname, based on
* the user's domain only to ensure that the content can be both read from and
* written to without requiring privilege escalation. If no appropriate
* directory or directories can be located, the user's temporary directory is
* returned instead and the given name is ignored.
*
* The user's support directory
*
* In: ( NSString * ) name
* Name of the subdirectory of interest.
*
* Out: ( NSString * )
* Full POSIX path of the named Application Support subdirectory, or the
* user's temporary directory.
\******************************************************************************/
+ ( NSMutableArray * ) applicationSupportDirectoriesFor: ( NSString * ) name
{
NSMutableArray * appPaths;
NSArray * supportPaths = NSSearchPathForDirectoriesInDomains
(
NSApplicationSupportDirectory,
NSUserDomainMask,
YES
);
if ( [ supportPaths count ] > 0 )
{
appPaths = [ NSMutableArray arrayWithCapacity: [ supportPaths count ] ];
for ( NSString * path in supportPaths )
{
[ appPaths addObject: [ path stringByAppendingPathComponent: name ] ];
}
}
else
{
appPaths = [ NSMutableArray arrayWithObject: NSTemporaryDirectory() ];
}
return appPaths;
}
@end