Cherry-pick 2af5d6176d48b98471e943582edcb2e19550af57

This commit is contained in:
Duy Tran Khanh
2021-02-13 20:02:42 +07:00
parent fde4950097
commit b34709200e
11 changed files with 2 additions and 317 deletions

View File

@@ -1,3 +0,0 @@
From https://github.com/xfl03/ForgeInstallerHeadless
No changes on source code.

View File

Binary file not shown.

View File

@@ -11,7 +11,6 @@ import android.widget.*;
import androidx.appcompat.app.*;
import java.io.*;
import java.util.*;
import net.kdt.pojavlaunch.installers.*;
import net.kdt.pojavlaunch.prefs.*;
import net.kdt.pojavlaunch.utils.*;
import org.lwjgl.glfw.*;
@@ -270,46 +269,6 @@ public class JavaGUILauncherActivity extends LoggableActivity implements View.On
this.mousePointer.setTranslationY(y);
}
public String dialogInput(final String title, final int message) {
final StringBuilder str = new StringBuilder();
runOnUiThread(new Runnable(){
@Override
public void run() {
final EditText editText = new EditText(JavaGUILauncherActivity.this);
editText.setHint(message);
editText.setSingleLine();
AlertDialog.Builder d = new AlertDialog.Builder(JavaGUILauncherActivity.this);
d.setCancelable(false);
d.setTitle(title);
d.setView(editText);
d.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener(){
@Override
public void onClick(DialogInterface i, int id) {
str.append(editText.getText().toString());
synchronized (mDialogLock) {
mDialogLock.notifyAll();
}
}
});
d.show();
}
});
try {
synchronized (mDialogLock) {
mDialogLock.wait();
}
} catch (InterruptedException e) {
e.printStackTrace();
}
return str.toString();
}
public void forceClose(View v) {
BaseMainActivity.dialogForceClose(this);
}
@@ -328,32 +287,8 @@ public class JavaGUILauncherActivity extends LoggableActivity implements View.On
private int doCustomInstall(File modFile, String javaArgs) throws IOException {
isLogAllow = true;
// Attempt to detects some mod installers
BaseInstaller installer = new BaseInstaller();
installer.setInput(modFile);
if (InstallerDetector.isForgeLegacy(installer)) {
appendlnToLog("Detected Forge Installer 1.12.1 or below!");
return new LegacyForgeInstaller(installer).install(this);
} else if (InstallerDetector.isForge1p12p2(installer)) {
appendlnToLog("Detected Forge Installer 1.12.2!");
return new Legacy1p12p2ForgeInstaller(installer).install(this);
} else if (InstallerDetector.isForgeNew(installer)) {
appendlnToLog("Detected Forge Installer 1.13 or above!");
return new NewForgeInstaller(installer).install(this);
} else if (InstallerDetector.isFabric(installer)) {
appendlnToLog("Detected Fabric Installer!");
return new FabricInstaller(installer).install(this);
}else if (InstallerDetector.isOptiFine(installer)) {
appendlnToLog("Detected OptiFine Installer!");
return new LegacyOptifineInstaller(installer).install(this);
} else {
appendlnToLog("No mod detected. Starting JVM");
isLogAllow = false;
mSkipDetectMod = true;
return launchJavaRuntime(modFile, javaArgs);
}
mSkipDetectMod = true;
return launchJavaRuntime(modFile, javaArgs);
}
public int launchJavaRuntime(File modFile, String javaArgs) {
@@ -370,8 +305,6 @@ public class JavaGUILauncherActivity extends LoggableActivity implements View.On
javaArgList.add("-jar");
javaArgList.add(modFile.getAbsolutePath());
}
// System.out.println(Arrays.toString(javaArgList.toArray(new String[0])));
appendlnToLog("Info: Java arguments: " + Arrays.toString(javaArgList.toArray(new String[0])));

View File

@@ -1,24 +0,0 @@
package net.kdt.pojavlaunch.installers;
import java.io.*;
import java.util.zip.*;
import net.kdt.pojavlaunch.*;
public class BaseInstaller {
protected File mFile;
protected ZipFile mJarFile;
public void setInput(File file) throws IOException {
mFile = file;
mJarFile = new ZipFile(file);
}
public int install(JavaGUILauncherActivity ctx) throws IOException {
return 0;
}
public void from(BaseInstaller base) {
mFile = base.mFile;
mJarFile = base.mJarFile;
}
}

