添加7z.dll文件,更新项目引用以支持SevenZipExtractor和SevenZipSharp,新增异步解压tim.7z文件的功能

This commit is contained in:
2025-06-29 18:59:15 +08:00
parent 8ad1be350b
commit cf20942533
4 changed files with 58 additions and 0 deletions

BIN
7z.dll Normal file

Binary file not shown.

View File

@@ -89,6 +89,12 @@
<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>
</Reference>
<Reference Include="SevenZipExtractor, Version=1.0.19.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>packages\SevenZipExtractor.1.0.19\lib\net45\SevenZipExtractor.dll</HintPath>
</Reference>
<Reference Include="SevenZipSharp, Version=0.64.3890.29348, Culture=neutral, PublicKeyToken=20de82c62b055c88, processorArchitecture=MSIL">
<HintPath>packages\SevenZipSharp.0.64\lib\SevenZipSharp.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Buffers, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll</HintPath>
@@ -177,6 +183,9 @@
<Install>false</Install>
</BootstrapperPackage>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="7z.dll" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
@@ -185,7 +194,11 @@
<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'))" />
<Error Condition="!Exists('packages\SevenZipSharp.Interop.19.1.0\build\SevenZipSharp.Interop.targets')" Text="$([System.String]::Format('$(ErrorText)', 'packages\SevenZipSharp.Interop.19.1.0\build\SevenZipSharp.Interop.targets'))" />
<Error Condition="!Exists('packages\SevenZipExtractor.1.0.19\build\SevenZipExtractor.targets')" Text="$([System.String]::Format('$(ErrorText)', 'packages\SevenZipExtractor.1.0.19\build\SevenZipExtractor.targets'))" />
</Target>
<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')" />
<Import Project="packages\SevenZipSharp.Interop.19.1.0\build\SevenZipSharp.Interop.targets" Condition="Exists('packages\SevenZipSharp.Interop.19.1.0\build\SevenZipSharp.Interop.targets')" />
<Import Project="packages\SevenZipExtractor.1.0.19\build\SevenZipExtractor.targets" Condition="Exists('packages\SevenZipExtractor.1.0.19\build\SevenZipExtractor.targets')" />
</Project>

View File

@@ -23,6 +23,8 @@ using Newtonsoft.Json.Linq;
using System.Collections.Concurrent;
using System.Diagnostics;
using System.Configuration;
using SevenZipExtractor;
using System.Reflection;
namespace CheckDownload
{
@@ -273,6 +275,8 @@ namespace CheckDownload
await VerifyAndSaveAllFiles();
await DecompressTim7zAsync();
// 校验和保存成功后清理临时目录
CleanupTempDirectory();
@@ -1474,5 +1478,44 @@ namespace CheckDownload
}
return $"{dblSByte:0.##}{suffixes[i]}";
}
/// <summary>
/// 异步解压 tim.7z 文件(如果存在)。
/// </summary>
private async Task DecompressTim7zAsync()
{
try
{
var sevenZipFile = Directory.EnumerateFiles(_baseDirectory, "tim.7z", SearchOption.AllDirectories).FirstOrDefault();
if (sevenZipFile != null)
{
UpdateStatus("发现tim.7z,正在解压...");
await Task.Run(() => {
try
{
string extractionPath = Path.GetDirectoryName(sevenZipFile);
using (var archiveFile = new ArchiveFile(sevenZipFile))
{
archiveFile.Extract(extractionPath, true);
}
}
catch (Exception ex)
{
throw new Exception($"解压失败: {ex.Message}");
}
});
UpdateStatus("tim.7z 解压完成。");
await Task.Delay(1000);
}
}
catch (Exception ex)
{
UpdateStatus($"处理 tim.7z 时出错: {ex.Message}");
await Task.Delay(3000);
}
}
}
}

View File

@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="7z" version="15.8.0" targetFramework="net472" />
<package id="Aliyun.OSS.SDK" version="2.14.1" targetFramework="net472" />
<package id="Costura.Fody" version="6.0.0" targetFramework="net472" developmentDependency="true" />
<package id="DnsClient" version="1.8.0" targetFramework="net472" />
@@ -7,6 +8,7 @@
<package id="LanzouCloudSolve" version="1.0.3" 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="SevenZipExtractor" version="1.0.19" 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" />