Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check for settings.json in current directory as well #3436

Merged
merged 4 commits into from
Jun 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions Unreal/Plugins/AirSim/Source/SimHUD/SimHUD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,13 @@ void ASimHUD::initializeSubWindows()
}
}

FString ASimHUD::getLaunchPath(const std::string& filename)
{
FString launch_rel_path = FPaths::LaunchDir();
FString abs_path = FPaths::ConvertRelativePathToFull(launch_rel_path);
return FPaths::Combine(abs_path, FString(filename.c_str()));
}

// Attempts to parse the settings text from one of multiple locations.
// First, check the command line for settings provided via "-s" or "--settings" arguments
// Next, check the executable's working directory for the settings file.
Expand All @@ -362,6 +369,7 @@ bool ASimHUD::getSettingsText(std::string& settingsText)
{
return (getSettingsTextFromCommandLine(settingsText) ||
readSettingsTextFromFile(FString(msr::airlib::Settings::getExecutableFullPath("settings.json").c_str()), settingsText) ||
readSettingsTextFromFile(getLaunchPath("settings.json"), settingsText) ||
readSettingsTextFromFile(FString(msr::airlib::Settings::Settings::getUserDirectoryFullPath("settings.json").c_str()), settingsText));
}

Expand Down Expand Up @@ -395,9 +403,8 @@ bool ASimHUD::getSettingsTextFromCommandLine(std::string& settingsText)
return found;
}

bool ASimHUD::readSettingsTextFromFile(FString settingsFilepath, std::string& settingsText)
bool ASimHUD::readSettingsTextFromFile(const FString& settingsFilepath, std::string& settingsText)
{

bool found = FPaths::FileExists(settingsFilepath);
if (found) {
FString settingsTextFStr;
Expand Down
4 changes: 3 additions & 1 deletion Unreal/Plugins/AirSim/Source/SimHUD/SimHUD.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,11 @@ class AIRSIM_API ASimHUD : public AHUD

bool getSettingsText(std::string& settingsText);
bool getSettingsTextFromCommandLine(std::string& settingsText);
bool readSettingsTextFromFile(FString fileName, std::string& settingsText);
bool readSettingsTextFromFile(const FString& fileName, std::string& settingsText);
std::string getSimModeFromUser();

static FString getLaunchPath(const std::string& filename);

private:
typedef common_utils::Utils Utils;
UClass* widget_class_;
Expand Down
25 changes: 18 additions & 7 deletions docs/settings.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,27 @@
# AirSim Settings

## Where are Settings Stored?
AirSim is searching for the settings definition in 4 different ways in the following order. The first match will be used:
AirSim is searching for the settings definition in the following order. The first match will be used:

1. Looking at the (absolute) path specified by the `--settings` command line argument.
For example, in Windows: `AirSim.exe --settings 'C:\path\to\settings.json'`
1. Looking at the (absolute) path specified by the `--settings` command line argument.
For example, in Windows: `AirSim.exe --settings 'C:\path\to\settings.json'`
In Linux `./Blocks.sh --settings '/home/$USER/path/to/settings.json'`
1. Looking for a json document passed as a command line argument by the `--settings` argument.
For example, in Windows: `AirSim.exe --settings '{"foo" : "bar"}'`

2. Looking for a json document passed as a command line argument by the `--settings` argument.
For example, in Windows: `AirSim.exe --settings '{"foo" : "bar"}'`
In Linux `./Blocks.sh --settings '{"foo" : "bar"}'`
1. Looking in the folder of the executable for a file called `settings.json`.
2. Looking in the users home folder for a file called `settings.json`. The AirSim subfolder is located at `Documents\AirSim` on Windows and `~/Documents/AirSim` on Linux systems.

3. Looking in the folder of the executable for a file called `settings.json`.
This will be a deep location where the actual executable of the Editor or binary is stored.
For e.g. with the Blocks binary, the location searched is `<path-of-binary>/LinuxNoEditor/Blocks/Binaries/Linux/settings.json`.

4. Searching for `settings.json` in the folder from where the executable is launched

This is a top-level directory containing the launch script or executable. For e.g. Linux: `<path-of-binary>/LinuxNoEditor/settings.json`, Windows: `<path-of-binary>/WindowsNoEditor/settings.json`

Note that this path changes depending on where its invoked from. On Linux, if executing the `Blocks.sh` script from inside LinuxNoEditor folder like `./Blocks.sh`, then the previous mentioned path is used. However, if launched from outside LinuxNoEditor folder such as `./LinuxNoEditor/Blocks.sh`, then `<path-of-binary>/settings.json` will be used.

5. Looking in the AirSim subfolder for a file called `settings.json`. The AirSim subfolder is located at `Documents\AirSim` on Windows and `~/Documents/AirSim` on Linux systems.

The file is in usual [json format](https://en.wikipedia.org/wiki/JSON). On first startup AirSim would create `settings.json` file with no settings at the users home folder. To avoid problems, always use ASCII format to save json file.

Expand Down