Beispiel #1
0
        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);
        }
Beispiel #2
0
        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));
                }
            }
        }
Beispiel #3
0
        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 (Properties.Settings.Default.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
                    {
                    }
                    finally
                    {
                        foreach (string thread in Threads)
                        {
                            Imageboard newImageboard = General.CreateNewImageboard(thread);
                            if (newImageboard != null && isUnique(newImageboard.getURL(), ListThreads))
                            {
                                AddURLToList(newImageboard);
                            }
                        }
                    }
                }
            }

            lock (threadLock)
            {
                //Download threads
                foreach (Imageboard imB in ListThreads)
                {
                    ThreadPool.QueueUserWorkItem(new WaitCallback(imB.download));
                }
            }
        }
Beispiel #4
0
        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);
        }
Beispiel #5
0
        private void AddUrl(string url)
        {
            if (string.IsNullOrWhiteSpace(url) && Clipboard.ContainsText())
            {
                url = Clipboard.GetText();
            }

            Imageboard newImageboard = General.CreateNewImageboard(url);

            if (newImageboard != null)
            {
                if (isUnique(newImageboard.getURL(), newImageboard.isBoard() ? ListBoards : ListThreads))
                {
                    AddURLToList(newImageboard);

                    if (!scnTimer.Enabled)
                    {
                        scnTimer.Enabled = true;
                    }
                    if (Properties.Settings.Default.saveOnClose)
                    {
                        General.WriteURLs(ListBoards, ListThreads);
                    }

                    scan(this, new EventArgs());
                }
                else
                {
                    DialogResult result = MessageBox.Show("URL is already in queue!\nOpen corresponding folder?", "Error", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);
                    if (result == DialogResult.Yes)
                    {
                        string spath = newImageboard.getPath();
                        if (!Directory.Exists(spath))
                        {
                            Directory.CreateDirectory(spath);
                        }
                        Process.Start(spath);
                    }
                }
            }
            else
            {
                MessageBox.Show("Corrupt URL, unsupported website or not a board/thread!");
                edtURL.Text = "";
            }
        }
Beispiel #6
0
        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();
            }
        }
Beispiel #7
0
        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();
            }
        }