Skip to content

Commit

Permalink
- Added option to export a single gpk
Browse files Browse the repository at this point in the history
- Added option to split texture dump
  • Loading branch information
GoneUp committed Jul 20, 2020
1 parent 10bb718 commit 1c63ecf
Show file tree
Hide file tree
Showing 8 changed files with 200 additions and 92 deletions.
55 changes: 32 additions & 23 deletions GPK_RePack/Forms/GUI.Designer.cs

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

106 changes: 72 additions & 34 deletions GPK_RePack/Forms/GUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Documents;
using System.Windows.Forms;
using System.Windows.Media.Imaging;
using System.Xml;
using GPK_RePack.Editors;
using GPK_RePack.Forms.Helper;
using GPK_RePack.IO;
using GPK_RePack.Model;
using GPK_RePack.Model.Composite;
using GPK_RePack.Model.Interfaces;
using GPK_RePack.Model.Payload;
using GPK_RePack.Model.Prop;
Expand All @@ -27,6 +29,7 @@
using NAudio.Wave.SampleProviders;
using NLog;
using NLog.Config;
using NLog.Filters;
using NLog.Targets;
using NLog.Windows.Forms;
using UpkManager.Dds;
Expand Down Expand Up @@ -242,7 +245,7 @@ private void openToolStripMenuItem_Click(object sender, EventArgs e)
}

//display info while loading
while (!Task.WaitAll(runningTasks.ToArray(), 50))
while (!Task.WaitAll(runningTasks.ToArray(), 500))
{
Application.DoEvents();
DisplayStatus(runningReaders, "Loading", start);
Expand Down Expand Up @@ -316,34 +319,14 @@ private void saveToolStripMenuItem_Click(object sender, EventArgs e)
if (gpkStore.LoadedGpkPackages.Count == 0)
return;

foreach (GpkPackage package in gpkStore.LoadedGpkPackages)
{
try
{
Writer tmpS = new Writer();
Task newTask = new Task(delegate ()
{
string savepath = package.Path + Settings.Default.SaveFileSuffix;
tmpS.SaveGpkPackage(package, savepath, usePadding);
});
newTask.Start();
runningTasks.Add(newTask);
runningSavers.Add(tmpS);
}
catch (Exception ex)
{
logger.Fatal(ex, "Save failure!");
}

}

//do it
this.gpkStore.SaveGpkListToFiles(gpkStore.LoadedGpkPackages, usePadding, runningSavers, runningTasks);

//display info while loading
while (!Task.WaitAll(runningTasks.ToArray(), 50))
{
Application.DoEvents();
DisplayStatus(runningSavers, "Saving", start);
//Thread.Sleep(50);
}

//Diplay end info
Expand Down Expand Up @@ -427,7 +410,7 @@ public void DrawPackages()
//TreeNode nodeP = treeMain.Nodes.Add(i.ToString(), package.Filename);
TreeNode nodeP = new TreeNode(package.Filename);
nodeP.Name = i.ToString(); //Key


Dictionary<string, TreeNode> classNodes = new Dictionary<string, TreeNode>();
TreeNode nodeI = null;
Expand Down Expand Up @@ -492,7 +475,7 @@ public void DrawPackages()
}



treeMain.Sort();
treeMain.EndUpdate();
}
Expand Down Expand Up @@ -1425,8 +1408,14 @@ private void decryptionToolStripMenuItem_Click(object sender, EventArgs e)

private void loadMappingToolStripMenuItem_Click(object sender, EventArgs e)
{
if (gpkStore.CompositeMap.Count > 0)
{
new FormMapperView(gpkStore).Show();
return;
}

var dialog = new FolderBrowserDialog();
if (Settings.Default.CookedPCPath != "")
if (Settings.Default.CookedPCPath != "")
dialog.SelectedPath = Settings.Default.CookedPCPath;
dialog.Description = "Select a folder with PkgMapper.dat and CompositePackageMapper.dat in it. Normally your CookedPC folder.";
if (dialog.ShowDialog() == DialogResult.Cancel)
Expand All @@ -1440,8 +1429,7 @@ private void loadMappingToolStripMenuItem_Click(object sender, EventArgs e)
int subCount = gpkStore.CompositeMap.Sum(entry => entry.Value.Count);
logger.Info("Parsed mappings, we have {0} composite GPKs and {1} sub-gpks!", gpkStore.CompositeMap.Count, subCount);

var mapperView = new formMapperView(gpkStore);
mapperView.Show();
new FormMapperView(gpkStore).Show();
}

