forked from opa334/TrollStore
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTSListControllerShared.m
223 lines (190 loc) · 6.75 KB
/
TSListControllerShared.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
#import "TSListControllerShared.h"
#import "TSUtil.h"
#import "TSPresentationDelegate.h"
@implementation TSListControllerShared
- (BOOL)isTrollStore
{
return YES;
}
- (NSString*)getTrollStoreVersion
{
if([self isTrollStore])
{
return [NSBundle.mainBundle objectForInfoDictionaryKey:@"CFBundleVersion"];
}
else
{
NSString* trollStorePath = trollStoreAppPath();
if(!trollStorePath) return nil;
NSBundle* trollStoreBundle = [NSBundle bundleWithPath:trollStorePath];
return [trollStoreBundle objectForInfoDictionaryKey:@"CFBundleVersion"];
}
}
- (void)downloadTrollStoreAndDo:(void (^)(NSString* localTrollStoreTarPath))doHandler
{
NSURL* trollStoreURL = [NSURL URLWithString:@"https://github.com/opa334/TrollStore/releases/latest/download/TrollStore.tar"];
NSURLRequest* trollStoreRequest = [NSURLRequest requestWithURL:trollStoreURL];
NSURLSessionDownloadTask* downloadTask = [NSURLSession.sharedSession downloadTaskWithRequest:trollStoreRequest completionHandler:^(NSURL *location, NSURLResponse *response, NSError *error)
{
if(error)
{
UIAlertController* errorAlert = [UIAlertController alertControllerWithTitle:@"Error" message:[NSString stringWithFormat:@"Error downloading TrollStore: %@", error] preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* closeAction = [UIAlertAction actionWithTitle:@"Close" style:UIAlertActionStyleDefault handler:nil];
[errorAlert addAction:closeAction];
dispatch_async(dispatch_get_main_queue(), ^
{
[TSPresentationDelegate stopActivityWithCompletion:^
{
[TSPresentationDelegate presentViewController:errorAlert animated:YES completion:nil];
}];
});
}
else
{
NSString* tarTmpPath = [NSTemporaryDirectory() stringByAppendingPathComponent:@"TrollStore.tar"];
[[NSFileManager defaultManager] removeItemAtPath:tarTmpPath error:nil];
[[NSFileManager defaultManager] copyItemAtPath:location.path toPath:tarTmpPath error:nil];
doHandler(tarTmpPath);
}
}];
[downloadTask resume];
}
- (void)_updateOrInstallTrollStore:(BOOL)update
{
if(update)
{
[TSPresentationDelegate startActivity:@"Updating TrollStore"];
}
else
{
[TSPresentationDelegate startActivity:@"Installing TrollStore"];
}
[self downloadTrollStoreAndDo:^(NSString* tmpTarPath)
{
int ret = spawnRoot(rootHelperPath(), @[@"install-trollstore", tmpTarPath], nil, nil);
[[NSFileManager defaultManager] removeItemAtPath:tmpTarPath error:nil];
if(ret == 0)
{
respring();
if([self isTrollStore])
{
exit(0);
}
else
{
dispatch_async(dispatch_get_main_queue(), ^
{
[TSPresentationDelegate stopActivityWithCompletion:^
{
[self reloadSpecifiers];
}];
});
}
}
else
{
dispatch_async(dispatch_get_main_queue(), ^
{
[TSPresentationDelegate stopActivityWithCompletion:^
{
UIAlertController* errorAlert = [UIAlertController alertControllerWithTitle:@"Error" message:[NSString stringWithFormat:@"Error installing TrollStore: trollstorehelper returned %d", ret] preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* closeAction = [UIAlertAction actionWithTitle:@"Close" style:UIAlertActionStyleDefault handler:nil];
[errorAlert addAction:closeAction];
[TSPresentationDelegate presentViewController:errorAlert animated:YES completion:nil];
}];
});
}
}];
}
- (void)installTrollStorePressed
{
[self _updateOrInstallTrollStore:NO];
}
- (void)updateTrollStorePressed
{
[self _updateOrInstallTrollStore:YES];
}
- (void)rebuildIconCachePressed
{
[TSPresentationDelegate startActivity:@"Rebuilding Icon Cache"];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^
{
spawnRoot(rootHelperPath(), @[@"refresh-all"], nil, nil);
dispatch_async(dispatch_get_main_queue(), ^
{
[TSPresentationDelegate stopActivityWithCompletion:nil];
});
});
}
- (void)refreshAppRegistrationsPressed
{
[TSPresentationDelegate startActivity:@"Refreshing"];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^
{
spawnRoot(rootHelperPath(), @[@"refresh"], nil, nil);
respring();
dispatch_async(dispatch_get_main_queue(), ^
{
[TSPresentationDelegate stopActivityWithCompletion:nil];
});
});
}
- (void)uninstallPersistenceHelperPressed
{
if([self isTrollStore])
{
spawnRoot(rootHelperPath(), @[@"uninstall-persistence-helper"], nil, nil);
[self reloadSpecifiers];
}
else
{
UIAlertController* uninstallWarningAlert = [UIAlertController alertControllerWithTitle:@"Warning" message:@"Uninstalling the persistence helper will revert this app back to it's original state, you will however no longer be able to persistently refresh the TrollStore app registrations. Continue?" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* cancelAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil];
[uninstallWarningAlert addAction:cancelAction];
UIAlertAction* continueAction = [UIAlertAction actionWithTitle:@"Continue" style:UIAlertActionStyleDestructive handler:^(UIAlertAction* action)
{
spawnRoot(rootHelperPath(), @[@"uninstall-persistence-helper"], nil, nil);
exit(0);
}];
[uninstallWarningAlert addAction:continueAction];
[TSPresentationDelegate presentViewController:uninstallWarningAlert animated:YES completion:nil];
}
}
- (void)handleUninstallation
{
if([self isTrollStore])
{
exit(0);
}
else
{
[self reloadSpecifiers];
}
}
- (NSMutableArray*)argsForUninstallingTrollStore
{
return @[@"uninstall-trollstore"].mutableCopy;
}
- (void)uninstallTrollStorePressed
{
UIAlertController* uninstallAlert = [UIAlertController alertControllerWithTitle:@"Uninstall" message:@"You are about to uninstall TrollStore, do you want to preserve the apps installed by it?" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* uninstallAllAction = [UIAlertAction actionWithTitle:@"Uninstall TrollStore, Uninstall Apps" style:UIAlertActionStyleDestructive handler:^(UIAlertAction* action)
{
NSMutableArray* args = [self argsForUninstallingTrollStore];
spawnRoot(rootHelperPath(), args, nil, nil);
[self handleUninstallation];
}];
[uninstallAlert addAction:uninstallAllAction];
UIAlertAction* preserveAppsAction = [UIAlertAction actionWithTitle:@"Uninstall TrollStore, Preserve Apps" style:UIAlertActionStyleDestructive handler:^(UIAlertAction* action)
{
NSMutableArray* args = [self argsForUninstallingTrollStore];
[args addObject:@"preserve-apps"];
spawnRoot(rootHelperPath(), args, nil, nil);
[self handleUninstallation];
}];
[uninstallAlert addAction:preserveAppsAction];
UIAlertAction* cancelAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil];
[uninstallAlert addAction:cancelAction];
[TSPresentationDelegate presentViewController:uninstallAlert animated:YES completion:nil];
}
@end