Blender V4.3
AppConfig.cpp
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2008-2022 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
9#include "AppConfig.h"
10#include <iostream>
11
14
15using namespace std;
16
17#include "BKE_appdir.hh"
18
20
21Path *Path::_pInstance = nullptr;
23{
24 // get the root directory
25 // soc
26 const std::optional<std::string> path = BKE_appdir_folder_id(BLENDER_SYSTEM_SCRIPTS, nullptr);
27 setRootDir(path.value_or(BKE_appdir_program_dir()));
28
29 _pInstance = this;
30}
31
32void Path::setRootDir(const string &iRootDir)
33{
34 _ProjectDir = iRootDir + string(DIR_SEP) + "freestyle";
35 _ModelsPath = "";
36 _PatternsPath = _ProjectDir + string(DIR_SEP) + "data" + string(DIR_SEP) + "textures" +
37 string(DIR_SEP) + "variation_patterns" + string(DIR_SEP);
38 _BrushesPath = _ProjectDir + string(DIR_SEP) + "data" + string(DIR_SEP) + "textures" +
39 string(DIR_SEP) + "brushes" + string(DIR_SEP);
40 _EnvMapDir = _ProjectDir + string(DIR_SEP) + "data" + string(DIR_SEP) + "env_map" +
41 string(DIR_SEP);
42 _MapsDir = _ProjectDir + string(DIR_SEP) + "data" + string(DIR_SEP) + "maps" + string(DIR_SEP);
43}
44
45void Path::setHomeDir(const string &iHomeDir)
46{
47 _HomeDir = iHomeDir;
48}
49
51{
52 _pInstance = nullptr;
53}
54
56{
57 return _pInstance;
58}
59
60string Path::getEnvVar(const string &iEnvVarName)
61{
62 string value;
63 if (!getenv(iEnvVarName.c_str())) {
64 cerr << "Warning: You may want to set the $" << iEnvVarName
65 << " environment variable to use Freestyle." << endl
66 << " Otherwise, the current directory will be used instead." << endl;
67 value = ".";
68 }
69 else {
70 value = getenv(iEnvVarName.c_str());
71 }
72 return value;
73}
74
75} // namespace Freestyle::Config
Configuration file.
const char * BKE_appdir_program_dir() ATTR_WARN_UNUSED_RESULT ATTR_RETURNS_NONNULL
Definition appdir.cc:948
@ BLENDER_SYSTEM_SCRIPTS
std::optional< std::string > BKE_appdir_folder_id(int folder_id, const char *subfolder) ATTR_WARN_UNUSED_RESULT
Definition appdir.cc:704
Configuration definitions.
String utilities.
static string getEnvVar(const string &iEnvVarName)
Definition AppConfig.cpp:60
void setRootDir(const string &iRootDir)
Definition AppConfig.cpp:32
static Path * getInstance()
Definition AppConfig.cpp:55
void setHomeDir(const string &iHomeDir)
Definition AppConfig.cpp:45
static Path * _pInstance
Definition AppConfig.h:29
#define DIR_SEP
Definition path.cpp:29