ManaPlus
Functions
ModDB Namespace Reference

Functions

void load ()
 
void unload ()
 
ModInfoget (const std::string &name)
 
void loadXmlFile (const std::string &fileName, const SkipError skipError)
 
const ModInfosgetAll ()
 

Function Documentation

◆ get()

ModInfo * ModDB::get ( const std::string &  name)

Definition at line 108 of file moddb.cpp.

109 {
110  const ModInfoIterator i = mModInfos.find(name);
111  if (i == mModInfos.end())
112  return nullptr;
113  return i->second;
114 }
ModInfos::iterator ModInfoIterator
Definition: modinfo.h:69

References anonymous_namespace{moddb.cpp}::mModInfos.

◆ getAll()

const ModInfos & ModDB::getAll ( )

◆ load()

void ModDB::load ( )

Definition at line 42 of file moddb.cpp.

43 {
44  if (mLoaded)
45  unload();
46  logger->log1("Initializing mod database...");
49  loadXmlDir("modsPatchDir", loadXmlFile)
50  mLoaded = true;
51 }
static void loadXmlFile(const std::string &file, const std::string &name, BadgesInfos &arr, const SkipError skipError)
Definition: badgesdb.cpp:43
#define loadXmlDir(name, function)
Definition: beingcommon.h:39
std::string getStringValue(const std::string &key) const
void log1(const char *const log_text)
Definition: logger.cpp:238
Configuration paths
Logger * logger
Definition: logger.cpp:89
void unload()
Definition: net.cpp:180
const bool SkipError_false
Definition: skiperror.h:30
const bool SkipError_true
Definition: skiperror.h:30

References Configuration::getStringValue(), loadXmlDir, loadXmlFile(), Logger::log1(), logger, anonymous_namespace{moddb.cpp}::mLoaded, paths, SkipError_false, SkipError_true, and Net::unload().

Referenced by UpdaterWindow::loadDirMods(), and UpdaterWindow::loadMods().

◆ loadXmlFile()

void ModDB::loadXmlFile ( const std::string &  fileName,
const SkipError  skipError 
)

Definition at line 53 of file moddb.cpp.

55 {
56  XML::Document doc(fileName, UseVirtFs_true, skipError);
57  XmlNodeConstPtrConst rootNode = doc.rootNode();
58 
59  if ((rootNode == nullptr) || !xmlNameEqual(rootNode, "mods"))
60  {
61  logger->log("Mods Database: Error while loading %s!",
62  fileName.c_str());
63  return;
64  }
65 
66  for_each_xml_child_node(modNode, rootNode)
67  {
68  if (xmlNameEqual(modNode, "include"))
69  {
70  const std::string name = XML::getProperty(modNode, "name", "");
71  if (!name.empty())
72  loadXmlFile(name, skipError);
73  continue;
74  }
75 
76  if (!xmlNameEqual(modNode, "mod"))
77  continue;
78 
79  const std::string name = XML::langProperty(
80  // TRANSLATORS: unknown info name
81  modNode, "name", _("unnamed"));
82  ModInfo *currentInfo = nullptr;
83  if (mModInfos.find(name) != mModInfos.end())
84  currentInfo = mModInfos[name];
85  if (currentInfo == nullptr)
86  currentInfo = new ModInfo;
87 
88  currentInfo->setName(name);
89  currentInfo->setDescription(XML::langProperty(
90  modNode, "description", ""));
91  currentInfo->setHelp(XML::getProperty(
92  modNode, "help", ""));
93  currentInfo->setLocalDir(XML::getProperty(
94  modNode, "localdir", ""));
95 
96  mModInfos[name] = currentInfo;
97  }
98 }
void log(const char *const log_text,...)
Definition: logger.cpp:269
void setDescription(const std::string &text)
Definition: modinfo.h:43
void setLocalDir(const std::string &text)
Definition: modinfo.h:55
void setName(const std::string &name)
Definition: modinfo.h:37
void setHelp(const std::string &text)
Definition: modinfo.h:49
#define _(s)
Definition: gettext.h:35
#define for_each_xml_child_node(var, parent)
Definition: libxml.h:161
std::string langProperty(const xmlNodePtr node, const char *const name, const std::string &def)
Definition: libxml.cpp:258
int getProperty(const xmlNodePtr node, const char *const name, int def)
Definition: libxml.cpp:174
std::string fileName
Definition: testmain.cpp:39
const bool UseVirtFs_true
Definition: usevirtfs.h:30

References _, fileName, for_each_xml_child_node, XML::getProperty(), XML::langProperty(), loadXmlFile(), Logger::log(), logger, anonymous_namespace{moddb.cpp}::mModInfos, XML::Document::rootNode(), ModInfo::setDescription(), ModInfo::setHelp(), ModInfo::setLocalDir(), ModInfo::setName(), and UseVirtFs_true.

◆ unload()

void ModDB::unload ( )

Definition at line 100 of file moddb.cpp.

101 {
102  logger->log1("Unloading mod database...");
104  mModInfos.clear();
105  mLoaded = false;
106 }
void delete_all(Container &c)
Definition: dtor.h:56

References delete_all(), Logger::log1(), logger, anonymous_namespace{moddb.cpp}::mLoaded, and anonymous_namespace{moddb.cpp}::mModInfos.

Referenced by DbManager::unloadDb().