Update config

This commit is contained in:
FongMi 2023-10-17 17:06:44 +08:00
parent 2756d9acc0
commit 7ec4a6bed6
3 changed files with 7 additions and 3 deletions

View File

@ -61,20 +61,24 @@ public class Market extends Spider {
Utils.notify("正在下載...");
Response response = OkHttp.newCall(url);
File file = FileUtil.getCacheFile(Uri.parse(url).getLastPathSegment());
download(file, response.body().byteStream());
download(file, response.body().byteStream(), Double.parseDouble(response.header("Content-Length", "1")));
FileUtil.openFile(FileUtil.chmod(file));
} catch (Exception e) {
Utils.notify(e.getMessage());
}
}
private void download(File file, InputStream is) throws Exception {
private void download(File file, InputStream is, double length) throws Exception {
FileOutputStream os = new FileOutputStream(file);
try (BufferedInputStream input = new BufferedInputStream(is)) {
byte[] buffer = new byte[4096];
int readBytes;
long totalBytes = 0;
while ((readBytes = input.read(buffer)) != -1) {
totalBytes += readBytes;
os.write(buffer, 0, readBytes);
int progress = (int) (totalBytes / length * 100.0);
if (progress % 10 < 5) Utils.notify("正在下載..." + progress + "%");
}
}
}

Binary file not shown.

View File

@ -1 +1 @@
f78dde289126840ebdd4abaf0cb7841d
e387f38428b7c337475b2827c56949f5