更新依赖项版本,添加线程安全的计数更新方法,并调整UI以显示下载进度和计数

This commit is contained in:
2025-06-29 16:20:02 +08:00
parent 1563478854
commit 08ddd9723b
5 changed files with 161 additions and 111 deletions

View File

@@ -11,7 +11,7 @@
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Text.Json" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-8.0.0.1" newVersion="8.0.0.1" />
<bindingRedirect oldVersion="0.0.0.0-9.0.0.6" newVersion="9.0.0.6" />
</dependentAssembly>
</assemblyBinding>
</runtime>

View File

@@ -83,8 +83,8 @@
<Reference Include="LanzouCloudSolve, Version=1.0.3.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>packages\LanzouCloudSolve.1.0.3\lib\netstandard2.0\LanzouCloudSolve.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Bcl.AsyncInterfaces, Version=8.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>packages\Microsoft.Bcl.AsyncInterfaces.8.0.0\lib\net462\Microsoft.Bcl.AsyncInterfaces.dll</HintPath>
<Reference Include="Microsoft.Bcl.AsyncInterfaces, Version=9.0.0.6, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>packages\Microsoft.Bcl.AsyncInterfaces.9.0.6\lib\net462\Microsoft.Bcl.AsyncInterfaces.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>packages\Newtonsoft.Json.13.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
@@ -94,6 +94,9 @@
<HintPath>packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll</HintPath>
</Reference>
<Reference Include="System.Core" />
<Reference Include="System.IO.Pipelines, Version=9.0.0.6, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>packages\System.IO.Pipelines.9.0.6\lib\net462\System.IO.Pipelines.dll</HintPath>
</Reference>
<Reference Include="System.Memory, Version=4.0.1.2, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>packages\System.Memory.4.5.5\lib\net461\System.Memory.dll</HintPath>
</Reference>
@@ -104,11 +107,11 @@
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>packages\System.Runtime.CompilerServices.Unsafe.6.0.0\lib\net461\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
</Reference>
<Reference Include="System.Text.Encodings.Web, Version=8.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>packages\System.Text.Encodings.Web.8.0.0\lib\net462\System.Text.Encodings.Web.dll</HintPath>
<Reference Include="System.Text.Encodings.Web, Version=9.0.0.6, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>packages\System.Text.Encodings.Web.9.0.6\lib\net462\System.Text.Encodings.Web.dll</HintPath>
</Reference>
<Reference Include="System.Text.Json, Version=8.0.0.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>packages\System.Text.Json.8.0.1\lib\net462\System.Text.Json.dll</HintPath>
<Reference Include="System.Text.Json, Version=9.0.0.6, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>packages\System.Text.Json.9.0.6\lib\net462\System.Text.Json.dll</HintPath>
</Reference>
<Reference Include="System.Threading.Tasks.Extensions, Version=4.2.0.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>packages\System.Threading.Tasks.Extensions.4.5.4\lib\net461\System.Threading.Tasks.Extensions.dll</HintPath>

191
Form1.Designer.cs generated
View File

@@ -1,90 +1,101 @@
namespace CheckDownload
{
partial class Update
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
/// <param name="disposing">如果应释放托管资源,为 true否则为 false。</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows
/// <summary>
/// 设计器支持所需的方法 - 不要修改
/// 使用代码编辑器修改此方法的内容。
/// </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.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 = true;
this.Status_Box.Location = new System.Drawing.Point(72, 12);
this.Status_Box.Name = "Status_Box";
this.Status_Box.Size = new System.Drawing.Size(23, 12);
this.Status_Box.TabIndex = 2;
this.Status_Box.Text = "...";
//
// 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.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();
}
#endregion
private System.Windows.Forms.Label Update_Text;
private System.Windows.Forms.ProgressBar Update_Pro;
private System.Windows.Forms.Label Status_Box;
}
}
namespace CheckDownload
{
partial class Update
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
/// <param name="disposing">如果应释放托管资源,为 true否则为 false。</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows
/// <summary>
/// 设计器支持所需的方法 - 不要修改
/// 使用代码编辑器修改此方法的内容。
/// </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.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(213, 12);
this.Status_Box.TabIndex = 2;
this.Status_Box.Text = "...";
//
// Count_Box
//
this.Count_Box.Location = new System.Drawing.Point(291, 12);
this.Count_Box.Name = "Count_Box";
this.Count_Box.Size = new System.Drawing.Size(60, 13);
this.Count_Box.TabIndex = 3;
this.Count_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.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();
}
#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

