From a7e9479eab3f0611a80c6c47e320f6f98824a69c Mon Sep 17 00:00:00 2001 From: Mbucari <37587114+Mbucari@users.noreply.github.com> Date: Sat, 6 Dec 2025 10:40:02 -0700 Subject: [PATCH 1/2] Fix file utility modifying file extension using replacement character The file extension should not be subject to renaming. #1483 --- Source/FileManager/FileUtility.cs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/Source/FileManager/FileUtility.cs b/Source/FileManager/FileUtility.cs index 387178a1..484ed1a8 100644 --- a/Source/FileManager/FileUtility.cs +++ b/Source/FileManager/FileUtility.cs @@ -56,15 +56,18 @@ namespace FileManager fileExtension = GetStandardizedExtension(fileExtension); - // remove invalid chars - path = GetSafePath(path, replacements); + var pathStr = removeInvalidWhitespace(path.Path); + var pathWithoutExtension = pathStr.EndsWithInsensitive(fileExtension) + ? pathStr[..^fileExtension.Length] + : path.Path; + + // remove invalid chars, but leave file extension untouched + pathWithoutExtension = GetSafePath(pathWithoutExtension, replacements); // ensure uniqueness and check lengths - var dir = Path.GetDirectoryName(path)?.TruncateFilename(LongPath.MaxDirectoryLength) ?? string.Empty; + var dir = Path.GetDirectoryName(pathWithoutExtension)?.TruncateFilename(LongPath.MaxDirectoryLength) ?? string.Empty; - var fileName = Path.GetFileName(path); - var extIndex = fileName.LastIndexOf(fileExtension, StringComparison.OrdinalIgnoreCase); - var filenameWithoutExtension = extIndex >= 0 ? fileName.Remove(extIndex, fileExtension.Length) : fileName; + var filenameWithoutExtension = Path.GetFileName(pathWithoutExtension); var fileStem = Path.Combine(dir, filenameWithoutExtension.TruncateFilename(LongPath.MaxFilenameLength - fileExtension.Length)) .TruncateFilename(LongPath.MaxPathLength - fileExtension.Length); From 9545b3a874ab2617e1a5c84300d8bb18030adf81 Mon Sep 17 00:00:00 2001 From: Mbucari <37587114+Mbucari@users.noreply.github.com> Date: Sat, 6 Dec 2025 18:55:38 -0700 Subject: [PATCH 2/2] Invoke MessageBox on UI thread --- Source/LibationAvalonia/MessageBox.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Source/LibationAvalonia/MessageBox.cs b/Source/LibationAvalonia/MessageBox.cs index cbc56e94..34db9730 100644 --- a/Source/LibationAvalonia/MessageBox.cs +++ b/Source/LibationAvalonia/MessageBox.cs @@ -90,6 +90,7 @@ namespace LibationAvalonia /// The text to display in the title bar of the message box. /// Exception to log. public static async Task ShowAdminAlert(Window? owner, string text, string caption, Exception exception) + => await Dispatcher.UIThread.InvokeAsync(async () => { // for development and debugging, show me what broke! if (System.Diagnostics.Debugger.IsAttached) @@ -105,7 +106,7 @@ namespace LibationAvalonia var form = new MessageBoxAlertAdminDialog(text, caption, exception); await DisplayWindow(form, owner); - } + }); private static async Task ShowCoreAsync(Window? owner, string message, string caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton, bool saveAndRestorePosition = true) => await Dispatcher.UIThread.InvokeAsync(async () =>