Exemplo n.º 1
0
        private void UncompressLinkedFiles(Dictionary <String, DateTime> fileList, String destinationLinkedFilesPath,
                                           String linkedFilesPathPersisted)
        {
            using (var zipIn = OpenFWBackupZipfile())
            {
                ZipEntry entry;

                while ((entry = zipIn.GetNextEntry()) != null)
                {
                    //Code to use for restoring files with new file structure.
                    if (!fileList.ContainsKey(entry.Name))
                    {
                        continue;
                    }
                    var fileName = Path.GetFileName(entry.Name);
                    Debug.Assert(!String.IsNullOrEmpty(fileName));

                    //Contruct the path where the file will be unzipped too.
                    var    zipFileLinkFilesPath   = FdoFileHelper.GetZipfileFormattedPath(linkedFilesPathPersisted);
                    var    filenameWithSubFolders = entry.Name.Substring(zipFileLinkFilesPath.Length);
                    String pathForFileSubFolders  = "";
                    if (!fileName.Equals(filenameWithSubFolders))                     //if they are equal the file is in the root of LinkedFiles
                    {
                        pathForFileSubFolders = GetPathForSubFolders(filenameWithSubFolders, fileName.Length);
                    }
                    var destFolderZipFileFormat = FdoFileHelper.GetZipfileFormattedPath(destinationLinkedFilesPath);
                    var pathRoot = Path.GetPathRoot(destinationLinkedFilesPath);
                    Debug.Assert(!String.IsNullOrEmpty(pathRoot));
                    var pathforfileunzip = Path.Combine(pathRoot, destFolderZipFileFormat, pathForFileSubFolders);
                    UnzipFileToRestoreFolder(zipIn, fileName, entry.Size, pathforfileunzip, entry.DateTime);
                }
            }
        }
Exemplo n.º 2
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Verifies the file exists in the zip file.
        /// </summary>
        /// <param name="zip">The zip file.</param>
        /// <param name="fileNameAndPath">The file name (with path) to look for.</param>
        /// ------------------------------------------------------------------------------------
        private static void VerifyFileExistsInZipFile(ZipFile zip, String fileNameAndPath)
        {
            string str = FdoFileHelper.GetZipfileFormattedPath(fileNameAndPath);
            //ensure the entry is the correct one.
            ZipEntry entry = zip.GetEntry(str);

            Assert.True(entry.Name.Equals(str), String.Format("File {0} should exist in zipFile", str));
        }
