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, const SkipError skipError)
 
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 236 of file configuration.h.

Member Typedef Documentation

◆ ListenerIterator

typedef Listeners::iterator Configuration::ListenerIterator
private

Definition at line 372 of file configuration.h.

◆ ListenerMap

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

Definition at line 373 of file configuration.h.

◆ ListenerMapIterator

typedef ListenerMap::iterator Configuration::ListenerMapIterator
private

Definition at line 374 of file configuration.h.

◆ Listeners

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

Definition at line 371 of file configuration.h.

Constructor & Destructor Documentation

◆ Configuration()

Configuration::Configuration ( )

Definition at line 362 of file configuration.cpp.

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

◆ ~Configuration()

Configuration::~Configuration ( )

Definition at line 389 of file configuration.cpp.

390 {
391  cleanDefaults();
392 }

References cleanDefaults().

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 378 of file configuration.cpp.

379 {
380  for (DefaultsData::const_iterator iter = mDefaultsData.begin();
381  iter != mDefaultsData.end();
382  ++iter)
383  {
384  delete iter->second;
385  }
386  mDefaultsData.clear();
387 }

References mDefaultsData.

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

◆ getBoolValue()

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

Definition at line 597 of file configuration.cpp.

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

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

Referenced by ChangeDisplay::action(), Setup_Video::action(), ChatWindow::action(), SkillDialog::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(), BattleTab::BattleTab(), 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(), EAthena::ClanRecv::createTab(), GuildManager::createTab(), EmulateGuildTab::EmulateGuildTab(), ActorManager::findNearestLivingBeing(), LocalPlayer::fixAttackTarget(), ChatInput::focusLost(), Game::Game(), Client::gameInit(), MobileOpenGLScreenshotHelper::getScreenshot(), OpenGLScreenshotHelper::getScreenshot(), GuildTab::GuildTab(), WhoIsOnline::handleLink(), EventsManager::init(), GameModifiers::init(), Joystick::init(), KeyboardConfig::init(), TouchManager::init(), Settings::init(), SoundManager::init(), Client::initFeatures(), GraphicsManager::initGraphics(), Client::initGraphics(), Map::initializeParticleEffects(), GraphicsManager::initOpenGLFunctions(), Dirs::initScreenshotDir(), Client::initSoundManager(), SetupItem::load(), WhoIsOnline::loadList(), WhoIsOnline::loadWebList(), LocalPlayer::LocalPlayer(), UpdaterWindow::logic(), Map::Map(), Joystick::open(), DialogsManager::openErrorDialog(), ActorManager::optionChanged(), EventsManager::optionChanged(), ChatWindow::optionChanged(), Minimap::optionChanged(), NpcDialog::optionChanged(), WhoIsOnline::optionChanged(), GuiConfigListener::optionChanged(), Viewport::optionChanged(), Client::optionChanged(), LocalPlayer::optionChanged(), AvatarListBox::optionChanged(), EmulateGuildTab::optionChanged(), GuildTab::optionChanged(), PartyTab::optionChanged(), TouchManager::optionChanged(), Map::optionChanged(), MapLayer::optionChanged(), SoundManager::optionChanged(), PartyTab::PartyTab(), LocalPlayer::pickedUp(), SocialWindow::postInit(), WhoIsOnline::postInit(), Gui::postInit(), MobileOpenGLScreenshotHelper::prepare(), OpenGLScreenshotHelper::prepare(), Ea::BeingRecv::processBeingRemove(), EAthena::CharServerRecv::processChangeMapServer(), TmwAthena::CharServerRecv::processChangeMapServer(), EAthena::CharServerRecv::processCharMapInfo(), TmwAthena::CharServerRecv::processCharMapInfo(), EAthena::GuildRecv::processGuildPositionInfo(), Ea::ChatRecv::processMVPEffect(), EAthena::PlayerRecv::processOnlineList(), TmwAthena::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(), ParticleEngine::setupEngine(), GraphicsManager::setVideoMode(), PopupMenu::showDropPopup(), ChatWindow::showGMTab(), PopupMenu::showItemPopup(), Being::showName(), PopupMenu::showPopup(), ConfigManager::storeSafeParameters(), SoundManager::testAudio(), updateEnv(), SocialNavigationTab::updateList(), GraphicsManager::updateTextureFormat(), and ItemShortcut::useItem().

◆ getConfigPath()

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

Definition at line 336 of file configuration.h.

