From 9ba1b33ca31f786cd546ef941a6de1d1324121d9 Mon Sep 17 00:00:00 2001 From: dong <1278815766@qq.com> Date: Wed, 2 Jul 2025 15:03:53 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A7=BB=E9=99=A4=E6=B7=BB=E5=8A=A0=E4=BB=A5?= =?UTF-8?q?=E7=AE=A1=E7=90=86=E5=91=98=E8=BA=AB=E4=BB=BD=E8=BF=90=E8=A1=8C?= =?UTF-8?q?=E7=9A=84=E5=85=BC=E5=AE=B9=E6=80=A7=EF=BC=8C=E4=BB=A5=E9=98=B2?= =?UTF-8?q?windows=E6=8A=A5=E6=AF=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Form1.Designer.cs | 129 ++++++++++++++++++++-------------------------- Form1.cs | 62 +++++++++++++++------- 2 files changed, 101 insertions(+), 90 deletions(-) diff --git a/Form1.Designer.cs b/Form1.Designer.cs index 493cfc2..3bc24bb 100644 --- a/Form1.Designer.cs +++ b/Form1.Designer.cs @@ -28,81 +28,66 @@ /// private void InitializeComponent() { - this.Update_Text = new System.Windows.Forms.Label(); - this.Update_Pro = new System.Windows.Forms.ProgressBar(); - this.Status_Box = new System.Windows.Forms.Label(); - this.Count_Box = new System.Windows.Forms.Label(); - this.Size_Box = new System.Windows.Forms.Label(); - this.SuspendLayout(); - // - // Update_Text - // - this.Update_Text.AutoSize = true; - this.Update_Text.Location = new System.Drawing.Point(12, 12); - this.Update_Text.Name = "Update_Text"; - this.Update_Text.Size = new System.Drawing.Size(59, 12); - this.Update_Text.TabIndex = 0; - this.Update_Text.Text = "更新状态:"; - // - // Update_Pro - // - this.Update_Pro.Location = new System.Drawing.Point(12, 36); - this.Update_Pro.Name = "Update_Pro"; - this.Update_Pro.Size = new System.Drawing.Size(339, 23); - this.Update_Pro.TabIndex = 1; - // - // Status_Box - // - this.Status_Box.AutoSize = false; - this.Status_Box.Location = new System.Drawing.Point(72, 12); - this.Status_Box.Name = "Status_Box"; - this.Status_Box.Size = new System.Drawing.Size(94, 12); - this.Status_Box.TabIndex = 2; - this.Status_Box.Text = "..."; - // - // Count_Box - // - this.Count_Box.Location = new System.Drawing.Point(296, 12); - this.Count_Box.Name = "Count_Box"; - this.Count_Box.Size = new System.Drawing.Size(55, 13); - this.Count_Box.TabIndex = 3; - this.Count_Box.TextAlign = System.Drawing.ContentAlignment.TopRight; - // - // Size_Box - // - this.Size_Box.Location = new System.Drawing.Point(166, 12); - this.Size_Box.Name = "Size_Box"; - this.Size_Box.Size = new System.Drawing.Size(130, 13); - this.Size_Box.TabIndex = 4; - this.Size_Box.TextAlign = System.Drawing.ContentAlignment.TopRight; - // - // Update - // - this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(363, 73); - this.ControlBox = false; - this.Controls.Add(this.Size_Box); - this.Controls.Add(this.Count_Box); - this.Controls.Add(this.Status_Box); - this.Controls.Add(this.Update_Pro); - this.Controls.Add(this.Update_Text); - this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; - this.MaximizeBox = false; - this.MinimizeBox = false; - this.Name = "Update"; - this.ShowInTaskbar = false; - this.Text = "自动更新"; - this.TopMost = true; - this.Load += new System.EventHandler(this.Update_Load); - this.ResumeLayout(false); - this.PerformLayout(); - + this.Update_Pro = new System.Windows.Forms.ProgressBar(); + this.Status_Box = new System.Windows.Forms.Label(); + this.Count_Box = new System.Windows.Forms.Label(); + this.Size_Box = new System.Windows.Forms.Label(); + this.SuspendLayout(); + // + // Update_Pro + // + this.Update_Pro.Location = new System.Drawing.Point(12, 36); + this.Update_Pro.Name = "Update_Pro"; + this.Update_Pro.Size = new System.Drawing.Size(339, 23); + this.Update_Pro.TabIndex = 1; + // + // Status_Box + // + this.Status_Box.Location = new System.Drawing.Point(12, 12); + this.Status_Box.Name = "Status_Box"; + this.Status_Box.Size = new System.Drawing.Size(148, 12); + this.Status_Box.TabIndex = 2; + this.Status_Box.Text = "..."; + // + // Count_Box + // + this.Count_Box.Location = new System.Drawing.Point(296, 12); + this.Count_Box.Name = "Count_Box"; + this.Count_Box.Size = new System.Drawing.Size(55, 13); + this.Count_Box.TabIndex = 3; + this.Count_Box.TextAlign = System.Drawing.ContentAlignment.TopRight; + // + // Size_Box + // + this.Size_Box.Location = new System.Drawing.Point(166, 12); + this.Size_Box.Name = "Size_Box"; + this.Size_Box.Size = new System.Drawing.Size(130, 13); + this.Size_Box.TabIndex = 4; + this.Size_Box.TextAlign = System.Drawing.ContentAlignment.TopRight; + // + // Update + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(363, 73); + this.ControlBox = false; + this.Controls.Add(this.Size_Box); + this.Controls.Add(this.Count_Box); + this.Controls.Add(this.Status_Box); + this.Controls.Add(this.Update_Pro); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; + this.MaximizeBox = false; + this.MinimizeBox = false; + this.Name = "Update"; + this.ShowInTaskbar = false; + this.Text = "自动更新"; + this.TopMost = true; + this.Load += new System.EventHandler(this.Update_Load); + this.ResumeLayout(false); + } #endregion - - private System.Windows.Forms.Label Update_Text; private System.Windows.Forms.ProgressBar Update_Pro; private System.Windows.Forms.Label Status_Box; private System.Windows.Forms.Label Count_Box; diff --git a/Form1.cs b/Form1.cs index 7576e8f..8a8a76f 100644 --- a/Form1.cs +++ b/Form1.cs @@ -134,21 +134,13 @@ namespace CheckDownload /// 状态消息 private void UpdateStatus(string message) { - // 只保留冒号后的简短信息(一般是文件名);若无冒号则原样显示 - string display = message; - int idx = message.LastIndexOf(':'); - if (idx >= 0 && idx < message.Length - 1) - { - display = message.Substring(idx + 1).Trim(); - } - if (this.InvokeRequired) { - this.Invoke((MethodInvoker)delegate { Status_Box.Text = display; }); + this.Invoke((MethodInvoker)delegate { Status_Box.Text = message; }); } else { - Status_Box.Text = display; + Status_Box.Text = message; } } @@ -557,14 +549,20 @@ namespace CheckDownload return true; } - UpdateStatus($"{fileName}"); + if (!string.IsNullOrWhiteSpace(fileName)) + { + UpdateStatus($"下载:{fileName}"); + } UpdateCount($"{_completedCount + 1}/{_totalCount}"); if (await DownloadFileFromOneDrive(filePath, expectedMd5, tempFilePath)) { return true; } - UpdateStatus($"{fileName}"); + if (!string.IsNullOrWhiteSpace(fileName)) + { + UpdateStatus($"下载:{fileName}"); + } UpdateCount($"{_completedCount + 1}/{_totalCount}"); string ossKey = $"File/{expectedMd5}"; @@ -584,7 +582,10 @@ namespace CheckDownload } catch (Exception ex) when (ex is OssException || ex is WebException) { - UpdateStatus($"{fileName}"); + if (!string.IsNullOrWhiteSpace(fileName)) + { + UpdateStatus($"下载:{fileName}"); + } UpdateCount($"{_completedCount + 1}/{_totalCount}"); UpdateSize(""); string ossKey = $"File/{expectedMd5}"; @@ -592,7 +593,10 @@ namespace CheckDownload } catch (Exception ex) { - UpdateStatus($"下载异常: {fileName} - {ex.Message}"); + if (!string.IsNullOrWhiteSpace(fileName)) + { + UpdateStatus($"下载异常: {fileName} - {ex.Message}"); + } return false; } } @@ -613,25 +617,47 @@ namespace CheckDownload return false; } - UpdateStatus($"检查已存在的临时文件: {fileName}"); + if (!string.IsNullOrWhiteSpace(fileName)) + { + UpdateStatus($"检查已存在的临时文件: {fileName}"); + } string actualMd5 = await Task.Run(() => CalculateMD5FromFile(tempFilePath)); if (actualMd5.Equals(expectedMd5, StringComparison.OrdinalIgnoreCase)) { - UpdateStatus($"临时文件完整,跳过下载: {fileName}"); + if (!string.IsNullOrWhiteSpace(fileName)) + { + UpdateStatus($"临时文件完整,跳过下载: {fileName}"); + } + // === 新增: 将已存在的有效临时文件大小计入总下载量 === + try + { + var fileInfo = new FileInfo(tempFilePath); + Interlocked.Add(ref _totalDownloadedBytes, fileInfo.Length); + } + catch + { + // 忽略获取文件大小的错误 + } return true; } else { - UpdateStatus($"临时文件不完整,重新下载: {fileName}"); + if (!string.IsNullOrWhiteSpace(fileName)) + { + UpdateStatus($"临时文件不完整,重新下载: {fileName}"); + } File.Delete(tempFilePath); return false; } } catch (Exception ex) { - UpdateStatus($"检查临时文件时出错,将重新下载: {fileName} - {ex.Message}"); + if (!string.IsNullOrWhiteSpace(fileName)) + { + UpdateStatus($"检查临时文件时出错,将重新下载: {fileName} - {ex.Message}"); + } try { if (File.Exists(tempFilePath))