-
Notifications
You must be signed in to change notification settings - Fork 0
/
BarDirectories.m
108 lines (62 loc) · 3.08 KB
/
BarDirectories.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
//
// BarDirectories.m
// Bartender
//
// Created by Tom Houpt on 12/9/24.
// Copyright 2012 Behavioral Cybernetics. All rights reserved.
//
#import "BarDirectories.h"
// **********************************************************************
// DIRECTORY UTILITIES --------------------------------------------------------------
// returns the directory path to the standard directories
// side effect: creates the directory if it doesn't exist already
#define BartenderDataDirectoryName @"Bartender Data"
BOOL CreateDirectoryAtPath(NSString *directoryPath) {
NSError *fileManagerError;
BOOL createFlag;
NSFileManager *defaultFileManager = [ NSFileManager defaultManager];
createFlag = [defaultFileManager
createDirectoryAtPath:directoryPath
withIntermediateDirectories:YES
attributes:nil
error:&fileManagerError]; //returns YES on success
return createFlag;
}
NSString *GetDocDirectoryPath(void) {
NSString *docDirectoryPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex: 0];
if (CreateDirectoryAtPath(docDirectoryPath) ) { return docDirectoryPath; }
return nil;
}
NSString *GetExptDirectoryPath(void) {
// set to the template directory
// check if the appropriate directories exist, create them if they don't exist
NSString *docDirectoryPath = GetDocDirectoryPath();
NSString *exptDirectoryPath = [[docDirectoryPath stringByAppendingPathComponent:BartenderDataDirectoryName] stringByAppendingPathComponent:@"Experiments"];
if (CreateDirectoryAtPath(exptDirectoryPath) ) { return exptDirectoryPath; }
return nil;
}
NSString *GetArchiveDirectoryPath(NSString *code) {
// set to the template directory
// check if the appropriate directories exist, create them if they don't exist
NSString *docDirectoryPath = GetDocDirectoryPath();
NSString *exptArchiveName = [NSString stringWithFormat:@"%@/Archives/%@",BartenderDataDirectoryName,code];
NSString *archiveDirectoryPath = [docDirectoryPath stringByAppendingPathComponent:exptArchiveName];
if (CreateDirectoryAtPath(archiveDirectoryPath) ) { return archiveDirectoryPath; }
return nil;
}
NSString *GetDailyDataDirectoryPath(void) {
// set to the template directory
// check if the appropriate directories exist, create them if they don't exist
NSString *docDirectoryPath = GetDocDirectoryPath();
NSString *dailyDataDirectoryPath = [[docDirectoryPath stringByAppendingPathComponent:BartenderDataDirectoryName] stringByAppendingPathComponent:@"DailyData"];
if (CreateDirectoryAtPath(dailyDataDirectoryPath) ) { return dailyDataDirectoryPath; }
return nil;
}
NSString *GetTemplateDirectoryPath(void) {
// set to the template directory
// check if the appropriate directories exist, create them if they don't exist
NSString *docDirectoryPath = GetDocDirectoryPath();
NSString *templateDirectoryPath = [[docDirectoryPath stringByAppendingPathComponent:BartenderDataDirectoryName] stringByAppendingPathComponent:@"Templates"];
if (CreateDirectoryAtPath(templateDirectoryPath) ) { return templateDirectoryPath; }
return nil;
}