Commit Graph

77 Commits

Author SHA1 Message Date
Luca Bacci
86fccfcb70 GWin32AppInfo: Prefer file activation over URI activation for file URI's
(...unless file:// URI's are actually supported by the target app)

References:

 [1] - https://learn.microsoft.com/en-us/windows/uwp/launch-resume/handle-uri-activation
 [2] - https://learn.microsoft.com/en-us/windows/uwp/launch-resume/handle-file-activation
2023-01-05 17:50:15 +01:00
Luca Bacci
02417db370 GWin32AppInfo: Pass only one item to ActivateForProtocol()
IApplicationActivationManager::ActivateForProtocol() only uses the first
item from the IShellItemArray. When we have to activate multiple URI's,
call ActivateForProtocol() repeatedly in a loop, each time with one URI.

References:

 [1] - IApplicationActivationManager::ActivateForProtocol method [MSDN]
       https://learn.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-iapplicationactivationmanager-activateforprotocol
2023-01-05 17:46:50 +01:00
Luca Bacci
7bbbb1ee42 GWin32AppInfo: Create IShellItemArray object inside launch_uwp_internal()
The IShellItemArray object is only used in launch_uwp_internal(),
so do not make callers bother with that.
2023-01-05 17:42:03 +01:00
Luca Bacci
3c2b15fb15 GWin32AppInfo: Fix use-after-free 2022-12-22 15:14:29 +01:00
Luca Bacci
b0b16cf06e 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
2022-12-22 15:13:10 +01:00
Simon McVittie
65016fddd9 Replace all uses of G_VA_COPY with Standard C va_copy
Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-10-26 18:07:55 +01:00
Luca Bacci
e112bdb247 GWin32AppInfo: Add missing g_spawn_close_pid 2022-09-02 12:35:17 +02:00
Luca Bacci
53515197df GWin32AppInfo: Instantiate ApplicationActivationManager out-of-process
This is recommended on MSDN
2022-08-26 11:33:22 +02:00
Luca Bacci
42a76e1631 GWin32AppInfo: Check for task cancellation
We cannot cancel a spawn operation, but sometimes we have to
spawn the target application mutiple times (e.g. in case the
target app only supports one URI in its command-line, but we
were given multiple URI's), in that case continuously check
the cancellation status before attempting any spawn operation
2022-08-26 11:33:22 +02:00
Luca Bacci
cff3e660c1 GWin32AppInfo: Emit GAppLaunchContext signals for all code paths 2022-08-26 11:33:09 +02:00
Luca Bacci
f0ff6a6af0 GWin32AppInfo: Add g_win32_app_info_launch_uris_impl utility function
This utility function will be called by both launch_uris and
launch_uris_async, passing a from_task parameter respectively
as NULL and non-NULL. The from_task parameter will be needed
to know whether GAppLaunchContext signals should be emitted
directly (from_task == NULL) or scheduled for emission on the
main thread (from_task != NULL).
2022-08-16 12:29:18 +02:00
Luca Bacci
bf13a5e0a4 GWin32AppInfo: Implement launch_uris_async
Fixes https://gitlab.gnome.org/GNOME/gtk/-/issues/4400
2022-08-12 18:33:20 +02:00
Luca Bacci
d3ae4cc809 GWin32AppInfo: Ensure COM is initialized when activating UWP apps
Using the Application Activation Manager coclass. Its threading model
is marked as 'both', so it can be instantiated in any apartment type
without marshaling.
2022-08-04 21:35:08 +02:00
Luca Bacci
45bdeeddff GWin32AppInfo: Actually report the GPid in the GAppLaunchContext::launched signal
We need to pass the G_SPAWN_DO_NOT_REAP_CHILD flag to g_spawn_async,
otherwise the returned child_pid will always be 0.
2022-08-02 16:38:32 +02:00
Philip Withnall
a20a432100 Merge branch 'nacho/uwp-warnings' into 'main'
win32appinfo: change log level from warning to debug

Closes #2640

See merge request GNOME/glib!2661
2022-05-26 14:29:11 +00:00
Philip Withnall
5942cd7984 gio: Add SPDX license headers automatically
Add SPDX license (but not copyright) headers to all files which follow a
certain pattern in their existing non-machine-readable header comment.

This commit was entirely generated using the command:
```
git ls-files gio/*.[ch] | xargs perl -0777 -pi -e 's/\n \*\n \* This library is free software; you can redistribute it and\/or\n \* modify it under the terms of the GNU Lesser General Public/\n \*\n \* SPDX-License-Identifier: LGPL-2.1-or-later\n \*\n \* This library is free software; you can redistribute it and\/or\n \* modify it under the terms of the GNU Lesser General Public/igs'
```

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>

Helps: #1415
2022-05-18 09:18:52 +01:00
Ignacio Casal Quinteiro
acb1ce2272 win32appinfo: change log level from warning to debug
There is nothing that the user can do anyway and this dumps
lots of warnings without real need.

Closes #2640
2022-05-17 12:14:21 +02:00
Loic Le Page
84dabcf274 Fix global and local variables hidden by local variables and non-initialized variables in gio/gwin32appinfo.c 2022-04-01 00:18:40 +01:00
Luca Bacci
de6da5aa73
GWin32AppInfo: Implement should_show vfunc 2021-11-24 15:48:10 +01:00
Emmanuel Fleury
264055f3c0 Fix signedness warnings in gio/gwin32appinfo.c
gio/gwin32appinfo.c: In function 'uwp_package_cb':
gio/gwin32appinfo.c:3383:17: warning: comparison of integer expressions of different signedness: 'gint' {aka 'int'} and 'guint' {aka 'unsigned int'}
   for (i = 0; i < supported_extgroups->len; i++)
                 ^
gio/gwin32appinfo.c:3389:29: warning: comparison of integer expressions of different signedness: 'gint' {aka 'int'} and 'guint' {aka 'unsigned int'}
       for (i_ext = 0; i_ext < grp->extensions->len; i_ext++)
                             ^
gio/gwin32appinfo.c:3430:35: warning: comparison of integer expressions of different signedness: 'gint' {aka 'int'} and 'guint' {aka 'unsigned int'}
           for (i_verb = 0; i_verb < grp->verbs->len; i_verb++)
                                   ^
gio/gwin32appinfo.c:3463:33: warning: comparison of integer expressions of different signedness: 'gint' {aka 'int'} and 'guint' {aka 'unsigned int'}
       for (i_hverb = 0; i_hverb < ext->verbs->len; i_hverb++)
                                 ^
gio/gwin32appinfo.c:3478:17: warning: comparison of integer expressions of different signedness: 'gint' {aka 'int'} and 'guint' {aka 'unsigned int'}
   for (i = 0; i < supported_protocols->len; i++)
                 ^
gio/gwin32appinfo.c:3541:33: warning: comparison of integer expressions of different signedness: 'gint' {aka 'int'} and 'guint' {aka 'unsigned int'}
       for (i_hverb = 0; i_hverb < url->verbs->len; i_hverb++)
                                 ^
gio/gwin32appinfo.c: In function 'g_win32_app_info_launch_internal':
gio/gwin32appinfo.c:4799:37: warning: comparison of integer expressions of different signedness: 'gint' {aka 'int'} and 'guint' {aka 'unsigned int'}
           for (p_index = 0; p_index <= g_strv_length (envp); p_index++)
                                     ^~
2021-11-17 14:40:38 +01:00
Philip Withnall
e4bb09d8ec Merge branch 'fix-win32-app-info-registry-key-assert' into 'main'
GWin32AppInfo: Do not assert about successful open'ing of registry keys

See merge request GNOME/glib!2260
2021-11-01 10:41:31 +00:00
Emmanuel Fleury
8444dc5695 Fix cast from pointer to integer of different size warning in gio/gwin32appinfo.c 2021-10-26 11:48:48 +00:00
Luca Bacci
0460e78bc6
GWin32AppInfo: Remove assertion on the opened registry key
Relax assertion about opened registry key as it may have been removed
in the meantime between enumeration and when opening, or (more likely)
we may not have the required permissions to open the some enumerated
keys (i.e. RegOpenKeyExW fails and returns ERROR_ACCESS_DENIED).

Fixes https://gitlab.com/inkscape/inbox/-/issues/5669
2021-09-21 16:09:23 +02:00
Руслан Ижбулатов
ae5e016edc GWin32AppInfo: Fix missing initialization
The value should be initialized to NULL before calling
g_win32_registry_key_get_value_w(), to ensure that cleanup
can be done unconditionally afterward.
2021-08-02 14:19:35 +00:00
Руслан Ижбулатов
4e9e7bfd34 GWin32AppInfo: re-trigger registry watcher from the callback
To ensure that the watch is properly re-set every time, call
watch_keys() from the watch callback. Previously the watch was only
renewed after a data update was done in a worker thread, which made
no sense, since the update function was implemented in such a way
that it can (and should) be re-triggered on each key change, until
the changes stop coming, and that can only happen if we renew
the registry watcher right away.
2021-07-31 11:01:06 +00:00
Руслан Ижбулатов
f701d6c497 GIO W32: Pin gio DLL
On Windows gio runs a thread to update appinfo at startup.
If someone unloads gio (this happens when a dynamic gio module gets
unloaded by a program that doesn't use gio itself), there doesn't seem
to be a way to detect that until gio is already gone, and as soon as
gio is gone, the thread crashes, since it tries to execute instructions
that are no longer there.

Holding an extra reference to gio DLL fixes this, but it also prevents
gio from being unloaded, and there's no "weak references" for DLLs.
So we just pin gio and acknowledge that it will never be unloaded.

Fixes #2300
Fixes #2359
2021-03-25 15:16:08 +00:00
Ole André Vadla Ravnås
9b2ab509da gwin32appinfo: Fix printf length sub-specifier
warning: format string '%x' requires an argument of type 'unsigned int',
but variadic argument 1 has type 'gsize'.
2021-01-21 20:10:50 +01:00
Руслан Ижбулатов
c816d074c3 GWin32AppInfo: fix a leak 2020-12-23 01:47:01 +00:00
Руслан Ижбулатов
d33c3747dc GWin32AppInfo: invert verb comparison function
The list is sorted in ascending order, which means that to put
verbs alphabetically we need to sort ealier verbs with -1. Same for
the "open" verb and the preferred verb (if any).
2020-12-23 01:46:33 +00:00
Руслан Ижбулатов
48d96b21f9 GWin32AppInfo: enforce chosen handler on UWP apps, use URI verbs
* UWP apps that have low registry footprint might end up with chosen_handler == NULL.
Ensure that this doesn't happen.
* UWP apps don't need verbs for URIs, but we do need verbs to have a link to an app
(since handlers don't contain app fields). Work around this by adding an "open" verb
to each UWP URI handler.
* Duplicate the code that inserts extension handler verbs into the app to also insert
URI handler verbs. This allows URI-only apps to be used correctly later on (otherwise
GLib errors out, saying that the app has no verbs).
2020-12-23 01:46:11 +00:00
Руслан Ижбулатов
a2f823113c GWin32AppInfo: read UWP handler metadata (indirect strings)
Have to use of SHLoadIndirectString() from shell32.dll for this, no
way around that.
2020-12-23 01:46:10 +00:00
Руслан Ижбулатов
a2c287bf9f GWin32AppInfo: be less picky about names
Use pretty name as the result of _name(), if available. This is
more in line with what .desktop files return. Canonical name
may be completely unintelligible.
2020-12-23 01:45:20 +00:00
Руслан Ижбулатов
e7a738711b GWin32AppInfo: be more permissive about verbs in capable apps
MSDN doesn't say much on this subject, but i've seen apps in the wild
that have the "shell" subkey with verbs *either* in the root app key *or*
in the "Capabilities" subkey of the root key. Accommodate either case by trying both
(root key gets a priority, since this is how MS Address Book is registered -
assume that MS knows how to do this the right way).
2020-12-23 01:44:47 +00:00
Руслан Ижбулатов
10def41dc5 GWin32AppInfo: simplify appinfo wait condition 2020-12-23 01:44:34 +00:00
Руслан Ижбулатов
4c3a61e221 GWin32AppInfo: use g_new() instead of g_malloc() 2020-12-23 01:43:39 +00:00
Руслан Ижбулатов
f28b75e9ff GWin32AppInfo: Support launching UWP applications 2020-12-23 01:43:38 +00:00
Руслан Ижбулатов
0ea2f34723 GWin32AppInfo: more checks for UWP apps
UWP apps have no exectuables or commandlines. Check for that.
2020-12-23 01:43:38 +00:00
Руслан Ижбулатов
720b51032c GWin32AppInfo: Support getting information about UWP apps 2020-12-23 01:43:38 +00:00
Руслан Ижбулатов
fdfa9236a2 GWin32AppInfo: Store UWP AppUserModelId for a handler
Could be used later on to launch UWP apps.

UWP apps need verbs, but we don't have any code to get UWP app
info yet.
2020-12-23 01:33:28 +00:00
Руслан Ижбулатов
e1bf1c2711 GWin32AppInfo: Recognize UWP applications 2020-11-18 15:21:03 +00:00
Руслан Ижбулатов
6931edc28f Plug a leak 2020-11-18 15:20:38 +00:00
Руслан Ижбулатов
427d4fad24 GWin32AppInfo: Use a thread for async appinfo tree rebuilds 2020-11-17 18:11:56 +00:00
Руслан Ижбулатов
106e78af97 GWin32AppInfo: Support verbs other than "open"
This combines a massive code re-folding with functionlity expansion
that allows us to track multiple verbs per handler or per application.

Also fixes a few issues and removes a function that made no sense.
2020-10-01 17:18:03 +01:00
Руслан Ижбулатов
f77a6a1626 GWin32AppInfo: Drop read_resource_string(), use GWin32RegistryKey
Now GWin32RegistryKey can internally do the same thing that
read_resource_string() does, and more.
2020-05-22 14:17:12 +00:00
Руслан Ижбулатов
a22a15dc5a GWin32RegistryKey: add MUI capabilities to get_value()
An extra argument to g_win32_registry_key_get_value_w() and
g_win32_registry_key_get_value() indicates that RegLoadMUIStringW()
should be used instead of RegQueryValueExW(). It only works on
strings, and automatically resolves resource strings (the ones
that start with "@").

The extra argument is needed to find resource DLLs that are only
specified by their relative name.
2020-05-20 14:23:49 +00:00
Руслан Ижбулатов
9d4d5dfca8 GWin32AppInfo: fix a potential memory leak
Make sure that hndexe_fc_basename is only allocated before it is
actually used.
2020-01-15 18:04:14 +00:00
Руслан Ижбулатов
9f070db4c5 GWin32AppInfo: Support rundll32-using applications
1) When parsing the executable name out of the command line,
see if the executable is rundll32.exe. If that is the case,
use the DLL name from its first argument as the "executable"
(this is used only for matching, and Windows Registry matches
these programs by their DLLs, so this is correct; for running
the application GLib would still use the command line, with
rundll32).

2) If an app runs with rundll32, ensure that rundll32 arguments
can be safely quoted. Otherwise GLib will break them with its
protective quotation.
2020-01-15 18:04:14 +00:00
Philip Withnall
29e8f5795d gwin32appinfo: Fix a potential free of an uninitialised variable
Signed-off-by: Philip Withnall <withnall@endlessm.com>

Closes: #1637
2019-01-07 10:25:46 +00:00
Sébastien Wilmet
3bf4a720c3 gio/: LGPLv2+ -> LGPLv2.1+
Sub-directories inside gio/ already processed in a previous commit:
- fam/
- gdbus-2.0/ (which contains only codegen/)
- gvdb/
- inotify/
- tests/
- win32/
- xdgmime/

Other sub-directories inside gio/:
- completion/: no license headers
- kqueue/: not LGPL, BSD-style license

https://bugzilla.gnome.org/show_bug.cgi?id=776504
2017-05-29 19:53:34 +02:00
Paolo Borelli
c97729532f W32: fix uninitialized var in g_app_info_get_all_for_type
Compare with the handler->app, not with the app var which is not
initialized yet

https://bugzilla.gnome.org/show_bug.cgi?id=759408
2015-12-14 14:32:17 +01:00