yacreader/YACReaderLibraryServer/libraries_updater.cpp
Luis Ángel San Martín 71a7a07274 Add DB_VERSION to keep track of DBs versions
This will make easy to track compatibility with a certain DB structure across different flavors of YACReader. It will only change when the DB structure changes.
2023-08-06 08:55:55 +02:00

34 lines
880 B
C++

#include "libraries_updater.h"
#include "yacreader_libraries.h"
#include "data_base_management.h"
LibrariesUpdater::LibrariesUpdater()
{
}
void LibrariesUpdater::updateIfNeeded()
{
YACReaderLibraries libraries;
libraries.load();
foreach (QString name, libraries.getNames()) {
QString path = libraries.getPath(name) + "/.yacreaderlibrary";
QDir d;
QString dbVersion;
if (d.exists(path) && d.exists(path + "/library.ydb") && (dbVersion = DataBaseManagement::checkValidDB(path + "/library.ydb")) != "") {
int comparation = DataBaseManagement::compareVersions(dbVersion, DB_VERSION);
if (comparation < 0) {
bool updated = DataBaseManagement::updateToCurrentVersion(path);
if (!updated) {
// TODO log error
}
}
}
}
}