fault tolerance for delete

This commit is contained in:
Downforce Agent 2024-06-29 13:20:23 -05:00
parent 6078cb3bec
commit 8cc7fca35c

View File

@ -119,6 +119,7 @@ public class MissPiggy implements ActionListener {
fileMenu.getItem(5).addActionListener(this); fileMenu.getItem(5).addActionListener(this);
toolsMenu.getItem(0).addActionListener(this); toolsMenu.getItem(0).addActionListener(this);
toolsMenu.getItem(1).addActionListener(this); toolsMenu.getItem(1).addActionListener(this);
toolsMenu.getItem(2).addActionListener(this);
helpMenu.getItem(0).addActionListener(this); helpMenu.getItem(0).addActionListener(this);
deployButton.addActionListener(this); deployButton.addActionListener(this);
@ -258,6 +259,10 @@ public class MissPiggy implements ActionListener {
if (actionEvent.getSource() == toggleButton) {throwUnimplemented();} else // todo if (actionEvent.getSource() == toggleButton) {throwUnimplemented();} else // todo
if (actionEvent.getSource() == deleteButton1) {deleteSelected();} else 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();} if (actionEvent.getSource() == helpMenu.getItem(0)) {new Rowlf().displayAboutScreen();}
} }
@ -339,11 +344,15 @@ public class MissPiggy implements ActionListener {
} }
public void deleteSelected() { public void deleteSelected() {
File file = new File(System.getProperty("user.home") + "/.firestar/mods/" + Main.Mods.get(modList.getSelectedIndex()).path); if (modList.getSelectedIndex() >= 0) {
file.delete(); File file = new File(System.getProperty("user.home") + "/.firestar/mods/" + Main.Mods.get(modList.getSelectedIndex()).path);
System.out.println("Deleted " + Main.Mods.get(modList.getSelectedIndex()).friendlyName); //debug file.delete();
Main.Mods.remove(modList.getSelectedIndex()); System.out.println("Deleted " + Main.Mods.get(modList.getSelectedIndex()).friendlyName); //debug
regenerateModIndex(true); 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() { public void generatorGUI() {