Skip to content

Commit

Permalink
Less logging, memory leak fixes, memory optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
GoneUp committed Jul 15, 2020
1 parent 9e6c172 commit 10bb718
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 70 deletions.
39 changes: 18 additions & 21 deletions GPK_RePack/Forms/GUI.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 0 additions & 5 deletions GPK_RePack/Forms/GUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,6 @@ private void exitToolStripMenuItem_Click(object sender, EventArgs e)
Environment.Exit(0);
}

private void boxLog_TextChanged(object sender, EventArgs e)
{
boxLog.SelectionStart = boxLog.TextLength;
boxLog.ScrollToCaret();
}

private void clearToolStripMenuItem_Click(object sender, EventArgs e)
{
Expand Down
7 changes: 4 additions & 3 deletions GPK_RePack/Forms/NLogConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@ public static void SetDefaultConfig()
AsyncTargetWrapper asyncWrapperLog = new AsyncTargetWrapper(logfile);
config.AddTarget("logfile", asyncWrapperLog);

var formTargetSync = new FormControlTarget();
formTargetSync.Layout = "${date:format=HH\\:mm\\:ss} ${logger} # ${message} ${newline}";
formTargetSync.Append = true;
var formTargetSync = new RichTextBoxTarget();
formTargetSync.Layout = "${date:format=HH\\:mm\\:ss} ${logger} # ${message}";
formTargetSync.AutoScroll = true;
formTargetSync.ControlName = "boxLog";
formTargetSync.FormName = "GUI";
formTargetSync.MaxLines = 1000;
config.AddTarget("form", formTargetSync);
formTarget = new AsyncTargetWrapper(formTargetSync);
config.AddTarget("form", formTarget);
Expand Down
1 change: 1 addition & 0 deletions GPK_RePack/IO/MassDumper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ public static void DumpMassTextures(GpkStore store, String outdir)

Reader r = new Reader();
var package = r.ReadSubGpkFromComposite(path, entry.UID, entry.FileOffset, entry.FileLength);
package.LowMemMode = true;

//extract
var exports = package.GetExportsByClass("Core.Texture2D");
Expand Down
29 changes: 22 additions & 7 deletions GPK_RePack/IO/Reader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,16 +106,19 @@ public List<GpkPackage> ReadGpk(string path, bool skipExportData)

public GpkPackage ReadSubGpkFromComposite(string path, string fileID, int fileOffset, int dataLength)
{
BinaryReader reader = null;

try
{
logger = LogManager.GetLogger("ReadSubGpkFromComposite: " + fileID);

var reader = new BinaryReader(new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read));
reader = new BinaryReader(new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read));
stat = new Status();

reader.BaseStream.Seek(fileOffset, SeekOrigin.Begin);
var data = reader.ReadBytes(dataLength);
reader.Close();
reader.Dispose();

GpkPackage tmpGPK = new GpkPackage();
tmpGPK.Filename = fileID;
Expand All @@ -127,7 +130,7 @@ public GpkPackage ReadSubGpkFromComposite(string path, string fileID, int fileOf

var fullGpk = ReadSubGpkPackage(tmpGPK, data, false, stat);

logger.Debug("done");
logger.Debug("Done");

return fullGpk;
}
Expand All @@ -136,19 +139,26 @@ public GpkPackage ReadSubGpkFromComposite(string path, string fileID, int fileOf
logger.Fatal("Parse failure!");
logger.Fatal(ex);
}
finally
{
if (reader != null)
reader.Close();
}

return null;
}

private GpkPackage ReadSubGpkPackage(GpkPackage package, byte[] data, bool skipExportData, Status stat)
{
BinaryReader reader = null;

try
{
BinaryReader reader = new BinaryReader(new MemoryStream(data));
reader = new BinaryReader(new MemoryStream(data));
Stopwatch pkgWatch = new Stopwatch();

logger = LogManager.GetLogger("[ReadSubGpkPackage:" + package.Filename + "]");
logger.Info("Reading Start");
logger.Debug("Reading Start");
stat.name = package.Filename;
pkgWatch.Start();

Expand All @@ -158,6 +168,7 @@ private GpkPackage ReadSubGpkPackage(GpkPackage package, byte[] data, bool skipE
if (file != null)
{
reader.Close();
reader.Dispose();
reader = new BinaryReader(new MemoryStream(file));
}

Expand All @@ -175,7 +186,6 @@ private GpkPackage ReadSubGpkPackage(GpkPackage package, byte[] data, bool skipE
stat.time = pkgWatch.ElapsedMilliseconds;
stat.finished = true;
logger.Info("Reading of package {0} complete, took {1}ms!", package.Filename, pkgWatch.ElapsedMilliseconds);
logger.Info("Reading Done");

return package;
}
Expand All @@ -184,6 +194,11 @@ private GpkPackage ReadSubGpkPackage(GpkPackage package, byte[] data, bool skipE
logger.Fatal("Parse failure!");
logger.Fatal(ex);
}
finally
{
if (reader != null)
reader.Close();
}

return null;
}
Expand Down Expand Up @@ -221,7 +236,7 @@ private void ReadHeader(BinaryReader reader, GpkPackage package)

package.Header.DependsOffset = reader.ReadInt32();

if (package.x64) package.Header.HeaderSize = reader.ReadInt32();
if (package.x64) package.Header.HeaderSize = reader.ReadInt32();

logger.Debug("NameCount " + package.Header.NameCount);
logger.Debug("NameOffset " + package.Header.NameOffset);
Expand Down Expand Up @@ -570,7 +585,7 @@ private void ReadExportData(BinaryReader reader, GpkPackage package)

if (export.Payload != null) logger.Debug(export.Payload.ToString());
}
}
}


logger.Trace(String.Format("Export {0}: Read Data ({1} bytes {2}) and {3} Properties ({4} bytes)", export.ObjectName, toread, tag, export.Properties.Count, export.PropertySize));
Expand Down
3 changes: 2 additions & 1 deletion GPK_RePack/Model/GpkPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ class GpkPackage
public long OrginalSize; //raw compressed size
public long UncompressedSize;


//
public Boolean Changes = false;
public Boolean LowMemMode = false;

//data structs
public GpkHeader Header;
Expand Down
1 change: 1 addition & 0 deletions GPK_RePack/Model/Payload/MipMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class MipMap
public string loadedFromTextureCache = "";

public List<ChunkBlock> blocks = new List<ChunkBlock>();
internal int blockCount;

public void generateBlocks()
{
Expand Down
Loading

0 comments on commit 10bb718

Please sign in to comment.