Commit Graph

85 Commits

Author SHA1 Message Date
Christian Hergert
0f95b18a7b gio: use g_variant_builder_init_static()
All uses of g_variant_builder_init() in gio are safe to translate to the
new g_variant_builder_init_static() alternative as the type will outlive
the call to g_variant_builder_end() (or is already static in nature).
2024-09-26 12:48:16 +01:00
Philip Withnall
21fdb3be24
gappinfo: Move all platform-independent API docs to gappinfo.c
Previously, some of the doc comments for platform-independent APIs were
in `gdesktopappinfo.c`, which is only built on Unix systems. This meant
the introspection annotations for those APIs were not used on non-Unix
systems, which caused platform differences in `Gio-2.0.gir`.

So, move those doc comments to `gappinfo.c` and put them next to some
new platform-independent wrapper functions which provide a consistent
entry point and location for the API preconditions.

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

Helps: #3399
2024-07-24 17:45:22 +02:00
Ville Skyttä
b20647c2e2 docs: spelling and grammar fixes
Signed-off-by: Ville Skyttä <ville.skytta@iki.fi>
2024-04-01 11:01:06 +00:00
Philip Withnall
c4b47c708d gwin32appinfo: Use correct gettext macro
`P_()` is for pspec strings — it gave us the option to split them out to
a separate translation domain. `_()` is for normal strings.

Spotted by Sophie Herold: https://gitlab.gnome.org/GNOME/glib/-/merge_requests/3411#note_1733329

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2023-11-29 13:41:34 +00:00
Luca Bacci
337912072a Windows: Compile with the UNICODE / _UNICODE macros
It's the recommended way to build C/C++ projects on Windows, see
https://learn.microsoft.com/en-us/windows/win32/intl/conventions-for-function-prototypes
2023-10-12 11:32:03 +02:00
Luca Bacci
65e2413dd5 GWin32AppInfo: Fix g_str_has_prefix() check
Fixes https://gitlab.gnome.org/GNOME/glib/-/issues/2972
2023-04-05 13:50:23 +02:00
Luca Bacci
061da06118 GWin32AppInfo: Add NULL string checks
Fixes #2922
2023-03-09 14:29:38 +01:00
Luca Bacci
01889cd348 GWin32AppInfo: Retrieve display name of UWP (packaged) apps 2023-02-22 13:24:13 +01:00
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