public void btnAdd_Click(object sender, EventArgs e, string ForceURL) { string usedURL = ""; if (ForceURL != null) { usedURL = ForceURL; } else { usedURL = edtURL.Text; } bool board = (tcApp.SelectedIndex == 1); // Board Tab is open -> board=true; Thread tab -> board=false Imageboard newImageboard = General.createNewIMB(usedURL.Trim(), board); if (newImageboard != null) { if (isUnique(newImageboard.getURL(), clThreads)) { if (board) { lbBoards.Items.Add(usedURL); clBoards.Add(newImageboard); } else { lbThreads.Items.Add(new IBDownloadItem(usedURL)); clThreads.Add(newImageboard); } } else { MessageBox.Show("URL is already in queue!"); } } else { MessageBox.Show("Corrupt URL, unsupported website or not a board/thread!"); edtURL.Text = ""; return; } if (!board) { Thread nIMB = new Thread(delegate() { newImageboard.download(); }); nIMB.Name = newImageboard.getURL(); thrThreads.Add(nIMB); thrThreads[thrThreads.Count - 1].Start(); } edtURL.Text = ""; if (!scnTimer.Enabled) { scnTimer.Enabled = true; } scan(null, null); }
private void frmMain_Load(object sender, EventArgs e) { General.loadSettings(); // load settings on startup if (!General.minimizeToTray) // if trayicon deactivated { nfTray.Visible = false; // hide it } scnTimer.Enabled = false; // disable timer scnTimer.Interval = General.timer; // set interval scnTimer.Tick += new EventHandler(this.scan); // when Timer ticks call scan() if (General.saveOnClose) // if enabled load URLs from file { string[] URLs; string boards = General.loadURLs(true); if (boards != "") { URLs = boards.Split('\n'); for (int i = 0; i < URLs.Length - 1; i++) { Imageboard newImageboard = General.createNewIMB(URLs[i], true); // and add them lbBoards.Items.Add(URLs[i]); clBoards.Add(newImageboard); } scnTimer.Enabled = true; // activate the timer scan(null, null); // and start scanning } string threads = General.loadURLs(false); // load threads if (threads != "") { URLs = threads.Split('\n'); for (int i = 0; i < URLs.Length - 1; i++) { Imageboard newImageboard = General.createNewIMB(URLs[i], false); if (newImageboard == null) { MessageBox.Show(URLs[i]); } else { lbThreads.Items.Add(URLs[i]); clThreads.Add(newImageboard); Thread nIMB = new Thread(delegate() { newImageboard.download(); }); thrThreads.Add(nIMB); thrThreads.Last().Start(); } } } } if (General.firstStart) { FirstStart tFirstStart = new FirstStart(); // if first start, show first start message tFirstStart.ShowDialog(); } }
private void ScanThread() { lock (threadLock) { //Removes 404'd threads foreach (Imageboard imB in ListThreads.ToArray()) { if (imB.isGone()) { ListThreads.Remove(imB); updateDataSource(typeURL.thread); if (General.saveOnClose) { General.writeURLs(ListBoards, ListThreads); } } } } lock (boardLock) { //Searches for new threads on the watched boards foreach (Imageboard imB in ListBoards) { string[] Threads = { }; try { Threads = imB.getThreads(); } catch (Exception exep) { } foreach (string thread in Threads) { Imageboard newImageboard = General.createNewIMB(thread, false); if (newImageboard != null && isUnique(newImageboard.getURL(), ListThreads)) { lock (threadLock) { ListThreads.Add(newImageboard); updateDataSource(typeURL.thread); } } } } } lock (threadLock) { //Download threads foreach (Imageboard imB in ListThreads) { ThreadPool.QueueUserWorkItem(new WaitCallback(imB.download)); } } }
private void frmMain_Load(object sender, EventArgs e) { General.loadSettings(); // load settings on startup if (!General.minimizeToTray) // if trayicon deactivated { nfTray.Visible = false; // hide it } scnTimer.Enabled = false; // disable timer scnTimer.Interval = General.timer; // set interval scnTimer.Tick += new EventHandler(this.scan); // when Timer ticks call scan() ThreadPool.SetMaxThreads(Environment.ProcessorCount, Environment.ProcessorCount); if (General.firstStart) { FirstStart tFirstStart = new FirstStart(); // if first start, show first start message tFirstStart.ShowDialog(); } if (General.saveOnClose) // if enabled load URLs from file { string boards = General.loadURLs(true); string threads = General.loadURLs(false); // load threads if (!String.IsNullOrWhiteSpace(boards)) { lock (boardLock) { string[] URLs = boards.Split('\n'); for (int i = 0; i < URLs.Length - 1; i++) { Imageboard newImageboard = General.createNewIMB(URLs[i], true); // and add them ListBoards.Add(newImageboard); } } } if (!String.IsNullOrWhiteSpace(threads)) { lock (threadLock) { string[] URLs = threads.Split('\n'); for (int i = 0; i < URLs.Length - 1; i++) { Imageboard newImageboard = General.createNewIMB(URLs[i], false); ListThreads.Add(newImageboard); } } } lbBoards.DataSource = ListBoards; lbThreads.DataSource = ListThreads; scnTimer.Enabled = true; // activate the timer scan(null, null); // and start scanning } }
private void AddUrl(string url, bool board) { Imageboard newImageboard = General.createNewIMB(url, board); if (newImageboard != null) { if (isUnique(newImageboard.getURL(), ListThreads)) { if (board) { lock (boardLock) { ListBoards.Add(newImageboard); updateDataSource(typeURL.board); } } else { lock (threadLock) { ListThreads.Add(newImageboard); updateDataSource(typeURL.thread); } } } else { MessageBox.Show("URL is already in queue!"); return; } } else { MessageBox.Show("Corrupt URL, unsupported website or not a board/thread!"); edtURL.Text = ""; return; } if (!scnTimer.Enabled) { scnTimer.Enabled = true; } if (General.saveOnClose) { General.writeURLs(ListBoards, ListThreads); } scan(null, null); }
private void scan(object sender, EventArgs e) { /*#if DEBUG * MessageBox.Show("Threads: (" + thrThreads.Count + ") (" + clThreads.Count +")"); * MessageBox.Show("Boards: (" + thrBoards.Count + ") (" + clBoards.Count +")"); #endif*/ if (Scanner == null || !Scanner.IsAlive) { Scanner = new Thread(delegate() { for (int k = 0; k < clThreads.Count; k++) { if (clThreads[k].isGone()) { clThreads.RemoveAt(k); thrThreads.RemoveAt(k); lbThreads.Invoke((MethodInvoker) delegate { lbThreads.Items.RemoveAt(k); }); } } for (int k = 0; k < clBoards.Count; k++) { string[] Threads = { }; try { Threads = clBoards[k].getThreads().Split('\n'); } catch (Exception exep) { } for (int l = 0; l < Threads.Length; l++) { Imageboard newImageboard = General.createNewIMB(Threads[l], false); if (newImageboard != null && isUnique(newImageboard.getURL(), clThreads)) { lbThreads.Invoke((MethodInvoker)(() => { lbThreads.Items.Add(Threads[l]); })); clThreads.Add(newImageboard); Thread nIMB = new Thread(delegate() { newImageboard.download(); }); nIMB.Name = newImageboard.getURL(); thrThreads.Add(nIMB); thrThreads[thrThreads.Count - 1].Start(); } } } for (int k = 0; k < clThreads.Count; k++) { if (!thrThreads[k].IsAlive) { /* MessageBox.Show("Down: " + k); */ thrThreads[k] = new Thread(delegate() { int x = k; try { clThreads[k - 1].download(); // why } catch (Exception exp) { // MessageBox.Show(exp.Message + " k: " + x); } }); thrThreads[k].Name = clThreads[k].getURL(); thrThreads[k].Start(); } } }); Scanner.Start(); } }
private void scan(object sender, EventArgs e) { /*#if DEBUG * MessageBox.Show("Threads: (" + thrThreads.Count + ") (" + clThreads.Count +")"); * MessageBox.Show("Boards: (" + thrBoards.Count + ") (" + clBoards.Count +")"); #endif*/ if (Scanner == null || !Scanner.IsAlive) { Scanner = new Thread(delegate() { for (int k = 0; k < clThreads.Count; k++) { if (clThreads[k].isGone()) { //clThreads.RemoveAt(k); //thrThreads.RemoveAt(k); thrThreads[k].Abort(); lbThreads.Invoke((MethodInvoker) delegate { (lbThreads.Items[k] as IBDownloadItem).State = IBThreadState.DELETED; }); } if (clThreads[k].isArchived()) { lbThreads.Invoke((MethodInvoker) delegate { (lbThreads.Items[k] as IBDownloadItem).State = IBThreadState.ARCHIVED; }); } if (clThreads[k].FirstQueryDone() && !clThreads[k].isGone() && !clThreads[k].isArchived()) { lbThreads.Invoke((MethodInvoker) delegate { (lbThreads.Items[k] as IBDownloadItem).State = IBThreadState.ONGOING; }); } lbThreads.Invoke((MethodInvoker) delegate { if (!(lbThreads.Items[k] as IBDownloadItem).OverrideThreadName && clThreads[k].itsThreadName() != "") { if ((lbThreads.Items[k] as IBDownloadItem).ThreadName != clThreads[k].itsThreadName()) { (lbThreads.Items[k] as IBDownloadItem).ThreadName = clThreads[k].itsThreadName(); } } }); } lbThreads.Invoke((MethodInvoker) delegate { lbThreads.RefreshItems(); }); for (int k = 0; k < clBoards.Count; k++) { string[] Threads = { }; try { Threads = clBoards[k].getThreads().Split('\n'); } catch (Exception exep) { } for (int l = 0; l < Threads.Length; l++) { Imageboard newImageboard = General.createNewIMB(Threads[l], false); if (newImageboard != null && isUnique(newImageboard.getURL(), clThreads)) { lbThreads.Invoke((MethodInvoker)(() => { lbThreads.Items.Add(new IBDownloadItem(Threads[l])); })); clThreads.Add(newImageboard); Thread nIMB = new Thread(delegate() { newImageboard.download(); }); nIMB.Name = newImageboard.getURL(); thrThreads.Add(nIMB); thrThreads[thrThreads.Count - 1].Start(); } } } for (int k = 0; k < clThreads.Count; k++) { IBThreadState thisThreadState = IBThreadState.PENDING; lbThreads.Invoke((MethodInvoker) delegate { thisThreadState = (lbThreads.Items[k] as IBDownloadItem).State; }); if (thisThreadState != IBThreadState.DELETED && !thrThreads[k].IsAlive) { /* MessageBox.Show("Down: " + k); */ thrThreads[k] = new Thread(delegate() { int x = k; try { clThreads[k - 1].download(); // why } catch (Exception exp) { // MessageBox.Show(exp.Message + " k: " + x); } }); thrThreads[k].Name = clThreads[k].getURL(); thrThreads[k].Start(); } } }); Scanner.Start(); } }