Skip to content

Commit

Permalink
2.0.1: Switch to FileStream, AutoTOC go brrrrr
Browse files Browse the repository at this point in the history
  • Loading branch information
henbagle committed May 14, 2021
1 parent 77693e7 commit 278cf1f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
13 changes: 10 additions & 3 deletions AutoTOC/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
Expand All @@ -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();
}

Expand Down
2 changes: 1 addition & 1 deletion AutoTOC/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]

0 comments on commit 278cf1f

Please sign in to comment.