SevenZipHelper.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading;
  7. using System.Threading.Tasks;
  8. namespace NewArchivesCenter
  9. {
  10. internal class SevenZipHelper
  11. {
  12. public static void CreateEncryptedZip(string sourceDirectory, string destinationZipFile, string password)
  13. {
  14. string sevenZipPath = @"C:\Program Files\7-Zip\7z.exe";
  15. string arguments = $"a -tzip \"{destinationZipFile}\" \"{sourceDirectory}\\*\" -p{password} -mem=AES256";
  16. ProcessStartInfo startInfo = new ProcessStartInfo
  17. {
  18. FileName = sevenZipPath,
  19. Arguments = arguments,
  20. UseShellExecute = false,
  21. RedirectStandardOutput = true,
  22. RedirectStandardError = true,
  23. CreateNoWindow = true
  24. };
  25. using (Process process = Process.Start(startInfo))
  26. {
  27. process.WaitForExit();
  28. }
  29. }
  30. public static void ExtractEncryptedArchive(string archivePath, string outputPath, string password)
  31. {
  32. string zipPath = @"C:\Program Files\7-Zip\7z.exe";
  33. string arguments = $"x \"{archivePath}\" -o\"{outputPath}\" -p{password}";
  34. ProcessStartInfo psi = new ProcessStartInfo
  35. {
  36. FileName = zipPath,
  37. Arguments = arguments
  38. };
  39. using (Process process = new Process())
  40. {
  41. process.StartInfo = psi;
  42. process.Start();
  43. }
  44. Thread.Sleep(1000);
  45. }
  46. }
  47. }