Esempio n. 1
0
        /// <summary>
        /// 下载种子链接文件
        /// </summary>
        /// <param name="torrent">种子文件</param>
        /// <param name="fileName">输出文件名</param>
        /// <param name="dir">下载目录</param>
        /// <param name="taskOptions">下载任务选项</param>
        /// <returns>成功返回任务标识符,失败返回空</returns>
        public string AddTorrent(string torrent, string fileName = "", string dir = "", List <Dictionary <string, string> > taskOptions = null)
        {
            try
            {
                string autoSaveFileID = "";
                string gid            = Aria2cWarpper.AddTorrent(ref autoSaveFileID, torrent, fileName, dir, taskOptions);
                if (!string.IsNullOrWhiteSpace(gid))
                {
                    Aria2cTask task = Aria2cWarpper.TellStatus(gid);
                    OnStart?.Invoke(this, new Aria2cTaskEvent(task));
                    AddDownTask(task);

                    if (autoSaveFileID != "")
                    {
                        gidAndTorrentOrMeta4Map.Add(gid, autoSaveFileID + ".torrent");
                    }
                }
                return(gid);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                return(string.Empty);
            }
        }
Esempio n. 2
0
 /// <summary>
 /// 下载种子链接文件
 /// </summary>
 /// <param name="torrent">种子文件</param>
 /// <param name="fileName">输出文件名</param>
 /// <param name="dir">下载目录</param>
 /// <returns>成功返回任务标识符,失败返回空</returns>
 public string AddTorrent(string torrent, string fileName = "", string dir = "")
 {
     try
     {
         string gid = Aria2cWarpper.AddTorrent(torrent, fileName, dir);
         if (!string.IsNullOrWhiteSpace(gid))
         {
             Aria2cTask task = Aria2cWarpper.TellStatus(gid);
             OnStart?.Invoke(this, new Aria2cTaskEvent(task));
             AddDownTask(task);
         }
         return(gid);
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex);
         return(string.Empty);
     }
 }