fix: issue with file downloads for non third party enabled files on CurseForge not working
This commit is contained in:
parent
859e033503
commit
52fabe35ae
5 changed files with 100 additions and 34 deletions
|
@ -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
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<File> 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();
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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 {
|
||||
|
|
|
@ -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<Boolean, Void> implements NetworkProgressable {
|
||||
|
@ -418,17 +415,23 @@ public class InstanceInstaller extends SwingWorker<Boolean, Void> 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<Boolean, Void> 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<Boolean, Void> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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<Boolean, Void> 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<Boolean, Void> 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<Boolean, Void> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
|
|
Loading…
Reference in a new issue