Example #1
0
        public static TorrentFileInfo GetTorrentFileInfo(BinaryReader binaryReader)
        {
            TorrentFileInfo torrentFileInfo = new TorrentFileInfo();
            char            next            = (char)binaryReader.PeekChar();
            object          fileInfo;

            switch (next)
            {
            case 'i':
                // Integer
                binaryReader.ReadChar();
                fileInfo = Bint(binaryReader); break;

            case 'l':
                // List
                binaryReader.ReadChar();
                fileInfo = Blist(binaryReader); break;

            case 'd':
                // Dictionary
                binaryReader.ReadChar();
                fileInfo = Bdictionary(binaryReader, torrentFileInfo); break;

            case '0':
            case '1':
            case '2':
            case '3':
            case '4':
            case '5':
            case '6':
            case '7':
            case '8':
            case '9':
                fileInfo = Bstring(binaryReader); break;

            default:
                fileInfo = null; break;
            }
            return(torrentFileInfo);
        }
Example #2
0
        public static Dictionary <object, object> Bdictionary(BinaryReader binaryReader, TorrentFileInfo torrentFileInfo)
        {
            Dictionary <object, object> dic = new Dictionary <object, object>();
            char ch;

            while ((ch = (char)binaryReader.PeekChar()) != 'e')
            {
                object Value;
                switch (ch)
                {
                case '0':
                case '1':
                case '2':
                case '3':
                case '4':
                case '5':
                case '6':
                case '7':
                case '8':
                case '9':
                    Value = Bstring(binaryReader); break;

                default:
                    Value = null; break;
                }
                switch (Value)
                {
                case "announce": torrentFileInfo.announce = Bstring(binaryReader); break;

                case "announce-list":
                    torrentFileInfo.announce_list = new List <string>();
                    torrentFileInfo.announce_list = Blist(binaryReader, torrentFileInfo.announce_list); break;

                case "creation date": torrentFileInfo.creation_date = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1)).AddSeconds(Bint(binaryReader)); break;

                case "created by": torrentFileInfo.created_by = Bstring(binaryReader); break;

                case "encoding": torrentFileInfo.encoding = Bstring(binaryReader); break;

                case "conmment": torrentFileInfo.conmment = Bstring(binaryReader); break;

                case "info":
                    torrentFileInfo.info = new TorrentFileInfoDetailinfo();
                    torrentFileInfo.info = Bdictionary(binaryReader, torrentFileInfo.info); break;

                case "publisher": torrentFileInfo.publisher = Bstring(binaryReader); break;

                case "publisher url": torrentFileInfo.publisher_url = Bstring(binaryReader); break;
                }
            }
            binaryReader.ReadChar();
            return(dic);
        }