diff --git a/.vs/Switch_Toolbox/v15/.suo b/.vs/Switch_Toolbox/v15/.suo index 7ce422d0..4b9a2e61 100644 Binary files a/.vs/Switch_Toolbox/v15/.suo and b/.vs/Switch_Toolbox/v15/.suo differ diff --git a/.vs/Switch_Toolbox/v15/Server/sqlite3/storage.ide b/.vs/Switch_Toolbox/v15/Server/sqlite3/storage.ide index 8f865bb2..e00ebafd 100644 Binary files a/.vs/Switch_Toolbox/v15/Server/sqlite3/storage.ide and b/.vs/Switch_Toolbox/v15/Server/sqlite3/storage.ide differ diff --git a/.vs/Switch_Toolbox/v15/Server/sqlite3/storage.ide-wal b/.vs/Switch_Toolbox/v15/Server/sqlite3/storage.ide-wal index 908df3b3..596ac680 100644 Binary files a/.vs/Switch_Toolbox/v15/Server/sqlite3/storage.ide-wal and b/.vs/Switch_Toolbox/v15/Server/sqlite3/storage.ide-wal differ diff --git a/Switch_FileFormatsMain/obj/Release/DesignTimeResolveAssemblyReferences.cache b/Switch_FileFormatsMain/obj/Release/DesignTimeResolveAssemblyReferences.cache index 575a1e07..4bec992a 100644 Binary files a/Switch_FileFormatsMain/obj/Release/DesignTimeResolveAssemblyReferences.cache and b/Switch_FileFormatsMain/obj/Release/DesignTimeResolveAssemblyReferences.cache differ diff --git a/Switch_FileFormatsMain/obj/Release/Switch_FileFormatsMain.csprojAssemblyReference.cache b/Switch_FileFormatsMain/obj/Release/Switch_FileFormatsMain.csprojAssemblyReference.cache index bb3bfc31..e7581a30 100644 Binary files a/Switch_FileFormatsMain/obj/Release/Switch_FileFormatsMain.csprojAssemblyReference.cache and b/Switch_FileFormatsMain/obj/Release/Switch_FileFormatsMain.csprojAssemblyReference.cache differ diff --git a/Switch_Toolbox_Library/FileFormats/SizeTables/TPFileSizeTable.cs b/Switch_Toolbox_Library/FileFormats/SizeTables/TPFileSizeTable.cs index a4104f7d..9c008874 100644 --- a/Switch_Toolbox_Library/FileFormats/SizeTables/TPFileSizeTable.cs +++ b/Switch_Toolbox_Library/FileFormats/SizeTables/TPFileSizeTable.cs @@ -23,21 +23,16 @@ namespace Switch_Toolbox.Library public Dictionary FileSizes = new Dictionary(); public Dictionary DecompressedFileSizes = new Dictionary(); - - 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")); + public bool IsInFileSizeList(string FileName) => FileSizes.ContainsKey(FileName); + public bool IsInDecompressedFileSizeList(string FileName) => DecompressedFileSizes.ContainsKey(FileName); - // 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 SetFileSizeEntry(string FileName, uint Size) { + FileSizes[FileName] = Size; + } + public void SetDecompressedFileSizeEntry(string FileName, uint Size) { + DecompressedFileSizes[FileName].Size = Size; } public void ReadCompressedTable(FileReader reader) @@ -63,6 +58,8 @@ namespace Switch_Toolbox.Library entry.Precentage = reader.ReadString(BinaryStringFormat.ZeroTerminated); entry.FilePath = reader.ReadString(BinaryStringFormat.ZeroTerminated); + Console.WriteLine($"Size {Size} Size2 {Size2} {entry.Precentage} {entry.FilePath}"); + uint sizeNum = 0; uint sizeNum2 = 0; @@ -76,23 +73,6 @@ namespace Switch_Toolbox.Library } } - public bool TrySetSize(string Path, uint DecompSize, uint CompSize, Dictionary ArchiveFiles = null) - { - string RelativePath = Path.Replace(Runtime.TpGamePath, string.Empty); - - if (FileSizes.ContainsKey(RelativePath)) - { - if (UseCompressedSizes) - FileSizes[RelativePath] = CompSize; - else - FileSizes[RelativePath] = DecompSize; - - return true; - } - - return false; - } - public void WriteCompressedTable(FileWriter writer) { foreach (var file in FileSizes) diff --git a/Switch_Toolbox_Library/Forms/STConsole.cs b/Switch_Toolbox_Library/Forms/STConsole.cs index e3e34c30..fd761293 100644 --- a/Switch_Toolbox_Library/Forms/STConsole.cs +++ b/Switch_Toolbox_Library/Forms/STConsole.cs @@ -25,6 +25,32 @@ namespace Switch_Toolbox.Library ReadOnly = true; } + public static void WriteLine(object line, int ColorKeyIndex) + { + if (console == null) + return; + + if (ColorKeyIndex == 0) + WriteLine(line.ToString(), Color.Red); + else if (ColorKeyIndex == 1) + WriteLine(line.ToString(), Color.Green); + else + WriteLine(line.ToString()); + } + + public static void WriteLine(string line, int ColorKeyIndex) + { + if (console == null) + return; + + if (ColorKeyIndex == 0) + WriteLine(line.ToString(), Color.Red); + else if (ColorKeyIndex == 1) + WriteLine(line.ToString(), Color.Green); + else + WriteLine(line.ToString()); + } + public static void WriteLine(object line, Color? color = null) { if (console == null) diff --git a/Switch_Toolbox_Library/IO/STFileSaver.cs b/Switch_Toolbox_Library/IO/STFileSaver.cs index f9a2d57b..248b9d83 100644 --- a/Switch_Toolbox_Library/IO/STFileSaver.cs +++ b/Switch_Toolbox_Library/IO/STFileSaver.cs @@ -39,7 +39,7 @@ namespace Switch_Toolbox.Library.IO FileFormat.IFileInfo.CompressedSize = (uint)FinalData.Length; - DetailsLog += "\n" + SatisfyFileTables(FileName, FinalData, + DetailsLog += "\n" + SatisfyFileTables(FileFormat, FileName, FinalData, FileFormat.IFileInfo.DecompressedSize, FileFormat.IFileInfo.CompressedSize, FileFormat.IFileInfo.FileIsCompressed); @@ -51,7 +51,7 @@ namespace Switch_Toolbox.Library.IO Cursor.Current = Cursors.Default; } - private static string SatisfyFileTables(string FilePath, byte[] Data, uint DecompressedSize, uint CompressedSize, bool IsCompressed) + private static string SatisfyFileTables(IFileFormat FileFormat, string FilePath, byte[] Data, uint DecompressedSize, uint CompressedSize, bool IsCompressed) { string FileLog = ""; @@ -83,11 +83,17 @@ namespace Switch_Toolbox.Library.IO //Now apply the file table then save the table if (BotwResourceTable.IsInTable(newFilePath)) + { FileLog += $"File found in resource table! {newFilePath}"; + STConsole.WriteLine(FileLog, 1); + } else + { FileLog += $"File NOT found in resource table! {newFilePath}"; + STConsole.WriteLine(FileLog, 0); + + } - STConsole.WriteLine(FileLog); BotwResourceTable.SetEntry(newFilePath, Data); BotwResourceTable.Write(new FileWriter(RstbPath)); @@ -96,7 +102,51 @@ namespace Switch_Toolbox.Library.IO if (Runtime.ResourceTables.TpTable && IsTPHDFile) { + string newFilePath = FilePath.Replace(Runtime.BotwGamePath, string.Empty).Remove(0, 1); + newFilePath = newFilePath.Replace(".s", "."); + newFilePath = newFilePath.Replace(@"\", "/"); + //Read the tables and set the new sizes if paths match + TPFileSizeTable CompressedFileTbl = new TPFileSizeTable(); + CompressedFileTbl.ReadCompressedTable(new FileReader($"{Runtime.TpGamePath}/FileSizeList.txt")); + if (CompressedFileTbl.IsInFileSizeList(newFilePath)) + { + STConsole.WriteLine("Found matching path in File Size List table! " + newFilePath, 1); + CompressedFileTbl.SetFileSizeEntry(newFilePath, CompressedSize); + } + else + STConsole.WriteLine("Failed to find path in File Size List table! " + newFilePath, 0); + + + TPFileSizeTable DecompressedFileTbl = new TPFileSizeTable(); + DecompressedFileTbl.ReadDecompressedTable(new FileReader($"{Runtime.TpGamePath}/DecompressedSizeList.txt")); + + bool IsArchive = false; + foreach (var inter in FileFormat.GetType().GetInterfaces()) + if (inter.IsGenericType && inter.GetGenericTypeDefinition() == typeof(IArchiveFile)) + IsArchive = true; + + if (IsArchive) + { + IArchiveFile Archive = (IArchiveFile)FileFormat; + foreach (var file in Archive.Files) + { + uint DecompressedFileSize = (uint)file.FileData.Length; + string ArchiveFilePath = $"/DVDRoot/{file.FileName}"; + + DecompressedFileTbl.ReadCompressedTable(new FileReader($"{Runtime.TpGamePath}/FileSizeList.txt")); + if (DecompressedFileTbl.IsInDecompressedFileSizeList(newFilePath)) + { + STConsole.WriteLine("Found matching path in File Size List table! " + newFilePath, 1); + DecompressedFileTbl.SetDecompressedFileSizeEntry(newFilePath, DecompressedFileSize); + } + else + STConsole.WriteLine("Failed to find path in File Size List table! " + newFilePath, 0); + } + } + + DecompressedFileTbl.WriteCompressedTable(new FileWriter($"{Runtime.TpGamePath}/FileSizeListTEST.txt")); + DecompressedFileTbl.WriteDecompressedTable(new FileWriter($"{Runtime.TpGamePath}/DecompressedSizeListTEST.txt")); } return FileLog;