Skip to content

Commit

Permalink
Check for settings.json in current directory as well
Browse files Browse the repository at this point in the history
  • Loading branch information
rajat2004 committed Mar 3, 2021
1 parent 4a91e0c commit 8a0a494
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 0 deletions.
8 changes: 8 additions & 0 deletions AirLib/include/common/Settings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ class Settings {
return common_utils::FileSystem::combine(path, fileName);
}

static std::string getCurrentDir(std::string fileName)
{
std::string path = common_utils::FileSystem::getCurrentDir();
std::string res = common_utils::FileSystem::combine(path, fileName);
common_utils::Utils::log(res);
return res;
}

static Settings& loadJSonString(const std::string& json_str)
{
singleton().full_filepath_ = "";
Expand Down
2 changes: 2 additions & 0 deletions AirLib/include/common/common_utils/FileSystem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ class FileSystem

static std::string getExecutableFolder();

static std::string getCurrentDir();

static std::string getAppDataFolder() {
return ensureFolder(combine(getUserDocumentsFolder(), ProductFolderName));
}
Expand Down
26 changes: 26 additions & 0 deletions AirLib/src/common/common_utils/FileSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,32 @@ std::string FileSystem::getExecutableFolder() {
return ensureFolder(path);
}

std::string FileSystem::getCurrentDir() {
std::string path;
#ifdef _WIN32
wchar_t szPath[MAX_PATH];

if (_wgetcwd(szPath, sizeof(szPath))) {
std::wstring_convert<std::codecvt_utf8<wchar_t>, wchar_t> converter;
path = converter.to_bytes(szPath);
}
else {
HRESULT hr = GetLastError();
throw std::invalid_argument(Utils::stringf("Error getting current working directory, hr = %d", hr));
}
#else
char szPath[8192];
if (getcwd(szPath, sizeof(szPath))) {
path = std::string(szPath);
}
else {
throw std::invalid_argument(Utils::stringf("Error getting current working directory, errno=%d, message=%s", errno, strerror(errno)).c_str() );
}
#endif

return path;
}

} // namespace common_utils

#endif
2 changes: 2 additions & 0 deletions Unreal/Plugins/AirSim/Source/SimHUD/SimHUD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,8 @@ bool ASimHUD::getSettingsText(std::string& settingsText)
||
readSettingsTextFromFile(FString(msr::airlib::Settings::getExecutableFullPath("settings.json").c_str()), settingsText)
||
readSettingsTextFromFile(FString(msr::airlib::Settings::getCurrentDir("settings.json").c_str()), settingsText)
||
readSettingsTextFromFile(FString(msr::airlib::Settings::Settings::getUserDirectoryFullPath("settings.json").c_str()), settingsText));
}

Expand Down

0 comments on commit 8a0a494

Please sign in to comment.