2 Commits

Author SHA1 Message Date
be3c42d7b4 prevent importing bogus files 2024-06-30 09:09:52 -05:00
59b070214c ignore run scripts 2024-06-30 08:59:01 -05:00
2 changed files with 10 additions and 3 deletions

2
.gitignore vendored
View File

@@ -28,3 +28,5 @@ bin/
### Mac OS ###
.DS_Store
/firestar.zip
/run-linux.sh
/run-win32.bat

View File

@@ -41,6 +41,7 @@ import java.util.Random;
import java.util.regex.Pattern;
import net.lingala.zip4j.*;
import net.lingala.zip4j.exception.ZipException;
import org.json.JSONException;
import org.json.JSONObject;
import static java.nio.file.StandardCopyOption.*;
@@ -365,9 +366,10 @@ public class MissPiggy implements ActionListener {
File selectedFile = fileChooser.getSelectedFile();
System.out.println("Importing selected mod file \"" + selectedFile.getName() + "\"");
ZipFile zipImporterHandler = new ZipFile(selectedFile.getPath());
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/"
+ selectedFile.getName() + "_" + Main.Mods.size() + ".zip");
Files.copy(Paths.get(selectedFile.getPath()), importDestination, StandardCopyOption.REPLACE_EXISTING);
@@ -380,13 +382,16 @@ public class MissPiggy implements ActionListener {
InitializeModListStructure();
InitializeModListInGUI();
} 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);
} catch (Exception e) {
System.out.println(e.getMessage());
JOptionPane.showMessageDialog(frame, "An error has occured.\n" + e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
}
} else {
System.out.println("ERROR: File is not a valid ZIP archive. Aborting.");
JOptionPane.showMessageDialog(frame, "Whoops, that's not a valid ZIP archive.", "Error", JOptionPane.ERROR_MESSAGE);
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);
}
}
}