diff --git a/GPK_RePack/Forms/GUI.Designer.cs b/GPK_RePack/Forms/GUI.Designer.cs index f7f9254..d1b46ed 100644 --- a/GPK_RePack/Forms/GUI.Designer.cs +++ b/GPK_RePack/Forms/GUI.Designer.cs @@ -43,7 +43,6 @@ private void InitializeComponent() this.exportOGGToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.exportDDSToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripSeparator5 = new System.Windows.Forms.ToolStripSeparator(); - this.addToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.removeToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.copyToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.pasteToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); @@ -118,6 +117,8 @@ private void InitializeComponent() this.ProgressBar = new System.Windows.Forms.ToolStripProgressBar(); this.splitContainerLog_InfoTree = new System.Windows.Forms.SplitContainer(); this.boxLog = new System.Windows.Forms.RichTextBox(); + this.addToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.exportPackageToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.treeContextMenu.SuspendLayout(); this.menuStrip.SuspendLayout(); this.tabControl.SuspendLayout(); @@ -170,7 +171,7 @@ private void InitializeComponent() this.toolStripSeparator6, this.previewOGGToolStripMenuItem}); this.treeContextMenu.Name = "treeContextMenu"; - this.treeContextMenu.Size = new System.Drawing.Size(161, 184); + this.treeContextMenu.Size = new System.Drawing.Size(181, 206); this.treeContextMenu.ItemClicked += new System.Windows.Forms.ToolStripItemClickedEventHandler(this.treeContextMenu_ItemClicked); // // importToolStripMenuItem @@ -180,7 +181,7 @@ private void InitializeComponent() this.importOGGToolStripMenuItem, this.importDDSToolStripMenuItem}); this.importToolStripMenuItem.Name = "importToolStripMenuItem"; - this.importToolStripMenuItem.Size = new System.Drawing.Size(160, 24); + this.importToolStripMenuItem.Size = new System.Drawing.Size(180, 24); this.importToolStripMenuItem.Text = "Import"; this.importToolStripMenuItem.DropDownItemClicked += new System.Windows.Forms.ToolStripItemClickedEventHandler(this.treeContextMenu_ItemClicked); // @@ -207,69 +208,63 @@ private void InitializeComponent() this.exportToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.exportRawDataToolStripMenuItem, this.exportOGGToolStripMenuItem, - this.exportDDSToolStripMenuItem}); + this.exportDDSToolStripMenuItem, + this.exportPackageToolStripMenuItem}); this.exportToolStripMenuItem.Name = "exportToolStripMenuItem"; - this.exportToolStripMenuItem.Size = new System.Drawing.Size(160, 24); + this.exportToolStripMenuItem.Size = new System.Drawing.Size(180, 24); this.exportToolStripMenuItem.Text = "Export"; this.exportToolStripMenuItem.DropDownItemClicked += new System.Windows.Forms.ToolStripItemClickedEventHandler(this.treeContextMenu_ItemClicked); // // exportRawDataToolStripMenuItem // this.exportRawDataToolStripMenuItem.Name = "exportRawDataToolStripMenuItem"; - this.exportRawDataToolStripMenuItem.Size = new System.Drawing.Size(136, 24); + this.exportRawDataToolStripMenuItem.Size = new System.Drawing.Size(180, 24); this.exportRawDataToolStripMenuItem.Text = "Raw Data"; // // exportOGGToolStripMenuItem // this.exportOGGToolStripMenuItem.Name = "exportOGGToolStripMenuItem"; - this.exportOGGToolStripMenuItem.Size = new System.Drawing.Size(136, 24); + this.exportOGGToolStripMenuItem.Size = new System.Drawing.Size(180, 24); this.exportOGGToolStripMenuItem.Text = "OGG"; // // exportDDSToolStripMenuItem // this.exportDDSToolStripMenuItem.Name = "exportDDSToolStripMenuItem"; - this.exportDDSToolStripMenuItem.Size = new System.Drawing.Size(136, 24); + this.exportDDSToolStripMenuItem.Size = new System.Drawing.Size(180, 24); this.exportDDSToolStripMenuItem.Text = "DDS"; // // toolStripSeparator5 // this.toolStripSeparator5.Name = "toolStripSeparator5"; - this.toolStripSeparator5.Size = new System.Drawing.Size(157, 6); - // - // addToolStripMenuItem - // - this.addToolStripMenuItem.Enabled = false; - this.addToolStripMenuItem.Name = "addToolStripMenuItem"; - this.addToolStripMenuItem.Size = new System.Drawing.Size(160, 24); - this.addToolStripMenuItem.Text = "Add"; + this.toolStripSeparator5.Size = new System.Drawing.Size(177, 6); // // removeToolStripMenuItem // this.removeToolStripMenuItem.Name = "removeToolStripMenuItem"; - this.removeToolStripMenuItem.Size = new System.Drawing.Size(160, 24); + this.removeToolStripMenuItem.Size = new System.Drawing.Size(180, 24); this.removeToolStripMenuItem.Text = "Remove"; // // copyToolStripMenuItem // this.copyToolStripMenuItem.Name = "copyToolStripMenuItem"; - this.copyToolStripMenuItem.Size = new System.Drawing.Size(160, 24); + this.copyToolStripMenuItem.Size = new System.Drawing.Size(180, 24); this.copyToolStripMenuItem.Text = "Copy"; // // pasteToolStripMenuItem // this.pasteToolStripMenuItem.Name = "pasteToolStripMenuItem"; - this.pasteToolStripMenuItem.Size = new System.Drawing.Size(160, 24); + this.pasteToolStripMenuItem.Size = new System.Drawing.Size(180, 24); this.pasteToolStripMenuItem.Text = "Paste"; // // toolStripSeparator6 // this.toolStripSeparator6.Name = "toolStripSeparator6"; - this.toolStripSeparator6.Size = new System.Drawing.Size(157, 6); + this.toolStripSeparator6.Size = new System.Drawing.Size(177, 6); // // previewOGGToolStripMenuItem // this.previewOGGToolStripMenuItem.Name = "previewOGGToolStripMenuItem"; - this.previewOGGToolStripMenuItem.Size = new System.Drawing.Size(160, 24); + this.previewOGGToolStripMenuItem.Size = new System.Drawing.Size(180, 24); this.previewOGGToolStripMenuItem.Text = "Preview OGG"; // // menuStrip @@ -395,7 +390,7 @@ private void InitializeComponent() // this.loadMappingToolStripMenuItem.Name = "loadMappingToolStripMenuItem"; this.loadMappingToolStripMenuItem.Size = new System.Drawing.Size(236, 24); - this.loadMappingToolStripMenuItem.Text = "Load Mapping"; + this.loadMappingToolStripMenuItem.Text = "Load/Show Mapping"; this.loadMappingToolStripMenuItem.Click += new System.EventHandler(this.loadMappingToolStripMenuItem_Click); // // dumpCompositeTexturesToolStripMenuItem @@ -980,6 +975,19 @@ private void InitializeComponent() this.boxLog.TabIndex = 0; this.boxLog.Text = ""; // + // addToolStripMenuItem + // + this.addToolStripMenuItem.Enabled = false; + this.addToolStripMenuItem.Name = "addToolStripMenuItem"; + this.addToolStripMenuItem.Size = new System.Drawing.Size(180, 24); + this.addToolStripMenuItem.Text = "Add"; + // + // packageToolStripMenuItem + // + this.exportPackageToolStripMenuItem.Name = "packageToolStripMenuItem"; + this.exportPackageToolStripMenuItem.Size = new System.Drawing.Size(180, 24); + this.exportPackageToolStripMenuItem.Text = "Package"; + // // GUI // this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F); @@ -1101,7 +1109,6 @@ private void InitializeComponent() private ToolStripMenuItem exportOGGToolStripMenuItem; private ToolStripMenuItem exportDDSToolStripMenuItem; private ToolStripSeparator toolStripSeparator5; - private ToolStripMenuItem addToolStripMenuItem; private ToolStripMenuItem removeToolStripMenuItem; private ToolStripMenuItem copyToolStripMenuItem; private ToolStripMenuItem pasteToolStripMenuItem; @@ -1116,6 +1123,8 @@ private void InitializeComponent() private ToolStripMenuItem loadMappingToolStripMenuItem; private ToolStripMenuItem dumpCompositeTexturesToolStripMenuItem; private RichTextBox boxLog; + private ToolStripMenuItem exportPackageToolStripMenuItem; + private ToolStripMenuItem addToolStripMenuItem; } } diff --git a/GPK_RePack/Forms/GUI.cs b/GPK_RePack/Forms/GUI.cs index 96e58ea..2da66d7 100644 --- a/GPK_RePack/Forms/GUI.cs +++ b/GPK_RePack/Forms/GUI.cs @@ -10,6 +10,7 @@ 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; @@ -17,6 +18,7 @@ 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; @@ -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; @@ -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); @@ -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 @@ -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 classNodes = new Dictionary(); TreeNode nodeI = null; @@ -492,7 +475,7 @@ public void DrawPackages() } - + treeMain.Sort(); treeMain.EndUpdate(); } @@ -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) @@ -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) @@ -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> 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 @@ -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 } @@ -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) @@ -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(); + packages.Add(selectedPackage); + var writerList = new List(); + var taskList = new List(); + + this.gpkStore.SaveGpkListToFiles(packages, false, writerList, taskList); + //wait + while (!Task.WaitAll(taskList.ToArray(), 50)) + { + Application.DoEvents(); + } + logger.Info("Single export done!"); + } + } @@ -1992,7 +2030,7 @@ private void selectContextAction(object sender, ToolStripItemClickedEventArgs e) #endregion - + } } diff --git a/GPK_RePack/Forms/MapperView.Designer.cs b/GPK_RePack/Forms/MapperView.Designer.cs index 917a220..9a4098c 100644 --- a/GPK_RePack/Forms/MapperView.Designer.cs +++ b/GPK_RePack/Forms/MapperView.Designer.cs @@ -2,7 +2,7 @@ namespace GPK_RePack.Forms { - partial class formMapperView + partial class FormMapperView { /// /// Required designer variable. @@ -32,6 +32,7 @@ private void InitializeComponent() { this.splitContainer1 = new System.Windows.Forms.SplitContainer(); this.treeMapperView = new GPK_RePack.Forms.Helper.CompositeTreeView(); + this.btnDeleteMapping = new System.Windows.Forms.Button(); this.label1 = new System.Windows.Forms.Label(); this.boxSearch = new System.Windows.Forms.TextBox(); ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit(); @@ -53,6 +54,7 @@ private void InitializeComponent() // // splitContainer1.Panel2 // + this.splitContainer1.Panel2.Controls.Add(this.btnDeleteMapping); this.splitContainer1.Panel2.Controls.Add(this.label1); this.splitContainer1.Panel2.Controls.Add(this.boxSearch); this.splitContainer1.Size = new System.Drawing.Size(584, 480); @@ -68,6 +70,16 @@ private void InitializeComponent() this.treeMapperView.TabIndex = 0; this.treeMapperView.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.treeMapperView_AfterSelect); // + // btnDeleteMapping + // + this.btnDeleteMapping.Location = new System.Drawing.Point(478, 22); + this.btnDeleteMapping.Name = "btnDeleteMapping"; + this.btnDeleteMapping.Size = new System.Drawing.Size(106, 23); + this.btnDeleteMapping.TabIndex = 2; + this.btnDeleteMapping.Text = "Delete Mapping"; + this.btnDeleteMapping.UseVisualStyleBackColor = true; + this.btnDeleteMapping.Click += new System.EventHandler(this.btnDeleteMapping_Click); + // // label1 // this.label1.AutoSize = true; @@ -86,14 +98,14 @@ private void InitializeComponent() this.boxSearch.TabIndex = 0; this.boxSearch.TextChanged += new System.EventHandler(this.boxSearch_TextChanged); // - // formMapperView + // FormMapperView // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(584, 480); this.Controls.Add(this.splitContainer1); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.SizableToolWindow; - this.Name = "formMapperView"; + this.Name = "FormMapperView"; this.Text = "MapperView"; this.Load += new System.EventHandler(this.formMapperView_Load); this.splitContainer1.Panel1.ResumeLayout(false); @@ -111,5 +123,6 @@ private void InitializeComponent() private System.Windows.Forms.TextBox boxSearch; private CompositeTreeView treeMapperView; private System.Windows.Forms.Label label1; + private System.Windows.Forms.Button btnDeleteMapping; } } \ No newline at end of file diff --git a/GPK_RePack/Forms/MapperView.cs b/GPK_RePack/Forms/MapperView.cs index 69dfd4c..b1a90d3 100644 --- a/GPK_RePack/Forms/MapperView.cs +++ b/GPK_RePack/Forms/MapperView.cs @@ -15,11 +15,11 @@ namespace GPK_RePack.Forms { - partial class formMapperView : Form + partial class FormMapperView : Form { private GpkStore store; private Logger logger = LogManager.GetCurrentClassLogger(); - public formMapperView(GpkStore store) + public FormMapperView(GpkStore store) { InitializeComponent(); @@ -73,5 +73,12 @@ private void boxSearch_TextChanged(object sender, EventArgs e) { } + + private void btnDeleteMapping_Click(object sender, EventArgs e) + { + this.Close(); + this.store.clearCompositeMap(); + logger.Info("Deleted Mapping Cache"); + } } } diff --git a/GPK_RePack/Forms/NLogConfig.cs b/GPK_RePack/Forms/NLogConfig.cs index 808652c..57a80af 100644 --- a/GPK_RePack/Forms/NLogConfig.cs +++ b/GPK_RePack/Forms/NLogConfig.cs @@ -1,4 +1,5 @@ using System; +using System.Windows.Forms; using GPK_RePack.Properties; using NLog; using NLog.Config; @@ -11,32 +12,24 @@ namespace GPK_RePack.Forms class NLogConfig { private static FileTarget logfile; - private static AsyncTargetWrapper formTarget; private static LoggingRule fileLoggingRule; + private static LoggingRule formLoggingRule; public static void SetDefaultConfig() { LogManager.ThrowExceptions = true; - var config = new LoggingConfiguration(); - + var config = new LoggingConfiguration(); - //Targets - logfile = new FileTarget(); + //Targets + logfile = new FileTarget(); logfile.FileName = "Terahelper.log"; logfile.DeleteOldFileOnStartup = true; logfile.KeepFileOpen = true; AsyncTargetWrapper asyncWrapperLog = new AsyncTargetWrapper(logfile); config.AddTarget("logfile", asyncWrapperLog); - 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); + var formTarget = getFormTarget(); config.AddTarget("form", formTarget); //Rules @@ -56,10 +49,10 @@ public static void SetDefaultConfig() fileLoggingRule = new LoggingRule("*", level, asyncWrapperLog); config.LoggingRules.Add(fileLoggingRule); - var rule2 = new LoggingRule("*", LogLevel.Info, formTarget); - config.LoggingRules.Add(rule2); + formLoggingRule = new LoggingRule("*", LogLevel.Info, formTarget); + config.LoggingRules.Add(formLoggingRule); + - LogManager.Configuration = config; } @@ -88,11 +81,27 @@ public static void ReloadFileLoggingRule() public static void DisableFormLogging() { LogManager.Configuration.RemoveTarget("form"); + LogManager.Configuration.LoggingRules.Remove(formLoggingRule); } public static void EnableFormLogging() { - LogManager.Configuration.AddTarget("form", formTarget); + SetDefaultConfig(); } + + + private static AsyncTargetWrapper getFormTarget() + { + 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; + var formTarget = new AsyncTargetWrapper(formTargetSync); + + return formTarget; + } + } } diff --git a/GPK_RePack/IO/MassDumper.cs b/GPK_RePack/IO/MassDumper.cs index 0469527..fb0ffac 100644 --- a/GPK_RePack/IO/MassDumper.cs +++ b/GPK_RePack/IO/MassDumper.cs @@ -7,7 +7,9 @@ using System.Threading.Tasks; using System.Windows; using GPK_RePack.Editors; +using GPK_RePack.Forms; using GPK_RePack.Model; +using GPK_RePack.Model.Composite; using GPK_RePack.Model.Interfaces; using GPK_RePack.Model.Payload; using NLog; @@ -102,14 +104,14 @@ public static void DumpMassHeaders(String outfile, String[] gpkFiles) } - public static void DumpMassTextures(GpkStore store, String outdir) + public static void DumpMassTextures(GpkStore store, String outdir, Dictionary> filterList) { logger.Info("Started dumping textures to " + outdir); Directory.CreateDirectory(outdir); List runningTasks = new List(); - foreach (var file in store.CompositeMap) + foreach (var file in filterList) { var fileOutPath = string.Format("{0}\\{1}.gpk\\", outdir, file.Key); Directory.CreateDirectory(fileOutPath); @@ -157,6 +159,7 @@ public static void DumpMassTextures(GpkStore store, String outdir) Task.WaitAll(runningTasks.ToArray()); + NLogConfig.EnableFormLogging(); logger.Info("Dumping done"); } } diff --git a/GPK_RePack/Model/GpkStore.cs b/GPK_RePack/Model/GpkStore.cs index 7313d2c..e7d3977 100644 --- a/GPK_RePack/Model/GpkStore.cs +++ b/GPK_RePack/Model/GpkStore.cs @@ -1,23 +1,26 @@ using System; using System.Collections.Generic; +using System.Collections.Specialized; using System.Linq; using System.Runtime.InteropServices; using System.Text; using System.Threading.Tasks; using GPK_RePack.IO; using GPK_RePack.Model.Composite; +using GPK_RePack.Model.Interfaces; +using GPK_RePack.Properties; +using NLog; namespace GPK_RePack.Model { class GpkStore { + private static Logger logger = LogManager.GetCurrentClassLogger(); + public Dictionary> CompositeMap; public string BaseSearchPath; - public List LoadedGpkPackages { get; } = new List(); - - //events public delegate void GpkListChangeHandler(); public event GpkListChangeHandler PackagesChanged; @@ -27,8 +30,6 @@ public GpkStore() CompositeMap = new Dictionary>(); } - - public void loadGpk(string path, Reader reader = null, bool triggerEvent = true) { if (reader == null) @@ -40,11 +41,10 @@ public void loadGpk(string path, Reader reader = null, bool triggerEvent = true) LoadedGpkPackages.AddRange(gpks); - if (triggerEvent) + if (triggerEvent) PackagesChanged(); } - public void loadSubGpk(string path, string fileID, int fileOffset, int dataLength) { var reader = new Reader(); @@ -57,13 +57,37 @@ public void loadSubGpk(string path, string fileID, int fileOffset, int dataLengt PackagesChanged(); } + public void SaveGpkListToFiles(List saveList, bool usePadding, List runningSavers, List runningTasks) + { + + foreach (GpkPackage package in saveList) + { + try + { + Writer tmpS = new Writer(); + Task newTask = new Task(() => + { + 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!"); + } + + } + } + public void DeleteGpk(GpkPackage package) { LoadedGpkPackages.Remove(package); PackagesChanged(); } - public void clearGpkList() { LoadedGpkPackages.Clear(); @@ -71,6 +95,11 @@ public void clearGpkList() PackagesChanged(); } + public void clearCompositeMap() + { + CompositeMap = new Dictionary>(); + BaseSearchPath = ""; + } } diff --git a/GPK_RePack/Model/Payload/Texture2D.cs b/GPK_RePack/Model/Payload/Texture2D.cs index 7457950..a1764c6 100644 --- a/GPK_RePack/Model/Payload/Texture2D.cs +++ b/GPK_RePack/Model/Payload/Texture2D.cs @@ -69,7 +69,7 @@ public void WriteData(BinaryWriter writer, GpkPackage package, GpkExport export) int chunkSize = 16 + map.blocks.Count * 8 + map.compressedSize; if (chunkSize != map.compChunkSize) { - logger.Info("fixing chunksize for " + objectExport.ObjectName); + logger.Debug("fixing chunksize for " + objectExport.ObjectName); map.compChunkSize = chunkSize; } @@ -182,7 +182,7 @@ public void ReadData(GpkPackage package, GpkExport export) cacheReader.BaseStream.Seek(-4, SeekOrigin.Current); if (map.signature == MipMap.DEFAULT_SIGNATURE) { - ReadMipMapFromReader(cacheReader, map); + ReadMipMapFromReader(cacheReader, map, package); } cacheReader.Close(); @@ -200,7 +200,7 @@ public void ReadData(GpkPackage package, GpkExport export) else if (((CompressionTypes)map.flags & NothingToDo) == 0) { //normal in gpk data - ReadMipMapFromReader(reader, map); + ReadMipMapFromReader(reader, map, package); } else {