packwiz / packwiz-installer-bootstrap

An updater for packwiz-installer.
https://packwiz.infra.link/
MIT License
28 stars 8 forks source link

Support being called as Java-Agent #14

Open zbx1425 opened 11 months ago

zbx1425 commented 11 months ago

Support being called as Java-Agent would enable Packwiz-Installer to be used on:


Currently there's a community workaround for the aforementioned issues ("packwiz-installer-bootstrap-wrapper") by teacon.org:

package org.teacon.codenamed;

import java.io.File;
import java.lang.instrument.Instrumentation;

public class JavaAgentEntryPoint {

  public static void premain(String args, Instrumentation inst) {
    String javaExecutable = System.getProperty("java.home") + System.getProperty("java.home") + "bin" + File.separator;
    if (System.getProperty("os.name").startsWith("Win")) {
      javaExecutable = javaExecutable + "javaw.exe";
    } else {
      javaExecutable = javaExecutable + "java";
    } 
    try {
      Process p = (new ProcessBuilder(new String[] { javaExecutable, "-jar", "packwiz-installer-bootstrap.jar", "--bootstrap-main-jar", "packwiz-installer.jar", "--bootstrap-no-update", args })).inheritIO().start();
      int exitCode;
      if ((exitCode = p.waitFor()) != 0)
        throw new RuntimeException("Process exit status is " + exitCode + ", meaning an error has occurred."); 
    } catch (Exception e) {
      throw new RuntimeException("Game failed to launch, see console output for details.", e);
    } 
  }
}