Add the ability to update libraries to new versions in the headless server

It checks the libraries on the start up. It will block the app until everyting it is ready. C
This commit is contained in:
Luis Ángel San Martín 2018-04-28 10:24:10 +02:00
parent a4941553ec
commit c593e3570d
3 changed files with 58 additions and 0 deletions

View File

@ -0,0 +1,39 @@
#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,VERSION);
if(comparation < 0)
{
bool updated = DataBaseManagement::updateToCurrentVersion(path);
if(!updated) {
//TODO log error
}
}
}
}
}

View File

@ -0,0 +1,13 @@
#ifndef LIBRARIES_UPDATER_H
#define LIBRARIES_UPDATER_H
class LibrariesUpdater
{
public:
LibrariesUpdater();
void updateIfNeeded();
};
#endif // LIBRARIES_UPDATER_H

View File

@ -11,6 +11,8 @@
#include "yacreader_libraries.h"
#include "yacreader_local_server.h"
#include "libraries_updater.h"
#include "console_ui_library_creator.h"
#include <iostream>
@ -136,6 +138,10 @@ int main( int argc, char ** argv )
}
QLOG_INFO() << "YACReaderLibrary starting";
//Update libraries to now versions
LibrariesUpdater updater;
updater.updateIfNeeded();
YACReaderLocalServer * localServer = new YACReaderLocalServer();
int ret = app.exec();