Skip to content

Commit

Permalink
fix EstimatedFileCount and ggpk default version
Browse files Browse the repository at this point in the history
  • Loading branch information
Chuanhsing committed Jan 21, 2021
1 parent 8c7e4c0 commit ec37a11
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
10 changes: 5 additions & 5 deletions LibGGPK/GrindingGearsPackageContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
/// </summary>
private const int EstimatedFileCount = 700000;
private const int EstimatedFileCount = 40000;

public bool IsReadOnly { get { return _isReadOnly; } }
private bool _isReadOnly;
Expand Down Expand Up @@ -236,7 +236,7 @@ public void DeserializeRecords(string pathToBin, Action<string> output)
/// </summary>
/// <param name="pathToGgpk">Path to pack file to read</param>
/// <param name="output">Output function</param>
private void ReadRecordOffsets(string pathToGgpk, Action<string> output)
public void ReadRecordOffsets(string pathToGgpk, Action<string> output)
{
var previousPercentComplete = 0.0f;

Expand Down Expand Up @@ -453,7 +453,7 @@ public void Save(string pathToGgpkNew, Action<string> 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);
Expand All @@ -463,7 +463,7 @@ public void Save(string pathToGgpkNew, Action<string> 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<long, long>();
Expand All @@ -479,7 +479,7 @@ public void Save(string pathToGgpkNew, Action<string> output)
writer.Write(data);

fileCopied++;
var percentComplete = fileCopied/_files.Count;
var percentComplete = fileCopied / _files.Count;
if (!(percentComplete - previousPercentComplete >= 0.05f)) return;

if (output != null)
Expand Down
8 changes: 3 additions & 5 deletions LibGGPK/Records/GGPKRecord.cs
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -19,7 +17,7 @@ public sealed class GgpkRecord : BaseRecord
/// </summary>
public long[] RecordOffsets;

public uint Version;
public uint Version = 3;

public GgpkRecord(uint length)
{
Expand Down Expand Up @@ -60,7 +58,7 @@ public override void Write(BinaryWriter bw, Dictionary<long, long> 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);
Expand Down

0 comments on commit ec37a11

Please sign in to comment.