From bfb37d74d80ff502e31ba4f80a3b86e2343bb427 Mon Sep 17 00:00:00 2001 From: Downforce Agent Date: Sun, 30 Jun 2024 17:16:28 -0500 Subject: [PATCH] Prevent incompatible mods from being loaded when features are added in the future --- src/MissPiggy.java | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/MissPiggy.java b/src/MissPiggy.java index e380081..bcb7e9e 100644 --- a/src/MissPiggy.java +++ b/src/MissPiggy.java @@ -380,19 +380,24 @@ public class MissPiggy implements ActionListener { ZipFile zipImporterHandler = new ZipFile(selectedFile.getAbsolutePath()); if (zipImporterHandler.isValidZipFile()) { try { - new JSONObject(new ZipFile(selectedFile.getAbsolutePath()).getComment()); // intentionally trigger exception if file is random BS - Path importDestination = Paths.get(System.getProperty("user.home") + "/.firestar/mods/" + JSONObject json = new JSONObject(new ZipFile(selectedFile.getAbsolutePath()).getComment()); // intentionally trigger exception if file is random BS + if ((int)json.get("loaderversion") <= Main.vint) { + Path importDestination = Paths.get(System.getProperty("user.home") + "/.firestar/mods/" + selectedFile.getName() + "_" + Main.Mods.size() + ".zip"); - Files.copy(Paths.get(selectedFile.getPath()), importDestination, StandardCopyOption.REPLACE_EXISTING); - String importDestinationName = importDestination.toFile().getName(); + Files.copy(Paths.get(selectedFile.getPath()), importDestination, StandardCopyOption.REPLACE_EXISTING); + String importDestinationName = importDestination.toFile().getName(); - BufferedWriter bw = new BufferedWriter(new FileWriter(System.getProperty("user.home") + "/.firestar/mods/index", true)); - bw.write(Main.Mods.size() + "=" + importDestinationName); - bw.newLine(); - bw.close(); + BufferedWriter bw = new BufferedWriter(new FileWriter(System.getProperty("user.home") + "/.firestar/mods/index", true)); + bw.write(Main.Mods.size() + "=" + importDestinationName); + bw.newLine(); + bw.close(); - InitializeModListStructure(); - InitializeModListInGUI(); + InitializeModListStructure(); + InitializeModListInGUI(); + } else { + System.out.println("ERROR: This mod requires feature level " + json.get("loaderversion").toString() + ", but you have level " + Main.vint + "."); + JOptionPane.showMessageDialog(frame, "This mod requires feature level " + json.get("loaderversion").toString() + ", but you have level " + Main.vint + ".\nPlease update Firestar to the latest version.", "Error", JOptionPane.ERROR_MESSAGE); + } } catch (JSONException e) { System.out.println("ERROR: File is not a valid ZIP archive with mod data. Aborting."); JOptionPane.showMessageDialog(frame, "Whoops, that's not a valid mod file.", "Error", JOptionPane.ERROR_MESSAGE);