Load and save the decompressed file size table.
This commit is contained in:
parent
84c643d667
commit
79c2d3b384
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -47,6 +47,7 @@ namespace FirstPlugin
|
||||
public List<FileInfo> files = new List<FileInfo>();
|
||||
public Dictionary<long, byte[]> SavedDataEntries = new Dictionary<long, byte[]>();
|
||||
public Dictionary<long, string> SavedStringEntries = new Dictionary<long, string>();
|
||||
public Dictionary<string, uint> ArchiveSizes = new Dictionary<string, uint>();
|
||||
|
||||
public uint Alignment;
|
||||
public static readonly uint DefaultAlignment = 4;
|
||||
@ -84,17 +85,10 @@ namespace FirstPlugin
|
||||
|
||||
if (Runtime.TpGamePath != "" && Directory.Exists(Runtime.TpGamePath))
|
||||
{
|
||||
string TablePath = $"{Runtime.TpGamePath}/FileSizeList.txt";
|
||||
|
||||
TPFileSizeTable.SetTables(this);
|
||||
}
|
||||
|
||||
string TablePath = $"{Runtime.TpGamePath}/FileSizeList.txt";
|
||||
|
||||
TPFileSizeTable table = new TPFileSizeTable();
|
||||
table.Read(new FileReader($"{Runtime.TpGamePath}/FileSizeList.txt"));
|
||||
|
||||
var tableSave = new MemoryStream();
|
||||
table.Write(new FileWriter(tableSave));
|
||||
File.WriteAllBytes($"{Runtime.TpGamePath}/FileSizeListTEST.txt", tableSave.ToArray());
|
||||
}
|
||||
|
||||
private void Save(object sender, EventArgs args)
|
||||
@ -114,6 +108,8 @@ namespace FirstPlugin
|
||||
|
||||
private void SaveFile(FileWriter writer)
|
||||
{
|
||||
ArchiveSizes.Clear();
|
||||
|
||||
writer.ByteOrder = Syroot.BinaryData.ByteOrder.BigEndian;
|
||||
|
||||
writer.WriteSignature("TMPK");
|
||||
@ -127,6 +123,8 @@ namespace FirstPlugin
|
||||
writer.Write(uint.MaxValue);
|
||||
writer.Write(files[i].Data.Length); //Padding
|
||||
writer.Write(0); //Padding
|
||||
|
||||
ArchiveSizes.Add(files[i].Text, (uint)files[i].Data.Length);
|
||||
}
|
||||
for (int i = 0; i < files.Count; i++)
|
||||
{
|
||||
|
@ -1,39 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Switch_Toolbox.Library.IO;
|
||||
using Syroot.BinaryData;
|
||||
|
||||
namespace FirstPlugin
|
||||
{
|
||||
public class TPFileSizeTable
|
||||
{
|
||||
public Dictionary<string, uint> FileSizes = new Dictionary<string, uint>();
|
||||
|
||||
public void Read(FileReader reader)
|
||||
{
|
||||
while (reader.Position < reader.BaseStream.Length)
|
||||
{
|
||||
string FileName = reader.ReadString(BinaryStringFormat.ZeroTerminated);
|
||||
string Size = reader.ReadString(BinaryStringFormat.ZeroTerminated);
|
||||
|
||||
uint sizeNum = 0;
|
||||
uint.TryParse(Size, out sizeNum);
|
||||
FileSizes.Add(FileName, sizeNum);
|
||||
|
||||
Console.WriteLine(FileName + " " + Size);
|
||||
}
|
||||
}
|
||||
|
||||
public void Write(FileWriter writer)
|
||||
{
|
||||
foreach (var file in FileSizes)
|
||||
{
|
||||
writer.Write(file.Key, BinaryStringFormat.ZeroTerminated);
|
||||
writer.Write(file.Value.ToString(), BinaryStringFormat.ZeroTerminated);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
114
Switch_FileFormatsMain/FileFormats/SizeTables/TPFileSizeTable.cs
Normal file
114
Switch_FileFormatsMain/FileFormats/SizeTables/TPFileSizeTable.cs
Normal file
@ -0,0 +1,114 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Switch_Toolbox.Library.IO;
|
||||
using Switch_Toolbox.Library;
|
||||
using Syroot.BinaryData;
|
||||
|
||||
namespace FirstPlugin
|
||||
{
|
||||
public class TPFileSizeTable
|
||||
{
|
||||
public class DecompressedTableEntry
|
||||
{
|
||||
public string FilePath { get; set; }
|
||||
public uint Size { get; set; }
|
||||
public uint Size2 { get; set; }
|
||||
public string Precentage { get; set; }
|
||||
}
|
||||
|
||||
public bool UseCompressedSizes = false;
|
||||
|
||||
public Dictionary<string, uint> FileSizes = new Dictionary<string, uint>();
|
||||
public Dictionary<string, DecompressedTableEntry> DecompressedFileSizes = new Dictionary<string, DecompressedTableEntry>();
|
||||
|
||||
public static void SetTables(IFileFormat FileFormat)
|
||||
{
|
||||
//Read the tables
|
||||
TPFileSizeTable CompressedFileTbl = new TPFileSizeTable();
|
||||
CompressedFileTbl.ReadCompressedTable(new FileReader($"{Runtime.TpGamePath}/FileSizeList.txt"));
|
||||
|
||||
TPFileSizeTable DecompressedFileTbl = new TPFileSizeTable();
|
||||
DecompressedFileTbl.ReadDecompressedTable(new FileReader($"{Runtime.TpGamePath}/DecompressedSizeList.txt"));
|
||||
|
||||
// var tableSave = new MemoryStream();
|
||||
// CompressedFileTbl.Write(new FileWriter(tableSave));
|
||||
// File.WriteAllBytes($"{Runtime.TpGamePath}/FileSizeListTEST.txt", tableSave.ToArray());
|
||||
// bool IsSuccess = CompressedFileTbl.TrySetSize(FileName, IFileInfo.CompressedSize, IFileInfo.DecompressedSize, ArchiveSizes);
|
||||
|
||||
}
|
||||
|
||||
public void ReadCompressedTable(FileReader reader)
|
||||
{
|
||||
while (reader.Position < reader.BaseStream.Length)
|
||||
{
|
||||
string FileName = reader.ReadString(BinaryStringFormat.ZeroTerminated);
|
||||
string Size = reader.ReadString(BinaryStringFormat.ZeroTerminated);
|
||||
|
||||
uint sizeNum = 0;
|
||||
uint.TryParse(Size, out sizeNum);
|
||||
FileSizes.Add(FileName, sizeNum);
|
||||
}
|
||||
}
|
||||
|
||||
public void ReadDecompressedTable(FileReader reader)
|
||||
{
|
||||
while (reader.Position < reader.BaseStream.Length)
|
||||
{
|
||||
var entry = new DecompressedTableEntry();
|
||||
string Size = reader.ReadString(BinaryStringFormat.ZeroTerminated);
|
||||
string Size2 = reader.ReadString(BinaryStringFormat.ZeroTerminated);
|
||||
entry.Precentage = reader.ReadString(BinaryStringFormat.ZeroTerminated);
|
||||
entry.FilePath = reader.ReadString(BinaryStringFormat.ZeroTerminated);
|
||||
|
||||
uint sizeNum = 0;
|
||||
uint sizeNum2 = 0;
|
||||
|
||||
uint.TryParse(Size, out sizeNum);
|
||||
uint.TryParse(Size2, out sizeNum2);
|
||||
|
||||
entry.Size = sizeNum;
|
||||
entry.Size2 = sizeNum2;
|
||||
|
||||
DecompressedFileSizes.Add(entry.FilePath, entry);
|
||||
}
|
||||
}
|
||||
|
||||
public bool TrySetSize(string Path, uint DecompSize, uint CompSize, Dictionary<string, uint> ArchiveFiles = null)
|
||||
{
|
||||
string RelativePath = Path.Replace(Runtime.TpGamePath, "");
|
||||
|
||||
if (FileSizes.ContainsKey(RelativePath))
|
||||
{
|
||||
if (UseCompressedSizes)
|
||||
FileSizes[RelativePath] = CompSize;
|
||||
else
|
||||
FileSizes[RelativePath] = DecompSize;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void WriteCompressedTable(FileWriter writer)
|
||||
{
|
||||
foreach (var file in FileSizes)
|
||||
{
|
||||
writer.Write(file.Key, BinaryStringFormat.ZeroTerminated);
|
||||
writer.Write(file.Value.ToString(), BinaryStringFormat.ZeroTerminated);
|
||||
}
|
||||
}
|
||||
|
||||
public void WriteDecompressedTable(FileWriter writer)
|
||||
{
|
||||
foreach (var file in DecompressedFileSizes.Values)
|
||||
{
|
||||
writer.Write(file.Size.ToString(), BinaryStringFormat.ZeroTerminated);
|
||||
writer.Write(file.Size2.ToString(), BinaryStringFormat.ZeroTerminated);
|
||||
writer.Write(file.Precentage.ToString(), BinaryStringFormat.ZeroTerminated);
|
||||
writer.Write(file.FilePath.ToString(), BinaryStringFormat.ZeroTerminated);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -212,7 +212,7 @@
|
||||
<Compile Include="FileFormats\Audio\Archives\BFGRP.cs" />
|
||||
<Compile Include="FileFormats\Hashes\SAHT.cs" />
|
||||
<Compile Include="FileFormats\Shader\SHARCFBNX.cs" />
|
||||
<Compile Include="FileFormats\SizeLists\TPFileSizeTable.cs" />
|
||||
<Compile Include="FileFormats\SizeTables\TPFileSizeTable.cs" />
|
||||
<Compile Include="FileFormats\Texture\BFLIM.cs" />
|
||||
<Compile Include="FileFormats\Layout\BFLAN.cs" />
|
||||
<Compile Include="FileFormats\Layout\BFLYT.cs" />
|
||||
|
Binary file not shown.
@ -1 +1 @@
|
||||
3b03006b7b29c0b0451fd6a30a22d1a6e904e30f
|
||||
0c66796b6bfc37f42e1fe84c64d916d889aa3eee
|
||||
|
Binary file not shown.
@ -56,7 +56,6 @@ namespace Switch_Toolbox.Library.IO
|
||||
if (CompType != CompressionType.None)
|
||||
CompressedFileSize = (uint)fileReader.BaseStream.Length;
|
||||
|
||||
|
||||
if (fileReader.BaseStream.Length <= 4)
|
||||
{
|
||||
fileReader.Close();
|
||||
|
Loading…
x
Reference in New Issue
Block a user