/// <summary> /// Restore LinkedFiles to the project or a non-standard location depending on the /// fPutFilesInProject parameter. /// </summary> /// <param name="fPutFilesInProject"></param> /// <param name="filesContainedInLinkdFilesFolder"></param> /// <param name="linkedFilesPathInZip"></param> /// <param name="proposedDestinationLinkedFilesPath"></param> protected void RestoreLinkedFiles(bool fPutFilesInProject, Dictionary <string, DateTime> filesContainedInLinkdFilesFolder, string linkedFilesPathInZip, string proposedDestinationLinkedFilesPath) { if (fPutFilesInProject) { m_sLinkDirChangedTo = FdoFileHelper.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); } }
public void GatherBuiltInAndUserConfigurations_ProjectOverrideReplacesShipped() { var configObjectName = "Dictionary"; var projectDictionaryConfigs = Path.Combine(FdoFileHelper.GetConfigSettingsDir(Cache.ProjectId.ProjectFolder), "Dictionary"); Directory.CreateDirectory(projectDictionaryConfigs); using (var tempConfigFile = TempFile.WithFilename(Path.Combine(projectDictionaryConfigs, "Override" + DictionaryConfigurationModel.FileExtension))) { string firstShippedConfigName; var shippedFileList = Directory.EnumerateFiles(Path.Combine(FwDirectoryFinder.DefaultConfigurations, "Dictionary"), "*" + DictionaryConfigurationModel.FileExtension); var fileList = shippedFileList.ToArray(); using (var stream = new FileStream(fileList.First(), FileMode.Open)) { var doc = new XmlDocument(); doc.Load(stream); var node = doc.SelectSingleNode("DictionaryConfiguration"); firstShippedConfigName = node.Attributes["name"].Value; } File.WriteAllText(tempConfigFile.Path, "<?xml version='1.0' encoding='utf-8'?><DictionaryConfiguration name='" + firstShippedConfigName + "'/>"); // SUT var fileListFromResults = DictionaryConfigurationUtils.GatherBuiltInAndUserConfigurations(Cache, configObjectName).Values; CollectionAssert.Contains(fileListFromResults, tempConfigFile.Path); Assert.AreEqual(fileListFromResults.Count, fileList.Count(), "Override was added instead of replacing a shipped config."); } }
public void MigrateIfNeeded(SimpleLogger logger, Mediator mediator, string appVersion) { m_logger = logger; Cache = (FdoCache)mediator.PropertyTable.GetValue("cache"); var foundOne = string.Format("{0}: Configuration was found in need of migration. - {1}", appVersion, DateTime.Now.ToString("yyyy MMM d h:mm:ss")); var configSettingsDir = FdoFileHelper.GetConfigSettingsDir(Cache.ProjectId.ProjectFolder); var dictionaryConfigLoc = Path.Combine(configSettingsDir, DictionaryConfigurationListener.DictionaryConfigurationDirectoryName); var stemPath = Path.Combine(dictionaryConfigLoc, "Stem" + DictionaryConfigurationModel.FileExtension); var lexemePath = Path.Combine(dictionaryConfigLoc, "Lexeme" + DictionaryConfigurationModel.FileExtension); if (File.Exists(stemPath) && !File.Exists(lexemePath)) { File.Move(stemPath, lexemePath); } foreach (var config in DCM.GetConfigsNeedingMigration(Cache, DCM.VersionCurrent)) { m_logger.WriteLine(foundOne); if (config.Label.StartsWith("Stem-")) { config.Label = config.Label.Replace("Stem-", "Lexeme-"); } m_logger.WriteLine(string.Format("Migrating {0} configuration '{1}' from version {2} to {3}.", config.Type, config.Label, config.Version, DCM.VersionCurrent)); m_logger.IncreaseIndent(); MigrateFrom83Alpha(logger, config, LoadBetaDefaultForAlphaConfig(config)); config.Save(); m_logger.DecreaseIndent(); } }
private string CreateNewSoundFilename(out string path) { var obj = m_innerView.Cache.ServiceLocator.GetObject(m_innerView.HvoObj); var mediaDir = FdoFileHelper.GetMediaDir(m_innerView.Cache.LangProject.LinkedFilesRootDir); Directory.CreateDirectory(mediaDir); // Palaso media library does not cope if it does not exist. // Make up a unique file name for the new recording. It starts with the shortname of the object // so as to somewhat link them together, then adds a unique timestamp, then if by any chance // that exists it keeps trying. var baseNameForFile = obj.ShortName; // LT-12926: Path.ChangeExtension checks for invalid filename chars, // so we need to fix the filename before calling it. foreach (var c in Path.GetInvalidFileNameChars()) { baseNameForFile = baseNameForFile.Replace(c, '_'); } // WeSay and most other programs use NFC for file names, so we'll standardize on this. baseNameForFile = baseNameForFile.Normalize(NormalizationForm.FormC); string filename; do { filename = baseNameForFile; filename = Path.ChangeExtension(DateTime.UtcNow.Ticks + filename, "wav"); path = Path.Combine(mediaDir, filename); } while (File.Exists(path)); return(filename); }
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); } } }
public void MigrateOldConfigurationsIfNeeded_MatchesLabelsWhenUIIsLocalized() { // Localize a Part's label to German (sufficient to cause a mismatched nodes crash if one config's labels are localized) var localizedPartLabels = new Dictionary <string, string>(); localizedPartLabels["Main Entry"] = "Haupteintrag"; var pathsToL10nStrings = (Dictionary <string, Dictionary <string, string> >)ReflectionHelper.GetField(m_mediator.StringTbl, "m_pathsToStrings"); pathsToL10nStrings["group[@id = 'LocalizedAttributes']/"] = localizedPartLabels; var configSettingsDir = FdoFileHelper.GetConfigSettingsDir(Path.GetDirectoryName(Cache.ProjectId.Path)); var newConfigFilePath = Path.Combine(configSettingsDir, DictionaryConfigurationListener.DictionaryConfigurationDirectoryName, "Lexeme" + DictionaryConfigurationModel.FileExtension); Assert.False(File.Exists(newConfigFilePath), "should not yet be migrated"); Directory.CreateDirectory(configSettingsDir); File.WriteAllLines(Path.Combine(configSettingsDir, "Test.fwlayout"), new[] { @"<layoutType label='Lexeme-based (complex forms as main entries)' layout='publishStem'><configure class='LexEntry' label='Main Entry' layout='publishStemEntry' />", @"<configure class='LexEntry' label='Minor Entry' layout='publishStemMinorEntry' hideConfig='true' /></layoutType>'" }); var migrator = new DictionaryConfigurationMigrator(m_mediator); Assert.DoesNotThrow(() => migrator.MigrateOldConfigurationsIfNeeded(), "ArgumentException indicates localized labels."); // SUT var updatedConfigModel = new DictionaryConfigurationModel(newConfigFilePath, Cache); Assert.AreEqual(2, updatedConfigModel.Parts.Count, "Should have 2 top-level nodes"); Assert.AreEqual("Main Entry", updatedConfigModel.Parts[0].Label); DirectoryUtilities.DeleteDirectoryRobust(configSettingsDir); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Uncompress the FieldWorks project data file and the Questions files. /// </summary> /// ------------------------------------------------------------------------------------ private void UncompressDataFiles() { using (var zipIn = OpenFWBackupZipfile()) { ZipEntry entry; while ((entry = zipIn.GetNextEntry()) != null) { var fileName = Path.GetFileName(entry.Name); if (fileName == FdoFileHelper.GetXmlDataFileName(m_restoreSettings.Backup.ProjectName)) { UnzipFileToRestoreFolder(zipIn, m_restoreSettings.DbFilename, entry.Size, m_restoreSettings.ProjectPath, entry.DateTime); } if (fileName == m_restoreSettings.QuestionNotesFilename) { UnzipFileToRestoreFolder(zipIn, m_restoreSettings.QuestionNotesFilename, entry.Size, m_restoreSettings.ProjectPath, entry.DateTime); } } string bakFile = Path.Combine(m_restoreSettings.ProjectPath, m_restoreSettings.ProjectName) + FdoFileHelper.ksFwDataFallbackFileExtension; if (FileUtils.TrySimilarFileExists(bakFile, out bakFile)) { FileUtils.Delete(bakFile); // TODO: do something about the .Lock file....... } } }
private void SetupSoundControls() { if (m_innerView.WritingSystemsToDisplay == null) { return; // should get called again when it is set up. } if (m_innerView.RootBox == null) { return; // called again in MakeRoot, when information more complete. } int index = -1; foreach (var ws in m_innerView.WritingSystemsToDisplay) { index++; var pws = ws as WritingSystemDefinition; if (pws == null || !pws.IsVoice || MultiStringSelectionUtils.GetSelAtStartOfWs(m_innerView.RootBox, m_innerView.Flid, index, ws) == null) { continue; } var soundFieldControl = new ShortSoundFieldControl(); m_soundControls.Add(soundFieldControl); // todo: one for each audio one soundFieldControl.Visible = true; soundFieldControl.PlayOnly = false; var filename = m_innerView.Cache.DomainDataByFlid.get_MultiStringAlt(m_innerView.HvoObj, m_innerView.Flid, ws.Handle).Text ?? ""; string path; if (String.IsNullOrEmpty(filename)) { // Provide a filename for copying an existing file to. CreateNewSoundFilename(out path); } else { var mediaDir = FdoFileHelper.GetMediaDir(m_innerView.Cache.LangProject.LinkedFilesRootDir); Directory.CreateDirectory(mediaDir); // Palaso media library does not cope if it does not exist. path = Path.Combine(mediaDir, filename.Normalize(NormalizationForm.FormC)); // Windows in total defiance of the Unicode standard does not consider alternate normalizations // of file names equal. The name in our string will always be NFD. From 7.2.2 we are saving files // in NFC, but files from older versions could be NFD, so we need to check both. This is not // foolproof...don't know any way to look for all files that might exist with supposedly equivalent // names not normalized at all. if (!File.Exists(path)) { var tryPath = path.Normalize(NormalizationForm.FormD); if (File.Exists(tryPath)) { path = tryPath; } } } soundFieldControl.Path = path; soundFieldControl.BeforeStartingToRecord += soundFieldControl_BeforeStartingToRecord; soundFieldControl.SoundRecorded += soundFieldControl_SoundRecorded; soundFieldControl.SoundDeleted += soundFieldControl_SoundDeleted; Controls.Add(soundFieldControl); } }
/// ------------------------------------------------------------------------------------ /// <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)); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Constructor /// </summary> /// <param name="backupProjectView">The backup project dialog box.</param> /// <param name="appAbbrev">The command-line abbreviation for the application displaying /// this backup dialog box.</param> /// <param name="cache">The cache.</param> /// ------------------------------------------------------------------------------------ internal BackupProjectPresenter(IBackupProjectView backupProjectView, string appAbbrev, FdoCache cache) { m_cache = cache; m_appAbbrev = appAbbrev; m_backupProjectView = backupProjectView; //Older projects might not have this folder so when launching the backup dialog we want to create it. Directory.CreateDirectory(FdoFileHelper.GetSupportingFilesDir(m_cache.ProjectId.ProjectFolder)); }
public void AssertValid_Valid() { string projFile = GetXmlProjectFilename("monkey"); m_mockFileOs.AddExistingFile(projFile); var proj = new ProjectId(FdoFileHelper.GetXmlDataFileName("monkey"), null); proj.AssertValid(); // no exception should be thrown here for a valid project. }
public void IsValid_XML_True() { const string sProjectName = "monkey"; string sFile = FdoFileHelper.GetXmlDataFileName(sProjectName); m_mockFileOs.AddExistingFile(GetXmlProjectFilename(sProjectName)); ProjectId proj = new ProjectId("xml", sFile, null); Assert.IsTrue(proj.IsValid); }
public void IsValid_NullType() { const string sProjectName = "monkey"; string sFile = FdoFileHelper.GetXmlDataFileName(sProjectName); m_mockFileOs.AddExistingFile(GetXmlProjectFilename(sProjectName)); ProjectId proj = new ProjectId(null, sFile, null); Assert.AreEqual(FDOBackendProviderType.kXML, proj.Type); Assert.IsTrue(proj.IsValid); }
internal static List <DictionaryConfigurationModel> GetConfigsNeedingMigration(FdoCache cache, int targetVersion) { var configSettingsDir = FdoFileHelper.GetConfigSettingsDir(Path.GetDirectoryName(cache.ProjectId.Path)); var dictionaryConfigLoc = Path.Combine(configSettingsDir, DictionaryConfigurationListener.DictionaryConfigurationDirectoryName); var reversalIndexConfigLoc = Path.Combine(configSettingsDir, DictionaryConfigurationListener.ReversalIndexConfigurationDirectoryName); var projectConfigPaths = new List <string>(ConfigFilesInDir(dictionaryConfigLoc)); projectConfigPaths.AddRange(ConfigFilesInDir(reversalIndexConfigLoc)); return(projectConfigPaths.Select(path => new DictionaryConfigurationModel(path, null)) .Where(model => model.Version < targetVersion).ToList()); }
public void CleanUpNameForType_XML_FullPath() { string expectedPath = Path.Combine(FwDirectoryFinder.ProjectsDirectory, FdoFileHelper.GetXmlDataFileName("monkey")); m_mockFileOs.AddExistingFile(expectedPath); var proj = new ProjectId(expectedPath, null); Assert.AreEqual(expectedPath, proj.Path); Assert.AreEqual(FDOBackendProviderType.kXML, proj.Type); Assert.IsTrue(proj.IsValid); }
public void CleanUpNameForType_XML_onlyNameWithExtension() { string expectedPath = GetXmlProjectFilename("monkey"); m_mockFileOs.AddExistingFile(expectedPath); var proj = new ProjectId(FdoFileHelper.GetXmlDataFileName("monkey"), null); Assert.AreEqual(expectedPath, proj.Path); Assert.AreEqual(FDOBackendProviderType.kXML, proj.Type); Assert.IsTrue(proj.IsValid); }
public void NameAndPath() { string myProjectFolder = Path.Combine(FwDirectoryFinder.ProjectsDirectory, "My.Project"); ProjectId projId = new ProjectId(FDOBackendProviderType.kXML, "My.Project", null); Assert.AreEqual(Path.Combine(myProjectFolder, FdoFileHelper.GetXmlDataFileName("My.Project")), projId.Path); Assert.AreEqual("My.Project", projId.Name); projId = new ProjectId(FDOBackendProviderType.kDb4oClientServer, "My.Project", null); Assert.AreEqual(Path.Combine(myProjectFolder, FdoFileHelper.GetDb4oDataFileName("My.Project")), projId.Path); Assert.AreEqual("My.Project", projId.Name); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Create a db4o database file of given name. /// </summary> /// <param name="projectName">the desired name.</param> /// ------------------------------------------------------------------------------------ public void CreateServerFile(string projectName) { string projectDir = Path.Combine(RemotingServer.Directories.ProjectsDirectory, projectName); string newFilename = Path.Combine(projectDir, FdoFileHelper.GetDb4oDataFileName(projectName)); // Ensure directory exists. Directory.CreateDirectory(projectDir); using (FileStream stream = File.Create(newFilename)) stream.Close(); PopulateServerList(); }
public void AssertValid_InvalidProjectType() { var proj = new ProjectId(FDOBackendProviderType.kInvalid, FdoFileHelper.GetXmlDataFileName("invalid"), null); try { proj.AssertValid(); Assert.Fail("FwStartupException expected"); } catch (StartupException exception) { Assert.IsTrue(exception.ReportToUser); } }
public void CleanUpNameForType_XML_NameWithPeriod_FilesWithAndWithoutExtensionExist() { string myMonkeyProjectFolder = Path.Combine(FwDirectoryFinder.ProjectsDirectory, "my.monkey"); string expectedPath = Path.Combine(myMonkeyProjectFolder, FdoFileHelper.GetXmlDataFileName("my.monkey")); m_mockFileOs.AddExistingFile(expectedPath); m_mockFileOs.AddExistingFile(Path.Combine(myMonkeyProjectFolder, "my.monkey")); var proj = new ProjectId("my.monkey", null); Assert.AreEqual(expectedPath, proj.Path); Assert.AreEqual(FDOBackendProviderType.kXML, proj.Type); Assert.IsTrue(proj.IsValid); }
public void AssertValid_Invalid_FileNotFound() { var proj = new ProjectId(FdoFileHelper.GetXmlDataFileName("notfound"), null); try { proj.AssertValid(); Assert.Fail("FwStartupException expected"); } catch (StartupException exception) { Assert.IsTrue(exception.ReportToUser); } }
public void GetValidConfigurationForPublication_PublicationThatMatchesNoConfigReturnsNull() { using (var helper = new UndoableUnitOfWorkHelper(Cache.ActionHandlerAccessor, "doit", "undoit")) { var testPubItem = Cache.ServiceLocator.GetInstance <ICmPossibilityFactory>().Create(); int enId = Cache.WritingSystemFactory.GetWsFromStr("en"); var testPubName = Cache.TsStrFactory.MakeString("NotTheTestPub", enId); Cache.LangProject.LexDbOA.PublicationTypesOA.PossibilitiesOS.Add(testPubItem); testPubItem.Name.set_String(enId, testPubName); var configSansTestPub = ConfigurationTemplate.Replace("</Publications>", "<Publication>NotTheTestPub</Publication></Publications>"); var overrideFiles = new List <TempFile>(); using (var docView = new TestXhtmlDocView()) { docView.SetConfigObjectName("Dictionary"); docView.SetMediator(m_mediator); var projConfigs = Path.Combine(FdoFileHelper.GetConfigSettingsDir(Cache.ProjectId.ProjectFolder), "Dictionary"); Directory.CreateDirectory(projConfigs); // override every shipped config with a config that does not have the TestPub publication var shippedFileList = Directory.EnumerateFiles(Path.Combine(FwDirectoryFinder.DefaultConfigurations, "Dictionary"), "*" + DictionaryConfigurationModel.FileExtension); var overrideCount = 0; foreach (var shippedFile in shippedFileList) { ++overrideCount; var tempFileName = Path.Combine(projConfigs, overrideCount + DictionaryConfigurationModel.FileExtension); var tempConfigFile = TempFile.WithFilename(tempFileName); overrideFiles.Add(tempConfigFile); using (var stream = new FileStream(shippedFile, FileMode.Open)) { var doc = new XmlDocument(); doc.Load(stream); var node = doc.SelectSingleNode("DictionaryConfiguration"); var shippedName = node.Attributes["name"].Value; File.WriteAllText(tempConfigFile.Path, configSansTestPub.Replace("name='AConfigPubtest'", "name='" + shippedName + "'")); } } // SUT var result = docView.GetValidConfigurationForPublication("TestPub"); // Delete all our temp files before asserting so they are sure to go away foreach (var tempFile in overrideFiles) { tempFile.Dispose(); } Assert.IsNull(result, "When no configurations have the publication null should be returned."); } } }
public void AssertValid_Invalid_SharedFolderNotFound() { var proj = new ProjectId(FdoFileHelper.GetDb4oDataFileName("monkey"), FwLinkArgs.kLocalHost); try { proj.AssertValid(); Assert.Fail("FwStartupException expected"); } catch (StartupException exception) { Assert.IsTrue(exception.ReportToUser); } }
internal static void RemoveAnyFilesAndFoldersCreatedByTests(RestoreProjectSettings settings) { RemoveAllFilesFromFolderAndSubfolders(FdoFileHelper.GetBackupSettingsDir(settings.ProjectPath)); RemoveAllFilesFromFolderAndSubfolders(settings.ProjectSupportingFilesPath); RemoveAllFilesFromFolderAndSubfolders(settings.FlexConfigurationSettingsPath); RemoveAllFilesFromFolderAndSubfolders(settings.PicturesPath); RemoveAllFilesFromFolderAndSubfolders(settings.MediaPath); RemoveAllFilesFromFolderAndSubfolders(settings.OtherExternalFilesPath); RemoveAllFilesFromFolderAndSubfolders(settings.LinkedFilesPath); RemoveAllFilesFromFolderAndSubfolders(settings.WritingSystemStorePath); RemoveAllFilesFromFolderAndSubfolders(Path.Combine(settings.ProjectPath, FdoFileHelper.ksSortSequenceTempDir)); //Remove this one last of all because the other folders need to be removed first. RemoveAllFilesFromFolderAndSubfolders(settings.ProjectPath); }
public void CleanUpNameForType_Default_onlyName() { m_defaultBepType = FDOBackendProviderType.kDb4oClientServer; string expectedPath = Path.Combine(Path.Combine(FwDirectoryFinder.ProjectsDirectory, "ape"), FdoFileHelper.GetDb4oDataFileName("ape")); m_localCsSvcs.Stub(cs => cs.IdForLocalProject("ape")).Return(expectedPath); m_mockFileOs.AddExistingFile(expectedPath); ProjectId proj = new ProjectId("ape", null); Assert.AreEqual(expectedPath, proj.Path); Assert.AreEqual(FDOBackendProviderType.kDb4oClientServer, proj.Type); Assert.IsTrue(proj.IsValid); }
/// <summary> /// Displays a dialog that asks the user how to handle a situation where non-standard location linked files /// cannot be restored to their previous position. /// </summary> /// <param name="linkedFilesPathPersisted"></param> /// <param name="filesContainedInLinkdFilesFolder"></param> protected virtual void CouldNotRestoreLinkedFilesToOriginalLocation(string linkedFilesPathPersisted, Dictionary <string, DateTime> filesContainedInLinkdFilesFolder) { YesNoCancel userSelection = m_ui.CannotRestoreLinkedFilesToOriginalLocation(); if (userSelection == YesNoCancel.OkYes) { m_sLinkDirChangedTo = FdoFileHelper.GetDefaultLinkedFilesDir(m_restoreSettings.ProjectPath); //Restore the files to the project folder. UncompressLinkedFiles(filesContainedInLinkdFilesFolder, m_sLinkDirChangedTo, linkedFilesPathPersisted); } else if (userSelection == YesNoCancel.OkNo) { //Do nothing. Do not restore any LinkedFiles. } }
public void CreateNewLangProject() { const string dbName = "Maileingwij2025"; string storePath = FdoFileHelper.GetWritingSystemDir(Path.Combine(FwDirectoryFinder.ProjectsDirectory, dbName)); string sharedStorePath = DirectoryFinder.GlobalWritingSystemStoreDirectory; using (var dlg = new DummyFwNewLangProject()) { FdoCache cache = null; if (DbExists(dbName)) { DestroyDb(dbName, true); } dlg.setProjectName(dbName); try { dlg.CreateNewLangProj(); Assert.IsTrue(DbExists(dbName)); // despite of the name is DummyProgressDlg no real dialog (doesn't derive from Control), so // we don't need a 'using' cache = FdoCache.CreateCacheFromExistingData( new TestProjectId(FDOBackendProviderType.kXML, DbFilename(dbName)), "en", new DummyFdoUI(), FwDirectoryFinder.FdoDirectories, new FdoSettings(), new DummyProgressDlg()); CheckInitialSetOfPartsOfSpeech(cache); Assert.AreEqual(1, cache.ServiceLocator.WritingSystems.AnalysisWritingSystems.Count); Assert.AreEqual("English", cache.ServiceLocator.WritingSystems.AnalysisWritingSystems.First().LanguageName); Assert.AreEqual(1, cache.ServiceLocator.WritingSystems.CurrentAnalysisWritingSystems.Count); Assert.AreEqual("English", cache.ServiceLocator.WritingSystems.DefaultAnalysisWritingSystem.LanguageName); Assert.AreEqual(1, cache.ServiceLocator.WritingSystems.VernacularWritingSystems.Count); Assert.AreEqual("French", cache.ServiceLocator.WritingSystems.VernacularWritingSystems.First().LanguageName); Assert.AreEqual(1, cache.ServiceLocator.WritingSystems.CurrentVernacularWritingSystems.Count); Assert.AreEqual("French", cache.ServiceLocator.WritingSystems.DefaultVernacularWritingSystem.LanguageName); } finally { // Blow away the database to clean things up if (cache != null) { cache.Dispose(); } DestroyDb(dbName, false); } } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Initializes a new instance of the <see cref="BackupFileSettings"/> class from an /// existing BackupProjectSettings object /// </summary> /// <param name="settings">The BackupProjectSettings.</param> /// ------------------------------------------------------------------------------------ private BackupFileSettings(BackupProjectSettings settings) { m_backupTime = settings.BackupTime; m_comment = settings.Comment; m_configurationSettings = settings.IncludeConfigurationSettings; m_supportingFiles = settings.IncludeSupportingFiles; m_linkedFiles = settings.IncludeLinkedFiles; m_projectName = settings.ProjectName; m_projectPathPersisted = FdoFileHelper.GetPathWithoutRoot(settings.ProjectPath); m_spellCheckAdditions = settings.IncludeSpellCheckAdditions; m_dbVersion = settings.DbVersion; m_fwVersion = settings.FwVersion; m_linkedFilesPathRelative = LinkedFilesRelativePathHelper.GetLinkedFilesRelativePathFromFullPath(settings.ProjectsRootFolder, settings.LinkedFilesPath, settings.ProjectPath, settings.ProjectName); m_linkedFilesPathActual = settings.LinkedFilesPath; m_appAbbrev = settings.AppAbbrev; }
/// <summary> /// Stores the configuration name as the key, and the file path as the value /// User configuration files with the same name as a shipped configuration will trump the shipped /// </summary> /// <seealso cref="DictionaryConfigurationController.ListDictionaryConfigurationChoices()"/> public static SortedDictionary <string, string> GatherBuiltInAndUserConfigurations(FdoCache cache, string configObjectName) { var configurations = new SortedDictionary <string, string>(); var defaultConfigs = Directory.EnumerateFiles(Path.Combine(FwDirectoryFinder.DefaultConfigurations, configObjectName), "*" + DictionaryConfigurationModel.FileExtension); // for every configuration file in the DefaultConfigurations folder add an entry AddOrOverrideConfiguration(defaultConfigs, configurations); var projectConfigPath = Path.Combine(FdoFileHelper.GetConfigSettingsDir(cache.ProjectId.ProjectFolder), configObjectName); if (Directory.Exists(projectConfigPath)) { var projectConfigs = Directory.EnumerateFiles(projectConfigPath, "*" + DictionaryConfigurationModel.FileExtension); // for every configuration in the projects configurations folder either override a shipped configuration or add an entry AddOrOverrideConfiguration(projectConfigs, configurations); } return(configurations); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Persists the dialog settings as an XML file. /// </summary> /// ------------------------------------------------------------------------------------ private void PersistBackupFileSettings() { string backupSettingsFile = Path.Combine(FdoFileHelper.GetBackupSettingsDir( m_settings.ProjectPath), FdoFileHelper.kBackupSettingsFilename); string settingsDir = Path.GetDirectoryName(backupSettingsFile); if (!Directory.Exists(settingsDir)) { Directory.CreateDirectory(settingsDir); } using (FileStream fs = new FileStream(backupSettingsFile, FileMode.Create)) { BackupFileSettings.SaveToStream(m_settings, fs); } }