public void LoadDB() { torrents.Clear(); Encoding encode = System.Text.Encoding.GetEncoding("utf-8"); try { StreamReader db = new StreamReader("_database.db", encode); db.ReadLine(); String data = db.ReadToEnd(); db.Close(); data = data.Replace("\r\n", "\n"); String[] lines = data.Split('\n'); for (int i = 0; i < lines.Length; i++) { if (lines[i].Length < 3) //skip empty lines continue; String item = lines[i]; TorrentInfo new_torrent = new TorrentInfo(); String chunk = item.Substring(1, item.IndexOf("\";\"")-1); new_torrent.id = Convert.ToUInt32(chunk); item = item.Substring(item.IndexOf("\";\"") + 2); chunk = item.Substring(1, item.IndexOf("\";\"") - 1); new_torrent.name = chunk; item = item.Substring(item.IndexOf("\";\"") + 2); chunk = item.Substring(1, item.IndexOf("\";\"") - 1); new_torrent.magnet = chunk; item = item.Substring(item.IndexOf("\";\"") + 2); chunk = item.Substring(1, 1); new_torrent.status = Convert.ToInt32(chunk); torrents.Add(new_torrent); } } catch (Exception e) { return; }; }
public void addtorrent(UInt32 id, String name, String magnet, int status) { for (int i = 0; i < torrents.Count; i++) { if (torrents[i].id == id) { torrents.Remove(torrents[i]); break; }; }; String torrentname = name; String magnetlink = magnet; TorrentInfo newitem = new TorrentInfo(); newitem.id = id; if (torrentname == null) torrentname = ""; if (magnetlink == null) magnetlink = ""; newitem.magnet = magnetlink; newitem.name = torrentname; if (((magnetlink.Length == 0) || (torrentname.Length == 0)) && (status == 0)) status = 1; newitem.status = status; torrents.Add(newitem); }