移除添加以管理员身份运行的兼容性,以防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

129
Form1.Designer.cs generated
View File

@@ -28,81 +28,66 @@
/// </summary>
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;

View File

@@ -134,21 +134,13 @@ namespace CheckDownload
/// <param name="message">状态消息</param>
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))