コード例 #1
0
ファイル: Program.cs プロジェクト: kolrabi/DesktopBooru
 public bool Quit()
 {
     if (this.EventCenter.Quit())
     {
         foreach (var plugin in this.PluginLoader.LoadedPlugins)
         {
             plugin.OnUnload();
         }
         Booru.DatabaseQuery.DumpTimes();
         LoggingMutex.DumpAllStats();
         Gtk.Application.Quit();
         return(true);
     }
     else
     {
         return(false);
     }
 }
コード例 #2
0
        public void OpenDatabase(DbConnection connection)
        {
            this.Close();
            this.IsLoaded = false;

            BooruApp.BooruApplication.EventCenter.BeginChangeDatabase();
            BooruApp.BooruApplication.TaskRunner.StartTaskAsync("Open database " + BooruApp.BooruApplication.DBFile, () => {
                Logger.Log(BooruLog.Severity.Info, "Opening database " + BooruApp.BooruApplication.DBFile + "...");
                this.Connection = connection;
                this.Mutex      = new LoggingMutex(this.Connection, "Database");

                try {
                    this.Connection.Open();

                    var pragmaCommand         = this.Connection.CreateCommand();
                    pragmaCommand.CommandText =
                        "PRAGMA cache_size = -8192; ";
                    pragmaCommand.ExecuteNonQuery();

                    this.TagEntryCompletionStore = new Gtk.ListStore(typeof(string), typeof(int));

                    this.Config = new Configuration(this);

                    Logger.Log(BooruLog.Severity.Info, "Checking database version...");
                    var versionString = this.Config.GetString("$version", null);
                    if (string.IsNullOrEmpty(versionString))
                    {
                        Logger.Log(BooruLog.Severity.Error, "Database version not found. Not a booru database!");
                        this.Connection.Close();
                        BooruApp.BooruApplication.EventCenter.FinishChangeDatabase(false);
                        return;
                    }

                    var version = this.Config.GetInt("$version");
                    if (version != DATABASE_VERSION)
                    {
                        this.UpgradeDatabase(version);
                    }

                    Logger.Log(BooruLog.Severity.Info, "Caching tags...");
                    this.CacheTags();

                    Logger.Log(BooruLog.Severity.Info, "Checking for obsolete path references...");
                    var allPaths     = this.GetAllPaths();
                    var deletedPaths = new List <string>();
                    Logger.Log(BooruLog.Severity.Info, "File paths in database: " + allPaths.Count);
                    foreach (var path in allPaths)
                    {
                        if (!System.IO.File.Exists(path))
                        {
                            deletedPaths.Add(path);
                            this.RemoveImagePath(path);
                        }
                    }
                    if (deletedPaths.Count > 0)
                    {
                        Logger.Log(BooruLog.Severity.Info, "Removed " + deletedPaths.Count + " path references:");
                        foreach (var path in deletedPaths)
                        {
                            Logger.Log(BooruLog.Severity.Info, "    " + path);
                        }
                    }

                    var voteStats = Queries.Images.GetVoteStats.Execute();
                    Logger.Log(BooruLog.Severity.Info, "Voting statistics:");
                    int totalImageCount = 0;
                    foreach (var stat in voteStats)
                    {
                        Logger.Log(BooruLog.Severity.Info, string.Format("{0} votes: {1} images", stat.Key, stat.Value));
                        totalImageCount += stat.Value;
                    }
                    Logger.Log(BooruLog.Severity.Info, string.Format("{0} images total", totalImageCount));

                    Logger.Log(BooruLog.Severity.Info, "Database successfully opened.");
                    BooruApp.BooruApplication.EventCenter.FinishChangeDatabase(true);
                    this.IsLoaded = true;
                } catch (System.Data.Common.DbException ex) {
                    Logger.Log(ex, "Caught exception while opening database");
                    BooruApp.BooruApplication.EventCenter.FinishChangeDatabase(false);
                }
            });
        }