From 787d3b3b57e289ab3563bf03d6bd9af3fc217025 Mon Sep 17 00:00:00 2001 From: dong <1278815766@qq.com> Date: Sun, 22 Jun 2025 22:38:20 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=BF=E7=94=A8123=E7=9B=98=E4=B8=8B?= =?UTF-8?q?=E8=BD=BD=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CheckDownload.csproj | 4 ++-- Form1.cs | 16 ++++++++++------ 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/CheckDownload.csproj b/CheckDownload.csproj index 9c5f324..da5ff88 100644 --- a/CheckDownload.csproj +++ b/CheckDownload.csproj @@ -178,10 +178,10 @@ 这台计算机上缺少此项目引用的 NuGet 程序包。使用“NuGet 程序包还原”可下载这些程序包。有关更多信息,请参见 http://go.microsoft.com/fwlink/?LinkID=322105。缺少的文件是 {0}。 - + - + \ No newline at end of file diff --git a/Form1.cs b/Form1.cs index a57f5ee..55300d8 100644 --- a/Form1.cs +++ b/Form1.cs @@ -394,9 +394,13 @@ namespace CheckDownload _downloadedFiles[file.Key] = (null, file.Value); } Interlocked.Increment(ref _completedCount); + + // 实时更新进度(0-95%用于下载) int progress = (int)((double)_completedCount / _totalCount * 95); UpdateProgressValue(progress); - UpdateStatus($"已下载 {_completedCount}/{_totalCount}: {Path.GetFileName(file.Key)}"); + + // 更新下载完成状态:文件名称 当前进度/总进度 + UpdateStatus($"{Path.GetFileName(file.Key)} {_completedCount}/{_totalCount}"); } else { @@ -420,18 +424,19 @@ namespace CheckDownload private async Task AttemptDownloadAsync(string filePath, string expectedMd5) { string tempFilePath = Path.Combine(_tempDirectory, filePath); + string fileName = Path.GetFileName(filePath); try { // 1. 首先尝试从123盘下载 - UpdateStatus($"{Path.GetFileName(filePath)}"); + UpdateStatus($"{fileName} {_completedCount + 1}/{_totalCount}"); if (await DownloadFileFromOneDrive(filePath, expectedMd5, tempFilePath)) { return true; } // 2. 如果123盘下载失败,使用阿里云OSS作为备用 - UpdateStatus($"123盘下载失败,尝试阿里云OSS备用方案: {Path.GetFileName(filePath)}"); + UpdateStatus($"{fileName} {_completedCount + 1}/{_totalCount}"); string ossKey = $"File/{expectedMd5}"; var client = new OssClient(OssEndpoint, OssAccessKeyId, OssAccessKeySecret); @@ -447,18 +452,17 @@ namespace CheckDownload { await obj.Content.CopyToAsync(fileStream); } - UpdateStatus($"阿里云OSS下载成功: {Path.GetFileName(filePath)}"); return true; } catch (Exception ex) when (ex is OssException || ex is WebException) { - UpdateStatus($"主下载失败,尝试OSS备用方案: {Path.GetFileName(filePath)}"); + UpdateStatus($"{fileName} {_completedCount + 1}/{_totalCount}"); string ossKey = $"File/{expectedMd5}"; return await DownloadFileWithFallback(ossKey, tempFilePath); } catch (Exception ex) { - UpdateStatus($"下载异常: {Path.GetFileName(filePath)} - {ex.Message}"); + UpdateStatus($"下载异常: {fileName} - {ex.Message}"); return false; } }