Skip to content

Commit

Permalink
Implement Config System
Browse files Browse the repository at this point in the history
  • Loading branch information
CADIndie committed Dec 8, 2024
1 parent 307b13e commit 3ea2c22
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 16 deletions.
12 changes: 0 additions & 12 deletions src/main/java/pojlib/API.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,13 @@

import androidx.annotation.Nullable;

import com.google.gson.JsonObject;

import pojlib.account.MinecraftAccount;
import pojlib.account.Msa;
import pojlib.util.Logger;
import pojlib.util.json.MinecraftInstances;
import pojlib.util.Constants;
import pojlib.account.LoginHelper;

import java.io.IOException;
import java.util.Date;

/**
* This class is the only class used by the launcher to communicate and talk to pojlib. This keeps pojlib and launcher separate.
Expand All @@ -28,25 +24,17 @@ public class API {

public static String msaMessage = "";
public static String model = "Quest";
private static boolean hasQueried = false;
private static JsonObject initialResponse;
public static boolean finishedDownloading = true;
public static boolean ignoreInstanceName;
public static boolean customRAMValue = false;
public static double downloadStatus = 0;
public static String currentDownload = "";
public static String profileImage;
public static String profileName;
public static String profileUUID;
public static String memoryValue = "1800";
public static boolean developerMods;
public static MinecraftAccount currentAcc;
public static boolean isDemoMode;
public static MinecraftInstances.Instance currentInstance;

public static boolean advancedDebugger;


/**
* Add a mod to an instance
*
Expand Down
39 changes: 39 additions & 0 deletions src/main/java/pojlib/util/ConfigUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package pojlib.util;

import java.io.File;
import java.util.ArrayList;

public class ConfigUtil {

public static Config config;
public static File configFile = new File(Constants.CONFIG_PATH);

public static void LoadConfig() {
if (configFile.exists()) {
config = GsonUtils.jsonFileToObject(configFile.getAbsolutePath(), Config.class);
} else {
config = new Config();
GsonUtils.objectToJsonFile(configFile.getAbsolutePath(), config);
}
}

public static void SaveConfig() {
GsonUtils.objectToJsonFile(configFile.getAbsolutePath(), config);
LoadConfig();
}

public static class Config {
public boolean acceptedLegal = false;
public boolean setDevMods = false;
public boolean setCustomRAM = false;
public String customRAMValue = "2048";
public int lastSelectedInstance = 0;
public int lastSelectedAccount = 0;
public ArrayList<Accounts> accounts = new ArrayList<>();
}

public static class Accounts {
public String username;
public String uuid;
}
}
1 change: 1 addition & 0 deletions src/main/java/pojlib/util/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@ public class Constants {
public static String MINOTAR_URL = "https://minotar.net";

public static String USER_HOME = new File(Environment.getExternalStorageDirectory(),"Android/data/com.qcxr.qcxr/files").getAbsolutePath();
public static String CONFIG_PATH = USER_HOME + "/config.json";
}
7 changes: 4 additions & 3 deletions src/main/java/pojlib/util/JREUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,10 @@ public static int launchJavaVM(final Activity activity, final List<String> JVMAr

//Add automatically generated args

if (API.customRAMValue) {
userArgs.add("-Xms" + API.memoryValue + "M");
userArgs.add("-Xmx" + API.memoryValue + "M");
// TODO: Let user set Xmx AND Xms
if (ConfigUtil.config.setCustomRAM) {
userArgs.add("-Xms" + ConfigUtil.config.customRAMValue + "M");
userArgs.add("-Xmx" + ConfigUtil.config.customRAMValue + "M");
} else {
if (API.model.equals("Meta Quest Pro") || API.model.equals("Oculus Headset1")) {
userArgs.add("-Xms" + 2048 + "M");
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/pojlib/util/json/MinecraftInstances.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import pojlib.account.MinecraftAccount;
import pojlib.API;
import pojlib.InstanceHandler;
import pojlib.util.ConfigUtil;
import pojlib.util.Constants;
import pojlib.util.download.DownloadManager;
import pojlib.util.download.DownloadUtils;
Expand Down Expand Up @@ -77,7 +78,7 @@ private ModsJson parseModsJson(String jsonPath) {

private ModsJson downloadCurrentModsJson(String userHome) throws Exception {
File mods = new File(userHome + "/new_mods.json");
if(API.developerMods) {
if(ConfigUtil.config.setDevMods) {
DownloadUtils.downloadFile(InstanceHandler.DEV_MODS, mods, new DownloadManager(1));
} else {
DownloadUtils.downloadFile(InstanceHandler.MODS, mods, new DownloadManager(1));
Expand Down

0 comments on commit 3ea2c22

Please sign in to comment.