Skip to content

Commit fa753a8

Browse files
committed
Fix mod updating
1 parent e9c0157 commit fa753a8

1 file changed

Lines changed: 65 additions & 65 deletions

File tree

lib/src/main/java/pojlib/instance/MinecraftInstance.java

Lines changed: 65 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -108,81 +108,81 @@ public List<String> generateLaunchArgs(MinecraftAccount account) {
108108
public void updateOrDownloadsMods() {
109109
API_V1.finishedDownloading = false;
110110
new Thread(()->{
111-
try {
112-
File mods = new File(Constants.USER_HOME + "/mods-new.json");
113-
File modsOld = new File(Constants.USER_HOME + "/mods.json");
114-
File customMods = new File(Constants.MC_DIR + "/custom_mods.json");
115-
116-
if (API_V1.developerMods) {
117-
DownloadUtils.downloadFile(DEV_MODS, mods);
118-
} else { DownloadUtils.downloadFile(MODS, mods); }
119-
120-
CustomMods customModsObj = GsonUtils.jsonFileToObject(customMods.getAbsolutePath(), CustomMods.class);
121-
JsonObject obj = GsonUtils.jsonFileToObject(mods.getAbsolutePath(), JsonObject.class);
122-
JsonObject objOld = GsonUtils.jsonFileToObject(modsOld.getAbsolutePath(), JsonObject.class);
123-
124-
ArrayList<String> versions = new ArrayList<>();
125-
ArrayList<String> downloads = new ArrayList<>();
126-
ArrayList<String> name = new ArrayList<>();
127-
128-
JsonArray verMods = obj.getAsJsonArray(this.versionName);
129-
for (JsonElement verMod : verMods) {
130-
JsonObject object = verMod.getAsJsonObject();
131-
versions.add(object.get("version").getAsString());
132-
downloads.add(object.get("download_link").getAsString());
133-
name.add(object.get("slug").getAsString());
134-
}
111+
try {
112+
File mods = new File(Constants.USER_HOME + "/mods-new.json");
113+
File modsOld = new File(Constants.USER_HOME + "/mods.json");
114+
File customMods = new File(Constants.MC_DIR + "/custom_mods.json");
115+
116+
if (API_V1.developerMods) {
117+
DownloadUtils.downloadFile(DEV_MODS, mods);
118+
} else { DownloadUtils.downloadFile(MODS, mods); }
119+
120+
CustomMods customModsObj = GsonUtils.jsonFileToObject(customMods.getAbsolutePath(), CustomMods.class);
121+
JsonObject obj = GsonUtils.jsonFileToObject(mods.getAbsolutePath(), JsonObject.class);
122+
JsonObject objOld = GsonUtils.jsonFileToObject(modsOld.getAbsolutePath(), JsonObject.class);
123+
124+
ArrayList<String> versions = new ArrayList<>();
125+
ArrayList<String> downloads = new ArrayList<>();
126+
ArrayList<String> name = new ArrayList<>();
127+
128+
JsonArray verMods = obj.getAsJsonArray(this.versionName);
129+
for (JsonElement verMod : verMods) {
130+
JsonObject object = verMod.getAsJsonObject();
131+
versions.add(object.get("version").getAsString());
132+
downloads.add(object.get("download_link").getAsString());
133+
name.add(object.get("slug").getAsString());
134+
}
135135

136-
if(modsOld.exists()) {
137-
InputStream stream = Files.newInputStream(mods.toPath());
138-
int size = stream.available();
139-
byte[] buffer = new byte[size];
140-
stream.read(buffer);
141-
stream.close();
142-
FileUtil.write(modsOld.getAbsolutePath(), buffer);
143-
int i = 0;
144-
boolean downloadAll = !(new File(Constants.MC_DIR + "/mods/" + this.versionName).exists());
145-
for (String download : downloads) {
146-
if(!Objects.equals(versions.get(i), ((JsonObject) objOld.getAsJsonArray(versionName).get(i)).getAsJsonPrimitive("version").getAsString()) || downloadAll) {
136+
if(mods.exists()) {
137+
InputStream stream = Files.newInputStream(mods.toPath());
138+
int size = stream.available();
139+
byte[] buffer = new byte[size];
140+
stream.read(buffer);
141+
stream.close();
142+
FileUtil.write(modsOld.getAbsolutePath(), buffer);
143+
int i = 0;
144+
boolean downloadAll = !(new File(Constants.MC_DIR + "/mods/" + this.versionName).exists());
145+
for (String download : downloads) {
146+
if(!versions.get(i).equals(((JsonObject) objOld.getAsJsonArray(versionName).get(i)).getAsJsonPrimitive("version").getAsString()) || downloadAll) {
147+
API_V1.currentDownload = name.get(i);
148+
DownloadUtils.downloadFile(download, new File(Constants.MC_DIR + "/mods/" + this.versionName + "/" + name.get(i) + ".jar"));
149+
}
150+
i++;
151+
}
152+
mods.delete();
153+
} else {
154+
InputStream stream = Files.newInputStream(mods.toPath());
155+
int size = stream.available();
156+
byte[] buffer = new byte[size];
157+
stream.read(buffer);
158+
stream.close();
159+
FileUtil.write(modsOld.getAbsolutePath(), buffer);
160+
int i = 0;
161+
for (String download : downloads) {
147162
API_V1.currentDownload = name.get(i);
148163
DownloadUtils.downloadFile(download, new File(Constants.MC_DIR + "/mods/" + this.versionName + "/" + name.get(i) + ".jar"));
164+
i++;
149165
}
150-
i++;
166+
mods.delete();
151167
}
152-
mods.delete();
153-
} else {
154-
InputStream stream = Files.newInputStream(mods.toPath());
155-
int size = stream.available();
156-
byte[] buffer = new byte[size];
157-
stream.read(buffer);
158-
stream.close();
159-
FileUtil.write(modsOld.getAbsolutePath(), buffer);
160-
int i = 0;
161-
for (String download : downloads) {
162-
API_V1.currentDownload = name.get(i);
163-
DownloadUtils.downloadFile(download, new File(Constants.MC_DIR + "/mods/" + this.versionName + "/" + name.get(i) + ".jar"));
164-
i++;
165-
}
166-
mods.delete();
167-
}
168168

169-
if(customMods.exists()) {
170-
for(CustomMods.InstanceMods instMods : customModsObj.instances) {
171-
if(!instMods.version.equals(this.versionName)) {
172-
continue;
173-
}
174-
for(CustomMods.ModInfo info : instMods.mods) {
175-
API_V1.currentDownload = info.name;
176-
DownloadUtils.downloadFile(info.url, new File(Constants.MC_DIR + "/mods/" + this.versionName + "/" + info.name + ".jar"));
169+
if(customMods.exists()) {
170+
for(CustomMods.InstanceMods instMods : customModsObj.instances) {
171+
if(!instMods.version.equals(this.versionName)) {
172+
continue;
173+
}
174+
for(CustomMods.ModInfo info : instMods.mods) {
175+
API_V1.currentDownload = info.name;
176+
DownloadUtils.downloadFile(info.url, new File(Constants.MC_DIR + "/mods/" + this.versionName + "/" + info.name + ".jar"));
177+
}
177178
}
178179
}
180+
181+
} catch (IOException e) {
182+
e.printStackTrace();
179183
}
180184

181-
} catch (IOException e) {
182-
e.printStackTrace();
183-
}
184-
185-
API_V1.finishedDownloading = true;
185+
API_V1.finishedDownloading = true;
186186
}).start();
187187
}
188188

0 commit comments

Comments
 (0)