forked from khanhduytran0/LiveContainer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AppInfo.m
70 lines (60 loc) · 1.71 KB
/
AppInfo.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
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import "AppInfo.h"
@implementation AppInfo
- (instancetype)initWithBundlePath:(NSString*)bundlePath {
self = [super init];
if(self) {
_bundlePath = bundlePath;
_info = [NSMutableDictionary dictionaryWithContentsOfFile:[NSString stringWithFormat:@"%@/Info.plist", bundlePath]];
}
return self;
}
- (NSString*)displayName {
if (_info[@"CFBundleDisplayName"]) {
return _info[@"CFBundleDisplayName"];
} else if (_info[@"CFBundleName"]) {
return _info[@"CFBundleName"];
} else if (_info[@"CFBundleExecutable"]) {
return _info[@"CFBundleExecutable"];
} else {
return nil;
}
}
- (NSString*)version {
NSString* version = _info[@"CFBundleShortVersionString"];
if (!version) {
version = _info[@"CFBundleVersion"];
}
return version;
}
- (NSString*)bundleIdentifier {
return _info[@"CFBundleIdentifier"];
}
- (NSString*)dataUUID {
if (!_info[@"LCDataUUID"]) {
self.dataUUID = NSUUID.UUID.UUIDString;
}
return _info[@"LCDataUUID"];
}
- (void)setDataUUID:(NSString *)uuid {
_info[@"LCDataUUID"] = uuid;
[self save];
}
- (NSString*)bundlePath {
return _bundlePath;
}
- (NSMutableDictionary*)info {
return _info;
}
- (UIImage*)icon {
UIImage* icon = [UIImage imageNamed:[_info valueForKeyPath:@"CFBundleIcons.CFBundlePrimaryIcon.CFBundleIconFiles"][0] inBundle:[[NSBundle alloc] initWithPath: _bundlePath] compatibleWithTraitCollection:nil];
if(!icon) {
icon = [UIImage imageNamed:@"DefaultIcon"];
}
return icon;
}
- (void)save {
[_info writeToFile:[NSString stringWithFormat:@"%@/Info.plist", _bundlePath] atomically:YES];
}
@end