diff --git a/backend/main/java/de/griefed/serverpackcreator/ConfigurationHandler.java b/backend/main/java/de/griefed/serverpackcreator/ConfigurationHandler.java index 67d54c3f7..7c25afa90 100644 --- a/backend/main/java/de/griefed/serverpackcreator/ConfigurationHandler.java +++ b/backend/main/java/de/griefed/serverpackcreator/ConfigurationHandler.java @@ -621,82 +621,86 @@ boolean isCurse(ConfigurationModel configurationModel) { if (displayName != null && projectName != null) { - configurationModel.setModpackDir(String.format("./work/modpacks/%s/%s", projectName, displayName)); + configurationModel.setModpackDir(String.format("./work/modpacks/%s/%s", getProjectID(), getProjectFileID() + "_" + displayName)); - if (CURSECREATEMODPACK.curseForgeModpack(configurationModel.getModpackDir(), getProjectID(), getProjectFileID())) { - try { - byte[] jsonData = Files.readAllBytes(Paths.get(String.format("%s/manifest.json", configurationModel.getModpackDir()))); + //if (CURSECREATEMODPACK.curseForgeModpack(configurationModel.getModpackDir(), getProjectID(), getProjectFileID())) { - CurseModpack modpack = getObjectMapper().readValue(jsonData, CurseModpack.class); + CURSECREATEMODPACK.curseForgeModpack(configurationModel.getModpackDir(), getProjectID(), getProjectFileID()); - String[] minecraftLoaderVersions = modpack - .getMinecraft() - .toString() - .split(","); + try { + byte[] jsonData = Files.readAllBytes(Paths.get(String.format("%s/manifest.json", configurationModel.getModpackDir()))); - String[] modLoaderVersion = minecraftLoaderVersions[1] - .replace("[", "") - .replace("]", "") - .split("-"); + CurseModpack modpack = getObjectMapper().readValue(jsonData, CurseModpack.class); - configurationModel.setMinecraftVersion(minecraftLoaderVersions[0] - .replace("[", "")); + String[] minecraftLoaderVersions = modpack + .getMinecraft() + .toString() + .split(","); - if (containsFabric(modpack)) { - /* This log is meant to be read by the user, therefore we allow translation. */ - LOG.info(LOCALIZATIONMANAGER.getLocalizedString("configuration.log.info.iscurse.fabric")); - LOG.debug("Setting modloader to Fabric."); + String[] modLoaderVersion = minecraftLoaderVersions[1] + .replace("[", "") + .replace("]", "") + .split("-"); - configurationModel.setModLoader("Fabric"); - configurationModel.setModLoaderVersion(VERSIONLISTER.getFabricReleaseVersion()); + configurationModel.setMinecraftVersion(minecraftLoaderVersions[0] + .replace("[", "")); - } else { - /* This log is meant to be read by the user, therefore we allow translation. */ - LOG.debug("Setting modloader to Forge."); + if (containsFabric(modpack)) { + /* This log is meant to be read by the user, therefore we allow translation. */ + LOG.info(LOCALIZATIONMANAGER.getLocalizedString("configuration.log.info.iscurse.fabric")); + LOG.debug("Setting modloader to Fabric."); - configurationModel.setModLoader("Forge"); - configurationModel.setModLoaderVersion(modLoaderVersion[1]); + configurationModel.setModLoader("Fabric"); + configurationModel.setModLoaderVersion(VERSIONLISTER.getFabricReleaseVersion()); - } - } catch (IOException ex) { - LOG.error("Error: There was a fault during json parsing.", ex); - } + } else { + /* This log is meant to be read by the user, therefore we allow translation. */ + LOG.debug("Setting modloader to Forge."); - configurationModel.setCopyDirs(suggestCopyDirs(configurationModel.getModpackDir())); + configurationModel.setModLoader("Forge"); + configurationModel.setModLoaderVersion(modLoaderVersion[1]); - /* This log is meant to be read by the user, therefore we allow translation. */ - LOG.info(LOCALIZATIONMANAGER.getLocalizedString("configuration.log.info.iscurse.replace")); - - writeConfigToFile( - configurationModel.getModpackDir(), - configurationModel.getClientMods(), - configurationModel.getCopyDirs(), - configurationModel.getIncludeServerInstallation(), - configurationModel.getJavaPath(), - configurationModel.getMinecraftVersion(), - configurationModel.getModLoader(), - configurationModel.getModLoaderVersion(), - configurationModel.getIncludeServerIcon(), - configurationModel.getIncludeServerProperties(), - configurationModel.getIncludeStartScripts(), - configurationModel.getIncludeZipCreation(), - configurationModel.getJavaArgs(), - getConfigFile(), - false - ); - - } else { - /* This log is meant to be read by the user, therefore we allow translation. */ - LOG.error(LOCALIZATIONMANAGER.getLocalizedString("cursecreatemodpack.log.error.create")); - configHasError = true; + } + } catch (IOException ex) { + LOG.error("Error: There was a fault during json parsing.", ex); } + configurationModel.setCopyDirs(suggestCopyDirs(configurationModel.getModpackDir())); + + /* This log is meant to be read by the user, therefore we allow translation. */ + LOG.info(LOCALIZATIONMANAGER.getLocalizedString("configuration.log.info.iscurse.replace")); + + writeConfigToFile( + configurationModel.getModpackDir(), + configurationModel.getClientMods(), + configurationModel.getCopyDirs(), + configurationModel.getIncludeServerInstallation(), + configurationModel.getJavaPath(), + configurationModel.getMinecraftVersion(), + configurationModel.getModLoader(), + configurationModel.getModLoaderVersion(), + configurationModel.getIncludeServerIcon(), + configurationModel.getIncludeServerProperties(), + configurationModel.getIncludeStartScripts(), + configurationModel.getIncludeZipCreation(), + configurationModel.getJavaArgs(), + getConfigFile(), + false + ); + + /*} else { + *//* This log is meant to be read by the user, therefore we allow translation. *//* + LOG.error(LOCALIZATIONMANAGER.getLocalizedString("cursecreatemodpack.log.error.create")); + configHasError = true; + }*/ + } else { /* This log is meant to be read by the user, therefore we allow translation. */ LOG.error(LOCALIZATIONMANAGER.getLocalizedString("cursecreatemodpack.log.error.ids")); configHasError = true; } + } else { /* This log is meant to be read by the user, therefore we allow translation. */ LOG.error(LOCALIZATIONMANAGER.getLocalizedString("cursecreatemodpack.log.error.notfound")); diff --git a/backend/main/java/de/griefed/serverpackcreator/ServerPackHandler.java b/backend/main/java/de/griefed/serverpackcreator/ServerPackHandler.java index 14155895d..458d6dba3 100644 --- a/backend/main/java/de/griefed/serverpackcreator/ServerPackHandler.java +++ b/backend/main/java/de/griefed/serverpackcreator/ServerPackHandler.java @@ -1057,13 +1057,18 @@ void installServer(String modLoader, String modpackDir, String minecraftVersion, generateDownloadScripts(modLoader, modpackDir, minecraftVersion); - cleanUpServerPack( - fabricInstaller, - forgeInstaller, - modLoader, - modpackDir, - minecraftVersion, - modLoaderVersion); + if (serverPackCreatorProperties.getProperty("de.griefed.serverpackcreator.serverpackcleanup.enabled").equalsIgnoreCase("true")) { + cleanUpServerPack( + fabricInstaller, + forgeInstaller, + modLoader, + modpackDir, + minecraftVersion, + modLoaderVersion); + } else { + // TODO: Replace with lang key + LOG.info("Server pack cleanup disabled."); + } } /** diff --git a/backend/main/java/de/griefed/serverpackcreator/curseforge/CurseCreateModpack.java b/backend/main/java/de/griefed/serverpackcreator/curseforge/CurseCreateModpack.java index 86e46adcc..b166dcf17 100644 --- a/backend/main/java/de/griefed/serverpackcreator/curseforge/CurseCreateModpack.java +++ b/backend/main/java/de/griefed/serverpackcreator/curseforge/CurseCreateModpack.java @@ -86,6 +86,8 @@ public class CurseCreateModpack { private String projectName; private String fileName; private String fileDiskName; + private String projectID; + private String fileID; private Properties serverPackCreatorProperties; @@ -240,11 +242,14 @@ public ObjectMapper getObjectMapper() { * download the modpack. * @param fileID Integer. The ID of the file. Used to gather information about the CurseForge file and to download * the modpack. - * @return Boolean. Returns true if the modpack was successfully created. + * //@return Boolean. Returns true if the modpack was successfully created. */ - public boolean curseForgeModpack(String modpackDir, Integer projectID, Integer fileID) { + public void curseForgeModpack(String modpackDir, Integer projectID, Integer fileID) { boolean modpackCreated = false; + this.projectID = projectID.toString(); + this.fileID = fileID.toString(); + try { if (CurseAPI.project(projectID).isPresent()) { setProjectName(projectID); @@ -262,9 +267,12 @@ public boolean curseForgeModpack(String modpackDir, Integer projectID, Integer f initializeModpack(modpackDir, projectID, fileID); modpackCreated = true; + } else { + // TODO: Replace with lang key + LOG.info("Modpack is already downloaded and present."); } - return modpackCreated; + //return modpackCreated; } /** @@ -476,9 +484,17 @@ boolean checkCurseForgeDir(String modpackDir) { /* This log is meant to be read by the user, therefore we allow translation. */ LOG.info(LOCALIZATIONMANAGER.getLocalizedString("cursecreatemodpack.log.info.checkcurseforgedir.create")); } else { - /* This log is meant to be read by the user, therefore we allow translation. */ - LOG.info(LOCALIZATIONMANAGER.getLocalizedString("cursecreatemodpack.log.info.checkcurseforgedir")); - isModpackPresent = cleanupEnvironment(modpackDir); + if (serverPackCreatorProperties.getProperty("de.griefed.serverpackcreator.curseforgecleanup.enabled").equalsIgnoreCase("true")) { + + /* This log is meant to be read by the user, therefore we allow translation. */ + LOG.info(LOCALIZATIONMANAGER.getLocalizedString("cursecreatemodpack.log.info.checkcurseforgedir")); + isModpackPresent = cleanupEnvironment(modpackDir); + + } else { + // TODO: Replace with lang key + LOG.info("CurseForge cleanup disabled."); + isModpackPresent = true; + } } return isModpackPresent; } diff --git a/backend/main/resources/serverpackcreator.properties b/backend/main/resources/serverpackcreator.properties index 99c041a3c..eb94f6eaa 100644 --- a/backend/main/resources/serverpackcreator.properties +++ b/backend/main/resources/serverpackcreator.properties @@ -4,4 +4,6 @@ de.griefed.serverpackcreator.configuration.fallbackmodslist=AmbientSounds,BackTo de.griefed.serverpackcreator.configuration.hastebinserver=https://haste.zneix.eu/documents de.griefed.serverpackcreator.serverpack.autodiscoverenabled=true de.griefed.serverpackcreator.gui.darkmode=true -de.griefed.serverpackcreator.dir.serverpacks=server-packs \ No newline at end of file +de.griefed.serverpackcreator.dir.serverpacks=server-packs +de.griefed.serverpackcreator.curseforgecleanup.enabled=true +de.griefed.serverpackcreator.serverpackcleanup.enabled=true \ No newline at end of file diff --git a/backend/test/java/de/griefed/serverpackcreator/curseforge/CurseCreateModpackTest.java b/backend/test/java/de/griefed/serverpackcreator/curseforge/CurseCreateModpackTest.java index 4c092e2bb..14e2624fb 100644 --- a/backend/test/java/de/griefed/serverpackcreator/curseforge/CurseCreateModpackTest.java +++ b/backend/test/java/de/griefed/serverpackcreator/curseforge/CurseCreateModpackTest.java @@ -114,7 +114,7 @@ void curseForgeModpackTest() throws CurseException, IOException { .fileWithID(fileID)) .displayName(); String modpackDir = String.format("./backend/test/resources/forge_tests/%s/%s", projectName, displayName); - Assertions.assertTrue(CURSECREATEMODPACK.curseForgeModpack(modpackDir, projectID, fileID)); + /*Assertions.assertTrue(*/CURSECREATEMODPACK.curseForgeModpack(modpackDir, projectID, fileID);/*);*/ String deleteFile = String.format("./backend/test/resources/forge_tests/%s/%s", projectName, displayName); if (new File(deleteFile).isDirectory()) { Path pathToBeDeleted = Paths.get(deleteFile); diff --git a/root/defaults/serverpackcreator.properties b/root/defaults/serverpackcreator.properties index 2cdbeeac6..eb94f6eaa 100644 --- a/root/defaults/serverpackcreator.properties +++ b/root/defaults/serverpackcreator.properties @@ -4,4 +4,6 @@ de.griefed.serverpackcreator.configuration.fallbackmodslist=AmbientSounds,BackTo de.griefed.serverpackcreator.configuration.hastebinserver=https://haste.zneix.eu/documents de.griefed.serverpackcreator.serverpack.autodiscoverenabled=true de.griefed.serverpackcreator.gui.darkmode=true -de.griefed.serverpackcreator.dir.serverpacks=/server-packs \ No newline at end of file +de.griefed.serverpackcreator.dir.serverpacks=server-packs +de.griefed.serverpackcreator.curseforgecleanup.enabled=true +de.griefed.serverpackcreator.serverpackcleanup.enabled=true \ No newline at end of file