ManaPlus
Public Member Functions | Private Types | Private Attributes
Configuration Class Reference

#include <configuration.h>

Inheritance diagram for Configuration:
ConfigurationObject

Public Member Functions

 Configuration ()
 
 ~Configuration ()
 
void init (const std::string &filename, const UseVirtFs useResManager=UseVirtFs_false, const SkipError skipError=SkipError_false)
 
void reInit ()
 
void unload ()
 
DefaultsDatagetDefaultValues ()
 
void write ()
 
void addListener (const std::string &key, ConfigListener *const listener)
 
void removeListener (const std::string &key, ConfigListener *const listener)
 
void removeListeners (ConfigListener *const listener)
 
void setValue (const std::string &key, const std::string &value)
 
void incValue (const std::string &key)
 
void setSilent (const std::string &key, const std::string &value)
 
void setValue (const std::string &key, const char *const value)
 
void setSilent (const std::string &key, const char *const value)
 
void setValue (const std::string &key, const float value)
 
void setValue (const std::string &key, const double value)
 
void setValue (const std::string &key, const int value)
 
void setValueInt (const std::string &key, const int value)
 
void setValue (const std::string &key, const unsigned value)
 
void setValue (const std::string &key, const bool value)
 
void setSilent (const std::string &key, const bool value)
 
int resetIntValue (const std::string &key)
 
bool resetBoolValue (const std::string &key)
 
const std::string & getConfigPath () const
 
int getIntValue (const std::string &key) const
 
float getFloatValue (const std::string &key) const
 
std::string getStringValue (const std::string &key) const
 
bool getBoolValue (const std::string &key) const
 
std::string getDirectory () const
 
void removeOldKeys ()
 
std::string getFileName () const
 
void writeUpdated ()
 
void cleanDefaults ()
 
- Public Member Functions inherited from ConfigurationObject
virtual ~ConfigurationObject ()
 
void deleteKey (const std::string &key)
 
std::string getValue (const std::string &key, const std::string &deflt) const
 
int getValue (const std::string &key, const int deflt) const
 
int getValueInt (const std::string &key, const int deflt) const
 
bool getValueBool (const std::string &key, const bool deflt) const
 
unsigned getValue (const std::string &key, const unsigned deflt) const
 
double getValue (const std::string &key, const double deflt) const
 
void clear ()
 
template<class IT , class T , class CONT >
void setList (const std::string &name, IT begin, IT end, ConfigurationListManager< T, CONT > *manager)
 
template<class T , class CONT >
CONT getList (const std::string &name, CONT empty, ConfigurationListManager< T, CONT > *manager)
 

Private Types

typedef std::list< ConfigListener * > Listeners
 
typedef Listeners::iterator ListenerIterator
 
typedef std::map< std::string, ListenersListenerMap
 
typedef ListenerMap::iterator ListenerMapIterator
 

Private Attributes

ListenerMap mListenerMap
 
std::string mConfigPath
 
DefaultsData mDefaultsData
 Defaults of value for a given key. More...
 
std::string mDirectory
 
std::string mFilename
 
UseVirtFs mUseResManager
 
bool mUpdated
 

Additional Inherited Members

- Protected Types inherited from ConfigurationObject
typedef std::map< std::string, std::string > Options
 
typedef std::list< ConfigurationObject * > ConfigurationList
 
- Protected Member Functions inherited from ConfigurationObject
 ConfigurationObject ()
 
virtual void initFromXML (const xmlNode *const parentNode)
 
virtual void writeToXML (const xmlTextWriterPtr writer)
 
void deleteList (const std::string &name)
 
- Protected Attributes inherited from ConfigurationObject
Options mOptions
 
std::map< std::string, ConfigurationListmContainerOptions
 

Detailed Description

Configuration handler for reading (and writing).

Definition at line 235 of file configuration.h.

Member Typedef Documentation

◆ ListenerIterator

typedef Listeners::iterator Configuration::ListenerIterator
private

Definition at line 371 of file configuration.h.

◆ ListenerMap

typedef std::map<std::string, Listeners> Configuration::ListenerMap
private

Definition at line 372 of file configuration.h.

◆ ListenerMapIterator

typedef ListenerMap::iterator Configuration::ListenerMapIterator
private

Definition at line 373 of file configuration.h.

◆ Listeners

typedef std::list<ConfigListener*> Configuration::Listeners
private

Definition at line 370 of file configuration.h.

Constructor & Destructor Documentation

◆ Configuration()

Configuration::Configuration ( )

Definition at line 361 of file configuration.cpp.

361  :
363  mListenerMap(),
364  mConfigPath(),
365  mDefaultsData(),
366  mDirectory(),
367  mFilename(),
369  mUpdated(false)
370 {
371 #ifdef DEBUG_CONFIG
372  mLogKeys = false;
373  mIsMain = false;
374 #endif // DEBUG_CONFIG
375 }
const bool UseVirtFs_false
Definition: usevirtfs.h:29
std::string mDirectory
std::string mFilename
ListenerMap mListenerMap
DefaultsData mDefaultsData
Defaults of value for a given key.
std::string mConfigPath
UseVirtFs mUseResManager

◆ ~Configuration()

Configuration::~Configuration ( )

Definition at line 388 of file configuration.cpp.

References cleanDefaults().

389 {
390  cleanDefaults();
391 }

Member Function Documentation

◆ addListener()

void Configuration::addListener ( const std::string &  key,
ConfigListener *const  listener 
)

◆ cleanDefaults()

void Configuration::cleanDefaults ( )

Clean up the default values member.

Definition at line 377 of file configuration.cpp.

References mDefaultsData.

Referenced by init(), setBrandingDefaults(), setConfigDefaults(), setFeaturesDefaults(), setPathsDefaults(), unload(), and ~Configuration().

378 {
379  for (DefaultsData::const_iterator iter = mDefaultsData.begin();
380  iter != mDefaultsData.end();
381  ++iter)
382  {
383  delete iter->second;
384  }
385  mDefaultsData.clear();
386 }
DefaultsData mDefaultsData
Defaults of value for a given key.

◆ getBoolValue()

bool Configuration::getBoolValue ( const std::string &  key) const

Definition at line 596 of file configuration.cpp.

