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