每个人都有自己的知识体系。
Toggle navigation
Home
随笔
C#/.Net
树莓派 / Raspberry
皓月汉化组
Beego
Golang
OxideMod
apache
haproxy
windows
Java
Objective-C
日语/罗马音歌词/日语常识
MongoDB
python
电学
公告
Minecraft服务器-公告
NanoPi
C4D (CINEMA 4D)
生活
推流/m3u8/rtmp/rtsp
Unity3d
ffmpeg
数据结构
区块链
tarui
UnityForPSVita
About Me
Archives
Tags
C# 解压程序内嵌的压缩包类型资源文件
2019-12-11 09:56:47
1485
0
0
akiragatsu
首先引入SevenZipBase 和 7z.dll public R7z() { var path = Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "7z\\7z.dll"); SevenZipBase.SetLibraryPath(path); } 我们看到SevenZipBase 中的构造方法有四个 传入文件路径的带密码的和不带密码的、传入Stream的带密码的和不带密码的 public SevenZipExtractor(Stream archiveStream); public SevenZipExtractor(string archiveFullName); public SevenZipExtractor(string archiveFullName, string password); public SevenZipExtractor(Stream archiveStream, string password); 我们的资源文件读取都是byte[] ,转换成Stream调用对应构造方法即可 static void Main(string[] args) { @"C:\Users\Administrator\Desktop\2a2baf80-8ded-4a09-80d4-880a740ebb49"); new R7z().Decompression(BytesToStream(Resources.资源文件), @"C:\Users\35337\Desktop\123456"); Console.WriteLine("完毕"); Console.ReadLine(); } public static Stream BytesToStream(byte[] bytes) { Stream stream = new MemoryStream(bytes); return stream; } /// <summary> /// 解压文件 /// </summary> /// <param name="CompressFile">压缩的文件</param> /// <param name="targetAddress">解压的目标地址下</param> /// <param name="password">解密密码</param> /// <returns></returns> public bool Decompression(Stream archiveStream, string targetAddress, string password = "") { try { if (string.IsNullOrWhiteSpace(password)) { using (var tmp = new SevenZipExtractor(archiveStream)) { for (int i = 0; i < tmp.ArchiveFileData.Count; i++) { tmp.ExtractFiles(targetAddress, tmp.ArchiveFileData[i].Index); } } } else { using (var tmp = new SevenZipExtractor(archiveStream, password)) { for (int i = 0; i < tmp.ArchiveFileData.Count; i++) { tmp.ExtractFiles(targetAddress, tmp.ArchiveFileData[i].Index); } } } } catch (Exception ex) { } return false; }
Pre:
ILSPY反编译时 常见IL推导错误
Next:
皓月云男友4 第三方开服协定
0
likes
1485
Weibo
Wechat
Tencent Weibo
QQ Zone
RenRen
Submit
Sign in
to leave a comment.
No Leanote account?
Sign up now.
0
comments
More...
Table of content
No Leanote account? Sign up now.