public void LoadDatabase(string filename) { this.UpdateStatusText("Loading database..."); if (this._db != null) this._db.Dispose(); this._db = ThreadDatabase.LoadFromFile(filename); if (this._db == null) Program._genericMessageBox("An error occurred loading the database. Ensure you have specified a valid database. Check the Debug Console for more information.", MessageBoxIcon.Error); else { DrawDatabaseTree(this._db); this.grpPostStats.Hide(); this.pnlDetails.Show(); this.mnuMain_Scraper.Enabled = true; } this.UpdateStatusText("Ready."); }
private void mnuMain_FileNew_Click(object sender, EventArgs e) { Dialogs.frmNewDatabaseDialog d = new Dialogs.frmNewDatabaseDialog(); DialogResult dr = d.ShowDialog(); if (dr == DialogResult.OK) { ThreadDatabase db = new ThreadDatabase(d.DBName, d.DBLoc, d.DBUrl); if (!Directory.Exists(db.ImageDir)) Directory.CreateDirectory(db.ImageDir); if (!d.ScrapeAll) db.CrawledAllPages = true; db.Save(); db.Dispose(); this.LoadDatabase(d.DBLoc); if (d.StartNow) new SysThread(new ThreadStart(delegate() { this.mnuMain_ScraperNow_Click(null, null); })).Start(); } }
public void DrawDatabaseTree(ThreadDatabase db) { this.UpdateStatusText("Redrawing database tree..."); try { this.treePostWindow.SuspendLayout(); this.treePostWindow.Nodes.Clear(); TreeNode[] tree = new TreeNode[db.ThreadCount]; int j = 0; foreach (KeyValuePair<int, Thread> kvp in db) { TreeNode[] children = new TreeNode[kvp.Value.Count]; for (int i = 0; i < kvp.Value.Count; i++) { children[i] = new TreeNode(kvp.Value[i].Id + (i == 0 ? " (OP)" : "")); if (kvp.Value[i].IsNewPost) { children[i].ForeColor = Color.LimeGreen; kvp.Value[i].IsNewPost = false; } children[i].Tag = "post"; } tree[j] = new TreeNode(kvp.Value.Name != null ? kvp.Value.Name : kvp.Value.Id.ToString(), children); if (kvp.Value.IsNewThread) { tree[j].ForeColor = Color.LimeGreen; kvp.Value.IsNewThread = false; } tree[j++].Tag = "thread"; } this.treePostWindow.Nodes.AddRange(tree); this.treePostWindow.Sort(); this.treePostWindow.ResumeLayout(false); this.treePostWindow.PerformLayout(); } catch (InvalidOperationException) { } this.UpdateStatusText("Ready."); Application.DoEvents(); }