x86和x64

This commit is contained in:
2025-06-29 19:14:04 +08:00
parent cf20942533
commit 7060ef38bb
5 changed files with 113 additions and 65 deletions

BIN
7z-x64.dll Normal file

Binary file not shown.

BIN
7z-x86.dll Normal file

Binary file not shown.

BIN
7z.dll

Binary file not shown.

View File

@@ -184,7 +184,8 @@
</BootstrapperPackage>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="7z.dll" />
<EmbeddedResource Include="7z-x86.dll" />
<EmbeddedResource Include="7z-x64.dll" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">

View File

@@ -270,7 +270,7 @@ namespace CheckDownload
if (_completedCount == 0 && orderedFileList.Count > 0)
{
throw new Exception("所有文件下载失败。");
throw new Exception("所有文件下载失败。");
}
await VerifyAndSaveAllFiles();
@@ -445,7 +445,7 @@ namespace CheckDownload
if (_completedCount == 0 && fileList.Count > 0)
{
throw new Exception("所有文件下载失败。");
throw new Exception("所有文件下载失败。");
}
await VerifyAndSaveAllFiles();
@@ -1495,8 +1495,14 @@ namespace CheckDownload
await Task.Run(() => {
try
{
string sevenZipDllPath = Extract7zDll();
if (string.IsNullOrEmpty(sevenZipDllPath))
{
throw new Exception("无法提取7z.dll解压中止。");
}
string extractionPath = Path.GetDirectoryName(sevenZipFile);
using (var archiveFile = new ArchiveFile(sevenZipFile))
using (var archiveFile = new ArchiveFile(sevenZipFile, sevenZipDllPath))
{
archiveFile.Extract(extractionPath, true);
}
@@ -1514,8 +1520,49 @@ namespace CheckDownload
catch (Exception ex)
{
UpdateStatus($"处理 tim.7z 时出错: {ex.Message}");
MessageBox.Show($"处理 tim.7z 时出错: {ex.Message}");
await Task.Delay(3000);
}
}
/// <summary>
/// 从嵌入的资源中提取与当前进程体系结构匹配的7z.dll到临时目录。
/// </summary>
/// <returns>提取的7z.dll的路径如果失败则返回null。</returns>
private string Extract7zDll()
{
try
{
string dllName = Environment.Is64BitProcess ? "7z-x64.dll" : "7z-x86.dll";
string resourceName = $"CheckDownload.{dllName}";
string dllPath = Path.Combine(_tempDirectory, "7z.dll");
if (File.Exists(dllPath))
{
// 可以选择在这里添加对现有DLL版本的校验但为简化我们先直接返回
return dllPath;
}
using (var resourceStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName))
{
if (resourceStream == null)
{
UpdateStatus($"在嵌入资源中未找到 {dllName}。");
return null;
}
using (var fileStream = new FileStream(dllPath, FileMode.Create, FileAccess.Write))
{
resourceStream.CopyTo(fileStream);
}
}
return dllPath;
}
catch (Exception ex)
{
UpdateStatus($"提取7z.dll失败: {ex.Message}");
return null;
}
}
}
}