-
Notifications
You must be signed in to change notification settings - Fork 1
/
EXBTheme.m
59 lines (44 loc) · 1.47 KB
/
EXBTheme.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
#include "EXBTheme.h"
@implementation EXBTheme
+ (EXBTheme *)themeWithDirectoryName:(NSString *)name {
return [EXBTheme themeWithPath:[EXBThemesDirectory stringByAppendingPathComponent:name]];
}
+ (EXBTheme *)themeWithPath:(NSString*)path {
return [[EXBTheme alloc] initWithPath:path];
}
- (UIImage *)getImage:(NSString *)filename {
return [UIImage imageWithContentsOfFile:[self getPath:filename]];
}
- (UIImage *)getPreviewImage:(BOOL)modern {
if (_previewImage) return _previewImage;
if (modern) {
_previewImage = [self getImage:@"preview_modern.png"];
if (!_previewImage) {
_previewImage = [self getImage:@"preview_modern.jpg"];
}
}
if (!_previewImage) {
_previewImage = [self getImage:@"preview.png"];
}
if (!_previewImage) {
_previewImage = [self getImage:@"preview.jpg"];
}
return _previewImage;
}
- (NSString *)getPath:(NSString *)filename {
return [self.path stringByAppendingPathComponent:filename];
}
- (id)initWithPath:(NSString*)path {
BOOL isDir = NO;
BOOL exists = [[NSFileManager defaultManager] fileExistsAtPath:path isDirectory:&isDir];
if (!exists || !isDir) {
return nil;
}
if ((self = [super init])) {
self.path = path;
self.name = [[path lastPathComponent] stringByDeletingPathExtension];
self.info = [[NSDictionary alloc] initWithContentsOfFile:[self getPath:@"info.plist"]];
}
return self;
}
@end