337  { return mConfigPath; }

References mConfigPath.

Referenced by Client::gameInit().

◆ getDefaultValues()

DefaultsData& Configuration::getDefaultValues ( )
inline

◆ getDirectory()

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

Definition at line 355 of file configuration.h.

356  { return mDirectory; }

References mDirectory.

Referenced by Dirs::updateDataPath().

◆ getFileName()

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

Definition at line 360 of file configuration.h.

361  { return mFilename; }

References mFilename.

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

◆ getFloatValue()

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

Definition at line 542 of file configuration.cpp.

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

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

Referenced by WindowManager::applyGamma(), GraphicsManager::initGraphics(), Client::optionChanged(), Map::optionChanged(), and Text::Text().

◆ 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 404 of file configuration.cpp.

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

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

Referenced by Setup_Video::action(), DidYouKnowWindow::action(), RegisterDialog::action(), Net::Download::addProxy(), Game::adjustPerfomance(), LocalPlayer::afkRespond(), Setup_Theme::apply(), Setup_Video::apply(), WindowManager::applyKeyRepeat(), WindowManager::applyScale(), WindowManager::applyVSync(), CharacterViewNormal::CharacterViewNormal(), CharCreateDialog::CharCreateDialog(), CharSelectDialog::CharSelectDialog(), ChatTab::chatLog(), ChatTab::ChatTab(), ConfigManager::checkConfigVersion(), GraphicsManager::createRenderers(), NpcDialog::createSkinControls(), GraphicsManager::detectPixelSize(), EquipmentWindow::EquipmentWindow(), TouchManager::executeAction(), Client::gameInit(), Being::getDefaultEffectId(), Being::getHitEffect(), EventsManager::handleActive(), Being::handleSkill(), Being::handleSkillCasting(), GameModifiers::init(), BuyDialog::init(), Joystick::init(), KeyboardConfig::init(), TouchManager::init(), BeingInfo::init(), SoundManager::init(), GraphicsManager::initGraphics(), Client::initSoundManager(), InventoryWindow::InventoryWindow(), SetupItem::load(), MiniStatusWindow::loadBars(), DidYouKnowWindow::loadData(), ItemDB::loadXmlFile(), LocalPlayer::LocalPlayer(), NpcDialog::NpcDialog(), Joystick::open(), WindowMenu::optionChanged(), Viewport::optionChanged(), Client::optionChanged(), Being::optionChanged(), LocalPlayer::optionChanged(), TouchManager::optionChanged(), Map::optionChanged(), SoundManager::optionChanged(), SkillDialog::playCastingDstTileEffect(), SkillDialog::playRemoveEffect(), SkillDialog::playUpdateEffect(), SetupWindow::postInit(), Being::postInit(), Gui::postInit(), BeingCommon::readObjectNodes(), RegisterDialog::RegisterDialog(), Being::reReadConfig(), Game::resetAdjustLevel(), ServerDialog::ServerDialog(), 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().

◆ getStringValue()

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

Definition at line 488 of file configuration.cpp.

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

References data, VariableData::DATA_BOOL, VariableData::DATA_FLOAT, VariableData::DATA_INT, VariableData::DATA_STRING, GETLOG, 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(), PlayerRelationsManager::checkName(), CrazyMoves::crazyMoveA(), 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(), SetupItem::load(), AvatarDB::load(), CharDB::load(), ClanDb::load(), ColorDB::load(), CommandsDB::load(), DeadDB::load(), ElementalDb::load(), EmoteDB::load(), GroupDb::load(), HomunculusDB::load(), HorseDB::load(), ItemDB::load(), ItemFieldDb::load(), ItemOptionDb::load(), LanguageDb::load(), MapDB::load(), MercenaryDB::load(), ModDB::load(), MonsterDB::load(), NetworkDb::load(), NPCDB::load(), NpcDialogDB::load(), PETDB::load(), QuestDb::load(), SkillUnitDb::load(), SoundDB::load(), StatDb::load(), StatusEffectDB::load(), TextDb::load(), UnitsDb::load(), SpriteDef::load(), PlayerInfo::loadData(), Client::loadData(), loadDB(), MapReader::loadEmptyAtlas(), DidYouKnowWindow::loadFile(), HelpWindow::loadFile(), Net::loadIgnorePackets(), TextCommand::loadImage(), loadMusic(), PaletteDB::loadPalette(), UpdaterWindow::loadPatch(), ServerDialog::loadServers(), SkillDialog::loadSkillData(), SkillDialog::loadSkills(), EmoteDB::loadSpecialXmlFile(), HelpWindow::loadTags(), ClanDb::loadXmlFile(), DeadDB::loadXmlFile(), ElementalDb::loadXmlFile(), EmoteDB::loadXmlFile(), GroupDb::loadXmlFile(), HomunculusDB::loadXmlFile(), HorseDB::loadXmlFile(), MercenaryDB::loadXmlFile(), MonsterDB::loadXmlFile(), NPCDB::loadXmlFile(), PETDB::loadXmlFile(), SkillUnitDb::loadXmlFile(), StatusEffectDB::loadXmlFile(), UnitsDb::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::showClanBadge(), 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().

