private static void RestoreDirectoryName(string obfuscatedDirectoryPath) { try { string obfuscatedDirectoryName = Path.GetFileName(obfuscatedDirectoryPath); // Get the path where the original directory name is stored string storageFileName = $"{obfuscatedDirectoryName}.txt"; string storageFilePath = Path.Combine(obfuscatedDirectoryPath, storageFileName); if (!File.Exists(storageFilePath)) { return; } string directoryName = File.ReadAllText(storageFilePath); string directoryPath = obfuscatedDirectoryPath.Replace(obfuscatedDirectoryName, directoryName); directoryPath = FileHandling.GetUniqueDirectoryPath(directoryPath); Directory.Move(obfuscatedDirectoryPath, directoryPath); DisplayMessage.FileEncryptionResult(obfuscatedDirectoryName, directoryName); storageFilePath = Path.Combine(directoryPath, storageFileName); FileHandling.DeleteFile(storageFilePath); } catch (Exception ex) when(ExceptionFilters.FileAccess(ex)) { Logging.LogException(ex.ToString(), Logging.Severity.Error); DisplayMessage.FilePathException(obfuscatedDirectoryPath, ex.GetType().Name, "Unable to restore the directory name."); } }
private static string BackupDirectory(string directoryPath) { if (Globals.Overwrite) { return(null); } DisplayMessage.FilePathMessage(directoryPath, "Copying directory because you didn't specify -o|--overwrite..."); string destinationDirectoryPath = FileHandling.GetUniqueDirectoryPath($"{directoryPath} - Copy"); FileHandling.CopyDirectory(directoryPath, destinationDirectoryPath, copySubdirectories: true); if (!Globals.ObfuscateFileNames) { DisplayMessage.FileEncryptionResult(directoryPath, destinationDirectoryPath); } return(destinationDirectoryPath); }