can choose the directory to save the extracted files

This commit is contained in:
Perfare 2020-08-10 14:07:29 +08:00
parent 8ce5b947f6
commit ec0a2a47f1
4 changed files with 72 additions and 62 deletions

View File

@ -109,7 +109,6 @@
this.toolStripStatusLabel1 = new System.Windows.Forms.ToolStripStatusLabel(); this.toolStripStatusLabel1 = new System.Windows.Forms.ToolStripStatusLabel();
this.timer = new System.Windows.Forms.Timer(this.components); this.timer = new System.Windows.Forms.Timer(this.components);
this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog(); this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
this.saveFileDialog1 = new System.Windows.Forms.SaveFileDialog();
this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components); this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components);
this.copyToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.copyToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.exportSelectedAssetsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.exportSelectedAssetsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
@ -901,11 +900,6 @@
this.openFileDialog1.Multiselect = true; this.openFileDialog1.Multiselect = true;
this.openFileDialog1.RestoreDirectory = true; this.openFileDialog1.RestoreDirectory = true;
// //
// saveFileDialog1
//
this.saveFileDialog1.Filter = "FBX file|*.fbx";
this.saveFileDialog1.RestoreDirectory = true;
//
// contextMenuStrip1 // contextMenuStrip1
// //
this.contextMenuStrip1.ImageScalingSize = new System.Drawing.Size(20, 20); this.contextMenuStrip1.ImageScalingSize = new System.Drawing.Size(20, 20);
@ -1052,7 +1046,6 @@
private System.Windows.Forms.ToolStripMenuItem extractFileToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem extractFileToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem extractFolderToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem extractFolderToolStripMenuItem;
private System.Windows.Forms.OpenFileDialog openFileDialog1; private System.Windows.Forms.OpenFileDialog openFileDialog1;
private System.Windows.Forms.SaveFileDialog saveFileDialog1;
private System.Windows.Forms.ToolStripMenuItem showExpOpt; private System.Windows.Forms.ToolStripMenuItem showExpOpt;
private GOHierarchy sceneTreeView; private GOHierarchy sceneTreeView;
private System.Windows.Forms.ToolStripMenuItem debugMenuItem; private System.Windows.Forms.ToolStripMenuItem debugMenuItem;

View File

