private void btnOk_Click(object sender, EventArgs e) { this.lblStatus.Text = "Validating input..."; Application.DoEvents(); try { FileInfo fi = new FileInfo(this.txtDbLoc.Text); bool exists = fi.Exists; Directory.CreateDirectory(fi.DirectoryName); fi.Create().Close(); if(!exists) fi.Delete(); } catch { Program._genericMessageBox("An error occurred creating the database file; ensure you have permissions to the directory in which you are creating it.", MessageBoxIcon.Error); return; } try { using (BoardParser bp = new BoardParser(this.cbBoardURL.Text)) { if (bp.DetectPageCount() < 1) throw new Exception(); } } catch { Program._genericMessageBox("An error occured parsing your board URL; ensure the URL is a valid 4chan board.", MessageBoxIcon.Error); return; } this.DialogResult = DialogResult.OK; this.Close(); }
void cmTree_Rescrape_Click(object sender, EventArgs e) { if (this.treePostWindowMouseAt == null) return; if (this.treePostWindowMouseAt.Tag.Equals("thread")) { if (this._threadParse != null && this._threadParse.IsAlive) { Program._genericMessageBox("A metadata scrape is already in progress. Please wait until the current metadata scrape is complete.", MessageBoxIcon.Warning); return; } Thread t = this._db[this.treePostWindowMouseAt.Text]; if (t == null) return; this._threadParse = new SysThread(new ThreadStart(delegate() { this.Invoke(new __UpdateStatusText(this.UpdateStatusText), "Grabbing metadata for 1 thread..."); try { using (BoardParser bp = new BoardParser(this._db.URL)) { Thread tt = new Thread(t.Id); bp.CrawlThread(tt); t += tt; } } catch { Program._genericMessageBox("Crawling the thread failed. It may have been 404'd.", MessageBoxIcon.Error); } this._db[this.treePostWindowMouseAt.Text] = t; })); this._threadParse.Start(); while (this._running && this._threadParse.IsAlive) { Application.DoEvents(); SysThread.Sleep(50); } this.DrawDatabaseTree(this._db); this.treePostWindow.SelectedNode = this.treePostWindowMouseAt; this._crawlThread(t, this._db.ImageDir); _statusLoopDownloading(); } }
private void mnuMain_ScraperManAdd_Click(object sender, EventArgs e) { Dialogs.frmInputDialog input = new Scraper.Dialogs.frmInputDialog("Enter the URL or thread ID of a thread in the board."); input.ShowDialog(); string str = input.InputText.Trim(); if (str == "") return; int id = 0; if (!int.TryParse(str, out id)) { Match m = frmMain.threadIdR.Match(str); if (m.Success) id = int.Parse(m.Groups[1].Value); } if (id == 0) return; System.Net.HttpWebRequest req = System.Net.WebRequest.Create(this._db.URL + (this._db.URL.EndsWith("/") ? "" : "/") + "res/" + id) as System.Net.HttpWebRequest; req.Credentials = System.Net.CredentialCache.DefaultCredentials; req.Method = "HEAD"; System.Net.HttpWebResponse resp = req.GetResponse() as System.Net.HttpWebResponse; if (resp.StatusCode != System.Net.HttpStatusCode.OK) { Program._genericMessageBox("The thread you specified was not found. Please check your input.", MessageBoxIcon.Exclamation); return; } resp.Close(); if (this._threadParse != null && this._threadParse.IsAlive) { Program._genericMessageBox("A metadata scrape is already in progress. Please wait until the current metadata scrape is complete.", MessageBoxIcon.Warning); return; } Thread t = new Thread(id); this._threadParse = new SysThread(new ThreadStart(delegate() { this.Invoke(new __UpdateStatusText(this.UpdateStatusText), "Grabbing metadata for 1 thread..."); try { using (BoardParser bp = new BoardParser(this._db.URL)) { bp.CrawlThread(t); } } catch { Program._genericMessageBox("Crawling the thread failed. It may have been 404'd.", MessageBoxIcon.Error); } })); this._threadParse.Start(); while (this._running && this._threadParse.IsAlive) { Application.DoEvents(); SysThread.Sleep(50); } this._db.AddThread(t); this.DrawDatabaseTree(this._db); this._crawlThread(this._db[id], this._db.ImageDir); _statusLoopDownloading(); }
public void ScrapeBoard() { if (this._threadParse != null && this._threadParse.IsAlive) { Program._genericMessageBox("A metadata scrape is already in progress. Please wait until the current metadata scrape is complete.", MessageBoxIcon.Warning); return; } List<Thread> newThreads = new List<Thread>(); this._threadParse = new SysThread(new ThreadStart(delegate() { BoardParser bp = new BoardParser(this._db.URL); if (this.EnableScrapeAll) { int pages = bp.DetectPageCount(); string[] urls = new string[pages]; this.Invoke(new __UpdateStatusText(this.UpdateStatusText), "Grabbing metadata for " + pages + " pages...this may take a while."); for (int i = 1; i <= pages; i++) { urls[pages - i] = this._db.URL.TrimEnd('/') + "/" + (i == 1 ? "" : i.ToString()); } foreach (string s in urls) newThreads.AddRange(new BoardParser(s).Parse()); this.EnableScrapeAll = false; } else { this.Invoke(new __UpdateStatusText(this.UpdateStatusText), "Grabbing metadata...this may take a while."); newThreads.AddRange(new BoardParser(this._db.URL).Parse()); } })); this._threadParse.Start(); while (this._threadParse.IsAlive) { Application.DoEvents(); SysThread.Sleep(50); } this._db.AddThreads(newThreads); this.DrawDatabaseTree(this._db); if (!Directory.Exists(this._db.ImageDir)) Directory.CreateDirectory(this._db.ImageDir); this._crawlThreads(newThreads, this._db.ImageDir); this._statusLoopDownloading(); }