mirror of
https://github.com/HMCL-dev/HMCL.git
synced 2025-09-16 23:37:14 -04:00
Fix crash
This commit is contained in:
parent
6e79d287f3
commit
61abed04f3
@ -237,7 +237,7 @@ public class FileDownloadTask extends Task<Void> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int contentLength = con.getContentLength();
|
int contentLength = con.getContentLength();
|
||||||
if (contentLength < 1)
|
if (contentLength < 0)
|
||||||
throw new IOException("The content length is invalid.");
|
throw new IOException("The content length is invalid.");
|
||||||
|
|
||||||
if (!FileUtils.makeDirectory(file.getAbsoluteFile().getParentFile()))
|
if (!FileUtils.makeDirectory(file.getAbsoluteFile().getParentFile()))
|
||||||
|
@ -89,7 +89,7 @@ public final class GetTask extends Task<String> {
|
|||||||
updateProgress(0);
|
updateProgress(0);
|
||||||
HttpURLConnection conn = NetworkUtils.createConnection(url);
|
HttpURLConnection conn = NetworkUtils.createConnection(url);
|
||||||
if (checkETag) repository.injectConnection(conn);
|
if (checkETag) repository.injectConnection(conn);
|
||||||
conn.connect();
|
conn = NetworkUtils.resolveConnection(conn);
|
||||||
|
|
||||||
if (conn.getResponseCode() == HttpURLConnection.HTTP_NOT_MODIFIED) {
|
if (conn.getResponseCode() == HttpURLConnection.HTTP_NOT_MODIFIED) {
|
||||||
// Handle cache
|
// Handle cache
|
||||||
|
@ -36,7 +36,6 @@ public final class NetworkUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static String withQuery(String baseUrl, Map<String, String> params) {
|
public static String withQuery(String baseUrl, Map<String, String> params) {
|
||||||
try {
|
|
||||||
StringBuilder sb = new StringBuilder(baseUrl);
|
StringBuilder sb = new StringBuilder(baseUrl);
|
||||||
boolean first = true;
|
boolean first = true;
|
||||||
for (Entry<String, String> param : params.entrySet()) {
|
for (Entry<String, String> param : params.entrySet()) {
|
||||||
@ -48,14 +47,11 @@ public final class NetworkUtils {
|
|||||||
} else {
|
} else {
|
||||||
sb.append('&');
|
sb.append('&');
|
||||||
}
|
}
|
||||||
sb.append(URLEncoder.encode(param.getKey(), "UTF-8"));
|
sb.append(encodeURL(param.getKey()));
|
||||||
sb.append('=');
|
sb.append('=');
|
||||||
sb.append(URLEncoder.encode(param.getValue(), "UTF-8"));
|
sb.append(encodeURL(param.getValue()));
|
||||||
}
|
}
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
} catch (IOException e) {
|
|
||||||
throw new UncheckedIOException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static HttpURLConnection createConnection(URL url) throws IOException {
|
public static HttpURLConnection createConnection(URL url) throws IOException {
|
||||||
@ -198,8 +194,8 @@ public final class NetworkUtils {
|
|||||||
|
|
||||||
public static URL toURL(String str) {
|
public static URL toURL(String str) {
|
||||||
try {
|
try {
|
||||||
return new URL(URLEncoder.encode(str, "UTF-8"));
|
return new URL(str);
|
||||||
} catch (MalformedURLException | UnsupportedEncodingException e) {
|
} catch (MalformedURLException e) {
|
||||||
throw new IllegalArgumentException(e);
|
throw new IllegalArgumentException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user