public void Hash()
 {
     if (TM.State != TorrentState.Hashing)
     {
         TM.HashCheck(true);
     }
 }
 private void OnRecheckItemActivated(object sender, EventArgs args)
 {
     try{
         if (selectedTorrent.State != TorrentState.Stopped)
         {
             selectedTorrent.Stop();
         }
         selectedTorrent.HashCheck(true);
     } catch (Exception) {
         logger.Warn("Unable to force re-hash on " + selectedTorrent.Torrent.Name);
     }
 }
Beispiel #3
0
        public override void ViewDidDisappear(bool animated)
        {
            base.ViewDidDisappear(animated);

            Manager.Singletone.updateActions.Remove(action);
            foreach (var file in manager.Torrent.Files)
            {
                bool check = false;
                if (file.fileRemoved)
                {
                    check            = true;
                    file.fileRemoved = false;
                }
                if (check && manager.State == TorrentState.Stopped)
                {
                    manager.HashCheck(true);
                }
            }
        }
Beispiel #4
0
        void RestoreTorrents()
        {
            SaveClass save = null;

            if (File.Exists(DatFile))
            {
                try {
                    save = Utils.DeSerializeObject <SaveClass>(DatFile);
                } catch (System.Xml.XmlException e) {
                    Console.WriteLine(e.StackTrace);
                    File.Move(DatFile, Path.Combine(ConfigFolder, "dat1.itor"));
                    var controller = UIAlertController.Create("Config file loading error", "There was a problem loading the configuration file, a copy will be created under the \"dat1\" name, and a new one will be created", UIAlertControllerStyle.Alert);

                    var topWindow = new UIWindow(UIScreen.MainScreen.Bounds);
                    topWindow.RootViewController = new UIViewController();
                    topWindow.WindowLevel        = UIWindowLevel.Alert + 1;

                    var ok = UIAlertAction.Create("OK", UIAlertActionStyle.Cancel, delegate {
                        topWindow.Hidden = true;
                        topWindow        = null;
                    });
                    controller.AddAction(ok);

                    topWindow.MakeKeyAndVisible();
                    topWindow.RootViewController.PresentViewController(controller, true, null);
                }
            }
            if (File.Exists(Path.Combine(ConfigFolder, "_temp.torrent")))
            {
                File.Delete(Path.Combine(ConfigFolder, "_temp.torrent"));
            }

            if (Directory.Exists(ConfigFolder))
            {
                foreach (var file in Directory.GetFiles(ConfigFolder))
                {
                    new Thread(() => {
                        if (file.EndsWith(".torrent", StringComparison.Ordinal))
                        {
                            Torrent torrent        = Torrent.Load(file);
                            TorrentManager manager = new TorrentManager(torrent, RootFolder, new TorrentSettings());

                            engine.Register(manager);
                            manager.TorrentStateChanged += (sender, e) => {
                                Manager.OnFinishLoading(manager, e);
                            };

                            if (save != null && save.data.ContainsKey(torrent.InfoHash.ToHex()))
                            {
                                if (save.data[torrent.InfoHash.ToHex()].resume != null)
                                {
                                    manager.LoadFastResume(new FastResume(BEncodedValue.Decode(save.data[torrent.InfoHash.ToHex()].resume) as BEncodedDictionary));
                                    manager.dateOfAdded  = save.data[torrent.InfoHash.ToHex()].date;
                                    manager.allowSeeding = save.data[torrent.InfoHash.ToHex()].allowSeeding;
                                    switch (save.data[torrent.InfoHash.ToHex()].state)
                                    {
                                    case TorrentState.Downloading:
                                        manager.Start();
                                        break;

                                    default:
                                        manager.Stop();
                                        break;
                                    }
                                }
                                foreach (var _file in torrent.Files)
                                {
                                    if (save.data[torrent.InfoHash.ToHex()].downloading.ContainsKey(_file.Path))
                                    {
                                        _file.Priority = save.data[torrent.InfoHash.ToHex()].downloading[_file.Path] ? Priority.Highest : Priority.DoNotDownload;
                                    }
                                }
                            }
                            else
                            {
                                foreach (var _file in torrent.Files)
                                {
                                    _file.Priority = Priority.DoNotDownload;
                                }
                                manager.HashCheck(true);
                            }

                            PiecePicker picker = new StandardPicker();
                            picker             = new PriorityPicker(picker);
                            manager.ChangePicker(picker);

                            foreach (TrackerTier tier in manager.TrackerManager)
                            {
                                foreach (Tracker t in tier.Trackers)
                                {
                                    t.AnnounceComplete += delegate(object sender, AnnounceResponseEventArgs e) {
                                        Console.WriteLine(string.Format("{0}!: {1}", e.Successful, e.Tracker));
                                    };
                                }
                            }

                            managers.Add(manager);

                            UIApplication.SharedApplication.InvokeOnMainThread(() => {
                                restoreAction?.Invoke();
                            });
                        }
                    }).Start();
                }
            }
        }
 public void HashCheck(bool autoStart)
 {
     manager.HashCheck(autoStart);
 }
