diff --git a/app_pojavlauncher/src/main/assets/components/forge_installer/forge_installer.jar b/app_pojavlauncher/src/main/assets/components/forge_installer/forge_installer.jar index c9475cb38..c9c5045a2 100644 Binary files a/app_pojavlauncher/src/main/assets/components/forge_installer/forge_installer.jar and b/app_pojavlauncher/src/main/assets/components/forge_installer/forge_installer.jar differ diff --git a/app_pojavlauncher/src/main/assets/components/forge_installer/version b/app_pojavlauncher/src/main/assets/components/forge_installer/version index e650fdcf5..b8f0d6121 100644 --- a/app_pojavlauncher/src/main/assets/components/forge_installer/version +++ b/app_pojavlauncher/src/main/assets/components/forge_installer/version @@ -1 +1 @@ -1687971356220 \ No newline at end of file +1688118307460 \ No newline at end of file diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/fragments/OptiFineInstallFragment.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/fragments/OptiFineInstallFragment.java index 5718c5623..a37704618 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/fragments/OptiFineInstallFragment.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/fragments/OptiFineInstallFragment.java @@ -1,9 +1,11 @@ package net.kdt.pojavlaunch.fragments; import android.content.Context; +import android.content.Intent; import android.view.LayoutInflater; import android.widget.ExpandableListAdapter; +import net.kdt.pojavlaunch.JavaGUILauncherActivity; import net.kdt.pojavlaunch.R; import net.kdt.pojavlaunch.Tools; import net.kdt.pojavlaunch.modloaders.ModloaderListenerProxy; @@ -55,6 +57,8 @@ public class OptiFineInstallFragment extends ModVersionListFragment minecraftVersions; public List> optifineVersions; } public static class OptiFineVersion { + public String minecraftVersion; public String versionName; public String downloadUrl; } diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/tasks/AsyncMinecraftDownloader.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/tasks/AsyncMinecraftDownloader.java index b04c54055..74112fefd 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/tasks/AsyncMinecraftDownloader.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/tasks/AsyncMinecraftDownloader.java @@ -46,7 +46,7 @@ public class AsyncMinecraftDownloader { /* Allows each downloading thread to have its own RECYCLED buffer */ private final ConcurrentHashMap mThreadBuffers = new ConcurrentHashMap<>(5); - public AsyncMinecraftDownloader(@NonNull Activity activity, JMinecraftVersionList.Version version, String realVersion, + public AsyncMinecraftDownloader(Activity activity, JMinecraftVersionList.Version version, String realVersion, @NonNull DoneListener listener){ // this was there for a reason sExecutorService.execute(() -> { try { @@ -58,7 +58,7 @@ public class AsyncMinecraftDownloader { }); } /* we do the throws DownloaderException thing to avoid blanket-catching Exception as a form of anti-lazy-developer protection */ - private void downloadGame(@NonNull Activity activity, JMinecraftVersionList.Version verInfo, String versionName) throws DownloaderException { + private void downloadGame(Activity activity, JMinecraftVersionList.Version verInfo, String versionName) throws DownloaderException { final String downVName = "/" + versionName + "/" + versionName; //Downloading libraries @@ -88,7 +88,7 @@ public class AsyncMinecraftDownloader { verInfo = Tools.getVersionInfo(versionName); // THIS one function need the activity in the case of an error - if(!JRE17Util.installNewJreIfNeeded(activity, verInfo)){ + if(activity != null && !JRE17Util.installNewJreIfNeeded(activity, verInfo)){ ProgressKeeper.submitProgress(ProgressLayout.DOWNLOAD_MINECRAFT, -1, -1); throw new DownloaderException(); } diff --git a/app_pojavlauncher/src/main/res/values/strings.xml b/app_pojavlauncher/src/main/res/values/strings.xml index da26fa683..5f75caf87 100644 --- a/app_pojavlauncher/src/main/res/values/strings.xml +++ b/app_pojavlauncher/src/main/res/values/strings.xml @@ -392,7 +392,7 @@ Modded versions Select versions Select OptiFine version - Failed to get the OptiFine download link + Failed to collect data for OptiFine installation Downloading %s Create OptiFine profile diff --git a/forge_installer/src/main/java/git/artdeell/forgeinstaller/Agent.java b/forge_installer/src/main/java/git/artdeell/forgeinstaller/Agent.java index a9272cbd6..cc2d82d63 100644 --- a/forge_installer/src/main/java/git/artdeell/forgeinstaller/Agent.java +++ b/forge_installer/src/main/java/git/artdeell/forgeinstaller/Agent.java @@ -20,11 +20,12 @@ import javax.swing.JOptionPane; public class Agent implements AWTEventListener { private boolean forgeWindowHandled = false; private final boolean suppressProfileCreation; - + private final boolean optiFineInstallation; private final Timer componentTimer = new Timer(); - public Agent(boolean ps) { - this.suppressProfileCreation = ps; + public Agent(boolean nps, boolean of) { + this.suppressProfileCreation = !nps; + this.optiFineInstallation = of; } @Override @@ -33,7 +34,7 @@ public class Agent implements AWTEventListener { Window window = windowEvent.getWindow(); if(windowEvent.getID() == WindowEvent.WINDOW_OPENED) { if(!forgeWindowHandled) { // false at startup, so we will handle the first window as the Forge one - forgeWindowHandled = handleForgeWindow(window); + forgeWindowHandled = handleMainWindow(window); if(forgeWindowHandled) { componentTimer.cancel(); componentTimer.purge(); @@ -46,34 +47,47 @@ public class Agent implements AWTEventListener { } } - public boolean handleForgeWindow(Window window) { + public boolean handleMainWindow(Window window) { List components = new ArrayList<>(); insertAllComponents(components, window, new MainWindowFilter()); AbstractButton okButton = null; for(Component component : components) { if(component instanceof AbstractButton) { AbstractButton abstractButton = (AbstractButton) component; - switch(abstractButton.getText()) { - case "OK": - okButton = abstractButton; // store the button, so we can press it after processing other stuff - break; - case "Install client": - abstractButton.doClick(); // It should be the default, but let's make sure - } - + abstractButton = optiFineInstallation ? + handleOptiFineButton(abstractButton) : + handleForgeButton(abstractButton); + if(abstractButton != null) okButton = abstractButton; } } if(okButton == null) { System.out.println("Failed to set all the UI components, wil try again in the next window"); - System.exit(17); return false; }else{ - ProfileFixer.storeProfile(); + ProfileFixer.storeProfile(optiFineInstallation ? "OptiFine" : "forge"); EventQueue.invokeLater(okButton::doClick); // do that after forge actually builds its window, otherwise we set the path too fast return true; } } + + public AbstractButton handleForgeButton(AbstractButton abstractButton) { + switch(abstractButton.getText()) { + case "OK": + return abstractButton; // return the button, so we can press it after processing other stuff + case "Install client": + abstractButton.doClick(); // It should be the default, but let's make sure + } + return null; + } + + public AbstractButton handleOptiFineButton(AbstractButton abstractButton) { + if ("Install".equals(abstractButton.getText())) { + return abstractButton; + } + return null; + } + public void handleDialog(Window window) { List components = new ArrayList<>(); insertAllComponents(components, window, new DialogFilter()); // ensure that it's a JOptionPane dialog @@ -84,7 +98,7 @@ public class Agent implements AWTEventListener { JOptionPane optionPane = (JOptionPane) components.get(0); if(optionPane.getMessageType() == JOptionPane.INFORMATION_MESSAGE) { // forge doesn't emit information messages for other reasons yet System.out.println("The install was successful!"); - ProfileFixer.reinsertProfile(suppressProfileCreation); + ProfileFixer.reinsertProfile(optiFineInstallation ? "OptiFine" : "forge", suppressProfileCreation); System.exit(0); // again, forge doesn't call exit for some reason, so we do that ourselves here } } @@ -102,8 +116,15 @@ public class Agent implements AWTEventListener { } public static void premain(String args, Instrumentation inst) { + boolean noProfileSuppression = false; + boolean optifine = false; + if(args != null ) { + noProfileSuppression = args.contains("NPS"); // No Profile Suppression + optifine = args.contains("OF"); // OptiFine + } + Agent agent = new Agent(noProfileSuppression, optifine); Toolkit.getDefaultToolkit() - .addAWTEventListener(new Agent(!"NPS".equals(args)), // No Profile Suppression + .addAWTEventListener(agent, AWTEvent.WINDOW_EVENT_MASK); } } diff --git a/forge_installer/src/main/java/git/artdeell/forgeinstaller/ProfileFixer.java b/forge_installer/src/main/java/git/artdeell/forgeinstaller/ProfileFixer.java index 5228c0a2c..da0b1d4d1 100644 --- a/forge_installer/src/main/java/git/artdeell/forgeinstaller/ProfileFixer.java +++ b/forge_installer/src/main/java/git/artdeell/forgeinstaller/ProfileFixer.java @@ -15,23 +15,23 @@ public class ProfileFixer { private static final Random random = new Random(); private static final Path profilesPath = Paths.get(System.getProperty("user.home"), ".minecraft", "launcher_profiles.json"); private static JSONObject oldProfile = null; - public static void storeProfile() { + public static void storeProfile(String profileName) { try { JSONObject minecraftProfiles = new JSONObject( new String(Files.readAllBytes(profilesPath), StandardCharsets.UTF_8) ); JSONObject profilesArray = minecraftProfiles.getJSONObject("profiles"); - oldProfile = profilesArray.optJSONObject("forge", null); + oldProfile = profilesArray.optJSONObject(profileName, null); }catch (IOException | JSONException e) { System.out.println("Failed to store Forge profile: "+e); } } - private static String pickProfileName() { - return "forge"+random.nextInt(); + private static String pickProfileName(String profileName) { + return profileName+random.nextInt(); } - public static void reinsertProfile(boolean suppressProfileCreation) { + public static void reinsertProfile(String profileName, boolean suppressProfileCreation) { try { JSONObject minecraftProfiles = new JSONObject( new String(Files.readAllBytes(profilesPath), @@ -41,8 +41,8 @@ public class ProfileFixer { if(oldProfile != null) { if(suppressProfileCreation) profilesArray.put("forge", oldProfile); // restore the old profile else { - String name = pickProfileName(); - while(profilesArray.has(name)) name = pickProfileName(); + String name = pickProfileName(profileName); + while(profilesArray.has(name)) name = pickProfileName(profileName); profilesArray.put(name, oldProfile); // restore the old profile under a new name } }else{