mirror of
https://gitee.com/spark-store-project/spark-store
synced 2026-03-25 14:59:44 +08:00
确保正确上传版本号,避免升级改变UUID
This commit is contained in:
@@ -89,12 +89,25 @@ void Application::checkAppConfigLocation()
|
|||||||
void Application::setBuildDateTime(const QString &buildDateTime)
|
void Application::setBuildDateTime(const QString &buildDateTime)
|
||||||
{
|
{
|
||||||
QSettings config(QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation) + "/config.ini", QSettings::IniFormat);
|
QSettings config(QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation) + "/config.ini", QSettings::IniFormat);
|
||||||
|
|
||||||
|
// 确保 UUID 存在
|
||||||
|
if (!config.contains("info/uuid")) {
|
||||||
|
QUuid uuid = QUuid::createUuid();
|
||||||
|
config.setValue("info/uuid", uuid.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
QString currentUuid = config.value("info/uuid").toString();
|
||||||
|
|
||||||
if (config.value("build/version").toString() != QString(APP_VERSION)) {
|
if (config.value("build/version").toString() != QString(APP_VERSION)) {
|
||||||
qDebug() << "Spark Store has been updated!";
|
qDebug() << "Spark Store has been updated!";
|
||||||
|
|
||||||
config.setValue("build/version", QString(APP_VERSION));
|
config.setValue("build/version", QString(APP_VERSION));
|
||||||
config.setValue("build/branch", QString(APP_BRANCH));
|
config.setValue("build/branch", QString(APP_BRANCH));
|
||||||
config.setValue("build/time", buildDateTime);
|
config.setValue("build/time", buildDateTime);
|
||||||
|
|
||||||
|
// 恢复原有的 UUID
|
||||||
|
config.setValue("info/uuid", currentUuid);
|
||||||
|
|
||||||
config.sync();
|
config.sync();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QTextStream>
|
#include <QTextStream>
|
||||||
|
#include <QCoreApplication>
|
||||||
|
|
||||||
DataCollectorAndUploader::DataCollectorAndUploader(QObject *parent) : QObject(parent)
|
DataCollectorAndUploader::DataCollectorAndUploader(QObject *parent) : QObject(parent)
|
||||||
{
|
{
|
||||||
@@ -27,11 +28,17 @@ void DataCollectorAndUploader::collectData()
|
|||||||
QString architecture;
|
QString architecture;
|
||||||
|
|
||||||
QSettings config(QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation) + "/config.ini", QSettings::IniFormat);
|
QSettings config(QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation) + "/config.ini", QSettings::IniFormat);
|
||||||
QString version = config.value("build/version").toString();
|
QString version = QString(APP_VERSION); // 使用编译时定义的版本号
|
||||||
QString uuid = config.value("info/uuid").toString();
|
QString uuid = config.value("info/uuid").toString();
|
||||||
|
|
||||||
// Read /etc/os-release file
|
// 根据环境变量选择 os-release 文件路径
|
||||||
QFile osReleaseFile("/etc/os-release");
|
QString osReleasePath = "/etc/os-release";
|
||||||
|
if (qEnvironmentVariableIsSet("IS_ACE_ENV") && qgetenv("IS_ACE_ENV") == "1") {
|
||||||
|
osReleasePath = "/host/etc/os-release";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read os-release file
|
||||||
|
QFile osReleaseFile(osReleasePath);
|
||||||
if (osReleaseFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
if (osReleaseFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||||
QTextStream in(&osReleaseFile);
|
QTextStream in(&osReleaseFile);
|
||||||
while (!in.atEnd()) {
|
while (!in.atEnd()) {
|
||||||
@@ -44,7 +51,7 @@ void DataCollectorAndUploader::collectData()
|
|||||||
}
|
}
|
||||||
osReleaseFile.close();
|
osReleaseFile.close();
|
||||||
} else {
|
} else {
|
||||||
qWarning() << "Could not open /etc/os-release file";
|
qWarning() << "Could not open os-release file:" << osReleasePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Execute uname -m to get the architecture
|
// Execute uname -m to get the architecture
|
||||||
@@ -83,4 +90,4 @@ void DataCollectorAndUploader::collectData()
|
|||||||
}
|
}
|
||||||
reply->deleteLater();
|
reply->deleteLater();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user