feat(client): improve SDK packaging and registry config
This commit is contained in:
+28
-34
@@ -1,8 +1,7 @@
|
||||
#include "LocalStateHelper.h"
|
||||
#include <QFile>
|
||||
#include <QFileInfo>
|
||||
#include <QJsonDocument>
|
||||
#include <QDir>
|
||||
#include "LocalStateHelper.h"
|
||||
#include "ConfigHelper.h"
|
||||
#include <QFile>
|
||||
#include <QJsonDocument>
|
||||
|
||||
LocalStateHelper::LocalStateHelper(const QString& baseDir)
|
||||
: m_baseDir(baseDir)
|
||||
@@ -13,19 +12,12 @@ LocalStateHelper::LocalStateHelper(const QString& baseDir)
|
||||
bool LocalStateHelper::loadState(const QString& relativePath)
|
||||
{
|
||||
m_filePath = m_baseDir + "/" + relativePath;
|
||||
QFile file(m_filePath);
|
||||
if (!file.exists())
|
||||
{
|
||||
QDir dir(QFileInfo(m_filePath).path());
|
||||
if (!dir.exists() && !dir.mkpath("."))
|
||||
{
|
||||
m_error = QString("Cannot create state directory: %1").arg(dir.path());
|
||||
return false;
|
||||
}
|
||||
|
||||
m_state = QJsonObject{
|
||||
{"max_policy_seq", 0},
|
||||
{"last_success_run_at", QString()},
|
||||
QFile file(m_filePath);
|
||||
if (!file.exists())
|
||||
{
|
||||
m_state = QJsonObject{
|
||||
{"max_policy_seq", 0},
|
||||
{"last_success_run_at", QString()},
|
||||
{"last_online_verified_at", QString()},
|
||||
{"last_success_version", QString()}
|
||||
};
|
||||
@@ -60,22 +52,24 @@ bool LocalStateHelper::loadState(const QString& relativePath)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool LocalStateHelper::saveState() const
|
||||
{
|
||||
if (!m_loaded)
|
||||
return false;
|
||||
|
||||
QFile file(m_filePath);
|
||||
if (!file.open(QIODevice::WriteOnly | QIODevice::Truncate))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
QJsonDocument doc(m_state);
|
||||
file.write(doc.toJson(QJsonDocument::Indented));
|
||||
file.close();
|
||||
return true;
|
||||
}
|
||||
bool LocalStateHelper::saveState() const
|
||||
{
|
||||
if (!m_loaded)
|
||||
{
|
||||
m_error = "State is not loaded";
|
||||
return false;
|
||||
}
|
||||
|
||||
QJsonDocument doc(m_state);
|
||||
QString writeError;
|
||||
if (!ConfigHelper::writeFileWithElevationIfNeeded(m_filePath, doc.toJson(QJsonDocument::Indented), &writeError))
|
||||
{
|
||||
m_error = QString("Cannot save state file: %1").arg(writeError);
|
||||
return false;
|
||||
}
|
||||
m_error.clear();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool LocalStateHelper::isLoaded() const
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user