public bool DeleteExpiredBackups() { if (_useDatabase) { foreach (int backupToDelete in _expiredDBBackups) { LoadedBackupDB.DeleteBackup(backupToDelete); } foreach (int orphanFileEntry in LoadedBackupDB.GetOrphanFiles()) { string dbBackupFilePath = LoadedBackupDB.GetBackupFilePathByEntryID(orphanFileEntry); if (File.Exists(Path.Combine(FullBackupLocationDBDataPath, dbBackupFilePath))) { File.Delete(Path.Combine(FullBackupLocationDBDataPath, dbBackupFilePath)); } LoadedBackupDB.DeleteFile(orphanFileEntry); } LoadedBackupDB.WriteDatabaseToFile(); _expiredDBBackups = null; return(true); //would come in handy if we ever added a progress dialog. } else { foreach (string folderToDelete in _expiredFolders) { Directory.Delete(folderToDelete, true); } _expiredFolders = null; return(true); //would come in handy if we ever added a progress dialog. } }
private bool BackUpWithDatabase() { if (!Directory.Exists(FullBackupLocationDBDataPath)) { Directory.CreateDirectory(FullBackupLocationDBDataPath); } int backupID = LoadedBackupDB.StartBackup(); DialogResult backupResult = _progressDialog.StartProgressDialog(_generalResourceManager.GetString("BackupProgressTitle"), _generalResourceManager.GetString("BackupProgressText"), _source.SourceSize.Value, bg_BackUpWithDatabase_DoWork, backupID); if (backupResult != DialogResult.Cancel) { LoadedBackupDB.CompleteBackup(backupID); LoadedBackupDB.WriteDatabaseToFile(); return(true); } else { return(false); } }
private bool RecursiveDatabaseBasedCopy(DirectoryInfo fromFolder, int backupID) { foreach (FileInfo sourceFile in fromFolder.GetFiles()) { bool physicalCopy; string physicalFileName; int?existingFileID = LoadedBackupDB.GetFileRecordIDByProperties(_source.StripSourceFromPath(sourceFile.FullName), sourceFile.LastWriteTime, sourceFile.Length); if (existingFileID == null) { existingFileID = LoadedBackupDB.AddFileRecord(_source.StripSourceFromPath(sourceFile.FullName), sourceFile.LastWriteTime, sourceFile.Length); physicalFileName = ""; physicalCopy = true; } else { physicalFileName = LoadedBackupDB.GetBackupFilePathByEntryID(existingFileID.Value); if (!string.IsNullOrEmpty(physicalFileName) && File.Exists(Path.Combine(FullBackupLocationDBDataPath, physicalFileName))) { physicalCopy = false; } else { physicalCopy = true; } } if (physicalCopy) { physicalFileName = DefineDBDataFileName(existingFileID.Value, _source.StripSourceFromPath(sourceFile.FullName), sourceFile.LastWriteTime, sourceFile.Length, _password); string SHA1 = ""; if (string.IsNullOrEmpty(_password)) { sourceFile.CopyTo(Path.Combine(FullBackupLocationDBDataPath, physicalFileName), true); //No SHA1 - would be expensive to calculate given that we are using simple file copy. } else { SHA1 = Utils.EncryptFile(sourceFile.FullName, Path.Combine(FullBackupLocationDBDataPath, physicalFileName), _password); } LoadedBackupDB.UpdateDBDataFileName(existingFileID.Value, physicalFileName, SHA1); } LoadedBackupDB.AddBackupFileRecord(backupID, existingFileID.Value); //update progress (exit if cancelled) if (_progressDialog != null && !_progressDialog.Worker_SetSpecificProgress(null, _progressDialog.CurrentCount + sourceFile.Length, null)) { return(false); } } foreach (DirectoryInfo sourceFolder in fromFolder.GetDirectories()) { if (!RecursiveDatabaseBasedCopy(sourceFolder, backupID)) { return(false); //if cancelled at any point, return/abort. (recursive...) } } return(true); //if we got to this point, so far so good! (recursive...) }