From 8cc7fca35c7be7779b20ab54e848d0c71638529c Mon Sep 17 00:00:00 2001 From: Downforce Agent Date: Sat, 29 Jun 2024 13:20:23 -0500 Subject: [PATCH] fault tolerance for delete --- src/MissPiggy.java | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/MissPiggy.java b/src/MissPiggy.java index 20afb69..c6448ef 100644 --- a/src/MissPiggy.java +++ b/src/MissPiggy.java @@ -119,6 +119,7 @@ public class MissPiggy implements ActionListener { fileMenu.getItem(5).addActionListener(this); toolsMenu.getItem(0).addActionListener(this); toolsMenu.getItem(1).addActionListener(this); + toolsMenu.getItem(2).addActionListener(this); helpMenu.getItem(0).addActionListener(this); deployButton.addActionListener(this); @@ -258,6 +259,10 @@ public class MissPiggy implements ActionListener { if (actionEvent.getSource() == toggleButton) {throwUnimplemented();} else // todo if (actionEvent.getSource() == deleteButton1) {deleteSelected();} else + if (actionEvent.getSource() == toolsMenu.getItem(0)) {throwUnimplemented();} else + if (actionEvent.getSource() == toolsMenu.getItem(1)) {throwUnimplemented();} else + if (actionEvent.getSource() == toolsMenu.getItem(2)) {throwUnimplemented();} else + if (actionEvent.getSource() == helpMenu.getItem(0)) {new Rowlf().displayAboutScreen();} } @@ -339,11 +344,15 @@ public class MissPiggy implements ActionListener { } public void deleteSelected() { - File file = new File(System.getProperty("user.home") + "/.firestar/mods/" + Main.Mods.get(modList.getSelectedIndex()).path); - file.delete(); - System.out.println("Deleted " + Main.Mods.get(modList.getSelectedIndex()).friendlyName); //debug - Main.Mods.remove(modList.getSelectedIndex()); - regenerateModIndex(true); + if (modList.getSelectedIndex() >= 0) { + File file = new File(System.getProperty("user.home") + "/.firestar/mods/" + Main.Mods.get(modList.getSelectedIndex()).path); + file.delete(); + System.out.println("Deleted " + Main.Mods.get(modList.getSelectedIndex()).friendlyName); //debug + Main.Mods.remove(modList.getSelectedIndex()); + regenerateModIndex(true); + } else { + JOptionPane.showMessageDialog(frame, "Please select a mod to delete first.", "Error", JOptionPane.ERROR_MESSAGE); + } } public void generatorGUI() {