Example #1
0
        private void QuickAddClicked(object sender, RoutedEventArgs e)
        {
            IgnoredClipboardValue = Clipboard.GetText();
            CheckMagnetLinks();

            var link = new MagnetLink(IgnoredClipboardValue);
            var name = HttpUtility.HtmlDecode(HttpUtility.UrlDecode(link.Name));

            var path = Path.Combine(SettingsManager.DefaultDownloadLocation,
                                    ClientManager.CleanFileName(name));

            AddTorrent(link, path);
        }
Example #2
0
        private void AddClicked(object sender, RoutedEventArgs e)
        {
            if (customDestinationTextBox.IsFocused)
            {
                return;
            }
            try
            {
                string name;
                if (magnetLinkRadioButton.IsChecked.Value)
                {
                    MagnetLink = new MagnetLink(magnetLinkTextBox.Text);
                    name       = HttpUtility.HtmlDecode(HttpUtility.UrlDecode(MagnetLink.Name));
                }
                else
                {
                    Torrent = Torrent.Load(torrentFileTextBox.Text);
                    name    = Torrent.Name;
                }
                if (defaultDestinationRadioButton.IsChecked.Value)
                {
                    DestinationPath = DefaultLocation;
                }
                else if (recentRadioButton.IsChecked.Value)
                {
                    var recent = recentItemsComboBox.SelectedItem as FolderBrowserItem;
                    DestinationPath = recent.FullPath;
                }
                else
                {
                    DestinationPath = customDestinationTextBox.Text;
                }

                Settings.RecentDownloadLocations = new[] { DestinationPath }
                .Concat(Settings.RecentDownloadLocations.Where(r => r != DestinationPath)).ToArray();

                DestinationPath = Path.Combine(DestinationPath, ClientManager.CleanFileName(name));
            }
            catch
            {
                MessageBox.Show("Unable to load this torrent.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            DialogResult = true;
            Close();
        }
Example #3
0
        public PeriodicTorrent AddTorrent(MagnetLink link, string path, bool suppressMessages = false)
        {
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
            var name  = HttpUtility.HtmlDecode(HttpUtility.UrlDecode(link.Name));
            var cache = Path.Combine(
                SettingsManager.TorrentCachePath,
                ClientManager.CleanFileName(name) + ".torrent");

            for (int i = 0; i < link.AnnounceUrls.Count; i++)
            {
                link.AnnounceUrls[i] = HttpUtility.UrlDecode(HttpUtility.UrlDecode(link.AnnounceUrls[i]));
            }
            var wrapper = new TorrentWrapper(link, path, new TorrentSettings(), cache);

            if (Client.Torrents.Any(t => t.Torrent.InfoHash == wrapper.InfoHash))
            {
                if (!suppressMessages)
                {
                    MessageBox.Show(name + " has already been added.", "Error");
                }
                return(null);
            }
            var periodic = Client.AddTorrent(wrapper);

            periodic.CacheFilePath = cache;
            periodic.UpdateInfo();
            var serializer = new JsonSerializer();

            using (var writer = new StreamWriter(Path.Combine(SettingsManager.TorrentCachePath,
                                                              Path.GetFileNameWithoutExtension(periodic.CacheFilePath) + ".info")))
                serializer.Serialize(new JsonTextWriter(writer), periodic.TorrentInfo);
            return(periodic);
        }
Example #4
0
        public void HandleArguments(string[] args)
        {
            if (args.Length == 0)
            {
                Dispatcher.BeginInvoke(new Action(() =>
                {
                    Visibility = Visibility.Visible;
                    Activate();
                }));
                return;
            }
            if (args[0] == "--minimized")
            {
                Visibility    = Visibility.Hidden;
                ShowInTaskbar = false;
                ShowActivated = false;
                WindowStyle   = WindowStyle.None;
                Width         = Height = 0;
                return;
            }
            Dispatcher.BeginInvoke(new Action(() =>
            {
                try
                {
                    var magnetLink = new MagnetLink(args[0]);
                    if (SettingsManager.PromptForSaveOnShellLinks)
                    {
                        var window        = new AddTorrentWindow(SettingsManager);
                        window.MagnetLink = magnetLink;
                        if (window.ShowDialog().Value)
                        {
                            if (window.IsMagnet)
                            {
                                AddTorrent(window.MagnetLink, window.DestinationPath);
                            }
                            else
                            {
                                AddTorrent(window.Torrent, window.DestinationPath);
                            }

                            SaveSettings();

                            Visibility = Visibility.Visible;
                            Activate();
                            FlashWindow(new WindowInteropHelper(this).Handle, true);
                        }
                    }
                    else
                    {
                        var path = Path.Combine(SettingsManager.DefaultDownloadLocation, ClientManager.CleanFileName(magnetLink.Name));
                        if (!Directory.Exists(path))
                        {
                            Directory.CreateDirectory(path);
                        }
                        AddTorrent(magnetLink, path, true);
                    }
                }
                catch
                {
                    try
                    {
                        var torrent = Torrent.Load(args[0]);
                        if (SettingsManager.PromptForSaveOnShellLinks)
                        {
                            var window = new AddTorrentWindow(SettingsManager, args[0]);
                            if (window.ShowDialog().Value)
                            {
                                if (window.IsMagnet)
                                {
                                    AddTorrent(window.MagnetLink, window.DestinationPath);
                                }
                                else
                                {
                                    AddTorrent(window.Torrent, window.DestinationPath);
                                }

                                SaveSettings();

                                Visibility = Visibility.Visible;
                                Activate();
                                FlashWindow(new WindowInteropHelper(this).Handle, true);
                            }
                        }
                        else
                        {
                            var path = Path.Combine(SettingsManager.DefaultDownloadLocation, ClientManager.CleanFileName(torrent.Name));
                            if (!Directory.Exists(path))
                            {
                                Directory.CreateDirectory(path);
                            }
                            AddTorrent(torrent, path, true);

                            Visibility = Visibility.Visible;
                            Activate();
                            FlashWindow(new WindowInteropHelper(this).Handle, true);
                        }
                    }
                    catch { }
                }
            }));
        }