From 97ea3edbbfc21d338d339333a0ea10d672b9120d Mon Sep 17 00:00:00 2001 From: Flavio Tordini Date: Mon, 3 Aug 2015 14:18:46 +0200 Subject: [PATCH] Qt5 changed the data path, import db from old location --- src/database.cpp | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/src/database.cpp b/src/database.cpp index 0e1059f..004db38 100644 --- a/src/database.cpp +++ b/src/database.cpp @@ -31,9 +31,10 @@ Database::Database() { QString dataLocation = Paths::getDataLocation(); if (!QDir().mkpath(dataLocation)) { - qCritical() << "Failed to create directory " << dataLocation; + qCritical() << "Failed to create directory " << dataLocation; } dbLocation = dataLocation + "/" + dbName; + qDebug() << "dbLocation" << dbLocation; QMutexLocker locker(&lock); @@ -54,6 +55,20 @@ Database::~Database() { } void Database::createDatabase() { + qDebug() << __PRETTY_FUNCTION__; + +#ifdef APP_LINUX + // Qt5 changed its "data" path. Try to move the old db to the new path + QString qt4DataLocation = Paths::getHomeLocation() + "/.local/share/data/" + Constants::ORG_NAME + "/" + Constants::NAME; + QString oldDbLocation = qt4DataLocation + "/" + dbName; + qDebug() << oldDbLocation; + if (QFile::exists(oldDbLocation)) { + if (QFile::copy(oldDbLocation, dbLocation)) { + qDebug() << "Moved db from" << oldDbLocation << "to" << dbLocation; + return; + } + } +#endif qWarning() << "Creating the database"; @@ -108,8 +123,17 @@ QString Database::getDbLocation() { // static bool Database::exists() { static bool fileExists = false; - if (!fileExists) + if (!fileExists) { fileExists = QFile::exists(getDbLocation()); +#ifdef APP_LINUX + if (!fileExists) { + QString qt4DataLocation = Paths::getHomeLocation() + "/.local/share/data/" + Constants::ORG_NAME + "/" + Constants::NAME; + QString oldDbLocation = qt4DataLocation + "/" + dbName; + qDebug() << "asd" << oldDbLocation; + fileExists = QFile::exists(oldDbLocation); + } +#endif + } return fileExists; } -- 2.39.5