private void CreateTorrentInfo(HdknTorrentManager manager, TorrentInfo info) { info.Data = manager.TorrentData; info.DownloadedBytes = manager.DownloadedBytes; if (manager.HashChecked) { info.FastResumeData = manager.SaveFastResume(); } else { info.FastResumeData = null; } info.InfoHash = manager.InfoHash; info.Label = manager.Label; info.SavePath = manager.SavePath; info.StartTime = manager.StartTime; info.CompletedTime = manager.CompletedTime; // to prevent nesting directories if (manager.Torrent.Files.Length > 1) info.SavePath = Directory.GetParent(manager.SavePath).FullName; info.State = manager.State; info.UploadedBytes = manager.UploadedBytes; // save torrent settings info.ConnectionRetentionFactor = manager.Settings.ConnectionRetentionFactor; info.EnablePeerExchange = manager.Settings.EnablePeerExchange; info.InitialSeedingEnabled = manager.Settings.InitialSeedingEnabled; info.MaxConnections = manager.Settings.MaxConnections; info.MaxDownloadSpeed = manager.Settings.MaxDownloadSpeed; info.MaxUploadSpeed = manager.Settings.MaxUploadSpeed; info.MinimumTimeBetweenReviews = manager.Settings.MinimumTimeBetweenReviews; info.PercentOfMaxRateToSkipReview = manager.Settings.PercentOfMaxRateToSkipReview; info.UploadSlots = manager.Settings.UploadSlots; info.UseDht = manager.Settings.UseDht; }
private HdknTorrentManager RegisterTorrentManager(TorrentManager manager, byte[] data = null) { // register with engine if (_clientEngine.Contains(manager)) return null; _clientEngine.Register(manager); // add to dictionary var hdknManager = new HdknTorrentManager(manager, _kvs, _fs, _mbus) { TorrentData = data }; hdknManager.Load(); _torrents.Add(hdknManager.InfoHash, hdknManager); _mbus.Send<ITorrentAdded>(m => { m.Torrent = hdknManager; }); // Save state whenever adding torrents. SaveState(); return hdknManager; }
private void BringToState(HdknTorrentManager manager, HdknTorrentState state) { switch (state) { case HdknTorrentState.Downloading: case HdknTorrentState.Seeding: manager.Start(); break; case HdknTorrentState.Hashing: manager.HashCheck(false); break; case HdknTorrentState.Paused: manager.Start(); manager.Pause(); break; case HdknTorrentState.Stopped: manager.Stop(); break; } }