Public void rarsave (string rarpatch, string rarfiles, string patch, string rarname)
{
String the_rar;
Registrykey the_reg;
Object the_obj;
String the_info;
Processstartinfo the_startinfo;
Process the_process;
Try
{
The_reg = registry. classesroot. opensubkey (@ "applications \ winrar.exe \ shell \ open \ command ");
The_obj = the_reg.getvalue ("");
The_rar = the_obj.tostring ();
The_reg.close ();
The_rar = the_rar.substring (1, the_rar.length-7 );
If (! Directory. exists (patch ))
Directory. createdirectory (patch );
// Command Parameters
// The_info = "A c: \ test.rar a.txt-R"; // File compression
the_info = string. format ("A-DF {0 }\{ 1} {2}-R", patch, rarname, rarfiles ); // "A" + rarname + "" + patch;
the_startinfo = new processstartinfo ();
the_startinfo.filename = the_rar;
the_startinfo.arguments = the_info;
the_startinfo.windowstyle = processwindowstyle. hidden;
// directory where the packaged files are stored
The_startinfo.workingdirectory = rarpatch;
The_process = new process ();
The_process.startinfo = the_startinfo;
The_process.start ();
The_process.waitforexit ();
The_process.close ();
}
Catch (exception ex)
{
Throw ex;
}
}
Public String unrar (string rarpath, string rarname, string unrarpath)
{
String the_rar;
Registrykey the_reg;
Object the_obj;
String the_info;
Processstartinfo the_startinfo;
Process the_process;
Try
{
The_reg = registry. classesroot. opensubkey (@ "applications \ winrar.exe \ shell \ open \ command ");
The_obj = the_reg.getvalue ("");
The_rar = the_obj.tostring ();
The_reg.close ();
The_rar = the_rar.substring (1, the_rar.length-7 );
If (! Directory. exists (unrarpath + "\" + rarname. substring (0, rarname. lastindexof (".")-1 )))
Directory. createdirectory (unrarpath + "\" + rarname. substring (0, rarname. lastindexof (".")-1 ));
The_info = string. format ("X {0} {1 }\\{ 2}-y", rarname, unrarpath, rarname. substring (0, rarname. lastindexof (". ")-1 ));
The_startinfo = new processstartinfo ();
The_startinfo.filename = the_rar;
The_startinfo.arguments = the_info;
The_startinfo.windowstyle = processwindowstyle. hidden;
The_startinfo.workingdirectory = rarpath; // obtain the path of the compressed package
The_process = new process ();
The_process.startinfo = the_startinfo;
The_process.start ();
The_process.waitforexit ();
The_process.close ();
}
Catch (exception ex)
{
Throw ex;
}
Return ""; // server. mappath (unrarpatch );
}
Public String unrar (string rarpath, string rarname, string unrarpath, string unrarpathname)
{
String the_rar;
Registrykey the_reg;
Object the_obj;
String the_info;
Processstartinfo the_startinfo;
Process the_process;
Try
{
The_reg = registry. classesroot. opensubkey (@ "applications \ winrar.exe \ shell \ open \ command ");
The_obj = the_reg.getvalue ("");
The_rar = the_obj.tostring ();
The_reg.close ();
The_rar = the_rar.substring (1, the_rar.length-7 );
// If (! Directory. exists (unrarpath + "\" + unrarpathname ))
// Directory. createdirectory (unrarpath + "\" + unrarpathname );
// The_info = string. Format ("X {0} {1} \\{ 2}-y", rarname, unrarpath, unrarpathname );
If (! Directory. exists (unrarpath ))
Directory. createdirectory (unrarpath );
The_info = string. Format ("X {0} {1}-y", rarname, unrarpath );
The_startinfo = new processstartinfo ();
The_startinfo.filename = the_rar;
The_startinfo.arguments = the_info;
The_startinfo.windowstyle = processwindowstyle. hidden;
The_startinfo.workingdirectory = rarpath; // obtain the path of the compressed package
The_process = new process ();
The_process.startinfo = the_startinfo;
The_process.start ();
The_process.waitforexit ();
The_process.close ();
}
Catch (exception ex)
{
Throw ex;
}
Return ""; // server. mappath (unrarpatch );
}
Rarsave ("C: \ emrbs", "1.txt 2.txt"," C: \ test "," test.rar ");
Unrar ("d :\\", "f.rar", "d :\\ ftest ");