コード例 #1
0
        public TorrentDownload DownloadTorrent(string name)
        {
            Trace.TraceInformation("starting download {0}", name);
            var down = new TorrentDownload(name);

            plasmaService.DownloadFileAsync(name, down);
            return(down);
        }
コード例 #2
0
        public TorrentDownload DownloadTorrent(string name)
        {
            Trace.TraceInformation("starting download {0}", name);
            var down = new TorrentDownload(name);


            Task.Factory.StartNew(() => {
                DownloadFileResult e;
                try {
                    e = plasmaService.DownloadFile(name);
                } catch (Exception ex) {
                    Trace.TraceError("Error downloading {0}: {1}", down.Name, ex);
                    down.Finish(false);
                    return;
                }

                if (e == null || e.links == null || e.torrent == null || e.links.Count == 0)
                {
                    Trace.TraceWarning("Cannot download {0}, not registered or has no links", down.Name);
                    down.Finish(false);
                    return;
                }

                try
                {
                    var tor       = Torrent.Load(e.torrent);
                    down.FileName = tor.Files[0].Path;
                    //down.Length = (int)tor.Size;
                    down.Length         = 1;//workaround for progress bars
                    down.TypeOfResource = e.resourceType == ResourceType.Map ? DownloadType.MAP : DownloadType.MOD;


                    // just 1 link, use normal webdownload
                    if (e.links.Count() == 1 || e.links.Count(x => !x.Contains("springfiles.com")) == 1) // mirrors or mirros without jobjol = 1
                    {
                        var wd = new WebFileDownload(e.links[0], GetDestPath(down.TypeOfResource, down.FileName), incomingFolder);
                        down.AddNeededDownload(wd);
                        down.Finish(true); // mark current torrent dl as complete - will wait for dependency
                        wd.Start();        // start dependent download
                    }
                    else
                    {
                        var wd = new WebMultiDownload(e.links.Shuffle(), GetDestPath(down.TypeOfResource, down.FileName), incomingFolder, tor);
                        down.AddNeededDownload(wd);
                        down.Finish(true); // mark current torrent dl as complete - will wait for dependency
                        wd.Start();        // start dependent download
                    }
                    foreach (var dependency in e.dependencies)
                    {
                        var dep = plasmaDownloader.GetResource(DownloadType.UNKNOWN, dependency);
                        if (dep != null)
                        {
                            down.AddNeededDownload(dep);
                        }
                    }
                }
                catch (Exception ex)
                {
                    Trace.TraceError("downloading torrent failed {0}", ex);
                    down.Finish(false);
                }
            });


            return(down);
        }
コード例 #3
0
        public TorrentDownload DownloadTorrent(string name)
        {
            Trace.TraceInformation("starting download {0}", name);
            var down = new TorrentDownload(name);


            Task.Factory.StartNew(() => {
                DownloadFileResult e;
                try {
                    e = plasmaService.DownloadFile(name);
                } catch (Exception ex) {
                    Trace.TraceError("Error downloading {0}: {1}", down.Name, ex);
                    down.Finish(false);
                    return;
                }

                if (e == null || e.links == null || e.torrent == null || e.links.Count == 0)
                {
                    Trace.TraceWarning("Cannot download {0}, not registered or has no links", down.Name);
                    down.Finish(false);
                    return;
                }

                try
                {
                    var tor       = Torrent.Load(e.torrent);
                    down.FileName = tor.Files[0].Path;
                    //down.Length = (int)tor.Size;
                    down.Length         = 1;//workaround for progress bars
                    down.TypeOfResource = e.resourceType == ResourceType.Map ? DownloadType.MAP : DownloadType.RAPID;


                    foreach (var dependency in e.dependencies)
                    {
                        var dep = plasmaDownloader.GetResource(DownloadType.NOTKNOWN, dependency);
                        if (dep != null)
                        {
                            down.AddNeededDownload(dep);
                        }
                    }


                    if (!plasmaDownloader.ForceMapRedownload)
                    {
                        var defPath = Utils.MakePath(plasmaDownloader.SpringPaths.WritableDirectory,
                                                     down.TypeOfResource == DownloadType.MAP ? "maps" : "games",
                                                     down.FileName);

                        if (File.Exists(defPath))
                        {
                            var exTor = CreateTorrentFromFile(defPath);
                            if (exTor != null && exTor.InfoHash.Equals(tor.InfoHash))
                            {
                                down.Finish(true);
                                return; // done
                            }
                        }
                    }

                    var wd = new WebMultiDownload(e.links.Shuffle(), GetDestPath(down.TypeOfResource, down.FileName), incomingFolder, tor);
                    down.AddNeededDownload(wd);
                    down.Finish(true); // mark current torrent dl as complete - will wait for dependency
                    wd.Start();        // start dependent download
                }
                catch (Exception ex)
                {
                    Trace.TraceError("downloading torrent failed {0}", ex);
                    down.Finish(false);
                }
            });


            return(down);
        }
