SHA256
Fix Linux Folder Dialog Reopening After Cancel
This commit is contained in:
1 file changed
+12
-8
@@ -18,8 +18,8 @@ namespace ADOFAIRenderer.Util.OS;
|
||||
/// </para>
|
||||
/// <para>- <b>macOS</b>: <c>osascript</c> running AppleScript <c>choose folder</c>.</para>
|
||||
/// <para>
|
||||
/// - <b>Linux</b>: <c>zenity --file-selection --directory</c>; when zenity does not return an existing directory (not installed,
|
||||
/// cancelled or failed), <c>kdialog --getexistingdirectory</c>.
|
||||
/// - <b>Linux</b>: <c>zenity --file-selection --directory</c>; when zenity is not installed or fails (exit code other than 0
|
||||
/// or 1), <c>kdialog --getexistingdirectory</c>. A cancelled zenity dialog (exit code 1) ends the selection.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// The dialog runs off the main Unity thread so the game keeps rendering frames while it is open. Only one dialog can be open
|
||||
@@ -688,13 +688,13 @@ internal static class FolderDialogUtil
|
||||
|
||||
/// <summary>
|
||||
/// Runs <c>zenity --file-selection --directory --title=... [--filename=initialDirectory]</c> and blocks until it exits.
|
||||
/// When zenity cannot be started, exits with a non-zero code (cancel or error) or prints a path that is not an existing
|
||||
/// directory, runs <c>kdialog --getexistingdirectory [initialDirectory] --title ...</c> instead. Both commands print the
|
||||
/// Exit code 0 returns the printed path when it is an existing directory, and exit code 1 (cancelled or closed) returns null
|
||||
/// without opening a second dialog. When zenity cannot be started or exits with any other code, runs <c>kdialog --getexistingdirectory [initialDirectory] --title ...</c> instead. Both commands print the
|
||||
/// selected path to standard output.
|
||||
/// </summary>
|
||||
/// <param name="initialDirectory">Folder shown first; used only when it is an existing directory.</param>
|
||||
/// <returns>
|
||||
/// The selected existing directory; null when both dialogs return nothing, when kdialog cannot be started, or on an
|
||||
/// The selected existing directory; null when the dialog is cancelled, when kdialog cannot be started, or on an
|
||||
/// exception (logged as a warning).
|
||||
/// </returns>
|
||||
private static string? OpenLinuxFolderBrowser(string initialDirectory)
|
||||
@@ -725,15 +725,19 @@ internal static class FolderDialogUtil
|
||||
var output = process.StandardOutput.ReadToEnd().Trim();
|
||||
process.WaitForExit();
|
||||
|
||||
if (process.ExitCode == 0 && !string.IsNullOrEmpty(output) && Directory.Exists(output))
|
||||
if (process.ExitCode == 0)
|
||||
{
|
||||
return output;
|
||||
return !string.IsNullOrEmpty(output) && Directory.Exists(output) ? output : null;
|
||||
}
|
||||
|
||||
// zenity exit code 1: the dialog was cancelled or closed.
|
||||
// Reference: https://gitlab.gnome.org/GNOME/zenity/-/raw/master/src/util.c (ZENITY_OK_DEFAULT 0, ZENITY_CANCEL_DEFAULT 1, ZENITY_ESC_DEFAULT 1, ZENITY_ERROR_DEFAULT -1).
|
||||
if (process.ExitCode == 1) return null;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Fallback to kdialog if zenity fails to start
|
||||
// Falls back to kdialog when zenity is not installed or cannot be started.
|
||||
}
|
||||
|
||||
var kdialogInfo = new ProcessStartInfo
|
||||
|
||||
Reference in new issue
Block a user