View File

@@ -1,23 +0,0 @@
package net.kdt.pojavlaunch.installers;
import java.io.*;
import net.kdt.pojavlaunch.*;
public class FabricInstaller extends BaseInstaller {
public FabricInstaller(BaseInstaller i) {
from(i);
}
@Override
public int install(JavaGUILauncherActivity ctx) throws IOException {
// Unused ZipFile
mJarFile.close();
String mcversion = ctx.dialogInput("Fabric installer", R.string.main_version);
ctx.appendlnToLog("Launching JVM");
return ctx.launchJavaRuntime(null,
"-jar " + mFile.getAbsolutePath() + " client -dir . -mcversion " + mcversion);
}
}

View File

@@ -1,37 +0,0 @@
package net.kdt.pojavlaunch.installers;
import java.io.*;
import java.util.Enumeration;
import java.util.zip.ZipEntry;
import com.google.gson.*;
import net.kdt.pojavlaunch.value.*;
public class InstallerDetector
{
public static boolean isFabric(BaseInstaller installer) {
return installer.mJarFile.getEntry("net/fabricmc/installer/Main.class") != null;
}
public static boolean isOptiFine(BaseInstaller installer) {
Enumeration e = installer.mJarFile.entries();
return installer.mJarFile.getEntry("optifine/Installer.class") != null;
}
// Forge Legacy: for 1.12.1 and below
public static boolean isForgeLegacy(BaseInstaller installer) throws IOException, JsonSyntaxException {
ForgeInstallProfile profile = LegacyForgeInstaller.readInstallProfile(installer);
return profile != null && profile.versionInfo != null;
}
// Forge for 1.12.2 only
public static boolean isForge1p12p2(BaseInstaller installer) throws IOException, JsonSyntaxException {
ForgeInstallProfile profile = LegacyForgeInstaller.readInstallProfile(installer);
// Forge 1.12.2 install_profile.json has same format as Forge 1.13+
return isForgeNew(installer) && profile.minecraft.equals("1.12.2");
}
// Forge New: for 1.13 and above
public static boolean isForgeNew(BaseInstaller installer) throws IOException, JsonSyntaxException {
ForgeInstallProfile profile = LegacyForgeInstaller.readInstallProfile(installer);
return profile != null && profile.version != null;
}
}

View File

@@ -1,60 +0,0 @@
package net.kdt.pojavlaunch.installers;
import android.content.*;
import java.io.*;
import java.util.jar.*;
import net.kdt.pojavlaunch.*;
import java.nio.charset.*;
import net.kdt.pojavlaunch.value.*;
import org.apache.commons.io.*;
import com.google.gson.*;
import java.util.zip.*;
public class Legacy1p12p2ForgeInstaller extends BaseInstaller {
public Legacy1p12p2ForgeInstaller(BaseInstaller i) {
from(i);
}
@Override
public int install(JavaGUILauncherActivity ctx) throws IOException {
String target;
ctx.appendlnToLog("Reading install_profile.json");
ForgeInstallProfile profile = readInstallProfile(this);
// Write the json file
File versionFile = new File(Tools.DIR_HOME_VERSION, profile.version);
versionFile.mkdir();
target = versionFile.getAbsolutePath() + "/" + profile.version + ".json";
ctx.appendlnToLog("Writing " + target + " from " + profile.json);
ZipEntry versionJson = mJarFile.getEntry(profile.json==null ? "version.json" : profile.json.substring(profile.json.indexOf("/")+1,profile.json.length()));
Tools.write(
target,
Tools.convertStream(mJarFile.getInputStream(versionJson))
);
// Forge 1.12.2+ installer does not include universal, so download
// Users are already go throught Forge ads to download installer, so not again.
String[] libInfos = profile.path.split(":");
File libraryFile = new File(Tools.DIR_HOME_LIBRARY, Tools.artifactToPath(libInfos[0], libInfos[1], libInfos[2]));
libraryFile.getParentFile().mkdirs();
target = libraryFile.getAbsolutePath();
String downloadPath = "https://files.minecraftforge.net/maven/" + profile.path.replace(":", "/").replace("net.minecraftforge","net/minecraftforge") + "/forge-" + libInfos[2] + "-universal.jar";
ctx.appendlnToLog("Downloading " + target);
Tools.downloadFile(downloadPath, target);
mJarFile.close();
return 0;
}
public static ForgeInstallProfile readInstallProfile(BaseInstaller base) throws IOException, JsonSyntaxException {
ZipEntry entry = base.mJarFile.getEntry("install_profile.json");
return entry == null ? null : Tools.GLOBAL_GSON.fromJson(
Tools.convertStream(
base.mJarFile.getInputStream(entry)
),
ForgeInstallProfile.class
);
}
}