コード例 #4
0
        public TorrentDownload DownloadTorrent(string name)
        {
            Trace.TraceInformation("starting download {0}", name);
            var down = new TorrentDownload(name);


            Task.Factory.StartNew(() => {
                DownloadFileResult e;
                try {
                    e = plasmaService.DownloadFile(name);
                } catch (Exception ex) {
                    Trace.TraceError("Error downloading {0}: {1}", down.Name, ex);
                    down.Finish(false);
                    return;
                }

                if (e == null || e.links == null || e.torrent == null || e.links.Count == 0)
                {
                    Trace.TraceWarning("Cannot download {0}, not registered or has no links", down.Name);
                    down.Finish(false);
                    return;
                }

                try
                {
                    var tor = Torrent.Load(e.torrent);
                    down.FileName = tor.Files[0].Path;
                    //down.Length = (int)tor.Size;
                    down.Length = 1;//workaround for progress bars
                    down.TypeOfResource = e.resourceType == ResourceType.Map ? DownloadType.MAP : DownloadType.RAPID;


                    foreach (var dependency in e.dependencies)
                    {
                        var dep = plasmaDownloader.GetResource(DownloadType.NOTKNOWN, dependency);
                        if (dep != null) down.AddNeededDownload(dep);
                    }


                    var defPath = Utils.MakePath(plasmaDownloader.SpringPaths.WritableDirectory, down.TypeOfResource == DownloadType.MAP ? "maps" : "games", down.FileName);
                    
                    if (File.Exists(defPath))
                    {
                        var exTor = CreateTorrentFromFile(defPath);
                        if (exTor != null && exTor.InfoHash.Equals(tor.InfoHash))
                        {
                            down.Finish(true);
                            return; // done
                        }
                    }


                    // just 1 link, use normal webdownload
                    if (e.links.Count() == 1 || e.links.Count(x => !x.Contains("springfiles.com")) == 1) // mirrors or mirros without jobjol = 1
                    {
                        var wd = new WebFileDownload(e.links[0], GetDestPath(down.TypeOfResource, down.FileName), incomingFolder);
                        down.AddNeededDownload(wd);
                        down.Finish(true); // mark current torrent dl as complete - will wait for dependency
                        wd.Start(); // start dependent download
                    }
                    else
                    {
                        var wd = new WebMultiDownload(e.links.Shuffle(), GetDestPath(down.TypeOfResource, down.FileName), incomingFolder, tor);
                        down.AddNeededDownload(wd);
                        down.Finish(true); // mark current torrent dl as complete - will wait for dependency
                        wd.Start(); // start dependent download
                    }


                }
                catch (Exception ex)
                {
                    Trace.TraceError("downloading torrent failed {0}", ex);
                    down.Finish(false);
                }

            });
            
            
            return down;
        }