16 #include <itkObject.h> 17 #include <itksys/SystemTools.hxx> 34 if (m_Instance.IsNull())
42 FileSearchVectorType::iterator iter;
50 if (insertInFrontOfSearchList)
61 FileSearchVectorType::iterator it;
76 FileSearchVectorType::iterator it;
80 std::string currDir = (*it);
83 if (currDir.find_last_of(
"\\") + 1 != currDir.size() || currDir.find_last_of(
"/") + 1 != currDir.size())
90 if (currDir.find_last_of(
"\\") + 1 == currDir.size() || currDir.find_last_of(
"/") + 1 == currDir.size())
91 currDir.erase(currDir.size() - 1, currDir.size());
94 currDir = itksys::SystemTools::ConvertToOutputPath(currDir.c_str());
98 if (currDir.find_last_of(
"\"") + 1 == currDir.size())
99 currDir.erase(currDir.size() - 1, currDir.size());
100 if (currDir.find_last_of(
"\"") == 0)
104 if (itksys::SystemTools::FileExists(currDir.c_str()))
107 return std::string(
"");
112 std::string directoryPath;
115 const char *mitkConf = itksys::SystemTools::GetEnv(
"MITKCONF");
116 if (mitkConf !=
nullptr)
120 #if defined(_WIN32) && !defined(__CYGWIN__) 121 const char *homeDrive = itksys::SystemTools::GetEnv(
"HOMEDRIVE");
122 const char *homePath = itksys::SystemTools::GetEnv(
"HOMEPATH");
124 if ((homeDrive !=
nullptr) || (homePath !=
nullptr))
126 directoryPath = homeDrive;
127 directoryPath += homePath;
128 directoryPath +=
"/.mitk/";
133 const char *homeDirectory = itksys::SystemTools::GetEnv(
"HOME");
134 if (homeDirectory !=
nullptr)
136 directoryPath = homeDirectory;
137 directoryPath +=
"/.mitk/";
141 #endif // defined(_WIN32) && !defined(__CYGWIN__) 147 directoryPath = itksys::SystemTools::GetCurrentWorkingDirectory();
150 std::string directoryBinPath = directoryPath +
"/bin";
156 directoryPath += pathInSourceDir;
158 directoryPath +=
'/';
166 const char *mitkoptions = itksys::SystemTools::GetEnv(
"MITKOPTIONS");
167 std::string optionsDirectory;
169 if (mitkoptions !=
nullptr)
172 optionsDirectory = mitkoptions;
173 optionsDirectory +=
"/";
178 std::string homeDirectory;
179 #if defined(_WIN32) && !defined(__CYGWIN__) 180 const char *homeDrive = itksys::SystemTools::GetEnv(
"HOMEDRIVE");
181 const char *homePath = itksys::SystemTools::GetEnv(
"HOMEPATH");
182 if ((homeDrive ==
nullptr) || (homePath ==
nullptr))
184 itkGenericOutputMacro(<<
"Environment variables HOMEDRIVE and/or HOMEPATH not set" 185 <<
". Using current working directory as home directory: " 186 << itksys::SystemTools::GetCurrentWorkingDirectory());
187 homeDirectory = itksys::SystemTools::GetCurrentWorkingDirectory();
191 homeDirectory = homeDrive;
192 homeDirectory += homePath;
194 if (itksys::SystemTools::FileExists(homeDirectory.c_str()) ==
false)
196 itkGenericOutputMacro(<<
"Could not find home directory at " << homeDirectory
197 <<
". Using current working directory as home directory: " 198 << itksys::SystemTools::GetCurrentWorkingDirectory());
199 homeDirectory = itksys::SystemTools::GetCurrentWorkingDirectory();
202 const char *home = itksys::SystemTools::GetEnv(
"HOME");
205 itkGenericOutputMacro(<<
"Environment variable HOME not set" 206 <<
". Using current working directory as home directory: " 207 << itksys::SystemTools::GetCurrentWorkingDirectory());
208 homeDirectory = itksys::SystemTools::GetCurrentWorkingDirectory();
211 homeDirectory = home;
212 if (itksys::SystemTools::FileExists(homeDirectory.c_str()) ==
false)
214 itkGenericOutputMacro(<<
"Could not find home directory at " << homeDirectory
215 <<
". Using current working directory as home directory: " 216 << itksys::SystemTools::GetCurrentWorkingDirectory());
217 homeDirectory = itksys::SystemTools::GetCurrentWorkingDirectory();
219 #endif // defined(_WIN32) && !defined(__CYGWIN__) 221 optionsDirectory = homeDirectory;
222 optionsDirectory +=
"/.mitk";
225 optionsDirectory = itksys::SystemTools::ConvertToOutputPath(optionsDirectory.c_str());
226 if (itksys::SystemTools::CountChar(optionsDirectory.c_str(),
'"') > 0)
228 char *unquoted = itksys::SystemTools::RemoveChars(optionsDirectory.c_str(),
"\"");
229 optionsDirectory = unquoted;
233 if (itksys::SystemTools::MakeDirectory(optionsDirectory.c_str()) ==
false)
235 itkGenericExceptionMacro(<<
"Could not create .mitk directory at " << optionsDirectory);
237 return optionsDirectory;
FileSearchVectorType m_SearchDirectories
~StandardFileLocations() override
void RemoveDirectoryForSearch(const char *dir)
Remove a directory from the search queue: \ Use this function in combination with FindFile()...
std::string GetOptionDirectory()
Return directory of/for option files.
void AddDirectoryForSearch(const char *dir, bool insertInFrontOfSearchList=true)
Adds a directory into the search queue: \ Use this function in combination with FindFile(), after adding some \ directories, they will also be searched for the requested file.
std::string FindFile(const char *filename, const char *pathInSourceDir=nullptr)
looks for a file in several standard locations
static StandardFileLocations * GetInstance()
std::string SearchDirectoriesForFile(const char *filename)
Provides a method to look for configuration and option files etc.