Blender V4.5
autoexec.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
12#include <cstdlib>
13#include <cstring>
14
15#include "DNA_userdef_types.h"
16
17#include "BLI_fnmatch.h"
18#include "BLI_path_utils.hh"
19#include "BLI_string.h"
20
21#include "BKE_autoexec.hh" /* own include */
22#include "BKE_global.hh"
23
24bool BKE_autoexec_match(const char *path)
25{
26 bPathCompare *path_cmp;
27
28#ifdef WIN32
29 const int fnmatch_flags = FNM_CASEFOLD;
30#else
31 const int fnmatch_flags = 0;
32#endif
33
35
36 for (path_cmp = static_cast<bPathCompare *>(U.autoexec_paths.first); path_cmp;
37 path_cmp = path_cmp->next)
38 {
39 if (path_cmp->path[0] == '\0') {
40 /* pass */
41 }
42 else if (path_cmp->flag & USER_PATHCMP_GLOB) {
43 if (fnmatch(path_cmp->path, path, fnmatch_flags) == 0) {
44 return true;
45 }
46 }
47 else if (BLI_path_ncmp(path_cmp->path, path, strlen(path_cmp->path)) == 0) {
48 return true;
49 }
50 }
51
52 return false;
53}
54
55bool BKE_autoexec_default_trust_source(const char *filepath)
56{
57 if (G.autoexec_override.has_value()) {
58 /* The command line forced auto-execution on or off, excluded paths don't apply. */
59 return *G.autoexec_override;
60 }
62 /* Nothing is trusted by default, the user may still opt-in. */
63 return false;
64 }
65
66 char dirpath[FILE_MAX];
67 STRNCPY(dirpath, filepath);
68 BLI_path_canonicalize_native(dirpath, sizeof(dirpath));
69 /* Truncating at the file name leaves the trailing slash. */
70 *const_cast<char *>(BLI_path_basename(dirpath)) = '\0';
71
72 return !BKE_autoexec_match(dirpath);
73}
#define BLI_assert(a)
Definition BLI_assert.h:46
#define BLI_path_ncmp
void void void const char * BLI_path_basename(const char *path) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT
#define FILE_MAX
int BLI_path_canonicalize_native(char *path, int path_maxncpy)
char * STRNCPY(char(&dst)[N], const char *src)
Definition BLI_string.h:688
@ USER_SCRIPT_AUTOEXEC_DISABLE
@ USER_PATHCMP_GLOB
bool BKE_autoexec_match(const char *path)
Definition autoexec.cc:24
bool BKE_autoexec_default_trust_source(const char *filepath)
Definition autoexec.cc:55
unsigned int U
Definition btGjkEpa3.h:78
#define G(x, y, z)
struct bPathCompare * next