fix: issue with file downloads for non third party enabled files on CurseForge not working

This commit is contained in:
Ryan Dowling 2024-02-02 19:48:23 +11:00
parent 859e033503
commit 52fabe35ae
No known key found for this signature in database
GPG key ID: 5539FCDB88950EFD
5 changed files with 100 additions and 34 deletions

View file

@ -9,6 +9,7 @@ This changelog only contains the changes that are unreleased. For changes for in
### Fixes ### Fixes
- Creating pack not resetting modloader when switched back to none - 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 ### Misc
- Remove old FTB pack installing code - Remove old FTB pack installing code

View file

@ -1387,8 +1387,10 @@ public class Instance extends MinecraftVersion {
} }
dialog.setIndeterminate(); dialog.setIndeterminate();
String filename = file.fileName.replace(" ", "+"); String filename = file.fileName;
String filename2 = file.fileName.replace(" ", "+");
File fileLocation = downloadLocation.toFile(); File fileLocation = downloadLocation.toFile();
File fileLocation2 = FileSystem.DOWNLOADS.resolve(filename2).toFile();
// if file downloaded already, but hashes don't match, delete it // if file downloaded already, but hashes don't match, delete it
if (fileLocation.exists() if (fileLocation.exists()
&& ((md5Hash.isPresent() && ((md5Hash.isPresent()
@ -1397,15 +1399,25 @@ public class Instance extends MinecraftVersion {
&& !Hashing.sha1(fileLocation.toPath()) && !Hashing.sha1(fileLocation.toPath())
.equals(Hashing.toHashCode(sha1Hash.get().value))))) { .equals(Hashing.toHashCode(sha1Hash.get().value))))) {
FileUtils.delete(fileLocation.toPath()); 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 downloadsFolderFile = new File(FileSystem.getUserDownloadsPath().toFile(), filename);
File downloadsFolderFile2 = new File(FileSystem.getUserDownloadsPath().toFile(), filename2);
if (downloadsFolderFile.exists()) { if (downloadsFolderFile.exists()) {
Utils.moveFile(downloadsFolderFile, fileLocation, true); 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; int retValue = 1;
do { do {
if (retValue == 1) { if (retValue == 1) {
@ -1428,7 +1440,8 @@ public class Instance extends MinecraftVersion {
.build()) .build())
.addOption(GetText.tr("Open Folder"), true) .addOption(GetText.tr("Open Folder"), true)
.addOption(GetText.tr("I've Downloaded This File")).setType(DialogManager.INFO) .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) { if (retValue == DialogManager.CLOSED_OPTION) {
return; return;
@ -1437,10 +1450,12 @@ public class Instance extends MinecraftVersion {
} }
} while (retValue != 1); } while (retValue != 1);
if (!fileLocation.exists()) { if (!fileLocation.exists() && !fileLocation2.exists()) {
// Check users downloads folder to see if it's there // Check users downloads folder to see if it's there
if (downloadsFolderFile.exists()) { if (downloadsFolderFile.exists()) {
Utils.moveFile(downloadsFolderFile, fileLocation, true); 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 // 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(); File zipAddedFile = FileSystem.DOWNLOADS.resolve(file.fileName + ".zip").toFile();
@ -1462,6 +1477,13 @@ public class Instance extends MinecraftVersion {
&& !Hashing.sha1(fileLocation.toPath()) && !Hashing.sha1(fileLocation.toPath())
.equals(Hashing.toHashCode(sha1Hash.get().value))))) { .equals(Hashing.toHashCode(sha1Hash.get().value))))) {
FileUtils.delete(fileLocation.toPath()); 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() { public boolean isUpdatableExternalPack() {
return isExternalPack() && ((isCurseForgePack() 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) || (isTechnicPack() && ConfigManager.getConfigItem("platforms.technic.modpacksEnabled", true) == true)
|| (isModrinthPack() || (isModrinthPack()
&& ConfigManager.getConfigItem("platforms.modrinth.modpacksEnabled", true) == true)); && ConfigManager.getConfigItem("platforms.modrinth.modpacksEnabled", true) == true));

View file

@ -19,6 +19,7 @@ package com.atlauncher.managers;
import java.awt.Window; import java.awt.Window;
import java.io.File; import java.io.File;
import java.util.Arrays;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Timer; import java.util.Timer;
@ -28,10 +29,10 @@ import javax.swing.Icon;
import javax.swing.JDialog; import javax.swing.JDialog;
import javax.swing.JOptionPane; import javax.swing.JOptionPane;
import com.atlauncher.App;
import org.mini2Dx.gettext.GetText; import org.mini2Dx.gettext.GetText;
import com.atlauncher.App;
public final class DialogManager { public final class DialogManager {
public static final int OPTION_TYPE = 0; public static final int OPTION_TYPE = 0;
public static final int CONFIRM_TYPE = 1; 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) { 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 { try {
Object[] options = this.getOptions(); Object[] options = this.getOptions();
@ -206,13 +215,13 @@ public final class DialogManager {
jop.setComponentOrientation(this.getParent().getComponentOrientation()); jop.setComponentOrientation(this.getParent().getComponentOrientation());
JDialog dialog = jop.createDialog(this.getParent(), this.title); JDialog dialog = jop.createDialog(this.getParent(), this.title);
List<File> filesForMonitoring = Arrays.asList(files);
Timer timer = new Timer(); Timer timer = new Timer();
timer.schedule(new TimerTask() { timer.schedule(new TimerTask() {
@Override @Override
public void run() { public void run() {
if ((firstFile != null && (firstFile.exists() && firstFile.length() == size)) if (filesForMonitoring.stream().anyMatch(f -> f.exists() && f.length() == size)) {
|| (secondFile != null && (secondFile.exists() && secondFile.length() == size))) {
timer.cancel(); timer.cancel();
jop.setValue(options[returnValue]); jop.setValue(options[returnValue]);
dialog.dispose(); dialog.dispose();

View file

@ -126,17 +126,23 @@ public class ImportPackUtils {
.show(); .show();
} }
String filename = curseFile.fileName.replace(" ", "+"); String filename = curseFile.fileName;
String filename2 = curseFile.fileName.replace(" ", "+");
File fileLocation = FileSystem.DOWNLOADS.resolve(filename).toFile(); 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(), File downloadsFolderFile = new File(FileSystem.getUserDownloadsPath().toFile(),
filename); filename);
File downloadsFolderFile2 = new File(FileSystem.getUserDownloadsPath().toFile(),
filename2);
if (downloadsFolderFile.exists()) { if (downloadsFolderFile.exists()) {
Utils.moveFile(downloadsFolderFile, fileLocation, true); 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; int retValue = 1;
do { do {
if (retValue == 1) { if (retValue == 1) {
@ -159,8 +165,8 @@ public class ImportPackUtils {
.build()) .build())
.addOption(GetText.tr("Open Folder"), true) .addOption(GetText.tr("Open Folder"), true)
.addOption(GetText.tr("I've Downloaded This File")).setType(DialogManager.INFO) .addOption(GetText.tr("I've Downloaded This File")).setType(DialogManager.INFO)
.showWithFileMonitoring(fileLocation, downloadsFolderFile, .showWithFileMonitoring(curseFile.fileLength, 1, fileLocation, fileLocation2,
curseFile.fileLength, 1); downloadsFolderFile, downloadsFolderFile2);
if (retValue == DialogManager.CLOSED_OPTION) { if (retValue == DialogManager.CLOSED_OPTION) {
return false; return false;
@ -169,16 +175,22 @@ public class ImportPackUtils {
} }
} while (retValue != 1); } while (retValue != 1);
if (!fileLocation.exists()) { if (!fileLocation.exists() && !fileLocation2.exists()) {
// Check users downloads folder to see if it's there // Check users downloads folder to see if it's there
if (downloadsFolderFile.exists()) { if (downloadsFolderFile.exists()) {
Utils.moveFile(downloadsFolderFile, fileLocation, true); 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); return loadCurseForgeFormat(tempZip.toFile(), projectId, fileId);
} else { } else {

View file

@ -30,7 +30,6 @@ import java.nio.file.StandardOpenOption;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
@ -38,7 +37,6 @@ import java.util.Map;
import java.util.Optional; import java.util.Optional;
import java.util.Set; import java.util.Set;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
@ -136,7 +134,6 @@ import com.atlauncher.utils.Utils;
import com.atlauncher.utils.walker.CaseFileVisitor; import com.atlauncher.utils.walker.CaseFileVisitor;
import com.google.gson.reflect.TypeToken; import com.google.gson.reflect.TypeToken;
import okhttp3.CacheControl;
import okhttp3.OkHttpClient; import okhttp3.OkHttpClient;
public class InstanceInstaller extends SwingWorker<Boolean, Void> implements NetworkProgressable { public class InstanceInstaller extends SwingWorker<Boolean, Void> implements NetworkProgressable {
@ -418,17 +415,23 @@ public class InstanceInstaller extends SwingWorker<Boolean, Void> implements Net
.show(); .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(); 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(), File downloadsFolderFile = new File(FileSystem.getUserDownloadsPath().toFile(),
filename); filename);
File downloadsFolderFile2 = new File(FileSystem.getUserDownloadsPath().toFile(),
filename2);
if (downloadsFolderFile.exists()) { if (downloadsFolderFile.exists()) {
Utils.moveFile(downloadsFolderFile, fileLocation, true); 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; int retValue = 1;
do { do {
if (retValue == 1) { if (retValue == 1) {
@ -451,8 +454,8 @@ public class InstanceInstaller extends SwingWorker<Boolean, Void> implements Net
.build()) .build())
.addOption(GetText.tr("Open Folder"), true) .addOption(GetText.tr("Open Folder"), true)
.addOption(GetText.tr("I've Downloaded This File")).setType(DialogManager.INFO) .addOption(GetText.tr("I've Downloaded This File")).setType(DialogManager.INFO)
.showWithFileMonitoring(fileLocation, downloadsFolderFile, .showWithFileMonitoring(version._curseForgeFile.fileLength, 1, fileLocation,
version._curseForgeFile.fileLength, 1); fileLocation2, downloadsFolderFile, downloadsFolderFile2);
if (retValue == DialogManager.CLOSED_OPTION) { if (retValue == DialogManager.CLOSED_OPTION) {
return; return;
@ -461,16 +464,22 @@ public class InstanceInstaller extends SwingWorker<Boolean, Void> implements Net
} }
} while (retValue != 1); } while (retValue != 1);
if (!fileLocation.exists()) { if (!fileLocation.exists() && !fileLocation2.exists()) {
// Check users downloads folder to see if it's there // Check users downloads folder to see if it's there
if (downloadsFolderFile.exists()) { if (downloadsFolderFile.exists()) {
Utils.moveFile(downloadsFolderFile, fileLocation, true); 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 { } else {
com.atlauncher.network.Download serverPackDownload = com.atlauncher.network.Download.build() com.atlauncher.network.Download serverPackDownload = com.atlauncher.network.Download.build()
.setUrl(version._curseForgeFile.downloadUrl).downloadTo(serverPackFile) .setUrl(version._curseForgeFile.downloadUrl).downloadTo(serverPackFile)
@ -878,17 +887,23 @@ public class InstanceInstaller extends SwingWorker<Boolean, Void> implements Net
.show(); .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(); 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(), File downloadsFolderFile = new File(FileSystem.getUserDownloadsPath().toFile(),
filename); filename);
File downloadsFolderFile2 = new File(FileSystem.getUserDownloadsPath().toFile(),
filename2);
if (downloadsFolderFile.exists()) { if (downloadsFolderFile.exists()) {
Utils.moveFile(downloadsFolderFile, fileLocation, true); 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; int retValue = 1;
do { do {
if (retValue == 1) { if (retValue == 1) {
@ -911,8 +926,9 @@ public class InstanceInstaller extends SwingWorker<Boolean, Void> implements Net
.build()) .build())
.addOption(GetText.tr("Open Folder"), true) .addOption(GetText.tr("Open Folder"), true)
.addOption(GetText.tr("I've Downloaded This File")).setType(DialogManager.INFO) .addOption(GetText.tr("I've Downloaded This File")).setType(DialogManager.INFO)
.showWithFileMonitoring(fileLocation, downloadsFolderFile, .showWithFileMonitoring(version._curseForgeFile.fileLength, 1, fileLocation,
version._curseForgeFile.fileLength, 1); fileLocation2,
downloadsFolderFile, downloadsFolderFile2);
if (retValue == DialogManager.CLOSED_OPTION) { if (retValue == DialogManager.CLOSED_OPTION) {
return; return;
@ -921,16 +937,22 @@ public class InstanceInstaller extends SwingWorker<Boolean, Void> implements Net
} }
} while (retValue != 1); } while (retValue != 1);
if (!fileLocation.exists()) { if (!fileLocation.exists() && !fileLocation2.exists()) {
// Check users downloads folder to see if it's there // Check users downloads folder to see if it's there
if (downloadsFolderFile.exists()) { if (downloadsFolderFile.exists()) {
Utils.moveFile(downloadsFolderFile, fileLocation, true); 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 { } else {
com.atlauncher.network.Download manifestDownload = com.atlauncher.network.Download.build() com.atlauncher.network.Download manifestDownload = com.atlauncher.network.Download.build()
.setUrl(version._curseForgeFile.downloadUrl).downloadTo(manifestFile) .setUrl(version._curseForgeFile.downloadUrl).downloadTo(manifestFile)