Blender V5.3
wm_platform.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2024 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
10
11#include "WM_api.hh" /* Own include. */
12
13#ifdef WIN32
14# include "BLI_winstuff.hh"
15#elif defined(__APPLE__)
16/* Pass. */
17#else
18# ifdef WITH_PYTHON
19# include "BLI_string.hh"
20
21# include "BKE_context.hh"
22
23# include "BPY_extern_run.hh"
24# endif
25#endif
26
27namespace blender {
28
29/* -------------------------------------------------------------------- */
32
33bool WM_platform_associate_set(bool do_register, bool all_users, char **r_error_msg)
34{
35 bool result = false;
36 *r_error_msg = nullptr;
37#ifdef WIN32
38 {
39 if (all_users) {
40 if (do_register) {
41 result = BLI_windows_execute_self("--register-allusers", true, true, true);
42 }
43 else {
44 result = BLI_windows_execute_self("--unregister-allusers", true, true, true);
45 }
46 }
47 else {
48 if (do_register) {
50 }
51 else {
53 }
54 }
55 }
56#elif defined(__APPLE__)
57 /* Pass. */
58 UNUSED_VARS(do_register, all_users);
59#else
60 {
61# ifdef WITH_PYTHON
62 BPy_RunErrInfo err_info = {};
63 err_info.use_single_line_error = true;
64 err_info.r_string = r_error_msg;
65
66 const char *imports[] = {
67 "_bpy_internal",
68 "_bpy_internal.platform.freedesktop",
69 nullptr,
70 };
71 char expr_buf[128];
72
73 SNPRINTF(expr_buf,
74 "_bpy_internal.platform.freedesktop.%s(all_users=%d)",
75 do_register ? "register" : "unregister",
76 int(all_users));
77
78 /* NOTE: this could be null, however the running a script without `bpy.context` access
79 * is a rare enough situation that it's better to keep this a requirement of the API and
80 * pass in a temporary context instead of making an exception for this one case. */
81 bContext *C_temp = CTX_create();
82 char *value = nullptr;
83 if (BPY_run_string_as_string_or_none(C_temp, imports, expr_buf, &err_info, &value)) {
84 result = (value == nullptr);
85 *r_error_msg = value;
86 }
87 /* Else `r_error_msg` will be set to a single line exception. */
88 CTX_free(C_temp);
89# else
90 /* Pass. */
91 UNUSED_VARS(do_register, all_users);
92# endif
93 }
94#endif
95 return result;
96}
97
99
100} // namespace blender
#define SNPRINTF(dst, format,...)
Compatibility-like things for windows.
#define UNUSED_VARS(...)
BMesh Iterators.
bool BLI_windows_unregister_blend_extension(bool all_users)
bool BLI_windows_execute_self(const char *parameters, const bool wait, const bool elevated, const bool silent)
bool WM_platform_associate_set(bool do_register, bool all_users, char **r_error_msg)
bContext * CTX_create()
void CTX_free(bContext *C)
bool BLI_windows_register_blend_extension(bool all_users)
bool bool bool bool bool bool BPY_run_string_as_string_or_none(bContext *C, const char *imports[], const char *expr, BPy_RunErrInfo *err_info, char **r_value) ATTR_NONNULL(1