diff --git a/.vs/Switch_Toolbox/v15/.suo b/.vs/Switch_Toolbox/v15/.suo index 8418a140..dc4a7bfd 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 c7ba5797..afceca4d 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 3e564199..24642dfe 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/FileFormats/Archives/SARC.cs b/Switch_FileFormatsMain/FileFormats/Archives/SARC.cs index e23200fd..c05aae11 100644 --- a/Switch_FileFormatsMain/FileFormats/Archives/SARC.cs +++ b/Switch_FileFormatsMain/FileFormats/Archives/SARC.cs @@ -134,7 +134,12 @@ namespace FirstPlugin.New public void Unload() { + foreach (var file in files) + file.FileData = null; + files.Clear(); + + GC.SuppressFinalize(this); } IEnumerable Collect(TreeNodeCollection nodes) diff --git a/Switch_FileFormatsMain/FileFormats/Archives/SARC_OLD.cs b/Switch_FileFormatsMain/FileFormats/Archives/SARC_OLD.cs index bf3830b3..6c776659 100644 --- a/Switch_FileFormatsMain/FileFormats/Archives/SARC_OLD.cs +++ b/Switch_FileFormatsMain/FileFormats/Archives/SARC_OLD.cs @@ -239,19 +239,19 @@ namespace FirstPlugin private void SaveFileEntryData(SarcEntry sarc) { - string dir = Path.GetDirectoryName(sarc.FullName); + string dir = Path.GetDirectoryName(sarc.FileName); if (!sarcData.HashOnly) { if (dir == string.Empty) - sarc.FullName = sarc.Text; + sarc.FileName = sarc.Text; else - sarc.FullName = Path.Combine(dir, sarc.Text); + sarc.FileName = Path.Combine(dir, sarc.Text); - sarc.FullName = sarc.FullName.Replace(@"\", "/"); + sarc.FileName = sarc.FileName.Replace(@"\", "/"); } - sarcData.Files.Add(sarc.FullName, sarc.Data); + sarcData.Files.Add(sarc.FileName, sarc.FileData); } public static void ReplaceNode(TreeNode node, TreeNode replaceNode, TreeNode NewNode) { @@ -335,7 +335,7 @@ namespace FirstPlugin public class SarcEntry : TreeNodeCustom, IContextMenuNode { public SARC sarc; //Sarc file the entry is located in - public byte[] Data; + public byte[] FileData; public string sarcHash; public SarcEntry() @@ -373,17 +373,17 @@ namespace FirstPlugin } editor.Text = Text; editor.Dock = DockStyle.Fill; - editor.LoadData(Data); + editor.LoadData(FileData); } public IFileFormat OpenFile() { - return STFileLoader.OpenFileFormat(FullName, Data, false, true, this); + return STFileLoader.OpenFileFormat(FileName, FileData, false, true, this); } public override void OnDoubleMouseClick(TreeView treeView) { - if (Data.Length <= 0) + if (FileData.Length <= 0) return; IFileFormat file = OpenFile(); @@ -396,7 +396,7 @@ namespace FirstPlugin } else if (file != null) { - sarc.OpenedFiles.Add(FullPath, Data); + sarc.OpenedFiles.Add(FullPath, FileData); ReplaceNode(this.Parent, this, (TreeNode)file); } } @@ -414,7 +414,7 @@ namespace FirstPlugin { if (fileFormat.CanSave) { - Data = fileFormat.Save(); + FileData = fileFormat.Save(); UpdateHexView(); } } @@ -427,7 +427,7 @@ namespace FirstPlugin if (fileFormat.CanSave) { - Data = fileFormat.Save(); + FileData = fileFormat.Save(); UpdateHexView(); } } @@ -453,7 +453,7 @@ namespace FirstPlugin // Determine by checking the Text property. } - public string FullName; + public string FileName; private void Replace(object sender, EventArgs args) { OpenFileDialog ofd = new OpenFileDialog(); @@ -463,13 +463,13 @@ namespace FirstPlugin if (ofd.ShowDialog() == DialogResult.OK) { - Data = File.ReadAllBytes(ofd.FileName); + FileData = File.ReadAllBytes(ofd.FileName); } } private void ExportToFileLoc(object sender, EventArgs args) { Cursor.Current = Cursors.WaitCursor; - File.WriteAllBytes($"{Path.GetDirectoryName(sarc.FilePath)}/{Text}", Data); + File.WriteAllBytes($"{Path.GetDirectoryName(sarc.FilePath)}/{Text}", FileData); Cursor.Current = Cursors.Default; } private void Export(object sender, EventArgs args) @@ -481,7 +481,7 @@ namespace FirstPlugin if (sfd.ShowDialog() == DialogResult.OK) { - File.WriteAllBytes(sfd.FileName, Data); + File.WriteAllBytes(sfd.FileName, FileData); } } @@ -495,7 +495,7 @@ namespace FirstPlugin } editor.Text = Text; editor.Dock = DockStyle.Fill; - editor.FillEditor(Data); + editor.FillEditor(FileData); } private void Remove(object sender, EventArgs args) @@ -599,11 +599,11 @@ namespace FirstPlugin public SarcEntry SetupFileEntry(byte[] data, string name, string fullName) { SarcEntry sarcEntry = new SarcEntry(); - sarcEntry.FullName = fullName; + sarcEntry.FileName = fullName; sarcEntry.Name = name; sarcEntry.Text = name; sarcEntry.sarc = this; - sarcEntry.Data = data; + sarcEntry.FileData = data; Files.Add(sarcEntry); diff --git a/Switch_FileFormatsMain/FileFormats/BFRES/BFRES.cs b/Switch_FileFormatsMain/FileFormats/BFRES/BFRES.cs index b42577da..5969e3ca 100644 --- a/Switch_FileFormatsMain/FileFormats/BFRES/BFRES.cs +++ b/Switch_FileFormatsMain/FileFormats/BFRES/BFRES.cs @@ -194,8 +194,7 @@ namespace FirstPlugin { foreach (var file in ((SARC)FileFormat).Files) { - Console.WriteLine($"{FileFormat.FileName} {file.Text}"); - var archiveFile = STFileLoader.OpenFileFormat(file.FullName, new Type[] { typeof(BFRES), typeof(SARC) }, file.Data); + var archiveFile = STFileLoader.OpenFileFormat(file.FileName, new Type[] { typeof(BFRES), typeof(SARC) }, file.FileData); if (archiveFile == null) continue; @@ -820,10 +819,57 @@ namespace FirstPlugin ObjectEditor.RemoveContainer(DrawableContainer); + if (resFile != null) + { + resFile.Models.Clear(); + resFile.SkeletalAnims.Clear(); + resFile.MaterialAnims.Clear(); + resFile.SceneAnims.Clear(); + resFile.ShapeAnims.Clear(); + resFile.BoneVisibilityAnims.Clear(); + resFile.ModelDict.Clear(); + resFile.SkeletalAnimDict.Clear(); + resFile.MaterialAnimDict.Clear(); + resFile.SceneAnimDict.Clear(); + resFile.ShapeAnimDict.Clear(); + resFile.BoneVisibilityAnimDict.Clear(); + resFile.ExternalFiles.Clear(); + resFile.ExternalFileDict.Clear(); + } + else if (resFileU != null) + { + resFileU.Models.Clear(); + resFileU.Textures.Clear(); + resFileU.SkeletalAnims.Clear(); + resFileU.ShaderParamAnims.Clear(); + resFileU.ColorAnims.Clear(); + resFileU.TexSrtAnims.Clear(); + resFileU.TexPatternAnims.Clear(); + resFileU.BoneVisibilityAnims.Clear(); + resFileU.MatVisibilityAnims.Clear(); + resFileU.ShapeAnims.Clear(); + resFileU.SceneAnims.Clear(); + resFileU.ExternalFiles.Clear(); + } + foreach (var node in TreeViewExtensions.Collect(BFRESRender.ResFileNode.Nodes)) { if (node is BFRESGroupNode) { + if (((BFRESGroupNode)node).Type == BRESGroupType.Models) + { + for (int i = 0; i < ((BFRESGroupNode)node).Nodes.Count; i++) + { + FMDL model = ((FMDL)((BFRESGroupNode)node).Nodes[i]); + for (int shp = 0; shp < model.shapes.Count; shp++) + { + model.shapes[shp].vertices.Clear(); + model.shapes[shp].faces.Clear(); + foreach (var lod in model.shapes[shp].lodMeshes) + lod.faces.Clear(); + } + } + } if (((BFRESGroupNode)node).Type == BRESGroupType.Textures) { for (int i = 0; i < ((BFRESGroupNode)node).Nodes.Count; i++) diff --git a/Switch_FileFormatsMain/FileFormats/Texture/BFLIM.cs b/Switch_FileFormatsMain/FileFormats/Texture/BFLIM.cs index 08bd6d93..d6e15015 100644 --- a/Switch_FileFormatsMain/FileFormats/Texture/BFLIM.cs +++ b/Switch_FileFormatsMain/FileFormats/Texture/BFLIM.cs @@ -220,7 +220,7 @@ namespace FirstPlugin { foreach (var file in ((SARC)FileFormat).Files) { - var archiveFile = STFileLoader.OpenFileFormat(file.FullName, new Type[] { typeof(BFLIM) , typeof(SARC) }, file.Data); + var archiveFile = STFileLoader.OpenFileFormat(file.FileName, new Type[] { typeof(BFLIM) , typeof(SARC) }, file.FileData); if (archiveFile == null) continue; diff --git a/Switch_FileFormatsMain/FileFormats/Texture/BNTX.cs b/Switch_FileFormatsMain/FileFormats/Texture/BNTX.cs index 99a61ff5..68741b8c 100644 --- a/Switch_FileFormatsMain/FileFormats/Texture/BNTX.cs +++ b/Switch_FileFormatsMain/FileFormats/Texture/BNTX.cs @@ -137,14 +137,14 @@ namespace FirstPlugin { foreach (var file in ((SARC)FileFormat).Files) { - var archiveFile = STFileLoader.OpenFileFormat(file.FullName, new Type[] { typeof(BNTX), typeof(BFRES), typeof(PTCL), typeof(SARC) }, file.Data); + var archiveFile = STFileLoader.OpenFileFormat(file.FileName, new Type[] { typeof(BNTX), typeof(BFRES), typeof(PTCL), typeof(SARC) }, file.FileData); if (archiveFile == null) continue; SearchBinary(archiveFile, Folder, Extension); } } - if (FileFormat is BNTX) + /* if (FileFormat is BNTX) { foreach (var texture in ((BNTX)FileFormat).Textures.Values) texture.Export(Path.Combine(Folder, $"{FileFormat.FileName}_{texture.Text}{Extension}")); @@ -156,6 +156,8 @@ namespace FirstPlugin { foreach (var texture in bntx.Textures.Values) texture.Export(Path.Combine(Folder, $"{FileFormat.FileName}_{texture.Text}{Extension}")); + + bntx.Unload(); } } if (FileFormat is PTCL) @@ -165,10 +167,13 @@ namespace FirstPlugin { foreach (var texture in bntx.Textures.Values) texture.Export(Path.Combine(Folder, $"{FileFormat.FileName}_{texture.Text}{Extension}")); + + bntx.Unload(); } - } + }*/ FileFormat.Unload(); + GC.Collect(); } } diff --git a/Switch_FileFormatsMain/Main.cs b/Switch_FileFormatsMain/Main.cs index 8f218363..74040bd8 100644 --- a/Switch_FileFormatsMain/Main.cs +++ b/Switch_FileFormatsMain/Main.cs @@ -213,10 +213,10 @@ namespace FirstPlugin { foreach (var file in ((SARC)FileFormat).Files) { - string ext = System.IO.Path.GetExtension(file.FullName); + string ext = System.IO.Path.GetExtension(file.FileName); if (ext == ".bfres") { - bfresFiles.Add((BFRES)STFileLoader.OpenFileFormat(file.FullName, file.Data)); + bfresFiles.Add((BFRES)STFileLoader.OpenFileFormat(file.FileName, file.FileData)); } } } diff --git a/Switch_FileFormatsMain/obj/Release/DesignTimeResolveAssemblyReferences.cache b/Switch_FileFormatsMain/obj/Release/DesignTimeResolveAssemblyReferences.cache index 25a763ac..841f7460 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 b85e863a..4e7b2592 100644 Binary files a/Switch_FileFormatsMain/obj/Release/Switch_FileFormatsMain.csprojAssemblyReference.cache and b/Switch_FileFormatsMain/obj/Release/Switch_FileFormatsMain.csprojAssemblyReference.cache differ