mirror of
https://github.com/HMCL-dev/HMCL.git
synced 2025-09-16 15:26:27 -04:00
alt: do not retry when server respond with 404
This commit is contained in:
parent
97e8ff91ea
commit
f84c4310f9
@ -63,8 +63,20 @@ public class AdaptedDownloadProvider implements DownloadProvider {
|
||||
public List<URL> injectURLWithCandidates(String baseURL) {
|
||||
List<DownloadProvider> d = downloadProviderCandidates;
|
||||
List<URL> results = new ArrayList<>(d.size());
|
||||
for (int i = 0; i < d.size(); i++) {
|
||||
results.add(NetworkUtils.toURL(d.get(i).injectURL(baseURL)));
|
||||
for (DownloadProvider downloadProvider : d) {
|
||||
results.add(NetworkUtils.toURL(downloadProvider.injectURL(baseURL)));
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<URL> injectURLsWithCandidates(List<String> urls) {
|
||||
List<DownloadProvider> d = downloadProviderCandidates;
|
||||
List<URL> results = new ArrayList<>(d.size());
|
||||
for (DownloadProvider downloadProvider : d) {
|
||||
for (String baseURL : urls) {
|
||||
results.add(NetworkUtils.toURL(downloadProvider.injectURL(baseURL)));
|
||||
}
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
@ -88,8 +88,8 @@ public final class ForgeBMCLVersionList extends VersionList<ForgeRemoteVersion>
|
||||
+ (StringUtils.isNotBlank(version.getBranch()) ? "-" + version.getBranch() : "");
|
||||
String fileName1 = "forge-" + classifier + "-" + file.getCategory() + "." + file.getFormat();
|
||||
String fileName2 = "forge-" + classifier + "-" + gameVersion + "-" + file.getCategory() + "." + file.getFormat();
|
||||
urls.add("https://files.minecraftforge.net/maven/net/minecraftforge/forge/" + classifier + "-" + gameVersion + "/" + fileName2);
|
||||
urls.add("https://files.minecraftforge.net/maven/net/minecraftforge/forge/" + classifier + "/" + fileName1);
|
||||
urls.add("https://files.minecraftforge.net/maven/net/minecraftforge/forge/" + classifier + "-" + gameVersion + "/" + fileName2);
|
||||
urls.add(NetworkUtils.withQuery("https://bmclapi2.bangbang93.com/forge/download", mapOf(
|
||||
pair("mcversion", version.getGameVersion()),
|
||||
pair("version", version.getVersion()),
|
||||
|
@ -227,10 +227,11 @@ public class FileDownloadTask extends Task<Void> {
|
||||
Exception exception = null;
|
||||
URL failedURL = null;
|
||||
|
||||
for (int repeat = 0; repeat < retry * urls.size(); repeat++) {
|
||||
URL url = urls.get(repeat / retry);
|
||||
int repeat = 0;
|
||||
download: for (URL url : urls) {
|
||||
for (int retryTime = 0; retryTime < retry; retryTime++) {
|
||||
if (isCancelled()) {
|
||||
break;
|
||||
break download;
|
||||
}
|
||||
|
||||
Logging.LOG.log(Level.FINER, "Downloading " + url + " to " + file);
|
||||
@ -254,11 +255,11 @@ public class FileDownloadTask extends Task<Void> {
|
||||
repository.removeRemoteEntry(con);
|
||||
// Now we must reconnect the server since 304 may result in empty content,
|
||||
// if we want to redownload the file, we must reconnect the server without etag settings.
|
||||
repeat--;
|
||||
retryTime--;
|
||||
continue;
|
||||
}
|
||||
} else if (con.getResponseCode() / 100 == 4) {
|
||||
|
||||
break; // we will not try this URL again
|
||||
} else if (con.getResponseCode() / 100 != 2) {
|
||||
throw new ResponseCodeException(url, con.getResponseCode());
|
||||
}
|
||||
@ -312,7 +313,7 @@ public class FileDownloadTask extends Task<Void> {
|
||||
// Restore temp file to original name.
|
||||
if (isCancelled()) {
|
||||
temp.toFile().delete();
|
||||
break;
|
||||
break download;
|
||||
}
|
||||
|
||||
for (IntegrityCheckHandler handler : integrityCheckHandlers) {
|
||||
@ -351,11 +352,12 @@ public class FileDownloadTask extends Task<Void> {
|
||||
temp.toFile().delete();
|
||||
failedURL = url;
|
||||
exception = e;
|
||||
Logging.LOG.log(Level.WARNING, "Failed to download " + url + ", repeat times: " + (repeat + 1), e);
|
||||
Logging.LOG.log(Level.WARNING, "Failed to download " + url + ", repeat times: " + (++repeat), e);
|
||||
} finally {
|
||||
closeFiles();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (exception != null)
|
||||
throw new DownloadException(failedURL, exception);
|
||||
|
Loading…
x
Reference in New Issue
Block a user