blob: 3b81738f802edd32611ed2e5d389d5acba0ef216 (
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
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
|
/* SwordCommentary.mm - Sword API wrapper for Commentaries.
Copyright 2008 Manfred Bergmann
Based on code by Will Thimbleby
This program is free software; you can redistribute it and/or modify it under the terms of the
GNU General Public License as published by the Free Software Foundation version 2.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details. (http://www.gnu.org/licenses/gpl.html)
*/
#import "SwordCommentary.h"
@implementation SwordCommentary
/**
creates a new empty editable commentary module
caller has to make sure the module doesn't exist yet
@return path of the created module
*/
+ (NSString *)createCommentaryWithName:(NSString *)aName {
NSString *ret = nil;
// let's create the directory for storing our module
NSFileManager *fm = [NSFileManager defaultManager];
// modulePath
NSString *modPath = [[[Configuration config] defaultModulePath] stringByAppendingFormat:@"/%@.swd", aName];
if([fm fileExistsAtPath:modPath]) {
ALog(@"path exists already for mod: %@", aName);
} else {
ret = modPath;
// create folder
[fm createDirectoryAtPath:modPath withIntermediateDirectories:NO attributes:nil error:NULL];
// create mods.d folder
NSString *modsdPath = [modPath stringByAppendingPathComponent:@"mods.d"];
[fm createDirectoryAtPath:modsdPath withIntermediateDirectories:NO attributes:nil error:NULL];
// create module folder
NSString *dataPath = [modPath stringByAppendingPathComponent:@"modules"];
[fm createDirectoryAtPath:dataPath withIntermediateDirectories:NO attributes:nil error:NULL];
dataPath = [dataPath stringByAppendingPathComponent:@"comments"];
[fm createDirectoryAtPath:dataPath withIntermediateDirectories:NO attributes:nil error:NULL];
dataPath = [dataPath stringByAppendingPathComponent:@"rawfiles"];
[fm createDirectoryAtPath:dataPath withIntermediateDirectories:NO attributes:nil error:NULL];
dataPath = [dataPath stringByAppendingPathComponent:aName];
[fm createDirectoryAtPath:dataPath withIntermediateDirectories:NO attributes:nil error:NULL];
// let's create a brand new empty module
sword::RawFiles::createModule([dataPath UTF8String]);
// let's add our .conf file
sword::SWConfig newConf([[modsdPath stringByAppendingFormat:@"/%@.conf", aName] UTF8String]);
const char *aNameCStr = [aName UTF8String];
newConf[aNameCStr]["DataPath"] = [[NSString stringWithFormat:@"./modules/comments/rawfiles/%@", aName] UTF8String];
newConf[aNameCStr]["ModDrv"] = "RawFiles";
newConf[aNameCStr]["SourceType"] = "ThML";
newConf[aNameCStr]["Editable"] = "YES";
newConf[aNameCStr]["About"] = "This module allows you to store your own commentary.";
newConf.Save();
}
return ret;
}
- (id)init {
return [super init];
}
- (void)finalize {
[super finalize];
}
- (void)dealloc {
[super dealloc];
}
@end
|