◆ incValue()

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

Definition at line 255 of file configuration.cpp.

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

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

Referenced by Game::Game(), and Client::gameInit().

◆ init()

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

Reads config file and parse all options into memory.

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

Definition at line 739 of file configuration.cpp.

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

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 Client::gameExec(), Client::gameInit(), TestMain::initConfig(), ConfigManager::initConfiguration(), Client::initFeatures(), Dirs::initRootDir(), ConfigManager::initServerConfig(), Client::loadData(), and TestMain::writeConfig().

◆ reInit()

void Configuration::reInit ( )

Definition at line 793 of file configuration.cpp.

794 {
796  if (doc.rootNode() == nullptr)
797  {
798  logger->log("Couldn't open configuration file: %s", mFilename.c_str());
799  return;
800  }
801 
802  XmlNodeConstPtrConst rootNode = doc.rootNode();
803 
804  if ((rootNode == nullptr) || !xmlNameEqual(rootNode, "configuration"))
805  {
806  logger->log("Warning: No configuration file (%s)", mFilename.c_str());
807  return;
808  }
809 
810  initFromXML(rootNode);
811 }
const bool SkipError_false
Definition: skiperror.h:30

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

◆ 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 912 of file configuration.cpp.

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

References anonymous_namespace{itemlinkhandler.cpp}::listener, and mListenerMap.

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

◆ removeListeners()

void Configuration::removeListeners ( ConfigListener *const  listener)

◆ removeOldKeys()

void Configuration::removeOldKeys ( )

Definition at line 945 of file configuration.cpp.

946 {
947  if (mOptions.find(unusedKeys[0]) != mOptions.end() ||
948  mOptions.find(unusedKeys[1]) != mOptions.end() ||
949  mOptions.find(unusedKeys[2]) != mOptions.end())
950  {
951  int f = 0;
952  while (!unusedKeys[f].empty())
953  {
954  deleteKey(unusedKeys[f]);
955  logger->log("remove unused key: " + unusedKeys[f]);
956  f ++;
957  }
958  for (f = 0; f < 80; f ++)
959  {
960  const std::string str = toString(f);
961  deleteKey("Outfit" + str);
962  deleteKey("OutfitUnequip" + str);
963  deleteKey("commandShortcutCmd" + str);
964  deleteKey("commandShortcutFlags" + str);
965  deleteKey("commandShortcutSymbol" + str);
966  deleteKey("drop" + str);
967  deleteKey("shortcut" + str);
968  }
969  }
970 }
void deleteKey(const std::string &key)
const std::string unusedKeys[]
std::string empty
Definition: podict.cpp:26

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

Referenced by Client::gameClear().

◆ resetBoolValue()

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

Definition at line 666 of file configuration.cpp.

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

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

Referenced by GameModifiers::resetModifiers().

◆ resetIntValue()

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

Definition at line 457 of file configuration.cpp.

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

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

Referenced by GameModifiers::resetModifiers().

◆ setSilent() [1/3]

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

Definition at line 328 of file configuration.h.

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

References setSilent().

◆ setSilent() [2/3]

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

Definition at line 300 of file configuration.h.

302  { if (value != nullptr) setSilent(key, std::string(value)); }

References setSilent().

◆ setSilent() [3/3]

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

Definition at line 263 of file configuration.cpp.

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

References ConfigurationObject::setValue().

Referenced by Game::adjustPerfomance(), and setSilent().

◆ setValue() [1/7]

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

Definition at line 324 of file configuration.h.

326  { setValue(key, value ? "1" : "0"); }

References setValue().

◆ setValue() [2/7]

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

Definition at line 296 of file configuration.h.

298  { if (value != nullptr) setValue(key, std::string(value)); }

