static void OnChanged(object source, FileSystemEventArgs e) { Console.WriteLine($"File: {e.FullPath} {e.ChangeType}"); BackupCreation.CreateBackupDirectories(BackupCreation.GetAllFilesForBackups(Program.pathToOriginal), Program.pathToAllBackups); BackupCreation.CreateBackup(e.FullPath); }
private static string GetBackupDirectory(int docnum, string pathtooriginals, string pathtobackups) { string[] originalFiles = BackupCreation.GetAllFilesForBackups(pathtooriginals); string name = Path.GetFileName(originalFiles[docnum]); string pathToDirectory = string.Format(@"{0}{1}\", pathtobackups, name); return(pathToDirectory); }
public static void ShowOriginalFiles(string path) { string[] originalFiles = BackupCreation.GetAllFilesForBackups(path); for (int i = 0; i < originalFiles.Length; i++) { Console.WriteLine($"{i} {originalFiles[i]}"); } }
public static void FileRecover(int docnum, int versionum, string pathtooriginals, string pathtobackups) { string[] filesToBackup = Directory.GetFiles(GetBackupDirectory(docnum, pathtooriginals, pathtobackups)); string pathToFile = string.Format(filesToBackup[versionum]); string[] originalFiles = BackupCreation.GetAllFilesForBackups(pathtooriginals); string name = Path.GetFileName(originalFiles[docnum]); string pathToOriginal = string.Format(@"{0}{1}", pathtooriginals, name); string[] strings = File.ReadAllLines(pathToFile); File.WriteAllLines(pathToOriginal, strings); }
public static void DoCase1() { FileSystemWatcher watcher = new FileSystemWatcher(); watcher.Path = Program.pathToOriginal; watcher.Filter = "*.txt"; watcher.Changed += OnChanged; watcher.Created += OnChanged; watcher.Deleted += OnChanged; watcher.Renamed += OnRenamed; string[] files = BackupCreation.GetAllFilesForBackups(Program.pathToOriginal); BackupCreation.CreateBackupDirectories(files, Program.pathToAllBackups); BackupCreation.CreateBackup(files, Program.pathToAllBackups); watcher.EnableRaisingEvents = true; Console.ReadKey(); }
static void OnRenamed(object source, RenamedEventArgs e) { Console.WriteLine($"File: {e.OldFullPath} renamed to {e.FullPath}"); BackupCreation.RenameDirectory(e.FullPath, e.OldFullPath); }