Exemplo n.º 1
0
        void HandleShouldAdd(object sender, ShouldAddEventArgs e)
        {
            LoadTorrentDialog dialog = new LoadTorrentDialog(e.Torrent, e.SavePath);
            dialog.AlwaysAsk = interfaceSettings.ShowLoadDialog;

            try
            {
                e.ShouldAdd = dialog.Run () == (int)ResponseType.Ok;
                interfaceSettings.ShowLoadDialog = dialog.AlwaysAsk;
                e.SavePath = dialog.SelectedPath;
            }
            finally
            {
                dialog.Destroy ();
            }
        }
Exemplo n.º 2
0
        public bool addTorrent(string path, bool ask, out string error)
        {
            Torrent torrent;
            error = null;

            if (!Torrent.TryLoad (path, out torrent)) {
                error = _("Invalid torrent selected");
                return false;
            }

            if (Engine.Contains(torrent)) {
                error = _("Torrent has already been added");
                return false;
            }

            string savePath = engine.Settings.SavePath;
            if (ask) {
                EventHandler<ShouldAddEventArgs> h = ShouldAdd;
                if (h != null) {
                    ShouldAddEventArgs e = new ShouldAddEventArgs (torrent, savePath);
                    h (this, e);
                    if (!e.ShouldAdd)
                        return true;
                    savePath = e.SavePath;
                }
            }

            try
            {
                addTorrent (torrent, savePath);
            }
            catch (Exception ex)
            {
                Console.WriteLine (ex);
                error = _("An unexpected error occured while loading the torrent. {0}");
                error = string.Format (error, ex.Message);
                return  false;
            }
            return true;
        }