Skip to content

Commit

Permalink
[GUI] Improve file and folder loading (drag&drop)
Browse files Browse the repository at this point in the history
- Added support for drag&drop of multiple folders
- Open/Export dialog can now also use a path taken from drag&drop items
  • Loading branch information
aelurum committed May 29, 2023
1 parent b7d5d73 commit 2f8f57c
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 29 deletions.
52 changes: 43 additions & 9 deletions AssetStudio/AssetsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,53 @@ public void SetAssetFilter(List<ClassIDType> classIDTypeList)
SetAssetFilter(classIDType);
}

public void LoadFiles(params string[] files)
public void LoadFilesAndFolders(params string[] path)
{
var path = Path.GetDirectoryName(Path.GetFullPath(files[0]));
MergeSplitAssets(path);
var toReadFile = ProcessingSplitFiles(files.ToList());
Load(toReadFile);
List<string> pathList = new List<string>();
pathList.AddRange(path);
LoadFilesAndFolders(out _, pathList);
}

public void LoadFilesAndFolders(out string parentPath, params string[] path)
{
List<string> pathList = new List<string>();
pathList.AddRange(path);
LoadFilesAndFolders(out parentPath, pathList);
}

public void LoadFolder(string path)
public void LoadFilesAndFolders(out string parentPath, List<string> pathList)
{
MergeSplitAssets(path, true);
var files = Directory.GetFiles(path, "*.*", SearchOption.AllDirectories).ToList();
var toReadFile = ProcessingSplitFiles(files);
List<string> fileList = new List<string>();
bool filesInPath = false;
parentPath = "";
foreach (var path in pathList)
{
var fullPath = Path.GetFullPath(path);
if (Directory.Exists(fullPath))
{
var parent = Directory.GetParent(fullPath).FullName;
if (!filesInPath && (parentPath == "" || parentPath.Length > parent.Length))
{
parentPath = parent;
}
MergeSplitAssets(fullPath, true);
fileList.AddRange(Directory.GetFiles(fullPath, "*.*", SearchOption.AllDirectories));
}
else
{
parentPath = Path.GetDirectoryName(fullPath);
fileList.Add(fullPath);
filesInPath = true;
}
}
if (filesInPath)
{
MergeSplitAssets(parentPath);
}
var toReadFile = ProcessingSplitFiles(fileList);
fileList.Clear();
pathList.Clear();

Load(toReadFile);
}

Expand Down
9 changes: 1 addition & 8 deletions AssetStudioCLI/Studio.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,7 @@ public bool LoadAssets()
assetsManager.SpecifyUnityVersion = options.o_unityVersion.Value;
assetsManager.SetAssetFilter(options.o_exportAssetTypes.Value);

if (Directory.Exists(options.inputPath))
{
assetsManager.LoadFolder(options.inputPath);
}
else
{
assetsManager.LoadFiles(options.inputPath);
}
assetsManager.LoadFilesAndFolders(options.inputPath);
if (assetsManager.assetsFileList.Count == 0)
{
Logger.Warning("No Unity file can be loaded.");
Expand Down
16 changes: 4 additions & 12 deletions AssetStudioGUI/AssetStudioGUIForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,14 +143,8 @@ private async void AssetStudioGUIForm_DragDrop(object sender, DragEventArgs e)
{
ResetForm();
assetsManager.SpecifyUnityVersion = specifyUnityVersion.Text;
if (paths.Length == 1 && Directory.Exists(paths[0]))
{
await Task.Run(() => assetsManager.LoadFolder(paths[0]));
}
else
{
await Task.Run(() => assetsManager.LoadFiles(paths));
}
await Task.Run(() => assetsManager.LoadFilesAndFolders(out openDirectoryBackup, paths));
saveDirectoryBackup = openDirectoryBackup;
BuildAssetStructures();
}
}
Expand All @@ -161,9 +155,8 @@ private async void loadFile_Click(object sender, EventArgs e)
if (openFileDialog1.ShowDialog(this) == DialogResult.OK)
{
ResetForm();
openDirectoryBackup = Path.GetDirectoryName(openFileDialog1.FileNames[0]);
assetsManager.SpecifyUnityVersion = specifyUnityVersion.Text;
await Task.Run(() => assetsManager.LoadFiles(openFileDialog1.FileNames));
await Task.Run(() => assetsManager.LoadFilesAndFolders(out openDirectoryBackup, openFileDialog1.FileNames));
BuildAssetStructures();
}
}
Expand All @@ -175,9 +168,8 @@ private async void loadFolder_Click(object sender, EventArgs e)
if (openFolderDialog.ShowDialog(this) == DialogResult.OK)
{
ResetForm();
openDirectoryBackup = openFolderDialog.Folder;
assetsManager.SpecifyUnityVersion = specifyUnityVersion.Text;
await Task.Run(() => assetsManager.LoadFolder(openFolderDialog.Folder));
await Task.Run(() => assetsManager.LoadFilesAndFolders(out openDirectoryBackup, openFolderDialog.Folder));
BuildAssetStructures();
}
}
Expand Down

0 comments on commit 2f8f57c

Please sign in to comment.