Example #1
0
        private Torrent(AddTorrentParams addParams)
        {
            TorrentFileName = addParams.Filename;
            Url             = addParams.Url;
            DownloadFolder  = addParams.SaveFolder;

            fastResumeDir      = Path.Combine(appDataFolder, ".resume");
            torrentDir         = Path.Combine(appDataFolder, ".torrents");
            activeTorrentsFile = Path.Combine(appDataFolder, ".download");
            LoadTorrentState(ref addParams);

            active = true;
        }
Example #2
0
        private void LoadTorrentState(ref AddTorrentParams p)
        {
            if (IsEmpty || p.TorrentInfo == null)
            {
                return;
            }
            string file = Path.Combine(fastResumeDir, p.TorrentInfo.Name + ".fastresume");

            if (File.Exists(file))
            {
                p.ResumeData = File.ReadAllBytes(file);
            }
        }
Example #3
0
        public static Torrent Create(AddTorrentParams addParams, Session session)
        {
            Torrent torrent = new Torrent(addParams, session);

            Task.Run(delegate
            {
                while (torrent.active)
                {
                    torrent.UpdateProperties();
                    Thread.Sleep(1000);
                }
            });
            return(torrent);
        }
Example #4
0
 private Torrent(AddTorrentParams addParams, Session session)
 {
     fastResumeDir      = Path.Combine(appDataFolder, ".resume");
     torrentDir         = Path.Combine(appDataFolder, ".torrents");
     activeTorrentsFile = Path.Combine(appDataFolder, ".download");
     LoadTorrentState(ref addParams);
     handle = session.AddTorrent(addParams);
     handle.SequentialDownload = true;
     handle.AutoManaged        = false;
     handle.FlushCache();
     this.session = session;
     Url          = addParams.Url;
     active       = true;
 }
Example #5
0
        public static async Task <Torrent> Create(AddTorrentParams addParams)
        {
            Torrent torrent = new Torrent(addParams);
            await torrent.StartAsync();

            Task.Run(delegate
            {
                while (torrent.active)
                {
                    torrent.UpdateProperties();
                    Thread.Sleep(1000);
                }
            });
            return(torrent);
        }
Example #6
0
        public static Torrent CreateFromSavedData(dynamic torrent, Session session)
        {
            AddTorrentParams addParams = new AddTorrentParams
            {
                SavePath = string.IsNullOrEmpty((string)torrent.Path) ? Properties.Settings.Default.Location : (string)torrent.Path
            };

            if (string.IsNullOrEmpty((string)torrent.TorrentFileName))
            {
                if (string.IsNullOrEmpty((string)torrent.Url))
                {
                    return(null);
                }
                else
                {
                    addParams.Url = (string)torrent.Url;
                }
            }
            else
            {
                if (File.Exists(Path.Combine(appDataFolder, ".torrents", (string)torrent.TorrentFileName)))
                {
                    addParams.TorrentInfo = new TorrentInfo(Path.Combine(appDataFolder, ".torrents", (string)torrent.TorrentFileName));
                }
                else
                {
                    return(null);
                }
            }
            var result = Create(addParams, session);

            result.Url             = (string)torrent.Url;
            result.TorrentFileName = Path.Combine(appDataFolder, ".torrents", (string)torrent.TorrentFileName);
            if (torrent.Status == "Pause")
            {
                result.handle.Pause();
            }
            return(result);
        }
Example #7
0
        public static async Task <Torrent> CreateFromSavedData(dynamic torrent)
        {
            AddTorrentParams addParams = new AddTorrentParams
            {
                SaveFolder = string.IsNullOrEmpty((string)torrent.Path) ? Properties.Settings.Default.Location : (string)torrent.Path
            };

            if (string.IsNullOrEmpty((string)torrent.TorrentFileName))
            {
                if (string.IsNullOrEmpty((string)torrent.Url))
                {
                    return(null);
                }
                else
                {
                    addParams.Url = (string)torrent.Url;
                }
            }
            else
            {
                if (File.Exists(Path.Combine(appDataFolder, ".torrents", (string)torrent.TorrentFileName)))
                {
                    addParams.Filename = Path.Combine(appDataFolder, ".torrents", (string)torrent.TorrentFileName);
                }
                else
                {
                    return(null);
                }
            }
            var result = await Create(addParams);

            if (torrent.Status == "Pause")
            {
                //result.manager.Pause();
            }
            return(result);
        }