Skip to content

Commit

Permalink
feat: Allow users to disable cleanups of server packs and downloaded …
Browse files Browse the repository at this point in the history
…CurseForge modpacks. Can save bandwidth, time and disk operations, if the user is interested in that.
  • Loading branch information
Griefed committed Sep 1, 2021
1 parent aa647f7 commit 3155af4
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand All @@ -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;
}

/**
Expand Down Expand Up @@ -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;
}
Expand Down
4 changes: 3 additions & 1 deletion backend/main/resources/serverpackcreator.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
de.griefed.serverpackcreator.dir.serverpacks=server-packs
de.griefed.serverpackcreator.curseforgecleanup.enabled=true
de.griefed.serverpackcreator.serverpackcleanup.enabled=true
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 3 additions & 1 deletion root/defaults/serverpackcreator.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
de.griefed.serverpackcreator.dir.serverpacks=server-packs
de.griefed.serverpackcreator.curseforgecleanup.enabled=true
de.griefed.serverpackcreator.serverpackcleanup.enabled=true

0 comments on commit 3155af4

Please sign in to comment.