References CAST_S32, data, VariableData::DATA_BOOL, VariableData::DATA_FLOAT, VariableData::DATA_INT, VariableData::DATA_STRING, getBoolFromString(), GETLOG, VariableData::getType(), mConfigPath, mDefaultsData, ConfigurationObject::mOptions, and reportAlways.

Referenced by ChangeDisplay::action(), Setup_Video::action(), SkillDialog::action(), ChatWindow::action(), anonymous_namespace{client.cpp}::LoginListener::action(), ChatWindow::addChannelTab(), PopupMenu::addFollow(), Game::addWatermark(), ChatWindow::addWhisper(), ChatWindow::addWhisperTab(), Game::adjustPerfomance(), ChatWindow::adjustTabSize(), Setup_Audio::apply(), Setup_Misc::apply(), Setup_Video::apply(), applyEffectByOption(), applyEffectByOption1(), WindowManager::applyGamma(), WindowManager::applyGrabMode(), DialogsManager::attributeChanged(), ChatWindow::attributeChanged(), ConfigManager::backupConfig(), BattleTab::BattleTab(), Actions::changeRelation(), Ea::ChatHandler::ChatHandler(), ChatWindow::chatInput(), ChatTab::chatLog(), ChatWindow::ChatWindow(), Ea::LoginHandler::chooseServer(), Ea::ChatHandler::clear(), TradeWindow::completeTrade(), createGuiWindows(), GraphicsManager::createRenderers(), Game::createScreenshot(), Ea::PartyRecv::createTab(), GuildManager::createTab(), Actions::doSit(), EmulateGuildTab::EmulateGuildTab(), ActorManager::findNearestLivingBeing(), LocalPlayer::fixAttackTarget(), ChatInput::focusLost(), Game::Game(), Client::gameInit(), Viewport::getMouseTile(), MobileOpenGLScreenshotHelper::getScreenshot(), OpenGLScreenshotHelper::getScreenshot(), GuildTab::GuildTab(), WhoIsOnline::handleLink(), GameModifiers::init(), EventsManager::init(), KeyboardConfig::init(), SoundManager::init(), Joystick::init(), Settings::init(), TouchManager::init(), Client::initConfigListeners(), Client::initFeatures(), GraphicsManager::initGraphics(), Client::initGraphics(), Map::initializeParticleEffects(), GraphicsManager::initOpenGLFunctions(), Dirs::initScreenshotDir(), Client::initSoundManager(), SetupItem::load(), WhoIsOnline::loadList(), loadReplaceLayer(), WhoIsOnline::loadWebList(), LocalPlayer::LocalPlayer(), UpdaterWindow::logic(), Map::Map(), Joystick::open(), DialogsManager::openErrorDialog(), GuildTab::optionChanged(), PartyTab::optionChanged(), GuiConfigListener::optionChanged(), EmulateGuildTab::optionChanged(), AvatarListBox::optionChanged(), SoundManager::optionChanged(), EventsManager::optionChanged(), Minimap::optionChanged(), Client::optionChanged(), WhoIsOnline::optionChanged(), Viewport::optionChanged(), MapLayer::optionChanged(), TouchManager::optionChanged(), NpcDialog::optionChanged(), ChatWindow::optionChanged(), Map::optionChanged(), LocalPlayer::optionChanged(), ActorManager::optionChanged(), PartyTab::PartyTab(), LocalPlayer::pickedUp(), SocialWindow::postInit(), WhoIsOnline::postInit(), Gui::postInit(), MobileOpenGLScreenshotHelper::prepare(), OpenGLScreenshotHelper::prepare(), Ea::BeingRecv::processBeingRemove(), TmwAthena::CharServerRecv::processChangeMapServer(), EAthena::CharServerRecv::processChangeMapServer(), TmwAthena::CharServerRecv::processCharMapInfo(), EAthena::CharServerRecv::processCharMapInfo(), EAthena::GuildRecv::processGuildPositionInfo(), Ea::ChatRecv::processMVPEffect(), EAthena::PlayerRecv::processOnlineList(), ShopWindow::processRequest(), ChatInput::processVisible(), TmwAthena::ChatRecv::processWhisperContinue(), MapReader::readTileset(), Map::reduce(), TmwAthena::BuySellHandler::requestBuyList(), TmwAthena::BuySellHandler::requestSellList(), Being::reReadConfig(), Game::resetAdjustLevel(), ChatTab::saveToLogFile(), TmwAthena::BuySellHandler::sendBuyRequest(), ShopWindow::sendMessage(), TmwAthena::BuySellHandler::sendSellRequest(), ServerDialog::ServerDialog(), Desktop::setBestFittingWallpaper(), Minimap::setMap(), TradeWindow::setMoney(), Graphics::setOpenGLMode(), ActorSprite::setStatusEffectBlock(), ParticleEngine::setupEngine(), GraphicsManager::setVideoMode(), PopupMenu::showDropPopup(), ChatWindow::showGMTab(), PopupMenu::showItemPopup(), Being::showName(), PopupMenu::showPopup(), Actions::splitWhisper(), ConfigManager::storeSafeParameters(), SoundManager::testAudio(), updateEnv(), SocialNavigationTab::updateList(), GraphicsManager::updateTextureFormat(), and ItemShortcut::useItem().

597 {
598  GETLOG();
599  bool defaultValue = false;
600  const Options::const_iterator iter = mOptions.find(key);
601  if (iter == mOptions.end())
602  {
603  const DefaultsData::const_iterator itdef
604  = mDefaultsData.find(key);
605 
606  if (itdef != mDefaultsData.end() &&
607  (itdef->second != nullptr))
608  {
609  const VariableData *const data = itdef->second;
610  const VariableData::DataType type = static_cast<
612  if (type == VariableData::DATA_BOOL)
613  {
614  defaultValue = (static_cast<const BoolData*>(
615  data))->getData();
616  }
617  else if (type == VariableData::DATA_INT)
618  {
619  if ((static_cast<const IntData*>(data))->getData() != 0)
620  defaultValue = true;
621  else
622  defaultValue = false;
623  }
624  else if (type == VariableData::DATA_STRING)
625  {
626  if ((static_cast<const StringData*>(
627  data))->getData() != "0")
628  {
629  defaultValue = true;
630  }
631  else
632  {
633  defaultValue = false;
634  }
635  }
636  if (type == VariableData::DATA_FLOAT)
637  {
638  if (CAST_S32((static_cast<const FloatData*>(
639  data))->getData()) != 0)
640  {
641  defaultValue = true;
642  }
643  else
644  {
645  defaultValue = false;
646  }
647  }
648  }
649  else
650  {
651  reportAlways(
652  "%s: No boolean value in registry for key %s",
653  mConfigPath.c_str(),
654  key.c_str());
655  }
656  }
657  else
658  {
659  defaultValue = getBoolFromString(iter->second);
660  }
661 
662  return defaultValue;
663 }
virtual int getType() const =0
#define GETLOG()
DefaultsData mDefaultsData
Defaults of value for a given key.
#define CAST_S32
Definition: cast.h:29
uint32_t data
bool getBoolFromString(const std::string &text)
std::string mConfigPath
#define reportAlways(...)
Definition: checkutils.h:252

