Commit 284350ca authored by Boudewijn Rempt's avatar Boudewijn Rempt

Add checking of zip-based files after they've been saved

parent 762a82fb
......@@ -32,6 +32,8 @@ Boston, MA 02110-1301, USA.
#include "KoUpdater.h"
#include <klocalizedstring.h>
#include "kis_config.h"
#include <KoStore.h>
#include <KisDocument.h>
const QString KisImportExportFilter::ImageContainsTransparencyTag = "ImageContainsTransparency";
const QString KisImportExportFilter::ColorModelIDTag = "ColorModelID";
......@@ -322,3 +324,21 @@ void KisImportExportFilter::addSupportedColorModels(QList<QPair<KoID, KoID> > su
}
}
}
QString KisImportExportFilter::verifyZiPBasedFiles(const QString &fileName, const QStringList &filesToCheck) const
{
QScopedPointer<KoStore> store(KoStore::createStore(fileName, KoStore::Read, KIS_MIME_TYPE, KoStore::Zip));
if (!store || store->bad()) {
return i18n("Could not open the saved file %1. Please try to save again in a different location.", fileName);
}
Q_FOREACH(const QString &file, filesToCheck) {
if (!store->hasFile(file)) {
return i18n("File %1 is missing in %2 and is broken. Please try to save again in a different location.", file, fileName);
}
}
return QString();
}
......@@ -175,6 +175,8 @@ protected:
void addCapability(KisExportCheckBase *capability);
void addSupportedColorModels(QList<QPair<KoID, KoID> > supportedColorModels, const QString &name, KisExportCheckBase::Level level = KisExportCheckBase::PARTIALLY);
QString verifyZiPBasedFiles(const QString &fileName, const QStringList &filesToCheck) const;
private:
KisImportExportFilter(const KisImportExportFilter& rhs);
......
......@@ -683,6 +683,7 @@ KisImportExportErrorCode KisImportExportManager::doExportImpl(const QString &loc
// Do some minimal verification
QString verificationResult = filter->verify(location);
qDebug() << verificationResult;
if (!verificationResult.isEmpty()) {
status = KisImportExportErrorCode(ImportExportCodes::ErrorWhileWriting);
m_document->setErrorMessage(verificationResult);
......
......@@ -74,5 +74,21 @@ void KraExport::initializeCapabilities()
}
}
QString KraExport::verify(const QString &fileName) const
{
QString error = KisImportExportFilter::verify(fileName);
if (error.isEmpty()) {
return KisImportExportFilter::verifyZiPBasedFiles(fileName,
QStringList()
<< "mimetype"
<< "documentinfo.xml"
<< "maindoc.xml"
<< "mergedimage.png"
<< "preview.png");
}
return error;
}
#include <kra_export.moc>
......@@ -33,7 +33,7 @@ public:
public:
KisImportExportErrorCode convert(KisDocument *document, QIODevice *io, KisPropertiesConfigurationSP configuration = 0) override;
void initializeCapabilities() override;
QString verify(const QString &fileName) const override;
};
#endif
......@@ -23,7 +23,7 @@
#include <kpluginfactory.h>
#include <QFileInfo>
#include <QApplication>
#include <KoStore.h>
#include <KisImportExportManager.h>
#include <KoColorModelStandardIds.h>
#include <KoColorSpace.h>
......@@ -97,6 +97,20 @@ void OraExport::initializeCapabilities()
addSupportedColorModels(supportedColorModels, "OpenRaster");
}
QString OraExport::verify(const QString &fileName) const
{
QString error = KisImportExportFilter::verify(fileName);
if (error.isEmpty()) {
return KisImportExportFilter::verifyZiPBasedFiles(fileName,
QStringList()
<< "mimetype"
<< "stack.xml"
<< "mergedimage.png");
}
return error;
}
#include <ora_export.moc>
......
......@@ -31,6 +31,7 @@ public:
public:
KisImportExportErrorCode convert(KisDocument *document, QIODevice *io, KisPropertiesConfigurationSP configuration = 0) override;
void initializeCapabilities() override;
QString verify(const QString &fileName) const override;
};
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment