From 92618f7fcbc13af101ac4774a9b537d8097c6956 Mon Sep 17 00:00:00 2001 From: The Judge Date: Mon, 15 Apr 2024 18:41:23 -0700 Subject: [PATCH 1/5] Fix default mods toggle --- src/main/java/pojlib/instance/MinecraftInstances.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/java/pojlib/instance/MinecraftInstances.java b/src/main/java/pojlib/instance/MinecraftInstances.java index debdd2bb..8b4189e7 100644 --- a/src/main/java/pojlib/instance/MinecraftInstances.java +++ b/src/main/java/pojlib/instance/MinecraftInstances.java @@ -101,10 +101,12 @@ public void updateMods(String gameDir, MinecraftInstances instances) { DownloadUtils.downloadFile(info.download_link, mod); modInfos.add(info); } - for(ModInfo info : version.defaultMods) { - File mod = new File(gameDir + "/mods/" + modsDirName + "/" + info.slug + ".jar"); - DownloadUtils.downloadFile(info.download_link, mod); - modInfos.add(info); + if(defaultMods) { + for (ModInfo info : version.defaultMods) { + File mod = new File(gameDir + "/mods/" + modsDirName + "/" + info.slug + ".jar"); + DownloadUtils.downloadFile(info.download_link, mod); + modInfos.add(info); + } } mods = modInfos.toArray(modInfos.toArray(new ModInfo[0])); GsonUtils.objectToJsonFile(gameDir + "/instances.json", instances); From e03b9748b8599b85e84c16750355cf90755c8697 Mon Sep 17 00:00:00 2001 From: The Judge Date: Mon, 15 Apr 2024 18:51:48 -0700 Subject: [PATCH 2/5] Add imageURL --- src/main/java/pojlib/api/API_V1.java | 7 ++++--- src/main/java/pojlib/instance/InstanceHandler.java | 8 ++------ src/main/java/pojlib/instance/MinecraftInstances.java | 1 + 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/main/java/pojlib/api/API_V1.java b/src/main/java/pojlib/api/API_V1.java index f722460f..387e8cbe 100644 --- a/src/main/java/pojlib/api/API_V1.java +++ b/src/main/java/pojlib/api/API_V1.java @@ -132,17 +132,18 @@ public static boolean deleteInstance(MinecraftInstances instances, MinecraftInst * @param home The base directory where minecraft should be setup * @param useDefaultMods Use QC's default mods for the version (Core mods are automatically included) * @param minecraftVersion The version of minecraft to install + * @param imageURL Modpack image url, nullable * @return A minecraft instance object * @throws IOException Throws if download of library or asset fails */ - public static MinecraftInstances.Instance createNewInstance(Activity activity, MinecraftInstances instances, String instanceName, String home, boolean useDefaultMods, String minecraftVersion, String modsFolderName) throws IOException { + public static MinecraftInstances.Instance createNewInstance(Activity activity, MinecraftInstances instances, String instanceName, String home, boolean useDefaultMods, String minecraftVersion, String modsFolderName, String imageURL) throws IOException { if(ignoreInstanceName) { - return InstanceHandler.create(activity, instances, instanceName, home, useDefaultMods, minecraftVersion, InstanceHandler.ModLoader.Fabric, modsFolderName); + return InstanceHandler.create(activity, instances, instanceName, home, useDefaultMods, minecraftVersion, InstanceHandler.ModLoader.Fabric, modsFolderName, imageURL); } else if (instanceName.contains("/") || instanceName.contains("!")) { throw new IOException("You cannot use special characters (!, /, ., etc) when creating instances."); } else { - return InstanceHandler.create(activity, instances, instanceName, home, useDefaultMods, minecraftVersion, InstanceHandler.ModLoader.Fabric, modsFolderName); + return InstanceHandler.create(activity, instances, instanceName, home, useDefaultMods, minecraftVersion, InstanceHandler.ModLoader.Fabric, modsFolderName, imageURL); } } diff --git a/src/main/java/pojlib/instance/InstanceHandler.java b/src/main/java/pojlib/instance/InstanceHandler.java index 228f922d..c857083b 100644 --- a/src/main/java/pojlib/instance/InstanceHandler.java +++ b/src/main/java/pojlib/instance/InstanceHandler.java @@ -3,13 +3,10 @@ import android.app.Activity; import com.google.common.collect.Lists; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; import java.io.File; import java.io.IOException; import java.util.ArrayList; -import java.util.Arrays; import pojlib.account.MinecraftAccount; import pojlib.api.API_V1; @@ -20,8 +17,6 @@ import pojlib.install.VersionInfo; import pojlib.util.Constants; import pojlib.util.ModInfo; -import pojlib.util.ModsJson; -import pojlib.util.DownloadUtils; import pojlib.util.GsonUtils; import pojlib.util.JREUtils; import pojlib.util.Logger; @@ -45,7 +40,7 @@ public enum ModLoader { } //creates a new instance of a minecraft version, install game + mod loader, stores non login related launch info to json - public static MinecraftInstances.Instance create(Activity activity, MinecraftInstances instances, String instanceName, String gameDir, boolean useDefaultMods, String minecraftVersion, ModLoader modLoader, String modsFolderName) { + public static MinecraftInstances.Instance create(Activity activity, MinecraftInstances instances, String instanceName, String gameDir, boolean useDefaultMods, String minecraftVersion, ModLoader modLoader, String modsFolderName, String imageURL) { File instancesFile = new File(gameDir + "/instances.json"); if (instancesFile.exists()) { for (MinecraftInstances.Instance instance : instances.instances) { @@ -60,6 +55,7 @@ public static MinecraftInstances.Instance create(Activity activity, MinecraftIns MinecraftInstances.Instance instance = new MinecraftInstances.Instance(); instance.instanceName = instanceName; + instance.instanceImageURL = imageURL; instance.versionName = minecraftVersion; instance.gameDir = new File(gameDir).getAbsolutePath(); instance.defaultMods = useDefaultMods; diff --git a/src/main/java/pojlib/instance/MinecraftInstances.java b/src/main/java/pojlib/instance/MinecraftInstances.java index 8b4189e7..28185c24 100644 --- a/src/main/java/pojlib/instance/MinecraftInstances.java +++ b/src/main/java/pojlib/instance/MinecraftInstances.java @@ -35,6 +35,7 @@ public Instance[] toArray() { public static class Instance { public String instanceName; + public String instanceImageURL; public String versionName; public String modsDirName; public String versionType; From 1e3cfc5c5c004b39f9038b844af4213237a82603 Mon Sep 17 00:00:00 2001 From: The Judge Date: Mon, 15 Apr 2024 18:53:15 -0700 Subject: [PATCH 3/5] Fix javadocs --- src/main/java/pojlib/api/API_V1.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/pojlib/api/API_V1.java b/src/main/java/pojlib/api/API_V1.java index 387e8cbe..4fd97575 100644 --- a/src/main/java/pojlib/api/API_V1.java +++ b/src/main/java/pojlib/api/API_V1.java @@ -47,7 +47,7 @@ public class API_V1 { * Add a mod to an instance * * @param instances Acquired from {@link pojlib.api.API_V1#loadAll(String)} - * @param instance Acquired from {@link pojlib.api.API_V1#createNewInstance(Activity, String, String, boolean, String, String)} + * @param instance Acquired from {@link pojlib.api.API_V1#createNewInstance(Activity, MinecraftInstances, String, String, boolean, String, String, String)} * or {@link pojlib.api.API_V1#load(MinecraftInstances, String)} * @param gameDir .minecraft directory * @param name Mod name @@ -62,7 +62,7 @@ public static void addMod(MinecraftInstances instances, MinecraftInstances.Insta /** * Check if an instance has a mod * - * @param instance Acquired from {@link pojlib.api.API_V1#createNewInstance(Activity, String, String, boolean, String, String)} + * @param instance Acquired from {@link pojlib.api.API_V1#createNewInstance(Activity, MinecraftInstances, String, String, boolean, String, String, String)} * or {@link pojlib.api.API_V1#load(MinecraftInstances, String)} * @param name Mod name * @return True if the mod is already in the instance @@ -75,7 +75,7 @@ public static boolean hasMod(MinecraftInstances.Instance instance, String name) * Remove a mod from an instance * * @param instances Acquired from {@link pojlib.api.API_V1#loadAll(String)} - * @param instance Acquired from {@link pojlib.api.API_V1#createNewInstance(Activity, String, String, boolean, String, String)} + * @param instance Acquired from {@link pojlib.api.API_V1#createNewInstance(Activity, MinecraftInstances, String, String, boolean, String, String, String)} * or {@link pojlib.api.API_V1#load(MinecraftInstances, String)} * @param gameDir .minecraft directory * @param name Mod name @@ -161,7 +161,7 @@ public static void updateMods(MinecraftInstances instances, MinecraftInstances.I * * @param activity Android activity object * @param account Account object - * @param instance Instance object from {@link pojlib.api.API_V1#createNewInstance(Activity, String, String, boolean, String, String)} + * @param instance Instance object from {@link pojlib.api.API_V1#createNewInstance(Activity, MinecraftInstances, String, String, boolean, String, String, String)} * or {@link pojlib.api.API_V1#load(MinecraftInstances, String)} */ public static void launchInstance(Activity activity, MinecraftAccount account, MinecraftInstances.Instance instance) { From 49a9357a75e932930d11a9fdec96370ce2f42200 Mon Sep 17 00:00:00 2001 From: The Judge Date: Mon, 15 Apr 2024 18:57:22 -0700 Subject: [PATCH 4/5] Fix actions? --- .github/workflows/gradle.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index 2638bcaa..b6b3aa97 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -29,7 +29,7 @@ jobs: java-version: '17' distribution: 'temurin' - name: Make Gradle wrapper executable - run: chmod +x ./gradlew + run: git lfs pull | chmod +x ./gradlew - name: Build with Gradle uses: gradle/gradle-build-action@v2 with: From e6f34363d5e982849b16650308193bf1a10c7cf5 Mon Sep 17 00:00:00 2001 From: Darien Johnson <84008186+CADIndie@users.noreply.github.com> Date: Wed, 17 Apr 2024 16:50:08 -0400 Subject: [PATCH 5/5] Slightly More Logging --- .../java/pojlib/account/MinecraftAccount.java | 9 ++++-- .../java/pojlib/instance/InstanceHandler.java | 6 ---- src/main/java/pojlib/util/DownloadUtils.java | 28 +------------------ 3 files changed, 7 insertions(+), 36 deletions(-) diff --git a/src/main/java/pojlib/account/MinecraftAccount.java b/src/main/java/pojlib/account/MinecraftAccount.java index 14ecd45a..fabe9f44 100644 --- a/src/main/java/pojlib/account/MinecraftAccount.java +++ b/src/main/java/pojlib/account/MinecraftAccount.java @@ -16,6 +16,7 @@ import pojlib.util.Constants; import pojlib.util.GsonUtils; +import pojlib.util.Logger; public class MinecraftAccount { @@ -37,7 +38,9 @@ public static MinecraftAccount login(String gameDir, String[] response) throws I public static boolean logout(Activity activity) { File accountFile = new File(activity.getFilesDir() + "/accounts/account.json"); - return accountFile.delete(); + File accountCache = new File(Constants.USER_HOME + "/cache_data"); + + return accountFile.delete() && accountCache.delete(); } //Try this before using login - the account will have been saved to disk if previously logged in @@ -54,16 +57,16 @@ public static MinecraftAccount load(String path, @Nullable String newToken, @Nul GsonUtils.objectToJsonFile(path + "/account.json", acc); return acc; } catch (IOException | JSONException e) { + Logger.getInstance().appendToLog("Unable to load account! | " + e); return null; } } public static String getSkinFaceUrl(MinecraftAccount account) { - //TODO: Log this to latestlog.txt for Support staff try { return Constants.MINOTAR_URL + "/helm/" + account.uuid; } catch (NullPointerException e) { - System.out.println("Username not set! Please set your username at Minecraft.net and try again."); + Logger.getInstance().appendToLog("Username likely not set! Please set your username at Minecraft.net and try again. | " + e); return null; } } diff --git a/src/main/java/pojlib/instance/InstanceHandler.java b/src/main/java/pojlib/instance/InstanceHandler.java index c857083b..a5c0cb64 100644 --- a/src/main/java/pojlib/instance/InstanceHandler.java +++ b/src/main/java/pojlib/instance/InstanceHandler.java @@ -79,12 +79,6 @@ public static MinecraftInstances.Instance create(Activity activity, MinecraftIns modLoaderVersionInfo = QuiltMeta.getVersionInfo(quiltVersion, minecraftVersion); break; } - case Forge: - case NeoForge: - { - System.out.println("Error!: You cannot use Forge or NeoForge with QuestCraft!"); - break; - } } VersionInfo minecraftVersionInfo = MinecraftMeta.getVersionInfo(minecraftVersion); diff --git a/src/main/java/pojlib/util/DownloadUtils.java b/src/main/java/pojlib/util/DownloadUtils.java index 88a08609..ad561e02 100644 --- a/src/main/java/pojlib/util/DownloadUtils.java +++ b/src/main/java/pojlib/util/DownloadUtils.java @@ -1,9 +1,5 @@ package pojlib.util; -import android.content.res.AssetManager; - -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; import org.apache.commons.codec.binary.Hex; import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.io.IOUtils; @@ -14,17 +10,10 @@ import java.net.HttpURLConnection; import java.net.URL; import java.nio.file.Files; -import java.util.ArrayList; import java.util.Objects; -import static pojlib.util.FileUtil.read; -import static pojlib.util.GsonUtils.GLOBAL_GSON; - public class DownloadUtils { - public static AssetManager assetManager; - - private static void download(URL url, OutputStream os) throws IOException { final int MAX_RETRIES = 3; int attempts = 0; @@ -96,23 +85,8 @@ public static boolean compareSHA1(File f, String sourceSHA) { else return true; // fake match }catch (IOException e) { - System.out.println("Fake-matching a hash due to a read error: " + e); + Logger.getInstance().appendToLog("Fake-matching a hash due to a read error: " + e); return true; } } - - public static ArrayList getCompatibleVersions(String tag) { - ArrayList versions = new ArrayList<>(); - try { - InputStream stream = assetManager.open("jsons/modmanager.json"); - JsonObject versionsJson = GLOBAL_GSON.fromJson(read(stream), JsonObject.class); - - for (JsonElement version : versionsJson.get("compatible_versions").getAsJsonObject().getAsJsonArray(tag)) { - versions.add(version.getAsString()); - } - } catch (IOException e) { - e.printStackTrace(); - } - return versions; - } }