@ -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) 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(); var openFolderDialog = new OpenFolderDialog();
if (openFolderDialog1.ShowDialog(this) == DialogResult.OK) if (openFolderDialog.ShowDialog(this) == DialogResult.OK)
{ {
var files = Directory.GetFiles(openFolderDialog1.Folder, "*.*", SearchOption.AllDirectories); var saveFolderDialog = new OpenFolderDialog();
ExtractFile(files); 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) if (animator != null)
{ {
var saveFolderDialog1 = new OpenFolderDialog(); var saveFolderDialog = new OpenFolderDialog();
if (saveFolderDialog1.ShowDialog(this) == DialogResult.OK) if (saveFolderDialog.ShowDialog(this) == DialogResult.OK)
{ {
var exportPath = saveFolderDialog1.Folder + "\\Animator\\"; var exportPath = saveFolderDialog.Folder + "\\Animator\\";
ExportAnimatorWithAnimationClip(animator, animationList, exportPath); ExportAnimatorWithAnimationClip(animator, animationList, exportPath);
} }
} }
@ -1301,10 +1316,10 @@ namespace AssetStudioGUI
{ {
if (sceneTreeView.Nodes.Count > 0) if (sceneTreeView.Nodes.Count > 0)
{ {
var saveFolderDialog1 = new OpenFolderDialog(); var saveFolderDialog = new OpenFolderDialog();
if (saveFolderDialog1.ShowDialog(this) == DialogResult.OK) if (saveFolderDialog.ShowDialog(this) == DialogResult.OK)
{ {
var exportPath = saveFolderDialog1.Folder + "\\GameObject\\"; var exportPath = saveFolderDialog.Folder + "\\GameObject\\";
List<AssetItem> animationList = null; List<AssetItem> animationList = null;
if (animation) if (animation)
{ {
@ -1419,10 +1434,10 @@ namespace AssetStudioGUI
{ {
if (sceneTreeView.Nodes.Count > 0) if (sceneTreeView.Nodes.Count > 0)
{ {
var saveFolderDialog1 = new OpenFolderDialog(); var saveFolderDialog = new OpenFolderDialog();
if (saveFolderDialog1.ShowDialog(this) == DialogResult.OK) if (saveFolderDialog.ShowDialog(this) == DialogResult.OK)
{ {
var savePath = saveFolderDialog1.Folder + Path.DirectorySeparatorChar; var savePath = saveFolderDialog.Folder + Path.DirectorySeparatorChar;
ExportSplitObjects(savePath, sceneTreeView.Nodes); ExportSplitObjects(savePath, sceneTreeView.Nodes);
} }
} }
@ -1479,8 +1494,8 @@ namespace AssetStudioGUI
{ {
if (exportableAssets.Count > 0) if (exportableAssets.Count > 0)
{ {
var saveFolderDialog1 = new OpenFolderDialog(); var saveFolderDialog = new OpenFolderDialog();
if (saveFolderDialog1.ShowDialog(this) == DialogResult.OK) if (saveFolderDialog.ShowDialog(this) == DialogResult.OK)
{ {
timer.Stop(); timer.Stop();
@ -1497,7 +1512,7 @@ namespace AssetStudioGUI
toExportAssets = visibleAssets; toExportAssets = visibleAssets;
break; break;
} }
Studio.ExportAssets(saveFolderDialog1.Folder, toExportAssets, exportType); Studio.ExportAssets(saveFolderDialog.Folder, toExportAssets, exportType);
} }
} }
else else

View File

@ -120,9 +120,6 @@
<metadata name="menuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> <metadata name="menuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>312, 17</value> <value>312, 17</value>
</metadata> </metadata>
<metadata name="statusStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>432, 17</value>
</metadata>
<data name="fontPreviewBox.Text" xml:space="preserve"> <data name="fontPreviewBox.Text" xml:space="preserve">
<value>abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWYZ <value>abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWYZ
1234567890.:,;'\"(!?)+-*/= 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</value> The quick brown fox jumps over the lazy dog. 1234567890</value>
</data> </data>
<metadata name="statusStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>432, 17</value>
</metadata>
<metadata name="timer.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> <metadata name="timer.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>553, 17</value> <value>553, 17</value>
</metadata> </metadata>
<metadata name="openFileDialog1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> <metadata name="openFileDialog1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>636, 17</value> <value>636, 17</value>
</metadata> </metadata>
<metadata name="saveFileDialog1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>784, 17</value>
</metadata>
<metadata name="contextMenuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> <metadata name="contextMenuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>147, 17</value> <value>147, 17</value>
</metadata> </metadata>

View File

@ -27,50 +27,52 @@ namespace AssetStudioGUI
public static List<AssetItem> visibleAssets = new List<AssetItem>(); public static List<AssetItem> visibleAssets = new List<AssetItem>();
internal static Action<string> StatusStripUpdate = x => { }; internal static Action<string> StatusStripUpdate = x => { };
public static void ExtractFile(string[] fileNames) public static int ExtractFolder(string path, string savePath)
{ {
ThreadPool.QueueUserWorkItem(state => var files = Directory.GetFiles(path, "*.*", SearchOption.AllDirectories);
{ return ExtractFile(files, savePath);
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.");
});
} }
private static int ExtractBundleFile(string bundleFileName, EndianBinaryReader reader) public static int ExtractFile(string[] fileNames, string savePath)
{ {
StatusStripUpdate($"Decompressing {Path.GetFileName(bundleFileName)} ..."); int extractedCount = 0;
var bundleFile = new BundleFile(reader, bundleFileName); 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(); reader.Dispose();
if (bundleFile.fileList.Length > 0) if (bundleFile.fileList.Length > 0)
{ {
var extractPath = bundleFileName + "_unpacked\\"; var extractPath = Path.Combine(savePath, Path.GetFileName(bundleFilePath) + "_unpacked");
return ExtractStreamFile(extractPath, bundleFile.fileList); return ExtractStreamFile(extractPath, bundleFile.fileList);
} }
return 0; 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); var webFile = new WebFile(reader);
reader.Dispose(); reader.Dispose();
if (webFile.fileList.Length > 0) if (webFile.fileList.Length > 0)
{ {
var extractPath = webFileName + "_unpacked\\"; var extractPath = Path.Combine(savePath, Path.GetFileName(webFilePath) + "_unpacked");
return ExtractStreamFile(extractPath, webFile.fileList); return ExtractStreamFile(extractPath, webFile.fileList);
} }
return 0; return 0;
@ -81,14 +83,17 @@ namespace AssetStudioGUI
int extractedCount = 0; int extractedCount = 0;
foreach (var file in fileList) foreach (var file in fileList)
{ {
var filePath = extractPath + file.fileName; var filePath = Path.Combine(extractPath, file.fileName);
if (!Directory.Exists(extractPath)) if (!Directory.Exists(extractPath))
{ {
Directory.CreateDirectory(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; extractedCount += 1;
} }
file.stream.Dispose(); file.stream.Dispose();