public void Save(string path) { using (FileStream fs = new FileStream(path, FileMode.Create, FileAccess.Write)) { using ( GZipStream outputStream = new GZipStream(fs, CompressionMode.Compress, CompressionLevel.Level9)) { outputStream.LastModified = new DateTime(1970, 1, 1); uint crcValue; using (CrcCalculatorStream crc = new CrcCalculatorStream(outputStream, true)) { using (BinaryWriter bw = new BinaryWriter(crc)) { bw.Write(MAGIC); // Magic header bw.Write((byte)IrdVersion); // IrdVersion bit, version 1 ;) 255 versions should be enough byte[] gameIdBuf = Encoding.ASCII.GetBytes(GameID); crc.Write(gameIdBuf, 0, 9); bw.Write(GameName); byte[] update = Encoding.ASCII.GetBytes(UpdateVersion); crc.Write(update, 0, 4); byte[] buf = Encoding.ASCII.GetBytes(GameVersion); byte[] gameVersion = new byte[5]; Array.Copy(buf, 0, gameVersion, 0, buf.Length); // GameVersion can be string.Empty crc.Write(gameVersion, 0, 5); buf = Encoding.ASCII.GetBytes(AppVersion); byte[] appVersion = new byte[5]; Array.Copy(buf, 0, appVersion, 0, buf.Length); // AppVersion can be string.Empty crc.Write(appVersion, 0, 5); Header.Compress(bw); Footer.Compress(bw); // Save the hashes bw.Write((byte)RegionHashes.Count); foreach (byte[] hash in RegionHashes) { bw.Write(hash); } bw.Write(FileHashes.Count); foreach (KeyValuePair <long, byte[]> file in FileHashes) { bw.Write(file.Key); bw.Write(file.Value ?? EMPTY); } bw.Write((UInt16)0); // Extra configurations bw.Write((UInt16)0); // Attachments bw.Write(Data1); bw.Write(Data2); bw.Write(PIC); } crcValue = (uint)crc.Crc; } byte[] crcBuffer = BitConverter.GetBytes(crcValue); outputStream.Write(crcBuffer, 0, 4); Version = IrdVersion; Crc = crcValue; } } }