cs压缩文件解压不了后全是这些东西,求解

程序写累了,就来玩玩酷跑小游戏吧,嘿嘿。
雨松MOMO送你一首歌曲,嘿嘿。
Unity3D研究院之LZMA压缩文件与解压文件
Unity3D研究院之LZMA压缩文件与解压文件
围观53599次
编辑日期: 字体:
前两天有朋友告诉我Unity的Assetbundle是LZMA压缩的,刚好今天有时间那么就研究研究LZMA。它是一个开源的类库,有C、 C++、C#、JAVA的类库,那么在我大Unity里面我们当然要使用C#的类库啦。
下载地址:
或者在文章的最后下载我的测试工程、如下图所示,因为9.22是Beta版本,所以我们还是老老实实下载9.20正式版本。
解压后把整个CS文件夹拖入Unity工程即可。当我在拖入Unity的时候发现Settings.cs报错了,查了一下是因为mono并不是完整的.net 。不过这个文件我们不需要用,所以直接把Settings.cs删除即可。
下面上代码,这是编辑时的一个类。我先把根目录下的一个文件压缩,接着在解压缩。
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
using UnityEngine;using System.Collections;using UnityEditor;using SevenZip.Compression.LZMA;using System.IO;using System;&public class Test : Editor {& [MenuItem ("MyMenu/CompressFile")] static void CompressFile ()
//压缩文件
CompressFileLZMA(Application.dataPath+"/1.jpg",Application.dataPath+"/2.zip");
AssetDatabase.Refresh();& } [MenuItem ("MyMenu/DecompressFile")] static void DecompressFile ()
//解压文件
DecompressFileLZMA(Application.dataPath+"/2.zip",Application.dataPath+"/3.jpg");
AssetDatabase.Refresh(); }&& private static void CompressFileLZMA(string inFile, string outFile) {
SevenZip.Compression.LZMA.Encoder coder = new SevenZip.Compression.LZMA.Encoder();
FileStream input = new FileStream(inFile, FileMode.Open);
FileStream output = new FileStream(outFile, FileMode.Create);
// Write the encoder properties
coder.WriteCoderProperties(output);
// Write the decompressed file size.
output.Write(BitConverter.GetBytes(input.Length), 0, 8);
// Encode the file.
coder.Code(input, output, input.Length, -1, null);
output.Flush();
output.Close();
input.Close(); }
private static void DecompressFileLZMA(string inFile, string outFile) {
SevenZip.Compression.LZMA.Decoder coder = new SevenZip.Compression.LZMA.Decoder();
FileStream input = new FileStream(inFile, FileMode.Open);
FileStream output = new FileStream(outFile, FileMode.Create);
// Read the decoder properties
byte[] properties = new byte[5];
input.Read(properties, 0, 5);
// Read in the decompress file size.
byte [] fileLengthBytes = new byte[8];
input.Read(fileLengthBytes, 0, 8);
long fileLength = BitConverter.ToInt64(fileLengthBytes, 0);&
// Decompress the file.
coder.SetDecoderProperties(properties);
coder.Code(input, output, input.Length, fileLength, null);
output.Flush();
output.Close();
input.Close(); }&&}
我参考了这篇文章,不过它点问题,所以我改了改。
如下图所示,我把1.jpg先压缩成2.zip ,然后在把2.zip在解压成3.jpg。
下载地址:
如果你想运行时运行LZMA按照上述代码简单改改就可以使用了。比如你把压缩过的文件放在服务器,然后用www下载到内存以后,可以通过lzma的解压方法将文件还原在保存在本地。 欢迎大家一起讨论与学习。嘿嘿,或者有什么更好的压缩方式,欢迎在下面给我留言,谢谢。
本文固定链接:
转载请注明:
雨松MOMO提醒您:亲,如果您觉得本文不错,快快将这篇文章分享出去吧 。另外请点击网站顶部彩色广告或者捐赠支持本站发展,谢谢!
作者:雨松MOMO
专注移动互联网,Unity3D游戏开发
如果您愿意花10块钱请我喝一杯咖啡的话,请用手机扫描二维码即可通过支付宝直接向我捐款哦。
您可能还会对这些文章感兴趣!主要是使用Rar.exe压缩解压文件(夹)(*.rar),另外还有使用SevenZipSharp.dll、zLib1.dll、7z.dll压缩解压文件(夹)(*.zip)。需要注意的几点如下:
1、注意Rar.exe软件存放的位置,此次放在了Debug目录下
2、SevenZipSharp.dll、zLib1.dll、7z.dll必须同时存在,否则常报&加载7z.dll错误&,项目引用时,只引用SevenZipSharp.dll即可
3、另外找不到7z.dll文件也会报错,测试时发现只用@"..\..\dll\7z.dll";相对路径时,路径是变化的,故此处才用了string libPath = System.AppDomain.CurrentDomain.BaseDirectory + @"..\..\dll\7z.dll";&&&&&&&&&&&&&&& SevenZip.SevenZipCompressor.SetLibraryPath(libPath);
具体代码如下:
using System.Collections.G
using System.L
using System.T
using System.Threading.T
namespace CompressProj
/// &summary&
/// 执行压缩命令结果
/// &/summary&
public enum CompressResults
SourceObjectNotExist,
/// &summary&
/// 执行解压缩命令结果
/// &/summary&
public enum UnCompressResults
SourceObjectNotExist,
PasswordError,
/// &summary&
/// 进程运行结果
/// &/summary&
public enum ProcessResults
CommonFunctions.cs
using System.Collections.G
using System.D
using System.IO;
using System.L
using System.T
using System.Threading.T
namespace CompressProj
class CommonFunctions
#region 单例模式
private static CommonFunctions uniqueI
private static object _lock = new object();
private CommonFunctions() { }
public static CommonFunctions getInstance()
if (null == uniqueInstance)
//确认要实例化后再进行加锁,降低加锁的性能消耗。
lock (_lock)
if (null == uniqueInstance)
uniqueInstance = new CommonFunctions();
return uniqueI
#endregion
#region 进程
/// &summary&
/// 另起一进程执行命令
/// &/summary&
/// &param name="exe"&可执行程序(路径+名)&/param&
/// &param name="commandInfo"&执行命令&/param&
/// &param name="workingDir"&执行所在初始目录&/param&
/// &param name="processWindowStyle"&进程窗口样式&/param&
/// &param name="isUseShellExe"&Shell启动程序&/param&
public void ExecuteProcess(string exe, string commandInfo, string workingDir = "", ProcessWindowStyle processWindowStyle = ProcessWindowStyle.Hidden,bool isUseShellExe = false)
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName =
startInfo.Arguments = commandI
startInfo.WindowStyle = processWindowS
startInfo.UseShellExecute = isUseShellE
if (!string.IsNullOrWhiteSpace(workingDir))
startInfo.WorkingDirectory = workingD
ExecuteProcess(startInfo);
/// &summary&
/// 直接另启动一个进程
/// &/summary&
/// &param name="startInfo"&启动进程时使用的一组值&/param&
public void ExecuteProcess(ProcessStartInfo startInfo)
Process process = new Process();
process.StartInfo = startI
process.Start();
process.WaitForExit();
process.Close();
process.Dispose();
catch(Exception ex)
throw new Exception("进程执行失败:\n\r" + startInfo.FileName + "\n\r" + ex.Message);
/// &summary&
/// 去掉文件夹或文件的只读属性
/// &/summary&
/// &param name="objectPathName"&文件夹或文件全路径&/param&
public void Attribute2Normal(string objectPathName)
if (true == Directory.Exists(objectPathName))
System.IO.DirectoryInfo directoryInfo = new System.IO.DirectoryInfo(objectPathName);
directoryInfo.Attributes = FileAttributes.N
File.SetAttributes(objectPathName,FileAttributes.Normal);
#endregion
RarOperate.cs
using System.Collections.G
using System.D
using System.IO;
using System.L
using System.T
using System.Threading.T
using System.Windows.F
namespace CompressProj
class RarOperate
private CommonFunctions commFuncs = CommonFunctions.getInstance();
#region 单例模式
private static RarOperate uniqueI
private static object _lock = new object();
private RarOperate() { }
public static RarOperate getInstance()
if (null == uniqueInstance)
//确认要实例化后再进行加锁,降低加锁的性能消耗。
lock (_lock)
if (null == uniqueInstance)
uniqueInstance = new RarOperate();
return uniqueI
#endregion
#region 压缩
/// &summary&
/// 使用Rar.exe压缩对象
/// &/summary&
/// &param name="rarRunPathName"&Rar.exe路径+对象名&/param&
/// &param name="objectPathName"&被压缩对象路径+对象名&/param&
/// &param name="objectRarPathName"&对象压缩后路径+对象名&/param&
/// &returns&&/returns&
public CompressResults CompressObject(string rarRunPathName, string objectPathName, string objectRarPathName,string password)
//被压缩对象是否存在
int beforeObjectNameIndex = objectPathName.LastIndexOf('\\');
string objectPath = objectPathName.Substring(0, beforeObjectNameIndex);
//System.IO.DirectoryInfo directoryInfo = new System.IO.DirectoryInfo(objectPathName);
if (Directory.Exists(objectPathName)/*directoryInfo.Exists*/ == false && System.IO.File.Exists(objectPathName) == false)
return CompressResults.SourceObjectNotE
//将对应字符串转换为命令字符串
string rarCommand = "\"" + rarRunPathName + "\"";
string objectPathNameCommand = "\"" + objectPathName + "\"";
int beforeObjectRarNameIndex = objectRarPathName.LastIndexOf('\\');
int objectRarNameIndex = beforeObjectRarNameIndex + 1;
string objectRarName = objectRarPathName.Substring(objectRarNameIndex);
string rarNameCommand = "\"" + objectRarName + "\"";
string objectRarPath = objectRarPathName.Substring(0, beforeObjectRarNameIndex);
//目标目录、文件是否存在
if (System.IO.Directory.Exists(objectRarPath) == false)
System.IO.Directory.CreateDirectory(objectRarPath);
else if (System.IO.File.Exists(objectRarPathName) == true)
System.IO.File.Delete(objectRarPathName);
//Rar压缩命令
string commandInfo = "a " + rarNameCommand + " " + objectPathNameCommand + " -y -p" + password + " -ep1 -r -s- -rr ";
//另起一线程执行
commFuncs.ExecuteProcess(rarCommand, commandInfo, objectRarPath, ProcessWindowStyle.Hidden);
CompressRarTest(rarCommand, objectRarPathName, password);
CorrectConfusedRar(objectRarPathName);
catch (Exception ex)
MessageBox.Show(ex.Message);
return CompressResults.UnK
return CompressResults.S
#endregion
#region 解压
/// &summary&
/// 解压:将文件解压到某个文件夹中。 注意:要对路径加上双引号,避免带空格的路径,在rar命令中失效
/// &/summary&
/// &param name="rarRunPath"&rar.exe的名称及路径&/param&
/// &param name="fromRarPath"&被解压的rar文件路径&/param&
/// &param name="toRarPath"&解压后的文件存放路径&/param&
/// &returns&&/returns&
public UnCompressResults unCompressRAR(String rarRunPath, String objectRarPathName, String objectPath, string password)
bool isFileExist = File.Exists(objectRarPathName);
if (false == isFileExist)
MessageBox.Show("解压文件不存在!" + objectRarPathName);
return UnCompressResults.SourceObjectNotE
File.SetAttributes(objectRarPathName, FileAttributes.Normal);
//去掉只读属性
if (Directory.Exists(objectPath) == false)
Directory.CreateDirectory(objectPath);
String rarCommand = "\"" + rarRunPath + "\"";
String objectPathCommand = "\"" + objectPath + "\\\"";
String commandInfo = "x \"" + objectRarPathName + "\" " + objectPath + " -y -p" +
commFuncs.ExecuteProcess(rarCommand, commandInfo, objectPath, ProcessWindowStyle.Hidden);
MessageBox.Show("解压缩成功!" + objectRarPathName);
return UnCompressResults.S
MessageBox.Show( "解压缩失败!" + objectRarPathName);
return UnCompressResults.UnK
#endregion
#region 进程
#endregion
#region 测试压缩文件
/// &summary&
/// 测试压缩后的文件是否正常。
/// &/summary&
/// &param name="rarRunPath"&&/param&
/// &param name="rarFilePathName"&&/param&
public bool CompressRarTest(String rarRunPath, String rarFilePathName,string password)
bool isOk = false;
String commandInfo = "t -p" + password + " \"" + rarFilePathName + "\"";
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = rarRunP
startInfo.Arguments = commandI
startInfo.WindowStyle = ProcessWindowStyle.H
startInfo.UseShellExecute = false;
startInfo.RedirectStandardOutput = true;
startInfo.CreateNoWindow = true;
Process process = new Process();
process.StartInfo = startI
process.Start();
StreamReader streamReader = process.StandardO
process.WaitForExit();
if (streamReader.ReadToEnd().ToLower().IndexOf("error") &= 0)
MessageBox.Show("压缩文件已损坏!");
isOk = false;
MessageBox.Show("压缩文件良好!");
isOk = true;
process.Close();
process.Dispose();
return isOk;
/// &summary&
/// 混淆Rar
/// &/summary&
/// &param name="objectRarPathName"&rar路径+名&/param&
/// &returns&&/returns&
public bool ConfusedRar(string objectRarPathName)
System.IO.FileStream fs = new FileStream(objectRarPathName, FileMode.Open);
fs.WriteByte(0x53);
fs.Close();
return true;
catch (Exception ex)
MessageBox.Show("混淆Rar失败!" + ex.Message);
return false;
/// &summary&
/// 纠正混淆的Rar
/// &/summary&
/// &param name="objectRarPathName"&rar路径+名&/param&
/// &returns&&/returns&
public bool CorrectConfusedRar(string objectRarPathName)
bool isCorrect = false;
//先判断一下待解压文件是否经过混淆
FileStream fsRar = new FileStream(objectRarPathName, FileMode.Open, FileAccess.Read);
int b = fsRar.ReadByte();
fsRar.Close();
if (b != 0x52)
//R:0x52 原始开始值
string strTempFile = System.IO.Path.GetTempFileName();
File.Copy(objectRarPathName, strTempFile, true);
File.SetAttributes(strTempFile, FileAttributes.Normal);
//去掉只读属性
FileStream fs = new FileStream(strTempFile, FileMode.Open);
fs.WriteByte(0x52);
fs.Close();
System.IO.File.Delete(objectRarPathName);
File.Copy(strTempFile, objectRarPathName, true);
isCorrect = true;
return isC
MessageBox.Show("判断待解压文件是否经过混淆时出错!" + objectRarPathName);
return isC
#endregion
#endregion
ZipOperate.cs
using SevenZ
using System.Collections.G
using System.IO;
using System.L
using System.T
using System.Threading.T
using System.Windows.F
namespace CompressProj
class ZipOperate
#region 单例模式
private static ZipOperate uniqueI
private static object _lock = new object();
private ZipOperate() { }
public static ZipOperate getInstance()
if (null == uniqueInstance)
//确认要实例化后再进行加锁,降低加锁的性能消耗。
lock (_lock)
if (null == uniqueInstance)
uniqueInstance = new ZipOperate();
return uniqueI
#endregion
#region 7zZip压缩、解压方法
/// &summary&
/// 压缩文件
/// &/summary&
/// &param name="objectPathName"&压缩对象(即可以是文件夹|也可以是文件)&/param&
/// &param name="objectZipPathName"&保存压缩文件的路径&/param&
/// &param name="strPassword"&加密码&/param&
/// 测试压缩文件夹:压缩文件(objectZipPathName)不能放在被压缩文件(objectPathName)内,否则报&文件夹被另一进程使用中&错误。
/// &returns&&/returns&
public CompressResults Compress7zZip(String objectPathName, String objectZipPathName, String strPassword)
///releases/view/51254 下载sevenzipsharp.dll
//SevenZipSharp.dll、zLib1.dll、7z.dll必须同时存在,否则常报&加载7z.dll错误&
string libPath = System.AppDomain.CurrentDomain.BaseDirectory + @"..\..\dll\7z.dll";
SevenZip.SevenZipCompressor.SetLibraryPath(libPath);
SevenZip.SevenZipCompressor sevenZipCompressor = new SevenZip.SevenZipCompressor();
pressionLevel = pressionLevel.F
sevenZipCompressor.ArchiveFormat = SevenZip.OutArchiveFormat.Z
//被压缩对象是否存在
int beforeObjectNameIndex = objectPathName.LastIndexOf('\\');
string objectPath = objectPathName.Substring(0, beforeObjectNameIndex);
//System.IO.DirectoryInfo directoryInfo = new System.IO.DirectoryInfo(objectPathName);
if (Directory.Exists(objectPathName)/*directoryInfo.Exists*/ == false && System.IO.File.Exists(objectPathName) == false)
return CompressResults.SourceObjectNotE
int beforeObjectRarNameIndex = objectZipPathName.LastIndexOf('\\');
int objectRarNameIndex = beforeObjectRarNameIndex + 1;
//string objectZipName = objectZipPathName.Substring(objectRarNameIndex);
string objectZipPath = objectZipPathName.Substring(0, beforeObjectRarNameIndex);
//目标目录、文件是否存在
if (System.IO.Directory.Exists(objectZipPath) == false)
System.IO.Directory.CreateDirectory(objectZipPath);
else if (System.IO.File.Exists(objectZipPathName) == true)
System.IO.File.Delete(objectZipPathName);
if (Directory.Exists(objectPathName))
//压缩对象是文件夹
if (String.IsNullOrEmpty(strPassword))
pressDirectory(objectPathName, objectZipPathName);
pressDirectory(objectPathName, objectZipPathName, strPassword);
//压缩对象是文件 无加密方式
pressFiles(objectZipPathName, objectPathName);
return CompressResults.S
catch(Exception ex)
MessageBox.Show("压缩文件失败!" + ex.Message);
return CompressResults.UnK
/// &summary&
/// 解压缩文件
/// &/summary&
/// &param name="zipFilePathName"&zip文件具体路径+名&/param&
/// &param name="unCompressDir"&解压路径&/param&
/// &param name="strPassword"&解密码&/param&
/// &returns&&/returns&
public UnCompressResults UnCompress7zZip(String zipFilePathName, String unCompressDir, String strPassword)
//SevenZipSharp.dll、zLib1.dll、7z.dll必须同时存在,否则常报&加载7z.dll错误&而项目引用时,只引用SevenZipSharp.dll就可以了
string libPath = System.AppDomain.CurrentDomain.BaseDirectory + @"..\..\dll\7z.dll";
SevenZip.SevenZipCompressor.SetLibraryPath(libPath);
bool isFileExist = File.Exists(zipFilePathName);
if (false == isFileExist)
MessageBox.Show("解压文件不存在!" + zipFilePathName);
return UnCompressResults.SourceObjectNotE
File.SetAttributes(zipFilePathName, FileAttributes.Normal);
//去掉只读属性
if (Directory.Exists(unCompressDir) == false)
Directory.CreateDirectory(unCompressDir);
SevenZip.SevenZipExtractor sevenZipE
if (String.IsNullOrEmpty(strPassword))
sevenZipExtractor = new SevenZip.SevenZipExtractor(zipFilePathName);
sevenZipExtractor = new SevenZip.SevenZipExtractor(zipFilePathName, strPassword);
sevenZipExtractor.ExtractArchive(unCompressDir);
sevenZipExtractor.Dispose();
return UnCompressResults.S
catch(Exception ex)
MessageBox.Show("解压缩文件失败!" + ex.Message);
return UnCompressResults.UnK
#endregion
FileOperate.cs
using System.Collections.G
using System.IO;
using System.L
using System.T
using System.Threading.T
using System.Windows.F
namespace CompressProj
class FileOperate
private RarOperate rarOperate = RarOperate.getInstance();
#region 单例模式
private static FileOperate uniqueI
private static object _lock = new object();
private FileOperate() { }
public static FileOperate getInstance()
if (null == uniqueInstance)
//确认要实例化后再进行加锁,降低加锁的性能消耗。
lock (_lock)
if (null == uniqueInstance)
uniqueInstance = new FileOperate();
return uniqueI
#endregion
/// &summary&
/// 打开文件
/// &/summary&
/// &param name="openFileDialog"&&/param&
/// &param name="filter"&&/param&
/// &param name="isReadOnly"&是否另外开启一使用该文件进程,防止该文件被操作&/param&
/// &returns&&/returns&
public string OpenFile(OpenFileDialog openFileDialog,string filter,string openFileDialogTitle = "压缩文件",bool isReadOnly = false)
string filePathName = string.E
if (string.IsNullOrEmpty(filter))
filter = "AllFiles(*.*)|*.*";
//TXT(*.txt)|*.txt|Word(*.doc,*.docx)|*.*.docx|图像文件(*.*.*.*.*.psd)|*.*.*.*.*.psd|
openFileDialog.Filter =
DialogResult dResult = openFileDialog.ShowDialog();
if (dResult == DialogResult.OK)
string defaultExt = ".docx";
//string filter = string.E
//openFileDialog.ReadOnlyChecked = isReadO
openFileDialog.SupportMultiDottedExtensions = true;
openFileDialog.AutoUpgradeEnabled = true;
openFileDialog.AddExtension = true;
openFileDialog.CheckPathExists = true;
openFileDialog.CheckFileExists = true;
openFileDialog.DefaultExt = defaultE
openFileDialog.Multiselect = true;
openFileDialog.ShowReadOnly = true;
openFileDialog.Title = openFileDialogT
openFileDialog.ValidateNames = true;
openFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Templates);
//添加后界面没变化 Win7 + VS11
openFileDialog.ShowHelp = true;
filePathName = openFileDialog.FileN
if (true == isReadOnly)
openFileDialog.OpenFile();
//打开只读文件,即开启一使用该文件进程,防止其他进程操作该文件
openFileDialog.Dispose();
return filePathN
/// &summary&
/// 打开文件
/// &/summary&
/// &param name="saveFileDialog"&&/param&
/// &param name="filter"&&/param&
/// &param name="isReadOnly"&&/param&
/// &returns&&/returns&
public string SaveFile(SaveFileDialog saveFileDialog, string filter,string saveFileDialogTitle = "保存文件", bool isReadOnly = false)
string filePathName = string.E
if (string.IsNullOrEmpty(filter))
filter = "AllFiles(*.*)|*.*";
//TXT(*.txt)|*.txt|Word(*.doc,*.docx)|*.*.docx|图像文件(*.*.*.*.*.psd)|*.*.*.*.*.psd|
saveFileDialog.Filter =
DialogResult dResult = saveFileDialog.ShowDialog();
if (dResult == DialogResult.OK)
string defaultExt = ".docx";
//string filter = string.E
//string saveFileDialogTitle = "保存文件";
saveFileDialog.SupportMultiDottedExtensions = true;
saveFileDialog.AutoUpgradeEnabled = true;
saveFileDialog.AddExtension = true;
saveFileDialog.CheckPathExists = true;
saveFileDialog.CheckFileExists = true;
saveFileDialog.DefaultExt = defaultE
saveFileDialog.RestoreDirectory = true;
saveFileDialog.OverwritePrompt = true;
saveFileDialog.Title = saveFileDialogT
saveFileDialog.ValidateNames = true;
saveFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Templates);
//添加后界面没变化 Win7 + VS11
saveFileDialog.ShowHelp = true;
filePathName = saveFileDialog.FileN
if (true == isReadOnly)
saveFileDialog.OpenFile();
//打开只读文件,即开启一使用该文件进程,防止其他进程操作该文件
saveFileDialog.Dispose();
return filePathN
测试调用代码如下:
RarForm.cs
using System.Collections.G
using ponentM
using System.D
using System.D
using System.D
using System.IO;
using System.L
using System.T
using System.Threading.T
using System.Windows.F
namespace CompressProj
public partial class RarForm : Form
private FileOperate fileOperate = FileOperate.getInstance();
private RarOperate rarOperate = RarOperate.getInstance();
private ZipOperate zipOperate = ZipOperate.getInstance();
public RarForm()
InitializeComponent();
private void btnCompress_Click(object sender, EventArgs e)
string filter = "TXT(*.txt)|*.txt|Word(*.doc,*.docx)|*.*.docx|AllFiles(*.*)|*.*";
string openFileDialogTitle = "压缩文件";
string compressFilePathName = fileOperate.OpenFile(this.openFileDialog1, filter, openFileDialogTitle,true);
if (string.IsNullOrEmpty(compressFilePathName) || string.IsNullOrWhiteSpace(compressFilePathName))
this.openFileDialog1.HelpRequest += new EventHandler(openFileDialog1_HelpRequest);
string objectRarPathName = compressFilePathName.Substring(0,compressFilePathName.LastIndexOf('.')) + ".rar";
string rarPathName = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\Rar.exe";
string password = string.E//"shenc";
CompressResults compressResult = pressObject(rarPathName, compressFilePathName, objectRarPathName, password);
if (CompressResults.Success == compressResult)
MessageBox.Show(objectRarPathName);
private void openFileDialog1_HelpRequest(object sender, EventArgs e)
MessageBox.Show("HelpRequest!");
private void btnUncompress_Click(object sender, EventArgs e)
string filter = "Rar(*.rar)|*.rar";
string openFileDialogTitle = "解压文件";
string unCompressFilePathName = fileOperate.OpenFile(this.openFileDialog1, filter, openFileDialogTitle, false);
if (string.IsNullOrEmpty(unCompressFilePathName) || string.IsNullOrWhiteSpace(unCompressFilePathName))
string objectPath = unCompressFilePathName.Substring(0, unCompressFilePathName.LastIndexOf('.'));
string rarPathName = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\Rar.exe";
string password = string.E//"shenc";
UnCompressResults unCompressResult = rarOperate.unCompressRAR(rarPathName, unCompressFilePathName, objectPath, password);
if (UnCompressResults.Success == unCompressResult)
MessageBox.Show(objectPath);
private void btnCompressZip_Click(object sender, EventArgs e)
string filter = "TXT(*.txt)|*.txt|Word(*.doc,*.docx)|*.*.docx|AllFiles(*.*)|*.*";
string openFileDialogTitle = "压缩文件";
string compressFilePathName = fileOperate.OpenFile(this.openFileDialog1, filter, openFileDialogTitle, false);
if (string.IsNullOrEmpty(compressFilePathName) || string.IsNullOrWhiteSpace(compressFilePathName))
//this.openFileDialog1.HelpRequest += new EventHandler(openFileDialog1_HelpRequest);
string password = string.E//"shenc";
string objectZipPathName = compressFilePathName.Substring(0, compressFilePathName.LastIndexOf('.')) + ".zip";
CompressResults compressResult = press7zZip(compressFilePathName, objectZipPathName, password); //压缩文件
////测试压缩文件夹:压缩文件不能放在被压缩文件内,否则报&文件夹被另一进程使用中&错误。
//string objectPath = compressFilePathName.Substring(0, compressFilePathName.LastIndexOf('\\'));
//objectZipPathName = objectPath + ".zip";
//CompressResults compressResult = press7zZip(objectPath, objectZipPathName, password);
//压缩文件夹
if (CompressResults.Success == compressResult)
MessageBox.Show(objectZipPathName);
private void btnUnCompressZip_Click(object sender, EventArgs e)
string filter = "Zip(*.zip)|*.zip";
string openFileDialogTitle = "解压文件";
string unCompressFilePathName = fileOperate.OpenFile(this.openFileDialog1, filter, openFileDialogTitle, false);
if (string.IsNullOrEmpty(unCompressFilePathName) || string.IsNullOrWhiteSpace(unCompressFilePathName))
string objectPath = unCompressFilePathName.Substring(0, unCompressFilePathName.LastIndexOf('.'));
string password = string.E//"shenc";
UnCompressResults unCompressResult = zipOperate.UnCompress7zZip(unCompressFilePathName, objectPath, password);
if (UnCompressResults.Success == unCompressResult)
MessageBox.Show(objectPath);
阅读(...) 评论()}

我要回帖

更多关于 压缩文件解压密码破解 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信