Now twilight princess file table works

This commit is contained in:
KillzXGaming 2019-06-11 20:59:53 -04:00
parent 35f547e9a7
commit 0b87737eac
93 changed files with 11 additions and 28 deletions

Binary file not shown.

View file

@ -56,7 +56,6 @@ namespace FirstPlugin
public Dictionary<long, byte[]> SavedDataEntries = new Dictionary<long, byte[]>(); public Dictionary<long, byte[]> SavedDataEntries = new Dictionary<long, byte[]>();
public Dictionary<long, string> SavedStringEntries = new Dictionary<long, string>(); public Dictionary<long, string> SavedStringEntries = new Dictionary<long, string>();
public Dictionary<string, uint> ArchiveSizes = new Dictionary<string, uint>();
public uint Alignment; public uint Alignment;
public static readonly uint DefaultAlignment = 4; public static readonly uint DefaultAlignment = 4;
@ -81,19 +80,6 @@ namespace FirstPlugin
} }
} }
private void SatisfyFileSizeTable()
{
uint TotalDecompressedSize = IFileInfo.DecompressedSize;
uint TotalCompressedSize = IFileInfo.CompressedSize;
if (Runtime.TpGamePath != "" && Directory.Exists(Runtime.TpGamePath))
{
string TablePath = $"{Runtime.TpGamePath}/FileSizeList.txt";
TPFileSizeTable.SetTables(this);
}
}
private void Save(object sender, EventArgs args) private void Save(object sender, EventArgs args)
{ {
SaveFileDialog sfd = new SaveFileDialog(); SaveFileDialog sfd = new SaveFileDialog();
@ -104,15 +90,11 @@ namespace FirstPlugin
if (sfd.ShowDialog() == DialogResult.OK) if (sfd.ShowDialog() == DialogResult.OK)
{ {
STFileSaver.SaveFileFormat(this, sfd.FileName); STFileSaver.SaveFileFormat(this, sfd.FileName);
SatisfyFileSizeTable();
} }
} }
private void SaveFile(FileWriter writer) private void SaveFile(FileWriter writer)
{ {
ArchiveSizes.Clear();
writer.ByteOrder = Syroot.BinaryData.ByteOrder.BigEndian; writer.ByteOrder = Syroot.BinaryData.ByteOrder.BigEndian;
writer.WriteSignature("TMPK"); writer.WriteSignature("TMPK");
@ -126,8 +108,6 @@ namespace FirstPlugin
writer.Write(uint.MaxValue); writer.Write(uint.MaxValue);
writer.Write(files[i].FileData.Length); //Padding writer.Write(files[i].FileData.Length); //Padding
writer.Write(0); //Padding writer.Write(0); //Padding
ArchiveSizes.Add(files[i].FileName, (uint)files[i].FileData.Length);
} }
for (int i = 0; i < files.Count; i++) for (int i = 0; i < files.Count; i++)
{ {

View file

@ -1 +0,0 @@
81115f490d097ea68b62b86788a8bc08ded17c3e

View file

@ -189,7 +189,7 @@ namespace Switch_Toolbox.Library.IO
{ {
using (MemoryStream mem = new MemoryStream()) using (MemoryStream mem = new MemoryStream())
{ {
using (GZipStream source = new GZipStream(new MemoryStream(b), CompressionMode.Decompress)) using (GZipStream source = new GZipStream(new MemoryStream(b), CompressionMode.Decompress, false))
{ {
source.CopyTo(mem); source.CopyTo(mem);
} }
@ -202,7 +202,7 @@ namespace Switch_Toolbox.Library.IO
using (MemoryStream mem = new MemoryStream()) using (MemoryStream mem = new MemoryStream())
{ {
using (GZipStream gzip = new GZipStream(mem, using (GZipStream gzip = new GZipStream(mem,
CompressionMode.Compress, true)) CompressionMode.Compress))
{ {
gzip.Write(b, 0, b.Length); gzip.Write(b, 0, b.Length);
} }

View file

@ -22,7 +22,7 @@ namespace Switch_Toolbox.Library.IO
{ {
//These always get created on loading a file,however not on creating a new file //These always get created on loading a file,however not on creating a new file
if (FileFormat.IFileInfo == null) if (FileFormat.IFileInfo == null)
throw new System.Exception("Make sure to impliment a IFileInfo instance if a format is being created!"); throw new System.NotImplementedException("Make sure to impliment a IFileInfo instance if a format is being created!");
Cursor.Current = Cursors.WaitCursor; Cursor.Current = Cursors.WaitCursor;
FileFormat.FilePath = FileName; FileFormat.FilePath = FileName;
@ -119,7 +119,8 @@ namespace Switch_Toolbox.Library.IO
TPFileSizeTable DecompressedFileTbl = new TPFileSizeTable(); TPFileSizeTable DecompressedFileTbl = new TPFileSizeTable();
DecompressedFileTbl.ReadDecompressedTable(new FileReader($"{Runtime.TpGamePath}/DecompressedSizeList.txt")); DecompressedFileTbl.ReadDecompressedTable(new FileReader($"{Runtime.TpGamePath}/DecompressedSizeList.txt"));
newFilePath = $"/DVDRoot/{newFilePath}"; newFilePath = $"./DVDRoot/{newFilePath}";
newFilePath = newFilePath.Replace(".gz", string.Empty);
//Write the decompressed file size //Write the decompressed file size
if (DecompressedFileTbl.IsInDecompressedFileSizeList(newFilePath)) if (DecompressedFileTbl.IsInDecompressedFileSizeList(newFilePath))
@ -133,8 +134,11 @@ namespace Switch_Toolbox.Library.IO
//Check if archive type //Check if archive type
bool IsArchive = false; bool IsArchive = false;
foreach (var inter in FileFormat.GetType().GetInterfaces()) foreach (var inter in FileFormat.GetType().GetInterfaces())
if (inter.IsGenericType && inter.GetGenericTypeDefinition() == typeof(IArchiveFile)) {
if (inter == typeof(IArchiveFile))
IsArchive = true; IsArchive = true;
}
//Write all the file sizes in the archive if it's an archive type //Write all the file sizes in the archive if it's an archive type
if (IsArchive) if (IsArchive)
@ -155,8 +159,8 @@ namespace Switch_Toolbox.Library.IO
} }
} }
CompressedFileTbl.WriteCompressedTable(new FileWriter($"{Runtime.TpGamePath}/FileSizeListTEST.txt")); CompressedFileTbl.WriteCompressedTable(new FileWriter($"{Runtime.TpGamePath}/FileSizeList.txt"));
DecompressedFileTbl.WriteDecompressedTable(new FileWriter($"{Runtime.TpGamePath}/DecompressedSizeListTEST.txt")); DecompressedFileTbl.WriteDecompressedTable(new FileWriter($"{Runtime.TpGamePath}/DecompressedSizeList.txt"));
} }
return FileLog; return FileLog;