From 278cf1f7d635f14aef0c97d3cb950fe388d2ce89 Mon Sep 17 00:00:00 2001 From: HenBagle Date: Fri, 14 May 2021 19:48:00 -0400 Subject: [PATCH] 2.0.1: Switch to FileStream, AutoTOC go brrrrr --- AutoTOC/Program.cs | 13 ++++++++++--- AutoTOC/Properties/AssemblyInfo.cs | 2 +- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/AutoTOC/Program.cs b/AutoTOC/Program.cs index 7048dc6..df953c0 100644 --- a/AutoTOC/Program.cs +++ b/AutoTOC/Program.cs @@ -150,6 +150,7 @@ static void PrepareToCreateTOC(string consoletocFile) static void CreateTOC(string basepath, string tocFile, string[] files) { FileStream fs = new FileStream(tocFile, FileMode.Create, FileAccess.Write); + long selfSizePosition = -1; fs.Write(BitConverter.GetBytes((int)0x3AB70C13), 0, 4); fs.Write(BitConverter.GetBytes((int)0x0), 0, 4); fs.Write(BitConverter.GetBytes((int)0x1), 0, 4); @@ -165,12 +166,11 @@ static void CreateTOC(string basepath, string tocFile, string[] files) fs.Write(BitConverter.GetBytes((ushort)0), 0, 2);//Flags if (Path.GetFileName(file).ToLower() != "pcconsoletoc.bin") { - FileStream fs2 = new FileStream(basepath + file, FileMode.Open, FileAccess.Read); - fs.Write(BitConverter.GetBytes((int)fs2.Length), 0, 4);//Filesize - fs2.Close(); + fs.Write(BitConverter.GetBytes((int) (new FileInfo(basepath + file).Length)), 0, 4);//Filesize } else { + selfSizePosition = fs.Position; fs.Write(BitConverter.GetBytes((int)0), 0, 4);//Filesize } fs.Write(BitConverter.GetBytes((int)0x0), 0, 4);//SHA1 @@ -182,6 +182,13 @@ static void CreateTOC(string basepath, string tocFile, string[] files) fs.WriteByte((byte)c); fs.WriteByte(0); } + if (selfSizePosition >= 0) + { + // Write the size of our own TOC. This ensures TOC appears up to date when we try to update it later + // (important for DLC TOCs) + fs.Seek(selfSizePosition, SeekOrigin.Begin); + fs.Write(BitConverter.GetBytes((int)fs.Length), 0, 4); + } fs.Close(); } diff --git a/AutoTOC/Properties/AssemblyInfo.cs b/AutoTOC/Properties/AssemblyInfo.cs index 0a9841a..c7bff01 100644 --- a/AutoTOC/Properties/AssemblyInfo.cs +++ b/AutoTOC/Properties/AssemblyInfo.cs @@ -33,4 +33,4 @@ // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyVersion("2.0.*")] -[assembly: AssemblyFileVersion("2.0.0.0")] +[assembly: AssemblyFileVersion("2.0.1.0")]