예제 #1
0
 private void CouldNotRestoreLinkedFilesToOriginalLocation(string linkedFilesPathPersisted, Dictionary <string, DateTime> filesContainedInLinkdFilesFolder)
 {
     using (var dlgCantWriteFiles = new CantRestoreLinkedFilesToOriginalLocation(m_helpTopicProvider))
     {
         if (dlgCantWriteFiles.ShowDialog() == DialogResult.OK)
         {
             if (dlgCantWriteFiles.fRestoreLinkedFilesToProjectFolder)
             {
                 m_sLinkDirChangedTo = DirectoryFinder.GetDefaultLinkedFilesDir(m_restoreSettings.ProjectPath);
                 //Restore the files to the project folder.
                 UncompressLinkedFiles(filesContainedInLinkdFilesFolder, m_sLinkDirChangedTo,
                                       linkedFilesPathPersisted);
             }
             if (dlgCantWriteFiles.fDoNotRestoreLinkedFiles)
             {
                 //Do nothing. Do not restore any LinkedFiles.
             }
         }
     }
 }
예제 #2
0
        private void RestoreLinkedFiles(BackupFileSettings fileSettings)
        {
            Debug.Assert(fileSettings.LinkedFilesAvailable,
                         "The option to include linked files should not be allowed if they aren't available in the backup settings");

            var proposedDestinationLinkedFilesPath =
                DirectoryFinderRelativePaths.GetLinkedFilesFullPathFromRelativePath(fileSettings.LinkedFilesPathRelativePersisted,
                                                                                    m_restoreSettings.ProjectPath);

            var linkedFilesPathInZip = fileSettings.LinkedFilesPathActualPersisted;

            if (fileSettings.LinkedFilesPathRelativePersisted.StartsWith(DirectoryFinderRelativePaths.ksProjectRelPath))
            {
                // We store any files inside the project folder as a relative path from the project's directory.
                // Make sure we don't attempt to search for the whole directory structure in the zip file. (FWR-2909)
                linkedFilesPathInZip = fileSettings.LinkedFilesPathRelativePersisted.Substring(
                    DirectoryFinderRelativePaths.ksProjectRelPath.Length + 1);
            }
            var filesContainedInLinkdFilesFolder = GetAllFilesUnderFolderInZipFileAndDateTimes(linkedFilesPathInZip);


            //If the proposed location is not in the default location under the project, then ask the user if they want
            //to restore the files to the default location instead. Otherwise just go ahead and restore the files.
            var defaultLinkedFilesPath = DirectoryFinder.GetDefaultLinkedFilesDir(m_restoreSettings.ProjectPath);

            if (proposedDestinationLinkedFilesPath.Equals(defaultLinkedFilesPath))
            {
                if (!Directory.Exists(defaultLinkedFilesPath))
                {
                    Directory.CreateDirectory(proposedDestinationLinkedFilesPath);
                }
                ExternalLinksDirectoryExits(linkedFilesPathInZip, proposedDestinationLinkedFilesPath, filesContainedInLinkdFilesFolder);
            }
            else
            {
                //LinkedFiles folder does not exist which means it was not in the default location when the backup was made.
                //Therefore, ask the user if we can restore these files to the default location in the project's folder.
                using (var dlg = new RestoreLinkedFilesToProjectsFolder(m_helpTopicProvider))
                {
                    if (dlg.ShowDialog() == DialogResult.OK)
                    {
                        if (dlg.fRestoreLinkedFilesToProjectFolder)
                        {
                            m_sLinkDirChangedTo = DirectoryFinder.GetDefaultLinkedFilesDir(m_restoreSettings.ProjectPath);
                            //Restore the files to the project folder.
                            UncompressLinkedFiles(filesContainedInLinkdFilesFolder, m_sLinkDirChangedTo,
                                                  linkedFilesPathInZip);
                        }
                        else
                        {
                            if (!Directory.Exists(proposedDestinationLinkedFilesPath))
                            {
                                try
                                {
                                    Directory.CreateDirectory(proposedDestinationLinkedFilesPath);
                                }
                                catch (Exception error)
                                {
                                    CouldNotRestoreLinkedFilesToOriginalLocation(linkedFilesPathInZip, filesContainedInLinkdFilesFolder);
                                    return;
                                }
                            }
                            UncompressLinkedFiles(filesContainedInLinkdFilesFolder, proposedDestinationLinkedFilesPath,
                                                  linkedFilesPathInZip);
                        }
                    }
                }
            }
        }