Update DataDir search paths (GH #760)

pull/795/head
Jeffrey Walton 2019-02-02 00:29:36 -05:00
parent 2beb779286
commit 96eac11d3b
No known key found for this signature in database
GPG Key ID: B36AB348921B1838
1 changed files with 9 additions and 9 deletions

View File

@ -259,7 +259,8 @@ inline int StringToValue<int, true>(const std::string& str)
inline std::string AddSeparator(std::string str)
{
const char last = (str.empty() ? '\0' : str[str.length()-1]);
if (str.empty()) return "";
const char last = str[str.length()-1];
if (last != '/' && last != '\\')
return str + "/";
return str;
@ -282,6 +283,13 @@ static std::string GetDataDir()
file.open(name.c_str());
if (file.is_open())
return AddSeparator(g_argvPathHint) + std::string("../share/cryptopp/");
#endif
#ifdef CRYPTOPP_DATA_DIR
// Honor CRYPTOPP_DATA_DIR. This is likely an install directory if it is not "./".
name = AddSeparator(CRYPTOPP_DATA_DIR) + filename;
file.open(name.c_str());
if (file.is_open())
return AddSeparator(CRYPTOPP_DATA_DIR);
#endif
return "./";
}
@ -291,14 +299,6 @@ inline std::string DataDir(const std::string& filename)
std::string name;
std::ifstream file;
#ifdef CRYPTOPP_DATA_DIR
// Honor CRYPTOPP_DATA_DIR. This is likely an install directory if it is not "./".
name = AddSeparator(CRYPTOPP_DATA_DIR) + filename;
file.open(name.c_str());
if (file.is_open())
return name;
#endif
#if CRYPTOPP_CXX11_DYNAMIC_INIT
static std::string path = AddSeparator(GetDataDir());
name = path + filename;