Skip to content

Commit 082ea21

Browse files
committed
Remove deleted projects from list when creating a new mod
1 parent e3ff96e commit 082ea21

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

src/sporemodder/ProjectManager.java

+4
Original file line numberDiff line numberDiff line change
@@ -2334,4 +2334,8 @@ public void createNewProjectInMod(ModBundle modBundle, String projectName, List<
23342334
assert modBundle != null;
23352335
createNewProjectCommon(modBundle, projectName, presets);
23362336
}
2337+
2338+
public void removeInexistantMods() {
2339+
modBundles.removeInexistantMods();
2340+
}
23372341
}

src/sporemodder/util/ModBundlesList.java

+36
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import org.xml.sax.SAXException;
44
import sporemodder.PathManager;
5+
import sporemodder.ProjectManager;
56

67
import javax.xml.parsers.ParserConfigurationException;
78
import javax.xml.transform.TransformerException;
@@ -73,6 +74,41 @@ public void loadList() {
7374
}
7475
}
7576

77+
/**
78+
* Reads the mod bundles file again, and removes from the list any mod bundles whose folder
79+
* no longer exists.
80+
*/
81+
public void removeInexistantMods() {
82+
if (!Files.exists(getFile())) {
83+
return;
84+
}
85+
try {
86+
Files.readAllLines(getFile()).forEach(line -> {
87+
File modFolder;
88+
if (line.contains("/") || line.contains("\\")) {
89+
// External mod folder
90+
modFolder = new File(line);
91+
} else {
92+
// Normal mod inside SMFX Projects
93+
modFolder = new File(PathManager.get().getProjectsFolder(), line);
94+
}
95+
if (!modFolder.exists()) {
96+
for (Project project : modBundles.get(modFolder.getName().toLowerCase()).getProjects()) {
97+
try {
98+
ProjectManager.get().deleteProject(project);
99+
} catch (IOException e) {
100+
e.printStackTrace();
101+
}
102+
}
103+
modBundles.remove(modFolder.getName().toLowerCase());
104+
}
105+
});
106+
saveList();
107+
} catch (Exception e) {
108+
System.err.println("Failed to prune mod bundles list: " + e.getMessage());
109+
}
110+
}
111+
76112
public void loadModInfos() {
77113
for (ModBundle modBundle : modBundles.values()) {
78114
try {

src/sporemodder/view/dialogs/CreateProjectSimpleUI.java

+2
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ public void createMod() throws IOException, InterruptedException, ParserConfigur
7272
}
7373

7474
public static void show() {
75+
ProjectManager.get().removeInexistantMods();
76+
7577
CreateProjectSimpleUI node = UIManager.get().loadUI("dialogs/CreateProjectSimpleUI");
7678
node.dialog = new Dialog<>();
7779
node.dialog.getDialogPane().setContent(node.getMainNode());

0 commit comments

Comments
 (0)