123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.Linq;
- using System.Text;
- using System.Threading;
- using System.Threading.Tasks;
- namespace NewArchivesCenter
- {
- internal class SevenZipHelper
- {
- public static void CreateEncryptedZip(string sourceDirectory, string destinationZipFile, string password)
- {
- string sevenZipPath = @"C:\Program Files\7-Zip\7z.exe";
- string arguments = $"a -tzip \"{destinationZipFile}\" \"{sourceDirectory}\\*\" -p{password} -mem=AES256";
- ProcessStartInfo startInfo = new ProcessStartInfo
- {
- FileName = sevenZipPath,
- Arguments = arguments,
- UseShellExecute = false,
- RedirectStandardOutput = true,
- RedirectStandardError = true,
- CreateNoWindow = true
- };
- using (Process process = Process.Start(startInfo))
- {
- process.WaitForExit();
- }
- }
- public static void ExtractEncryptedArchive(string archivePath, string outputPath, string password)
- {
- string zipPath = @"C:\Program Files\7-Zip\7z.exe";
- string arguments = $"x \"{archivePath}\" -o\"{outputPath}\" -p{password}";
- ProcessStartInfo psi = new ProcessStartInfo
- {
- FileName = zipPath,
- Arguments = arguments
- };
- using (Process process = new Process())
- {
- process.StartInfo = psi;
- process.Start();
- }
- Thread.Sleep(1000);
- }
- }
- }
|