Exemplo n.º 3
0
        private void RestoreFrom7_0AndNewerBackup(BackupFileSettings fileSettings)
        {
            // Get rid of any saved settings, since they may not be consistent with something about the data
            // or settings we are restoring. (This extension is also known to RecordView.GetClerkPersistPathname()).
            var tempDirectory = Path.Combine(m_restoreSettings.ProjectPath, FdoFileHelper.ksSortSequenceTempDir);

            if (Directory.Exists(tempDirectory))
            {
                foreach (var sortSeqFile in Directory.GetFiles(tempDirectory, "*.fwss"))
                {
                    File.Delete(sortSeqFile);
                }
            }

            UncompressDataFiles();

            // We can't use Path.Combine here, because the zip files stores all file paths with '/'s
            UncompressFilesMatchingPath(FdoFileHelper.ksWritingSystemsDir + "/", m_restoreSettings.WritingSystemStorePath);

            if (m_restoreSettings.IncludeSupportingFiles)
            {
                Debug.Assert(fileSettings.IncludeSupportingFiles,
                             "The option to include supporting files should not be allowed if they aren't available in the backup settings");
                var zipEntryStartsWith = FdoFileHelper.ksSupportingFilesDir;
                UncompressFilesContainedInFolderandSubFolders(FdoFileHelper.GetZipfileFormattedPath(zipEntryStartsWith),
                                                              m_restoreSettings.ProjectSupportingFilesPath);
            }

            if (m_restoreSettings.IncludeConfigurationSettings)
            {
                UncompressFilesMatchingPath(FdoFileHelper.ksConfigurationSettingsDir + "/", m_restoreSettings.FlexConfigurationSettingsPath);
            }

            if (m_restoreSettings.IncludeLinkedFiles)
            {
                RestoreLinkedFiles(fileSettings);
            }

            if (m_restoreSettings.IncludeSpellCheckAdditions)
            {
                UncompressFilesMatchingPath(BackupSettings.ksSpellingDictionariesDir + "/", m_restoreSettings.SpellingDictionariesPath);

                CopySpellingOverrideFilesFromBackupToLocal();
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// patthernToMatch is used to distinguish files bases on the folder they are from in the zipFile.
        /// For example some files from the ...ProjectName/WritingSystemStore/ folder.
        /// Other files come from the ProjectName/ConfigurationsSettings/ folder.
        /// </summary>
        /// <param name="patternToMatch">The pattern to match.</param>
        /// <param name="destinationDirectory">The destination directory.</param>
        private void UncompressFilesMatchingPath(String patternToMatch, String destinationDirectory)
        {
            using (var zipIn = OpenFWBackupZipfile())
            {
                ZipEntry entry;

                RemoveAllFilesFromFolder(destinationDirectory);                  //Do we want some files to remain if they were not part of the backup project
                //This could be dangerous.
                Directory.CreateDirectory(destinationDirectory);
                while ((entry = zipIn.GetNextEntry()) != null)
                {
                    var fileName = Path.GetFileName(entry.Name);

                    //Code to use for restoring files with new file structure.
                    if (!String.IsNullOrEmpty(fileName) && !entry.Name.EndsWith("/") && entry.Name.Contains(patternToMatch))
                    {
                        //first make sure the new file created has the new project name in it if the restored project is being
                        //renamed.
                        var strbldr = new StringBuilder(fileName);
                        if (m_restoreSettings.CreateNewProject)
                        {
                            strbldr.Replace(m_restoreSettings.Backup.ProjectName, m_restoreSettings.ProjectName);
                        }

                        //Contruct the path where the file will be unzipped too.
                        var    zipFileLinkFilesPath   = FdoFileHelper.GetZipfileFormattedPath(patternToMatch.Replace("/", ""));
                        var    filenameWithSubFolders = entry.Name.Substring(zipFileLinkFilesPath.Length);
                        String pathForFileSubFolders  = "";
                        if (!fileName.Equals(filenameWithSubFolders))                         //if they are equal the file is in the root of LinkedFiles
                        {
                            pathForFileSubFolders = GetPathForSubFolders(filenameWithSubFolders, fileName.Length);
                        }
                        var destFolderZipFilePath = FdoFileHelper.GetZipfileFormattedPath(destinationDirectory);
                        var pathRoot         = Path.GetPathRoot(destinationDirectory);
                        var pathforfileunzip = Path.Combine(pathRoot, destFolderZipFilePath, pathForFileSubFolders);

                        //then restore the file to the temp directory and copy it to the final location
                        UnzipFileToRestoreFolder(zipIn, strbldr.ToString(), entry.Size, pathforfileunzip, entry.DateTime);
                    }
                }
            }
        }
Exemplo n.º 5
0
        private Dictionary <String, DateTime> GetAllFilesUnderFolderInZipFileAndDateTimes(string dir)
        {
            var filesAndDateTime = new Dictionary <String, DateTime>();
            var dirZipFileFormat = FdoFileHelper.GetZipfileFormattedPath(dir);

            using (var zipIn = OpenFWBackupZipfile())
            {
                ZipEntry entry;

                while ((entry = zipIn.GetNextEntry()) != null)
                {
                    var fileName = Path.GetFileName(entry.Name);

                    //Code to use for restoring files with new file structure.
                    if (!String.IsNullOrEmpty(fileName) && !entry.Name.EndsWith("/") && entry.Name.StartsWith(dirZipFileFormat))
                    {
                        filesAndDateTime.Add(entry.Name, entry.DateTime);
                    }
                }
                return(filesAndDateTime);
            }
        }