From ec0a2a47f1f1add9fc73a1e967b8f8fcd62fb45d Mon Sep 17 00:00:00 2001 From: Perfare Date: Mon, 10 Aug 2020 14:07:29 +0800 Subject: [PATCH] can choose the directory to save the extracted files --- AssetStudioGUI/AssetStudioGUIForm.Designer.cs | 7 -- AssetStudioGUI/AssetStudioGUIForm.cs | 53 +++++++++------ AssetStudioGUI/AssetStudioGUIForm.resx | 9 +-- AssetStudioGUI/Studio.cs | 65 ++++++++++--------- 4 files changed, 72 insertions(+), 62 deletions(-) diff --git a/AssetStudioGUI/AssetStudioGUIForm.Designer.cs b/AssetStudioGUI/AssetStudioGUIForm.Designer.cs index 45652ce..a68e0a2 100644 --- a/AssetStudioGUI/AssetStudioGUIForm.Designer.cs +++ b/AssetStudioGUI/AssetStudioGUIForm.Designer.cs @@ -109,7 +109,6 @@ this.toolStripStatusLabel1 = new System.Windows.Forms.ToolStripStatusLabel(); this.timer = new System.Windows.Forms.Timer(this.components); this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog(); - this.saveFileDialog1 = new System.Windows.Forms.SaveFileDialog(); this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components); this.copyToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.exportSelectedAssetsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); @@ -901,11 +900,6 @@ this.openFileDialog1.Multiselect = true; this.openFileDialog1.RestoreDirectory = true; // - // saveFileDialog1 - // - this.saveFileDialog1.Filter = "FBX file|*.fbx"; - this.saveFileDialog1.RestoreDirectory = true; - // // contextMenuStrip1 // this.contextMenuStrip1.ImageScalingSize = new System.Drawing.Size(20, 20); @@ -1052,7 +1046,6 @@ private System.Windows.Forms.ToolStripMenuItem extractFileToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem extractFolderToolStripMenuItem; private System.Windows.Forms.OpenFileDialog openFileDialog1; - private System.Windows.Forms.SaveFileDialog saveFileDialog1; private System.Windows.Forms.ToolStripMenuItem showExpOpt; private GOHierarchy sceneTreeView; private System.Windows.Forms.ToolStripMenuItem debugMenuItem; diff --git a/AssetStudioGUI/AssetStudioGUIForm.cs b/AssetStudioGUI/AssetStudioGUIForm.cs index 5d3e170..be1b5ec 100644 --- a/AssetStudioGUI/AssetStudioGUIForm.cs +++ b/AssetStudioGUI/AssetStudioGUIForm.cs @@ -150,21 +150,36 @@ namespace AssetStudioGUI } } - private void extractFileToolStripMenuItem_Click(object sender, EventArgs e) + private async void extractFileToolStripMenuItem_Click(object sender, EventArgs e) { if (openFileDialog1.ShowDialog() == DialogResult.OK) { - ExtractFile(openFileDialog1.FileNames); + var saveFolderDialog = new OpenFolderDialog(); + saveFolderDialog.Title = "Select the save folder"; + if (saveFolderDialog.ShowDialog(this) == DialogResult.OK) + { + var fileNames = openFileDialog1.FileNames; + var savePath = saveFolderDialog.Folder; + var extractedCount = await Task.Run(() => ExtractFile(fileNames, savePath)); + StatusStripUpdate($"Finished extracting {extractedCount} files."); + } } } - private void extractFolderToolStripMenuItem_Click(object sender, EventArgs e) + private async void extractFolderToolStripMenuItem_Click(object sender, EventArgs e) { - var openFolderDialog1 = new OpenFolderDialog(); - if (openFolderDialog1.ShowDialog(this) == DialogResult.OK) + var openFolderDialog = new OpenFolderDialog(); + if (openFolderDialog.ShowDialog(this) == DialogResult.OK) { - var files = Directory.GetFiles(openFolderDialog1.Folder, "*.*", SearchOption.AllDirectories); - ExtractFile(files); + var saveFolderDialog = new OpenFolderDialog(); + saveFolderDialog.Title = "Select the save folder"; + if (saveFolderDialog.ShowDialog(this) == DialogResult.OK) + { + var path = openFolderDialog.Folder; + var savePath = saveFolderDialog.Folder; + var extractedCount = await Task.Run(() => ExtractFolder(path, savePath)); + StatusStripUpdate($"Finished extracting {extractedCount} files."); + } } } @@ -1278,10 +1293,10 @@ namespace AssetStudioGUI if (animator != null) { - var saveFolderDialog1 = new OpenFolderDialog(); - if (saveFolderDialog1.ShowDialog(this) == DialogResult.OK) + var saveFolderDialog = new OpenFolderDialog(); + if (saveFolderDialog.ShowDialog(this) == DialogResult.OK) { - var exportPath = saveFolderDialog1.Folder + "\\Animator\\"; + var exportPath = saveFolderDialog.Folder + "\\Animator\\"; ExportAnimatorWithAnimationClip(animator, animationList, exportPath); } } @@ -1301,10 +1316,10 @@ namespace AssetStudioGUI { if (sceneTreeView.Nodes.Count > 0) { - var saveFolderDialog1 = new OpenFolderDialog(); - if (saveFolderDialog1.ShowDialog(this) == DialogResult.OK) + var saveFolderDialog = new OpenFolderDialog(); + if (saveFolderDialog.ShowDialog(this) == DialogResult.OK) { - var exportPath = saveFolderDialog1.Folder + "\\GameObject\\"; + var exportPath = saveFolderDialog.Folder + "\\GameObject\\"; List animationList = null; if (animation) { @@ -1419,10 +1434,10 @@ namespace AssetStudioGUI { if (sceneTreeView.Nodes.Count > 0) { - var saveFolderDialog1 = new OpenFolderDialog(); - if (saveFolderDialog1.ShowDialog(this) == DialogResult.OK) + var saveFolderDialog = new OpenFolderDialog(); + if (saveFolderDialog.ShowDialog(this) == DialogResult.OK) { - var savePath = saveFolderDialog1.Folder + Path.DirectorySeparatorChar; + var savePath = saveFolderDialog.Folder + Path.DirectorySeparatorChar; ExportSplitObjects(savePath, sceneTreeView.Nodes); } } @@ -1479,8 +1494,8 @@ namespace AssetStudioGUI { if (exportableAssets.Count > 0) { - var saveFolderDialog1 = new OpenFolderDialog(); - if (saveFolderDialog1.ShowDialog(this) == DialogResult.OK) + var saveFolderDialog = new OpenFolderDialog(); + if (saveFolderDialog.ShowDialog(this) == DialogResult.OK) { timer.Stop(); @@ -1497,7 +1512,7 @@ namespace AssetStudioGUI toExportAssets = visibleAssets; break; } - Studio.ExportAssets(saveFolderDialog1.Folder, toExportAssets, exportType); + Studio.ExportAssets(saveFolderDialog.Folder, toExportAssets, exportType); } } else diff --git a/AssetStudioGUI/AssetStudioGUIForm.resx b/AssetStudioGUI/AssetStudioGUIForm.resx index f5d72e1..3965e61 100644 --- a/AssetStudioGUI/AssetStudioGUIForm.resx +++ b/AssetStudioGUI/AssetStudioGUIForm.resx @@ -120,9 +120,6 @@ 312, 17 - - 432, 17 - abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWYZ 1234567890.:,;'\"(!?)+-*/= @@ -141,15 +138,15 @@ The quick brown fox jumps over the lazy dog. 1234567890 The quick brown fox jumps over the lazy dog. 1234567890 + + 432, 17 + 553, 17 636, 17 - - 784, 17 - 147, 17 diff --git a/AssetStudioGUI/Studio.cs b/AssetStudioGUI/Studio.cs index 2d7b1d1..e377198 100644 --- a/AssetStudioGUI/Studio.cs +++ b/AssetStudioGUI/Studio.cs @@ -27,50 +27,52 @@ namespace AssetStudioGUI public static List visibleAssets = new List(); internal static Action StatusStripUpdate = x => { }; - public static void ExtractFile(string[] fileNames) + public static int ExtractFolder(string path, string savePath) { - ThreadPool.QueueUserWorkItem(state => - { - int extractedCount = 0; - Progress.Reset(); - for (var i = 0; i < fileNames.Length; i++) - { - var fileName = fileNames[i]; - var type = ImportHelper.CheckFileType(fileName, out var reader); - if (type == FileType.BundleFile) - extractedCount += ExtractBundleFile(fileName, reader); - else if (type == FileType.WebFile) - extractedCount += ExtractWebDataFile(fileName, reader); - else - reader.Dispose(); - Progress.Report(i + 1, fileNames.Length); - } - - StatusStripUpdate($"Finished extracting {extractedCount} files."); - }); + var files = Directory.GetFiles(path, "*.*", SearchOption.AllDirectories); + return ExtractFile(files, savePath); } - private static int ExtractBundleFile(string bundleFileName, EndianBinaryReader reader) + public static int ExtractFile(string[] fileNames, string savePath) { - StatusStripUpdate($"Decompressing {Path.GetFileName(bundleFileName)} ..."); - var bundleFile = new BundleFile(reader, bundleFileName); + int extractedCount = 0; + Progress.Reset(); + for (var i = 0; i < fileNames.Length; i++) + { + var fileName = fileNames[i]; + var type = ImportHelper.CheckFileType(fileName, out var reader); + if (type == FileType.BundleFile) + extractedCount += ExtractBundleFile(fileName, reader, savePath); + else if (type == FileType.WebFile) + extractedCount += ExtractWebDataFile(fileName, reader, savePath); + else + reader.Dispose(); + Progress.Report(i + 1, fileNames.Length); + } + return extractedCount; + } + + private static int ExtractBundleFile(string bundleFilePath, EndianBinaryReader reader, string savePath) + { + StatusStripUpdate($"Decompressing {Path.GetFileName(bundleFilePath)} ..."); + var bundleFile = new BundleFile(reader, bundleFilePath); reader.Dispose(); if (bundleFile.fileList.Length > 0) { - var extractPath = bundleFileName + "_unpacked\\"; + var extractPath = Path.Combine(savePath, Path.GetFileName(bundleFilePath) + "_unpacked"); return ExtractStreamFile(extractPath, bundleFile.fileList); } return 0; } - private static int ExtractWebDataFile(string webFileName, EndianBinaryReader reader) + private static int ExtractWebDataFile(string webFilePath, EndianBinaryReader reader, string savePath) { - StatusStripUpdate($"Decompressing {Path.GetFileName(webFileName)} ..."); + StatusStripUpdate($"Decompressing {Path.GetFileName(webFilePath)} ..."); var webFile = new WebFile(reader); reader.Dispose(); if (webFile.fileList.Length > 0) { - var extractPath = webFileName + "_unpacked\\"; + var extractPath = Path.Combine(savePath, Path.GetFileName(webFilePath) + "_unpacked"); return ExtractStreamFile(extractPath, webFile.fileList); } return 0; @@ -81,14 +83,17 @@ namespace AssetStudioGUI int extractedCount = 0; foreach (var file in fileList) { - var filePath = extractPath + file.fileName; + var filePath = Path.Combine(extractPath, file.fileName); if (!Directory.Exists(extractPath)) { Directory.CreateDirectory(extractPath); } - if (!File.Exists(filePath) && file.stream is MemoryStream stream) + if (!File.Exists(filePath)) { - File.WriteAllBytes(filePath, stream.ToArray()); + using (var fileStream = File.Create(filePath)) + { + file.stream.CopyTo(fileStream); + } extractedCount += 1; } file.stream.Dispose();