ManaPlus
src
resources
db
textdb.cpp
Go to the documentation of this file.
1
/*
2
* The ManaPlus Client
3
* Copyright (C) 2013-2019 The ManaPlus Developers
4
* Copyright (C) 2019-2021 Andrei Karas
5
*
6
* This file is part of The ManaPlus Client.
7
*
8
* This program is free software; you can redistribute it and/or modify
9
* it under the terms of the GNU General Public License as published by
10
* the Free Software Foundation; either version 2 of the License, or
11
* any later version.
12
*
13
* This program is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
* GNU General Public License for more details.
17
*
18
* You should have received a copy of the GNU General Public License
19
* along with this program. If not, see <http://www.gnu.org/licenses/>.
20
*/
21
22
#include "
resources/db/textdb.h
"
23
24
#include "
configuration.h
"
25
26
#include "
utils/checkutils.h
"
27
28
#include "
resources/beingcommon.h
"
29
30
#include "
debug.h
"
31
32
namespace
33
{
34
StringVect
mTexts
;
35
}
// namespace
36
37
void
TextDb::load
()
38
{
39
unload
();
40
logger
->
log1
(
"Initializing text database..."
);
41
loadXmlFile
(
paths
.
getStringValue
(
"textsFile"
),
SkipError_false
);
42
loadXmlFile
(
paths
.
getStringValue
(
"textsPatchFile"
),
SkipError_true
);
43
loadXmlDir
(
"textsPatchDir"
,
loadXmlFile
)
44
}
45
46
void
TextDb::loadXmlFile
(
const
std::string &
fileName
,
47
const
SkipError
skipError)
48
{
49
XML::Document
*doc =
new
XML::Document
(
fileName
,
50
UseVirtFs_true
,
51
skipError);
52
XmlNodeConstPtrConst root = doc->
rootNode
();
53
54
if
((root ==
nullptr
) || !xmlNameEqual(root,
"texts"
))
55
{
56
delete
doc;
57
return
;
58
}
59
60
for_each_xml_child_node
(node, root)
61
{
62
if
(xmlNameEqual(node,
"include"
))
63
{
64
const
std::string name =
XML::getProperty
(node,
"name"
,
""
);
65
if
(!name.empty())
66
loadXmlFile
(name, skipError);
67
continue
;
68
}
69
else
if
(xmlNameEqual(node,
"text"
))
70
{
71
const
bool
show =
XML::getBoolProperty
(node,
"show"
,
false
);
72
if
(show ==
true
)
73
{
74
if
(!XmlHaveChildContent(node))
75
continue
;
76
77
std::string text = XmlChildContent(node);
78
mTexts
.push_back(text);
79
}
80
}
81
}
82
83
delete
doc;
84
}
85
86
void
TextDb::unload
()
87
{
88
logger
->
log1
(
"Unloading text database..."
);
89
mTexts
.clear();
90
}
91
92
const
StringVect
&
TextDb::getTexts
()
93
{
94
return
mTexts
;
95
}
96
97
std::string
TextDb::getByIndex
(
const
int
index)
98
{
99
if
(index < 0 ||
100
static_cast<
size_t
>
(index) >=
mTexts
.size())
101
{
102
return
std::string();
103
}
104
return
mTexts
[index];
105
}
loadXmlFile
static void loadXmlFile(const std::string &file, const std::string &name, BadgesInfos &arr, const SkipError skipError)
Definition:
badgesdb.cpp:43
beingcommon.h
loadXmlDir
#define loadXmlDir(name, function)
Definition:
beingcommon.h:39
checkutils.h
Configuration::getStringValue
std::string getStringValue(const std::string &key) const
Definition:
configuration.cpp:488
Logger::log1
void log1(const char *const log_text)
Definition:
logger.cpp:238
XML::Document
Definition:
libxml.h:54
XML::Document::rootNode
xmlNodePtr rootNode()
Definition:
libxml.cpp:169
paths
Configuration paths
Definition:
configuration.cpp:56
configuration.h
debug.h
for_each_xml_child_node
#define for_each_xml_child_node(var, parent)
Definition:
libxml.h:161
logger
Logger * logger
Definition:
logger.cpp:89
Net::unload
void unload()
Definition:
net.cpp:180
TextDb::load
void load()
Definition:
textdb.cpp:37
TextDb::loadXmlFile
void loadXmlFile(const std::string &fileName, const SkipError skipError)
Definition:
textdb.cpp:46
TextDb::getByIndex
std::string getByIndex(const int index)
Definition:
textdb.cpp:97
TextDb::getTexts
const StringVect & getTexts()
Definition:
textdb.cpp:92
TextDb::unload
void unload()
Definition:
textdb.cpp:86
XML::getBoolProperty
bool getBoolProperty(const xmlNodePtr node, const char *const name, const bool def)
Definition:
libxml.cpp:269
XML::getProperty
int getProperty(const xmlNodePtr node, const char *const name, int def)
Definition:
libxml.cpp:174
anonymous_namespace{textdb.cpp}::mTexts
StringVect mTexts
Definition:
textdb.cpp:34
SkipError_false
const bool SkipError_false
Definition:
skiperror.h:30
SkipError_true
const bool SkipError_true
Definition:
skiperror.h:30
SkipError
bool SkipError
Definition:
skiperror.h:30
StringVect
std::vector< std::string > StringVect
Definition:
stringvector.h:29
fileName
std::string fileName
Definition:
testmain.cpp:39
textdb.h
UseVirtFs_true
const bool UseVirtFs_true
Definition:
usevirtfs.h:30
Generated on Wed Mar 17 2021 19:19:09 for ManaPlus by
1.9.1