MCPcopy Create free account
hub / github.com/FreeCAD/FreeCAD / xmlFilesAreValid

Function xmlFilesAreValid

src/Gui/DocumentRecovery.cpp:524–564  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

522}
523
524bool xmlFilesAreValid(const QString& fcstdFile)
525{
526 try {
527 zipios::ZipFile zf(fcstdFile.toStdString());
528 auto doc = findEntry(zf, "Document.xml");
529 if (!doc) {
530 return false;
531 }
532 {
533 auto s = zf.getInputStream(doc);
534 QByteArray bytes;
535 bytes.resize(0);
536 std::string tmp((std::istreambuf_iterator<char>(*s)), std::istreambuf_iterator<char>());
537 QXmlStreamReader xr(QByteArray(tmp.data(), int(tmp.size())));
538 while (!xr.atEnd()) {
539 xr.readNext();
540 }
541 if (xr.hasError()) {
542 return false;
543 }
544 }
545
546 // GuiDocument.xml is optional, but if it's present it must be well-formed
547 if (auto gui = findEntry(zf, "GuiDocument.xml")) {
548 auto s = zf.getInputStream(gui);
549 std::string tmp((std::istreambuf_iterator<char>(*s)), std::istreambuf_iterator<char>());
550 QXmlStreamReader xr(QByteArray(tmp.data(), int(tmp.size())));
551 while (!xr.atEnd()) {
552 xr.readNext();
553 }
554 if (xr.hasError()) {
555 return false;
556 }
557 }
558
559 return true;
560 }
561 catch (...) {
562 return false;
563 }
564}
565
566bool DocumentRecoveryPrivate::isValidProject(const QFileInfo& fi) const
567{

Callers 1

isValidProjectMethod · 0.85

Calls 7

findEntryFunction · 0.85
toStdStringMethod · 0.80
QByteArrayClass · 0.70
getInputStreamMethod · 0.45
resizeMethod · 0.45
dataMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected