Exemplo n.º 1
0
        public void Initialize()
        {
            Directory.CreateDirectory(State.StateSaveDirectory);
            Directory.CreateDirectory(State.TorrentsStateSaveDirectory);

            this.LibtorrentSession = new Ragnar.Session();

            this.LibtorrentSession.SetAlertMask(Alerts_Mask);

            this.LibtorrentSession.ListenOn(App.Settings.ListeningPort, App.Settings.ListeningPort);

            if (App.Settings.EnableDHT)
                this.LibtorrentSession.StartDht();

            if (App.Settings.EnableLSD)
                this.LibtorrentSession.StartLsd();

            if (App.Settings.EnableNAT_PMP)
                this.LibtorrentSession.StartNatPmp();

            if (App.Settings.Enable_UPNP)
                this.LibtorrentSession.StartUpnp();

            this.LibTorrentAlerts = new LibTorrentAlertsWatcher(this.LibtorrentSession);

            this.LibTorrentAlerts.ResumeDataArrived += LibTorrentAlerts_ResumeDataArrived;
            this.LibTorrentAlerts.TorrentAdded += LibTorrentAlerts_TorrentAdded;
            this.LibTorrentAlerts.TorrentStateChanged += LibTorrentAlerts_TorrentStateChanged;
            this.LibTorrentAlerts.TorrentStatsUpdated += LibTorrentAlerts_TorrentStatsUpdated;
            this.LibTorrentAlerts.TorrentFinished += LibTorrentAlerts_TorrentFinished;
            this.LibTorrentAlerts.MetadataReceived += LibTorrentAlerts_MetadataReceived;
            //this.LibTorrentAlerts.TorrentNetworkStatisticsUpdated += LibTorrentAlerts_TorrentNetworkStatisticsUpdated;

            if (File.Exists(LtSessionFilePath))
            {
                this.LibtorrentSession.LoadState(File.ReadAllBytes(LtSessionFilePath));

                foreach (string file in Directory.GetFiles(State.TorrentsStateSaveDirectory, "*.torrent"))
                {
                    Ragnar.AddTorrentParams para = new Ragnar.AddTorrentParams();

                    para.TorrentInfo = new Ragnar.TorrentInfo(File.ReadAllBytes(file));

                    string tjson_file = Path.ChangeExtension(file, "tjson");

                    if (File.Exists(tjson_file))
                    {
                        using (var reader = File.OpenText(tjson_file))
                        {
                            JsonObject data = JsonConvert.Import<JsonObject>(reader);
                            para.SavePath = Convert.ToString(data["SavePath"]);
                        }
                    }
                    else
                    {
                        para.SavePath = App.Settings.DefaultDownloadPath;
                    }

                    string resume_file = Path.ChangeExtension(file, "resume");

                    if (File.Exists(resume_file))
                    {
                        // Loading the resume data will load all torrents settings,
                        // with the exception of byteflood settings {RatioLimit, RanCommand, PickedMovieData, ...}
                        // See TorrentInfo.LoadMiscSettings() method
                        para.ResumeData = File.ReadAllBytes(resume_file);
                    }

                    this.LibtorrentSession.AsyncAddTorrent(para);
                }
            }

            CheckByteFloodAssociation();

            listener = new Listener(this);
            listener.State = this;
        }
Exemplo n.º 2
0
        public void Initialize()
        {
            Directory.CreateDirectory(State.StateSaveDirectory);
            Directory.CreateDirectory(State.TorrentsStateSaveDirectory);

            this.LibtorrentSession = new Ragnar.Session();

            this.LibtorrentSession.SetAlertMask(Alerts_Mask);

            this.LibtorrentSession.ListenOn(App.Settings.ListeningPort, App.Settings.ListeningPort);

            if (App.Settings.EnableDHT)
            {
                this.LibtorrentSession.StartDht();
            }

            if (App.Settings.EnableLSD)
            {
                this.LibtorrentSession.StartLsd();
            }

            if (App.Settings.EnableNAT_PMP)
            {
                this.LibtorrentSession.StartNatPmp();
            }

            if (App.Settings.Enable_UPNP)
            {
                this.LibtorrentSession.StartUpnp();
            }

            this.LibTorrentAlerts = new LibTorrentAlertsWatcher(this.LibtorrentSession);

            this.LibTorrentAlerts.ResumeDataArrived   += LibTorrentAlerts_ResumeDataArrived;
            this.LibTorrentAlerts.TorrentAdded        += LibTorrentAlerts_TorrentAdded;
            this.LibTorrentAlerts.TorrentStateChanged += LibTorrentAlerts_TorrentStateChanged;
            this.LibTorrentAlerts.TorrentStatsUpdated += LibTorrentAlerts_TorrentStatsUpdated;
            this.LibTorrentAlerts.TorrentFinished     += LibTorrentAlerts_TorrentFinished;
            this.LibTorrentAlerts.MetadataReceived    += LibTorrentAlerts_MetadataReceived;
            //this.LibTorrentAlerts.TorrentNetworkStatisticsUpdated += LibTorrentAlerts_TorrentNetworkStatisticsUpdated;

            if (File.Exists(LtSessionFilePath))
            {
                this.LibtorrentSession.LoadState(File.ReadAllBytes(LtSessionFilePath));

                foreach (string file in Directory.GetFiles(State.TorrentsStateSaveDirectory, "*.torrent"))
                {
                    Ragnar.AddTorrentParams para = new Ragnar.AddTorrentParams();

                    para.TorrentInfo = new Ragnar.TorrentInfo(File.ReadAllBytes(file));

                    string tjson_file = Path.ChangeExtension(file, "tjson");

                    if (File.Exists(tjson_file))
                    {
                        using (var reader = File.OpenText(tjson_file))
                        {
                            JsonObject data = JsonConvert.Import <JsonObject>(reader);
                            para.SavePath = Convert.ToString(data["SavePath"]);
                        }
                    }
                    else
                    {
                        para.SavePath = App.Settings.DefaultDownloadPath;
                    }

                    string resume_file = Path.ChangeExtension(file, "resume");

                    if (File.Exists(resume_file))
                    {
                        // Loading the resume data will load all torrents settings,
                        // with the exception of byteflood settings {RatioLimit, RanCommand, PickedMovieData, ...}
                        // See TorrentInfo.LoadMiscSettings() method
                        para.ResumeData = File.ReadAllBytes(resume_file);
                    }

                    this.LibtorrentSession.AsyncAddTorrent(para);
                }
            }

            CheckByteFloodAssociation();

            listener       = new Listener(this);
            listener.State = this;
        }