Esempio n. 1
0
 public IBDownloadItem(string _url)
 {
     URL        = _url;
     ThreadName = "";
     State      = IBThreadState.PENDING;
 }
Esempio n. 2
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();
            }
        }