Skip to content

Commit

Permalink
Cleanup: remove legacy code and data migration
Browse files Browse the repository at this point in the history
  • Loading branch information
khanhduytran0 committed Jul 15, 2024
1 parent 4cf5906 commit 958a668
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 76 deletions.
5 changes: 2 additions & 3 deletions JavaApp/src/main/java/net/kdt/pojavlaunch/PojavLauncher.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,8 @@ public static void main(String[] args) throws Throwable {
Thread.currentThread().setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {

public void uncaughtException(Thread t, Throwable th) {
Tools.showError(th);
// Block this thread from exiting
while (true) {}
th.printStackTrace();
System.exit(1);
}
});

Expand Down
19 changes: 1 addition & 18 deletions JavaApp/src/main/java/net/kdt/pojavlaunch/Tools.java
Original file line number Diff line number Diff line change
Expand Up @@ -225,24 +225,7 @@ public static String generateLaunchClassPath(JMinecraftVersionList.Version info)

return libStr.toString();
}

public static void showError(Throwable e) {
showError(e, false);
}

public static void showError(final Throwable e, final boolean exitIfOk) {
showError("Error", e, exitIfOk, false);
}

public static void showError(final String title, final Throwable e, final boolean exitIfOk) {
showError(title, e, exitIfOk, false);
}

private static void showError(final String title, final Throwable e, final boolean exitIfOk, final boolean showMore) {
e.printStackTrace();
System.exit(1);
}


