From bd05388382722d52e77131aa47c876c8f92aa5f4 Mon Sep 17 00:00:00 2001 From: emd4600 Date: Sun, 6 Sep 2020 13:58:45 +0200 Subject: [PATCH] Added more checks for clearing project folders, version 2.1.20 --- src/sporemodder/FileManager.java | 12 +++++------- src/sporemodder/HashManager.java | 3 +++ src/sporemodder/ProjectManager.java | 10 +++++++--- src/sporemodder/UpdateManager.java | 2 +- src/sporemodder/file/dbpf/DBPFUnpackingTask.java | 10 +++++++++- src/sporemodder/view/dialogs/CreateProjectUI.java | 7 +++++-- 6 files changed, 30 insertions(+), 14 deletions(-) diff --git a/src/sporemodder/FileManager.java b/src/sporemodder/FileManager.java index 8f90f20..5b00fd3 100644 --- a/src/sporemodder/FileManager.java +++ b/src/sporemodder/FileManager.java @@ -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; @@ -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); } } diff --git a/src/sporemodder/HashManager.java b/src/sporemodder/HashManager.java index 461804c..ebc659f 100644 --- a/src/sporemodder/HashManager.java +++ b/src/sporemodder/HashManager.java @@ -25,6 +25,7 @@ import java.util.Locale; import java.util.Properties; +import sporemodder.file.cnv.CnvUnit; import sporemodder.util.NameRegistry; /** @@ -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); diff --git a/src/sporemodder/ProjectManager.java b/src/sporemodder/ProjectManager.java index 9bff037..d9168d0 100644 --- a/src/sporemodder/ProjectManager.java +++ b/src/sporemodder/ProjectManager.java @@ -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()); @@ -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()); @@ -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); diff --git a/src/sporemodder/UpdateManager.java b/src/sporemodder/UpdateManager.java index 29909cf..0d71ae7 100644 --- a/src/sporemodder/UpdateManager.java +++ b/src/sporemodder/UpdateManager.java @@ -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(); diff --git a/src/sporemodder/file/dbpf/DBPFUnpackingTask.java b/src/sporemodder/file/dbpf/DBPFUnpackingTask.java index a62c997..a5d26f3 100644 --- a/src/sporemodder/file/dbpf/DBPFUnpackingTask.java +++ b/src/sporemodder/file/dbpf/DBPFUnpackingTask.java @@ -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; diff --git a/src/sporemodder/view/dialogs/CreateProjectUI.java b/src/sporemodder/view/dialogs/CreateProjectUI.java index 6afa62e..322efe7 100644 --- a/src/sporemodder/view/dialogs/CreateProjectUI.java +++ b/src/sporemodder/view/dialogs/CreateProjectUI.java @@ -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); + } } }); }