Beispiel #1
0
        private void LoadState()
        {
            string settings = System.IO.Path.Combine(StoragePath, SettingsFile);

            if (!System.IO.File.Exists(settings))
            {
                return;
            }

            byte[]       buffer = System.IO.File.ReadAllBytes(settings);
            BEncodedList list   = BEncodedValue.Decode <BEncodedList> (buffer);

            List <TorrentData> data = new List <TorrentData>();

            foreach (BEncodedDictionary dict in list)
            {
                TorrentData d = new TorrentData();
                d.Deserialize(dict);
                data.Add(d);
            }

            foreach (TorrentData d in data)
            {
                Console.WriteLine("Reloading: {0}", d.TorrentPath);

                TorrentAdapter torrent = torrents[LoadTorrent(d.TorrentPath)];
                TorrentManager manager = new TorrentManager(torrent.Torrent, d.SavePath, d.Settings, d.FastResume);

                Load(torrent, d.Settings, manager);
            }
        }
Beispiel #2
0
        public void SaveState()
        {
            BEncodedList list = new BEncodedList();

            foreach (TorrentManagerAdapter adapter in this.downloaders.Values)
            {
                TorrentData d = new TorrentData();
                d.FastResume  = adapter.Manager.SaveFastResume();
                d.SavePath    = adapter.Manager.SavePath;
                d.Settings    = adapter.Manager.Settings;
                d.TorrentPath = adapter.Manager.Torrent.TorrentPath;
                list.Add(d.Serialize());
            }

            System.IO.File.WriteAllBytes(System.IO.Path.Combine(StoragePath, SettingsFile), list.Encode());
        }
Beispiel #3
0
        private void LoadState()
        {
            string settings = System.IO.Path.Combine (StoragePath, SettingsFile);
            if (!System.IO.File.Exists (settings))
                return;

            byte[] buffer = System.IO.File.ReadAllBytes (settings);
            BEncodedList list = BEncodedValue.Decode<BEncodedList> (buffer);

            List<TorrentData> data = new List<TorrentData>();
            foreach (BEncodedDictionary dict in list)
            {
                TorrentData d = new TorrentData();
                d.Deserialize(dict);
                data.Add(d);
            }

            foreach (TorrentData d in data)
            {
                Console.WriteLine ("Reloading: {0}", d.TorrentPath);

                TorrentAdapter torrent = torrents[LoadTorrent(d.TorrentPath)];
                TorrentManager manager = new TorrentManager(torrent.Torrent, d.SavePath, d.Settings, d.FastResume);

                Load (torrent, d.Settings, manager);
            }
        }
Beispiel #4
0
        public void SaveState()
        {
            BEncodedList list = new BEncodedList ();
            foreach (TorrentManagerAdapter adapter in this.downloaders.Values)
            {
                TorrentData d = new TorrentData ();
                d.FastResume = adapter.Manager.SaveFastResume ();
                d.SavePath = adapter.Manager.SavePath;
                d.Settings = adapter.Manager.Settings;
                d.TorrentPath = adapter.Manager.Torrent.TorrentPath;
                list.Add (d.Serialize ());
            }

            System.IO.File.WriteAllBytes (System.IO.Path.Combine (StoragePath, SettingsFile), list.Encode ());
        }