Skip to content

Commit

Permalink
💡 ConfigFile: parsing errors now contain filename + subsystem.
Browse files Browse the repository at this point in the history
  • Loading branch information
ohlidalp authored and Petr Ohlídal committed Dec 27, 2021
1 parent 7299c01 commit 16e1f27
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 5 deletions.
2 changes: 2 additions & 0 deletions source/main/resources/otc_fileformat/OTCFileFormat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "OTCFileFormat.h"

#include "Application.h"
#include "Console.h"
#include "SimConstants.h"
#include "ConfigFile.h"
#include "Utils.h"
Expand All @@ -43,6 +44,7 @@ bool RoR::OTCParser::LoadMasterConfig(Ogre::DataStreamPtr &ds, const char* filen
try
{
cfg.load(ds, "\t:=", false);
cfg.setLoggingInfo(ds->getName(), Console::CONSOLE_MSGTYPE_TERRN);

m_def->disable_cache = cfg.getBool ("disableCaching", false);
m_def->world_size_x = cfg.getInt ("WorldSizeX", 1024);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ bool Terrn2Parser::LoadTerrn2(Terrn2Def& def, Ogre::DataStreamPtr &ds)
{
RoR::ConfigFile file;
file.load(ds, "\t:=", true);
file.setLoggingInfo(ds->getName(), Console::CONSOLE_MSGTYPE_TERRN);

// read in the settings
def.name = file.getString("Name", "General");
Expand Down
11 changes: 9 additions & 2 deletions source/main/utils/ConfigFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Ogre::ColourValue ConfigFile::getColourValue(Ogre::String const& key, Ogre::Stri
}
else
{
App::GetConsole()->putMessage(Console::CONSOLE_MSGTYPE_INFO, Console::CONSOLE_SYSTEM_WARNING,
this->logMessage(
fmt::format("Could not parse '{}/{}' ({}) as color, format must be 'R G B A' or 'R G B', falling back to '{}'",
section, key, value, Ogre::StringConverter::toString(defaultValue)));
return defaultValue;
Expand All @@ -69,7 +69,7 @@ Ogre::Vector3 ConfigFile::getVector3(Ogre::String const& key, Ogre::String const
}
else
{
App::GetConsole()->putMessage(Console::CONSOLE_MSGTYPE_INFO, Console::CONSOLE_SYSTEM_WARNING,
this->logMessage(
fmt::format("Could not parse '{}/{}' ({}) as vector3, format must be 'X Y Z', falling back to '{}'",
section, key, value, Ogre::StringConverter::toString(defaultValue)));
return defaultValue;
Expand Down Expand Up @@ -120,3 +120,10 @@ bool ConfigFile::HasSection(std::string const & name)
// without either an OGRE exception being logged or using deprecated API.
return this->getSettingsBySection().find(name) != this->getSettingsBySection().end();
}

void ConfigFile::logMessage(std::string const & msg)
{
// If filename is specified, log "filename: message", otherwise just "message".
App::GetConsole()->putMessage(m_log_area, Console::CONSOLE_SYSTEM_WARNING,
fmt::format("{}{}{}", m_log_filename, (m_log_filename == "" ? "" : ": "), msg));
}
18 changes: 15 additions & 3 deletions source/main/utils/ConfigFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@

#pragma once

#include <OgreConfigFile.h>
#include <OgreColourValue.h>
#include <OgreString.h>
#include "Console.h"

#include <Ogre.h>

namespace RoR {

Expand Down Expand Up @@ -74,10 +74,22 @@ class ConfigFile: public Ogre::ConfigFile

bool HasSection(std::string const & name);

void setLoggingInfo(std::string const & filename, Console::MessageArea area)
{
m_log_filename = filename;
m_log_area = area;
}

private:
//Block access to Ogre::ConfigFile::getSetting() - not UTF8 safe!
Ogre::String getSetting(Ogre::String, Ogre::String);
Ogre::String getSetting(Ogre::String, Ogre::String, Ogre::String);

void logMessage(std::string const & msg);

// Logging info.
std::string m_log_filename;
Console::MessageArea m_log_area = Console::CONSOLE_MSGTYPE_INFO;
};

} // namespace RoR

0 comments on commit 16e1f27

Please # to comment.