Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/QuestCraft' into QuestCraft
Browse files Browse the repository at this point in the history
  • Loading branch information
The Judge committed Nov 28, 2023
2 parents f0988a0 + 4f19035 commit 7accc1d
Showing 1 changed file with 0 additions and 97 deletions.
97 changes: 0 additions & 97 deletions lib/src/main/java/pojlib/modmanager/ModManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,72 +28,6 @@ public class ModManager {
private static final ArrayList<String> currentDownloadSlugs = new ArrayList<>();
private static boolean saveStateCalled = false;

public static void init() {
Thread thread = new Thread() {
@Override
public void run() {
try {
JsonObject modManagerJson = GsonUtils.GLOBAL_GSON.fromJson(FileUtil.read(workDir + "/modmanager.json"), JsonObject.class);
modrinthCompat = GsonUtils.GLOBAL_GSON.fromJson(FileUtil.read(workDir + "/modrinth-compat.json"), JsonObject.class);

JsonArray repoList = modManagerJson.getAsJsonArray("repos");

//Init outside to cache version (see Fabric/Quilt.java)
String flVersion = Fabric.getLatestLoaderVersion();

if (!modsJson.exists()) {
state.fabricLoaderVersion = flVersion;
String gameVersion = DownloadUtils.getCompatibleVersions("releases").get(0);
Fabric.downloadJson(gameVersion, flVersion);
String fabricLoaderName = String.format("%s-%s-%s", "fabric-loader", flVersion, gameVersion);
Instance instance = new Instance();
instance.setName(fabricLoaderName);
instance.setGameVersion(gameVersion);
instance.setLoaderVersion(fabricLoaderName);
state.addInstance(instance);

gameVersion = DownloadUtils.getCompatibleVersions("releases").get(1);
Fabric.downloadJson(gameVersion, flVersion);
fabricLoaderName = String.format("%s-%s-%s", "fabric-loader", flVersion, gameVersion);
instance = new Instance();
instance.setName(fabricLoaderName);
instance.setGameVersion(gameVersion);
instance.setLoaderVersion(fabricLoaderName);
state.addInstance(instance);

GsonUtils.objectToJsonFile(modsJson.getPath(), GsonUtils.GLOBAL_GSON.toJson(state)); //Cant use save state cause async issues
} else state = GsonUtils.GLOBAL_GSON.fromJson(FileUtil.read(modsJson.getPath()), pojlib.modmanager.State.class);

//Remove mod metadata if they were deleted manually
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.N) return;
for (Instance instance : state.getInstances()) {
ArrayList<String> purgeList = new ArrayList<>();
File[] modFiles = new File(workDir + "/" + instance.getName()).listFiles();
if (modFiles == null) {
for (ModData mod : instance.getMods()) purgeList.add(mod.slug);
continue;
}

for (ModData mod : instance.getMods()) {
boolean foundMod = false;
for (File modFile : modFiles) {
if (modFile.getName().equals(mod.fileData.filename)) {
foundMod = true;
break;
}
}
if (!foundMod) purgeList.add(mod.slug);
}
instance.getMods().removeIf(mod -> purgeList.contains(mod.slug));
}
} catch (IOException e) {
e.printStackTrace();
}
}
};
thread.start();
}

public static String getModCompat(String platform, String name) {
JsonElement compatLevel = null;
if (platform.equals("modrinth")) compatLevel = modrinthCompat.get(name);
Expand All @@ -116,10 +50,6 @@ public static Instance getInstance(String name) {
return instance;
}

public static String getWorkDir() {
return workDir;
}

//Will only save the state if there is nothing currently happening
public static void saveState() {
Thread thread = new Thread() {
Expand Down Expand Up @@ -148,28 +78,6 @@ public static boolean isDownloading(String slug) {
return currentDownloadSlugs.contains(slug);
}

public static void createInstance(String name, String gameVersion, String loaderType) {
Thread thread = new Thread() {
@Override
public void run() {
String loaderVersion;
if (loaderType.equals("fabric")) {
loaderVersion = Fabric.getLatestLoaderVersion();
Fabric.downloadJson(gameVersion, loaderVersion);
}

String profileName = String.format("%s-%s-%s", loaderType + "-loader", loaderType, gameVersion);
Instance instance = new Instance();
instance.setName(name);
instance.setGameVersion(gameVersion);
instance.setLoaderVersion(profileName);
state.addInstance(instance);
saveState();
}
};
thread.start();
}

public static void addMod(Instance instance, String platform, String slug, String gameVersion) {
Thread thread = new Thread() {
public void run() {
Expand Down Expand Up @@ -206,11 +114,6 @@ public void run() {
thread.start();
}

public static void removeMod(String instanceName, String slug) {
Instance instance = state.getInstance(instanceName);
removeMod(instance, instance.getMod(slug));
}

public static void removeMod(Instance instance, ModData modData) {
File modJar = new File(workDir + "/instances/" + instance.getName() + "/" + modData.fileData.filename);
if (modJar.delete()) {
Expand Down

0 comments on commit 7accc1d

Please sign in to comment.