From 4b6835c9f98be1a401f34bff219c6d71ac83d317 Mon Sep 17 00:00:00 2001 From: Andreas Horn Date: Mon, 4 May 2020 17:32:37 +0200 Subject: [PATCH 1/2] 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. --- Unreal/Plugins/AirSim/Source/SimHUD/SimHUD.cpp | 10 ++++++++-- docs/settings.md | 12 +++++++++--- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/Unreal/Plugins/AirSim/Source/SimHUD/SimHUD.cpp b/Unreal/Plugins/AirSim/Source/SimHUD/SimHUD.cpp index 77a56954d5..1efa70c461 100644 --- a/Unreal/Plugins/AirSim/Source/SimHUD/SimHUD.cpp +++ b/Unreal/Plugins/AirSim/Source/SimHUD/SimHUD.cpp @@ -357,9 +357,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) { @@ -372,6 +373,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; diff --git a/docs/settings.md b/docs/settings.md index 8059e489c6..c7c87cd8e0 100644 --- a/docs/settings.md +++ b/docs/settings.md @@ -1,10 +1,16 @@ # AirSim Settings ## Where are Settings Stored? -Windows: `Documents\AirSim` -Linux: `~/Documents/AirSim` +AirSim is searching for the settings definition in 4 different ways in the following order. The first match will be used: -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. +1. Looking at the (absolute) path specified by the `--settings` command line argument. +Example: `AirSim.exe --settings 'C:\path\to\settings.json'` +2. Looking for a json document passed as a command line argument by the `--settings` argument. +Example: `AirSim.exe --settings '{"foo" : "bar"}'` +3. Looking in the folder of the executable for a file called `settings.json`. +3. 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: From c30a24f4124bbd2b3575295f3680e12c21543574 Mon Sep 17 00:00:00 2001 From: madratman Date: Fri, 24 Jul 2020 00:18:13 -0700 Subject: [PATCH 2/2] add linux example to doc --- docs/settings.md | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/docs/settings.md b/docs/settings.md index c7c87cd8e0..b9d360ff40 100644 --- a/docs/settings.md +++ b/docs/settings.md @@ -4,11 +4,13 @@ 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. -Example: `AirSim.exe --settings 'C:\path\to\settings.json'` -2. Looking for a json document passed as a command line argument by the `--settings` argument. -Example: `AirSim.exe --settings '{"foo" : "bar"}'` -3. Looking in the folder of the executable for a file called `settings.json`. -3. 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. +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.