References setValue().

◆ setValue() [3/7]

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

Definition at line 308 of file configuration.h.

310  { setValue(key, toString(value)); }

References setValue(), and Catch::toString().

◆ setValue() [4/7]

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

Definition at line 304 of file configuration.h.

306  { setValue(key, toString(value)); }

References setValue(), and Catch::toString().

◆ setValue() [5/7]

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

Definition at line 312 of file configuration.h.

314  { setValue(key, toString(value)); }

References setValue(), and Catch::toString().

◆ setValue() [6/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 239 of file configuration.cpp.

241 {
242  ConfigurationObject::setValue(key, value);
243  mUpdated = true;
244 
245  // Notify listeners
246  const ListenerMapIterator list = mListenerMap.find(key);
247  if (list != mListenerMap.end())
248  {
249  Listeners listeners = list->second;
250  FOR_EACH (ListenerIterator, i, listeners)
251  (*i)->optionChanged(key);
252  }
253 }
Listeners::iterator ListenerIterator
std::list< ConfigListener * > Listeners

References FOR_EACH, mListenerMap, mUpdated, and ConfigurationObject::setValue().

Referenced by Setup_Video::action(), BuyDialog::action(), ChatWindow::action(), DidYouKnowWindow::action(), QuitDialog::action(), Game::adjustPerfomance(), Setup_Joystick::apply(), Setup_Theme::apply(), Setup_Video::apply(), Setup_Video::cancel(), GameModifiers::changeGameModifiers(), GameModifiers::changeMode(), ConfigManager::checkConfigVersion(), ServerDialog::connectToSelectedServer(), GraphicsManager::detectGraphics(), GraphicsManager::detectVideoSettings(), ServerDialog::downloadServerList(), Joystick::finishCalibration(), incValue(), 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(), Joystick::open(), LoginDialog::prepareUpdate(), EAthena::LoginRecv::processLoginData(), TmwAthena::LoginRecv::processLoginData(), Game::resetAdjustLevel(), resetBoolValue(), resetIntValue(), WindowManager::resizeVideo(), SetupItem::save(), EmoteShortcut::save(), ItemShortcut::save(), ShortcutBase::save(), OutfitWindow::save(), SpellManager::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(), setValue(), setValueInt(), GraphicsManager::setVideoMode(), PlayerRelationsManager::store(), InputManager::store(), ActorManager::storeAttackList(), ConfigManager::storeSafeParameters(), InventoryWindow::storeSortOrder(), TestMain::writeConfig(), ChatWindow::~ChatWindow(), Minimap::~Minimap(), and UserPalette::~UserPalette().

◆ setValue() [7/7]

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

Definition at line 320 of file configuration.h.

322  { setValue(key, toString(value)); }

References setValue(), and Catch::toString().

◆ setValueInt()

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

Definition at line 316 of file configuration.h.

318  { setValue(key, toString(value)); }

References setValue(), and Catch::toString().

Referenced by GraphicsManager::setVideoMode().

◆ unload()

void Configuration::unload ( )

Definition at line 394 of file configuration.cpp.

395 {
396  cleanDefaults();
397  mConfigPath.clear();
398  mDirectory.clear();
399  mFilename.clear();
402 }

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

◆ write()

void Configuration::write ( )

Writes the current settings back to the config file.

Definition at line 859 of file configuration.cpp.

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

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

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

◆ writeUpdated()

void Configuration::writeUpdated ( )

Definition at line 853 of file configuration.cpp.

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

References mUpdated, and write().

Referenced by Game::slowLogic().

Field Documentation

◆ mConfigPath

std::string Configuration::mConfigPath
private

◆ mDefaultsData

DefaultsData Configuration::mDefaultsData
private

Defaults of value for a given key.

Definition at line 380 of file configuration.h.

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

◆ mDirectory

std::string Configuration::mDirectory
private

Definition at line 381 of file configuration.h.

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

◆ mFilename

std::string Configuration::mFilename
private

Definition at line 382 of file configuration.h.

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

◆ mListenerMap

ListenerMap Configuration::mListenerMap
private

Definition at line 375 of file configuration.h.

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

◆ mUpdated

bool Configuration::mUpdated
private

Definition at line 384 of file configuration.h.

Referenced by setValue(), write(), and writeUpdated().

◆ mUseResManager

UseVirtFs Configuration::mUseResManager
private

Definition at line 383 of file configuration.h.

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


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