public static void ExtractAndDecrypt(string file, string password, IAlgorithm decrypter, ProgressBar progress) { UpdateProgressBar(progress, 10.0); Directory.CreateDirectory(Path.GetDirectoryName(file) + "\\EncryptedFiles"); string rarFile = Path.ChangeExtension(file, ".rar"); File.Copy(file, rarFile, true); UpdateProgressBar(progress, 20.0); WinRAR.EXTRACT(rarFile, Path.GetDirectoryName(rarFile) + "\\EncryptedFiles"); UpdateProgressBar(progress, 40.0); int allFiles = (Directory.GetFiles(Path.GetDirectoryName(file) + "\\EncryptedFiles")).Length; int i = 1; foreach (string f in Directory.GetFiles(Path.GetDirectoryName(file) + "\\EncryptedFiles")) { DecryptFile(f, password, Path.GetDirectoryName(file), decrypter); UpdateProgressBar(progress, (40 + (i / (double)allFiles) * 30)); i++; } cmd.runCommand("rmdir /s /q" + " " + "\"" + Path.GetDirectoryName(rarFile) + "\\EncryptedFiles" + "\""); UpdateProgressBar(progress, 85.0); File.Delete(rarFile); UpdateProgressBar(progress, 100.0); MessageBox.Show("File decrypted!", Assembly.GetEntryAssembly().GetName().Name); UpdateProgressBar(progress, 0.0); }
public static void OpenWithoutCrypt(string fileToOpen, ProgressBar progress) { UpdateProgressBar(progress, 10.0); Directory.CreateDirectory(Path.GetDirectoryName(fileToOpen) + "\\Files"); string rarFile = Path.ChangeExtension(fileToOpen, ".rar"); File.Copy(fileToOpen, rarFile, true); UpdateProgressBar(progress, 40.0); //estrazione WinRAR.EXTRACT(rarFile, Path.GetDirectoryName(rarFile) + "\\Files"); UpdateProgressBar(progress, 80.0); //eliminazione archivio temporaneo File.Delete(rarFile); UpdateProgressBar(progress, 100.0); MessageBox.Show("File extracted! :D", Assembly.GetEntryAssembly().GetName().Name); UpdateProgressBar(progress, 0.0); }