Skip to content

Commit c3ced77

Browse files
committed
Extended XML loading process
Now you specify to not to crash when you're trying to load xml You can also specify two paths to try to load from Will be used in UI styles system.
1 parent d53f0a4 commit c3ced77

File tree

2 files changed

+32
-10
lines changed

2 files changed

+32
-10
lines changed

src/xrCore/XML/XMLDocument.cpp

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,23 +45,42 @@ void ParseFile(pcstr path, CMemoryWriter& W, IReader* F, XMLDocument* xml)
4545
}
4646
}
4747

48-
void XMLDocument::Load(pcstr path_alias, pcstr path, pcstr _xml_filename)
48+
bool XMLDocument::Load(pcstr path_alias, pcstr path, pcstr xml_filename, bool fatal)
4949
{
50-
shared_str fn = correct_file_name(path, _xml_filename);
50+
shared_str fn = correct_file_name(path, xml_filename);
5151

5252
string_path str;
5353
xr_sprintf(str, "%s\\%s", path, *fn);
54-
return Load(path_alias, str);
54+
return Load(path_alias, str, fatal);
5555
}
5656

57-
//инициализация и загрузка XML файла
58-
void XMLDocument::Load(pcstr path, pcstr xml_filename)
57+
// Try to load from the first path, and if it's failed then try the second one
58+
bool XMLDocument::Load(pcstr path_alias, pcstr path, pcstr path2, pcstr xml_filename, bool fatal /*= true*/)
5959
{
60-
xr_strcpy(m_xml_file_name, xml_filename);
61-
// Load and parse xml file
60+
shared_str fn = correct_file_name(path, xml_filename);
61+
62+
string_path str;
63+
xr_sprintf(str, "%s\\%s", path, *fn);
64+
if (Load(path_alias, str, false))
65+
return true;
6266

67+
xr_sprintf(str, "%s\\%s", path2, *fn);
68+
return Load(path_alias, str, fatal);
69+
}
70+
71+
// Load and parse xml file
72+
bool XMLDocument::Load(pcstr path, pcstr xml_filename, bool fatal)
73+
{
6374
IReader* F = FS.r_open(path, xml_filename);
64-
R_ASSERT2(F, xml_filename);
75+
if (!F)
76+
{
77+
if (fatal)
78+
R_ASSERT3(F, "Can't find specified xml file", xml_filename);
79+
else
80+
return false;
81+
}
82+
83+
xr_strcpy(m_xml_file_name, xml_filename);
6584

6685
CMemoryWriter W;
6786
ParseFile(path, W, F, this);
@@ -79,6 +98,8 @@ void XMLDocument::Load(pcstr path, pcstr xml_filename)
7998
}
8099

81100
m_root = m_Doc.firstChildElement();
101+
102+
return true;
82103
}
83104

84105
XML_NODE XMLDocument::NavigateToNode(XML_NODE start_node, pcstr path, const size_t node_index) const

src/xrCore/XML/XMLDocument.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,15 +127,16 @@ struct XML_DOC
127127

128128
class XRCORE_API XMLDocument
129129
{
130-
void Load(pcstr path_alias, pcstr xml_filename);
131130

132131
public:
133132
string_path m_xml_file_name;
134133
XMLDocument();
135134
virtual ~XMLDocument();
136135
void ClearInternal();
137136

138-
void Load(pcstr path_alias, pcstr path, pcstr xml_filename);
137+
bool Load(pcstr path_alias, pcstr xml_filename, bool fatal = true);
138+
bool Load(pcstr path_alias, pcstr path, pcstr xml_filename, bool fatal = true);
139+
bool Load(pcstr path_alias, pcstr path, pcstr path2, pcstr xml_filename, bool fatal = true);
139140

140141
//чтение элементов
141142
pcstr Read(pcstr path, const size_t index, pcstr default_str_val) const;

0 commit comments

Comments
 (0)