/// <summary> /// Saves a wz file to the disk, AKA repacking. /// </summary> /// <param name="path">Path to the output wz file</param> public void SaveToDisk(string path) { _wzIv = WzTool.GetIvByMapleVersion(MapleVersion); CreateVersionHash(); WzDirectory.SetHash(_versionHash); var tempFile = Path.GetFileNameWithoutExtension(path) + ".TEMP"; File.Create(tempFile).Close(); WzDirectory.GenerateDataFile(tempFile); WzTool.StringCache.Clear(); var totalLen = WzDirectory.GetImgOffsets(WzDirectory.GetOffsets(Header.FStart + 2)); var wzWriter = new WzBinaryWriter(File.Create(path), _wzIv) { Hash = _versionHash }; Header.FSize = totalLen - Header.FStart; for (var i = 0; i < 4; i++) { { wzWriter.Write((byte)Header.Ident[i]); } } wzWriter.Write((long)Header.FSize); wzWriter.Write(Header.FStart); wzWriter.WriteNullTerminatedString(Header.Copyright); var extraHeaderLength = Header.FStart - wzWriter.BaseStream.Position; if (extraHeaderLength > 0) { wzWriter.Write(new byte[(int)extraHeaderLength]); } wzWriter.Write(_version); wzWriter.Header = Header; WzDirectory.SaveDirectory(wzWriter); wzWriter.StringCache.Clear(); var fs = File.OpenRead(tempFile); WzDirectory.SaveImages(wzWriter, fs); fs.Close(); File.Delete(tempFile); wzWriter.StringCache.Clear(); wzWriter.Close(); GC.Collect(); GC.WaitForPendingFinalizers(); }