mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2025-03-01 10:33:28 +00:00
move 'name' to new config section general. (#345)
* move name to general add a version for config file * start impl. config migrator * fix typo amd set access level * fix schemaa name * fix schema * add structure for config migrator
This commit is contained in:
@@ -31,7 +31,7 @@
|
||||
#include <udplistener/UDPListener.h>
|
||||
|
||||
#include "hyperiond.h"
|
||||
|
||||
#include "configMigrator.h"
|
||||
|
||||
HyperionDaemon::HyperionDaemon(QString configFile, QObject *parent)
|
||||
: QObject(parent)
|
||||
@@ -51,7 +51,7 @@ HyperionDaemon::HyperionDaemon(QString configFile, QObject *parent)
|
||||
, _osxGrabber(nullptr)
|
||||
, _hyperion(nullptr)
|
||||
{
|
||||
loadConfig(configFile);
|
||||
loadConfig(configFile, CURRENT_CONFIG_VERSION );
|
||||
|
||||
if (Logger::getLogLevel() == Logger::WARNING)
|
||||
{
|
||||
@@ -116,20 +116,21 @@ void HyperionDaemon::run()
|
||||
|
||||
}
|
||||
|
||||
void HyperionDaemon::loadConfig(const QString & configFile)
|
||||
int HyperionDaemon::tryLoadConfig(const QString & configFile, const int schemaVersion)
|
||||
{
|
||||
Info(_log, "Selected configuration file: %s", configFile.toUtf8().constData());
|
||||
|
||||
// make sure the resources are loaded (they may be left out after static linking)
|
||||
Q_INIT_RESOURCE(resource);
|
||||
QJsonParseError error;
|
||||
|
||||
// read the json schema from the resource
|
||||
QFile schemaData(":/hyperion-schema");
|
||||
QString schemaFile = ":/hyperion-schema";
|
||||
if (schemaVersion > 0)
|
||||
schemaFile += "-" + QString::number(schemaVersion);
|
||||
QFile schemaData(schemaFile);
|
||||
if (!schemaData.open(QIODevice::ReadOnly))
|
||||
{
|
||||
std::stringstream error;
|
||||
error << "Schema not found: " << schemaData.errorString().toStdString();
|
||||
error << "Schema not found or not supported: " << schemaData.errorString().toStdString();
|
||||
throw std::runtime_error(error.str());
|
||||
}
|
||||
|
||||
@@ -168,11 +169,42 @@ void HyperionDaemon::loadConfig(const QString & configFile)
|
||||
{
|
||||
std::cout << *i << std::endl;
|
||||
}
|
||||
|
||||
|
||||
throw std::runtime_error("ERROR: Json validation failed");
|
||||
}
|
||||
|
||||
const QJsonObject & generalConfig = _qconfig["general"].toObject();
|
||||
return generalConfig["configVersion"].toInt(-1);
|
||||
}
|
||||
|
||||
|
||||
void HyperionDaemon::loadConfig(const QString & configFile, const int neededConfigVersion)
|
||||
{
|
||||
Info(_log, "Selected configuration file: %s", configFile.toUtf8().constData());
|
||||
|
||||
int configVersionId = tryLoadConfig(configFile,0);
|
||||
|
||||
// no config id found, assume legacy hyperion
|
||||
if (configVersionId < 0)
|
||||
{
|
||||
Debug(_log, "config file has no version, assume old hyperion.");
|
||||
configVersionId = tryLoadConfig(configFile,1);
|
||||
}
|
||||
Debug(_log, "config version: %d", configVersionId);
|
||||
configVersionId = tryLoadConfig(configFile, configVersionId);
|
||||
|
||||
if (neededConfigVersion == configVersionId)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// migrate configVersionId
|
||||
ConfigMigrator migrator;
|
||||
migrator.migrate(configFile, configVersionId, neededConfigVersion);
|
||||
|
||||
}
|
||||
|
||||
|
||||
void HyperionDaemon::startInitialEffect()
|
||||
{
|
||||
#define FGCONFIG_ARRAY fgEffectConfig.toArray()
|
||||
@@ -343,8 +375,8 @@ void HyperionDaemon::startNetworkServices()
|
||||
connect( Hyperion::getInstance(), SIGNAL(componentStateChanged(hyperion::Components,bool)), _udpListener, SLOT(componentStateChanged(hyperion::Components,bool)));
|
||||
|
||||
// zeroconf description - $leddevicename@$hostname
|
||||
const QJsonObject & deviceConfig = _qconfig["device"].toObject();
|
||||
const std::string mDNSDescr = ( deviceConfig["name"].toString("").toStdString()
|
||||
const QJsonObject & generalConfig = _qconfig["general"].toObject();
|
||||
const std::string mDNSDescr = ( generalConfig["name"].toString("").toStdString()
|
||||
+ "@" +
|
||||
QHostInfo::localHostName().toStdString()
|
||||
);
|
||||
|
Reference in New Issue
Block a user