From c8539cb80456ab83cf98b0001fd32e570068820b Mon Sep 17 00:00:00 2001 From: Asval Date: Wed, 5 Aug 2026 13:30:41 +0200 Subject: [PATCH] log results if export immediately --- CUE4Parse | 2 +- FModel/Settings/UserSettings.cs | 4 +- FModel/ViewModels/ExportOptionsViewModel.cs | 4 +- FModel/ViewModels/ExportSessionViewModel.cs | 86 +++++++++++++++++-- FModel/ViewModels/TabControlViewModel.cs | 2 +- .../Controls/ExportOptionsControl.xaml | 24 ++++-- FModel/Views/Snooper/Options.cs | 2 +- 7 files changed, 104 insertions(+), 20 deletions(-) diff --git a/CUE4Parse b/CUE4Parse index 7afcbb32..9ea4df65 160000 --- a/CUE4Parse +++ b/CUE4Parse @@ -1 +1 @@ -Subproject commit 7afcbb323c9fd9445d5452856b18b1d732d2dccd +Subproject commit 9ea4df652f1ce14684797d9e635c2984b30d3c26 diff --git a/FModel/Settings/UserSettings.cs b/FModel/Settings/UserSettings.cs index f937b6d2..d9527db6 100644 --- a/FModel/Settings/UserSettings.cs +++ b/FModel/Settings/UserSettings.cs @@ -64,12 +64,12 @@ public sealed class UserSettings : ViewModel Default.TextureExportFormat, Default.TextureQuality, Default.SaveHdrTexturesAsHdr, + Default.ExportAllTextureMips, Default.MaterialExportFormat, Default.SaveEmbeddedMaterials, Default.SaveMorphTargets, Default.SocketExportFormat, - Default.CompressionFormat, - Default.ExportAllTextureMips + Default.CompressionFormat ); } diff --git a/FModel/ViewModels/ExportOptionsViewModel.cs b/FModel/ViewModels/ExportOptionsViewModel.cs index 5f41ed1b..b22638db 100644 --- a/FModel/ViewModels/ExportOptionsViewModel.cs +++ b/FModel/ViewModels/ExportOptionsViewModel.cs @@ -228,11 +228,11 @@ public class ExportOptionsViewModel : ViewModel SelectedTextureFormat, TextureQuality, ExportHdrTexturesAsHdr, + ExportAllTextureMips, SelectedMaterialDepth, ExportMaterials, ExportMorphTargets, SelectedSocketFormat, - SelectedCompressionFormat, - ExportAllTextureMips + SelectedCompressionFormat ); } diff --git a/FModel/ViewModels/ExportSessionViewModel.cs b/FModel/ViewModels/ExportSessionViewModel.cs index 6d225ef1..4559463a 100644 --- a/FModel/ViewModels/ExportSessionViewModel.cs +++ b/FModel/ViewModels/ExportSessionViewModel.cs @@ -1,8 +1,10 @@ using System; using System.Collections.Concurrent; +using System.Collections.Generic; using System.Collections.ObjectModel; using System.ComponentModel; using System.Diagnostics; +using System.IO; using System.Linq; using System.Threading; using System.Threading.Tasks; @@ -15,6 +17,7 @@ using FModel.Extensions; using FModel.Framework; using FModel.Settings; using FModel.Views; +using FModel.Views.Resources.Controls; using FModel.Views.Snooper; using Serilog.Events; @@ -175,9 +178,9 @@ public class ExportSessionViewModel : ViewModel }); } - public async Task ExportAsync() + public async Task> ExportAsync() { - if (IsRunning || Session.TotalQueued == 0) return; + if (IsRunning || Session.TotalQueued == 0) return null; IsRunning = true; IsFinished = false; @@ -218,9 +221,10 @@ public class ExportSessionViewModel : ViewModel }); }); + IReadOnlyList results = null; try { - await Session.RunAsync(exportDirectory, exportOptions, progress, _cts.Token).ConfigureAwait(false); + results = await Session.RunAsync(exportDirectory, exportOptions, progress, _cts.Token).ConfigureAwait(false); } catch (OperationCanceledException) { @@ -237,14 +241,86 @@ public class ExportSessionViewModel : ViewModel UpdateElapsedAndEta(); }); } + return results; } public async Task ExportAutomaticallyAsync() { - if (UserSettings.Default.ExportImmediately) + if (!UserSettings.Default.ExportImmediately) return; + + var results = await ExportAsync(); + if (results is { Count: > 0 }) LogSummary(results); + } + + private static void LogSummary(IReadOnlyList results) + { + if (results.Count == 1) { - await ExportAsync(); + var result = results[0]; + switch (result.Success) + { + case true when result.DiskFilePaths is { Count: > 0 } files: + FLogger.Append(ELog.Information, () => + { + FLogger.Text("Successfully exported ", Constants.WHITE); + FLogger.Link(Path.GetFileName(files[0]), files[0], true); + }); + break; + case false when result.Error is { } exception: + FLogger.Append(exception); + break; + } + return; } + + var failed = 0; + var groups = new Dictionary(StringComparer.OrdinalIgnoreCase); + + foreach (var result in results) + { + if (!result.Success) + { + failed++; + continue; + } + + if (result.DiskFilePaths == null) continue; + + foreach (var file in result.DiskFilePaths) + { + var extension = Path.GetExtension(file).TrimStart('.'); + var source = SplitDirectory(result.ObjectPath); + var directory = SplitDirectory(file); + groups[extension] = groups.TryGetValue(extension, out var group) + ? (group.Count + 1, CommonPrefix(group.Source, source), CommonPrefix(group.Directory, directory)) + : (1, source, directory); + } + } + + foreach (var (extension, group) in groups) + { + var source = string.Join('/', group.Source); + var directory = string.Join(Path.DirectorySeparatorChar, group.Directory); + FLogger.Append(ELog.Information, () => + { + FLogger.Text($"Successfully exported {group.Count} {extension} from ", Constants.WHITE); + if (directory.Length > 0) FLogger.Link(source, directory, true); + else FLogger.Text(source, Constants.WHITE, true); + }); + } + + if (failed > 0) + { + FLogger.Append(ELog.Error, () => FLogger.Text($"Failed to export {failed} asset{(failed == 1 ? "" : "s")}", Constants.WHITE, true)); + } + } + + private static string[] SplitDirectory(string path) => Path.GetDirectoryName(path)?.Split(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar) ?? []; + private static string[] CommonPrefix(string[] a, string[] b) + { + var i = 0; + while (i < a.Length && i < b.Length && string.Equals(a[i], b[i], StringComparison.OrdinalIgnoreCase)) i++; + return i == a.Length ? a : a[..i]; } public void CancelExport() diff --git a/FModel/ViewModels/TabControlViewModel.cs b/FModel/ViewModels/TabControlViewModel.cs index 481e52be..ad8abe95 100644 --- a/FModel/ViewModels/TabControlViewModel.cs +++ b/FModel/ViewModels/TabControlViewModel.cs @@ -294,7 +294,7 @@ public class TabItem : ViewModel var img = new CTexture[1]; if (texture is UTexture2DArray textureArray) { - img = textureArray.DecodeTextureArray(UserSettings.Default.CurrentDir.TexturePlatform); + img = textureArray.DecodeTextureArray(null, UserSettings.Default.CurrentDir.TexturePlatform); appendLayerNumber = true; } else diff --git a/FModel/Views/Resources/Controls/ExportOptionsControl.xaml b/FModel/Views/Resources/Controls/ExportOptionsControl.xaml index 6ca6a7f4..e0c696c4 100644 --- a/FModel/Views/Resources/Controls/ExportOptionsControl.xaml +++ b/FModel/Views/Resources/Controls/ExportOptionsControl.xaml @@ -47,14 +47,22 @@