Exemplo n.º 1
0
        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();
        }
Exemplo n.º 2
0
        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();
        }