blob: 8821fe4d8a1c660d8f04965f89f64d72db3ee120 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
#include <precomp.h>
#include <bfc/wasabi_std.h>
#include "XMLAutoInclude.h"
#include <bfc/file/wildcharsenum.h>
#include <api/util/varmgr.h>
void LoadXmlFile(obj_xml *parser, const wchar_t *filename);
XMLAutoInclude::XMLAutoInclude(obj_xml *_parser, const wchar_t *_path)
{
path=_path;
parser = _parser;
if (parser)
{
parser->xmlreader_registerCallback(L"*\finclude", this);
}
}
XMLAutoInclude::~XMLAutoInclude()
{
if (parser)
{
parser->xmlreader_unregisterCallback(this);
}
}
static const wchar_t *varmgr_translate(const wchar_t *str)
{
static StringW ret;
StringW *s = PublicVarManager::translate_nocontext(str);
if (s)
{
ret.swap(s);
delete s;
return ret.getValueSafe();
}
return str;
}
void XMLAutoInclude::xmlReaderOnStartElementCallback(const wchar_t *xmlpath, const wchar_t *xmltag, ifc_xmlreaderparams *params)
{
const wchar_t *includeFile = params->getItemValue(L"file");
const wchar_t *trans = /*WASABI_API_WNDMGR->*/varmgr_translate(includeFile);
if (trans)
{
//const char *path = WASABI_API_SKIN->getSkinsPath();
if (!Wasabi::Std::isRootPath(trans))
includeFn=StringPathCombine(path, trans);
else
includeFn=trans;
}
}
void XMLAutoInclude::Include(const wchar_t *filename)
{
if (filename && *filename)
{
parser->xmlreader_interrupt();
StringW oldPath = path;
const wchar_t *file = Wasabi::Std::filename(filename);
int fnlen = wcslen(file);
path = filename;
path.trunc(-fnlen);
LoadXmlFile(parser, filename);
path = oldPath;
parser->xmlreader_resume();
}
}
void XMLAutoInclude::xmlReaderOnEndElementCallback(const wchar_t *xmlpath, const wchar_t *xmltag)
{
if (!includeFn.isempty())
{
WildcharsEnumerator e(includeFn);
if (e.getNumFiles() > 0) // if we're including multiple files
{
for (int i = 0;i < e.getNumFiles();i++)
{
Include(e.enumFile(i));
}
}
else
Include(includeFn);
}
}
|