使用123盘下载文件
This commit is contained in:
@@ -178,10 +178,10 @@
|
|||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<ErrorText>这台计算机上缺少此项目引用的 NuGet 程序包。使用“NuGet 程序包还原”可下载这些程序包。有关更多信息,请参见 http://go.microsoft.com/fwlink/?LinkID=322105。缺少的文件是 {0}。</ErrorText>
|
<ErrorText>这台计算机上缺少此项目引用的 NuGet 程序包。使用“NuGet 程序包还原”可下载这些程序包。有关更多信息,请参见 http://go.microsoft.com/fwlink/?LinkID=322105。缺少的文件是 {0}。</ErrorText>
|
||||||
</PropertyGroup>
|
</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.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\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>
|
</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\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>
|
</Project>
|
16
Form1.cs
16
Form1.cs
@@ -394,9 +394,13 @@ namespace CheckDownload
|
|||||||
_downloadedFiles[file.Key] = (null, file.Value);
|
_downloadedFiles[file.Key] = (null, file.Value);
|
||||||
}
|
}
|
||||||
Interlocked.Increment(ref _completedCount);
|
Interlocked.Increment(ref _completedCount);
|
||||||
|
|
||||||
|
// 实时更新进度(0-95%用于下载)
|
||||||
int progress = (int)((double)_completedCount / _totalCount * 95);
|
int progress = (int)((double)_completedCount / _totalCount * 95);
|
||||||
UpdateProgressValue(progress);
|
UpdateProgressValue(progress);
|
||||||
UpdateStatus($"已下载 {_completedCount}/{_totalCount}: {Path.GetFileName(file.Key)}");
|
|
||||||
|
// 更新下载完成状态:文件名称 当前进度/总进度
|
||||||
|
UpdateStatus($"{Path.GetFileName(file.Key)} {_completedCount}/{_totalCount}");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -420,18 +424,19 @@ namespace CheckDownload
|
|||||||
private async Task<bool> AttemptDownloadAsync(string filePath, string expectedMd5)
|
private async Task<bool> AttemptDownloadAsync(string filePath, string expectedMd5)
|
||||||
{
|
{
|
||||||
string tempFilePath = Path.Combine(_tempDirectory, filePath);
|
string tempFilePath = Path.Combine(_tempDirectory, filePath);
|
||||||
|
string fileName = Path.GetFileName(filePath);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// 1. 首先尝试从123盘下载
|
// 1. 首先尝试从123盘下载
|
||||||
UpdateStatus($"{Path.GetFileName(filePath)}");
|
UpdateStatus($"{fileName} {_completedCount + 1}/{_totalCount}");
|
||||||
if (await DownloadFileFromOneDrive(filePath, expectedMd5, tempFilePath))
|
if (await DownloadFileFromOneDrive(filePath, expectedMd5, tempFilePath))
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. 如果123盘下载失败,使用阿里云OSS作为备用
|
// 2. 如果123盘下载失败,使用阿里云OSS作为备用
|
||||||
UpdateStatus($"123盘下载失败,尝试阿里云OSS备用方案: {Path.GetFileName(filePath)}");
|
UpdateStatus($"{fileName} {_completedCount + 1}/{_totalCount}");
|
||||||
string ossKey = $"File/{expectedMd5}";
|
string ossKey = $"File/{expectedMd5}";
|
||||||
|
|
||||||
var client = new OssClient(OssEndpoint, OssAccessKeyId, OssAccessKeySecret);
|
var client = new OssClient(OssEndpoint, OssAccessKeyId, OssAccessKeySecret);
|
||||||
@@ -447,18 +452,17 @@ namespace CheckDownload
|
|||||||
{
|
{
|
||||||
await obj.Content.CopyToAsync(fileStream);
|
await obj.Content.CopyToAsync(fileStream);
|
||||||
}
|
}
|
||||||
UpdateStatus($"阿里云OSS下载成功: {Path.GetFileName(filePath)}");
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
catch (Exception ex) when (ex is OssException || ex is WebException)
|
catch (Exception ex) when (ex is OssException || ex is WebException)
|
||||||
{
|
{
|
||||||
UpdateStatus($"主下载失败,尝试OSS备用方案: {Path.GetFileName(filePath)}");
|
UpdateStatus($"{fileName} {_completedCount + 1}/{_totalCount}");
|
||||||
string ossKey = $"File/{expectedMd5}";
|
string ossKey = $"File/{expectedMd5}";
|
||||||
return await DownloadFileWithFallback(ossKey, tempFilePath);
|
return await DownloadFileWithFallback(ossKey, tempFilePath);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
UpdateStatus($"下载异常: {Path.GetFileName(filePath)} - {ex.Message}");
|
UpdateStatus($"下载异常: {fileName} - {ex.Message}");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user