Skip to content

Commit b591b27

Browse files
authored
feat: This version call works more consistently (#17)
1 parent b2c71d1 commit b591b27

File tree

3 files changed

+51
-42
lines changed

3 files changed

+51
-42
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ releases
77
*.dylib
88
.theos
99
local
10+
/bin/update

src/usr/bin/dmon

0 Bytes
Binary file not shown.

tools/dmon.m

Lines changed: 50 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,32 @@
44
#import <dlfcn.h>
55
#include <curl/curl.h>
66

7+
@interface LSResourceProxy : NSObject
8+
@end
9+
10+
@interface LSBundleProxy : LSResourceProxy
11+
@property (nonatomic, readonly) NSString *localizedShortName;
12+
@end
13+
14+
@interface LSApplicationProxy : LSBundleProxy
15+
@property (nonatomic, readonly) NSString *applicationType;
16+
@property (nonatomic, readonly) NSString *applicationIdentifier;
17+
@property(readonly) NSURL * dataContainerURL;
18+
@property(readonly) NSURL * bundleContainerURL;
19+
@property(readonly) NSString * localizedShortName;
20+
@property(readonly) NSString * localizedName;
21+
@end
22+
23+
@interface LSApplicationWorkspace : NSObject
24+
+ (id)defaultWorkspace;
25+
- (BOOL)installApplication:(NSURL *)path withOptions:(NSDictionary *)options;
26+
- (BOOL)uninstallApplication:(NSString *)identifier withOptions:(NSDictionary *)options;
27+
- (id)allApplications;
28+
- (id)allInstalledApplications;
29+
- (BOOL)applicationIsInstalled:(id)arg1;
30+
- (id)applicationsOfType:(unsigned int)arg1;
31+
@end
32+
733

834
NSString * getFrontMostApplication() {
935
mach_port_t p = SBSSpringBoardServerPort();
@@ -16,47 +42,6 @@
1642
return (frontmostApp);
1743
}
1844

19-
NSString * installedPogoVersion(void) {
20-
char path[1035];
21-
FILE *pogo_cmd = popen("find /var/containers/Bundle/Application/ -type d -name 'PokmonGO.app'", "r");
22-
NSString *bundlePath = nil;
23-
if (pogo_cmd == NULL) {
24-
NSLog(@"dmon: Unable to find PokemonGo on device");
25-
return nil;
26-
}
27-
28-
// Read the output from the command
29-
if (fgets(path, sizeof(path)-1, pogo_cmd) != NULL) {
30-
bundlePath = [NSString stringWithUTF8String:path];
31-
bundlePath = [bundlePath stringByTrimmingCharactersInSet:[NSCharacterSet newlineCharacterSet]];
32-
bundlePath = [bundlePath stringByAppendingPathComponent: @"Info.plist"];
33-
}
34-
35-
// Close the file
36-
pclose(pogo_cmd);
37-
38-
NSFileHandle *fileHandle = [NSFileHandle fileHandleForReadingAtPath:bundlePath];
39-
40-
if (fileHandle) {
41-
// Read the contents of the file
42-
NSData *fileData = [fileHandle readDataToEndOfFile];
43-
// Close the file handle
44-
[fileHandle closeFile];
45-
// Convert the file data to a dictionary
46-
NSDictionary *infoDict = [NSPropertyListSerialization propertyListWithData:fileData options:NSPropertyListImmutable format:NULL error:NULL];
47-
if (infoDict) {
48-
NSString *versionString = [infoDict objectForKey:@"CFBundleShortVersionString"];
49-
NSLog(@"dmon: Version of Pokemon Go: %@", versionString);
50-
return versionString;
51-
}
52-
}
53-
else {
54-
NSLog(@"dmon: Failed to open file for reading: %@", bundlePath);
55-
}
56-
57-
return nil;
58-
}
59-
6045
NSString *getAptList(NSString *packageName) {
6146
FILE *fp;
6247
char path[1035];
@@ -214,11 +199,34 @@ int downloadFile(NSString *url, NSString *userpass, NSString *outfile) {
214199
return -1;
215200
}
216201

202+
NSDictionary *installedAppInfo(NSString * bundleID) {
203+
LSApplicationWorkspace *workspace = [NSClassFromString(@"LSApplicationWorkspace") defaultWorkspace];
204+
for (LSApplicationProxy *proxy in [workspace applicationsOfType:0]) {
205+
if ([[proxy applicationIdentifier] isEqualToString: bundleID]) {
206+
NSString *bundlePath = [proxy bundleContainerURL].path;
207+
208+
// This might be a bad assumption. I only checked it with PokemonGO
209+
NSString *infoFile = [NSString stringWithFormat:@"%@.app/Info.plist", [proxy localizedShortName]];
210+
bundlePath = [bundlePath stringByAppendingPathComponent: infoFile];
211+
NSDictionary *infoDict = [[NSDictionary alloc] initWithContentsOfFile:bundlePath];
212+
NSString *versionString = [infoDict objectForKey:@"CFBundleShortVersionString"];
213+
214+
NSDictionary *dict = @{@"bundle_name" : [proxy localizedShortName],
215+
@"bundle_id" : [proxy applicationIdentifier],
216+
@"bundle_version" : versionString,
217+
@"bundle_path" : [proxy bundleContainerURL].path};
218+
NSLog(@"dmon: Version of %@: %@", bundleID, versionString);
219+
return dict;
220+
}
221+
}
222+
return nil;
223+
}
224+
217225
void update(NSDictionary *config) {
218226
NSString *versionFile = @"version.txt";
219227
NSString *pogo_ipa = @"pogo.ipa";
220228
NSString *gc_deb = @"gc.deb";
221-
NSString *pogoVersion = installedPogoVersion();
229+
NSString *pogoVersion = installedAppInfo(@"com.nianticlabs.pokemongo")[@"bundle_version"];
222230
NSString *gcVersion = getAptList(@"com.gocheats.jb");
223231
// getAptList(@"com.github.clburlison.dmon");
224232

0 commit comments

Comments
 (0)