Beispiel #6
0
 public void HashCheck()
 {
     Active = true;
     manager.HashCheck(false);
 }
        /// <summary>
        /// Add torrent file
        /// </summary>
        /// <param name="fileName">Torrent file path</param>
        /// <param name="settings">Torrent settings</param>
        /// <param name="savePath">Save path</param>
        public void Add(string fileName, TorrentSettings settings, string savePath)
        {
            GuiGeneralSettings genSettings = settingsBase.LoadSettings<GuiGeneralSettings>("General Settings");
            string newPath = string.Empty;
            Torrent torrent = null;

            if (File.Exists(fileName))
            {
                newPath = Path.Combine(genSettings.TorrentsPath, Path.GetFileName(fileName));
                if (newPath != fileName)
                {
                    if (File.Exists(newPath))
                    {
                        MessageBox.Show("This torrent already exist in torrent folder.");
                        return;
                    }
                    File.Copy(fileName, newPath);
                }
                torrent = Torrent.Load(newPath);
            }
            else
            {
                // Try as url
                if (fileName.IndexOf("//") > 0)
                {
                    newPath = Path.Combine(genSettings.TorrentsPath, fileName.Substring(fileName.LastIndexOf("/") + 1));
                    if (File.Exists(newPath))
                    {
                        MessageBox.Show("This torrent already exist in torrent folder.");
                        return;
                    }
                    torrent = Torrent.Load(new Uri(fileName), newPath);
                }
                else
                {
                    MessageBox.Show("This is not a valid torrent path or url.");
                    return;
                }
            }

            ListViewItem item = new ListViewItem(Path.GetFileName(newPath));

			ListViewItem.ListViewSubItem subitem = item.SubItems[0];
			subitem.Name = "colName";

			subitem = new ListViewItem.ListViewSubItem();
			subitem.Name = "colSize";
			item.SubItems.Add(subitem);

			subitem = new ListViewItem.ListViewSubItem();
			subitem.Name = "colStatus";
			item.SubItems.Add(subitem);

			subitem = new ListViewItem.ListViewSubItem();
			subitem.Name = "colSeeds";
			item.SubItems.Add(subitem);

			subitem = new ListViewItem.ListViewSubItem();
			subitem.Name = "colLeeches";
			item.SubItems.Add(subitem);

			subitem = new ListViewItem.ListViewSubItem();
			subitem.Name = "colDownSpeed";
			item.SubItems.Add(subitem);

			subitem = new ListViewItem.ListViewSubItem();
			subitem.Name = "colUpSpeed";
			item.SubItems.Add(subitem);

			subitem = new ListViewItem.ListViewSubItem();
			subitem.Name = "colDownloaded";
			item.SubItems.Add(subitem);

			subitem = new ListViewItem.ListViewSubItem();
			subitem.Name = "colUploaded";
			item.SubItems.Add(subitem);

            subitem = new ListViewItem.ListViewSubItem();
            subitem.Name = "colRatio";
            item.SubItems.Add(subitem);

            subitem = new ListViewItem.ListViewSubItem();
            subitem.Name = "colRemaining";
            item.SubItems.Add(subitem);

			mainForm.TorrentsView.Items.Add(item);
            
            // Add torrent to manager
            TorrentManager manager = new TorrentManager(torrent, savePath, settings);
            clientEngine.Register(manager);
            ImageListView.ImageListViewSubItem sitem = new ImageListView.ImageListViewSubItem(new TorrentProgressBar(manager));
            sitem.Name = "colProgress";
            item.SubItems.Insert(2,sitem);
            itemToTorrent.Add(item, manager);
            manager.PieceHashed += new EventHandler<PieceHashedEventArgs>(torrent_PieceHashed);
            manager.PeersFound += OnTorrentChange;
            manager.TorrentStateChanged += OnTorrentStateChange;
            manager.FileManager.BlockWritten += new EventHandler<BlockEventArgs>(FileManager_BlockWritten);
            manager.PieceManager.BlockReceived += new EventHandler<BlockEventArgs>(PieceManager_BlockReceived);
            manager.PieceManager.BlockRequestCancelled += new EventHandler<BlockEventArgs>(PieceManager_BlockRequestCancelled);
            manager.PieceManager.BlockRequested += new EventHandler<BlockEventArgs>(PieceManager_BlockRequested);
            manager.PeerConnected += OnPeerConnected;
            manager.PeerDisconnected += OnPeerDisconnected;
            item.SubItems["colSize"].Text = FormatSizeValue(manager.Torrent.Size);
            item.SubItems["colName"].Text = manager.Torrent.Name;
            manager.HashCheck(false);
        }