private void dumpCompositeTexturesToolStripMenuItem_Click(object sender, EventArgs e)
Expand All @@ -1463,20 +1451,47 @@ private void dumpCompositeTexturesToolStripMenuItem_Click(object sender, EventAr
int subCount = gpkStore.CompositeMap.Sum(entry => entry.Value.Count);
logger.Info("Parsed mappings, we have {0} composite GPKs and {1} sub-gpks!", gpkStore.CompositeMap.Count, subCount);

//selection
var text = Microsoft.VisualBasic.Interaction.InputBox("Select range of composite gpks to load. Format: n-n [e.g. 1-5] or empty for all."
, "Selection", "");
var filterList = filterCompositeList(text);

//save dir
dialog = new FolderBrowserDialog();
dialog.SelectedPath = Settings.Default.WorkingDir;
dialog.Description = "Select your output dir";
if (dialog.ShowDialog() == DialogResult.Cancel)
return;

logger.Info("Disabling logging, dump is running in the background. Consider setting file logging to only info.");
logger.Warn("Warning: This function can be ultra long running (hours) and unstable. Monitor logfile and output folder for progress.");
logger.Warn("Disabling logging, dump is running in the background. Consider setting file logging to only info.");

NLogConfig.DisableFormLogging();
var outDir = dialog.SelectedPath;
new Task(() => MassDumper.DumpMassTextures(gpkStore, outDir)).Start();

new Task(() => MassDumper.DumpMassTextures(gpkStore, outDir, filterList)).Start();
}

NLogConfig.EnableFormLogging();
private Dictionary<String, List<CompositeMapEntry>> filterCompositeList(string text)
{
try
{
if (text != "" && text.Split('-').Length > 0)
{
int start = Convert.ToInt32(text.Split('-')[0]) - 1;
int end = Convert.ToInt32(text.Split('-')[1]) - 1;
var filterCompositeList = gpkStore.CompositeMap.Skip(start).Take(end - start + 1).ToDictionary(k => k.Key, v => v.Value);
logger.Info("Filterd down to {0} GPKs.", end - start + 1);
return filterCompositeList;
}
else
{
return gpkStore.CompositeMap;
}
}
catch (Exception ex)
{
return gpkStore.CompositeMap;
}
}

#endregion
Expand Down Expand Up @@ -1736,7 +1751,8 @@ private IProperty readProperty(DataGridViewRow row)

if (cellValue.Length > 2)
{
if (selectedPackage.x64) {
if (selectedPackage.x64)
{
tmpByte.enumType = row.Cells["iType"].Value.ToString();
selectedPackage.AddString(tmpByte.enumType); //just in case
}
Expand Down Expand Up @@ -1969,6 +1985,10 @@ private void selectContextAction(object sender, ToolStripItemClickedEventArgs e)
{
btnExtractOGG_Click(null, null);
}
else if (e.ClickedItem == exportPackageToolStripMenuItem)
{
saveSingleGpkPackage();
}
//preview ogg

else if (e.ClickedItem == previewOGGToolStripMenuItem)
Expand All @@ -1978,7 +1998,25 @@ private void selectContextAction(object sender, ToolStripItemClickedEventArgs e)
}));
}

private void saveSingleGpkPackage()
{
if (selectedPackage != null && treeMain.SelectedNode != null && treeMain.SelectedNode.Level == 0)
{
var packages = new List<GpkPackage>();
packages.Add(selectedPackage);
var writerList = new List<IProgress>();
var taskList = new List<Task>();

this.gpkStore.SaveGpkListToFiles(packages, false, writerList, taskList);

//wait
while (!Task.WaitAll(taskList.ToArray(), 50))
{
Application.DoEvents();
}
logger.Info("Single export done!");
}
}



Expand All @@ -1992,7 +2030,7 @@ private void selectContextAction(object sender, ToolStripItemClickedEventArgs e)

#endregion


}
}

Expand Down
Loading

0 comments on commit 1c63ecf

Please sign in to comment.