Skip to content

Commit

Permalink
speed up raw data bulk export
Browse files Browse the repository at this point in the history
  • Loading branch information
4sval committed Dec 29, 2022
1 parent 944f77c commit 9cf6c32
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
28 changes: 20 additions & 8 deletions FModel/ViewModels/CUE4ParseViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,15 @@ private void BulkFolder(CancellationToken cancellationToken, TreeItem folder, Ac
}

public void ExportFolder(CancellationToken cancellationToken, TreeItem folder)
=> BulkFolder(cancellationToken, folder, asset => ExportData(asset.FullPath));
{
Parallel.ForEach(folder.AssetsList.Assets, asset =>
{
cancellationToken.ThrowIfCancellationRequested();
ExportData(asset.FullPath, false);
});

foreach (var f in folder.Folders) ExportFolder(cancellationToken, f);
}

public void ExtractFolder(CancellationToken cancellationToken, TreeItem folder)
=> BulkFolder(cancellationToken, folder, asset => Extract(cancellationToken, asset.FullPath, TabControl.HasNoTabs));
Expand Down Expand Up @@ -899,23 +907,27 @@ private void SaveExport(UObject export, bool auto)
}
}

public void ExportData(string fullPath)
public void ExportData(string fullPath, bool updateUi = true)
{
var fileName = fullPath.SubstringAfterLast('/');
if (Provider.TrySavePackage(fullPath, out var assets))
{
foreach (var kvp in assets)
Parallel.ForEach(assets, kvp =>
{
var path = Path.Combine(UserSettings.Default.RawDataDirectory, UserSettings.Default.KeepDirectoryStructure ? kvp.Key : kvp.Key.SubstringAfterLast('/')).Replace('\\', '/');
Directory.CreateDirectory(path.SubstringBeforeLast('/'));
File.WriteAllBytes(path, kvp.Value);
}
});

Log.Information("{FileName} successfully exported", fileName);
FLogger.AppendInformation();
FLogger.AppendText($"Successfully exported '{fileName}'", Constants.WHITE, true);
if (updateUi)
{
Log.Information("{FileName} successfully exported", fileName);
FLogger.AppendInformation();
FLogger.AppendText($"Successfully exported '{fileName}'", Constants.WHITE, true);
}
else ApplicationService.ApplicationView.Status.UpdateStatusLabel($"Raw Data for {fullPath.SubstringAfterLast('/')}");
}
else
else if (updateUi)
{
Log.Error("{FileName} could not be exported", fileName);
FLogger.AppendError();
Expand Down

0 comments on commit 9cf6c32

Please sign in to comment.