移除添加以管理员身份运行的兼容性,以防windows报毒

This commit is contained in:
2025-07-02 15:03:53 +08:00
parent 96cfa4be48
commit 9ba1b33ca3
2 changed files with 101 additions and 90 deletions

19
Form1.Designer.cs generated
View File

@@ -28,22 +28,12 @@
/// </summary> /// </summary>
private void InitializeComponent() private void InitializeComponent()
{ {
this.Update_Text = new System.Windows.Forms.Label();
this.Update_Pro = new System.Windows.Forms.ProgressBar(); this.Update_Pro = new System.Windows.Forms.ProgressBar();
this.Status_Box = new System.Windows.Forms.Label(); this.Status_Box = new System.Windows.Forms.Label();
this.Count_Box = new System.Windows.Forms.Label(); this.Count_Box = new System.Windows.Forms.Label();
this.Size_Box = new System.Windows.Forms.Label(); this.Size_Box = new System.Windows.Forms.Label();
this.SuspendLayout(); 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 // Update_Pro
// //
this.Update_Pro.Location = new System.Drawing.Point(12, 36); this.Update_Pro.Location = new System.Drawing.Point(12, 36);
@@ -53,10 +43,9 @@
// //
// Status_Box // Status_Box
// //
this.Status_Box.AutoSize = false; this.Status_Box.Location = new System.Drawing.Point(12, 12);
this.Status_Box.Location = new System.Drawing.Point(72, 12);
this.Status_Box.Name = "Status_Box"; this.Status_Box.Name = "Status_Box";
this.Status_Box.Size = new System.Drawing.Size(94, 12); this.Status_Box.Size = new System.Drawing.Size(148, 12);
this.Status_Box.TabIndex = 2; this.Status_Box.TabIndex = 2;
this.Status_Box.Text = "..."; this.Status_Box.Text = "...";
// //
@@ -86,7 +75,6 @@
this.Controls.Add(this.Count_Box); this.Controls.Add(this.Count_Box);
this.Controls.Add(this.Status_Box); this.Controls.Add(this.Status_Box);
this.Controls.Add(this.Update_Pro); this.Controls.Add(this.Update_Pro);
this.Controls.Add(this.Update_Text);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.MaximizeBox = false; this.MaximizeBox = false;
this.MinimizeBox = false; this.MinimizeBox = false;
@@ -96,13 +84,10 @@
this.TopMost = true; this.TopMost = true;
this.Load += new System.EventHandler(this.Update_Load); this.Load += new System.EventHandler(this.Update_Load);
this.ResumeLayout(false); this.ResumeLayout(false);
this.PerformLayout();
} }
#endregion #endregion
private System.Windows.Forms.Label Update_Text;
private System.Windows.Forms.ProgressBar Update_Pro; private System.Windows.Forms.ProgressBar Update_Pro;
private System.Windows.Forms.Label Status_Box; private System.Windows.Forms.Label Status_Box;
private System.Windows.Forms.Label Count_Box; private System.Windows.Forms.Label Count_Box;

View File

@@ -134,21 +134,13 @@ namespace CheckDownload
/// <param name="message">状态消息</param> /// <param name="message">状态消息</param>
private void UpdateStatus(string message) 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) if (this.InvokeRequired)
{ {
this.Invoke((MethodInvoker)delegate { Status_Box.Text = display; }); this.Invoke((MethodInvoker)delegate { Status_Box.Text = message; });
} }
else else
{ {
Status_Box.Text = display; Status_Box.Text = message;
} }
} }
@@ -557,14 +549,20 @@ namespace CheckDownload
return true; return true;
} }
UpdateStatus($"{fileName}"); if (!string.IsNullOrWhiteSpace(fileName))
{
UpdateStatus($"下载:{fileName}");
}
UpdateCount($"{_completedCount + 1}/{_totalCount}"); UpdateCount($"{_completedCount + 1}/{_totalCount}");
if (await DownloadFileFromOneDrive(filePath, expectedMd5, tempFilePath)) if (await DownloadFileFromOneDrive(filePath, expectedMd5, tempFilePath))
{ {
return true; return true;
} }
UpdateStatus($"{fileName}"); if (!string.IsNullOrWhiteSpace(fileName))
{
UpdateStatus($"下载:{fileName}");
}
UpdateCount($"{_completedCount + 1}/{_totalCount}"); UpdateCount($"{_completedCount + 1}/{_totalCount}");
string ossKey = $"File/{expectedMd5}"; string ossKey = $"File/{expectedMd5}";
@@ -584,15 +582,21 @@ namespace CheckDownload
} }
catch (Exception ex) when (ex is OssException || ex is WebException) catch (Exception ex) when (ex is OssException || ex is WebException)
{ {
UpdateStatus($"{fileName}"); if (!string.IsNullOrWhiteSpace(fileName))
{
UpdateStatus($"下载:{fileName}");
}
UpdateCount($"{_completedCount + 1}/{_totalCount}"); UpdateCount($"{_completedCount + 1}/{_totalCount}");
UpdateSize(""); UpdateSize("");
string ossKey = $"File/{expectedMd5}"; string ossKey = $"File/{expectedMd5}";
return await DownloadFileWithFallback(ossKey, tempFilePath); return await DownloadFileWithFallback(ossKey, tempFilePath);
} }
catch (Exception ex) catch (Exception ex)
{
if (!string.IsNullOrWhiteSpace(fileName))
{ {
UpdateStatus($"下载异常: {fileName} - {ex.Message}"); UpdateStatus($"下载异常: {fileName} - {ex.Message}");
}
return false; return false;
} }
} }
@@ -613,25 +617,47 @@ namespace CheckDownload
return false; return false;
} }
if (!string.IsNullOrWhiteSpace(fileName))
{
UpdateStatus($"检查已存在的临时文件: {fileName}"); UpdateStatus($"检查已存在的临时文件: {fileName}");
}
string actualMd5 = await Task.Run(() => CalculateMD5FromFile(tempFilePath)); string actualMd5 = await Task.Run(() => CalculateMD5FromFile(tempFilePath));
if (actualMd5.Equals(expectedMd5, StringComparison.OrdinalIgnoreCase)) if (actualMd5.Equals(expectedMd5, StringComparison.OrdinalIgnoreCase))
{
if (!string.IsNullOrWhiteSpace(fileName))
{ {
UpdateStatus($"临时文件完整,跳过下载: {fileName}"); UpdateStatus($"临时文件完整,跳过下载: {fileName}");
}
// === 新增: 将已存在的有效临时文件大小计入总下载量 ===
try
{
var fileInfo = new FileInfo(tempFilePath);
Interlocked.Add(ref _totalDownloadedBytes, fileInfo.Length);
}
catch
{
// 忽略获取文件大小的错误
}
return true; return true;
} }
else else
{
if (!string.IsNullOrWhiteSpace(fileName))
{ {
UpdateStatus($"临时文件不完整,重新下载: {fileName}"); UpdateStatus($"临时文件不完整,重新下载: {fileName}");
}
File.Delete(tempFilePath); File.Delete(tempFilePath);
return false; return false;
} }
} }
catch (Exception ex) catch (Exception ex)
{
if (!string.IsNullOrWhiteSpace(fileName))
{ {
UpdateStatus($"检查临时文件时出错,将重新下载: {fileName} - {ex.Message}"); UpdateStatus($"检查临时文件时出错,将重新下载: {fileName} - {ex.Message}");
}
try try
{ {
if (File.Exists(tempFilePath)) if (File.Exists(tempFilePath))