public BackupProject Clone() { BackupProject cp = new BackupProject(); cp.Name = Name; cp.BackupFolder = BackupFolder; cp.SourceFolder = SourceFolder; cp.Password = Password; cp.SafePassword = SafePassword.Clone(); cp.ExcludeExtensions = new List <string>(); foreach (string ss in ExcludeExtensions) { cp.ExcludeExtensions.Add(ss); } cp.ExcludeFiles = new List <string>(); foreach (string ss in ExcludeFiles) { cp.ExcludeFiles.Add(ss); } cp.SourceCredentials = SourceCredentials.Clone(); cp.BackupCredentials = BackupCredentials.Clone(); cp.UseVolumeShadowService = UseVolumeShadowService; cp.DoNotRemind = DoNotRemind; cp.AlternativePassword = AlternativePassword; lock (ArchiveFileList) cp.ArchiveFileList = ArchiveFileList.Clone(); cp.MostRecentBackup = MostRecentBackup; // The Manifest Cache is not cloned. return(cp); }
public void LoadAll(BackupProject Project) { Archives = new List <ArchiveFilename>(); try { FileInfo[] FileList = new DirectoryInfo(Project.CompleteBackupFolder).GetFiles("Backup_*.zip"); foreach (FileInfo fi in FileList) { ArchiveFilename af; if (!ArchiveFilename.TryParse(fi.Name, out af)) { continue; } Archives.Add(af); } } catch (DirectoryNotFoundException) { return; } }
public static BackupProject CreateDefault() { BackupProject ret = new BackupProject(); ret.Name = "My Documents"; ret.SourceFolder = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); // Determine if the user has DropBox installed... string Home = Utility.GetUserHomeDirectory(); if (Directory.Exists(Home + "\\DropBox")) { ret.BackupFolder = Home + "\\DropBox\\My Backups"; } else if (Directory.Exists(Home + "\\Google Drive")) { ret.BackupFolder = Home + "\\Google Drive\\My Backups"; } else { ret.BackupFolder = Home + "\\Backups"; } return(ret); }
/// <summary> /// LoadArchiveManifest decompresses the manifest information from the backup archive into RAM /// and converts it from XML into a Manifest object. An exception is thrown if the manifest /// cannot be retrieved. /// /// Precondition: Access to the backup folder must be available - thus any impersonation should /// be done before calling. /// </summary> /// <returns>The manifest from this backup archive.</returns> public Manifest LoadArchiveManifest(BackupProject Project, bool PromptForPassword) { try { using (ZipFile zip = ZipFile.Read(Project.CompleteBackupFolder + "\\" + this.ToString())) { foreach (ZipEntry ze in zip) { if (ze.FileName.ToLowerInvariant() == "manifest.xml") { using (MemoryStream ms = new MemoryStream()) { try { if (String.IsNullOrEmpty(Project.SafePassword.Password)) { ze.Extract(ms); } else { ze.ExtractWithPassword(ms, Project.SafePassword.Password); } } catch (Ionic.Zip.BadPasswordException bpe1) { try { if (!String.IsNullOrEmpty(Project.AlternativePassword)) { ze.ExtractWithPassword(ms, Project.AlternativePassword); } else { throw bpe1; } } catch (Ionic.Zip.BadPasswordException) { bool FirstPrompt = true; if (!PromptForPassword) { throw bpe1; } while (PromptForPassword) { PasswordForm pf = new PasswordForm(); if (FirstPrompt) { pf.Prompt = "The archive '" + ToString() + "' was created with a different password. (242)"; } else { pf.Prompt = "That was not a valid password for the archive '" + ToString() + "'."; } FirstPrompt = false; if (pf.ShowDialog() != DialogResult.OK) { throw new CancelException(); } Project.AlternativePassword = pf.Password; try { ze.ExtractWithPassword(ms, Project.AlternativePassword); break; } catch (Ionic.Zip.BadPasswordException) { } } } } ms.Seek(0, System.IO.SeekOrigin.Begin); try { Manifest ret = Manifest.FromXml(ms); if (ret == null) { throw new FormatException(); } return(ret); } catch (Exception ex) { throw new FormatException("Unable to parse archive's manifest. Error: " + ex.Message + "\n\n" + "Project: " + Project.ToString() + "\nArchive: " + ToString() + "\nManifest File: " + ze.FileName); } } } } throw new FileNotFoundException("Manifest was not found within the archive."); } } catch (CancelException ce) { throw ce; } catch (Ionic.Zip.BadPasswordException ex) { throw new Ionic.Zip.BadPasswordException(ex.Message + "\nUnable to retrieve archive manifest.\nArchive name: " + this.ToString(), ex); } catch (Exception ex) { throw new Exception(ex.Message + "\nUnable to retrieve archive manifest.\nArchive name: " + this.ToString(), ex); } }
public VerificationRun(BackupProject Project) { this.Project = Project; }
public SyncRun(BackupProject Project) { this.Project = Project; }
public Manifest(BackupProject Project) { BackupProjectName = Project.Name; SourcePath = Project.SourceFolder; }
public ExtractionRun(BackupProject Project) { this.Project = Project; }
void WorkerThread() { try { while (!Closing) { Thread.Sleep(0); lock (SearchStateLock) { BackupProject Project = CurrentProject; if (Project == null) { Thread.Sleep(100); IsArchiveNamesComplete = true; IsFolderNamesComplete = true; continue; } string[] SearchWords = CurrentSearchWords; if (SearchWords == null || SearchWords.Length == 0) { // In the case where the user has selected a project but no search details, // we want to show all available backup archives. if (!IsArchiveNamesComplete) { lock (Project.ArchiveFileList) { foreach (ArchiveFilename Backup in Project.ArchiveFileList.Archives) { if (!AllResults.Contains(Backup)) { AllResults.Add(Backup); lock (NewResults) NewResults.Add(Backup); } } } IsArchiveNamesComplete = true; } IsFolderNamesComplete = true; Thread.Sleep(100); continue; } if (!IsArchiveNamesComplete && IncludeArchiveNames) { lock (Project.ArchiveFileList) { foreach (ArchiveFilename Backup in Project.ArchiveFileList.Archives) { string BackupFile = Backup.ToString().ToLower(); bool Match = true; foreach (string Word in SearchWords) { if (!BackupFile.Contains(Word)) { Match = false; break; } } if (!Match) { continue; } if (!AllResults.Contains(Backup)) { AllResults.Add(Backup); lock (NewResults) NewResults.Add(Backup); } } } IsArchiveNamesComplete = true; continue; } if (!IsFolderNamesComplete && IncludeFolderNames) { ArchiveFilename ExamineNext = null; lock (Project.ArchiveFileList) { foreach (ArchiveFilename Backup in Project.ArchiveFileList.Archives) { bool AlreadyDone = false; foreach (ArchiveFilename PosRes in AllResults) { if (Backup == PosRes) { AlreadyDone = true; break; } } if (AlreadyDone) { continue; } foreach (ArchiveFilename NegRes in NegFolderNameResults) { if (Backup == NegRes) { AlreadyDone = true; break; } } if (AlreadyDone) { continue; } ExamineNext = Backup; break; } } if (ExamineNext == null) { IsFolderNamesComplete = true; continue; } /** Examine a single archive on this pass of the loop **/ Manifest Manifest; lock (Project.ManifestCache) { if (!Project.ManifestCache.TryGetValue(ExamineNext, out Manifest)) { try { using (NetworkConnection newconn = new NetworkConnection(Project.CompleteBackupFolder, Project.BackupCredentials)) Manifest = ExamineNext.LoadArchiveManifest(Project, false); Project.ManifestCache.Add(ExamineNext, Manifest); } catch (Ionic.Zip.BadPasswordException) { PasswordBlockedSearch = true; NegFolderNameResults.Add(ExamineNext); continue; } } } if (SearchManifestForFolderName(ExamineNext, Manifest.ArchiveRoot, SearchWords)) { if (!AllResults.Contains(ExamineNext)) { AllResults.Add(ExamineNext); lock (NewResults) NewResults.Add(ExamineNext); } } else { NegFolderNameResults.Add(ExamineNext); } continue; } // If we reach this point, the search has already completed. Idle time. Thread.Sleep(100); } } } catch (Exception ex) { lock (ExceptionLock) { WorkerException = ex; } } }