Skip to content
Snippets Groups Projects
Commit 89626764 authored by Samuel Jackson's avatar Samuel Jackson
Browse files

Refs #18676 Check outside package for .properties file

parent 73eabf4a
No related merge requests found
...@@ -121,6 +121,8 @@ public: ...@@ -121,6 +121,8 @@ public:
std::string m_prev; ///< The previous value for the property std::string m_prev; ///< The previous value for the property
}; };
/// Setup the base directory
void setBaseDirectory();
/// Reset to "factory" settings. Removes current user properties /// Reset to "factory" settings. Removes current user properties
void reset(); void reset();
/// Wipe out the current configuration and load a new one /// Wipe out the current configuration and load a new one
......
...@@ -160,28 +160,7 @@ ConfigServiceImpl::ConfigServiceImpl() ...@@ -160,28 +160,7 @@ ConfigServiceImpl::ConfigServiceImpl()
"StdoutChannel", "StdoutChannel",
new Poco::Instantiator<Poco::StdoutChannel, Poco::Channel>); new Poco::Instantiator<Poco::StdoutChannel, Poco::Channel>);
// Define the directory to search for the Mantid.properties file. setBaseDirectory();
Poco::File f;
// First directory: the current working
m_strBaseDir = Poco::Path::current();
f = Poco::File(m_strBaseDir + m_properties_file_name);
if (!f.exists()) {
// Check the executable directory to see if it includes a mantid.properties
// file
m_strBaseDir = getDirectoryOfExecutable();
f = Poco::File(m_strBaseDir + m_properties_file_name);
if (!f.exists()) {
// Last, use the MANTIDPATH environment var
if (Poco::Environment::has("MANTIDPATH")) {
// Here we have to follow the convention of the rest of this code and
// add a trailing slash.
// Note: adding it to the MANTIDPATH itself will make other parts of the
// code crash.
m_strBaseDir = Poco::Environment::get("MANTIDPATH") + "/";
}
}
}
// Fill the list of possible relative path keys that may require conversion to // Fill the list of possible relative path keys that may require conversion to
// absolute paths // absolute paths
...@@ -285,6 +264,55 @@ ConfigServiceImpl::~ConfigServiceImpl() { ...@@ -285,6 +264,55 @@ ConfigServiceImpl::~ConfigServiceImpl() {
clearFacilities(); clearFacilities();
} }
/**
* Set the base directory path so we can file the Mantid.properties file.
*
* This will search for the base directory that contains the .properties file
* by checking the following places:
* - The current working directory
* - The executable directory
* - The directory defined by the MANTIDPATH enviroment var
* - OSX only: the directory two directories up from the executable (which
* is the base on the OSX package.
*
*/
void ConfigServiceImpl::setBaseDirectory() {
// Define the directory to search for the Mantid.properties file.
Poco::File f;
// First directory: the current working
m_strBaseDir = Poco::Path::current();
f = Poco::File(m_strBaseDir + m_properties_file_name);
if (f.exists())
return;
// Check the executable directory to see if it includes a mantid.properties
// file
m_strBaseDir = getDirectoryOfExecutable();
f = Poco::File(m_strBaseDir + m_properties_file_name);
if (f.exists())
return;
// Check the MANTIDPATH environment var
if (Poco::Environment::has("MANTIDPATH")) {
// Here we have to follow the convention of the rest of this code and
// add a trailing slash.
// Note: adding it to the MANTIDPATH itself will make other parts of the
// code crash.
m_strBaseDir = Poco::Environment::get("MANTIDPATH") + "/";
f = Poco::File(m_strBaseDir + m_properties_file_name);
if (!f.exists())
return;
}
#ifdef __APPLE__
// Finally, on OSX check if we're in the package directory and the .properties
// file just happens to be two directories up
auto path = Poco::Path(getDirectoryOfExecutable());
m_strBaseDir = path.parent().parent().parent().toString();
#endif
}
/** Loads the config file provided. /** Loads the config file provided.
* If the file contains logging setup instructions then these will be used to * If the file contains logging setup instructions then these will be used to
*setup the logging framework. *setup the logging framework.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment