Skip to content

Commit 8eca16a

Browse files
committed
Minor code rearrangement, fix a bug causing the existing mods folder popup to always be shown when use custom loader is unticked, and check if the mods folder is not empty as a condition of showing the popup
1 parent f88a6ca commit 8eca16a

2 files changed

Lines changed: 43 additions & 45 deletions

File tree

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
org.gradle.jvmargs=-Xmx1G
33

44
# Version and packaging info
5-
version=1.0.2
5+
version=1.0.3
66
maven_group=net.hypercubemc
77
archives_base_name=Iris-Installer
88

src/main/java/net/hypercubemc/iris_installer/Installer.java

Lines changed: 42 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -266,67 +266,63 @@ public void start() {
266266
if (!installDir.exists() || !installDir.isDirectory()) installDir.mkdir();
267267

268268
File modsFolder = getInstallDir().resolve(useCustomLoader ? "iris-reserved" : "mods").toFile();
269-
if (!modsFolder.exists() || !modsFolder.isDirectory()) {
270-
modsFolder.mkdir();
271-
}
269+
File[] modsFolderContents = modsFolder.listFiles();
272270

273-
if (!useCustomLoader) {
274-
int result = JOptionPane.showConfirmDialog(frame,"An existing mods folder was found in the selected game directory. Do you want to update/install iris?", "Mods Folder Detected",
275-
JOptionPane.YES_NO_OPTION,
276-
JOptionPane.QUESTION_MESSAGE);
277-
if (result != JOptionPane.YES_OPTION) {
278-
cancelled = true;
271+
if (modsFolderContents != null) {
272+
boolean isEmpty = modsFolderContents.length == 0;
273+
274+
if (!useCustomLoader && modsFolder.exists() && modsFolder.isDirectory() && !isEmpty) {
275+
int result = JOptionPane.showConfirmDialog(frame,"An existing mods folder was found in the selected game directory. Do you want to update/install iris?", "Mods Folder Detected",
276+
JOptionPane.YES_NO_OPTION,
277+
JOptionPane.QUESTION_MESSAGE);
278+
if (result != JOptionPane.YES_OPTION) {
279+
cancelled = true;
280+
}
279281
}
280-
}
281282

282-
if (cancelled) {
283-
readyAll();
284-
return;
285-
}
283+
if (!cancelled) {
284+
boolean shownOptifineDialog = false;
285+
boolean failedToRemoveOptifine = false;
286286

287-
File[] modsFolderContents = modsFolder.listFiles();
288-
if (modsFolderContents != null) {
289-
boolean shownOptifineDialog = false;
290-
boolean failedToRemoveOptifine = false;
291-
292-
for (File mod : modsFolderContents) {
293-
if (mod.getName().toLowerCase().contains("optifine") || mod.getName().toLowerCase().contains("optifabric")) {
294-
if (!shownOptifineDialog) {
295-
int result = JOptionPane.showOptionDialog(frame,"Optifine was found in your mods folder, but Optifine is incompatible with Iris. Do you want to remove it, or cancel the installation?", "Optifine Detected",
296-
JOptionPane.DEFAULT_OPTION,
297-
JOptionPane.WARNING_MESSAGE, null, new String[]{"Yes", "Cancel"}, "Yes");
298-
299-
shownOptifineDialog = true;
300-
if (result != JOptionPane.YES_OPTION) {
301-
cancelled = true;
302-
break;
287+
for (File mod : modsFolderContents) {
288+
if (mod.getName().toLowerCase().contains("optifine") || mod.getName().toLowerCase().contains("optifabric")) {
289+
if (!shownOptifineDialog) {
290+
int result = JOptionPane.showOptionDialog(frame,"Optifine was found in your mods folder, but Optifine is incompatible with Iris. Do you want to remove it, or cancel the installation?", "Optifine Detected",
291+
JOptionPane.DEFAULT_OPTION,
292+
JOptionPane.WARNING_MESSAGE, null, new String[]{"Yes", "Cancel"}, "Yes");
293+
294+
shownOptifineDialog = true;
295+
if (result != JOptionPane.YES_OPTION) {
296+
cancelled = true;
297+
break;
298+
}
303299
}
304-
}
305300

306-
if (!mod.delete()) failedToRemoveOptifine = true;
301+
if (!mod.delete()) failedToRemoveOptifine = true;
302+
}
307303
}
308-
}
309304

310-
if (failedToRemoveOptifine) {
311-
System.out.println("Failed to delete optifine from mods folder");
312-
JOptionPane.showMessageDialog(frame, "Failed to remove optifine from your mods folder, please make sure your game is closed and try again!", "Failed to remove optifine", JOptionPane.ERROR_MESSAGE);
313-
cancelled = true;
305+
if (failedToRemoveOptifine) {
306+
System.out.println("Failed to delete optifine from mods folder");
307+
JOptionPane.showMessageDialog(frame, "Failed to remove optifine from your mods folder, please make sure your game is closed and try again!", "Failed to remove optifine", JOptionPane.ERROR_MESSAGE);
308+
cancelled = true;
309+
}
314310
}
315311

316-
boolean failedToRemoveIrisOrSodium = false;
317-
318312
if (!cancelled) {
313+
boolean failedToRemoveIrisOrSodium = false;
314+
319315
for (File mod : modsFolderContents) {
320316
if (mod.getName().toLowerCase().contains("iris") || mod.getName().toLowerCase().contains("sodium-fabric")) {
321317
if (!mod.delete()) failedToRemoveIrisOrSodium = true;
322318
}
323319
}
324-
}
325320

326-
if (failedToRemoveIrisOrSodium) {
327-
System.out.println("Failed to remove Iris or Sodium from mods folder to update them!");
328-
JOptionPane.showMessageDialog(frame, "Failed to remove iris and sodium from your mods folder to update them, please make sure your game is closed and try again!", "Failed to prepare mods for update", JOptionPane.ERROR_MESSAGE);
329-
cancelled = true;
321+
if (failedToRemoveIrisOrSodium) {
322+
System.out.println("Failed to remove Iris or Sodium from mods folder to update them!");
323+
JOptionPane.showMessageDialog(frame, "Failed to remove iris and sodium from your mods folder to update them, please make sure your game is closed and try again!", "Failed to prepare mods for update", JOptionPane.ERROR_MESSAGE);
324+
cancelled = true;
325+
}
330326
}
331327
}
332328

@@ -335,6 +331,8 @@ public void start() {
335331
return;
336332
}
337333

334+
if (!modsFolder.exists() || !modsFolder.isDirectory()) modsFolder.mkdir();
335+
338336
boolean installSuccess = installFromZip(saveLocation);
339337
if (installSuccess) {
340338
button.setText("Installation succeeded!");

0 commit comments

Comments
 (0)