Ejemplo n.º 1
0
        override public bool ReadMod()
        {
            tModInfo info = new tModInfo();

            using (FileStream fileStream = File.OpenRead(this.path))
            {
                BinaryReader binaryReader = new BinaryReader(fileStream);
                if (Encoding.ASCII.GetString(binaryReader.ReadBytes(4)) != "TMOD")
                {
                    return(false);
                }

                info.modloaderversion = new Version(binaryReader.ReadString());
                info.modhash          = binaryReader.ReadBytes(20);
                info.modsignature     = binaryReader.ReadBytes(256);
                fileStream.Seek(4, SeekOrigin.Current);

                fileStream.CopyTo(this.tempfile);
                this.tempfile.Seek(0, SeekOrigin.Begin);
                BinaryReader tempFileBinaryReader = new BinaryReader(this.tempfile);
                info.modname = tempFileBinaryReader.ReadString();
                Console.WriteLine(info.modname);
                info.modversion = new Version(tempFileBinaryReader.ReadString());
                info.filecount  = tempFileBinaryReader.ReadInt32();
                int WTF = 0;
                IDictionary <string, tModFileInfo> wtfDict = new Dictionary <string, tModFileInfo>();
                for (int index = 0; index < info.filecount; index++)
                {
                    tModFileInfo file = new tModFileInfo();
                    string       path = tempFileBinaryReader.ReadString().Replace("\\", "/");
                    file.filesize      = tempFileBinaryReader.ReadInt32();
                    file.filestart     = WTF;
                    file.compressedlen = tempFileBinaryReader.ReadInt32();
                    WTF += file.compressedlen;
                    wtfDict.Add(path, file);
                }
                int datastart = (int)this.tempfile.Position;
                foreach (string fileName in wtfDict.Keys)
                {
                    tModFileInfo file = wtfDict[fileName];
                    file.filestart += datastart;
                    this.files.Add(fileName, file);
                }
                this.info = info;
                return(true);
            }
        }
Ejemplo n.º 2
0
        public bool ReadMod()
        {
            tModInfo info = new tModInfo();

            using (FileStream fileStream = File.OpenRead(this.path))
            {
                BinaryReader binaryReader = new BinaryReader(fileStream);
                if (Encoding.ASCII.GetString(binaryReader.ReadBytes(4)) != "TMOD")
                {
                    return(false);
                }

                info.modloaderversion = binaryReader.ReadString();
                info.modhash          = binaryReader.ReadBytes(20);
                info.modsignature     = binaryReader.ReadBytes(256);

                fileStream.Seek(4, SeekOrigin.Current);

                DeflateStream inflateStream = new DeflateStream(fileStream, CompressionMode.Decompress);
                inflateStream.CopyTo(this.tempfile);
                inflateStream.Close();
                this.tempfile.Seek(0, SeekOrigin.Begin);
                BinaryReader tempFileBinaryReader = new BinaryReader(this.tempfile);

                info.modname    = tempFileBinaryReader.ReadString();
                info.modversion = tempFileBinaryReader.ReadString();
                info.filecount  = tempFileBinaryReader.ReadInt32();
                for (int index = 0; index < info.filecount; index++)
                {
                    tModFileInfo file = new tModFileInfo();
                    string       path = tempFileBinaryReader.ReadString().Replace("\\", "/");
                    file.filesize  = tempFileBinaryReader.ReadInt32();
                    file.filestart = this.tempfile.Position;
                    this.tempfile.Seek(file.filesize, SeekOrigin.Current);
                    this.files.Add(path, file);
                }
                this.info = info;
                return(true);
            }
        }