iv尝试了许多不同的方法来使这个工作,我得到它基本工作,但我不能得到WaitForExit(); 像他们在这里一样工作......所以我如何将其转换为使用sevenzip?因为我无法让它工作,而且我的SFX是密码使得除了使用程序之外无法访问它们以及添加7z.DLL我无法添加它因为我收到错误:
无法添加对7za.dll的引用.请确保该文件是可访问的,并且它是有效的程序集或COM组件.
string tempFolder = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
System.Diagnostics.Process defrag1 = System.Diagnostics.Process.Start(@"AusLogics_Defrag.exe", string.Format(" -o{0} -y -Pthisisthepass", tempFolder));
defrag1.WaitForExit();
string executableDirectoryName = Path.GetDirectoryName(Application.ExecutablePath);
System.Diagnostics.Process defrag2 = System.Diagnostics.Process.Start(tempFolder + "\\" + "AusLogics_Defrag" + "\\" + "DiskDefrag.exe", "");
defrag2.WaitForExit();
System.IO.Directory.Delete(tempFolder + "\\" + "AusLogics_Defrag", true);
Run Code Online (Sandbox Code Playgroud)
新:好吧这是我到目前为止,但我得到的错误"无法加载7-zip库或内部COM错误!消息:无法加载库"
SevenZipExtractor.SetLibraryPath("7z.dll"); //no idea of this is needed or not
SevenZipCompressor.SetLibraryPath("7z.dll"); //no idea of this is needed or not
string tempFolder = Environment.GerFolderPath(Environment.SpecialFolder.ApplicationData);
SevenZipExtractor defrag = new SevenZipExtractor(@"Programs\Optimize\Auslogics_Defrag.7z");
defrag.ExtracArchive(string.Format("-o{0} -y -PThisisthepass", tempFolder));
Run Code Online (Sandbox Code Playgroud) 我正在使用SevenZipSharp将文件压缩为zip文件.有没有办法用它来从内存流创建一个zip(意思是,之前将文件加载到内存流中)?
谢谢,玛雅.
我尝试过SevenZipLib和SevenZipSharp,但没有成功.有人能给我一个使用任何免费图书馆将文本文件存档到tar.gz的工作示例吗?
我知道这不是最好的拉链方式,但这是我的要求.
我想使用SevenZipsharp压缩卷中的文件,例如将100 mb的文件压缩为10个10 mb的文件.我们可以使用7zip.exe -volume参数来做同样的事情......
例如,当我使用7Zip压缩多卷时,我得到这些文件结构:
File.7z.001
File.7z.002
File.7z.003
etc...
Run Code Online (Sandbox Code Playgroud)
文件不是独立的,不是一个大小相同的7zip文件,是一个不同卷的压缩文件,我的意思是提取我们需要的第一个文件"File.7z.001"的整个内容
我想使用SevenZipSharp做同样的事情(如果可能的话).
我在vb.net中创建了这个片段(但不管答案是否在C#代码中),我需要实现多卷选项,我需要帮助:
Imports SevenZip
Dim dll As String = "7z.dll"
Private Function SevenZipSharp_Compress(ByVal Input_DirOrFile As String, _
Optional ByVal OutputFileName As String = Nothing, _
Optional ByVal Format As OutArchiveFormat = OutArchiveFormat.SevenZip, _
Optional ByVal CompressionMode As CompressionMode = CompressionMode.Create, _
Optional ByVal CompressionMethod As CompressionMethod = CompressionMethod.Lzma, _
Optional ByVal CompressionLevel As CompressionLevel = CompressionLevel.Normal, _
Optional ByVal Password As String = Nothing) As Boolean
Try
' Set library …Run Code Online (Sandbox Code Playgroud) 我想使用SevenZipCompressor将3个文件夹压缩到一个文件中.我知道如何压缩单个文件夹.这样的事可能吗?
谢谢 !
当我尝试提取 zip 文件时出现以下错误:“SevenZip.SevenZipArchiveException: Invalid archive: open/read error!它是否加密并提供了错误的密码?如果您的档案是异国情调的,则 SevenZipSharp 可能没有为其格式签名,因此错误地认为它是 TAR。”
对 zip 文件不起作用,但对 7z 文件一切正常。是否可以使用 SevenZipExtractor 提取 zip 文件?
string sourcePath = @"c:/temp/yyy.zip";
using (var file = new SevenZipExtractor(sourcePath))
{
file.ExtractArchive(outputPath);
}
Run Code Online (Sandbox Code Playgroud) 在我的程序中,我使用SevenZipSharp生成zip文件。SevenZipSharp是一个托管DLL,它将加载另一个DLL 7z.dll。我使用SevenZipCompressor.SetLibraryPath手动将SevenZipSharp的路径设置为7z.dll。
当我在“调试”模式下执行程序时,一切正常,并且生成的zip文件非常好。但是,当我使用mstest执行单元测试时,SevenZipSharp始终会给我以下错误:
“测试方法引发异常:SevenZip.SevenZipLibraryException:无法加载7-zip库或内部COM错误!消息:无法加载库。”
我怀疑MSTest可能正在做某些事情阻止SevenZipSharp能够加载7z.dll,例如在一个安全沙箱中运行(或其他。我是C#和MSTest的新手...)
有谁知道会发生什么事吗?
谢谢!
我创建了hallo.7z并使用7zxSD_LZMA.sfx作为模块.我认为我的配置是正确的,但在提取sfx时,我收到了
7-zip:不支持的方法
void CreateExeFile()
{
try
{
SfxModule mdl = SfxModule.Extended;
SevenZipSfx sfx = new SevenZipSfx(mdl);
sfx.ModuleFileName = @"7zxSD_LZMA.sfx";
sfx.MakeSfx("D:\\hallo.7z",
new Dictionary<string, string>
{
{ "Title", "Extract Files" },
{ "InstallPath", ProgramFilesx86() + "\\ATIG Platform" },
{ "BeginPrompt", "Choose directory },
{ "CancelPrompt", "Extract Now" },
{ "OverwriteMode", "0" },
{ "GUIMode", "1" },
{ "ExtractDialogText", "Process Extract" },
{ "ExtractTitle", "Extract Files" },
{ "ErrorTitle", "Error" }
},
"D:\\hallo.exe");
MessageBox.Show("Success !");
}
catch (IOException ex) …Run Code Online (Sandbox Code Playgroud) 我正在使用SevenZipSharp库来压缩然后解压缩包含简单序列化对象的MemoryStream.但是,压缩和解压缩的流具有不同的长度.
从下面的代码运行我得到
输入长度:174输出长度:338
(包含SevenZipSharp dll作为参考,7z.dll包含在项目输出中)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
namespace DataTransmission {
class Program {
static void Main(string[] args)
{
SevenZip.SevenZipCompressor compressor = new SevenZip.SevenZipCompressor();
//compressor.CompressionMethod = SevenZip.CompressionMethod.Lzma2;
//compressor.CompressionLevel = SevenZip.CompressionLevel.Normal;
MemoryStream inputStream = new MemoryStream();
Person me = new Person("John", "Smith");
BinaryFormatter formatter = new BinaryFormatter();
formatter.Serialize(inputStream, me);
Int32 inputStreamLength = (Int32)inputStream.Length;
MemoryStream outputStream = new MemoryStream();
compressor.CompressStream(inputStream, outputStream);
SevenZip.SevenZipExtractor decompressor = new SevenZip.SevenZipExtractor(outputStream);
decompressor.ExtractFile(0, outputStream);
Int32 outputStreamLength = (Int32)outputStream.Length;
Console.WriteLine("Input …Run Code Online (Sandbox Code Playgroud) 我想使用SevenZipSharp来确定文件是否是存档.我知道这是可能的,因为在资源管理器中如果我将.zip重命名为.bmp,7zip仍然将其识别为存档.
--edit:换句话说,我想让7zip告诉我文件(无论扩展名)是否包含某种受支持的存档(zip,tar,rar,iso等)
谢谢,菲德尔