예제 #1
0
        static void Main(string[] args)
        {
            string test = @"C:\Users\dotnet\Downloads\torr.torrent";

            Console.WriteLine("Torrent file path:");
            String torrentfile = test;

            TorrentFile torrent = Bencode.DecodeTorrentFile(torrentfile);

            Console.WriteLine("Info in torrentfile:");
            Console.WriteLine(torrent.Announce);
            foreach (var St in torrent.AnnounceList)
            {
                Console.WriteLine(St.ToString());
            }
            Console.WriteLine(torrent.Comment);
            Console.WriteLine(torrent.CreatedBy);
            Console.WriteLine(torrent.CreationDate);
            Console.WriteLine(torrent.Encoding);

            BDictionary info  = (BDictionary)torrent["info"];
            BList       files = (BList)info["files"];

            foreach (BDictionary v in files)
            {
                BList path = (BList)v["path"];

                Console.WriteLine("Path: {0}, length: {1}", path[0], v["length"]);
            }

            Console.ReadLine();
        }
예제 #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog();

            dialog.Title  = "Open Torrent File";
            dialog.Filter = "Torrent files (*.torrent)|*.torrent";
            if (dialog.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            torrentName = dialog.FileName;
            torrentSize = 0;
            fileList.Clear();

            listBoxInfo.Items.Clear();
            textBox1.Text = torrentName;

            TorrentFile torrent = Bencode.DecodeTorrentFile(torrentName);

            add_info(torrent.Info["name"].ToString());
            if (torrent.Info["source"] != null)
            {
                add_info(torrent.Info["source"].ToString());
            }
            add_info(torrent.Comment);
            add_info(torrent.CreatedBy);
            add_info(torrent.CreationDate);

            fileNum = 0;
            BList files = (BList)torrent.Info["files"];

            foreach (BDictionary file in files)
            {
                //add_info(file["length"].ToString());

                BList  path  = (BList)file["path"];
                string spath = "";
                foreach (BString elem in path)
                {
                    spath += "\\" + elem;
                }
                fileNum++;
                Int64 sz = Int64.Parse(file["length"].ToString());
                torrentSize += sz;
                fileList.Add(spath, sz);
            }
            add_info(fileNum.ToString() + " file(s), " + FormatSize(torrentSize));
        }
예제 #3
0
        public void ReadTorrentFile(string localfile)
        {
            TorrentFile torrent = Bencode.DecodeTorrentFile(localfile);

            Byte[] bytes        = File.ReadAllBytes(localfile);
            String base64string = Convert.ToBase64String(bytes);

            this.MetaInfo = base64string;

            if (torrent.Info.ContainsKey("name"))
            {
                this.TorrentName = ((BString)torrent.Info["name"]).ToString(Encoding.UTF8);
            }

            this.TorrentComment   = torrent.Comment;
            this.TorrentCreatedBy = torrent.CreatedBy;
            this.TorrentDate      = torrent.CreationDate;

            long piecelen = (BNumber)torrent.Info["piece length"];
            //var pieces = (BList)torrent.Info["pieces"];

            ObservableCollection <Model.TorrentFileName> filelist = new ObservableCollection <Model.TorrentFileName>();

            if (torrent.Info.ContainsKey("files"))
            {
                BList files = (BList)torrent.Info["files"];

                foreach (BDictionary file in files)
                {
                    GetTorrentFileList(filelist, file);
                }
            }
            else
            {
                GetTorrentFileList(filelist, torrent.Info);
            }

            this.TorrentFiles = filelist;
            RaisePropertyChanged("SelectedSize");
            RaisePropertyChanged("TotalSize");
        }
예제 #4
0
        public void AddTorrent(string path)
        {
            string ext = Path.GetExtension(path);

            if (!File.Exists(path) || Path.GetExtension(path) != ".torrent")
            {
                Logman.Log("Incorrect torrent file specified. Check the path and extension of the file.", LOG_TYPE.WARNING);
                return;
            }
            TorrentFile torrent    = Bencode.DecodeTorrentFile(path);
            Torrent     newTorrent = new Torrent(torrent.CalculateInfoHash(), Path.GetFileNameWithoutExtension(path), torrent.Announce);

            torrentList.Add(newTorrent);
            newTorrentList.Add(newTorrent);

            Logman.Log("Torrent added to database.");
            Database.Save(torrentList.ToArray());
            if (TorrentUpdateThresholdReached != null)
            {
                TorrentUpdateThresholdReached.Invoke(newTorrentList.ToArray());
            }
        }
예제 #5
0
        public void ReadLocalTorrentFile()
        {
            bool isMultiFile;
            //string file = @"C:\Users\dan.PARADOX\Downloads\ubuntu-14.10-desktop-amd64.iso.torrent";
            string      localfile = @"C:\Users\dan.PARADOX\Downloads\[kat.cr]deadpool.2016.1080p.bluray.x264.dts.jyk.torrent";
            TorrentFile torrent   = Bencode.DecodeTorrentFile(localfile);

            List <string> filelist = new List <string>();

            if (torrent.Info.ContainsKey("files"))
            {
                BList files = (BList)torrent.Info["files"];

                foreach (BDictionary file in files)
                {
                    //http://stackoverflow.com/questions/32067409/decode-bencode-torrent-files

                    // File size in bytes (BNumber has implicit conversion to int and long)
                    int size = (BNumber)file["length"];

                    // List of all parts of the file path. 'dir1/dir2/file.ext' => dir1, dir2 and file.ext
                    BList path = (BList)file["path"];

                    string fullpath = String.Join("|", path);

                    // Last element is the file name
                    BString fileName = (BString)path.Last();

                    // Converts fileName (BString = bytes) to a string
                    string fileNameString = fileName.ToString(Encoding.UTF8);
                }
            }
            else
            {
                filelist.Add(torrent.Info["name"].ToString());
            }
        }