mirror of
https://gitee.com/spark-store-project/spark-store
synced 2026-03-25 23:09:44 +08:00
确保正确上传版本号,避免升级改变UUID
This commit is contained in:
@@ -89,12 +89,25 @@ void Application::checkAppConfigLocation()
|
||||
void Application::setBuildDateTime(const QString &buildDateTime)
|
||||
{
|
||||
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)) {
|
||||
qDebug() << "Spark Store has been updated!";
|
||||
|
||||
config.setValue("build/version", QString(APP_VERSION));
|
||||
config.setValue("build/branch", QString(APP_BRANCH));
|
||||
config.setValue("build/time", buildDateTime);
|
||||
|
||||
// 恢复原有的 UUID
|
||||
config.setValue("info/uuid", currentUuid);
|
||||
|
||||
config.sync();
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include <QDebug>
|
||||
#include <QFile>
|
||||
#include <QTextStream>
|
||||
#include <QCoreApplication>
|
||||
|
||||
DataCollectorAndUploader::DataCollectorAndUploader(QObject *parent) : QObject(parent)
|
||||
{
|
||||
@@ -27,11 +28,17 @@ void DataCollectorAndUploader::collectData()
|
||||
QString architecture;
|
||||
|
||||
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();
|
||||
|
||||
// Read /etc/os-release file
|
||||
QFile osReleaseFile("/etc/os-release");
|
||||
// 根据环境变量选择 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)) {
|
||||
QTextStream in(&osReleaseFile);
|
||||
while (!in.atEnd()) {
|
||||
@@ -44,7 +51,7 @@ void DataCollectorAndUploader::collectData()
|
||||
}
|
||||
osReleaseFile.close();
|
||||
} else {
|
||||
qWarning() << "Could not open /etc/os-release file";
|
||||
qWarning() << "Could not open os-release file:" << osReleasePath;
|
||||
}
|
||||
|
||||
// Execute uname -m to get the architecture
|
||||
|
||||
Reference in New Issue
Block a user