◆ getConfigPath()

const std::string& Configuration::getConfigPath ( ) const
inline

Definition at line 335 of file configuration.h.

References A_WARN_UNUSED_NON_TESTS.

Referenced by anonymous_namespace{client.cpp}::LoginListener::action(), and Client::gameInit().

336  { return mConfigPath; }
std::string mConfigPath

◆ getDefaultValues()

DefaultsData& Configuration::getDefaultValues ( )
inline

Definition at line 258 of file configuration.h.

References anonymous_namespace{itemlinkhandler.cpp}::listener, and VirtFs::write().

Referenced by setBrandingDefaults(), setConfigDefaults(), setConfigDefaults2(), setFeaturesDefaults(), and setPathsDefaults().

259  { return mDefaultsData; }
DefaultsData mDefaultsData
Defaults of value for a given key.

◆ getDirectory()

std::string Configuration::getDirectory ( ) const
inline

Definition at line 354 of file configuration.h.

Referenced by Dirs::updateDataPath().

355  { return mDirectory; }
std::string mDirectory

◆ getFileName()

std::string Configuration::getFileName ( ) const
inline

◆ getFloatValue()

float Configuration::getFloatValue ( const std::string &  key) const

Definition at line 541 of file configuration.cpp.

References data, VariableData::DATA_BOOL, VariableData::DATA_FLOAT, VariableData::DATA_INT, VariableData::DATA_STRING, GETLOG, VariableData::getType(), mConfigPath, mDefaultsData, ConfigurationObject::mOptions, and reportAlways.

Referenced by anonymous_namespace{client.cpp}::LoginListener::action(), WindowManager::applyGamma(), GraphicsManager::initGraphics(), Client::optionChanged(), Map::optionChanged(), and Text::Text().

542 {
543  GETLOG();
544  float defaultValue = 0.0F;
545  const Options::const_iterator iter = mOptions.find(key);
546  if (iter == mOptions.end())
547  {
548  const DefaultsData::const_iterator itdef
549  = mDefaultsData.find(key);
550 
551  if (itdef != mDefaultsData.end() &&
552  (itdef->second != nullptr))
553  {
554  const VariableData *const data = itdef->second;
555  const VariableData::DataType type = static_cast<
557  if (type == VariableData::DATA_FLOAT)
558  {
559  defaultValue = static_cast<float>(
560  (static_cast<const FloatData*>(data))->getData());
561  }
562  else if (type == VariableData::DATA_STRING)
563  {
564  defaultValue = static_cast<float>(atof((
565  static_cast<const StringData*>(
566  data))->getData().c_str()));
567  }
568  else if (type == VariableData::DATA_BOOL)
569  {
570  if ((static_cast<const BoolData*>(data))->getData())
571  defaultValue = 1;
572  else
573  defaultValue = 0;
574  }
575  else if (type == VariableData::DATA_INT)
576  {
577  defaultValue = static_cast<float>((
578  static_cast<const IntData*>(
579  data))->getData());
580  }
581  }
582  else
583  {
584  reportAlways("%s: No float value in registry for key %s",
585  mConfigPath.c_str(),
586  key.c_str());
587  }
588  }
589  else
590  {
591  defaultValue = static_cast<float>(atof(iter->second.c_str()));
592  }
593  return defaultValue;
594 }
virtual int getType() const =0
#define GETLOG()
DefaultsData mDefaultsData
Defaults of value for a given key.
uint32_t data
std::string mConfigPath
#define reportAlways(...)
Definition: checkutils.h:252

◆ getIntValue()

int Configuration::getIntValue ( const std::string &  key) const

returns a value corresponding to the given key. The default value returned in based on fallbacks registry.

See also
defaults.h

Definition at line 403 of file configuration.cpp.

References CAST_S32, data, VariableData::DATA_BOOL, VariableData::DATA_FLOAT, VariableData::DATA_INT, VariableData::DATA_STRING, GETLOG, VariableData::getType(), mConfigPath, mDefaultsData, ConfigurationObject::mOptions, and reportAlways.

Referenced by Setup_Video::action(), DidYouKnowWindow::action(), RegisterDialog::action(), anonymous_namespace{client.cpp}::LoginListener::action(), Net::Download::addProxy(), Game::adjustPerfomance(), LocalPlayer::afkRespond(), Setup_Theme::apply(), Setup_Video::apply(), WindowManager::applyKeyRepeat(), WindowManager::applyScale(), WindowManager::applyVSync(), ConfigManager::backupConfig(), CharacterViewNormal::CharacterViewNormal(), CharCreateDialog::CharCreateDialog(), CharSelectDialog::CharSelectDialog(), ChatTab::chatLog(), ChatTab::ChatTab(), ConfigManager::checkConfigVersion(), GraphicsManager::createRenderers(), NpcDialog::createSkinControls(), GraphicsManager::detectPixelSize(), Actions::doSit(), EquipmentWindow::EquipmentWindow(), TouchManager::executeAction(), Client::gameInit(), Being::getDefaultEffectId(), Being::getHitEffect(), Viewport::getMouseTile(), EventsManager::handleActive(), Being::handleSkill(), Being::handleSkillCasting(), GameModifiers::init(), KeyboardConfig::init(), SoundManager::init(), Joystick::init(), BuyDialog::init(), TouchManager::init(), BeingInfo::init(), Client::initConfigListeners(), Client::initFeatures(), GraphicsManager::initGraphics(), Client::initSoundManager(), InventoryWindow::InventoryWindow(), SetupItem::load(), MiniStatusWindow::loadBars(), DidYouKnowWindow::loadData(), ItemDB::loadXmlFile(), EventsManager::logEvent(), NpcDialog::NpcDialog(), Joystick::open(), SoundManager::optionChanged(), Client::optionChanged(), WindowMenu::optionChanged(), Viewport::optionChanged(), TouchManager::optionChanged(), Map::optionChanged(), LocalPlayer::optionChanged(), Being::optionChanged(), SkillDialog::playCastingDstTileEffect(), SkillDialog::playRemoveEffect(), SkillDialog::playUpdateEffect(), SetupWindow::postInit(), Gui::postInit(), Being::postInit(), BeingCommon::readObjectNodes(), RegisterDialog::RegisterDialog(), Being::reReadConfig(), Game::resetAdjustLevel(), CharCreateDialog::setAttributes(), CharCreateDialog::setDefaultGender(), TmwAthena::setGm(), Being::setSpiritBalls(), Setup_Input::Setup_Input(), Setup_Joystick::Setup_Joystick(), Setup_Video::Setup_Video(), ParticleEngine::setupEngine(), GraphicsManager::setVideoMode(), ShopWindow::ShopWindow(), ChatWindow::showGMTab(), Game::slowLogic(), ConfigManager::storeSafeParameters(), SoundManager::testAudio(), ActorManager::updateBadges(), GraphicsManager::updateDebugLog(), updateEnv(), Gui::updateFonts(), Game::updateFrameRate(), GraphicsManager::updateTextureCompressionFormat(), and WindowMenu::WindowMenu().