public static void moveInside(String from, String to) {
File fromFile = new File(from);
for (File fromInside : fromFile.listFiles()) {
Expand Down
6 changes: 2 additions & 4 deletions Natives/LauncherNavigationController.m
Original file line number Diff line number Diff line change
Expand Up @@ -372,10 +372,8 @@ - (void)invokeAfterJITEnabled:(void(^)(void))handler {
BOOL hasTrollStoreJIT = getEntitlementValue(@"com.apple.private.local.sandboxed-jit");

if (isJITEnabled(false)) {
dispatch_async(dispatch_get_main_queue(), ^{
[ALTServerManager.sharedManager stopDiscovering];
handler();
});
[ALTServerManager.sharedManager stopDiscovering];
handler();
return;
} else if (hasTrollStoreJIT) {
NSURL *jitURL = [NSURL URLWithString:[NSString stringWithFormat:@"apple-magnifier://enable-jit?bundle-id=%@", NSBundle.mainBundle.bundleIdentifier]];
Expand Down
55 changes: 10 additions & 45 deletions Natives/main.m
Original file line number Diff line number Diff line change
Expand Up @@ -127,41 +127,6 @@ void init_logDeviceAndVer(char *argument) {
//printEntitlementAvailability(@"dynamic-codesigning");
}

void init_migrateDirIfNecessary() {
NSString *oldDir = @"/usr/share/pojavlauncher";
if ([fm fileExistsAtPath:oldDir]) {
NSString *newDir = @"";
if ([@(getenv("HOME")) isEqualToString:@"/var/mobile"]) {
newDir = [NSString stringWithFormat:@"%s/Documents/PojavLauncher", getenv("HOME")];
} else {
newDir = [NSString stringWithFormat:@"%s/Documents", getenv("HOME")];
}
[fm moveItemAtPath:oldDir toPath:newDir error:nil];
[fm removeItemAtPath:oldDir error:nil];
}
}

void init_migrateToPlist(char* prefKey, char* filename) {
NSError *error;
NSString *path_str = [NSString stringWithFormat:@"%s/%s", getenv("POJAV_HOME"), filename];
NSDebugLog(@"[Pre-Init] Beginning migration for file \"%s\"", filename);
NSString *str = [NSString stringWithContentsOfFile:path_str encoding:NSUTF8StringEncoding error:&error];
if (error == nil && ![str hasPrefix:@"#README"]) {
NSString *finalized = @"";
for (NSString *line in [str componentsSeparatedByCharactersInSet:NSCharacterSet.whitespaceAndNewlineCharacterSet]) {
if (![line hasPrefix:@"#"]) {
finalized = [finalized stringByAppendingString:[NSString stringWithFormat:@"%@ ", line]];
}
}

setPrefObject(@(prefKey), finalized);
[@"#README - this file has been merged into launcher_preferences.plist" writeToFile:path_str atomically:YES encoding:NSUTF8StringEncoding error:nil];
NSLog(@"[Pre-Init] File \"%s\" has been migrated", filename);
} else {
NSDebugLog(@"[Pre-Init] File \"%s\" was already migrated", filename);
}
}

void init_redirectStdio() {
NSLog(@"[Pre-init] Starting logging STDIO to latestlog.txt\n");

Expand Down Expand Up @@ -246,16 +211,20 @@ void init_setupMultiDir() {
}

const char *home = getenv("POJAV_HOME");
NSString *jvmPath = [NSString stringWithFormat:@"%s/java_runtimes", home];
NSString *lasmPath = [NSString stringWithFormat:@"%s/Library/Application Support/minecraft", home];
NSString *multidirPath = [NSString stringWithFormat:@"%s/instances/%@", home, multidir];
NSString *demoPath = [NSString stringWithFormat:@"%s/.demo", home];

[fm createDirectoryAtPath:jvmPath withIntermediateDirectories:YES attributes:nil error:nil];
[fm createDirectoryAtPath:demoPath withIntermediateDirectories:YES attributes:nil error:nil];
[fm createDirectoryAtPath:multidirPath withIntermediateDirectories:YES attributes:nil error:nil];

NSArray *dirsToCreate = @[
[NSString stringWithFormat:@"%s/.demo", home],
[NSString stringWithFormat:@"%s/java_runtimes", home],
lasmPath.stringByDeletingLastPathComponent,
multidirPath
];
for (NSString *dir in dirsToCreate) {
[fm createDirectoryAtPath:dir withIntermediateDirectories:YES attributes:nil error:nil];
}
[fm removeItemAtPath:lasmPath error:nil];
[fm createDirectoryAtPath:lasmPath.stringByDeletingLastPathComponent withIntermediateDirectories:YES attributes:nil error:nil];
[fm createSymbolicLinkAtPath:lasmPath withDestinationPath:multidirPath error:nil];
[fm changeCurrentDirectoryPath:lasmPath];
setenv("POJAV_GAME_DIR", lasmPath.UTF8String, 1);
Expand Down Expand Up @@ -318,7 +287,6 @@ int main(int argc, char *argv[]) {

setenv("BUNDLE_PATH", dirname(argv[0]), 1);
isJailbroken = init_checkForJailbreak();
init_migrateDirIfNecessary();
init_setupHomeDirectory();
init_redirectStdio();
init_logDeviceAndVer(argv[0]);
Expand All @@ -337,9 +305,6 @@ int main(int argc, char *argv[]) {
init_setupAccounts();
init_setupCustomControls();

init_migrateToPlist("java.java_args", "overrideargs.txt");
init_migrateToPlist("java.env_variables", "custom_env.txt");

// If sandbox is disabled, W^X JIT can be enabled by PojavLauncher itself
if (!isJITEnabled(true) && getEntitlementValue(@"com.apple.private.security.no-sandbox")) {
NSLog(@"[Pre-init] no-sandbox: YES, trying to enable JIT");
Expand Down
6 changes: 0 additions & 6 deletions Natives/main_hook.m
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,6 @@ void hooked_exit(int code) {
}
handle_fatal_exit(code);

/*
if (runtimeJavaVMPtr != NULL) {
(*runtimeJavaVMPtr)->DestroyJavaVM(runtimeJavaVMPtr);
}
*/

orig_exit(code);
}

Expand Down

0 comments on commit 958a668

Please sign in to comment.