/// ------------------------------------------------------------------------------------ /// <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); }
/// <summary> /// Import from a 6.0 XML file. /// </summary> public bool ImportFrom6_0Xml(string pathname, string folderName, string projectFile) { bool retval = true; bool fCreateFolder = !Directory.Exists(folderName); string replacedProj = null; if (fCreateFolder) { Directory.CreateDirectory(folderName); } else if (File.Exists(projectFile)) { replacedProj = projectFile + "-replaced"; if (File.Exists(replacedProj)) { File.Delete(replacedProj); } File.Move(projectFile, replacedProj); } using (var process = CreateAndInitProcess(m_converterConsolePath, '"' + pathname + "\" \"" + projectFile + '"')) { m_progressDlg.IsIndeterminate = true; // Can't get actual progress from external program m_progressDlg.Title = Strings.ksConverting; string message = String.Format(Strings.ksConvertingFile, Path.GetFileNameWithoutExtension(projectFile)); if (!(bool)m_progressDlg.RunTask(true, ProcessFile, process, message)) { // user canceled retval = false; } else if (process.ExitCode != 0 || !String.IsNullOrEmpty(m_errorMessages)) { message = String.Format(Strings.ksConversionProcessFailed, process.ExitCode, m_errorMessages); BackOutCleanUp(projectFile, fCreateFolder, folderName, replacedProj); throw new CannotConvertException(message); } if (retval == false) { BackOutCleanUp(projectFile, fCreateFolder, folderName, replacedProj); } else { try { string srcDir = Path.GetDirectoryName(pathname); string destDir = Path.GetDirectoryName(projectFile); if (srcDir == destDir) { File.Delete(pathname); string logfile = pathname.Replace(".xml", "-Export.log"); File.Delete(logfile); } LcmCache.CreateProjectSubfolders(folderName); } catch (Exception) { // ignore any exceptions thrown when trying to create the subdirectories. } } return(retval); } }