11#include <QDomDocument>
14#include <QDomNodeList>
25 if (type.startsWith(
"ko_")) {
28 else if (type.startsWith(
"kis_")) {
56 if (!device->isOpen()) {
57 if (!device->open(QIODevice::ReadOnly)) {
62 QDomDocument manifestDocument;
63#if QT_VERSION < QT_VERSION_CHECK(6, 5, 0)
67 if (!manifestDocument.setContent(device,
true, &errorMessage, &errorLine, &errorColumn)) {
68 warnKrita <<
"Error parsing manifest" << errorMessage
69 <<
"line" << errorLine
70 <<
"column" << errorColumn;
72 QDomDocument::ParseResult result = manifestDocument.setContent(device, QDomDocument::ParseOption::UseNamespaceProcessing);
74 warnKrita <<
"Error parsing manifest" << result.errorMessage
75 <<
"line" << result.errorLine
76 <<
"column" << result.errorColumn;
81 QDomElement root = manifestDocument.documentElement();
86 QDomElement e = root.firstChildElement(
"file-entry");
87 for (; !e.isNull(); e = e.nextSiblingElement(
"file-entry")) {
89 warnKrita <<
"Skipping invalid manifest entry"
90 <<
"line" << e.lineNumber();
108 if (fullPath ==
"/" && mediaType ==
"application/x-krita-resourcebundle") {
112 }
else if (fullPath.isNull() || mediaType.isNull() || md5sum.isNull()) {
117 QDomElement t = e.firstChildElement(
"tags")
118 .firstChildElement(
"tag");
119 for (; !t.isNull(); t = t.nextSiblingElement(
"tag")) {
120 QString tag = t.text();
126 addResource(mediaType, fullPath, tagList, QByteArray::fromHex(md5sum.toLatin1()), -1);
132 if (!device->isOpen()) {
133 if (!device->open(QIODevice::WriteOnly)) {
144 Q_FOREACH (QString resourceType,
m_resources.keys()) {
152 if (!resource.
tagList.isEmpty()) {
154 Q_FOREACH (
const QString tag, resource.
tagList) {
173 ResourceReference ref(fileName, fileTagList, fileTypeName, md5, resourceId, filenameInBundle);
175 m_resources[fileTypeName] = QMap<QString, ResourceReference>();
197 Q_FOREACH (
const QString &type,
m_resources.keys()) {
209 if (type.isEmpty()) {
211 Q_FOREACH (
const QString &type,
m_resources.keys()) {
224 Q_FOREACH (
const QString &type,
m_resources.keys()) {
QList< QString > QStringList
QString manifestTypeToResourceType(const QString &type)
QString resourceTypeToManifestType(const QString &type)
QStringList types() const
void removeFile(QString fileName)
removeFile : remove a file from the manifest
bool save(QIODevice *device)
save the ResourceBundleManifest to the given device
virtual ~KoResourceBundleManifest()
~ResourceBundleManifest : Dtor
bool parseFileEntry(const QDomElement &e)
KoResourceBundleManifest()
ResourceBundleManifest : Ctor.
bool load(QIODevice *device)
load the ResourceBundleManifest from the given device
QMap< QString, QMap< QString, ResourceReference > > m_resources
void removeResource(ResourceReference &resource)
void addResource(const QString &fileType, const QString &fileName, const QStringList &tagFileList, const QString &md5, const int resourceId=-1, const QString filenameInBundle="")
addTag : Add a file tag as a child of the fileType tag.
QList< ResourceReference > files(const QString &type=QString()) const
static const QString manifest
void addManifestEntry(const QString &fullPath, const QString &mediaType)
void startElement(const char *tagName, bool indentInside=true)
void endDocument()
Call this to terminate an XML document.
void startDocument(const char *rootElemName, const char *publicId=0, const char *systemId=0)
void addTextNode(const QString &str)
void addAttribute(const char *attrName, const QString &value)