Krita Source Code Documentation
Loading...
Searching...
No Matches
kis_md5_generator.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2015 Stefano Bonicatti <smjert@gmail.com>
3 *
4 * SPDX-License-Identifier: LGPL-2.1-or-later
5*/
6#include "kis_md5_generator.h"
7
8#include <kis_debug.h>
9#include <KoStore.h>
10
11KisMD5Generator::KisMD5Generator()
12{
13
14}
15
16KisMD5Generator::~KisMD5Generator()
17{
18
19}
20
21QByteArray KisMD5Generator::generateHash(const QString &filename)
22{
23 QByteArray ba;
24 if(filename.startsWith("bundle://")) {
25 QString bn = filename.mid(9);
26 int pos = bn.lastIndexOf(":");
27 QString fn = bn.right(bn.size() - pos - 1);
28 bn = bn.left(pos);
29
30 QScopedPointer<KoStore> resourceStore(KoStore::createStore(bn, KoStore::Read, "application/x-krita-resourcebundle", KoStore::Zip));
31 if (!resourceStore || resourceStore->bad()) {
32 warnKrita << "Could not open store on bundle" << bn;
33 return ba;
34 }
35
36 if (resourceStore->isOpen()) resourceStore->close();
37
38 if (!resourceStore->open(fn)) {
39 warnKrita << "Could not open preset" << fn << "in bundle" << bn;
40 return ba;
41 }
42
43 ba = resourceStore->device()->readAll();
44
45 resourceStore->close();
47
48 }
49
50 return KoMD5Generator::generateHash(filename);
51}
static QString generateHash(const QString &filename)
generateHash reads the given file and generates a hex-encoded md5sum for the file.
@ Read
Definition KoStore.h:29
@ Zip
Definition KoStore.h:30
static KoStore * createStore(const QString &fileName, Mode mode, const QByteArray &appIdentification=QByteArray(), Backend backend=Auto, bool writeMimetype=true)
Definition KoStore.cpp:39
#define warnKrita
Definition kis_debug.h:87