View File

@@ -1,61 +0,0 @@
package net.kdt.pojavlaunch.installers;
import android.content.*;
import java.io.*;
import java.util.jar.*;
import net.kdt.pojavlaunch.*;
import java.nio.charset.*;
import net.kdt.pojavlaunch.value.*;
import org.apache.commons.io.*;
import com.google.gson.*;
import java.util.zip.*;
public class LegacyForgeInstaller extends BaseInstaller {
public LegacyForgeInstaller(BaseInstaller i) {
from(i);
}
@Override
public int install(JavaGUILauncherActivity ctx) throws IOException {
String target;
ctx.appendlnToLog("Reading install_profile.json");
ForgeInstallProfile profile = readInstallProfile(this);
// Write the json file
File versionFile = new File(Tools.DIR_HOME_VERSION, profile.install.target);
versionFile.mkdir();
target = versionFile.getAbsolutePath() + "/" + profile.install.target + ".json";
ctx.appendlnToLog("Writing " + target);
Tools.write(
target,
Tools.GLOBAL_GSON.toJson(profile.versionInfo)
);
// Extract Forge universal
String[] libInfos = profile.install.path.split(":");
File libraryFile = new File(Tools.DIR_HOME_LIBRARY, Tools.artifactToPath(libInfos[0], libInfos[1], libInfos[2]));
libraryFile.getParentFile().mkdirs();
target = libraryFile.getAbsolutePath().replace("-universal", "");
ctx.appendlnToLog("Writing " + target);
InputStream in = mJarFile.getInputStream(mJarFile.getEntry(profile.install.filePath));
FileOutputStream out = new FileOutputStream(target);
IOUtils.copy(in, out);
in.close();
out.close();
mJarFile.close();
return 0;
}
public static ForgeInstallProfile readInstallProfile(BaseInstaller base) throws IOException, JsonSyntaxException {
ZipEntry entry = base.mJarFile.getEntry("install_profile.json");
return entry == null ? null : Tools.GLOBAL_GSON.fromJson(
Tools.convertStream(
base.mJarFile.getInputStream(entry),
Charset.forName("UTF-8")
),
ForgeInstallProfile.class
);
}
}

View File

@@ -1,19 +0,0 @@
package net.kdt.pojavlaunch.installers;
import java.io.*;
import net.kdt.pojavlaunch.*;
public class LegacyOptifineInstaller extends BaseInstaller {
public LegacyOptifineInstaller(BaseInstaller i) {
from(i);
}
@Override
public int install(JavaGUILauncherActivity ctx) throws IOException {
mJarFile.close();
ctx.appendlnToLog("Launching JVM");
return ctx.launchJavaRuntime(null,
"-jar "+Tools.DIR_GAME_NEW+"/config/OptiInst.jar " + mFile.getAbsolutePath() +" .");
}
}

View File

@@ -1,21 +0,0 @@
package net.kdt.pojavlaunch.installers;
import java.io.*;
import net.kdt.pojavlaunch.*;
public class NewForgeInstaller extends BaseInstaller
{
public NewForgeInstaller(BaseInstaller i) {
from(i);
}
@Override
public int install(JavaGUILauncherActivity ctx) throws IOException {
// Unused ZipFile
mJarFile.close();
ctx.appendlnToLog("Launching JVM");
return ctx.launchJavaRuntime(null,
"-cp " + Tools.DIR_GAME_NEW + "/config/forge-installer-headless.jar:" + mFile.getAbsolutePath() + " me.xfl03.HeadlessInstaller --installClient .");
}
}