示例#1
0
        public void Dispose()
        {
            var directory = new GGHash(new Dictionary <string, GGValue> {
                { "files", _gFiles }
            });

            byte[] directoryData;
            var    dirOffset = (int)_bw.BaseStream.Position;

            using (var ms = new MemoryStream())
            {
                using (var gbw = new GGBinaryWriter(new BinaryWriter(ms)))
                {
                    directory.WriteTo(gbw);
                }
                directoryData = ms.ToArray();
                GGBinaryReader.EncodeUnbreakableXor(directoryData);
            }
            _bw.Write(directoryData);
            var size = directoryData.Length;

            _bw.BaseStream.Position = 0;
            _bw.Write(dirOffset);
            _bw.Write(size);
        }
示例#2
0
        public GGPackWriter WriteFile(string path)
        {
            var filename = Path.GetFileName(path);

            using (var fs = File.OpenRead(path))
            {
                if (string.Equals(Path.GetExtension(filename), ".nut", StringComparison.OrdinalIgnoreCase))
                {
                    filename = Path.ChangeExtension(filename, ".bnut");
                }
                var hash = new GGHash
                {
                    { "filename", new GGLiteral(filename) },
                    { "offset", new GGLiteral(_offset) },
                    { "size", new GGLiteral((int)fs.Length) },
                };
                _gFiles.Add(hash);
                _offset += (int)fs.Length;
            }

            var data = File.ReadAllBytes(path);

            if (string.Equals(Path.GetExtension(filename), ".nut", StringComparison.OrdinalIgnoreCase))
            {
                GGPack.DecryptBnut(data);
            }
            else if (string.Equals(Path.GetExtension(filename), ".wimpy", StringComparison.OrdinalIgnoreCase))
            {
                GGHash hash;
                using (var ms = new MemoryStream(data))
                {
                    var parser = new GGParser(ms);
                    hash = parser.ParseHash();
                }
                using (var ms = new MemoryStream())
                {
                    using (var writer = new GGBinaryWriter(new BinaryWriter(ms)))
                    {
                        hash.WriteTo(writer);
                    }
                    data = ms.ToArray();
                }
            }
            GGBinaryReader.EncodeUnbreakableXor(data);
            _bw.Write(data);

            return(this);
        }