diff --git a/CHANGELOG.md b/CHANGELOG.md index 663562b3..65e3e293 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ This changelog only contains the changes that are unreleased. For changes for in ### Fixes - Creating pack not resetting modloader when switched back to none +- Issue with file downloads for non third party enabled files on CurseForge not working ### Misc - Remove old FTB pack installing code diff --git a/src/main/java/com/atlauncher/data/Instance.java b/src/main/java/com/atlauncher/data/Instance.java index 933310a6..d03e5909 100644 --- a/src/main/java/com/atlauncher/data/Instance.java +++ b/src/main/java/com/atlauncher/data/Instance.java @@ -1387,8 +1387,10 @@ public class Instance extends MinecraftVersion { } dialog.setIndeterminate(); - String filename = file.fileName.replace(" ", "+"); + String filename = file.fileName; + String filename2 = file.fileName.replace(" ", "+"); File fileLocation = downloadLocation.toFile(); + File fileLocation2 = FileSystem.DOWNLOADS.resolve(filename2).toFile(); // if file downloaded already, but hashes don't match, delete it if (fileLocation.exists() && ((md5Hash.isPresent() @@ -1397,15 +1399,25 @@ public class Instance extends MinecraftVersion { && !Hashing.sha1(fileLocation.toPath()) .equals(Hashing.toHashCode(sha1Hash.get().value))))) { FileUtils.delete(fileLocation.toPath()); + } else if (fileLocation2.exists() + && ((md5Hash.isPresent() + && !Hashing.md5(fileLocation2.toPath()).equals(Hashing.toHashCode(md5Hash.get().value))) + || (sha1Hash.isPresent() + && !Hashing.sha1(fileLocation2.toPath()) + .equals(Hashing.toHashCode(sha1Hash.get().value))))) { + FileUtils.delete(fileLocation2.toPath()); } - if (!fileLocation.exists()) { + if (!fileLocation.exists() && !fileLocation2.exists()) { File downloadsFolderFile = new File(FileSystem.getUserDownloadsPath().toFile(), filename); + File downloadsFolderFile2 = new File(FileSystem.getUserDownloadsPath().toFile(), filename2); if (downloadsFolderFile.exists()) { Utils.moveFile(downloadsFolderFile, fileLocation, true); + } else if (downloadsFolderFile.exists()) { + Utils.moveFile(downloadsFolderFile2, fileLocation, true); } - while (!fileLocation.exists()) { + while (!fileLocation.exists() && !fileLocation2.exists()) { int retValue = 1; do { if (retValue == 1) { @@ -1428,7 +1440,8 @@ public class Instance extends MinecraftVersion { .build()) .addOption(GetText.tr("Open Folder"), true) .addOption(GetText.tr("I've Downloaded This File")).setType(DialogManager.INFO) - .showWithFileMonitoring(fileLocation, downloadsFolderFile, file.fileLength, 1); + .showWithFileMonitoring(file.fileLength, 1, fileLocation, fileLocation2, + downloadsFolderFile, downloadsFolderFile2); if (retValue == DialogManager.CLOSED_OPTION) { return; @@ -1437,10 +1450,12 @@ public class Instance extends MinecraftVersion { } } while (retValue != 1); - if (!fileLocation.exists()) { + if (!fileLocation.exists() && !fileLocation2.exists()) { // Check users downloads folder to see if it's there if (downloadsFolderFile.exists()) { Utils.moveFile(downloadsFolderFile, fileLocation, true); + } else if (downloadsFolderFile2.exists()) { + Utils.moveFile(downloadsFolderFile2, fileLocation, true); } // Check to see if a browser has added a .zip to the end of the file File zipAddedFile = FileSystem.DOWNLOADS.resolve(file.fileName + ".zip").toFile(); @@ -1462,6 +1477,13 @@ public class Instance extends MinecraftVersion { && !Hashing.sha1(fileLocation.toPath()) .equals(Hashing.toHashCode(sha1Hash.get().value))))) { FileUtils.delete(fileLocation.toPath()); + } else if (fileLocation2.exists() + && ((md5Hash.isPresent() && !Hashing.md5(fileLocation2.toPath()) + .equals(Hashing.toHashCode(md5Hash.get().value))) + || (sha1Hash.isPresent() + && !Hashing.sha1(fileLocation2.toPath()) + .equals(Hashing.toHashCode(sha1Hash.get().value))))) { + FileUtils.delete(fileLocation2.toPath()); } } } @@ -2592,7 +2614,7 @@ public class Instance extends MinecraftVersion { public boolean isUpdatableExternalPack() { return isExternalPack() && ((isCurseForgePack() - && ConfigManager.getConfigItem("platforms.curseforge.modpacksEnabled", true) == true) + && ConfigManager.getConfigItem("platforms.curseforge.modpacksEnabled", true) == true) || (isTechnicPack() && ConfigManager.getConfigItem("platforms.technic.modpacksEnabled", true) == true) || (isModrinthPack() && ConfigManager.getConfigItem("platforms.modrinth.modpacksEnabled", true) == true)); diff --git a/src/main/java/com/atlauncher/managers/DialogManager.java b/src/main/java/com/atlauncher/managers/DialogManager.java index 0115819b..5bff8e12 100644 --- a/src/main/java/com/atlauncher/managers/DialogManager.java +++ b/src/main/java/com/atlauncher/managers/DialogManager.java @@ -19,6 +19,7 @@ package com.atlauncher.managers; import java.awt.Window; import java.io.File; +import java.util.Arrays; import java.util.LinkedList; import java.util.List; import java.util.Timer; @@ -28,10 +29,10 @@ import javax.swing.Icon; import javax.swing.JDialog; import javax.swing.JOptionPane; -import com.atlauncher.App; - import org.mini2Dx.gettext.GetText; +import com.atlauncher.App; + public final class DialogManager { public static final int OPTION_TYPE = 0; public static final int CONFIRM_TYPE = 1; @@ -196,6 +197,14 @@ public final class DialogManager { } public int showWithFileMonitoring(File firstFile, File secondFile, int size, int returnValue) { + if (secondFile != null) { + return showWithFileMonitoring(size, returnValue, firstFile, secondFile); + } + + return showWithFileMonitoring(size, returnValue, firstFile); + } + + public int showWithFileMonitoring(int size, int returnValue, File... files) { try { Object[] options = this.getOptions(); @@ -206,13 +215,13 @@ public final class DialogManager { jop.setComponentOrientation(this.getParent().getComponentOrientation()); JDialog dialog = jop.createDialog(this.getParent(), this.title); + List filesForMonitoring = Arrays.asList(files); Timer timer = new Timer(); timer.schedule(new TimerTask() { @Override public void run() { - if ((firstFile != null && (firstFile.exists() && firstFile.length() == size)) - || (secondFile != null && (secondFile.exists() && secondFile.length() == size))) { + if (filesForMonitoring.stream().anyMatch(f -> f.exists() && f.length() == size)) { timer.cancel(); jop.setValue(options[returnValue]); dialog.dispose(); diff --git a/src/main/java/com/atlauncher/utils/ImportPackUtils.java b/src/main/java/com/atlauncher/utils/ImportPackUtils.java index 1194a000..d5737a94 100644 --- a/src/main/java/com/atlauncher/utils/ImportPackUtils.java +++ b/src/main/java/com/atlauncher/utils/ImportPackUtils.java @@ -126,17 +126,23 @@ public class ImportPackUtils { .show(); } - String filename = curseFile.fileName.replace(" ", "+"); + String filename = curseFile.fileName; + String filename2 = curseFile.fileName.replace(" ", "+"); File fileLocation = FileSystem.DOWNLOADS.resolve(filename).toFile(); - if (!fileLocation.exists()) { + File fileLocation2 = FileSystem.DOWNLOADS.resolve(filename2).toFile(); + if (!fileLocation.exists() && !fileLocation2.exists()) { File downloadsFolderFile = new File(FileSystem.getUserDownloadsPath().toFile(), filename); + File downloadsFolderFile2 = new File(FileSystem.getUserDownloadsPath().toFile(), + filename2); if (downloadsFolderFile.exists()) { Utils.moveFile(downloadsFolderFile, fileLocation, true); + } else if (downloadsFolderFile2.exists()) { + Utils.moveFile(downloadsFolderFile2, fileLocation, true); } - while (!fileLocation.exists()) { + while (!fileLocation.exists() && !fileLocation2.exists()) { int retValue = 1; do { if (retValue == 1) { @@ -159,8 +165,8 @@ public class ImportPackUtils { .build()) .addOption(GetText.tr("Open Folder"), true) .addOption(GetText.tr("I've Downloaded This File")).setType(DialogManager.INFO) - .showWithFileMonitoring(fileLocation, downloadsFolderFile, - curseFile.fileLength, 1); + .showWithFileMonitoring(curseFile.fileLength, 1, fileLocation, fileLocation2, + downloadsFolderFile, downloadsFolderFile2); if (retValue == DialogManager.CLOSED_OPTION) { return false; @@ -169,16 +175,22 @@ public class ImportPackUtils { } } while (retValue != 1); - if (!fileLocation.exists()) { + if (!fileLocation.exists() && !fileLocation2.exists()) { // Check users downloads folder to see if it's there if (downloadsFolderFile.exists()) { Utils.moveFile(downloadsFolderFile, fileLocation, true); + } else if (downloadsFolderFile2.exists()) { + Utils.moveFile(downloadsFolderFile2, fileLocation, true); } } } } - FileUtils.moveFile(fileLocation.toPath(), tempZip, true); + if (fileLocation.exists()) { + FileUtils.moveFile(fileLocation.toPath(), tempZip, true); + } else if (fileLocation2.exists()) { + FileUtils.moveFile(fileLocation2.toPath(), tempZip, true); + } return loadCurseForgeFormat(tempZip.toFile(), projectId, fileId); } else { diff --git a/src/main/java/com/atlauncher/workers/InstanceInstaller.java b/src/main/java/com/atlauncher/workers/InstanceInstaller.java index 40914393..8f1f121d 100644 --- a/src/main/java/com/atlauncher/workers/InstanceInstaller.java +++ b/src/main/java/com/atlauncher/workers/InstanceInstaller.java @@ -30,7 +30,6 @@ import java.nio.file.StandardOpenOption; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; -import java.util.Comparator; import java.util.HashMap; import java.util.List; import java.util.Locale; @@ -38,7 +37,6 @@ import java.util.Map; import java.util.Optional; import java.util.Set; import java.util.UUID; -import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -136,7 +134,6 @@ import com.atlauncher.utils.Utils; import com.atlauncher.utils.walker.CaseFileVisitor; import com.google.gson.reflect.TypeToken; -import okhttp3.CacheControl; import okhttp3.OkHttpClient; public class InstanceInstaller extends SwingWorker implements NetworkProgressable { @@ -418,17 +415,23 @@ public class InstanceInstaller extends SwingWorker implements Net .show(); } - String filename = version._curseForgeFile.fileName.replace(" ", "+"); + String filename = version._curseForgeFile.fileName; + String filename2 = version._curseForgeFile.fileName.replace(" ", "+"); File fileLocation = FileSystem.DOWNLOADS.resolve(filename).toFile(); - if (!fileLocation.exists()) { + File fileLocation2 = FileSystem.DOWNLOADS.resolve(filename2).toFile(); + if (!fileLocation.exists() && !fileLocation2.exists()) { File downloadsFolderFile = new File(FileSystem.getUserDownloadsPath().toFile(), filename); + File downloadsFolderFile2 = new File(FileSystem.getUserDownloadsPath().toFile(), + filename2); if (downloadsFolderFile.exists()) { Utils.moveFile(downloadsFolderFile, fileLocation, true); + } else if (downloadsFolderFile2.exists()) { + Utils.moveFile(downloadsFolderFile2, fileLocation, true); } - while (!fileLocation.exists()) { + while (!fileLocation.exists() && !fileLocation2.exists()) { int retValue = 1; do { if (retValue == 1) { @@ -451,8 +454,8 @@ public class InstanceInstaller extends SwingWorker implements Net .build()) .addOption(GetText.tr("Open Folder"), true) .addOption(GetText.tr("I've Downloaded This File")).setType(DialogManager.INFO) - .showWithFileMonitoring(fileLocation, downloadsFolderFile, - version._curseForgeFile.fileLength, 1); + .showWithFileMonitoring(version._curseForgeFile.fileLength, 1, fileLocation, + fileLocation2, downloadsFolderFile, downloadsFolderFile2); if (retValue == DialogManager.CLOSED_OPTION) { return; @@ -461,16 +464,22 @@ public class InstanceInstaller extends SwingWorker implements Net } } while (retValue != 1); - if (!fileLocation.exists()) { + if (!fileLocation.exists() && !fileLocation2.exists()) { // Check users downloads folder to see if it's there if (downloadsFolderFile.exists()) { Utils.moveFile(downloadsFolderFile, fileLocation, true); + } else if (downloadsFolderFile2.exists()) { + Utils.moveFile(downloadsFolderFile2, fileLocation, true); } } } } - FileUtils.moveFile(fileLocation.toPath(), serverPackFile, true); + if (fileLocation.exists()) { + FileUtils.moveFile(fileLocation.toPath(), serverPackFile, true); + } else if (fileLocation2.exists()) { + FileUtils.moveFile(fileLocation2.toPath(), serverPackFile, true); + } } else { com.atlauncher.network.Download serverPackDownload = com.atlauncher.network.Download.build() .setUrl(version._curseForgeFile.downloadUrl).downloadTo(serverPackFile) @@ -878,17 +887,23 @@ public class InstanceInstaller extends SwingWorker implements Net .show(); } - String filename = version._curseForgeFile.fileName.replace(" ", "+"); + String filename = version._curseForgeFile.fileName; + String filename2 = version._curseForgeFile.fileName.replace(" ", "+"); File fileLocation = FileSystem.DOWNLOADS.resolve(filename).toFile(); - if (!fileLocation.exists()) { + File fileLocation2 = FileSystem.DOWNLOADS.resolve(filename2).toFile(); + if (!fileLocation.exists() && !fileLocation2.exists()) { File downloadsFolderFile = new File(FileSystem.getUserDownloadsPath().toFile(), filename); + File downloadsFolderFile2 = new File(FileSystem.getUserDownloadsPath().toFile(), + filename2); if (downloadsFolderFile.exists()) { Utils.moveFile(downloadsFolderFile, fileLocation, true); + } else if (downloadsFolderFile2.exists()) { + Utils.moveFile(downloadsFolderFile2, fileLocation, true); } - while (!fileLocation.exists()) { + while (!fileLocation.exists() && !fileLocation2.exists()) { int retValue = 1; do { if (retValue == 1) { @@ -911,8 +926,9 @@ public class InstanceInstaller extends SwingWorker implements Net .build()) .addOption(GetText.tr("Open Folder"), true) .addOption(GetText.tr("I've Downloaded This File")).setType(DialogManager.INFO) - .showWithFileMonitoring(fileLocation, downloadsFolderFile, - version._curseForgeFile.fileLength, 1); + .showWithFileMonitoring(version._curseForgeFile.fileLength, 1, fileLocation, + fileLocation2, + downloadsFolderFile, downloadsFolderFile2); if (retValue == DialogManager.CLOSED_OPTION) { return; @@ -921,16 +937,22 @@ public class InstanceInstaller extends SwingWorker implements Net } } while (retValue != 1); - if (!fileLocation.exists()) { + if (!fileLocation.exists() && !fileLocation2.exists()) { // Check users downloads folder to see if it's there if (downloadsFolderFile.exists()) { Utils.moveFile(downloadsFolderFile, fileLocation, true); + } else if (downloadsFolderFile2.exists()) { + Utils.moveFile(downloadsFolderFile2, fileLocation, true); } } } } - FileUtils.moveFile(fileLocation.toPath(), manifestFile, true); + if (fileLocation.exists()) { + FileUtils.moveFile(fileLocation.toPath(), manifestFile, true); + } else if (fileLocation2.exists()) { + FileUtils.moveFile(fileLocation2.toPath(), manifestFile, true); + } } else { com.atlauncher.network.Download manifestDownload = com.atlauncher.network.Download.build() .setUrl(version._curseForgeFile.downloadUrl).downloadTo(manifestFile)