Exemplo n.º 1
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())
                        {
                            DeadThreadURL      = new UriBuilder(lbThreads.Items[k].ToString()).Uri;
                            string ReturnID    = DeadThreadURL.Segments[3];
                            string ReturnBoard = DeadThreadURL.Segments[1].Replace("/", "");
                            // MessageBox.Show(ReturnID);

                            string deadAction = "";
                            if (YCSettings.Default.threadDeadAction == 1)
                            {
                                deadAction = "\nClick here to copy archive link";
                            }
                            else if (YCSettings.Default.threadDeadAction == 2)
                            {
                                deadAction = "\nClick here to open archive link";
                            }
                            else if (YCSettings.Default.threadDeadAction == 3)
                            {
                                deadAction = "\nClick here to copy original link";
                            }
                            else if (YCSettings.Default.threadDeadAction == 4)
                            {
                                deadAction = "\nClick here to open original link";
                            }
                            else if (YCSettings.Default.threadDeadAction == 5)
                            {
                                deadAction = "\nClick here to copy thread ID";
                            }
                            else if (YCSettings.Default.threadDeadAction == 6)
                            {
                                deadAction = "\nClick here to copy download folder path";
                            }
                            else if (YCSettings.Default.threadDeadAction == 7)
                            {
                                deadAction = "\nClick here to open download folder path";
                            }

                            is404 = true;
                            nfTray.BalloonTipTitle = "Thread 404'd";
                            nfTray.BalloonTipText  = "Thread " + ReturnID.Replace(".html", "") + " on /" + ReturnBoard + "/ has 404'd." + deadAction;
                            nfTray.BalloonTipIcon  = ToolTipIcon.Error;
                            nfTray.Icon            = Properties.Resources.YChanEx404;
                            nfTray.ShowBalloonTip(15000);

                            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) {
                            Debug.Print(exep.ToString());
                        }

                        for (int l = 0; l < Threads.Length; l++)
                        {
                            ImageBoard newImageboard = Controller.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) {
                                    Debug.Print(exp.ToString());
                                    //                                    MessageBox.Show(exp.Message + " k: " + x);
                                }
                            });
                            thrThreads[k].Name = clThreads[k].getURL();
                            thrThreads[k].Start();
                        }
                    }
                    GC.Collect();
                });
                Scanner.Start();
            }
        }
Exemplo n.º 2
0
        private void downloadURL(string url, bool silentDownload)
        {
            if (!Controller.isSupported(url))
            {
                MessageBox.Show("Please enter a supported site URL (Check the Github page for a list)");
                return;
            }

            bool       board         = (tcApp.SelectedIndex == 1);               // Board Tab is open -> board=true; Thread tab -> board=false
            ImageBoard newImageboard = Controller.createNewIMB(url.Trim(), board);

            if (url.StartsWith("fchan.us/"))
            {
                url = url.Replace("fchan.us/", "http://fchan.us/");
            }

            if (newImageboard != null)
            {
                if (isUnique(newImageboard.getURL(), clThreads))
                {
                    if (board)
                    {
                        lbBoards.Items.Add(url);
                        clBoards.Add(newImageboard);
                    }
                    else
                    {
                        lbThreads.Items.Add(url);
                        clThreads.Add(newImageboard);
                        addToHistory(url);
                    }
                }
                else
                {
                    MessageBox.Show("URL is already in queue!");
                    return;
                }
            }
            else
            {
                MessageBox.Show("Corrupt URL, unsupported website or not a board/thread!");
                return;
            }

            if (!board)
            {
                Thread nIMB = new Thread(delegate() { newImageboard.download(); });
                nIMB.Name = newImageboard.getURL();
                thrThreads.Add(nIMB);
                thrThreads[thrThreads.Count - 1].Start();
            }

            if (!scnTimer.Enabled)
            {
                scnTimer.Enabled = true;
            }

            scan(null, null);

            if (YCSettings.Default.saveOnClose)
            {
                Controller.saveURLs(clBoards, clThreads);
            }
        }