404 {
405  GETLOG();
406  int defaultValue = 0;
407  const Options::const_iterator iter = mOptions.find(key);
408  if (iter == mOptions.end())
409  {
410  const DefaultsData::const_iterator itdef
411  = mDefaultsData.find(key);
412 
413  if (itdef != mDefaultsData.end() && (itdef->second != nullptr))
414  {
415  const VariableData *const data = itdef->second;
416  const VariableData::DataType type = static_cast<
418  if (type == VariableData::DATA_INT)
419  {
420  defaultValue = (static_cast<const IntData*>(
421  data))->getData();
422  }
423  else if (type == VariableData::DATA_STRING)
424  {
425  defaultValue = atoi((static_cast<const StringData*>(
426  data))->getData().c_str());
427  }
428  else if (type == VariableData::DATA_BOOL)
429  {
430  if ((static_cast<const BoolData*>(data))->getData())
431  defaultValue = 1;
432  else
433  defaultValue = 0;
434  }
435  else if (type == VariableData::DATA_FLOAT)
436  {
437  defaultValue = CAST_S32(
438  (static_cast<const FloatData*>(data))->getData());
439  }
440  }
441  else
442  {
443  reportAlways(
444  "%s: No integer value in registry for key %s",
445  mConfigPath.c_str(),
446  key.c_str());
447  }
448  }
449  else
450  {
451  defaultValue = atoi(iter->second.c_str());
452  }
453  return defaultValue;
454 }
virtual int getType() const =0
#define GETLOG()
DefaultsData mDefaultsData
Defaults of value for a given key.
#define CAST_S32
Definition: cast.h:29
uint32_t data
std::string mConfigPath
#define reportAlways(...)
Definition: checkutils.h:252

◆ getStringValue()

std::string Configuration::getStringValue ( const std::string &  key) const

Definition at line 487 of file configuration.cpp.

References data, VariableData::DATA_BOOL, VariableData::DATA_FLOAT, VariableData::DATA_INT, VariableData::DATA_STRING, GETLOG, VariableData::getType(), mConfigPath, mDefaultsData, ConfigurationObject::mOptions, reportAlways, and Catch::toString().

Referenced by SetupItemSound::action(), Being::addEffect(), Net::Download::addProxy(), SkillDialog::addSkill(), Setup_Theme::apply(), Setup_Theme::cancel(), Actions::changeRelation(), PlayerRelationsManager::checkName(), CrazyMoves::crazyMoveA(), Actions::doSit(), UpdaterWindow::download(), ServerDialog::downloadServerList(), EffectManager::EffectManager(), EquipmentWindow::fillBoxes(), Theme::fillFontsList(), Theme::fillSkinsList(), Theme::fillSoundsList(), SkillDialog::getDefaultSkillIcon(), ShadersManager::getGles2Program(), StatusEffect::getIcon(), Item::getImage(), getLang(), getLangShort(), getLangSimple(), ShadersManager::getSimpleProgram(), SpriteDef::includeSprite(), initDefaultThemePath(), initDefaultWallpaperPaths(), Client::initFeatures(), GraphicsManager::initGraphics(), Dirs::initScreenshotDir(), WindowManager::initTitle(), Dirs::initUpdatesDir(), LanguageDb::load(), SoundDB::load(), TextDb::load(), ModDB::load(), StatDb::load(), GroupDb::load(), ItemFieldDb::load(), DeadDB::load(), AvatarDB::load(), ItemOptionDb::load(), PETDB::load(), SkillUnitDb::load(), UnitsDb::load(), QuestDb::load(), CharDB::load(), CommandsDB::load(), ElementalDb::load(), HomunculusDB::load(), MercenaryDB::load(), MonsterDB::load(), NPCDB::load(), ColorDB::load(), HorseDB::load(), ItemDB::load(), MapDB::load(), NetworkDb::load(), NpcDialogDB::load(), EmoteDB::load(), SpriteDef::load(), StatusEffectDB::load(), SetupItem::load(), Client::loadData(), PlayerInfo::loadData(), loadDB(), MapReader::loadEmptyAtlas(), DidYouKnowWindow::loadFile(), HelpWindow::loadFile(), Net::loadIgnorePackets(), TextCommand::loadImage(), loadMusic(), PaletteDB::loadPalette(), UpdaterWindow::loadPatch(), loadReplaceLayer(), ServerDialog::loadServers(), SkillDialog::loadSkillData(), SkillDialog::loadSkills(), EmoteDB::loadSpecialXmlFile(), HelpWindow::loadTags(), DeadDB::loadXmlFile(), GroupDb::loadXmlFile(), PETDB::loadXmlFile(), SkillUnitDb::loadXmlFile(), UnitsDb::loadXmlFile(), HorseDB::loadXmlFile(), ElementalDb::loadXmlFile(), HomunculusDB::loadXmlFile(), MercenaryDB::loadXmlFile(), MonsterDB::loadXmlFile(), EmoteDB::loadXmlFile(), NPCDB::loadXmlFile(), StatusEffectDB::loadXmlFile(), ServerDialog::needUpdateServers(), ChatWindow::parseGlobalsFilter(), ChatWindow::parseHighlights(), NpcDialog::parseListItems(), SoundManager::playGuiSound(), SoundManager::playSfx(), Gui::postInit(), EquipmentWindow::prepareSlotNames(), Theme::prepareThemePath(), MapDB::readAtlas(), Theme::resolveThemePath(), Being::setGender(), Being::setHairTempSprite(), SkillData::setIcon(), Item::setId(), ItemPopup::setItem(), setLangEnv(), Being::setLanguageId(), Minimap::setMap(), ChatLogger::setServerName(), Being::setSpriteCards(), Being::setSpriteColor(), Being::setSpriteColorId(), Being::setSpriteId(), Being::setTempSprite(), Setup_Perfomance::Setup_Perfomance(), Setup_Theme::Setup_Theme(), ActorSprite::setupSpriteDisplay(), CutInWindow::show(), Being::showAwayBadge(), Being::showGmBadge(), Being::showGuildBadge(), Being::showInactiveBadge(), Being::showNameBadge(), Being::showPartyBadge(), Being::showShopBadge(), Being::showTeamBadge(), ConfigManager::storeSafeParameters(), UserAgent::update(), Dirs::updateDataPath(), Gui::updateFonts(), MapReader::updateMusic(), and WindowManager::updateTitle().

