Changeset View
Changeset View
Standalone View
Standalone View
source/ps/XML/Xeromyces.cpp
Show First 20 Lines • Show All 168 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`. | |||||
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… | |||||
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… | |||||
{ | { | ||||
std::lock_guard<std::mutex> lock(g_ValidatorCacheLock); | std::lock_guard<std::mutex> lock(g_ValidatorCacheLock); | ||||
RelaxNGValidator& validator = GetValidator(validatorName); | RelaxNGValidator& validator = GetValidator(validatorName); | ||||
if (validator.CanValidate() && !validator.ValidateEncoded(doc)) | valid = !validator.CanValidate() || validator.ValidateEncoded(doc); | ||||
// For now, log the error and continue, in the future we might fail | if (!valid) | ||||
{ | |||||
LOGERROR("CXeromyces: failed to validate XML file %s", filename.string8()); | LOGERROR("CXeromyces: failed to validate XML file %s", filename.string8()); | ||||
return PSRETURN_Xeromyces_XMLValidationFailed; | |||||
} | |||||
} | } | ||||
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 All 28 Lines | if (!doc) | ||||
LOGERROR("CXeromyces: Failed to parse XML string"); | LOGERROR("CXeromyces: Failed to parse XML string"); | ||||
return PSRETURN_Xeromyces_XMLParseError; | return PSRETURN_Xeromyces_XMLParseError; | ||||
} | } | ||||
{ | { | ||||
std::lock_guard<std::mutex> lock(g_ValidatorCacheLock); | std::lock_guard<std::mutex> lock(g_ValidatorCacheLock); | ||||
RelaxNGValidator& validator = GetValidator(validatorName); | RelaxNGValidator& validator = GetValidator(validatorName); | ||||
if (validator.CanValidate() && !validator.ValidateEncoded(doc)) | if (validator.CanValidate() && !validator.ValidateEncoded(doc)) | ||||
// For now, log the error and continue, in the future we might fail | { | ||||
LOGERROR("CXeromyces: failed to validate XML string"); | LOGERROR("CXeromyces: failed to validate XML string"); | ||||
return PSRETURN_Xeromyces_XMLValidationFailed; | |||||
} | |||||
} | } | ||||
WriteBuffer writeBuffer; | WriteBuffer writeBuffer; | ||||
CreateXMB(doc, writeBuffer); | CreateXMB(doc, writeBuffer); | ||||
xmlFreeDoc(doc); | xmlFreeDoc(doc); | ||||
m_XMBBuffer = writeBuffer.Data(); // add a reference | m_XMBBuffer = writeBuffer.Data(); // add a reference | ||||
▲ Show 20 Lines • Show All 176 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
I think it's better to call it validSource, because of the function result is xmb.