@@ -133,6 +133,22 @@ namespace CheckDownload
}
}
/// <summary>
/// 更新计数显示文本(线程安全)
/// </summary>
/// <param name="countMessage">计数值</param>
private void UpdateCount(string countMessage)
{
if (this.InvokeRequired)
{
this.Invoke((MethodInvoker)delegate { Count_Box.Text = countMessage; });
}
else
{
Count_Box.Text = countMessage;
}
}
/// <summary>
/// 窗体加载事件处理,启动更新流程
/// </summary>
@@ -166,6 +182,7 @@ namespace CheckDownload
{
CleanupNewFiles();
UpdateStatus("下载在线MD5文件并读取...");
UpdateCount("");
string tempFilePath = Path.Combine(_tempDirectory, Md5File);
// 使用新的带123盘的下载方法
if (!await DownloadMd5FileWithFallback(Md5File, tempFilePath))
@@ -192,6 +209,7 @@ namespace CheckDownload
if (compareResult.Count == 0)
{
UpdateStatus("所有文件都是最新的,无需更新");
UpdateCount("");
UpdateProgressValue(100);
// 无需更新时清理临时文件夹
@@ -219,10 +237,12 @@ namespace CheckDownload
if (!failedFiles.IsEmpty)
{
UpdateStatus($"有 {failedFiles.Count} 个文件下载失败,开始重试...");
UpdateCount("");
var stillFailing = await RetryFailedFilesAsync(new Dictionary<string, string>(failedFiles));
if (stillFailing.Any())
{
UpdateStatus($"重试后仍有 {stillFailing.Count} 个文件下载失败。");
UpdateCount("");
}
}
@@ -432,7 +452,8 @@ namespace CheckDownload
int progress = (int)((double)_completedCount / _totalCount * 95);
UpdateProgressValue(progress);
UpdateStatus($"{Path.GetFileName(file.Key)} {_completedCount}/{_totalCount}");
UpdateStatus($"{Path.GetFileName(file.Key)}");
UpdateCount($"{_completedCount}/{_totalCount}");
}
else
{
@@ -465,13 +486,15 @@ namespace CheckDownload
return true;
}
UpdateStatus($"{fileName} {_completedCount + 1}/{_totalCount}");
UpdateStatus($"{fileName}");
UpdateCount($"{_completedCount + 1}/{_totalCount}");
if (await DownloadFileFromOneDrive(filePath, expectedMd5, tempFilePath))
{
return true;
}
UpdateStatus($"{fileName} {_completedCount + 1}/{_totalCount}");
UpdateStatus($"{fileName}");
UpdateCount($"{_completedCount + 1}/{_totalCount}");
string ossKey = $"File/{expectedMd5}";
var obj = _ossClient.GetObject(OssBucketName, ossKey);
@@ -490,7 +513,8 @@ namespace CheckDownload
}
catch (Exception ex) when (ex is OssException || ex is WebException)
{
UpdateStatus($"{fileName} {_completedCount + 1}/{_totalCount}");
UpdateStatus($"{fileName}");
UpdateCount($"{_completedCount + 1}/{_totalCount}");
string ossKey = $"File/{expectedMd5}";
return await DownloadFileWithFallback(ossKey, tempFilePath);
}
@@ -562,10 +586,12 @@ namespace CheckDownload
try
{
UpdateStatus($"正在从123盘下载: {fileName}");
UpdateCount("");
string authUrl = GenerateAuthUrl($"http://{OneDriveMainDomain}{OneDrivePath}", fileName);
UpdateStatus($"使用主域名下载文件...");
UpdateCount("");
var request = new HttpRequestMessage(HttpMethod.Get, authUrl) { Version = HttpVersion.Version11 };
request.Headers.Add("User-Agent", "CheckDownload/1.0");
@@ -586,21 +612,25 @@ namespace CheckDownload
}
UpdateStatus($"123盘主域名下载成功: {fileName}");
UpdateCount("");
return true;
}
}
catch (Exception ex)
catch (Exception)
{
UpdateStatus($"123盘主域名下载失败尝试备用域名: {fileName}");
UpdateCount("");
}
try
{
UpdateStatus($"正在从123盘备用域名下载: {fileName}");
UpdateCount("");
string authUrl = GenerateAuthUrl($"http://{OneDriveBackupDomain}{OneDrivePath}", fileName);
UpdateStatus($"使用备用域名下载文件...");
UpdateCount("");
var request = new HttpRequestMessage(HttpMethod.Get, authUrl) { Version = HttpVersion.Version11 };
request.Headers.Add("User-Agent", "CheckDownload/1.0");
@@ -621,6 +651,7 @@ namespace CheckDownload
}
UpdateStatus($"123盘备用域名下载成功: {fileName}");
UpdateCount("");
return true;
}
}
@@ -667,7 +698,7 @@ namespace CheckDownload
return true;
}
}
catch (Exception ex)
catch (Exception)
{
}
@@ -696,7 +727,7 @@ namespace CheckDownload
return true;
}
}
catch (Exception ex)
catch (Exception)
{
return false;
}
@@ -714,6 +745,7 @@ namespace CheckDownload
for (int i = 0; i < MaxDownloadRetries && filesToRetry.Any(); i++)
{
UpdateStatus($"第 {i + 1} 次重试,剩余 {filesToRetry.Count} 个文件...");
UpdateCount("");
var failedThisRound = new ConcurrentDictionary<string, string>();
await PerformDownloads(filesToRetry, failedThisRound);
@@ -723,6 +755,7 @@ namespace CheckDownload
if (filesToRetry.Any() && i < MaxDownloadRetries - 1)
{
UpdateStatus($"等待 3 秒后进行下一次重试...");
UpdateCount("");
await Task.Delay(3000);
}
}
@@ -757,7 +790,7 @@ namespace CheckDownload
return ips;
}
}
catch (Exception ex)
catch (Exception)
{
UpdateStatus($"通过 {dnsServer} 解析域名失败,尝试下一个...");
await Task.Delay(500);
@@ -774,6 +807,7 @@ namespace CheckDownload
private async Task VerifyAndSaveAllFiles()
{
UpdateStatus("正在校验文件...");
UpdateCount("");
var failedFiles = new ConcurrentBag<string>();
var filesForScripting = new ConcurrentBag<(string original, string newFile)>();
@@ -840,6 +874,7 @@ namespace CheckDownload
else
{
UpdateStatus("所有文件校验和保存成功");
UpdateCount("");
UpdateProgressValue(100);
}
}
@@ -1219,7 +1254,7 @@ namespace CheckDownload
Directory.Delete(tempPath, true);
}
}
catch (Exception ex)
catch (Exception)
{
}
}
@@ -1260,7 +1295,7 @@ namespace CheckDownload
_baseDirectory = Application.StartupPath;
}
}
catch (Exception ex)
catch (Exception)
{
_baseDirectory = Application.StartupPath;
}
@@ -1343,7 +1378,7 @@ namespace CheckDownload
return currentDir;
}
catch (Exception ex)
catch (Exception)
{
return currentDir;
}