488 {
489  GETLOG();
490  std::string defaultValue;
491  const Options::const_iterator iter = mOptions.find(key);
492  if (iter == mOptions.end())
493  {
494  const DefaultsData::const_iterator
495  itdef = mDefaultsData.find(key);
496 
497  if (itdef != mDefaultsData.end() &&
498  (itdef->second != nullptr))
499  {
500  const VariableData *const data = itdef->second;
501  const VariableData::DataType type = static_cast<
503  if (type == VariableData::DATA_STRING)
504  {
505  defaultValue = (static_cast<const StringData*>(
506  data))->getData();
507  }
508  else if (type == VariableData::DATA_BOOL)
509  {
510  if ((static_cast<const BoolData*>(data))->getData())
511  defaultValue = "1";
512  else
513  defaultValue = "0";
514  }
515  else if (type == VariableData::DATA_INT)
516  {
517  defaultValue = toString((static_cast<const IntData*>(
518  data))->getData());
519  }
520  else if (type == VariableData::DATA_FLOAT)
521  {
522  defaultValue = toString((static_cast<const FloatData*>(
523  data))->getData());
524  }
525  }
526  else
527  {
528  reportAlways("%s: No string value in registry for key %s",
529  mConfigPath.c_str(),
530  key.c_str());
531  }
532  }
533  else
534  {
535  defaultValue = iter->second;
536  }
537  return defaultValue;
538 }
virtual int getType() const =0
#define GETLOG()
DefaultsData mDefaultsData
Defaults of value for a given key.
uint32_t data
std::string toString(T const &value)
converts any type to a string
Definition: catch.hpp:1774
std::string mConfigPath
#define reportAlways(...)
Definition: checkutils.h:252

◆ incValue()

void Configuration::incValue ( const std::string &  key)

Definition at line 254 of file configuration.cpp.

References GETLOG, ConfigurationObject::mOptions, and ConfigurationObject::setValue().

Referenced by anonymous_namespace{client.cpp}::LoginListener::action(), Game::Game(), and Client::gameInit().

255 {
256  GETLOG();
257  const Options::const_iterator iter = mOptions.find(key);
258  setValue(key, (iter != mOptions.end())
259  ? atoi(iter->second.c_str()) + 1 : 1);
260 }
#define GETLOG()
void setValue(const std::string &key, const std::string &value)

◆ init()

void Configuration::init ( const std::string &  filename,
const UseVirtFs  useResManager = UseVirtFs_false,
const SkipError  skipError = SkipError_false 
)

Reads config file and parse all options into memory.

Parameters
filenamepath to config file
useResManagerMake use of the resource manager.

Definition at line 738 of file configuration.cpp.

References cleanDefaults(), ConfigurationObject::clear(), VirtFs::exists(), Files::existsLocal(), getFileDir(), getRealPath(), ConfigurationObject::initFromXML(), Logger::log(), Logger::log1(), logger, mConfigPath, mDirectory, mFilename, mUseResManager, XML::Document::rootNode(), and UseVirtFs_true.

Referenced by anonymous_namespace{client.cpp}::LoginListener::action(), Client::gameExec(), Client::gameInit(), TestMain::initConfig(), ConfigManager::initConfiguration(), Client::initFeatures(), Dirs::initRootDir(), ConfigManager::initServerConfig(), Client::loadData(), and TestMain::writeConfig().

741 {
742  cleanDefaults();
743  clear();
744  mFilename = filename;
745  mUseResManager = useResManager;
746 
747  if (useResManager == UseVirtFs_true)
748  {
749  mConfigPath = "virtfs://" + filename;
750  mDirectory.clear();
751  if (VirtFs::exists(filename) == false)
752  {
753  logger->log("Warning: No configuration file (%s)",
754  filename.c_str());
755  return;
756  }
757  }
758  else
759  {
760  mConfigPath = filename;
761  logger->log1("init 1");
762  mDirectory = getRealPath(getFileDir(filename));
763  if (Files::existsLocal(filename) == false)
764  {
765  logger->log("Warning: No configuration file (%s)",
766  filename.c_str());
767  return;
768  }
769  }
770 
771  XML::Document doc(filename,
772  useResManager,
773  skipError);
774  logger->log1("init 2");
775  if (doc.rootNode() == nullptr)
776  {
777  logger->log("Couldn't open configuration file: %s", filename.c_str());
778  return;
779  }
780 
781  XmlNodeConstPtrConst rootNode = doc.rootNode();
782 
783  if ((rootNode == nullptr) || !xmlNameEqual(rootNode, "configuration"))
784  {
785  logger->log("Warning: No configuration file (%s)", filename.c_str());
786  return;
787  }
788 
789  initFromXML(rootNode);
790 }
void log1(const char *const log_text)
Definition: logger.cpp:222
virtual void initFromXML(const xmlNode *const parentNode)
std::string mDirectory
std::string mFilename
Logger * logger
Definition: logger.cpp:95
const bool UseVirtFs_true
Definition: usevirtfs.h:29
bool exists(std::string name)
Definition: fs.cpp:123
std::string mConfigPath
UseVirtFs mUseResManager
bool existsLocal(const std::string &path)
Definition: files.cpp:207
void log(const char *const log_text,...)
Definition: logger.cpp:243
std::string getRealPath(const std::string &str)
Definition: paths.cpp:76
std::string getFileDir(const std::string &path)

