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