Skip to content

Commit

Permalink
Allows to pass the settings.json file location via the --settings arg…
Browse files Browse the repository at this point in the history
…ument (#2668)

* Allows to pass the settings.json file location via the --settings argument as a path in addition to passing its content.

Also updated documentation, which did not list the other loading possibilities added with #715.

* add linux example to doc

Co-authored-by: madratman <ratneshmadaan@gmail.com>
  • Loading branch information
ahorn42 and madratman authored Jul 24, 2020
1 parent fd895ea commit 0a69793
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
10 changes: 8 additions & 2 deletions Unreal/Plugins/AirSim/Source/SimHUD/SimHUD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -366,9 +366,10 @@ bool ASimHUD::getSettingsText(std::string& settingsText)
readSettingsTextFromFile(FString(msr::airlib::Settings::Settings::getUserDirectoryFullPath("settings.json").c_str()), settingsText));
}

// Attempts to parse the settings text from the command line
// Attempts to parse the settings file path or the settings text from the command line
// Looks for the flag "--settings". If it exists, settingsText will be set to the value.
// Example: AirSim.exe -s '{"foo" : "bar"}' -> settingsText will be set to {"foo": "bar"}
// Example (Path): AirSim.exe --settings "C:\path\to\settings.json"
// Example (Text): AirSim.exe -s '{"foo" : "bar"}' -> settingsText will be set to {"foo": "bar"}
// Returns true if the argument is present, false otherwise.
bool ASimHUD::getSettingsTextFromCommandLine(std::string& settingsText)
{
Expand All @@ -381,6 +382,11 @@ bool ASimHUD::getSettingsTextFromCommandLine(std::string& settingsText)
FString commandLineArgsFString = FString(commandLineArgs);
int idx = commandLineArgsFString.Find(TEXT("-settings"));
FString settingsJsonFString = commandLineArgsFString.RightChop(idx + 10);

if (readSettingsTextFromFile(settingsJsonFString.TrimQuotes(), settingsText)) {
return true;
}

if (FParse::QuotedString(*settingsJsonFString, settingsTextFString)) {
settingsText = std::string(TCHAR_TO_UTF8(*settingsTextFString));
found = true;
Expand Down
16 changes: 12 additions & 4 deletions docs/settings.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
# AirSim Settings

## Where are Settings Stored?
Windows: `Documents\AirSim`
Linux: `~/Documents/AirSim`

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. To avoid problems, always use ASCII format to save json file.
AirSim is searching for the settings definition in 4 different ways 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'`
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"}'`
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.

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.

## How to Chose Between Car and Multirotor?
The default is to use multirotor. To use car simple set `"SimMode": "Car"` like this:
Expand Down

0 comments on commit 0a69793

Please sign in to comment.