◆ reInit()

void Configuration::reInit ( )

Definition at line 792 of file configuration.cpp.

References ConfigurationObject::initFromXML(), Logger::log(), logger, mFilename, mUseResManager, XML::Document::rootNode(), and SkipError_false.

793 {
795  if (doc.rootNode() == nullptr)
796  {
797  logger->log("Couldn't open configuration file: %s", mFilename.c_str());
798  return;
799  }
800 
801  XmlNodeConstPtrConst rootNode = doc.rootNode();
802 
803  if ((rootNode == nullptr) || !xmlNameEqual(rootNode, "configuration"))
804  {
805  logger->log("Warning: No configuration file (%s)", mFilename.c_str());
806  return;
807  }
808 
809  initFromXML(rootNode);
810 }
const bool SkipError_false
Definition: skiperror.h:29
virtual void initFromXML(const xmlNode *const parentNode)
std::string mFilename
Logger * logger
Definition: logger.cpp:95
UseVirtFs mUseResManager
void log(const char *const log_text,...)
Definition: logger.cpp:243

◆ removeListener()

void Configuration::removeListener ( const std::string &  key,
ConfigListener *const  listener 
)

Removes a listener from the listen list of the specified config option.

Definition at line 911 of file configuration.cpp.

References FOR_EACH, anonymous_namespace{itemlinkhandler.cpp}::listener, Logger::log(), logger, and mListenerMap.

Referenced by Being::~Being(), LocalPlayer::~LocalPlayer(), MapLayer::~MapLayer(), Theme::~Theme(), and WindowMenu::~WindowMenu().

913 {
914  mListenerMap[key].remove(listener);
915 }
ListenerMap mListenerMap

◆ removeListeners()

void Configuration::removeListeners ( ConfigListener *const  listener)

◆ removeOldKeys()

void Configuration::removeOldKeys ( )

Definition at line 944 of file configuration.cpp.

References ConfigurationObject::deleteKey(), empty, Logger::log(), logger, ConfigurationObject::mOptions, ServerCommandType::str, Catch::toString(), and unusedKeys.

Referenced by Client::gameClear(), and Client::initConfigListeners().

945 {
946  if (mOptions.find(unusedKeys[0]) != mOptions.end() ||
947  mOptions.find(unusedKeys[1]) != mOptions.end() ||
948  mOptions.find(unusedKeys[2]) != mOptions.end())
949  {
950  int f = 0;
951  while (!unusedKeys[f].empty())
952  {
953  deleteKey(unusedKeys[f]);
954  logger->log("remove unused key: " + unusedKeys[f]);
955  f ++;
956  }
957  for (f = 0; f < 80; f ++)
958  {
959  const std::string str = toString(f);
960  deleteKey("Outfit" + str);
961  deleteKey("OutfitUnequip" + str);
962  deleteKey("commandShortcutCmd" + str);
963  deleteKey("commandShortcutFlags" + str);
964  deleteKey("commandShortcutSymbol" + str);
965  deleteKey("drop" + str);
966  deleteKey("shortcut" + str);
967  }
968  }
969 }
const std::string unusedKeys[]
Logger * logger
Definition: logger.cpp:95
std::string empty
Definition: podict.cpp:25
std::string toString(T const &value)
converts any type to a string
Definition: catch.hpp:1774
void deleteKey(const std::string &key)
void log(const char *const log_text,...)
Definition: logger.cpp:243

◆ resetBoolValue()

bool Configuration::resetBoolValue ( const std::string &  key)

Definition at line 665 of file configuration.cpp.

References data, VariableData::DATA_BOOL, GETLOG, VariableData::getType(), mConfigPath, mDefaultsData, reportAlways, and setValue().

Referenced by GameModifiers::resetModifiers().

666 {
667  GETLOG();
668  bool defaultValue = false;
669  const DefaultsData::const_iterator itdef = mDefaultsData.find(key);
670 
671  if (itdef == mDefaultsData.end())
672  {
673  reportAlways("%s: No boolean value in registry for key %s",
674  mConfigPath.c_str(),
675  key.c_str());
676  }
677  else
678  {
679  const VariableData *const data = itdef->second;
680  if (data != nullptr &&
681  data->getType() == VariableData::DATA_BOOL)
682  {
683  defaultValue = (static_cast<const BoolData*>(data))->getData();
684  }
685  else
686  {
687  reportAlways("%s: No boolean value in registry for key %s",
688  mConfigPath.c_str(),
689  key.c_str());
690  }
691  }
692 
693  setValue(key, defaultValue);
694  return defaultValue;
695 }
virtual int getType() const =0
#define GETLOG()
DefaultsData mDefaultsData
Defaults of value for a given key.
uint32_t data
std::string mConfigPath
#define reportAlways(...)
Definition: checkutils.h:252
void setValue(const std::string &key, const std::string &value)

◆ resetIntValue()

int Configuration::resetIntValue ( const std::string &  key)

Definition at line 456 of file configuration.cpp.

References data, VariableData::DATA_INT, GETLOG, VariableData::getType(), mConfigPath, mDefaultsData, reportAlways, and setValue().

Referenced by GameModifiers::resetModifiers().

457 {
458  GETLOG();
459  int defaultValue = 0;
460  const DefaultsData::const_iterator itdef = mDefaultsData.find(key);
461  if (itdef == mDefaultsData.end())
462  {
463  reportAlways("%s: No integer value in registry for key %s",
464  mConfigPath.c_str(),
465  key.c_str());
466  }
467  else
468  {
469  const VariableData *const data = itdef->second;
470  if (data != nullptr &&
471  data->getType() == VariableData::DATA_INT)
472  {
473  defaultValue = (static_cast<const IntData*>(
474  data))->getData();
475  }
476  else
477  {
478  reportAlways("%s: No integer value in registry for key %s",
479  mConfigPath.c_str(),
480  key.c_str());
481  }
482  }
483  setValue(key, defaultValue);
484  return defaultValue;
485 }
virtual int getType() const =0
#define GETLOG()
DefaultsData mDefaultsData
Defaults of value for a given key.
uint32_t data
std::string mConfigPath
#define reportAlways(...)
Definition: checkutils.h:252
void setValue(const std::string &key, const std::string &value)

