UI: add basic download progress
This commit is contained in:
1 parent
e65bcce36d
commit
bcb220ce5d
9 files changed
+137
-62
No files matched your search
@@ -14,8 +14,11 @@ import net.kdt.pojavlaunch.value.*;
|
||||
|
||||
public class PLaunchApp {
|
||||
public static JMinecraftVersionList mVersionList;
|
||||
public static MinecraftAccount mAccount;
|
||||
public static JMinecraftVersionList.Version mVersion;
|
||||
public static void main(String[] args) throws Throwable {
|
||||
// System.setProperty("os.name", "iOS");
|
||||
/*
|
||||
System.setProperty("javafx.verbose", "true");
|
||||
System.setProperty("javafx.platform", "ios");
|
||||
System.setProperty("glass.platform", "ios");
|
||||
@@ -27,46 +30,38 @@ public class PLaunchApp {
|
||||
System.setProperty("prism.mintexturesize", "16");
|
||||
System.setProperty("prism.static.libraries", "false");
|
||||
System.setProperty("prism.useNativeIIO", "false");
|
||||
*/
|
||||
|
||||
if (args[0].startsWith("/Applications/")) {
|
||||
System.out.println("We are on java now! Starting UI...");
|
||||
UIKit.launchUI(args);
|
||||
} else {
|
||||
// Test on cmdline
|
||||
launchMinecraft();
|
||||
}
|
||||
|
||||
LauncherPreferences.loadPreferences();
|
||||
}
|
||||
|
||||
public static void applicationDidFinishLaunching() {
|
||||
/*
|
||||
Thread launchThread = new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
Application.launch(PLaunchJFXApp.class);
|
||||
}
|
||||
};
|
||||
launchThread.setDaemon(true);
|
||||
launchThread.start();
|
||||
*/
|
||||
|
||||
launchMinecraft();
|
||||
}
|
||||
|
||||
public static void launchMinecraft() {
|
||||
System.out.println("Saving GLES context");
|
||||
JREUtils.saveGLContext();
|
||||
|
||||
// Start Minecraft there!
|
||||
System.out.println("Finding a version");
|
||||
String mcver = "1.13";
|
||||
public static void installMinecraft() {
|
||||
new Thread(() -> {
|
||||
|
||||
int currProgress, totalProgress;
|
||||
|
||||
UIKit.updateProgressSafe(currProgress, "Finding a version");
|
||||
String mcver = "1.16.5";
|
||||
|
||||
try {
|
||||
mcver = Tools.read(Tools.DIR_GAME_NEW + "/config_ver.txt");
|
||||
} catch (IOException e) {
|
||||
System.out.println("config_ver.txt not found, defaulting to Minecraft 1.13");
|
||||
UIKit.updateProgressSafe(currProgress, "config_ver.txt not found, defaulting to Minecraft 1.16.5");
|
||||
}
|
||||
|
||||
UIKit.updateProgressSafe(currProgress, "Selected Minecraft version: " + mcver);
|
||||
|
||||
Thread.sleep(1000);
|
||||
|
||||
// dummy account
|
||||
MinecraftAccount acc = new MinecraftAccount();
|
||||
acc.selectedVersion = mcver;
|
||||
|
||||
@@ -79,16 +74,17 @@ public class PLaunchApp {
|
||||
String minecraftMainJar = Tools.DIR_HOME_VERSION + downVName + ".jar";
|
||||
String verJsonDir = Tools.DIR_HOME_VERSION + downVName + ".json";
|
||||
|
||||
System.out.println("Downloading version list");
|
||||
UIKit.updateProgressSafe(currProgress, "Downloading version list");
|
||||
mVersionList = Tools.GLOBAL_GSON.fromJson(DownloadUtils.downloadString("https://launchermeta.mojang.com/mc/game/version_manifest.json"), JMinecraftVersionList.class);
|
||||
|
||||
verInfo = findVersion(mcver);
|
||||
if (verInfo.url != null && !new File(verJsonDir).exists()) {
|
||||
System.out.println("Downloading " + mcver + ".json");
|
||||
UIKit.updateProgressSafe(currProgress, "Downloading " + mcver + ".json");
|
||||
Tools.downloadFile(verInfo.url, verJsonDir);
|
||||
}
|
||||
|
||||
verInfo = Tools.getVersionInfo(mcver);
|
||||
totalProgress = verInfo.libraries.length + 1; // + verInfo.assetslength
|
||||
|
||||
File outLib;
|
||||
String libPathURL;
|
||||
@@ -98,7 +94,7 @@ public class PLaunchApp {
|
||||
libItem.name.startsWith("net.java.jinput") ||
|
||||
libItem.name.startsWith("org.lwjgl")
|
||||
) { // Black list
|
||||
System.out.println("Ignored " + libItem.name);
|
||||
UIKit.updateProgressSafe(currProgress++, "Ignored " + libItem.name);
|
||||
// Thread.sleep(100);
|
||||
} else {
|
||||
String[] libInfo = libItem.name.split(":");
|
||||
@@ -107,7 +103,7 @@ public class PLaunchApp {
|
||||
outLib.getParentFile().mkdirs();
|
||||
|
||||
if (!outLib.exists()) {
|
||||
System.out.println("Downloading " + libItem.name);
|
||||
UIKit.updateProgressSafe(currProgress++, "Downloading " + libItem.name);
|
||||
|
||||
boolean skipIfFailed = false;
|
||||
|
||||
@@ -122,33 +118,44 @@ public class PLaunchApp {
|
||||
libPathURL = libItem.downloads.artifact.url;
|
||||
Tools.downloadFile(libPathURL, outLib.getAbsolutePath());
|
||||
} catch (Throwable th) {
|
||||
/*
|
||||
if (!skipIfFailed) {
|
||||
throw th;
|
||||
} else {
|
||||
th.printStackTrace();
|
||||
publishProgress("0", th.getMessage());
|
||||
}
|
||||
*/
|
||||
|
||||
System.out.println("Download failed");
|
||||
th.printStackTrace();
|
||||
UIKit.updateProgressSafe(0, "Download failed");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println("Downloading " + mcver + ".jar");
|
||||
UIKit.updateProgressSafe(currProgress++, "Downloading " + mcver + ".jar");
|
||||
File minecraftMainFile = new File(minecraftMainJar);
|
||||
if (!minecraftMainFile.exists() || minecraftMainFile.length() == 0l) {
|
||||
Tools.downloadFile(verInfo.downloads.values().toArray(new MinecraftClientInfo[0])[0].url, minecraftMainJar);
|
||||
}
|
||||
|
||||
// TODO download assets
|
||||
|
||||
} catch (IOException e) {
|
||||
System.out.println("Download error, skipping");
|
||||
UIKit.updateProgressSafe(currProgress, "Download error, skipping");
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
mAccount = acc;
|
||||
mVersion = verInfo;
|
||||
|
||||
UIKit.runOnUIThread(() -> {
|
||||
UIKit.launchMinecraftSurface();
|
||||
});
|
||||
|
||||
}).start();
|
||||
}
|
||||
|
||||
// Called from SurfaceViewController
|
||||
public static void launchMinecraft() {
|
||||
System.out.println("Saving GLES context");
|
||||
JREUtils.saveGLContext();
|
||||
|
||||
System.out.println("Launching Minecraft " + mcver);
|
||||
try {
|
||||
Tools.launchMinecraft(acc, verInfo);
|
||||
Tools.launchMinecraft(mAccount, mVersion);
|
||||
} catch (Throwable th) {
|
||||
throw new RuntimeException(th);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package net.kdt.pojavlaunch.uikit;
|
||||
|
||||
import net.kdt.pojavlaunch.PLaunchApp;
|
||||
import org.lwjgl.glfw.*;
|
||||
|
||||
public class UIKit {
|
||||
@@ -7,12 +8,16 @@ public class UIKit {
|
||||
public static final int ACTION_UP = 1;
|
||||
public static final int ACTION_MOVE = 2;
|
||||
|
||||
public static void callback_AppDelegate_didFinishLaunching(int width, int height) {
|
||||
public static void callback_LauncherViewController_installMinecraft() {
|
||||
PLaunchApp.installMinecraft();
|
||||
}
|
||||
|
||||
public static void callback_SurfaceViewController_launchMinecraft(int width, int height) {
|
||||
GLFW.mGLFWWindowWidth = width;
|
||||
GLFW.mGLFWWindowHeight = height;
|
||||
CallbackBridge.mouseX = width / 2;
|
||||
CallbackBridge.mouseY = height / 2;
|
||||
net.kdt.pojavlaunch.PLaunchApp.applicationDidFinishLaunching();
|
||||
launchMinecraft();
|
||||
}
|
||||
|
||||
public static void callback_SurfaceViewController_onTouch(int event, int x, int y) {
|
||||
@@ -40,10 +45,23 @@ public class UIKit {
|
||||
CallbackBridge.sendCursorPos(CallbackBridge.mouseX, CallbackBridge.mouseY);
|
||||
}
|
||||
|
||||
public static void updateProgressSafe(final int percent, final String message) {
|
||||
System.out.println(message);
|
||||
runOnUIThread(() -> {
|
||||
updateProgress(percent, message);
|
||||
});
|
||||
}
|
||||
|
||||
static {
|
||||
System.loadLibrary("pojavexec");
|
||||
}
|
||||
|
||||
public static native int launchUI(String[] uiArgs);
|
||||
public static native void runOnUIThread(UIKitCallback callback);
|
||||
|
||||
// Update progress
|
||||
public static native void updateProgress(int percent, String message);
|
||||
|
||||
// Start SurfaceViewController
|
||||
public static native void launchMinecraftSurface();
|
||||
}
|
||||
Reference in new issue
Block a user