Skip to content

Commit

Permalink
Extended XML loading process
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Xottab-DUTY committed Sep 23, 2018
1 parent d53f0a4 commit c3ced77
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 10 deletions.
37 changes: 29 additions & 8 deletions src/xrCore/XML/XMLDocument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,23 +45,42 @@ void ParseFile(pcstr path, CMemoryWriter& W, IReader* F, XMLDocument* xml)
}
}

void XMLDocument::Load(pcstr path_alias, pcstr path, pcstr _xml_filename)
bool XMLDocument::Load(pcstr path_alias, pcstr path, pcstr xml_filename, bool fatal)
{
shared_str fn = correct_file_name(path, _xml_filename);
shared_str fn = correct_file_name(path, xml_filename);

string_path str;
xr_sprintf(str, "%s\\%s", path, *fn);
return Load(path_alias, str);
return Load(path_alias, str, fatal);
}

//инициализация и загрузка XML файла
void XMLDocument::Load(pcstr path, pcstr xml_filename)
// Try to load from the first path, and if it's failed then try the second one
bool XMLDocument::Load(pcstr path_alias, pcstr path, pcstr path2, pcstr xml_filename, bool fatal /*= true*/)
{
xr_strcpy(m_xml_file_name, xml_filename);
// Load and parse xml file
shared_str fn = correct_file_name(path, xml_filename);

string_path str;
xr_sprintf(str, "%s\\%s", path, *fn);
if (Load(path_alias, str, false))
return true;

xr_sprintf(str, "%s\\%s", path2, *fn);
return Load(path_alias, str, fatal);
}

// Load and parse xml file
bool XMLDocument::Load(pcstr path, pcstr xml_filename, bool fatal)
{
IReader* F = FS.r_open(path, xml_filename);
R_ASSERT2(F, xml_filename);
if (!F)
{
if (fatal)
R_ASSERT3(F, "Can't find specified xml file", xml_filename);
else
return false;
}

xr_strcpy(m_xml_file_name, xml_filename);

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

m_root = m_Doc.firstChildElement();

return true;
}

XML_NODE XMLDocument::NavigateToNode(XML_NODE start_node, pcstr path, const size_t node_index) const
Expand Down
5 changes: 3 additions & 2 deletions src/xrCore/XML/XMLDocument.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,16 @@ struct XML_DOC

class XRCORE_API XMLDocument
{
void Load(pcstr path_alias, pcstr xml_filename);

public:
string_path m_xml_file_name;
XMLDocument();
virtual ~XMLDocument();
void ClearInternal();

void Load(pcstr path_alias, pcstr path, pcstr xml_filename);
bool Load(pcstr path_alias, pcstr xml_filename, bool fatal = true);
bool Load(pcstr path_alias, pcstr path, pcstr xml_filename, bool fatal = true);
bool Load(pcstr path_alias, pcstr path, pcstr path2, pcstr xml_filename, bool fatal = true);

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

0 comments on commit c3ced77

Please sign in to comment.