◆ setSilent() [1/3]

void Configuration::setSilent ( const std::string &  key,
const std::string &  value 
)

Definition at line 262 of file configuration.cpp.

References ConfigurationObject::setValue().

Referenced by Game::adjustPerfomance().

264 {
265  ConfigurationObject::setValue(key, value);
266 }
virtual void setValue(const std::string &key, const std::string &value)

◆ setSilent() [2/3]

void Configuration::setSilent ( const std::string &  key,
const char *const  value 
)
inline

Definition at line 299 of file configuration.h.

301  { if (value != nullptr) setSilent(key, std::string(value)); }
void setSilent(const std::string &key, const std::string &value)

◆ setSilent() [3/3]

void Configuration::setSilent ( const std::string &  key,
const bool  value 
)
inline

Definition at line 327 of file configuration.h.

329  { setSilent(key, value ? "1" : "0"); }
void setSilent(const std::string &key, const std::string &value)

◆ setValue() [1/7]

void Configuration::setValue ( const std::string &  key,
const std::string &  value 
)
virtual

Sets an option using a string value.

Parameters
keyOption identifier.
valueValue.

Reimplemented from ConfigurationObject.

Definition at line 238 of file configuration.cpp.

References FOR_EACH, and ConfigurationObject::setValue().

Referenced by Setup_Video::action(), DidYouKnowWindow::action(), QuitDialog::action(), ChatWindow::action(), BuyDialog::action(), Game::adjustPerfomance(), Setup_Joystick::apply(), Setup_Theme::apply(), Setup_Video::apply(), ConfigManager::backupConfig(), Setup_Video::cancel(), GameModifiers::changeGameModifiers(), GameModifiers::changeMode(), Actions::changeRelation(), ConfigManager::checkConfigVersion(), ServerDialog::connectToSelectedServer(), GraphicsManager::detectGraphics(), GraphicsManager::detectVideoSettings(), ServerDialog::downloadServerList(), Joystick::finishCalibration(), GuildManager::init(), TestMain::initConfig(), ConfigManager::initConfiguration(), GraphicsManager::initGraphics(), GraphicsManager::initOpenGLFunctions(), Dirs::initScreenshotDir(), TestMain::invokeMobileOpenBatchTest(), TestMain::invokeModernOpenBatchTest(), TestMain::invokeModernOpenGLRenderTest(), TestMain::invokeNormalOpenBatchTest(), TestMain::invokeNormalOpenGLRenderTest(), TestMain::invokeSafeOpenBatchTest(), TestMain::invokeSafeOpenGLRenderTest(), TestMain::invokeSoftwareRenderTest(), TestMain::invokeTest(), TestMain::invokeTest4(), DidYouKnowWindow::loadData(), Ea::LoginHandler::loginOrRegister(), LoginDialog::prepareUpdate(), TmwAthena::LoginRecv::processLoginData(), EAthena::LoginRecv::processLoginData(), Game::resetAdjustLevel(), resetBoolValue(), resetIntValue(), WindowManager::resizeVideo(), SpellManager::save(), ItemShortcut::save(), ShortcutBase::save(), SetupItem::save(), OutfitWindow::save(), EmoteShortcut::save(), MiniStatusWindow::saveBars(), WindowMenu::saveButtons(), ServerDialog::saveCustomServers(), LocalPlayer::saveHomes(), Setup_Mods::saveMods(), PlayerInfo::saveProtectedItems(), ChatWindow::saveTab(), Window::saveWindowState(), LocalPlayer::setAfkMessage(), setDefaultOption(), GameModifiers::setQuickDropCounter(), ShopWindow::setShopName(), GraphicsManager::setVideoMode(), Client::stateSwitchLogin1(), InputManager::store(), PlayerRelationsManager::store(), ActorManager::storeAttackList(), ConfigManager::storeSafeParameters(), InventoryWindow::storeSortOrder(), TestMain::writeConfig(), ChatWindow::~ChatWindow(), Minimap::~Minimap(), and UserPalette::~UserPalette().

240 {
241  ConfigurationObject::setValue(key, value);
242  mUpdated = true;
243 
244  // Notify listeners
245  const ListenerMapIterator list = mListenerMap.find(key);
246  if (list != mListenerMap.end())
247  {
248  Listeners listeners = list->second;
249  FOR_EACH (ListenerIterator, i, listeners)
250  (*i)->optionChanged(key);
251  }
252 }
#define FOR_EACH(type, iter, array)
Definition: foreach.h:24
ListenerMap::iterator ListenerMapIterator
ListenerMap mListenerMap
virtual void setValue(const std::string &key, const std::string &value)
std::list< ConfigListener * > Listeners
Listeners::iterator ListenerIterator

◆ setValue() [2/7]

void Configuration::setValue ( const std::string &  key,
const char *const  value 
)
inline

Definition at line 295 of file configuration.h.

297  { if (value != nullptr) setValue(key, std::string(value)); }
void setValue(const std::string &key, const std::string &value)

◆ setValue() [3/7]

void Configuration::setValue ( const std::string &  key,
const float  value 
)
inline

Definition at line 303 of file configuration.h.

References Catch::toString().

305  { setValue(key, toString(value)); }
std::string toString(T const &value)
converts any type to a string
Definition: catch.hpp:1774
void setValue(const std::string &key, const std::string &value)

◆ setValue() [4/7]

void Configuration::setValue ( const std::string &  key,
const double  value 
)
inline

Definition at line 307 of file configuration.h.

References Catch::toString().

309  { setValue(key, toString(value)); }
std::string toString(T const &value)
converts any type to a string
Definition: catch.hpp:1774
void setValue(const std::string &key, const std::string &value)

◆ setValue() [5/7]

void Configuration::setValue ( const std::string &  key,
const int  value 
)
inline

Definition at line 311 of file configuration.h.

References Catch::toString().

