Skip to content

Commit

Permalink
Added more checks for clearing project folders, version 2.1.20
Browse files Browse the repository at this point in the history
  • Loading branch information
emd4600 committed Sep 6, 2020
1 parent 7a04fc0 commit bd05388
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 14 deletions.
12 changes: 5 additions & 7 deletions src/sporemodder/FileManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,11 @@ public static String getExtension(String name) {
* Deletes all the contents of a directory. If the directory does not exist,
* this method does nothing.
*
* @throws UnsupportedOperationException
* @throws IOException
* If there was an error while deleting the contents of the folder.
* @param dir
*/
public void deleteDirectory(File dir) {
public void deleteDirectory(File dir) throws IOException {
if (!dir.exists())
return;

Expand Down Expand Up @@ -123,11 +123,9 @@ public FileVisitResult postVisitDirectory(final Path dir, final IOException e) t
return FileVisitResult.CONTINUE;
}
});
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();

throw new UnsupportedOperationException(e);
}
catch (Exception e) {
throw new IOException(e);
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/sporemodder/HashManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.util.Locale;
import java.util.Properties;

import sporemodder.file.cnv.CnvUnit;
import sporemodder.util.NameRegistry;

/**
Expand Down Expand Up @@ -96,6 +97,8 @@ public void initialize(Properties properties) {
simulatorRegistry.read(PathManager.get().getProgramFile(simulatorRegistry.getFileName()));
}, "The simulator attributes registry (reg_simulator.txt) is corrupt or missing.");

CnvUnit.loadNameRegistry();

registries.put(fileRegistry.getFileName(), fileRegistry);
registries.put(typeRegistry.getFileName(), typeRegistry);
registries.put(propRegistry.getFileName(), propRegistry);
Expand Down
10 changes: 7 additions & 3 deletions src/sporemodder/ProjectManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -1148,7 +1148,7 @@ public boolean hasProject(String name) {
* Be aware, this operation cannot be reverted.
* @param project
*/
public void deleteProject(Project project) {
public void deleteProject(Project project) throws IOException {
FileManager.get().deleteDirectory(project.getFolder());

projects.remove(project.getName().toLowerCase());
Expand All @@ -1162,7 +1162,7 @@ public void deleteProject(Project project) {
* for it. It will delete any previously existing contents in the folder.
* @param project
*/
public void initializeProject(Project project) {
public void initializeProject(Project project) throws IOException {
if (project.getFolder().exists()) {
// Ensure there isn't such folder
FileManager.get().deleteDirectory(project.getFolder());
Expand Down Expand Up @@ -2065,7 +2065,11 @@ public boolean importOldProject() {
}

Project project = getOrCreateProject(projectName);
initializeProject(project);
if (!UIManager.get().tryAction(() -> initializeProject(project),
"Cannot initialize project. Try manually deleting the project folder in SporeModder FX\\Projects\\")) {
UIManager.get().setOverlay(false);
return false;
}

HashManager hasher = HashManager.get();
hasher.setUpdateProjectRegistry(true);
Expand Down
2 changes: 1 addition & 1 deletion src/sporemodder/UpdateManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public class UpdateManager {
*/
public static final TimeZone TIMEZONE = TimeZone.getTimeZone("UTC");

public final VersionInfo versionInfo = new VersionInfo(2, 1, 19, null);
public final VersionInfo versionInfo = new VersionInfo(2, 1, 20, null);

public static UpdateManager get() {
return MainApp.get().getUpdateManager();
Expand Down
10 changes: 9 additions & 1 deletion src/sporemodder/file/dbpf/DBPFUnpackingTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,15 @@ protected Exception call() throws Exception {

if (project != null) {
updateMessage("Clearing folder...");
ProjectManager.get().initializeProject(project);
try {
ProjectManager.get().initializeProject(project);
}
catch (Exception e) {
for (File inputFile : inputFiles) {
failedDBPFs.add(inputFile);
}
return e;
}
incProgress(CLEAR_FOLDER_PROGRESS);

progressFactor -= CLEAR_FOLDER_PROGRESS;
Expand Down
7 changes: 5 additions & 2 deletions src/sporemodder/view/dialogs/CreateProjectUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,11 @@ public static void show() {
}
}

projectManager.initializeProject(project);
projectManager.setActive(project);
if (UIManager.get().tryAction(() -> projectManager.initializeProject(project),
"Cannot initialize project. Try manually deleting the project folder in SporeModder FX\\Projects\\"))
{
projectManager.setActive(project);
}
}
});
}
Expand Down

0 comments on commit bd05388

Please sign in to comment.