Prevent incompatible mods from being loaded when features are added in the future

This commit is contained in:
Downforce Agent 2024-06-30 17:16:28 -05:00
parent 0a9d8d1bfd
commit bfb37d74d8

View File

@ -380,7 +380,8 @@ public class MissPiggy implements ActionListener {
ZipFile zipImporterHandler = new ZipFile(selectedFile.getAbsolutePath()); ZipFile zipImporterHandler = new ZipFile(selectedFile.getAbsolutePath());
if (zipImporterHandler.isValidZipFile()) { if (zipImporterHandler.isValidZipFile()) {
try { try {
new JSONObject(new ZipFile(selectedFile.getAbsolutePath()).getComment()); // intentionally trigger exception if file is random BS 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/" Path importDestination = Paths.get(System.getProperty("user.home") + "/.firestar/mods/"
+ selectedFile.getName() + "_" + Main.Mods.size() + ".zip"); + selectedFile.getName() + "_" + Main.Mods.size() + ".zip");
Files.copy(Paths.get(selectedFile.getPath()), importDestination, StandardCopyOption.REPLACE_EXISTING); Files.copy(Paths.get(selectedFile.getPath()), importDestination, StandardCopyOption.REPLACE_EXISTING);
@ -393,6 +394,10 @@ public class MissPiggy implements ActionListener {
InitializeModListStructure(); InitializeModListStructure();
InitializeModListInGUI(); 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) { } catch (JSONException e) {
System.out.println("ERROR: File is not a valid ZIP archive with mod data. Aborting."); 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); JOptionPane.showMessageDialog(frame, "Whoops, that's not a valid mod file.", "Error", JOptionPane.ERROR_MESSAGE);