From b933fbcd6b9e569b582acd10da8fc7e7c8ecc1ef Mon Sep 17 00:00:00 2001 From: Glavo Date: Thu, 5 Feb 2026 20:40:41 +0800 Subject: [PATCH] =?UTF-8?q?Fix=20#5437:=20=E4=BF=AE=E5=A4=8D=E6=80=BB?= =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E6=95=B0=E4=B8=BA=200=20=E6=97=B6=20Task=20?= =?UTF-8?q?=E8=BF=9B=E5=BA=A6=E8=AE=A1=E7=AE=97=E9=94=99=E8=AF=AF=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98=20(#5442)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/org/jackhuang/hmcl/task/Task.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/task/Task.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/task/Task.java index a0ee0dd20..5fb6a8b44 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/task/Task.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/task/Task.java @@ -341,13 +341,21 @@ public abstract class Task { private long lastUpdateProgressTime = 0L; - protected void updateProgress(long progress, long total) { - updateProgress(1.0 * progress / total); + protected void updateProgress(long count, long total) { + if (count < 0 || total < 0) + throw new IllegalArgumentException("Invalid count or total: count=" + count + ", total=" + total); + + double progress; + if (total >= count) + progress = 1.0; + else + progress = (double) count / total; + updateProgress(progress); } protected void updateProgress(double progress) { if (progress < 0 || progress > 1.0 || Double.isNaN(progress)) - throw new IllegalArgumentException("Progress must be between 0 and 1."); + throw new IllegalArgumentException("Invalid progress: " + progress); long now = System.currentTimeMillis(); if (progress == 1.0 || now - lastUpdateProgressTime >= 1000L) {