From 091042c82036192520905c8bfd8da0f00a4275c6 Mon Sep 17 00:00:00 2001 From: khanhduytran0 Date: Tue, 24 Nov 2020 06:28:18 +0700 Subject: [PATCH] Changes - Auto scale fixes - Now launch Fabric installer easier --- .../pojavlaunch/JavaGUILauncherActivity.java | 56 ++++++++++++++++--- .../main/java/net/kdt/pojavlaunch/Tools.java | 2 +- .../pojavlaunch/installers/BaseInstaller.java | 2 +- .../installers/FabricInstaller.java | 29 ++++++++++ .../installers/InstallerDetector.java | 4 ++ .../installers/LegacyForgeInstaller.java | 4 +- .../installers/NewForgeInstaller.java | 4 +- .../prefs/LauncherPreferenceFragment.java | 5 ++ .../prefs/LauncherPreferences.java | 2 +- app/src/main/jni/egl_bridge.c | 5 -- app/src/main/res/values/strings.xml | 4 +- 11 files changed, 97 insertions(+), 20 deletions(-) create mode 100644 app/src/main/java/net/kdt/pojavlaunch/installers/FabricInstaller.java diff --git a/app/src/main/java/net/kdt/pojavlaunch/JavaGUILauncherActivity.java b/app/src/main/java/net/kdt/pojavlaunch/JavaGUILauncherActivity.java index eaaa119a2..a0c8f6256 100644 --- a/app/src/main/java/net/kdt/pojavlaunch/JavaGUILauncherActivity.java +++ b/app/src/main/java/net/kdt/pojavlaunch/JavaGUILauncherActivity.java @@ -2,14 +2,16 @@ package net.kdt.pojavlaunch; import android.graphics.*; import android.os.*; +import android.support.v7.app.*; +import android.util.*; import android.view.*; import android.widget.*; import java.io.*; import java.util.*; +import net.kdt.pojavlaunch.installers.*; import net.kdt.pojavlaunch.utils.*; import org.lwjgl.glfw.*; -import net.kdt.pojavlaunch.installers.*; -import android.util.*; +import android.content.*; public class JavaGUILauncherActivity extends LoggableActivity { private AWTCanvasView mTextureView; @@ -20,6 +22,8 @@ public class JavaGUILauncherActivity extends LoggableActivity { private File logFile; private PrintStream logStream; + + private Object mDialogLock; private boolean isLogAllow, mSkipDetectMod; @@ -56,7 +60,6 @@ public class JavaGUILauncherActivity extends LoggableActivity { mSkipDetectMod = getIntent().getExtras().getBoolean("skipDetectMod", false); if (mSkipDetectMod) { - JREUtils.redirectAndPrintJRELog(this, null); new Thread(new Runnable(){ @Override public void run() { @@ -78,7 +81,7 @@ public class JavaGUILauncherActivity extends LoggableActivity { Toast.makeText(JavaGUILauncherActivity.this, R.string.toast_optifine_success, Toast.LENGTH_SHORT).show(); } }); - } catch (IOException e) { + } catch (Throwable e) { appendlnToLog("Install failed:"); appendlnToLog(Log.getStackTraceString(e)); Tools.showError(JavaGUILauncherActivity.this, e); @@ -90,6 +93,42 @@ public class JavaGUILauncherActivity extends LoggableActivity { Tools.showError(this, th, true); } } + + 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(message); + d.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener(){ + + @Override + public void onClick(DialogInterface i, int id) { + str.append(editText.getText().toString()); + mDialogLock.notifyAll(); + } + }); + } + }); + + try { + synchronized (mDialogLock) { + mDialogLock.wait(); + } + } catch (InterruptedException e) { + e.printStackTrace(); + } + + return str.toString(); + } public void forceClose(View v) { BaseMainActivity.dialogForceClose(this); @@ -120,16 +159,19 @@ public class JavaGUILauncherActivity extends LoggableActivity { } else if (InstallerDetector.isForgeNew(installer)) { appendlnToLog("Detected Forge Installer 1.12.2 or above!"); new NewForgeInstaller(installer).install(this); - } else { + } else if (InstallerDetector.isFabric(installer)) { + appendlnToLog("Detected Fabric Installer!"); + new FabricInstaller(installer).install(this); + } else { appendlnToLog("No mod detected. Starting JVM"); isLogAllow = false; mSkipDetectMod = true; - JREUtils.redirectAndPrintJRELog(this, null); launchJavaRuntime(modFile, javaArgs); } } - private void launchJavaRuntime(File modFile, String javaArgs) { + public void launchJavaRuntime(File modFile, String javaArgs) { + JREUtils.redirectAndPrintJRELog(this, null); try { List javaArgList = new ArrayList(); diff --git a/app/src/main/java/net/kdt/pojavlaunch/Tools.java b/app/src/main/java/net/kdt/pojavlaunch/Tools.java index 1c4d294ce..0f56e857e 100644 --- a/app/src/main/java/net/kdt/pojavlaunch/Tools.java +++ b/app/src/main/java/net/kdt/pojavlaunch/Tools.java @@ -344,7 +344,7 @@ public final class Tools public static float dpToPx(float dp) { // 921600 = 1280 * 720, default scale // TODO better way to scaling - float scaledDp = dp / DisplayMetrics.DENSITY_XHIGH * currentDisplayMetrics.densityDpi; + float scaledDp = dp; // / DisplayMetrics.DENSITY_XHIGH * currentDisplayMetrics.densityDpi; return (scaledDp * currentDisplayMetrics.density); } diff --git a/app/src/main/java/net/kdt/pojavlaunch/installers/BaseInstaller.java b/app/src/main/java/net/kdt/pojavlaunch/installers/BaseInstaller.java index f2f88be52..e97f5af90 100644 --- a/app/src/main/java/net/kdt/pojavlaunch/installers/BaseInstaller.java +++ b/app/src/main/java/net/kdt/pojavlaunch/installers/BaseInstaller.java @@ -13,7 +13,7 @@ public class BaseInstaller { mJarFile = new ZipFile(file); } - public void install(LoggableActivity ctx) throws IOException {} + public void install(JavaGUILauncherActivity ctx) throws IOException {} public void from(BaseInstaller base) { mFile = base.mFile; diff --git a/app/src/main/java/net/kdt/pojavlaunch/installers/FabricInstaller.java b/app/src/main/java/net/kdt/pojavlaunch/installers/FabricInstaller.java new file mode 100644 index 000000000..92e0079be --- /dev/null +++ b/app/src/main/java/net/kdt/pojavlaunch/installers/FabricInstaller.java @@ -0,0 +1,29 @@ +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 FabricInstaller extends BaseInstaller { + public FabricInstaller(BaseInstaller i) { + from(i); + } + + @Override + public void install(JavaGUILauncherActivity ctx) throws IOException { + // Unused ZipFile + mJarFile.close(); + + String mcversion = ctx.dialogInput("Fabric installer", R.string.main_version); + + ctx.appendlnToLog("Launching JVM"); + ctx.launchJavaRuntime(null, + "-jar " + mFile.getAbsolutePath() + " client -dir . -mcversion " + mcversion); + } +} diff --git a/app/src/main/java/net/kdt/pojavlaunch/installers/InstallerDetector.java b/app/src/main/java/net/kdt/pojavlaunch/installers/InstallerDetector.java index 9cd018398..789004d74 100644 --- a/app/src/main/java/net/kdt/pojavlaunch/installers/InstallerDetector.java +++ b/app/src/main/java/net/kdt/pojavlaunch/installers/InstallerDetector.java @@ -6,6 +6,10 @@ import net.kdt.pojavlaunch.value.*; public class InstallerDetector { + public static boolean isFabric(BaseInstaller installer) { + return installer.mJarFile.getEntry("net/fabricmc/installer/Main.class") != null; + } + // Forge Legacy: for 1.12.1 and below public static boolean isForgeLegacy(BaseInstaller installer) throws IOException, JsonSyntaxException { ForgeInstallProfile profile = LegacyForgeInstaller.readInstallProfile(installer); diff --git a/app/src/main/java/net/kdt/pojavlaunch/installers/LegacyForgeInstaller.java b/app/src/main/java/net/kdt/pojavlaunch/installers/LegacyForgeInstaller.java index b8e698ce2..2b8cb3189 100644 --- a/app/src/main/java/net/kdt/pojavlaunch/installers/LegacyForgeInstaller.java +++ b/app/src/main/java/net/kdt/pojavlaunch/installers/LegacyForgeInstaller.java @@ -15,7 +15,7 @@ public class LegacyForgeInstaller extends BaseInstaller { } @Override - public void install(LoggableActivity ctx) throws IOException { + public void install(JavaGUILauncherActivity ctx) throws IOException { String target; ctx.appendlnToLog("Reading install_profile.json"); @@ -40,6 +40,8 @@ public class LegacyForgeInstaller extends BaseInstaller { FileOutputStream out = new FileOutputStream(target); IOUtils.copy(mJarFile.getInputStream(mJarFile.getEntry(profile.install.filePath)), out); out.close(); + + mJarFile.close(); } public static ForgeInstallProfile readInstallProfile(BaseInstaller base) throws IOException, JsonSyntaxException { diff --git a/app/src/main/java/net/kdt/pojavlaunch/installers/NewForgeInstaller.java b/app/src/main/java/net/kdt/pojavlaunch/installers/NewForgeInstaller.java index 84701bab6..28703f046 100644 --- a/app/src/main/java/net/kdt/pojavlaunch/installers/NewForgeInstaller.java +++ b/app/src/main/java/net/kdt/pojavlaunch/installers/NewForgeInstaller.java @@ -16,7 +16,7 @@ public class NewForgeInstaller extends BaseInstaller { } @Override - public void install(LoggableActivity ctx) throws IOException { + public void install(JavaGUILauncherActivity ctx) throws IOException { String target; ctx.appendlnToLog("Reading install_profile.json"); @@ -42,6 +42,8 @@ public class NewForgeInstaller extends BaseInstaller { 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(); } public static ForgeInstallProfile readInstallProfile(BaseInstaller base) throws IOException, JsonSyntaxException { diff --git a/app/src/main/java/net/kdt/pojavlaunch/prefs/LauncherPreferenceFragment.java b/app/src/main/java/net/kdt/pojavlaunch/prefs/LauncherPreferenceFragment.java index ee76ab9a4..876e84d73 100644 --- a/app/src/main/java/net/kdt/pojavlaunch/prefs/LauncherPreferenceFragment.java +++ b/app/src/main/java/net/kdt/pojavlaunch/prefs/LauncherPreferenceFragment.java @@ -20,6 +20,11 @@ public class LauncherPreferenceFragment extends PreferenceFragmentCompat seek2.setMin(100); seek2.setMax(1000); seek2.setValue(500); + + SeekBarPreference seek3 = (SeekBarPreference) findPreference("buttonscale"); + seek3.setMin(20); + seek3.setMax(500); + seek3.setValue(100); } @Override diff --git a/app/src/main/java/net/kdt/pojavlaunch/prefs/LauncherPreferences.java b/app/src/main/java/net/kdt/pojavlaunch/prefs/LauncherPreferences.java index 93bcfd24d..f672c8290 100644 --- a/app/src/main/java/net/kdt/pojavlaunch/prefs/LauncherPreferences.java +++ b/app/src/main/java/net/kdt/pojavlaunch/prefs/LauncherPreferences.java @@ -20,7 +20,7 @@ public class LauncherPreferences public static String PREF_LANGUAGE = "default"; public static void loadPreferences() { - PREF_BUTTONSIZE = DEFAULT_PREF.getFloat("controlSize", 1f); + PREF_BUTTONSIZE = DEFAULT_PREF.getFloat("buttonscale", 100); PREF_FREEFORM = DEFAULT_PREF.getBoolean("freeform", false); PREF_VERTYPE_RELEASE = DEFAULT_PREF.getBoolean("vertype_release", true); PREF_VERTYPE_SNAPSHOT = DEFAULT_PREF.getBoolean("vertype_snapshot", false); diff --git a/app/src/main/jni/egl_bridge.c b/app/src/main/jni/egl_bridge.c index 17d45e52c..32e209893 100644 --- a/app/src/main/jni/egl_bridge.c +++ b/app/src/main/jni/egl_bridge.c @@ -190,12 +190,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_GL_nativeRegalMakeCurrent(JNIEnv *e RegalMakeCurrent(potatoBridge.eglContext); } -bool isSizeSet; JNIEXPORT jboolean JNICALL Java_org_lwjgl_glfw_GLFW_nativeEglSwapBuffers(JNIEnv *env, jclass clazz) { - if (!isSizeSet) { - isSizeSet = true; - Java_org_lwjgl_glfw_CallbackBridge_nativeSendScreenSize(NULL, NULL, savedWidth, savedHeight); - } return eglSwapBuffers(potatoBridge.eglDisplay, potatoBridge.eglSurface); } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index e00332ce3..a8d597cd4 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -53,8 +53,6 @@ Error! Please check the log below: %s No version! Unable to load version %s - Unable to convert library %s - Unable to convert Minecraft %s Show more Show less @@ -210,7 +208,7 @@ Welcome, Info (DEV) Switch user - Version: + Version: No crash detected No log.