Beispiel #1
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Determines whether the specified backup is valid.
 /// </summary>
 /// <param name="backup">The backup settings.</param>
 /// ------------------------------------------------------------------------------------
 private static bool IsBackupValid(BackupFileSettings backup)
 {
     try
     {
         backup.Validate();
         return(true);
     }
     catch             // Any errors during validate should be treated as not being valid
     {
         return(false);
     }
 }
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Perform a restore of the project specified in the settings.
        /// </summary>
        /// <param name="progressDlg">The progress dialog.</param>
        /// <exception cref="IOException">File does not exist, or some such problem</exception>
        /// <exception cref="InvalidBackupFileException">XML deserialization problem or required
        /// files not found in zip file</exception>
        /// ------------------------------------------------------------------------------------
        public void RestoreProject(IThreadedProgress progressDlg)
        {
            BackupFileSettings fileSettings = m_restoreSettings.Backup;

            fileSettings.Validate();             // Normally, this will already have been done, so this will do nothing.

            //First of all, if the project exists and we are overwriting it, then make a copy of the project.  That way
            //if the restoration fails part way through, we can put it back the way it was.
            if (Directory.Exists(m_restoreSettings.ProjectPath))
            {
                // If the project already exists using the fwdata extension, either we're not sharing,
                // or it is a project for which sharing is suppressed. In any case we don't want to
                // convert the new project.
                CreateACopyOfTheProject();
            }

            //When restoring a project, ensure all the normal folders are there even if some
            //of those folders had nothing from them in the backup.
            Directory.CreateDirectory(m_restoreSettings.ProjectPath);
            LcmCache.CreateProjectSubfolders(m_restoreSettings.ProjectPath);

            try
            {
                //Import from FW version 6.0 based on the file extension.
                var extension = Path.GetExtension(fileSettings.File).ToLowerInvariant();
                if (extension == LcmFileHelper.ksFw60BackupFileExtension || extension == ".xml")
                {
                    ImportFrom6_0Backup(fileSettings, progressDlg);
                }
                else                     //Restore from FW version 7.0 and newer backup.
                {
                    RestoreFrom7_0AndNewerBackup(fileSettings);
                }
            }
            catch (Exception error)
            {
                if (error is IOException || error is InvalidBackupFileException ||
                    error is UnauthorizedAccessException)
                {
                    CleanupAfterRestore(false);
                }
                throw;
            }

            CleanupAfterRestore(true);
        }