상속: System.ComponentModel.BackgroundWorker
예제 #1
0
파일: MainWindow.cs 프로젝트: joslinm/CSL
        public MainWindow()
        {
            InitializeComponent();
            this.ResizeRedraw = true;
            this.MainWindow_Resize(new object(), new EventArgs()); //Force a resize to make things look nice

            this.torrentsTableTableAdapter.Fill(this.dataset.TorrentsTable);
            this.moviesTableTableAdapter.Fill(this.dataset.MoviesTable);
            this.othersTableTableAdapter.Fill(this.dataset.OthersTable);

            //Allow another class to handle the deleting/handling of the datagridviews to keep this class slimmer
            dgvh = new DataGridViewHandler(ref torrentsTableDataGridView, ref torrentsTableBindingSource,
                ref moviesTableDataGridView, ref moviesTableBindingSource,
                ref othersTableDataGridView, ref othersTableBindingSource);
            data = new TorrentDataHandler(ref dataset, ref torrentsTableTableAdapter);

            timer.Interval = (double)SettingsHandler.GetAutoHandleTime();
            if (timer.Interval < (1000*10))
            {
                SettingsHandler.SetAutoHandleTime(10000);
                timer.Interval = 10000;
            }
            timer.Elapsed += new System.Timers.ElapsedEventHandler(timer_Elapsed);

            tb.RunWorkerCompleted += new RunWorkerCompletedEventHandler(BuildWorkerCompleted);
            tb.ProgressChanged += new ProgressChangedEventHandler(ProgressChanged);

            if (SettingsHandler.GetAutoHandleBool())
                timer.Start();

            HideSent = (HideSentTorrentsCheckBox.Checked) ? true : false;

            Arrow.Visible = false;
            StatusLabel.Visible = false;
            ArrowText.Visible = false;
            notifyIcon.Visible = false;

            try
            {
                if (System.Deployment.Application.ApplicationDeployment.IsNetworkDeployed)
                {
                    System.Deployment.Application.ApplicationDeployment ad =
                    System.Deployment.Application.ApplicationDeployment.CurrentDeployment;
                    string version = ad.CurrentVersion.ToString();

                    if (SettingsHandler.GetCurrentVersion().CompareTo(version) < 0)
                    {
                        UpdatedInformationWindow uw = new UpdatedInformationWindow();
                        uw.ShowDialog();
                        SettingsHandler.SetCurrentVersion(version);
                    }
                }
            }
            catch (Exception) { }

            test();
        }
예제 #2
0
        public void Build(object files)
        {
            TorrentDataHandler data = new TorrentDataHandler();
            List<Torrent> torrents = new List<Torrent>();
            List<FileInfo> items = null;
            Torrent torrent;
            try { items = (List<FileInfo>)files; }
            catch { DirectoryHandler.LogError("Fatal Error converting object files to items in TorrentBuilder.Build");}

            information[14] = null;
            int filescount = items.Count;
            double progress = 0;
            double count = 0;

            foreach(FileInfo item in items)
            {
                string birth = GetTorrentBirth(item);
                if (birth == null)
                {
                    string savefolder = null;
                    string announce = null;

                    try
                    {
                        object torrentdata = BEncoding.Decode(item);
                        savefolder = (string)(((ListDictionary)((ListDictionary)torrentdata)["info"])["name"]); //Torrentdata is a LD containing LD, which contains name
                        announce = (string)(((ListDictionary)torrentdata)["announce"]);
                        announce = announce.Replace("http://", "");
                        announce = announce.Substring(0, announce.IndexOf(":"));
                    }
                    catch { savefolder = item.Name; }
                    information[12] = (announce == null) ? "???" : announce;
                    information[11] = item.Name;
                    information[10] = item.FullName;
                    information[13] = SettingsHandler.GetOtherDownloadDirectory() + savefolder;
                    torrent = new Torrent(information);
                    torrent.SetPath(DirectoryHandler.MoveTorrentFile(torrent));
                    data.AddOtherTorrent(torrent);
                }
                else if (birth == "ptp")
                {
                    ProcessMovieTorrent(item, birth);
                    Movie tm = new Movie(information);
                    tm.SetPath(DirectoryHandler.MoveTorrentFile(tm));
                    data.AddMovieTorrent(tm);
                }
                else if (birth.Equals("waffles") || birth.Equals("what"))
                {
                    ProcessMusicTorrent(item, birth);

                    if (information[14] != "true")
                    {
                        if (SettingsHandler.GetDownloadFormatExists(information[2]))
                        {
                            torrent = VerifyMusicTorrent();
                            torrents.Add(torrent);
                            torrent.SetPath(DirectoryHandler.MoveTorrentFile(torrent));
                            data.AddTorrent(torrent);
                        }
                    }
                }
                //Clear out information for this run to avoid misinformation on the next run
                for (int b = 0; b < information.Length; b++)
                    information[b] = null;

                progress = (++count / filescount) * 100;

                if (progress <= 100 && progress >= 0)
                    this.ReportProgress((int)progress);
            }

            ew.ClearApplyToAll();
        }