diff options
author | Luca Bacci <luca.bacci982@gmail.com> | 2022-12-21 13:57:29 +0100 |
---|---|---|
committer | Philip Withnall <pwithnall@endlessos.org> | 2022-12-22 15:04:18 +0000 |
commit | 9af8252b0db4806a4ef2e732bcdbef65af1dc212 (patch) | |
tree | 8a388e7dd1b60b116b6d0a0e08449f3e48e1d430 | |
parent | 15395405882febf384928b3693246c414d1a92ca (diff) | |
download | glib-9af8252b0db4806a4ef2e732bcdbef65af1dc212.tar.gz |
GWin32AppInfo: Check for local file path first
When launching a registered handler we compose the command-line
string using the registered command-line template. Applications
expect files in their command-line as local paths rather than
complete URI strings.
For example,
"Program.exe" "%1"
Should expand to
"Program.exe" "C:\file.dat"
Rather than
"Program.exe" "file:///C:\file.dat"
Fixes https://gitlab.gnome.org/GNOME/glib/-/issues/2843
-rw-r--r-- | gio/gwin32appinfo.c | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/gio/gwin32appinfo.c b/gio/gwin32appinfo.c index 6ff259f7d..0e582a84a 100644 --- a/gio/gwin32appinfo.c +++ b/gio/gwin32appinfo.c @@ -4334,10 +4334,25 @@ expand_macro_single (char macro, file_or_uri *obj) case '8': case '9': /* TODO: handle 'l' and 'd' differently (longname and desktop name) */ - if (obj->uri) - result = g_strdup (obj->uri); - else if (obj->file) - result = g_strdup (obj->file); + if (obj->file) + { + result = g_strdup (obj->file); + } + else if (obj->uri) + { + const char *prefix = "file:///"; + const size_t prefix_len = strlen (prefix); + + if (g_str_has_prefix (obj->uri, prefix) == 0 && obj->uri[prefix_len] != 0) + { + GFile *file = g_file_new_for_uri (obj->uri); + result = g_file_get_path (file); + g_object_unref (file); + } + + if (!result) + result = g_strdup (obj->uri); + } break; case 'u': case 'U': |