using System;
using System.Runtime.InteropServices;
namespace ExeP
{
/// <summary>
/// DeCompress 的摘要说明。
/// </summary>
public class DeCompress
{
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Auto)]
private struct SHELLEXECUTEINFO
{
public int cbSize;
public uint fMask;
public IntPtr hwnd;
public string lpVerb;
public string lpFile;
public string lpParameters;
public string lpDirectory;
public int nShow;
public IntPtr hInstApp;
public int lpIDList;
public string lpClass;
public IntPtr hkeyClass;
public int dwHotKey;
public IntPtr hIcon;
public IntPtr hProcess;
}
[DllImport("shell32", CharSet=CharSet.Auto)]
extern static int ShellExecuteEx(ref SHELLEXECUTEINFO lpExecInfo);
private const int SEE_MASK_INVOKELIST = 0xC;
private const int SEE_MASK_DOENVSUBST =0x200;
private const int SEE_MASK_FLAG_DDEWAIT=0x100;
//0x04000000
private const int SEE_MASK_NOCLOSEPROCESS=0x40;
private const int SEE_MASK_NO_CONSOLE=0x8000;
private const uint INFINITE=0xFFFFFFFF;
[DllImport("kernel32.dll", SetLastError=true)] static extern int CloseHandle ( int hObject) ;
[DllImport("kernel32.dll", SetLastError=true)] static extern int WaitForSingleObject ( int hHandle, uint dwMilliseconds) ;
string _rarExeFilePathName="";
public DeCompress(string rarExeFilePathName)
{
//
// TODO: 在此处添加构造函数逻辑
//
_rarExeFilePathName=rarExeFilePathName;
}
/*
解压缩 函数
*/
public bool ExtractRarFile(string sourceRarFilePathName,string targetPath)
{
SHELLEXECUTEINFO seInfo = new SHELLEXECUTEINFO();
seInfo.cbSize = Marshal.SizeOf(seInfo);
seInfo.fMask =(SEE_MASK_DOENVSUBST | SEE_MASK_FLAG_DDEWAIT | 0x04000000 | SEE_MASK_NOCLOSEPROCESS | SEE_MASK_NO_CONSOLE) ;// SEE_MASK_INVOKELIST;
seInfo.lpVerb ="open";// "properties";
seInfo.lpFile = @"c:\Winnt\NOTEPAD.EXE";
seInfo.nShow=1;
string param=" E -inul -o+ \"" + sourceRarFilePathName + "\" \"" + targetPath +"\"";
seInfo.lpParameters=param;
ShellExecuteEx(ref seInfo);
if(seInfo.hProcess.ToInt32()>0)
{
Int32 h=seInfo.hProcess.ToInt32();
WaitForSingleObject(seInfo.hProcess.ToInt32(),INFINITE); // #define INFINITE 0xFFFFFFFF // Infinite timeout
CloseHandle(seInfo.hProcess.ToInt32());
return true;
}
else
{
return false;
}
}
}
}