Skip to content

Commit

Permalink
fix: Read dpks source file (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
clburlison authored Apr 9, 2023
1 parent b591b27 commit ad38a93
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 77 deletions.
2 changes: 1 addition & 1 deletion src/DEBIAN/control
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ Name: dmon
Package: com.github.clburlison.dmon
Section: Tweaks
Tag: purpose::extension, role::enduser
Version: 0.0.8
Version: 0.0.9
1 change: 1 addition & 0 deletions src/DEBIAN/postinst
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/bash

/usr/bin/rm /usr/bin/dmon_old 2>/dev/null
/usr/bin/launchctl unload /Library/LaunchDaemons/com.github.clburlison.dmon.plist 2>/dev/null
/usr/bin/sleep 2
/usr/bin/launchctl load /Library/LaunchDaemons/com.github.clburlison.dmon.plist
Binary file modified src/usr/bin/dmon
Binary file not shown.
45 changes: 0 additions & 45 deletions src/usr/bin/dmon_old

This file was deleted.

87 changes: 56 additions & 31 deletions tools/dmon.m
Original file line number Diff line number Diff line change
Expand Up @@ -42,30 +42,42 @@ - (id)applicationsOfType:(unsigned int)arg1;
return (frontmostApp);
}

NSString *getAptList(NSString *packageName) {
FILE *fp;
char path[1035];
NSString *command = [NSString stringWithFormat:@"dpkg-query --showformat='${Version}' --show %@ 2>/dev/null", packageName];
NSString *version = nil;

// Open the command for reading
fp = popen([command UTF8String], "r");
if (fp == NULL) {
NSLog(@"dmon: Failed to run command.");
return nil;
}
NSDictionary *getAptList(NSString *packageName) {
NSDictionary *result = [NSDictionary dictionary];
NSString *dpkStatusFile = @"/var/lib/dpkg/status";
NSFileHandle *fileHandle = [NSFileHandle fileHandleForReadingAtPath:dpkStatusFile];

if (fileHandle) {
// Read the contents of the file
NSData *fileData = [fileHandle readDataToEndOfFile];
// Convert the file data to a string
NSString *fileString = [[NSString alloc] initWithData:fileData encoding:NSUTF8StringEncoding];
// Close the file handle
[fileHandle closeFile];
// Convert the file data to a dictionary
NSArray *packages = [fileString componentsSeparatedByString:@"\n\n"];

for (NSString *packageString in packages) {
NSMutableDictionary *packageDict = [NSMutableDictionary dictionary];
NSArray *packageLines = [packageString componentsSeparatedByString:@"\n"];

for (NSString *line in packageLines) {
NSArray *keyValue = [line componentsSeparatedByString:@": "];
if (keyValue.count == 2) {
packageDict[keyValue[0]] = keyValue[1];
}
}

// Read the output from the command
if (fgets(path, sizeof(path)-1, fp) != NULL) {
version = [NSString stringWithUTF8String:path];
version = [version stringByTrimmingCharactersInSet:[NSCharacterSet newlineCharacterSet]];
if ([packageDict[@"Package"] isEqualToString:packageName]) {
NSLog(@"dmon: Version of %@: %@", packageName, packageDict[@"Version"]);
return packageDict;
}
}
}

// Close the file
pclose(fp);

NSLog(@"dmon: Version of %@: %@", packageName, version);
return version;
else {
NSLog(@"dmon: Failed to open file for reading: %@", dpkStatusFile);
}
return result;
}

NSDictionary * parseConfig(void) {
Expand Down Expand Up @@ -94,7 +106,6 @@ - (id)applicationsOfType:(unsigned int)arg1;

NSMutableDictionary * parseKeyValueFileAtPath(NSString *filePath) {
NSMutableDictionary *resultDict = [NSMutableDictionary dictionary];

NSError *error = nil;
NSString *fileContents = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:&error];
if (error) {
Expand Down Expand Up @@ -227,7 +238,7 @@ void update(NSDictionary *config) {
NSString *pogo_ipa = @"pogo.ipa";
NSString *gc_deb = @"gc.deb";
NSString *pogoVersion = installedAppInfo(@"com.nianticlabs.pokemongo")[@"bundle_version"];
NSString *gcVersion = getAptList(@"com.gocheats.jb");
NSString *gcVersion = getAptList(@"com.gocheats.jb")[@"Version"];
// getAptList(@"com.github.clburlison.dmon");

// Strip trailing forward slashes to make things consistent for users
Expand Down Expand Up @@ -282,13 +293,6 @@ void monitor(void) {
killall(@"pokemongo");
sleep(5);

// Attempt to check versions and update now that Pogo & Kernbypass are not running
NSDictionary *config = parseConfig();
if (config[@"dmon_url"] != nil && [config[@"dmon_url"] isKindOfClass:[NSString class]] && ![config[@"dmon_url"] isEqualToString:@""]) {
// NSLog(@"dmon: Full config: %@", config);
update(config);
}

// Launch Pogo
NSLog(@"dmon: Pogo not running. Launch it...");
void* sbServices = dlopen("/System/Library/PrivateFrameworks/SpringBoardServices.framework/SpringBoardServices", RTLD_LAZY);
Expand All @@ -303,6 +307,27 @@ void monitor(void) {
int main(void) {
NSLog(@"dmon: Starting...");

// Start loop
int i = 0;
while (1) {
// Only call at the start of loop
NSDictionary *config = parseConfig();
if (i == 0 && config[@"dmon_url"] != nil && [config[@"dmon_url"] isKindOfClass:[NSString class]] && ![config[@"dmon_url"] isEqualToString:@""]) {
// NSLog(@"dmon: Full config: %@", config);
update(config);
}

// Call this function every loop
monitor();

// Restart loop on the 30th iteration
if (++i == 30) {
i = 0;
}

sleep(30);
}

// Start loop
while (1) {
monitor();
Expand Down

0 comments on commit ad38a93

Please sign in to comment.