using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using System.Threading;
namespace DataService_Client
{
class WinRAR
{
private static Process myprocess = new Process();
public static bool Rar(string sourcePath, string destPath, string lx)
{
Process process = new System.Diagnostics.Process();
process.StartInfo.FileName = "Winrar.exe";
process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
process.StartInfo.CreateNoWindow = false;
string Myinfo = "";
bool flag = false;
try
{
if (lx == "0")
{
Myinfo = " a -ep \"" + destPath + "\" " + "\"" + sourcePath + "\"";
}
else
{
Myinfo = " X -o+ " + destPath + " \"" + sourcePath + "\"";
}
process.StartInfo.Arguments = Myinfo;
process.Start();
Thread.Sleep(3000);
if (process.HasExited && (process.ExitCode == 0))
{
flag = true;
}
KillProcess("WinRAR");
}
catch (Exception ex)
{
TPCClass.TPCCommonCls.AddErrorMsg("Rar", ex.Message, "WinRAR.txt");
}
return flag;
}
private static void KillProcess(string processname)
{
Process[] processesByName = Process.GetProcessesByName(processname);
foreach (Process process in processesByName)
{
process.Kill();
}
}
}
}