Esempio n. 1
0
        private void ImportFrom6_0Backup(BackupFileSettings fileSettings, IThreadedProgress progressDlg)
        {
            var  importer = new ImportFrom6_0(progressDlg, m_converterConsolePath, m_dbPath);
            bool importSuccessful;

            try
            {
                string projFile;
                importSuccessful = importer.Import(fileSettings.File, m_restoreSettings.ProjectName, m_restoreSettings.ProjectsRootFolder, out projFile);
            }
            catch (CannotConvertException e)
            {
                FailedImportCleanUp(importer);
                throw;
            }
            if (!importSuccessful)
            {
                FailedImportCleanUp(importer);

                if (!importer.HaveOldFieldWorks || !importer.HaveFwSqlServer)
                {
                    throw new MissingOldFwException("Error restoring from FieldWorks 6.0 (or earlier) backup",
                                                    importer.HaveFwSqlServer, importer.HaveOldFieldWorks);
                }
                throw new FailedFwRestoreException("Error restoring from FieldWorks 6.0 (or earlier) backup");
            }
        }
Esempio n. 2
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// The restore process has failed for Import from version 6.0, so delete anything it created that will just get in
 /// the way later.
 /// </summary>
 /// ------------------------------------------------------------------------------------
 private void CleanupFrom6_0FailedRestore(ImportFrom6_0 importer)
 {
     if (importer != null)
     {
         if (Directory.Exists(m_restoreSettings.ProjectPath))
         {
             Directory.Delete(m_restoreSettings.ProjectPath, true);
         }
         using (ZipInputStream zipIn = OpenFWBackupZipfile())
         {
             ZipEntry entry;
             while ((entry = zipIn.GetNextEntry()) != null)
             {
                 var fileName = Path.GetFileName(entry.Name);
                 if (!String.IsNullOrEmpty(fileName))
                 {
                     string filePath = Path.Combine(m_restoreSettings.ProjectsRootFolder, fileName);
                     if (FileUtils.TrySimilarFileExists(filePath, out filePath))
                     {
                         FileUtils.Delete(filePath);
                     }
                 }
             }
             zipIn.Close();
         }
     }
 }
Esempio n. 3
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Constructor.
 /// </summary>
 /// ------------------------------------------------------------------------------------
 public MigrateProjects(ImportFrom6_0 importer, string version, List <string> projects,
                        bool fAutoClose)
     : this()
 {
     m_importer   = importer;
     m_projects   = projects;
     m_fAutoClose = fAutoClose;
     if (m_fAutoClose)
     {
         m_btnClose.Text = Properties.Resources.ksSkip;
     }
     this.Text = String.Format(this.Text, version);
     foreach (string proj in m_projects)
     {
         if (proj == ImportFrom6_0.TempDatabaseName)
         {
             m_fTempMigrationDbExists = true;
         }
         else
         {
             if (proj != "Sena 2" && proj != "Sena 3" && proj != "Lela-Teli 2" && proj != "Lela-Teli 3")
             {
                 m_clbProjects.Items.Add(new ProjectItem(proj));
             }
         }
     }
     m_btnConvert.Enabled = false;               // disable until the user picks a project
 }
Esempio n. 4
0
        private void ImportFrom6_0Backup(BackupFileSettings fileSettings, IThreadedProgress progressDlg)
        {
            ImportFrom6_0 importer = new ImportFrom6_0(progressDlg);
            string        projFile;

            if (!importer.Import(fileSettings.File, m_restoreSettings.ProjectName, out projFile))
            {
                ExceptionHelper.LogAndIgnoreErrors(() => CleanupFrom6_0FailedRestore(importer));
                ExceptionHelper.LogAndIgnoreErrors(() => CleanupAfterRestore(false));
                if (!importer.HaveOldFieldWorks || !importer.HaveFwSqlServer)
                {
                    throw new MissingOldFwException("Error restoring from FieldWorks 6.0 (or earlier) backup",
                                                    importer.HaveFwSqlServer, importer.HaveOldFieldWorks);
                }
                MessageBoxUtils.Show(Strings.ksRestoringOldFwBackupFailed, Strings.ksFailed);
                throw new FailedFwRestoreException("Error restoring from FieldWorks 6.0 (or earlier) backup");
            }
        }
Esempio n. 5
0
 private void FailedImportCleanUp(ImportFrom6_0 importer)
 {
     ExceptionHelper.LogAndIgnoreErrors(() => CleanupFrom6_0FailedRestore(importer));
     ExceptionHelper.LogAndIgnoreErrors(() => CleanupAfterRestore(false));
 }
Esempio n. 6
0
        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);
        }
Esempio n. 7
0
        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);
        }