313  { setValue(key, toString(value)); }
std::string toString(T const &value)
converts any type to a string
Definition: catch.hpp:1774
void setValue(const std::string &key, const std::string &value)

◆ setValue() [6/7]

void Configuration::setValue ( const std::string &  key,
const unsigned  value 
)
inline

Definition at line 319 of file configuration.h.

References Catch::toString().

321  { setValue(key, toString(value)); }
std::string toString(T const &value)
converts any type to a string
Definition: catch.hpp:1774
void setValue(const std::string &key, const std::string &value)

◆ setValue() [7/7]

void Configuration::setValue ( const std::string &  key,
const bool  value 
)
inline

Definition at line 323 of file configuration.h.

325  { setValue(key, value ? "1" : "0"); }
void setValue(const std::string &key, const std::string &value)

◆ setValueInt()

void Configuration::setValueInt ( const std::string &  key,
const int  value 
)
inline

Definition at line 315 of file configuration.h.

References Catch::toString().

Referenced by GraphicsManager::setVideoMode().

317  { setValue(key, toString(value)); }
std::string toString(T const &value)
converts any type to a string
Definition: catch.hpp:1774
void setValue(const std::string &key, const std::string &value)

◆ unload()

void Configuration::unload ( )

Definition at line 393 of file configuration.cpp.

References cleanDefaults(), ConfigurationObject::clear(), mConfigPath, mDirectory, mFilename, mUseResManager, and UseVirtFs_false.

Referenced by Client::stateSwitchLogin1().

394 {
395  cleanDefaults();
396  mConfigPath.clear();
397  mDirectory.clear();
398  mFilename.clear();
401 }
const bool UseVirtFs_false
Definition: usevirtfs.h:29
std::string mDirectory
std::string mFilename
std::string mConfigPath
UseVirtFs mUseResManager

◆ write()

void Configuration::write ( )

Writes the current settings back to the config file.

Definition at line 858 of file configuration.cpp.

References BLOCK_END, BLOCK_START, Logger::log1(), logger, mConfigPath, mUpdated, reportAlways, and ConfigurationObject::writeToXML().

Referenced by SetupWindow::action(), QuitDialog::action(), ConfigManager::backupConfig(), GraphicsManager::detectGraphics(), Client::gameClear(), Client::initConfigListeners(), TestMain::invokeMobileOpenBatchTest(), TestMain::invokeModernOpenBatchTest(), TestMain::invokeModernOpenGLRenderTest(), TestMain::invokeNormalOpenBatchTest(), TestMain::invokeNormalOpenGLRenderTest(), TestMain::invokeSafeOpenBatchTest(), TestMain::invokeSafeOpenGLRenderTest(), TestMain::invokeSoftwareRenderTest(), TestMain::invokeTest(), PlayerInfo::saveProtectedItems(), Client::stateConnectServer1(), Client::stateSwitchLogin1(), PlayerRelationsManager::store(), ConfigManager::storeSafeParameters(), TestMain::writeConfig(), writeUpdated(), and Game::~Game().

859 {
860  BLOCK_START("Configuration::write")
861  if (mConfigPath.empty())
862  {
863  BLOCK_END("Configuration::write")
864  return;
865  }
866 
867  mUpdated = false;
868  // Do not attempt to write to file that cannot be opened for writing
869  FILE *const testFile = fopen(mConfigPath.c_str(), "w");
870  if (testFile == nullptr)
871  {
872  reportAlways("Configuration::write() couldn't open %s for writing",
873  mConfigPath.c_str());
874  BLOCK_END("Configuration::write")
875  return;
876  }
877  fclose(testFile);
878 
879  XmlTextWriterPtr writer = XmlNewTextWriterFilename(
880  mConfigPath.c_str(), 0);
881 
882  if (writer == nullptr)
883  {
884  logger->log1("Configuration::write() error while creating writer");
885  BLOCK_END("Configuration::write")
886  return;
887  }
888 
889  logger->log1("Configuration::write() writing configuration...");
890 
891  XmlTextWriterSetIndent(writer, 1);
892  XmlTextWriterStartDocument(writer, nullptr, nullptr, nullptr);
893 // xmlTextWriterStartDocument(writer, nullptr, "utf8", nullptr);
894  XmlTextWriterStartRootElement(writer, "configuration");
895 
896  writeToXML(writer);
897 
898  XmlTextWriterEndDocument(writer);
899  XmlSaveTextWriterFilename(writer,
900  mConfigPath.c_str());
901  XmlFreeTextWriter(writer);
903 }
void log1(const char *const log_text)
Definition: logger.cpp:222
#define BLOCK_START(name)
Definition: perfomance.h:78
if(!vert) return
#define BLOCK_END(name)
Definition: perfomance.h:79
Logger * logger
Definition: logger.cpp:95
virtual void writeToXML(const xmlTextWriterPtr writer)
std::string empty
Definition: podict.cpp:25
std::string mConfigPath
#define reportAlways(...)
Definition: checkutils.h:252

◆ writeUpdated()

void Configuration::writeUpdated ( )

Definition at line 852 of file configuration.cpp.

References mUpdated, and write().

Referenced by Game::slowLogic().

853 {
854  if (mUpdated)
855  write();
856 }

Field Documentation

◆ mConfigPath

std::string Configuration::mConfigPath
private

◆ mDefaultsData

DefaultsData Configuration::mDefaultsData
private

Defaults of value for a given key.

Definition at line 379 of file configuration.h.

Referenced by cleanDefaults(), getBoolValue(), getFloatValue(), getIntValue(), getStringValue(), resetBoolValue(), and resetIntValue().

◆ mDirectory

std::string Configuration::mDirectory
private

Definition at line 380 of file configuration.h.

Referenced by init(), and unload().

◆ mFilename

std::string Configuration::mFilename
private

Definition at line 381 of file configuration.h.

Referenced by init(), reInit(), and unload().

◆ mListenerMap

ListenerMap Configuration::mListenerMap
private

Definition at line 374 of file configuration.h.

Referenced by addListener(), removeListener(), and removeListeners().

◆ mUpdated

bool Configuration::mUpdated
private

Definition at line 383 of file configuration.h.

Referenced by write(), and writeUpdated().

◆ mUseResManager

UseVirtFs Configuration::mUseResManager
private

Definition at line 382 of file configuration.h.

Referenced by init(), reInit(), and unload().


The documentation for this class was generated from the following files: