///<summary> /// Returns an instance of an ldml in folder writing system reposistory. ///</summary> ///<param name="basePath">base location of the global writing system repository</param> ///<param name="migrationHandler">Callback if during the initialization any writing system id's are changed</param> ///<param name="loadProblemHandler">Callback if during the initialization any writing systems cannot be loaded</param> ///<param name="compatibilityMode"></param> public static LdmlInFolderWritingSystemRepository Initialize( string basePath, LdmlVersion0MigrationStrategy.MigrationHandler migrationHandler, WritingSystemLoadProblemHandler loadProblemHandler, WritingSystemCompatibility compatibilityMode ) { var migrator = new LdmlInFolderWritingSystemRepositoryMigrator(basePath, migrationHandler, compatibilityMode); migrator.Migrate(); var instance = new LdmlInFolderWritingSystemRepository(basePath, compatibilityMode); instance.LoadAllDefinitions(); // Call the loadProblemHandler with both migration problems and load problems var loadProblems = new List <WritingSystemRepositoryProblem>(); loadProblems.AddRange(migrator.MigrationProblems); loadProblems.AddRange(instance.LoadProblems); if (loadProblems.Count > 0 && loadProblemHandler != null) { loadProblemHandler(loadProblems); } return(instance); }
/// <summary> /// Returns an instance of an ldml in folder writing system reposistory. /// </summary> /// <param name="basePath">base location of the global writing system repository</param> /// <param name="customDataMappers">The custom data mappers.</param> /// <param name="globalRepository">The global repository.</param> /// <param name="migrationHandler">Callback if during the initialization any writing system id's are changed</param> /// <param name="loadProblemHandler">Callback if during the initialization any writing systems cannot be loaded</param> /// <returns></returns> public static LdmlInFolderWritingSystemRepository Initialize( string basePath, IEnumerable <ICustomDataMapper <WritingSystemDefinition> > customDataMappers, GlobalWritingSystemRepository globalRepository = null, Action <int, IEnumerable <LdmlMigrationInfo> > migrationHandler = null, Action <IEnumerable <WritingSystemRepositoryProblem> > loadProblemHandler = null ) { var migrator = new LdmlInFolderWritingSystemRepositoryMigrator(basePath, migrationHandler); migrator.Migrate(); var instance = new LdmlInFolderWritingSystemRepository(basePath, customDataMappers, globalRepository); migrator.ResetRemovedProperties(instance); // Call the loadProblemHandler with both migration problems and load problems var loadProblems = new List <WritingSystemRepositoryProblem>(); loadProblems.AddRange(migrator.MigrationProblems); loadProblems.AddRange(instance.LoadProblems); if (loadProblems.Count > 0 && loadProblemHandler != null) { loadProblemHandler(loadProblems); } return(instance); }
public void PerformMigration(IDomainObjectDTORepository repoDto) { DataMigrationServices.CheckVersionNumber(repoDto, 7000043); if (repoDto.ProjectFolder != Path.GetTempPath()) { // Skip migrating the global repository if we're just running tests. Slow and may not be wanted. // In a real project we do this first; thus if by any chance a WS is differently renamed in // the two folders, the renaming that is right for this project wins. var globalWsFolder = LcmFileHelper.OldGlobalWritingSystemStoreDirectory; var globalMigrator = new LdmlInFolderWritingSystemRepositoryMigrator(globalWsFolder, NoteMigration, 2); globalMigrator.Migrate(); } var ldmlFolder = Path.Combine(repoDto.ProjectFolder, LcmFileHelper.ksWritingSystemsDir); var migrator = new LdmlInFolderWritingSystemRepositoryMigrator(ldmlFolder, NoteMigration, 2); migrator.Migrate(); var wsIdMigrator = new WritingSystemIdMigrator(repoDto, TryGetNewTag, "*_Layouts.xml"); wsIdMigrator.Migrate(); DataMigrationServices.IncrementVersionNumber(repoDto); }
public void MigrateIfNecessary() { var oldMigrator = new WritingSystemPrefsMigrator(WritingSystemsOldPrefsFilePath, OnWritingSystemTagChange); oldMigrator.MigrateIfNecassary(); var ldmlMigrator = new LdmlInFolderWritingSystemRepositoryMigrator(WritingSystemsPath, OnWritingSystemTagChange, WritingSystemCompatibility.Flex7V0Compatible); ldmlMigrator.Migrate(); }
private void SetupLdmlFolder() { // Since we are only reading the Writing Systems, we make a copy and migrate. _ldmlFolder = Path.Combine(Path.GetTempPath(), Path.GetFileNameWithoutExtension(Path.GetTempFileName())); var wsFolder = Common.GetLDMLPath(); if (!Directory.Exists(wsFolder)) { return; } FolderTree.Copy(Common.GetLDMLPath(), _ldmlFolder); var migrator = new LdmlInFolderWritingSystemRepositoryMigrator(_ldmlFolder, null); migrator.Migrate(); }
static int Main(string[] rgArgs) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); for (int i = 0; i < rgArgs.Length; ++i) { if (rgArgs[i] == "-debug") { s_fDebug = true; } else if (rgArgs[i] == "-autoclose") { s_fAutoClose = true; } else if (rgArgs[i] == "-chars") { s_fMigrateChars = true; } } FwRegistryHelper.Initialize(); // needed to access proper registry values if (s_fMigrateChars && s_fDebug) { MessageBox.Show("Warning: MigrateSqlDbs called with no-longer valid argument, '-chars'. Run 'UnicodeCharEditor -i' instead."); } // TE-9422. If we had an older version of FW7 installed, ldml files are < verion 2, so will cause // a crash if we don't migrate the files to version 2 before opening a project with the current version. // TODO (WS_FIX): should we migrate all the way to version 3? string globalWsFolder = LcmFileHelper.OldGlobalWritingSystemStoreDirectory; var globalMigrator = new LdmlInFolderWritingSystemRepositoryMigrator(globalWsFolder, NoteMigration, 2); globalMigrator.Migrate(); using (var threadHelper = new ThreadHelper()) using (var progressDlg = new ProgressDialogWithTask(threadHelper)) { ImportFrom6_0 importer = new ImportFrom6_0(progressDlg, FwDirectoryFinder.ConverterConsoleExe, FwDirectoryFinder.DbExe, s_fDebug); if (!importer.IsFwSqlServerInstalled()) { return(-1); } string version; if (!importer.IsValidOldFwInstalled(out version)) { if (!String.IsNullOrEmpty(version) && version.CompareTo("5.4") < 0) { string launchesFlex = "0"; if (RegistryHelper.KeyExists(FwRegistryHelper.FieldWorksRegistryKey, "Language Explorer")) { using (RegistryKey keyFlex = FwRegistryHelper.FieldWorksRegistryKey.CreateSubKey("Language Explorer")) launchesFlex = keyFlex.GetValue("launches", "0") as string; } if (launchesFlex == "0") { FwRegistryHelper.FieldWorksRegistryKey.SetValue("MigrationTo7Needed", "true"); } using (var dlg = new FWVersionTooOld(version)) { dlg.ShowDialog(); } } return(-1); } List <string> projects = GetProjectList(); if (projects.Count > 0) { using (var migrateProjects = new MigrateProjects(importer, version, projects, s_fAutoClose)) { Application.Run(migrateProjects); } } else if (s_fDebug) { MessageBox.Show("No FieldWorks (SQL) projects were detected.", "DEBUG!"); } } return(s_ReturnValue); }
public void PerformMigration(IDomainObjectDTORepository repoDto) { DataMigrationServices.CheckVersionNumber(repoDto, 7000070); // Skip migrating the global repository if we're just running tests. Slow and may not be wanted. // In a real project we do this first; thus if by any chance a WS is differently renamed in // the two folders, the renaming that is right for this project wins. if (!repoDto.ProjectFolder.StartsWith(Path.GetTempPath())) { var globalMigrator = new GlobalWritingSystemRepositoryMigrator(GlobalWritingSystemRepository.DefaultBasePath, versionToMigrateTo: 3); // first migrate any existing global writing systems in the new global writing system directory if (globalMigrator.NeedsMigration()) { globalMigrator.Migrate(); } string migratedFilePath = Path.Combine(LcmFileHelper.OldGlobalWritingSystemStoreDirectory, ".migrated"); if (Directory.Exists(LcmFileHelper.OldGlobalWritingSystemStoreDirectory) && !File.Exists(migratedFilePath)) { // copy over all FW global writing systems from the old directory to the new directory and migrate string globalRepoPath = Path.Combine(GlobalWritingSystemRepository.DefaultBasePath, "3"); if (!Directory.Exists(globalRepoPath)) { GlobalWritingSystemRepository.CreateGlobalWritingSystemRepositoryDirectory(globalRepoPath); } CopyDirectoryContents(LcmFileHelper.OldGlobalWritingSystemStoreDirectory, globalRepoPath); globalMigrator.Migrate(); // add ".migrated" file to indicate that this folder has been migrated already File.WriteAllText(migratedFilePath, string.Format("The writing systems in this directory have been migrated to {0}.", globalRepoPath)); } } string ldmlFolder = Path.Combine(repoDto.ProjectFolder, LcmFileHelper.ksWritingSystemsDir); var migrator = new LdmlInFolderWritingSystemRepositoryMigrator(ldmlFolder, NoteMigration, 3); migrator.Migrate(); string sharedSettingsPath = LexiconSettingsFileHelper.GetSharedSettingsPath(repoDto.ProjectFolder); if (!Directory.Exists(sharedSettingsPath)) { Directory.CreateDirectory(sharedSettingsPath); } var projectSettingsStore = new FileSettingsStore(LexiconSettingsFileHelper.GetProjectLexiconSettingsPath(repoDto.ProjectFolder)); var userSettingsStore = new FileSettingsStore(LexiconSettingsFileHelper.GetUserLexiconSettingsPath(repoDto.ProjectFolder)); var repo = new CoreLdmlInFolderWritingSystemRepository(ldmlFolder, projectSettingsStore, userSettingsStore); migrator.ResetRemovedProperties(repo); // migrate local keyboard settings from CoreImpl application settings to new lexicon user settings file // skip if we're running unit tests, could interfere with the test results string localKeyboards; if (!repoDto.ProjectFolder.StartsWith(Path.GetTempPath()) && TryGetLocalKeyboardsSetting(out localKeyboards)) { if (localKeyboards.Length > 0) { XElement keyboardsElem = XElement.Parse(localKeyboards); foreach (XElement keyboardElem in keyboardsElem.Elements("keyboard")) { var wsId = (string)keyboardElem.Attribute("ws"); CoreWritingSystemDefinition ws; if (repo.TryGet(wsId, out ws)) { var layout = (string)keyboardElem.Attribute("layout"); var locale = (string)keyboardElem.Attribute("locale"); string keyboardId = string.IsNullOrEmpty(locale) ? layout : $"{locale}_{layout}"; IKeyboardDefinition keyboard; if (!Keyboard.Controller.TryGetKeyboard(keyboardId, out keyboard)) { keyboard = Keyboard.Controller.CreateKeyboard(keyboardId, KeyboardFormat.Unknown, Enumerable.Empty <string>()); } ws.LocalKeyboard = keyboard; } } } repo.Save(); } var wsIdMigrator = new WritingSystemIdMigrator(repoDto, TryGetNewLangTag, "*.fwlayout"); wsIdMigrator.Migrate(); DataMigrationServices.IncrementVersionNumber(repoDto); }
static int Main(string[] rgArgs) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); for (int i = 0; i < rgArgs.Length; ++i) { if (rgArgs[i] == "-debug") { s_fDebug = true; } else if (rgArgs[i] == "-autoclose") { s_fAutoClose = true; } else if (rgArgs[i] == "-chars") { s_fMigrateChars = true; } } RegistryHelper.ProductName = "FieldWorks"; // needed to access proper registry values if (s_fMigrateChars || s_fAutoClose) { try { string location = Assembly.GetExecutingAssembly().Location; string program = Path.Combine(Path.GetDirectoryName(location), "UnicodeCharEditor.exe"); using (Process proc = Process.Start(program, "-i")) { proc.WaitForExit(); } } catch (Exception e) { if (s_fDebug) { var msg = String.Format("Cannot migrate the custom character definitions:{1}{0}", e.Message, Environment.NewLine); MessageBox.Show(msg); } } } // TE-9422. If we had an older version of FW7 installed, ldml files are < verion 2, so will cause // a crash if we don't migrate the files to version 2 before opening a project with the current version. var globalWsFolder = DirectoryFinder.GlobalWritingSystemStoreDirectory; var globalMigrator = new LdmlInFolderWritingSystemRepositoryMigrator(globalWsFolder, NoteMigration); globalMigrator.Migrate(); using (var progressDlg = new ProgressDialogWithTask(null, new ThreadHelper())) { ImportFrom6_0 importer = new ImportFrom6_0(progressDlg, s_fDebug); if (!importer.IsFwSqlServerInstalled()) { return(-1); } string version; if (!importer.IsValidOldFwInstalled(out version)) { return(-1); } List <string> projects = GetProjectList(); if (projects.Count > 0) { using (var migrateProjects = new MigrateProjects(importer, version, projects, s_fAutoClose)) { Application.Run(migrateProjects); } } else if (s_fDebug) { MessageBox.Show("No FieldWorks (SQL) projects were detected.", "DEBUG!"); } } return(s_ReturnValue); }