public void Initialize(SettingsManager settingsManager) { SettingsManager = settingsManager; Torrents = new ObservableCollection<PeriodicTorrent>(); Torrents.CollectionChanged += Torrents_CollectionChanged; var port = SettingsManager.IncomingPort; if (SettingsManager.UseRandomPort) port = new Random().Next(1, 65536); var settings = new EngineSettings(SettingsManager.DefaultDownloadLocation, port); settings.PreferEncryption = SettingsManager.EncryptionSettings != EncryptionTypes.PlainText; // Always prefer encryption unless it's disabled settings.AllowedEncryption = SettingsManager.EncryptionSettings; Client = new ClientEngine(settings); Client.ChangeListenEndpoint(new IPEndPoint(IPAddress.Any, port)); if (SettingsManager.EnableDHT) { var listener = new DhtListener(new IPEndPoint(IPAddress.Any, port)); var dht = new DhtEngine(listener); Client.RegisterDht(dht); listener.Start(); if (File.Exists(SettingsManager.DhtCachePath)) dht.Start(File.ReadAllBytes(SettingsManager.DhtCachePath)); else dht.Start(); } SettingsManager.PropertyChanged += SettingsManager_PropertyChanged; }
public AddTorrentWindow(SettingsManager settingsManager, string torrentPath = null) { Settings = settingsManager; InitializeComponent(); foreach (var path in settingsManager.RecentDownloadLocations) recentItemsComboBox.Items.Add(new FolderBrowserItem(path, false)); if (recentItemsComboBox.Items.Count != 0) recentItemsComboBox.SelectedIndex = 0; DefaultLocation = settingsManager.DefaultDownloadLocation; defaultDestinationRadioButton.Content = Path.GetFileName(DefaultLocation) + " (default)"; // Check for auto-population of magnet link if (Clipboard.ContainsText()) { var text = Clipboard.GetText(); if (Uri.IsWellFormedUriString(text, UriKind.Absolute)) { var uri = new Uri(text); if (uri.Scheme == "magnet") { magnetLinkRadioButton.IsChecked = true; magnetLinkTextBox.Text = text; } } } UpdateFileBrower("C:\\"); if (torrentPath != null) { torrentFileRadioButton.IsChecked = true; torrentFileTextBox.Text = torrentPath; } Loaded += AddTorrentWindow_Loaded; }
public PreferencesWindow(SettingsManager manager) { InitializeComponent(); InitializeRegistryBoundItems(); var reader = new StreamReader(Assembly.GetExecutingAssembly().GetManifestResourceStream("Patchy.LICENSE")); licenseText.Text = reader.ReadToEnd(); reader.Close(); Settings = manager; DataContext = Settings; if (Settings.EncryptionSettings == EncryptionTypes.PlainText) encryptionSettingsComboBox.SelectedIndex = 0; else if (Settings.EncryptionSettings == EncryptionTypes.All) encryptionSettingsComboBox.SelectedIndex = 1; else encryptionSettingsComboBox.SelectedIndex = 2; seedingTorrentDoubleClickComboBox.SelectedIndex = (int)Settings.DoubleClickSeeding; downloadingTorrentDoubleClickComboBox.SelectedIndex = (int)Settings.DoubleClickDownloading; foreach (var label in Settings.Labels) { var comboItem = new ComboBoxItem { Content = label.Name, Background = label.Brush, Foreground = label.ForegroundBrush, Tag = label }; rssLabelComboBox.Items.Add(comboItem); } }
private void Initialize() { Client.Initialize(); SettingsManager = new SettingsManager(); SettingsManager.Initialize(); // Load prior session if (File.Exists(SettingsManager.FastResumePath)) { // Load on another thread because it takes some time new Thread(() => { var resume = BEncodedValue.Decode<BEncodedDictionary>( File.ReadAllBytes(SettingsManager.FastResumePath)); var torrents = Directory.GetFiles(SettingsManager.TorrentCachePath, "*.torrent"); foreach (var torrent in torrents) { var path = File.ReadAllText(Path.Combine( SettingsManager.TorrentCachePath, Path.GetFileNameWithoutExtension(torrent)) + ".info"); var wrapper = new TorrentWrapper(Torrent.Load(torrent), path, new TorrentSettings()); PeriodicTorrent periodicTorrent; Dispatcher.BeginInvoke(new Action(() => { if (resume.ContainsKey(wrapper.Torrent.InfoHash.ToHex())) { periodicTorrent = Client.LoadFastResume( new FastResume((BEncodedDictionary)resume[wrapper.Torrent.InfoHash.ToHex()]), wrapper); } else { periodicTorrent = Client.AddTorrent(wrapper); } periodicTorrent.CompletedOnAdd = wrapper.Complete; periodicTorrent.CacheFilePath = torrent; })); } }).Start(); } Timer = new Timer(o => Dispatcher.Invoke(new Action(PeriodicUpdate)), null, 1000, 1000); }
private void Initialize() { AutoWatchers = new List<FileSystemWatcher>(); SettingsManager.Initialize(); SettingsManager = new SettingsManager(); LoadSettings(); Client.Initialize(SettingsManager); foreach (var label in SettingsManager.Labels) AddLabel(label); // Load prior session on another thread because it takes some time Task.Factory.StartNew(() => { BEncodedDictionary resume = null; if (File.Exists(SettingsManager.FastResumePath)) { resume = BEncodedValue.Decode<BEncodedDictionary>( File.ReadAllBytes(SettingsManager.FastResumePath)); File.Delete(SettingsManager.FastResumePath); } var torrents = Directory.GetFiles(SettingsManager.TorrentCachePath, "*.torrent"); var toRemove = new List<string>(Directory.GetFiles(SettingsManager.TorrentCachePath, "*.info")); var serializer = new JsonSerializer(); foreach (var torrent in torrents) { var path = Path.Combine(SettingsManager.TorrentCachePath, Path.GetFileNameWithoutExtension(torrent)) + ".info"; if (toRemove.Contains(path)) toRemove.Remove(path); try { TorrentInfo info; using (var reader = new StreamReader(path)) info = serializer.Deserialize<TorrentInfo>(new JsonTextReader(reader)); var wrapper = new TorrentWrapper(Torrent.Load(torrent), info.Path, new TorrentSettings()); PeriodicTorrent periodicTorrent; if (resume != null && resume.ContainsKey(wrapper.Torrent.InfoHash.ToHex())) { periodicTorrent = Client.LoadFastResume( new FastResume((BEncodedDictionary)resume[wrapper.Torrent.InfoHash.ToHex()]), wrapper); } else periodicTorrent = Client.AddTorrent(wrapper); periodicTorrent.LoadInfo(info); periodicTorrent.CacheFilePath = torrent; } catch { } } // Clean up abandoned .info files foreach (var file in toRemove) File.Delete(file); }); Timer = new Timer(o => Dispatcher.Invoke(new Action(PeriodicUpdate)), null, 1000, 1000); IsIdle = false; if (SettingsManager.AutoUpdate) CheckForUpdates(); }