示例#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);
            }
        }
示例#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());
        }
示例#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);
            }
        }
示例#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 ());
        }