From ec37a118b615008536a868ac641c1c4926aa2028 Mon Sep 17 00:00:00 2001 From: chuanhsing Date: Thu, 21 Jan 2021 15:41:59 +0800 Subject: [PATCH] fix EstimatedFileCount and ggpk default version --- LibGGPK/GrindingGearsPackageContainer.cs | 10 +++++----- LibGGPK/Records/GGPKRecord.cs | 8 +++----- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/LibGGPK/GrindingGearsPackageContainer.cs b/LibGGPK/GrindingGearsPackageContainer.cs index 6b728e5..8e9f18d 100644 --- a/LibGGPK/GrindingGearsPackageContainer.cs +++ b/LibGGPK/GrindingGearsPackageContainer.cs @@ -29,7 +29,7 @@ public class GrindingGearsPackageContainer /// An estimation of the number of records in the Contents.GGPK file. This is only /// used to inform the users of the parsing progress. /// - private const int EstimatedFileCount = 700000; + private const int EstimatedFileCount = 40000; public bool IsReadOnly { get { return _isReadOnly; } } private bool _isReadOnly; @@ -236,7 +236,7 @@ public void DeserializeRecords(string pathToBin, Action output) /// /// Path to pack file to read /// Output function - private void ReadRecordOffsets(string pathToGgpk, Action output) + public void ReadRecordOffsets(string pathToGgpk, Action output) { var previousPercentComplete = 0.0f; @@ -453,7 +453,7 @@ public void Save(string pathToGgpkNew, Action output) FileStream readStream; FileStream writeStream; using (readStream = File.OpenRead(_pathToGppk)) - using (writeStream = File.Open(pathToGgpkNew, FileMode.Truncate, FileAccess.ReadWrite)) + using (writeStream = File.OpenWrite(pathToGgpkNew)) { var reader = new BinaryReader(readStream); var writer = new BinaryWriter(writeStream); @@ -463,7 +463,7 @@ public void Save(string pathToGgpkNew, Action output) throw new Exception("First record isn't GGPK record"); // Skip GGPK record for now - writer.Seek((int) ggpkRecord.Length, SeekOrigin.Begin); + writer.Seek((int)ggpkRecord.Length, SeekOrigin.Begin); // recursively write files and folders records var changedOffsets = new Dictionary(); @@ -479,7 +479,7 @@ public void Save(string pathToGgpkNew, Action output) writer.Write(data); fileCopied++; - var percentComplete = fileCopied/_files.Count; + var percentComplete = fileCopied / _files.Count; if (!(percentComplete - previousPercentComplete >= 0.05f)) return; if (output != null) diff --git a/LibGGPK/Records/GGPKRecord.cs b/LibGGPK/Records/GGPKRecord.cs index 6179467..2403c35 100644 --- a/LibGGPK/Records/GGPKRecord.cs +++ b/LibGGPK/Records/GGPKRecord.cs @@ -1,7 +1,5 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.IO; -using System.Linq; using System.Text; namespace LibGGPK.Records @@ -19,7 +17,7 @@ public sealed class GgpkRecord : BaseRecord /// public long[] RecordOffsets; - public uint Version; + public uint Version = 3; public GgpkRecord(uint length) { @@ -60,7 +58,7 @@ public override void Write(BinaryWriter bw, Dictionary changedOffset { bw.Write(Length); // 28 bw.Write(Encoding.ASCII.GetBytes(Tag)); // GGPK - bw.Write(Version); // 2 + bw.Write(Version); var offset = RecordOffsets[0]; bw.Write(changedOffsets.ContainsKey(offset) ? changedOffsets[offset] : offset);