using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using Microsoft.Win32;
namespace SmartOfflineUpdater
{
/// <summary>
/// 解压帮助类
/// </summary>
public class UnPackHelper
{
/// <summary>
/// 构造函数
/// </summary>
/// <param name="filePath">解压文件路径</param>
/// <param name="folder">解压到文件夹</param>
public UnPackHelper(string filePath, string folder)
{
FilePath = filePath;
UnPackDirectory = folder;
}
private string m_FilePath;
/// <summary>
/// 解压文件路径
/// </summary>
public string FilePath
{
get { return m_FilePath; }
set { m_FilePath = value; }
}
private string m_UnPackDirectory;
/// <summary>
/// 解压到文件夹路径
/// </summary>
public string UnPackDirectory
{
get { return m_UnPackDirectory; }
set { m_UnPackDirectory = value; }
}
/// <summary>
/// 解压开始
/// </summary>
public void DoUnPack()
{
Console.WriteLine("开始解压......");
RegistryKey reg;
string rarPath;
Process process = new Process();
try
{
reg=Registry.ClassesRoot.OpenSubKey(@"Applications\WinRar.exe\Shell\Open\Command");
rarPath = reg.GetValue("").ToString();
rarPath = rarPath.Substring(1, rarPath.Length - 7);
process.StartInfo.FileName = rarPath;
process.StartInfo.CreateNoWindow = true;
process.StartInfo.UseShellExecute = false;
// -0+ 如果已经存在则覆盖
process.StartInfo.Arguments = string.Format(" x -o+ {0} {1}", FilePath, UnPackDirectory);//这里是命令行 请参考winrar的说明
//开始解压
process.Start();
//进程终止
if (process.HasExited)
{
int exitCode = process.ExitCode;
if (exitCode == 0)
Console.WriteLine("{0} 正常完成", exitCode.ToString());
else
Console.WriteLine("{0} 正常完成", exitCode.ToString());
}
Console.WriteLine("解压完成");
}
catch (Exception ex)
{
throw ex;
}
finally
{
//释放资源
process.Close();
}
}
/// <summary>
/// 外部调用解压
/// </summary>
/// <param name="filePath"></param>
/// <param name="folder"></param>
public static void DoUnPack(string filePath, string folder)
{
UnPackHelper helper = new UnPackHelper(filePath, folder);
helper.DoUnPack();
}
}
}
Are you interested in Data Engineering Essentials course on Kontext? Learn more
.net C# winrar 解压程序
info Last modified by Raymond 14 years ago
copyright
This page is subject to Site terms.
Log in with external accounts
timeline Stats
Page index
0.10
More from Kontext
Cross-Platform .NET 6 Image Processing Libraries
visibility
567
thumb_up
0
access_time
5 months ago
SQLite in .NET Core with Entity Framework Core
visibility
55,278
thumb_up
3
access_time
2 years ago
Migrate ASP.NET Core Projects – VS2015 to VS2017 and TFS2015 to TFS2017 Issues and Fixes
visibility
768
thumb_up
0
access_time
2 years ago