Exemple #1
0
        private void RunRepair()
        {
            string dbPath = null;

            string[] args = Environment.GetCommandLineArgs();
            if (args.Length > 1)
            {
                if (args [1] == "-?" || args [1] == "/?")
                {
                    ShowHelp();
                    return;
                }
                string arg = args [1].ToLower();
                if ((arg == "-workdir" || arg == "/workdir") && args.Length > 2)
                {
                    dbPath = args [2];
                    if (args.Length > 3)
                    {
                        ProcessArgument(args [3]);
                    }
                }
                else
                {
                    ProcessArgument(arg);
                }
            }

            if (dbPath == null)
            {
                dbPath = RegUtil.DatabasePath;
                if (dbPath == null)
                {
                    dbPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
                                          "JetBrains\\Omea");
                }
            }

            OMEnv.WorkDir       = dbPath;
            MyPalStorage.DBPath = Path.Combine(OMEnv.WorkDir, "db");
            _ini = new IniFile(Path.Combine(OMEnv.WorkDir, "OmniaMea.ini"));

            Console.WriteLine("Processing database in " + dbPath);

            bool  omniaMeaIsNotRun;
            Mutex omniaMeaMux = new Mutex(true, "OmniaMeaMutex", out omniaMeaIsNotRun);

            try
            {
                if (!omniaMeaIsNotRun && !_ignoreMutex)
                {
                    Console.WriteLine("Omea is currently running. Please close Omea before running DBRepair.");
                    return;
                }

                if (_deleteIndex)
                {
                    DeleteIndex();
                }
                else if (_deleteTextIndex)
                {
                    DeleteFiles(OMEnv.WorkDir, "_*");
                }
                else if (_backup)
                {
                    string backupPath = _ini.ReadString("ResourceStore", "BackupPath", string.Empty);
                    if (backupPath.Length > 0)
                    {
                        Console.Write("Database backup in progress...");
                        MyPalStorage.BackupDatabase(IOTools.Combine(backupPath, MyPalStorage._dbBackupFile));
                        Console.WriteLine("\r                               \rDatabase backup done.");
                    }
                    else
                    {
                        Console.WriteLine("Backup path is not set. Run Omea, in Options | Paths set the path.");
                    }
                }
                else if (_restore)
                {
                    string backupPath = _ini.ReadString("ResourceStore", "BackupPath", string.Empty);
                    if (backupPath.Length > 0)
                    {
                        Console.Write("Restoring database from backup...");
                        MyPalStorage.RestoreFromBackup(IOTools.Combine(backupPath, MyPalStorage._dbBackupFile));
                        Console.WriteLine("\r                                  \rDatabase restored from backup.");
                    }
                    else
                    {
                        Console.WriteLine("Backup path is not set. Run Omea, in Options | Paths set the path.");
                    }
                }
                else
                {
                    if (!_textAnalyze || _lowCheck)
                    {
                        ProcessDB();
                    }
                    else
                    {
                        try
                        {
                            ProcessTextIndex(OMEnv.WorkDir + "\\_term.index");
                        }
                        catch (FormatException exc_)
                        {
                            Console.Error.WriteLine(exc_.Message);
                        }
                    }
                }
            }
            finally
            {
                omniaMeaMux.Close();
            }
            if (!_dump && !_deleteIndex)
            {
                Console.WriteLine("Press Enter to continue...");
                Console.ReadLine();
            }
        }