12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- using System.Diagnostics;
- using System.Threading;
- namespace Archives_Center
- {
- public 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);
- }
- }
- }
|