diff --git a/src/sporemodder/ProjectManager.java b/src/sporemodder/ProjectManager.java index 897d057..32c5bf5 100644 --- a/src/sporemodder/ProjectManager.java +++ b/src/sporemodder/ProjectManager.java @@ -2334,4 +2334,8 @@ public void createNewProjectInMod(ModBundle modBundle, String projectName, List< assert modBundle != null; createNewProjectCommon(modBundle, projectName, presets); } + + public void removeInexistantMods() { + modBundles.removeInexistantMods(); + } } diff --git a/src/sporemodder/util/ModBundlesList.java b/src/sporemodder/util/ModBundlesList.java index e6dc7bb..b5a53dd 100644 --- a/src/sporemodder/util/ModBundlesList.java +++ b/src/sporemodder/util/ModBundlesList.java @@ -2,6 +2,7 @@ import org.xml.sax.SAXException; import sporemodder.PathManager; +import sporemodder.ProjectManager; import javax.xml.parsers.ParserConfigurationException; import javax.xml.transform.TransformerException; @@ -73,6 +74,41 @@ public void loadList() { } } + /** + * Reads the mod bundles file again, and removes from the list any mod bundles whose folder + * no longer exists. + */ + public void removeInexistantMods() { + if (!Files.exists(getFile())) { + return; + } + try { + Files.readAllLines(getFile()).forEach(line -> { + File modFolder; + if (line.contains("/") || line.contains("\\")) { + // External mod folder + modFolder = new File(line); + } else { + // Normal mod inside SMFX Projects + modFolder = new File(PathManager.get().getProjectsFolder(), line); + } + if (!modFolder.exists()) { + for (Project project : modBundles.get(modFolder.getName().toLowerCase()).getProjects()) { + try { + ProjectManager.get().deleteProject(project); + } catch (IOException e) { + e.printStackTrace(); + } + } + modBundles.remove(modFolder.getName().toLowerCase()); + } + }); + saveList(); + } catch (Exception e) { + System.err.println("Failed to prune mod bundles list: " + e.getMessage()); + } + } + public void loadModInfos() { for (ModBundle modBundle : modBundles.values()) { try { diff --git a/src/sporemodder/view/dialogs/CreateProjectSimpleUI.java b/src/sporemodder/view/dialogs/CreateProjectSimpleUI.java index d3ae044..dd2f7cd 100644 --- a/src/sporemodder/view/dialogs/CreateProjectSimpleUI.java +++ b/src/sporemodder/view/dialogs/CreateProjectSimpleUI.java @@ -72,6 +72,8 @@ public void createMod() throws IOException, InterruptedException, ParserConfigur } public static void show() { + ProjectManager.get().removeInexistantMods(); + CreateProjectSimpleUI node = UIManager.get().loadUI("dialogs/CreateProjectSimpleUI"); node.dialog = new Dialog<>(); node.dialog.getDialogPane().setContent(node.getMainNode());