/// Use WinRAR for compression /// </Summary> /// <Param name = "path"> folder to be compressed (absolute path) </param> /// <Param name = "rarPath"> compressed. rar directory (absolute path) </param> /// <Param name = "rarName"> name (including suffix) of the compressed file </param> /// <Returns> true or false. True is returned if compression is successful. Otherwise, false is returned. </Returns> Public bool RAR (string path, string rarPath, string rarName) { Bool flag = false; String rarexe; // The complete path of WinRAR.exe RegistryKey regkey; // registry key Object regvalue; // key value String cmd; // WinRAR Command Parameters ProcessStartInfo startinfo; Process process; Try { Regkey = Registry. ClassesRoot. OpenSubKey (@ "Applications \ WinRAR.exe \ shell \ open \ command "); Regvalue = regkey. GetValue (""); // the key value is "d: \ Program Files \ WinRAR \ WinRAR.exe" "% 1" Rarexe = regvalue. ToString (); Regkey. Close (); Rarexe = rarexe. Substring (1, rarexe. Length-7); // d: \ Program Files \ WinRAR \ WinRAR.exe Directory. CreateDirectory (path ); // The compression command, which is equivalent to right-clicking on the folder (path) to be compressed-> WinRAR-> adding to the compressed file-> entering the compressed file name (rarName) Cmd = string. Format ("a {0} {1}-r", rarName, path ); Startinfo = new ProcessStartInfo (); Startinfo. FileName = rarexe; Startinfo. Arguments = cmd; // set Command Parameters Startinfo. WindowStyle = ProcessWindowStyle. Hidden; // hide the WinRAR window Startinfo. WorkingDirectory = rarPath; Process = new Process (); Process. StartInfo = startinfo; Process. Start (); Process. WaitForExit (); // wait for the winrar.exe process to exit indefinitely If (process. HasExited) { Flag = true; } Process. Close (); } Catch (Exception e) { Throw e; } Return flag; } /// <Summary> /// Decompress the package using WinRAR /// </Summary> /// <Param name = "path"> extract the file path (absolute) </param> /// <Param name = "rarPath"> storage directory of the. rar file to be decompressed (absolute path) </param> /// <Param name = "rarName"> name Of The. rar file to be decompressed (including the suffix) </param> /// <Returns> true or false. True is returned for successful decompression. Otherwise, false is returned. </Returns> Public bool UnRAR (string path, string rarPath, string rarName) { Bool flag = false; String rarexe; RegistryKey regkey; Object regvalue; String cmd; ProcessStartInfo startinfo; Process process; Try { Regkey = Registry. ClassesRoot. OpenSubKey (@ "Applications \ WinRAR.exe \ shell \ open \ command "); Regvalue = regkey. GetValue (""); Rarexe = regvalue. ToString (); Regkey. Close (); Rarexe = rarexe. Substring (1, rarexe. Length-7 ); Directory. CreateDirectory (path ); // Decompress the command, which is equivalent to right-clicking on the file to be compressed (rarName)-> WinRAR-> decompressing to the current folder Cmd = string. Format ("x {0} {1}-y", rarName, path ); Startinfo = new ProcessStartInfo (); Startinfo. FileName = rarexe; Startinfo. Arguments = cmd; Startinfo. WindowStyle = ProcessWindowStyle. Hidden; Startinfo. WorkingDirectory = rarPath; Process = new Process (); Process. StartInfo = startinfo; Process. Start (); Process. WaitForExit (); If (process. HasExited) { Flag = true; } Process. Close (); } Catch (Exception e) { Throw e; } Return flag; } /// <Summary> /// Use WinRAR for compression /// </Summary> /// <Param name = "path"> folder to be compressed (absolute path) </param> /// <Param name = "rarPath"> compressed. rar directory (absolute path) </param> /// <Param name = "rarName"> name (including suffix) of the compressed file </param> /// <Returns> true or false. True is returned if compression is successful. Otherwise, false is returned. </Returns> Public bool RAR (string path, string rarPath, string rarName) { Bool flag = false; String rarexe; // The complete path of WinRAR.exe RegistryKey regkey; // registry key Object regvalue; // key value String cmd; // WinRAR Command Parameters ProcessStartInfo startinfo; Process process; Try { Regkey = Registry. ClassesRoot. OpenSubKey (@ "Applications \ WinRAR.exe \ shell \ open \ command "); Regvalue = regkey. GetValue (""); // the key value is "d: \ Program Files \ WinRAR \ WinRAR.exe" "% 1" Rarexe = regvalue. ToString (); Regkey. Close (); Rarexe = rarexe. Substring (1, rarexe. Length-7); // d: \ Program Files \ WinRAR \ WinRAR.exe Directory. CreateDirectory (path ); // The compression command, which is equivalent to right-clicking on the folder (path) to be compressed-> WinRAR-> adding to the compressed file-> entering the compressed file name (rarName) Cmd = string. Format ("a {0} {1}-r", rarName, path ); Startinfo = new ProcessStartInfo (); Startinfo. FileName = rarexe; Startinfo. Arguments = cmd; // set Command Parameters Startinfo. WindowStyle = ProcessWindowStyle. Hidden; // hide the WinRAR window Startinfo. WorkingDirectory = rarPath; Process = new Process (); Process. StartInfo = startinfo; Process. Start (); Process. WaitForExit (); // wait for the winrar.exe process to exit indefinitely If (process. HasExited) { Flag = true; } Process. Close (); } Catch (Exception e) { Throw e; } Return flag; } /// <Summary> /// Decompress the package using WinRAR /// </Summary> /// <Param name = "path"> extract the file path (absolute) </param> /// <Param name = "rarPath"> storage directory of the. rar file to be decompressed (absolute path) </param> /// <Param name = "rarName"> name Of The. rar file to be decompressed (including the suffix) </param> /// <Returns> true or false. True is returned for successful decompression. Otherwise, false is returned. </Returns> Public bool UnRAR (string path, string rarPath, string rarName) { Bool flag = false; String rarexe; RegistryKey regkey; Object regvalue; String cmd; ProcessStartInfo startinfo; Process process; Try { Regkey = Registry. ClassesRoot. OpenSubKey (@ "Applications \ WinRAR.exe \ shell \ open \ command "); Regvalue = regkey. GetValue (""); Rarexe = regvalue. ToString (); Regkey. Close (); Rarexe = rarexe. Substring (1, rarexe. Length-7 ); Directory. CreateDirectory (path ); // Decompress the command, which is equivalent to right-clicking on the file to be compressed (rarName)-> WinRAR-> decompressing to the current folder Cmd = string. Format ("x {0} {1}-y", rarName, path ); Startinfo = new ProcessStartInfo (); Startinfo. FileName = rarexe; Startinfo. Arguments = cmd; Startinfo. WindowStyle = ProcessWindowStyle. Hidden; Startinfo. WorkingDirectory = rarPath; Process = new Process (); Process. StartInfo = startinfo; Process. Start (); Process. WaitForExit (); If (process. HasExited) { Flag = true; } Process. Close (); } Catch (Exception e) { Throw e; } Return flag; } |