forked from github/server
Use custom URI schemes for config files.
TODO: XML files need to be rebased, XIncludes replaced.
This commit is contained in:
parent
a316283a6d
commit
6ef8d1af3c
|
@ -1,11 +1,30 @@
|
|||
{
|
||||
"include": [
|
||||
"keywords.json",
|
||||
"calendar.json",
|
||||
"prefixes.json",
|
||||
"e2/terrains.json",
|
||||
"e2/rules.xml",
|
||||
"e2/locales.xml"
|
||||
"config://keywords.json",
|
||||
"config://calendar.json",
|
||||
"config://prefixes.json",
|
||||
"config://e2/terrains.json",
|
||||
"config://e2/locales.xml",
|
||||
"config://e2/rules.xml",
|
||||
"rules://core/ships.xml",
|
||||
"rules://core/spoils.xml",
|
||||
"rules://core/common/buildings.xml",
|
||||
"rules://core/common/items.xml",
|
||||
"rules://core/common/resources.xml",
|
||||
"rules://core/common/luxuries.xml",
|
||||
"rules://core/common/herbs.xml",
|
||||
"rules://core/common/potions.xml",
|
||||
"rules://core/common/armor.xml",
|
||||
"rules://core/common/weapons.xml",
|
||||
"rules://eressea/races.xml",
|
||||
"rules://eressea/artrewards.xml",
|
||||
"rules://eressea/buildings.xml",
|
||||
"rules://eressea/familiars.xml",
|
||||
"rules://eressea/buildings.xml",
|
||||
"rules://eressea/equipment.xml",
|
||||
"rules://eressea/items.xml",
|
||||
"rules://eressea/spells.xml",
|
||||
"rules://adamantium.xml"
|
||||
],
|
||||
"disabled": [
|
||||
"jsreport"
|
||||
|
|
|
@ -1,24 +1,6 @@
|
|||
<?xml version="1.0"?>
|
||||
<eressea xmlns:xi="http://www.w3.org/2001/XInclude">
|
||||
<eressea>
|
||||
|
||||
<xi:include href="config://core/common/items.xml" />
|
||||
<xi:include href="config://core/common/armor.xml" />
|
||||
<xi:include href="config://core/common/weapons.xml" />
|
||||
<xi:include href="config://core/common/resources.xml" />
|
||||
<xi:include href="config://core/common/luxuries.xml" />
|
||||
<xi:include href="config://core/common/herbs.xml" />
|
||||
<xi:include href="config://core/common/potions.xml" />
|
||||
<xi:include href="config://core/spoils.xml"/>
|
||||
<xi:include href="config://game/races.xml"/>
|
||||
<xi:include href="config://core/ships.xml"/>
|
||||
<xi:include href="config://core/common/buildings.xml"/>
|
||||
<xi:include href="config://game/familiars.xml"/>
|
||||
<xi:include href="config://game/artrewards.xml"/>
|
||||
<xi:include href="config://game/buildings.xml"/>
|
||||
<xi:include href="config://game/equipment.xml"/>
|
||||
<xi:include href="config://game/items.xml"/>
|
||||
<xi:include href="config://game/spells.xml"/>
|
||||
<xi:include href="config://default/adamantium.xml"/>
|
||||
<equipment>
|
||||
<set name="first_unit">
|
||||
<item name="money" amount="2500"/>
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?xml version="1.0"?>
|
||||
<eressea>
|
||||
<resources>
|
||||
|
||||
<resource name="money">
|
||||
|
@ -133,3 +134,4 @@
|
|||
</resource>
|
||||
|
||||
</resources>
|
||||
</eressea>
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
local confdir = 'conf/'
|
||||
if config.install then
|
||||
confdir = config.install .. '/' .. confdir
|
||||
end
|
||||
local rules = 'conf'
|
||||
|
||||
if config.rules then
|
||||
local rules = config.rules .. '/'
|
||||
assert(0 == eressea.config.read(rules .. 'config.json', confdir), "could not read JSON data")
|
||||
rules = rules .. '/' .. config.rules
|
||||
assert(0 == eressea.config.read(rules .. '/config.json', config.install), "could not read JSON data")
|
||||
-- assert(0 == read_xml(confdir .. rules .. 'rules.xml', confdir .. rules .. 'catalog.xml'), "could not load XML data, did you compile with LIBXML2 ?")
|
||||
-- assert(0 == read_xml(confdir .. rules .. 'locales.xml', confdir .. rules .. 'catalog.xml'), "could not load XML data, did you compile with LIBXML2 ?")
|
||||
end
|
||||
|
||||
eressea.game.reset()
|
||||
|
|
|
@ -887,16 +887,32 @@ static void json_races(cJSON *json) {
|
|||
|
||||
const char * json_relpath;
|
||||
|
||||
static void include_json(const char *filename) {
|
||||
static const char * uri_to_file(const char * uri, char *name, size_t size) {
|
||||
const char *pos, *path = json_relpath;
|
||||
|
||||
pos = strstr(uri, "://");
|
||||
if (pos) {
|
||||
size_t slen = pos - uri;
|
||||
/* identify scheme */
|
||||
if (strncmp(uri, "config", slen) == 0) {
|
||||
path = path_join(path, "conf", name, size);
|
||||
}
|
||||
else if (strncmp(uri, "rules", slen) == 0) {
|
||||
path = path_join(path, "res", name, size);
|
||||
}
|
||||
if (path) {
|
||||
return path_join(path, pos + 3, name, size);
|
||||
}
|
||||
}
|
||||
return uri;
|
||||
}
|
||||
|
||||
static void include_json(const char *uri) {
|
||||
FILE *F;
|
||||
if (json_relpath) {
|
||||
char name[PATH_MAX];
|
||||
path_join(json_relpath, filename, name, sizeof(name));
|
||||
F = fopen(name, "r");
|
||||
}
|
||||
else {
|
||||
const char *filename = uri_to_file(uri, name, sizeof(name));
|
||||
|
||||
F = fopen(filename, "r");
|
||||
}
|
||||
if (F) {
|
||||
long pos;
|
||||
fseek(F, 0, SEEK_END);
|
||||
|
@ -917,21 +933,20 @@ static void include_json(const char *filename) {
|
|||
cJSON_Delete(config);
|
||||
}
|
||||
else {
|
||||
log_error("invalid JSON, could not parse %s", filename);
|
||||
log_error("could not parse JSON from %s", uri);
|
||||
}
|
||||
}
|
||||
fclose(F);
|
||||
}
|
||||
}
|
||||
|
||||
static void include_xml(const char *filename) {
|
||||
static void include_xml(const char *uri) {
|
||||
char name[PATH_MAX];
|
||||
|
||||
if (json_relpath) {
|
||||
path_join(json_relpath, filename, name, sizeof(name));
|
||||
filename = name;
|
||||
const char *filename = uri_to_file(uri, name, sizeof(name));
|
||||
int err = read_xml(filename, NULL);
|
||||
if (err != 0) {
|
||||
log_error("could not parse XML from %s", uri);
|
||||
}
|
||||
read_xml(filename, NULL);
|
||||
}
|
||||
|
||||
static void json_include(cJSON *json) {
|
||||
|
@ -941,12 +956,13 @@ static void json_include(cJSON *json) {
|
|||
return;
|
||||
}
|
||||
for (child = json->child; child; child = child->next) {
|
||||
const char * filename = child->valuestring;
|
||||
if (strstr(filename, ".xml") != NULL) {
|
||||
include_xml(filename);
|
||||
const char *uri = child->valuestring;
|
||||
|
||||
if (strstr(uri, ".xml") != NULL) {
|
||||
include_xml(uri);
|
||||
}
|
||||
else {
|
||||
include_json(filename);
|
||||
include_json(uri);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue