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); }
public GGPack(GGHash directory, Stream stream) { _directory = directory; _stream = stream; var files = _directory["files"] as GGArray; _entries = files.Cast <GGHash>() .Select(o => new GGPackEntry((string)o["filename"], (int)o["offset"], (int)o["size"])) .ToList(); }
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); }
public bool Equals(GGHash other) { if (Pairs.Count != other.Pairs.Count) { return(false); } foreach (var pair in Pairs) { GGValue value; if (!other.Pairs.TryGetValue(pair.Key, out value)) { return(false); } if (!Equals(pair.Value, value)) { return(false); } } return(true); }