Commit 21af93e5 authored by Boudewijn Rempt's avatar Boudewijn Rempt

Distinguish between first run, first update, update or already initialized

parent 59cd1c2c
......@@ -27,6 +27,8 @@
#include <kis_debug.h>
#include "KisResourceLocator.h"
const QString dbDriver = "QSQLITE";
const QStringList KisResourceCacheDb::resourceTypes = QStringList() << "BRUSH_TIP"
......@@ -144,6 +146,7 @@ QSqlError KisResourceCacheDb::Private::initDb(const QString &location)
<< "At" << creationDate;
if (schemaVersion != databaseVersion) {
// XXX: Implement migration
warnResources << "Database schema is outdated, migration is needed";
schemaIsOutDated = true;
}
......
......@@ -24,12 +24,14 @@
#include <QDir>
#include <QFileInfo>
#include <QMessageBox>
#include <QVersionNumber>
#include <kconfig.h>
#include <kconfiggroup.h>
#include <ksharedconfig.h>
#include <klocalizedstring.h>
#include <KritaVersionWrapper.h>
#include "KoResourcePaths.h"
#include "KisResourceStorage.h"
......@@ -65,6 +67,8 @@ KisResourceLocator::~KisResourceLocator()
KisResourceLocator::LocatorError KisResourceLocator::initialize(const QString &installationResourcesLocation)
{
InitalizationStatus initalizationStatus = InitalizationStatus::Unknown;
KConfigGroup cfg(KSharedConfig::openConfig(), "");
d->resourceLocation = cfg.readEntry(resourceLocationKey, QStandardPaths::writableLocation(QStandardPaths::AppDataLocation));
......@@ -75,6 +79,7 @@ KisResourceLocator::LocatorError KisResourceLocator::initialize(const QString &i
d->errorMessages << i18n("1. Could not create the resource location at %1.", d->resourceLocation);
return LocatorError::CannotCreateLocation;
}
initalizationStatus = InitalizationStatus::FirstRun;
}
if (!fi.isWritable()) {
......@@ -82,8 +87,25 @@ KisResourceLocator::LocatorError KisResourceLocator::initialize(const QString &i
return LocatorError::LocationReadOnly;
}
if (QDir(d->resourceLocation).isEmpty()) {
KisResourceLocator::LocatorError res = firstTimeInstallation(installationResourcesLocation);
// Check whether we're updating from an older version
if (initalizationStatus != InitalizationStatus::FirstRun && !QDir(installationResourcesLocation).entryList().contains("KRITA_RESOURCE_VERSION")) {
initalizationStatus = InitalizationStatus::FirstUpdate;
}
else {
QFile fi(installationResourcesLocation + '/' + "KRITA_RESOURCE_VERSION");
fi.open(QFile::ReadOnly);
QVersionNumber resource_version = QVersionNumber::fromString(QString::fromUtf8(fi.readAll()));
QVersionNumber krita_version = QVersionNumber::fromString(KritaVersionWrapper::versionString());
if (krita_version > resource_version) {
initalizationStatus = InitalizationStatus::Updating;
}
else {
initalizationStatus = InitalizationStatus::Initialized;
}
}
if (initalizationStatus != InitalizationStatus::Initialized) {
KisResourceLocator::LocatorError res = firstTimeInstallation(initalizationStatus, installationResourcesLocation);
if (res != LocatorError::Ok) {
return res;
}
......@@ -97,8 +119,10 @@ QStringList KisResourceLocator::errorMessages() const
return d->errorMessages;
}
KisResourceLocator::LocatorError KisResourceLocator::firstTimeInstallation(const QString &installationResourcesLocation)
KisResourceLocator::LocatorError KisResourceLocator::firstTimeInstallation(InitalizationStatus initalizationStatus, const QString &installationResourcesLocation)
{
Q_UNUSED(initalizationStatus);
Q_FOREACH(const QString &folder, resourceTypeFolders) {
QDir dir(d->resourceLocation + '/' + folder + '/');
if (!dir.exists()) {
......@@ -122,5 +146,15 @@ KisResourceLocator::LocatorError KisResourceLocator::firstTimeInstallation(const
}
}
QFile f(installationResourcesLocation + '/' + "KRITA_RESOURCE_VERSION");
f.open(QFile::WriteOnly);
f.write(KritaVersionWrapper::versionString().toUtf8());
f.close();
return LocatorError::Ok;
}
KisResourceLocator::LocatorError KisResourceLocator::synchronizeDb()
{
return LocatorError::Ok;
}
......@@ -59,7 +59,17 @@ public:
private:
LocatorError firstTimeInstallation(const QString &installationResourcesLocation);
enum class InitalizationStatus {
Unknown, // We don't know whether Krita has run on this system for this resource location yet
Initialized, // Everything is ready to start synchronizing the database
FirstRun, // Krita hasn't run for this resource location yet
FirstUpdate, // Krita was installed, but it's a version from before the resource locator existed, only user-defined resources are present
Updating // Krita is updating from an older version with a resource locator
};
LocatorError firstTimeInstallation(InitalizationStatus initalizationStatus, const QString &installationResourcesLocation);
LocatorError synchronizeDb();
class Private;
QScopedPointer<Private> d;
......
......@@ -13,4 +13,4 @@ ecm_add_tests(
TestResourceLocator
TestResourceStorage
NAME_PREFIX "libs-kritaresources-"
LINK_LIBRARIES kritaresources KF5::ConfigCore Qt5::Sql Qt5::Test)
LINK_LIBRARIES kritaresources kritaversion KF5::ConfigCore Qt5::Sql Qt5::Test)
......@@ -20,12 +20,14 @@
#include "TestResourceLocator.h"
#include <QTest>
#include <QVersionNumber>
#include <kconfig.h>
#include <kconfiggroup.h>
#include <ksharedconfig.h>
#include <KisResourceLocator.h>
#include <KritaVersionWrapper.h>
#ifndef FILES_DATA_DIR
#error "FILES_DATA_DIR not set. A directory with the data used for testing installing resources"
......@@ -61,6 +63,11 @@ void TestResourceLocator::testLocator()
QVERIFY(dstDir.exists());
QVERIFY(dstDir.entryList(QDir::NoDotAndDotDot) == srcDir.entryList(QDir::NoDotAndDotDot));
}
QFile f(dstLocation + '/' + "KRITA_RESOURCE_VERSION");
f.open(QFile::ReadOnly);
QVersionNumber version = QVersionNumber::fromString(QString::fromUtf8(f.readAll()));
QVERIFY(version == QVersionNumber::fromString(KritaVersionWrapper::versionString()));
}
void TestResourceLocator::cleanupTestCase()
......
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