Changeset View
Changeset View
Standalone View
Standalone View
source/ps/XML/Xeromyces.cpp
/* Copyright (C) 2015 Wildfire Games. | /* Copyright (C) 2018 Wildfire Games. | ||||
* This file is part of 0 A.D. | * This file is part of 0 A.D. | ||||
* | * | ||||
* 0 A.D. is free software: you can redistribute it and/or modify | * 0 A.D. is free software: you can redistribute it and/or modify | ||||
* it under the terms of the GNU General Public License as published by | * it under the terms of the GNU General Public License as published by | ||||
* the Free Software Foundation, either version 2 of the License, or | * the Free Software Foundation, either version 2 of the License, or | ||||
* (at your option) any later version. | * (at your option) any later version. | ||||
* | * | ||||
* 0 A.D. is distributed in the hope that it will be useful, | * 0 A.D. is distributed in the hope that it will be useful, | ||||
▲ Show 20 Lines • Show All 158 Lines • ▼ Show 20 Lines | PSRETURN CXeromyces::ConvertFile(const PIVFS& vfs, const VfsPath& filename, const VfsPath& xmbPath, const std::string& validatorName) | ||||
xmlDocPtr doc = xmlReadMemory((const char*)input.GetBuffer(), input.GetBufferSize(), CStrW(filename.string()).ToUTF8().c_str(), NULL, | xmlDocPtr doc = xmlReadMemory((const char*)input.GetBuffer(), input.GetBufferSize(), CStrW(filename.string()).ToUTF8().c_str(), NULL, | ||||
XML_PARSE_NONET|XML_PARSE_NOCDATA); | XML_PARSE_NONET|XML_PARSE_NOCDATA); | ||||
if (!doc) | if (!doc) | ||||
{ | { | ||||
LOGERROR("CXeromyces: Failed to parse XML file %s", filename.string8()); | LOGERROR("CXeromyces: Failed to parse XML file %s", filename.string8()); | ||||
return PSRETURN_Xeromyces_XMLParseError; | return PSRETURN_Xeromyces_XMLParseError; | ||||
} | } | ||||
bool valid = true; | |||||
vladislavbelov: I think it's better to call it `validSource`, because of the function result is `xmb`. | |||||
elexisAuthorUnsubmitted Done Inline Actions(Guess its not so ambiguous since valid refers to the process of validation, but if we want to narrow it down, I'd suggest XML, as that's even more narrow than source) elexis: (Guess its not so ambiguous since valid refers to the process of validation, but if we want to… | |||||
elexisAuthorUnsubmitted Done Inline ActionsActually validXML is wrong, becaues the XML is valid according to XML specs, but the XML is not valid for that grammar. elexis: Actually validXML is wrong, becaues the XML is valid according to XML specs, but the XML is not… | |||||
{ | { | ||||
CScopeLock lock(g_ValidatorCacheLock); | CScopeLock lock(g_ValidatorCacheLock); | ||||
RelaxNGValidator& validator = GetValidator(validatorName); | RelaxNGValidator& validator = GetValidator(validatorName); | ||||
if (validator.CanValidate() && !validator.ValidateEncoded(doc)) | valid = !validator.CanValidate() || validator.ValidateEncoded(doc); | ||||
if (!valid) | |||||
// For now, log the error and continue, in the future we might fail | // For now, log the error and continue, in the future we might fail | ||||
LOGERROR("CXeromyces: failed to validate XML file %s", filename.string8()); | LOGERROR("CXeromyces: failed to validate XML file %s", filename.string8()); | ||||
} | } | ||||
WriteBuffer writeBuffer; | WriteBuffer writeBuffer; | ||||
CreateXMB(doc, writeBuffer); | CreateXMB(doc, writeBuffer); | ||||
xmlFreeDoc(doc); | xmlFreeDoc(doc); | ||||
// Save the file to disk, so it can be loaded quickly next time | // Save the file to disk, so it can be loaded quickly next time. | ||||
// Don't save if invalid, because we want the syntax error every program start. | |||||
if (valid) | |||||
vfs->CreateFile(xmbPath, writeBuffer.Data(), writeBuffer.Size()); | vfs->CreateFile(xmbPath, writeBuffer.Data(), writeBuffer.Size()); | ||||
m_XMBBuffer = writeBuffer.Data(); // add a reference | m_XMBBuffer = writeBuffer.Data(); // add a reference | ||||
// Set up the XMBFile | // Set up the XMBFile | ||||
const bool ok = Initialise((const char*)m_XMBBuffer.get()); | const bool ok = Initialise((const char*)m_XMBBuffer.get()); | ||||
ENSURE(ok); | ENSURE(ok); | ||||
return PSRETURN_OK; | return PSRETURN_OK; | ||||
▲ Show 20 Lines • Show All 223 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
I think it's better to call it validSource, because of the function result is xmb.