16#include <QCoreApplication>
17#include <QCryptographicHash>
21#include <QXmlSchemaValidator>
22#include <QXmlStreamReader>
33 : schemaFile_(std::move(schemaFile))
41 if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
43 ERR(
"XMLQtInterface::readFile(): Can't open xml-file {:s}.",
44 fileName.toStdString());
64 QDir(QCoreApplication::applicationDirPath()).filePath(
schemaFile_);
65 auto url = QUrl::fromLocalFile(path);
70 QXmlSchemaValidator validator(schema);
77 "XMLQtInterface::isValid(): XML file {:s} is invalid (in reference "
85 QXmlSchemaValidator validator;
92 "XMLQtInterface::isValid(): XML file {:s} is invalid (in reference "
102 QByteArray fileHash =
103 QCryptographicHash::hash(
fileData_, QCryptographicHash::Md5);
105 QFile file(md5FileName);
106 if (file.open(QIODevice::ReadOnly))
108 QByteArray referenceHash = file.readAll();
110 if (referenceHash == fileHash)
114 INFO(
"Hashfile does not match data ... checking file ...");
122 QFile fileMD5(md5FileName);
123 if (fileMD5.open(QIODevice::WriteOnly))
125 fileMD5.write(fileHash);
127 INFO(
"File is valid, hashfile written.");
131 WARN(
"File is valid but could not write hashfile!");
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
void WARN(fmt::format_string< Args... > fmt, Args &&... args)
QByteArray fileData_
Caches the actual file contents when reading.
QByteArray const & getContent() const
virtual int readFile(const QString &fileName)
XMLQtInterface(QString schemaFile="")
QString fileName_
The actual file name when reading.