Blender
V5.0
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 "
WM_api.hh
"
/* Own include. */
12
13
#ifdef WIN32
14
# include "
BLI_winstuff.h
"
15
#elif defined(__APPLE__)
16
/* Pass. */
17
#else
18
# ifdef WITH_PYTHON
19
# include "
BLI_string.h
"
20
21
# include "
BKE_context.hh
"
22
23
# include "
BPY_extern_run.hh
"
24
# endif
25
#endif
26
27
/* -------------------------------------------------------------------- */
30
31
bool
WM_platform_associate_set
(
bool
do_register,
bool
all_users,
char
**r_error_msg)
32
{
33
bool
result
=
false
;
34
*r_error_msg =
nullptr
;
35
#ifdef WIN32
36
{
37
if
(all_users) {
38
if
(do_register) {
39
result
=
BLI_windows_execute_self
(
"--register-allusers"
,
true
,
true
,
true
);
40
}
41
else
{
42
result
=
BLI_windows_execute_self
(
"--unregister-allusers"
,
true
,
true
,
true
);
43
}
44
}
45
else
{
46
if
(do_register) {
47
result
=
BLI_windows_register_blend_extension
(
false
);
48
}
49
else
{
50
result
=
BLI_windows_unregister_blend_extension
(
false
);
51
}
52
}
53
}
54
#elif defined(__APPLE__)
55
/* Pass. */
56
UNUSED_VARS
(do_register, all_users);
57
#else
58
{
59
# ifdef WITH_PYTHON
60
BPy_RunErrInfo
err_info = {};
61
err_info.
use_single_line_error
=
true
;
62
err_info.
r_string
= r_error_msg;
63
64
const
char
*imports[] = {
"_bpy_internal"
,
"_bpy_internal.freedesktop"
,
nullptr
};
65
char
expr_buf[128];
66
67
SNPRINTF
(expr_buf,
68
"_bpy_internal.freedesktop.%s(all_users=%d)"
,
69
do_register ?
"register"
:
"unregister"
,
70
int
(all_users));
71
72
/* NOTE: this could be null, however the running a script without `bpy.context` access
73
* is a rare enough situation that it's better to keep this a requirement of the API and
74
* pass in a temporary context instead of making an exception for this one case. */
75
bContext
*C_temp =
CTX_create
();
76
char
*value =
nullptr
;
77
if
(
BPY_run_string_as_string_or_none
(C_temp, imports, expr_buf, &err_info, &value)) {
78
result
= (value ==
nullptr
);
79
*r_error_msg = value;
80
}
81
/* Else `r_error_msg` will be set to a single line exception. */
82
CTX_free
(C_temp);
83
# else
84
/* Pass. */
85
UNUSED_VARS
(do_register, all_users);
86
# endif
87
}
88
#endif
89
return
result
;
90
}
91
BKE_context.hh
CTX_free
void CTX_free(bContext *C)
Definition
blenkernel/intern/context.cc:128
CTX_create
bContext * CTX_create()
Definition
blenkernel/intern/context.cc:111
result
double result
Definition
BLI_expr_pylike_eval_test.cc:351
BLI_string.h
SNPRINTF
#define SNPRINTF(dst, format,...)
Definition
BLI_string.h:604
UNUSED_VARS
#define UNUSED_VARS(...)
Definition
BLI_utildefines.h:505
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:63
WM_platform_associate_set
bool WM_platform_associate_set(bool do_register, bool all_users, char **r_error_msg)
Definition
wm_platform.cc:31
Generated on
for Blender by
doxygen
1.16.1