Blender  V2.93
AppConfig.cpp
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16 
21 #include "AppConfig.h"
22 #include <iostream>
23 
24 #include "../system/FreestyleConfig.h"
25 #include "../system/StringUtils.h"
26 
27 using namespace std;
28 
29 #include "BKE_appdir.h"
30 
31 namespace Freestyle::Config {
32 
33 Path *Path::_pInstance = nullptr;
34 Path::Path()
35 {
36  // get the root directory
37  // soc
38  setRootDir(BKE_appdir_folder_id(BLENDER_SYSTEM_SCRIPTS, nullptr));
39 
40  _pInstance = this;
41 }
42 
43 void Path::setRootDir(const string &iRootDir)
44 {
45  _ProjectDir = iRootDir + string(DIR_SEP) + "freestyle";
46  _ModelsPath = "";
47  _PatternsPath = _ProjectDir + string(DIR_SEP) + "data" + string(DIR_SEP) + "textures" +
48  string(DIR_SEP) + "variation_patterns" + string(DIR_SEP);
49  _BrushesPath = _ProjectDir + string(DIR_SEP) + "data" + string(DIR_SEP) + "textures" +
50  string(DIR_SEP) + "brushes" + string(DIR_SEP);
51  _EnvMapDir = _ProjectDir + string(DIR_SEP) + "data" + string(DIR_SEP) + "env_map" +
52  string(DIR_SEP);
53  _MapsDir = _ProjectDir + string(DIR_SEP) + "data" + string(DIR_SEP) + "maps" + string(DIR_SEP);
54 }
55 
56 void Path::setHomeDir(const string &iHomeDir)
57 {
58  _HomeDir = iHomeDir;
59 }
60 
61 Path::~Path()
62 {
63  _pInstance = nullptr;
64 }
65 
66 Path *Path::getInstance()
67 {
68  return _pInstance;
69 }
70 
71 string Path::getEnvVar(const string &iEnvVarName)
72 {
73  string value;
74  if (!getenv(iEnvVarName.c_str())) {
75  cerr << "Warning: You may want to set the $" << iEnvVarName
76  << " environment variable to use Freestyle." << endl
77  << " Otherwise, the current directory will be used instead." << endl;
78  value = ".";
79  }
80  else {
81  value = getenv(iEnvVarName.c_str());
82  }
83  return value;
84 }
85 
86 } // namespace Freestyle::Config
Configuration file.
@ BLENDER_SYSTEM_SCRIPTS
Definition: BKE_appdir.h:88
const char * BKE_appdir_folder_id(const int folder_id, const char *subfolder)
Definition: appdir.c:674
#define DIR_SEP
Definition: util_path.cpp:36