Blender
V4.3
source
blender
windowmanager
intern
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 "
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
/* -------------------------------------------------------------------- */
28
29
bool
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) {
45
result
=
BLI_windows_register_blend_extension
(
false
);
46
}
47
else
{
48
result
=
BLI_windows_unregister_blend_extension
(
false
);
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
BKE_context.hh
CTX_free
void CTX_free(bContext *C)
Definition
blenkernel/intern/context.cc:124
CTX_create
bContext * CTX_create()
Definition
blenkernel/intern/context.cc:107
result
double result
Definition
BLI_expr_pylike_eval_test.cc:351
BLI_string.h
SNPRINTF
#define SNPRINTF(dst, format,...)
Definition
BLI_string.h:597
UNUSED_VARS
#define UNUSED_VARS(...)
Definition
BLI_utildefines.h:533
BLI_winstuff.h
Compatibility-like things for windows.
BLI_windows_unregister_blend_extension
bool BLI_windows_unregister_blend_extension(bool all_users)
BLI_windows_execute_self
bool BLI_windows_execute_self(const char *parameters, const bool wait, const bool elevated, const bool silent)
BLI_windows_register_blend_extension
bool BLI_windows_register_blend_extension(bool all_users)
BPY_extern_run.hh
BPY_run_string_as_string_or_none
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
WM_api.hh
BPy_RunErrInfo
Definition
BPY_extern_run.hh:112
BPy_RunErrInfo::r_string
char ** r_string
Definition
BPY_extern_run.hh:121
BPy_RunErrInfo::use_single_line_error
bool use_single_line_error
Definition
BPY_extern_run.hh:114
bContext
Definition
blenkernel/intern/context.cc:61
WM_platform_associate_set
bool WM_platform_associate_set(bool do_register, bool all_users, char **r_error_msg)
Definition
wm_platform.cc:29
Generated on Sat Oct 4 2025 05:32:23 for Blender by
doxygen
1.14.0