public BTItem ReadDictionary(FileStream sr) { BTDictionary d = new BTDictionary(); for (;;) { BTItem next = this.ReadNext(sr); if ((next.Type == BTChunk.kListOrDictionaryEnd) || (next.Type == BTChunk.kBTEOF)) return d; if (next.Type != BTChunk.kString) { BTError e = new BTError(); e.Message = "Didn't get string as first of pair in dictionary"; return e; } BTDictionaryItem di = new BTDictionaryItem { Key = ((BTString)next).AsString(), Data = this.ReadNext(sr) }; d.Items.Add(di); } }
public BTItem ReadDictionary(System.IO.FileStream sr) { BTDictionary d = new BTDictionary(); for (;;) { BTItem next = ReadNext(sr); if ((next.Type == BTChunk.kListOrDictionaryEnd) || (next.Type == BTChunk.kBTEOF)) { return(d); } if (next.Type != BTChunk.kString) { BTError e = new BTError(); e.Message = "Didn't get string as first of pair in dictionary"; return(e); } BTDictionaryItem di = new BTDictionaryItem { Key = ((BTString)next).AsString(), Data = ReadNext(sr) }; d.Items.Add(di); } }
private void RefreshResumeDat() { if (!this.CheckResumeDatPath()) { return; } List <string> checkedItems = new List <String>(); foreach (string torrent in this.lbUTTorrents.CheckedItems) { checkedItems.Add(torrent); } this.lbUTTorrents.Items.Clear(); // open resume.dat file, fill checked list box with torrents available to choose from string file = TVSettings.Instance.ResumeDatPath; if (!File.Exists(file)) { return; } BEncodeLoader bel = new BEncodeLoader(); BTFile resumeDat = bel.Load(file); if (resumeDat == null) { return; } BTDictionary dict = resumeDat.GetDict(); for (int i = 0; i < dict.Items.Count; i++) { BTItem it = dict.Items[i]; if (it.Type == BTChunk.kDictionaryItem) { BTDictionaryItem d2 = (BTDictionaryItem)(it); if ((d2.Key != ".fileguard") && (d2.Data.Type == BTChunk.kDictionary)) { this.lbUTTorrents.Items.Add(d2.Key); } } } foreach (string torrent in checkedItems) { for (int i = 0; i < this.lbUTTorrents.Items.Count; i++) { if (this.lbUTTorrents.Items[i].ToString() == torrent) { this.lbUTTorrents.SetItemChecked(i, true); } } } }
private void SetupResumeDats() { List <string> checkedItems = new List <string>(); foreach (string torrent in lbUTTorrents.CheckedItems) { checkedItems.Add(torrent); } lbUTTorrents.Items.Clear(); string resume_dir = Path.Combine(Path.GetDirectoryName(TVSettings.Instance.ResumeDatPath), "resume_dir"); ResumeDats = new Dictionary <string, string>(); string[] files = Directory.GetFiles(resume_dir, "*.dat"); foreach (string file in files) { BEncodeLoader bel = new BEncodeLoader(); BTFile resumeDat = bel.Load(file); if (resumeDat == null) { break; } BTDictionary dict = resumeDat.GetDict(); foreach (BTItem it in dict.Items) { if (it.Type == BTChunk.kDictionaryItem) { BTDictionaryItem d2 = (BTDictionaryItem)(it); if ((d2.Key != ".fileguard") && (d2.Data.Type == BTChunk.kDictionary)) { ResumeDats.Add(Path.GetFileNameWithoutExtension(file), d2.Key); lbUTTorrents.Items.Add(d2.Key); } } } } foreach (string torrent in checkedItems) { for (int i = 0; i < lbUTTorrents.Items.Count; i++) { if (lbUTTorrents.Items[i].ToString() == torrent) { lbUTTorrents.SetItemChecked(i, true); } } } }