View File

@@ -5,14 +5,15 @@
<package id="DnsClient" version="1.8.0" targetFramework="net472" />
<package id="Fody" version="6.8.2" targetFramework="net472" developmentDependency="true" />
<package id="LanzouCloudSolve" version="1.0.3" targetFramework="net472" />
<package id="Microsoft.Bcl.AsyncInterfaces" version="8.0.0" targetFramework="net472" />
<package id="Microsoft.Bcl.AsyncInterfaces" version="9.0.6" targetFramework="net472" />
<package id="Newtonsoft.Json" version="13.0.3" targetFramework="net472" />
<package id="System.Buffers" version="4.5.1" targetFramework="net472" />
<package id="System.IO.Pipelines" version="9.0.6" targetFramework="net472" />
<package id="System.Memory" version="4.5.5" targetFramework="net472" />
<package id="System.Numerics.Vectors" version="4.5.0" targetFramework="net472" />
<package id="System.Runtime.CompilerServices.Unsafe" version="6.0.0" targetFramework="net472" />
<package id="System.Text.Encodings.Web" version="8.0.0" targetFramework="net472" />
<package id="System.Text.Json" version="8.0.1" targetFramework="net472" />
<package id="System.Text.Encodings.Web" version="9.0.6" targetFramework="net472" />
<package id="System.Text.Json" version="9.0.6" targetFramework="net472" />
<package id="System.Threading.Tasks.Extensions" version="4.5.4" targetFramework="net472" />
<package id="System.ValueTuple" version="4.5.0" targetFramework="net472" />
</packages>