Esempio n. 1
0
        public void Refresh(bool PromptForPassword)
        {
            try
            {
                LastRefresh = DateTime.Now;

                ArchiveFilename MostRecent;
                lock (ArchiveFileList)
                {
                    using (NetworkConnection newself = new NetworkConnection(CompleteBackupFolder, BackupCredentials))
                        ArchiveFileList.LoadAll(this);

                    // Locate most recent backup...
                    MostRecent = ArchiveFileList.FindMostRecent();
                }

                if (MostRecent == ArchiveFilename.MaxValue)
                {
                    MostRecentBackup = DateTime.MinValue;
                }
                else
                {
                    try
                    {
                        Manifest Manifest;
                        using (NetworkConnection newself = new NetworkConnection(CompleteBackupFolder, BackupCredentials))
                            Manifest = MostRecent.LoadArchiveManifest(this, PromptForPassword);
                        MostRecentBackup = Manifest.BackupStartTime;
                    }
                    catch (Ionic.Zip.BadPasswordException bpe)
                    {
                        if (PromptForPassword)
                        {
                            throw bpe;
                        }
                        else
                        {
                            MostRecentBackup = MostRecent.BackupDate;
                        }
                    }
                }

                // Also check for an Backup_Status.xml file...
                // This file is created with each backup, and is particularly helpful when we have an 'empty backup'
                // where no archive need be created (because nothing has changed).  We need to display to the user that
                // the project was backed up recently, but we needn't create an archive.  The Backup_Status.xml file
                // accomplishes this.
                FileInfo[] FileList = new DirectoryInfo(CompleteBackupFolder).GetFiles("Backup_Status.xml");
                if (FileList.Length > 0)
                {
                    BackupStatus Status = null;
                    try
                    {
                        Status = BackupStatus.Load(FileList[0].FullName);
                    }
                    catch (Exception exc)
                    {
                        MessageBox.Show("Unable to load backup status file (see error details below).  This file helps ZippyBackup keep track of some things, but we can also figure it out from scratch and make a new backup status file when you perform your next backup.  Click OK and ZippyBackup will proceed without it.  Your next backup may take longer than usual.\n\nDetailed error information: " + exc.Message);
                    }
                    if (Status != null)
                    {
                        if (MostRecent != ArchiveFilename.MaxValue &&
                            Status.LastArchive == MostRecent.ToString() &&
                            Status.LastBackup.ToUniversalTime() > MostRecentBackup.ToUniversalTime())
                        {
                            MostRecentBackup = Status.LastBackup;
                        }
                        MostRecentCompleteBackup = Status.LastCompletedBackup;
                        LastScanRelativePath     = Status.LastScanRelativePath;
                        LastVerifyRelativePath   = Status.LastVerifyRelativePath;
                        MostRecentVerify         = Status.LastVerify;
                        MostRecentCompleteVerify = Status.LastCompletedVerify;
                    }
                }

                // Clear out the manifest cache...
                lock (ManifestCache)
                    ManifestCache.Clear();

                LoadIssue = false;
            }
            catch (System.Security.Authentication.InvalidCredentialException) { LoadIssue = true; }
            catch (IOException) { LoadIssue = true; }
        }
Esempio n. 2
0
 /// <summary>
 /// OnNewBackup is similar to Refresh(), but is called whenever a backup run has completed
 /// that generated a new backup archive (i.e. files had changed).  It is called immediately
 /// after the backup run is completed.
 /// </summary>
 public void OnNewBackup()
 {
     lock (ArchiveFileList)
         using (NetworkConnection newself = new NetworkConnection(CompleteBackupFolder, BackupCredentials))
             ArchiveFileList.LoadAll(this);
 }
Esempio n. 3
0
        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;
                }
            }
        }