Example #1
0
        public void PackAndSaveSettingsFiles()
        {
            const string zipName = "1111111111_1111111111.zip";

            // Временные файлы не генерируются на лету, а копируются
            File.Copy(Path.Combine(testFileFolderPath, "indicator.xml"), Path.Combine(autosaveFolderPath, "indicator.xml"));
            File.Copy(Path.Combine(testFileFolderPath, "objects.xml"), Path.Combine(autosaveFolderPath, "objects.xml"));
            File.Copy(Path.Combine(testFileFolderPath, "settings.xml"), Path.Combine(autosaveFolderPath, "settings.xml"));


            SettingsAutosaver.PackAndSaveSettingsFiles(autosaveFolderPath, Path.Combine(autosaveFolderPath, zipName), false);

            var residualFilesXml = Directory.GetFiles(autosaveFolderPath, "*.xml");

            Assert.AreEqual(3, residualFilesXml.Length);
            var residualFilesZip = Directory.GetFiles(autosaveFolderPath, "*.zip");

            Assert.AreEqual(1, residualFilesZip.Length);

            // Удаляем временные файлы
            SettingsAutosaver.DeleteTempSettingsFileInAutosaveFolder(autosaveFolderPath);

            // после всей процедуры в папке "autosave" должен появиться на 1 архив больше и не должно остаться xml файлов
            residualFilesXml = Directory.GetFiles(autosaveFolderPath, "*.xml");
            Assert.AreEqual(0, residualFilesXml.Length);
            residualFilesZip = Directory.GetFiles(autosaveFolderPath, "*.zip");
            Assert.AreEqual(1, residualFilesZip.Length);
        }
Example #2
0
        public bool PerformAutosave(string fileName)
        {
            if (!EnsureAutosavePath(autosaveFolder))
            {
                return(false);
            }
            var targetFilePath = autosaveFolder + '\\' + fileName;

            // сохранить настройки во временную папку
            SaveCurrentSettings(autosaveFolder, true);
            // упаковать настройки в файл
            var result = SettingsAutosaver.PackAndSaveSettingsFiles(autosaveFolder, targetFilePath, false);

            // удалить временные файлы
            SettingsAutosaver.DeleteTempSettingsFileInAutosaveFolder(autosaveFolder);
            return(result);
        }