Blender V4.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
11#include "BLI_string.h"
12
13#include "WM_api.hh" /* Own include. */
14
15#ifdef WIN32
16# include "BLI_winstuff.h"
17#elif defined(__APPLE__)
18/* Pass. */
19#else
20# include "BKE_context.hh"
21
22# include "BPY_extern_run.hh"
23#endif
24
25/* -------------------------------------------------------------------- */
29bool WM_platform_associate_set(bool do_register, bool all_users, char **r_error_msg)
30{
31 bool result = false;
32 *r_error_msg = nullptr;
33#ifdef WIN32
34 {
35 if (all_users) {
36 if (do_register) {
37 result = BLI_windows_execute_self("--register-allusers", true, true, true);
38 }
39 else {
40 result = BLI_windows_execute_self("--unregister-allusers", true, true, true);
41 }
42 }
43 else {
44 if (do_register) {
46 }
47 else {
49 }
50 }
51 }
52#elif defined(__APPLE__)
53 /* Pass. */
54 UNUSED_VARS(do_register, all_users);
55#else
56 {
57 BPy_RunErrInfo err_info = {};
58 err_info.use_single_line_error = true;
59 err_info.r_string = r_error_msg;
60
61 const char *imports[] = {"_bpy_internal", "_bpy_internal.freedesktop", nullptr};
62 char expr_buf[128];
63
64 SNPRINTF(expr_buf,
65 "_bpy_internal.freedesktop.%s(all_users=%d)",
66 do_register ? "register" : "unregister",
67 int(all_users));
68
69 /* NOTE: this could be null, however the running a script without `bpy.context` access
70 * is a rare enough situation that it's better to keep this a requirement of the API and
71 * pass in a temporary context instead of making an exception for this one case. */
72 bContext *C_temp = CTX_create();
73 char *value = nullptr;
74 if (BPY_run_string_as_string_or_none(C_temp, imports, expr_buf, &err_info, &value)) {
75 result = (value == nullptr);
76 *r_error_msg = value;
77 }
78 /* Else `r_error_msg` will be set to a single line exception. */
79 CTX_free(C_temp);
80 }
81#endif
82 return result;
83}
84
void CTX_free(bContext *C)
bContext * CTX_create()
#define SNPRINTF(dst, format,...)
Definition BLI_string.h:597
#define UNUSED_VARS(...)
Compatibility-like things for windows.
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 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
draw_view push_constant(Type::INT, "radiance_src") .push_constant(Type capture_info_buf storage_buf(1, Qualifier::READ, "ObjectBounds", "bounds_buf[]") .push_constant(Type draw_view int
bool WM_platform_associate_set(bool do_register, bool all_users, char **r_error_msg)