使用123盘下载文件

This commit is contained in:
2025-06-22 22:38:20 +08:00
parent ce36eadae2
commit 787d3b3b57
2 changed files with 12 additions and 8 deletions

View File

@@ -178,10 +178,10 @@
<PropertyGroup>
<ErrorText>这台计算机上缺少此项目引用的 NuGet 程序包。使用“NuGet 程序包还原”可下载这些程序包。有关更多信息,请参见 http://go.microsoft.com/fwlink/?LinkID=322105。缺少的文件是 {0}。</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('packages\Fody.6.9.2\build\Fody.targets')" Text="$([System.String]::Format('$(ErrorText)', 'packages\Fody.6.9.2\build\Fody.targets'))" />
<Error Condition="!Exists('packages\Costura.Fody.6.0.0\build\Costura.Fody.props')" Text="$([System.String]::Format('$(ErrorText)', 'packages\Costura.Fody.6.0.0\build\Costura.Fody.props'))" />
<Error Condition="!Exists('packages\Costura.Fody.6.0.0\build\Costura.Fody.targets')" Text="$([System.String]::Format('$(ErrorText)', 'packages\Costura.Fody.6.0.0\build\Costura.Fody.targets'))" />
<Error Condition="!Exists('packages\Fody.6.9.2\build\Fody.targets')" Text="$([System.String]::Format('$(ErrorText)', 'packages\Fody.6.9.2\build\Fody.targets'))" />
</Target>
<Import Project="packages\Fody.6.9.2\build\Fody.targets" Condition="Exists('packages\Fody.6.9.2\build\Fody.targets')" />
<Import Project="packages\Costura.Fody.6.0.0\build\Costura.Fody.targets" Condition="Exists('packages\Costura.Fody.6.0.0\build\Costura.Fody.targets')" />
<Import Project="packages\Fody.6.9.2\build\Fody.targets" Condition="Exists('packages\Fody.6.9.2\build\Fody.targets')" />
</Project>

View File

@@ -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<bool> 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;
}
}