fix ghost files on windows

This commit is contained in:
Downforce Agent 2024-06-30 06:49:00 -05:00
parent 679b4bc68e
commit f6b8eeb29e

View File

@ -47,6 +47,8 @@ import static java.nio.file.StandardCopyOption.*;
import static javax.swing.WindowConstants.EXIT_ON_CLOSE; import static javax.swing.WindowConstants.EXIT_ON_CLOSE;
public class MissPiggy implements ActionListener { public class MissPiggy implements ActionListener {
private final String sl = File.separator;
BufferedImage windowIcon; BufferedImage windowIcon;
JFrame frame = new JFrame(); JFrame frame = new JFrame();
JPanel frameContainer; JPanel frameContainer;
@ -191,8 +193,11 @@ public class MissPiggy implements ActionListener {
06/29/24 - also skip files that were manually removed but remain in the list 06/29/24 - also skip files that were manually removed but remain in the list
*/ */
File mod = new File(System.getProperty("user.home") + sl + ".firestar" + sl + "mods" + sl + s.substring(s.indexOf("=") + 1).trim());
if (s.split("=")[0].matches("[0-9]+=*") && if (s.split("=")[0].matches("[0-9]+=*") &&
new File(System.getProperty("user.home") + "/.firestar/mods/" + s.substring(s.indexOf("=") + 1)).exists()) { mod.exists()) {
//append mod to list from substring //append mod to list from substring
Main.Mod m = new Main().new Mod(); Main.Mod m = new Main().new Mod();
m.path = s.substring(s.indexOf("=") + 1); m.path = s.substring(s.indexOf("=") + 1);
@ -201,7 +206,7 @@ public class MissPiggy implements ActionListener {
//get json metadata from zip comment //get json metadata from zip comment
JSONObject metadata; JSONObject metadata;
try { try {
metadata = new JSONObject(new ZipFile(System.getProperty("user.home") + "/.firestar/mods/" + m.path).getComment()); metadata = new JSONObject(new ZipFile(System.getProperty("user.home") + sl + ".firestar" + sl + "mods" + sl + m.path.trim()).getComment());
if (metadata.has("friendlyName")) {m.friendlyName = metadata.get("friendlyName").toString();} else {m.friendlyName = m.path;} if (metadata.has("friendlyName")) {m.friendlyName = metadata.get("friendlyName").toString();} else {m.friendlyName = m.path;}
if (metadata.has("description")) {m.description = metadata.get("description").toString();} if (metadata.has("description")) {m.description = metadata.get("description").toString();}
if (metadata.has("version")) {m.version = Integer.parseInt(metadata.get("version").toString());} if (metadata.has("version")) {m.version = Integer.parseInt(metadata.get("version").toString());}
@ -213,6 +218,7 @@ public class MissPiggy implements ActionListener {
Main.Mods.add(m); Main.Mods.add(m);
} catch (Exception e) { } catch (Exception e) {
System.out.println("WARNING: mod entry for " + s + " was found but does not contain valid JSON metadata. skipping"); System.out.println("WARNING: mod entry for " + s + " was found but does not contain valid JSON metadata. skipping");
System.out.println(e.getMessage());
} }
} else { } else {
if (!s.isEmpty()) {System.out.println("WARNING: mod entry for " + s + " doesn't actually exist. skipping");} if (!s.isEmpty()) {System.out.println("WARNING: mod entry for " + s + " doesn't actually exist. skipping");}