From b0d2d05bc920b73be9aca784d7467e80aeaa2eb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20=C3=81ngel=20San=20Mart=C3=ADn?= Date: Sat, 29 Mar 2025 13:29:09 +0100 Subject: [PATCH] Change the type of path passed to DataBaseManagement::updateToCurrentVersion --- YACReaderLibrary/db/data_base_management.cpp | 23 ++++++++++---------- YACReaderLibrary/db/data_base_management.h | 2 +- YACReaderLibrary/library_window.cpp | 4 ++-- YACReaderLibraryServer/libraries_updater.cpp | 8 +++---- 4 files changed, 19 insertions(+), 18 deletions(-) diff --git a/YACReaderLibrary/db/data_base_management.cpp b/YACReaderLibrary/db/data_base_management.cpp index 2397eb6f..54169ced 100644 --- a/YACReaderLibrary/db/data_base_management.cpp +++ b/YACReaderLibrary/db/data_base_management.cpp @@ -853,7 +853,7 @@ int DataBaseManagement::compareVersions(const QString &v1, const QString v2) return 0; } -bool DataBaseManagement::updateToCurrentVersion(const QString &libraryDataPath) +bool DataBaseManagement::updateToCurrentVersion(const QString &libraryPath) { bool pre7 = false; bool pre7_1 = false; @@ -863,28 +863,28 @@ bool DataBaseManagement::updateToCurrentVersion(const QString &libraryDataPath) bool pre9_13 = false; bool pre9_14 = false; - QString fullPath = libraryDataPath + "/library.ydb"; + QString libraryDatabasePath = LibraryPaths::libraryDatabasePath(libraryPath); - if (compareVersions(DataBaseManagement::checkValidDB(fullPath), "7.0.0") < 0) + if (compareVersions(DataBaseManagement::checkValidDB(libraryDatabasePath), "7.0.0") < 0) pre7 = true; - if (compareVersions(DataBaseManagement::checkValidDB(fullPath), "7.0.3") < 0) + if (compareVersions(DataBaseManagement::checkValidDB(libraryDatabasePath), "7.0.3") < 0) pre7_1 = true; - if (compareVersions(DataBaseManagement::checkValidDB(fullPath), "8.0.0") < 0) + if (compareVersions(DataBaseManagement::checkValidDB(libraryDatabasePath), "8.0.0") < 0) pre8 = true; - if (compareVersions(DataBaseManagement::checkValidDB(fullPath), "9.5.0") < 0) + if (compareVersions(DataBaseManagement::checkValidDB(libraryDatabasePath), "9.5.0") < 0) pre9_5 = true; - if (compareVersions(DataBaseManagement::checkValidDB(fullPath), "9.8.0") < 0) + if (compareVersions(DataBaseManagement::checkValidDB(libraryDatabasePath), "9.8.0") < 0) pre9_8 = true; - if (compareVersions(DataBaseManagement::checkValidDB(fullPath), "9.13.0") < 0) + if (compareVersions(DataBaseManagement::checkValidDB(libraryDatabasePath), "9.13.0") < 0) pre9_13 = true; - if (compareVersions(DataBaseManagement::checkValidDB(fullPath), "9.14.0") < 0) + if (compareVersions(DataBaseManagement::checkValidDB(libraryDatabasePath), "9.14.0") < 0) pre9_14 = true; QString connectionName = ""; bool returnValue = true; { - QSqlDatabase db = loadDatabaseFromFile(fullPath); + QSqlDatabase db = loadDatabaseFromFile(libraryDatabasePath); if (db.isValid() && db.isOpen()) { if (pre7) // TODO: execute only if previous version was < 7.0 { @@ -968,7 +968,8 @@ bool DataBaseManagement::updateToCurrentVersion(const QString &libraryDataPath) QImageReader thumbnail; while (selectQuery.next()) { - thumbnail.setFileName(libraryDataPath % "/covers/" % selectQuery.value(1).toString() % ".jpg"); + auto coverPath = LibraryPaths::coverPath(libraryPath, selectQuery.value(1).toString()); + thumbnail.setFileName(coverPath); float coverSizeRatio = static_cast(thumbnail.size().width()) / thumbnail.size().height(); updateCoverInfo.bindValue(":coverSizeRatio", coverSizeRatio); diff --git a/YACReaderLibrary/db/data_base_management.h b/YACReaderLibrary/db/data_base_management.h index 17219890..3a96cf74 100644 --- a/YACReaderLibrary/db/data_base_management.h +++ b/YACReaderLibrary/db/data_base_management.h @@ -57,7 +57,7 @@ public: static QString checkValidDB(const QString &fullPath); // retorna "" si la DB es inválida ó la versión si es válida. static int compareVersions(const QString &v1, const QString v2); // retorna <0 si v1 < v2, 0 si v1 = v2 y >0 si v1 > v2 - static bool updateToCurrentVersion(const QString &path); + static bool updateToCurrentVersion(const QString &libraryPath); }; #endif diff --git a/YACReaderLibrary/library_window.cpp b/YACReaderLibrary/library_window.cpp index 891aa70a..98dec578 100644 --- a/YACReaderLibrary/library_window.cpp +++ b/YACReaderLibrary/library_window.cpp @@ -831,8 +831,8 @@ void LibraryWindow::loadLibrary(const QString &name) importWidget->setUpgradeLook(); showImportingWidget(); - upgradeLibraryFuture = std::async(std::launch::async, [this, name, path] { - bool updated = DataBaseManagement::updateToCurrentVersion(path); + upgradeLibraryFuture = std::async(std::launch::async, [this, name, path, rootPath] { + bool updated = DataBaseManagement::updateToCurrentVersion(rootPath); if (!updated) emit errorUpgradingLibrary(path); diff --git a/YACReaderLibraryServer/libraries_updater.cpp b/YACReaderLibraryServer/libraries_updater.cpp index ede15a03..c49aaa9b 100644 --- a/YACReaderLibraryServer/libraries_updater.cpp +++ b/YACReaderLibraryServer/libraries_updater.cpp @@ -14,9 +14,9 @@ void LibrariesUpdater::updateIfNeeded() libraries.load(); foreach (QString name, libraries.getNames()) { - QString root = libraries.getPath(name); - QString libraryDataPath = YACReader::LibraryPaths::libraryDataPath(root); - QString databasePath = YACReader::LibraryPaths::libraryDatabasePath(root); + QString libraryPath = libraries.getPath(name); + QString libraryDataPath = YACReader::LibraryPaths::libraryDataPath(libraryPath); + QString databasePath = YACReader::LibraryPaths::libraryDatabasePath(libraryPath); QDir d; @@ -25,7 +25,7 @@ void LibrariesUpdater::updateIfNeeded() int comparation = DataBaseManagement::compareVersions(dbVersion, DB_VERSION); if (comparation < 0) { - bool updated = DataBaseManagement::updateToCurrentVersion(libraryDataPath); + bool updated = DataBaseManagement::updateToCurrentVersion(libraryPath); if (!updated) { // TODO log error }