RigsofRods
Soft-body Physics Simulation
ConfigFile.cpp
Go to the documentation of this file.
1 /*
2  This source file is part of Rigs of Rods
3  Copyright 2005-2012 Pierre-Michel Ricordel
4  Copyright 2007-2012 Thomas Fischer
5  Copyright 2013-2016 Petr Ohlidal
6 
7  For more information, see http://www.rigsofrods.org/
8 
9  Rigs of Rods is free software: you can redistribute it and/or modify
10  it under the terms of the GNU General Public License version 3, as
11  published by the Free Software Foundation.
12 
13  Rigs of Rods is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with Rigs of Rods. If not, see <http://www.gnu.org/licenses/>.
20 */
21 
28 #include "ConfigFile.h"
29 
30 #include "Application.h"
31 #include "Console.h"
32 #include "Utils.h"
33 
34 #include <OgreConfigFile.h>
35 #include <OgreString.h>
36 #include <OgreStringConverter.h>
37 
38 using namespace RoR;
39 
40 float ConfigFile::getFloat(Ogre::String const& key, Ogre::String const& section, float defaultValue)
41 {
42  return Ogre::StringConverter::parseReal(Ogre::ConfigFile::getSetting(key, section), defaultValue);
43 }
44 
45 Ogre::ColourValue ConfigFile::getColourValue(Ogre::String const& key, Ogre::String const& section, Ogre::ColourValue const& defaultValue)
46 {
47  Ogre::ColourValue result;
48  Ogre::String value = Ogre::ConfigFile::getSetting(key, section);
49  if (Ogre::StringConverter::parse(value, result))
50  {
51  return result;
52  }
53  else
54  {
55  this->logMessage(
56  fmt::format("Could not parse '{}/{}' ({}) as color, format must be 'R G B A' or 'R G B', falling back to '{}'",
57  section, key, value, Ogre::StringConverter::toString(defaultValue)));
58  return defaultValue;
59  }
60 }
61 
62 Ogre::Vector3 ConfigFile::getVector3(Ogre::String const& key, Ogre::String const& section, Ogre::Vector3 const& defaultValue)
63 {
64  Ogre::Vector3 result;
65  Ogre::String value = Ogre::ConfigFile::getSetting(key, section);
66  if (Ogre::StringConverter::parse(value, result))
67  {
68  return result;
69  }
70  else
71  {
72  this->logMessage(
73  fmt::format("Could not parse '{}/{}' ({}) as vector3, format must be 'X Y Z', falling back to '{}'",
74  section, key, value, Ogre::StringConverter::toString(defaultValue)));
75  return defaultValue;
76  }
77 }
78 
79 int ConfigFile::getInt(Ogre::String const& key, Ogre::String const& section, int defaultValue)
80 {
81  return Ogre::StringConverter::parseInt(Ogre::ConfigFile::getSetting(key, section), defaultValue);
82 }
83 
84 bool ConfigFile::getBool(Ogre::String const& key, Ogre::String const& section, bool defaultValue)
85 {
86  return Ogre::StringConverter::parseBool(Ogre::ConfigFile::getSetting(key, section), defaultValue);
87 }
88 
89 Ogre::String ConfigFile::getString(Ogre::String const& key, Ogre::String const& section, Ogre::String const& defaultValue)
90 {
91  auto setting = Ogre::ConfigFile::getSetting(key, section);
92  if (setting.empty())
93  {
94  return defaultValue;
95  }
96  return SanitizeUtf8String(setting);
97 }
98 
99 void ConfigFile::SetString(Ogre::String key, Ogre::String value, Ogre::String section /* = Ogre::BLANKSTRING */)
100 {
101  SettingsMultiMap* set = mSettingsPtr[section];
102  if (!set)
103  {
104  // new section
105  set = new SettingsMultiMap();
106  mSettingsPtr[section] = set;
107  }
108  if (set->count(key))
109  {
110  // known key, delete old first
111  set->erase(key);
112  }
113  // add key
114  set->insert(std::multimap<Ogre::String, Ogre::String>::value_type(key, value));
115 }
116 
117 bool ConfigFile::HasSection(std::string const & name)
118 {
119  // This is the only way to check existence of section
120  // without either an OGRE exception being logged or using deprecated API.
121  return this->getSettingsBySection().find(name) != this->getSettingsBySection().end();
122 }
123 
124 void ConfigFile::logMessage(std::string const & msg)
125 {
126  // If filename is specified, log "filename: message", otherwise just "message".
127  LOG(fmt::format("{}{}{}", m_log_filename, (m_log_filename == "" ? "" : ": "), msg));
128 }
set
set(SOURCE_FILES main.cpp Application.{h, cpp} ForwardDeclarations.h AppContext.{h, cpp} GameContext.{h, cpp} audio/MumbleIntegration.{h, cpp} audio/Sound.{h, cpp} audio/SoundManager.{h, cpp} audio/SoundScriptManager.{h, cpp} gameplay/AutoPilot.{h, cpp} gameplay/Character.{h, cpp} gameplay/CharacterFactory.{h, cpp} gameplay/ChatSystem.{h, cpp} gameplay/CruiseControl.cpp gameplay/EngineSim.{h, cpp} gameplay/Landusemap.{h, cpp} gameplay/RaceSystem.{h, cpp} gameplay/RepairMode.{h, cpp} gameplay/Replay.{h, cpp} gameplay/SceneMouse.{h, cpp} gameplay/ScriptEvents.h gameplay/TorqueCurve.{h, cpp} gameplay/TyrePressure.{h, cpp} gameplay/VehicleAI.{h, cpp} gfx/AdvancedScreen.h gfx/ColoredTextAreaOverlayElement.{h, cpp} gfx/ColoredTextAreaOverlayElementFactory.h gfx/DustPool.{h, cpp} gfx/EnvironmentMap.{h, cpp} gfx/GfxActor.{h, cpp} gfx/GfxData.{h, cpp} gfx/GfxScene.{h, cpp} gfx/HydraxWater.{h, cpp} gfx/IWater.h gfx/MovableText.{h, cpp} gfx/Renderdash.{h, cpp} gfx/ShadowManager.{h, cpp} gfx/SimBuffers.{h, cpp} gfx/Skidmark.{h, cpp} gfx/SkyManager.{h, cpp} gfx/SkyXManager.{h, cpp} gfx/SurveyMapTextureCreator.{h, cpp} gfx/Water.{h, cpp} gfx/camera/CameraManager.{h, cpp} gfx/camera/PerVehicleCameraContext.h gfx/hydrax/CfgFileManager.{h, cpp} gfx/hydrax/DecalsManager.{h, cpp} gfx/hydrax/Enums.{h, cpp} gfx/hydrax/FFT.{h, cpp} gfx/hydrax/GodRaysManager.{h, cpp} gfx/hydrax/GPUNormalMapManager.{h, cpp} gfx/hydrax/Help.{h, cpp} gfx/hydrax/Hydrax.{h, cpp} gfx/hydrax/Image.{h, cpp} gfx/hydrax/MaterialManager.{h, cpp} gfx/hydrax/Mesh.{h, cpp} gfx/hydrax/Module.{h, cpp} gfx/hydrax/Noise.{h, cpp} gfx/hydrax/Perlin.{h, cpp} gfx/hydrax/Prerequisites.{h, cpp} gfx/hydrax/PressurePoint.{h, cpp} gfx/hydrax/ProjectedGrid.{h, cpp} gfx/hydrax/RadialGrid.{h, cpp} gfx/hydrax/Real.{h, cpp} gfx/hydrax/RttManager.{h, cpp} gfx/hydrax/SimpleGrid.{h, cpp} gfx/hydrax/TextureManager.{h, cpp} gfx/hydrax/Wave.{h, cpp} gfx/particle/ExtinguishableFireAffector.{h, cpp} gfx/particle/ExtinguishableFireAffectorFactory.h gfx/particle/FireExtinguisherAffector.{h, cpp} gfx/particle/FireExtinguisherAffectorFactory.h gfx/particle/OgreParticleCustomParam.h gfx/particle/OgreShaderParticleRenderer.{h, cpp} gfx/skyx/AtmosphereManager.{h, cpp} gfx/skyx/BasicController.{h, cpp} gfx/skyx/CloudsManager.{h, cpp} gfx/skyx/ColorGradient.{h, cpp} gfx/skyx/Controller.h gfx/skyx/GPUManager.{h, cpp} gfx/skyx/MeshManager.{h, cpp} gfx/skyx/MoonManager.{h, cpp} gfx/skyx/Prerequisites.{h, cpp} gfx/skyx/SCfgFileManager.{h, cpp} gfx/skyx/SkyX.{h, cpp} gfx/skyx/VCloudsManager.{h, cpp} gfx/skyx/VClouds/DataManager.{h, cpp} gfx/skyx/VClouds/Ellipsoid.{h, cpp} gfx/skyx/VClouds/FastFakeRandom.{h, cpp} gfx/skyx/VClouds/GeometryBlock.{h, cpp} gfx/skyx/VClouds/GeometryManager.{h, cpp} gfx/skyx/VClouds/Lightning.{h, cpp} gfx/skyx/VClouds/LightningManager.{h, cpp} gfx/skyx/VClouds/VClouds.{h, cpp} gui/DashBoardManager.{h, cpp} gui/GUIManager.{h, cpp} gui/GUIUtils.{h, cpp} gui/OverlayWrapper.{h, cpp} gui/RTTLayer.{h, cpp} gui/imgui/imgui.{h, cpp} gui/imgui/imgui_demo.cpp gui/imgui/imgui_draw.cpp gui/imgui/imgui_widgets.cpp gui/imgui/OgreImGuiOverlay.{h, cpp} gui/imgui/OgreImGui.{h, cpp} gui/imgui/imconfig.h gui/imgui/imgui_internal.h gui/imgui/imstb_rectpack.h gui/imgui/imstb_textedit.h gui/imgui/imstb_truetype.h gui/panels/GUI_AngelScriptExamples.{h, cpp} gui/panels/GUI_CollisionsDebug.{h, cpp} gui/panels/GUI_ConsoleView.{h, cpp} gui/panels/GUI_ConsoleWindow.{h, cpp} gui/panels/GUI_DirectionArrow.{h, cpp} gui/panels/GUI_LoadingWindow.{h, cpp} gui/panels/GUI_FlexbodyDebug.{h, cpp} gui/panels/GUI_FrictionSettings.{h, cpp} gui/panels/GUI_TopMenubar.{h, cpp} gui/panels/GUI_TextureToolWindow.{h, cpp} gui/panels/GUI_RepositorySelector.{h, cpp} gui/panels/GUI_GameControls.{h, cpp} gui/panels/GUI_GameAbout.{h, cpp} gui/panels/GUI_GameChatBox.{h, cpp} gui/panels/GUI_GameMainMenu.{h, cpp} gui/panels/GUI_GameSettings.{h, cpp} gui/panels/GUI_MainSelector.{h, cpp} gui/panels/GUI_MessageBox.{h, cpp} gui/panels/GUI_MultiplayerSelector.{h, cpp} gui/panels/GUI_MultiplayerClientList.{h, cpp} gui/panels/GUI_NodeBeamUtils.{h, cpp} gui/panels/GUI_VehicleInfoTPanel.{h, cpp} gui/panels/GUI_ScriptMonitor.{h, cpp} gui/panels/GUI_SimPerfStats.{h, cpp} gui/panels/GUI_SurveyMap.{h, cpp} network/CurlHelpers.{h, cpp} network/DiscordRpc.{h, cpp} network/Network.{h, cpp} network/OutGauge.{h, cpp} network/RoRnet.h physics/Actor.{h, cpp} physics/ApproxMath.h physics/ActorForcesEuler.cpp physics/ActorManager.{h, cpp} physics/ActorSlideNode.cpp physics/ActorSpawner.{h, cpp} physics/ActorSpawnerFlow.cpp physics/CmdKeyInertia.{h, cpp} physics/Differentials.{h, cpp} physics/Savegame.cpp physics/SimConstants.h physics/SimData.{h, cpp} physics/SlideNode.{h, cpp} physics/air/AeroEngine.h physics/air/AirBrake.{h, cpp} physics/air/Airfoil.{h, cpp} physics/air/TurboJet.{h, cpp} physics/air/TurboProp.{h, cpp} physics/collision/CartesianToTriangleTransform.h physics/collision/Collisions.{h, cpp} physics/collision/DynamicCollisions.{h, cpp} physics/collision/PointColDetector.{h, cpp} physics/collision/Triangle.h physics/flex/Flexable.h physics/flex/FlexAirfoil.{h, cpp} physics/flex/FlexBody.{h, cpp} physics/flex/FlexFactory.{h, cpp} physics/flex/FlexMesh.{h, cpp} physics/flex/FlexMeshWheel.{h, cpp} physics/flex/FlexObj.{h, cpp} physics/flex/Locator_t.h physics/water/Buoyance.{h, cpp} physics/water/ScrewProp.{h, cpp} resources/CacheSystem.{h, cpp} resources/ContentManager.{h, cpp} resources/addonpart_fileformat/AddonPartFileFormat.{h, cpp} resources/otc_fileformat/OTCFileFormat.{h, cpp} resources/odef_fileformat/ODefFileFormat.{h, cpp} resources/rig_def_fileformat/RigDef_File.{h, cpp} resources/rig_def_fileformat/RigDef_Node.{h, cpp} resources/rig_def_fileformat/RigDef_Parser.{h, cpp} resources/rig_def_fileformat/RigDef_Prerequisites.h resources/rig_def_fileformat/RigDef_Regexes.h resources/rig_def_fileformat/RigDef_SequentialImporter.{h, cpp} resources/rig_def_fileformat/RigDef_Serializer.{h, cpp} resources/rig_def_fileformat/RigDef_Validator.{h, cpp} resources/skin_fileformat/SkinFileFormat.{h, cpp} resources/terrn2_fileformat/Terrn2FileFormat.{h, cpp} resources/tobj_fileformat/TObjFileFormat.{h, cpp} resources/tuneup_fileformat/TuneupFileFormat.{h, cpp} system/AppCommandLine.cpp system/AppConfig.cpp system/Console.{h, cpp} system/ConsoleCmd.{h, cpp} system/CVar.{h, cpp} terrain/OgreTerrainPSSMMaterialGenerator.{h, cpp} terrain/ProceduralManager.{h, cpp} terrain/ProceduralRoad.{h, cpp} terrain/SurveyMapEntity.h terrain/TerrainEditor.{h, cpp} terrain/TerrainGeometryManager.{h, cpp} terrain/Terrain.{h, cpp} terrain/TerrainObjectManager.{h, cpp} threadpool/ThreadPool.h utils/ConfigFile.{h, cpp} utils/ErrorUtils.{h, cpp} utils/ForceFeedback.{h, cpp} utils/GenericFileFormat.{h, cpp} utils/ImprovedConfigFile.h utils/InputEngine.{h, cpp} utils/InterThreadStoreVector.h utils/Language.{h, cpp} utils/MeshObject.{h, cpp} utils/PlatformUtils.{h, cpp} utils/SHA1.{h, cpp} utils/Utils.{h, cpp} utils/WriteTextToTexture.{h, cpp} utils/memory/RefCountingObject.h utils/memory/RefCountingObjectPtr.h) if(ROR_USE_ANGELSCRIPT) list(APPEND SOURCE_FILES scripting/GameScript.
Definition: CMakeLists.txt:5
RoR::ConfigFile::getInt
int getInt(Ogre::String const &key, int defaultValue=0)
Definition: ConfigFile.h:64
RoR::ConfigFile::logMessage
void logMessage(std::string const &msg)
Definition: ConfigFile.cpp:124
format
Truck file format(technical spec)
RoR::ConfigFile::SetString
void SetString(Ogre::String key, Ogre::String value, Ogre::String section=Ogre::BLANKSTRING)
Definition: ConfigFile.cpp:99
RoR::SanitizeUtf8String
std::string SanitizeUtf8String(std::string const &str_in)
Definition: Utils.cpp:117
Console.h
RoR::ConfigFile::m_log_filename
std::string m_log_filename
Definition: ConfigFile.h:91
RoR::ConfigFile::getString
Ogre::String getString(Ogre::String const &key, Ogre::String const &section, Ogre::String const &defaultValue="")
Definition: ConfigFile.cpp:89
Utils.h
RoR::ConfigFile::getBool
bool getBool(Ogre::String const &key, bool defaultValue=false)
Definition: ConfigFile.h:57
Application.h
Central state/object manager and communications hub.
RoR::ConfigFile::getFloat
float getFloat(Ogre::String const &key, float defaultValue=0.f)
Definition: ConfigFile.h:50
RoR::ConfigFile::HasSection
bool HasSection(std::string const &name)
Definition: ConfigFile.cpp:117
RoR::ConfigFile::getVector3
Ogre::Vector3 getVector3(Ogre::String const &key, Ogre::String const &section, Ogre::Vector3 const &defaultValue=Ogre::Vector3::ZERO)
Definition: ConfigFile.cpp:62
RoR::ConfigFile::getColourValue
Ogre::ColourValue getColourValue(Ogre::String const &key, Ogre::ColourValue const &defaultValue=Ogre::ColourValue())
Definition: ConfigFile.h:41
ConfigFile.h
RoR
Definition: AppContext.h:36