Skip to content

Commit

Permalink
Remove deleted projects from list when creating a new mod
Browse files Browse the repository at this point in the history
  • Loading branch information
emd4600 committed Oct 16, 2024
1 parent e3ff96e commit 082ea21
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/sporemodder/ProjectManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -2334,4 +2334,8 @@ public void createNewProjectInMod(ModBundle modBundle, String projectName, List<
assert modBundle != null;
createNewProjectCommon(modBundle, projectName, presets);
}

public void removeInexistantMods() {
modBundles.removeInexistantMods();
}
}
36 changes: 36 additions & 0 deletions src/sporemodder/util/ModBundlesList.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions src/sporemodder/view/dialogs/CreateProjectSimpleUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down

0 comments on commit 082ea21

Please sign in to comment.