Some ram usage improvements when bfres is cleared

This commit is contained in:
KillzXGaming 2019-06-28 21:15:23 -04:00
parent 8767898577
commit a18463db24
11 changed files with 83 additions and 27 deletions

Binary file not shown.

View file

@ -134,7 +134,12 @@ namespace FirstPlugin.New
public void Unload()
{
foreach (var file in files)
file.FileData = null;
files.Clear();
GC.SuppressFinalize(this);
}
IEnumerable<TreeNode> Collect(TreeNodeCollection nodes)

View file

@ -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);

View file

@ -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++)

View file

@ -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;

View file

@ -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();
}
}

View file

@ -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));
}
}
}