feat: 支持按策略生成 Git 标签清单
This commit is contained in:
@@ -101,8 +101,8 @@ void UpdateLogic::getDownloadUrl(const QString& appId, const QString& channel, c
|
||||
});
|
||||
}
|
||||
|
||||
bool UpdateLogic::cacheManifest(const QString& appId, const QString& channel, const QString& version,
|
||||
int versionId, const QString& cacheDir)
|
||||
bool UpdateLogic::cacheManifest(const QString& appId, const QString& channel, const QString& version,
|
||||
int versionId, const QString& cacheDir)
|
||||
{
|
||||
m_error.clear();
|
||||
if (appId.isEmpty() || channel.isEmpty() || version.isEmpty() || versionId <= 0) {
|
||||
@@ -157,11 +157,56 @@ bool UpdateLogic::cacheManifest(const QString& appId, const QString& channel, co
|
||||
return false;
|
||||
}
|
||||
qDebug() << "Current version manifest cached to" << file.fileName();
|
||||
return true;
|
||||
}
|
||||
|
||||
void UpdateLogic::reportUpdateResult(const QString& deviceId, const QString& fromVer, const QString& toVer, bool success)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool UpdateLogic::refreshGitTagsFile(const QString& outputPath)
|
||||
{
|
||||
m_error.clear();
|
||||
if (m_serverAddr.isEmpty()) {
|
||||
m_error = QCoreApplication::translate("UpdateLogic", "Server address is empty.");
|
||||
return false;
|
||||
}
|
||||
|
||||
QJsonObject response;
|
||||
int statusCode = 0;
|
||||
QJsonObject body;
|
||||
body["app_id"] = m_appId;
|
||||
body["channel"] = m_channel;
|
||||
m_http.postRequest(m_serverAddr + "/api/v1/git/tags", body,
|
||||
[&](int code, const QJsonObject& resp) {
|
||||
statusCode = code;
|
||||
response = resp;
|
||||
});
|
||||
|
||||
if (statusCode != 200) {
|
||||
const QJsonValue detail = response.value("detail");
|
||||
const QString message = detail.isObject()
|
||||
? detail.toObject().value("msg").toString()
|
||||
: detail.toString();
|
||||
m_error = message.isEmpty()
|
||||
? QCoreApplication::translate("UpdateLogic", "Git tags request failed (HTTP %1).").arg(statusCode)
|
||||
: message;
|
||||
return false;
|
||||
}
|
||||
|
||||
const QString tagsText = response.value("tags_text").toString();
|
||||
if (tagsText.isEmpty()) {
|
||||
m_error = QCoreApplication::translate("UpdateLogic", "Git tags response is empty.");
|
||||
return false;
|
||||
}
|
||||
|
||||
QString writeError;
|
||||
if (!ConfigHelper::writeFileWithElevationIfNeeded(outputPath, tagsText.toUtf8(), &writeError)) {
|
||||
m_error = QCoreApplication::translate("UpdateLogic", "Cannot write Git tags file: %1").arg(writeError);
|
||||
return false;
|
||||
}
|
||||
qDebug() << "Git tags file refreshed:" << outputPath;
|
||||
return true;
|
||||
}
|
||||
|
||||
void UpdateLogic::reportUpdateResult(const QString& deviceId, const QString& fromVer, const QString& toVer, bool success)
|
||||
{
|
||||
QString url = m_serverAddr + "/api/v1/update/report";
|
||||
QJsonObject body;
|
||||
body["app_id"] = m_appId;
|
||||
|
||||
@@ -15,6 +15,7 @@ public:
|
||||
void reportUpdateResult(const QString& deviceId, const QString& fromVer, const QString& toVer, bool success);
|
||||
bool cacheManifest(const QString& appId, const QString& channel, const QString& version,
|
||||
int versionId, const QString& cacheDir);
|
||||
bool refreshGitTagsFile(const QString& outputPath);
|
||||
|
||||
bool getNeedUpdate() const { return m_needUpdate; }
|
||||
QString getLatestVersion() const { return m_latestVer; }
|
||||
|
||||
+21
-5
@@ -251,15 +251,31 @@ int main(int argc, char* argv[])
|
||||
QCoreApplication::translate("Launcher", "A version policy sequence rollback was detected. Startup has been blocked."));
|
||||
return -1;
|
||||
}
|
||||
if (state.isSystemTimeRewound())
|
||||
{
|
||||
progress.close();
|
||||
if (state.isSystemTimeRewound())
|
||||
{
|
||||
progress.close();
|
||||
QMessageBox::critical(nullptr,
|
||||
QCoreApplication::translate("Launcher", "Security Check Failed"),
|
||||
QCoreApplication::translate("Launcher", "A possible system time rollback was detected. Startup has been blocked."));
|
||||
return -1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (networkOk && policy.gitTagsEnabled())
|
||||
{
|
||||
progress.setLabelText(QCoreApplication::translate("Launcher", "Generating Git tag list..."));
|
||||
QApplication::processEvents();
|
||||
const QString tagsPath = QDir(appDir).filePath("tags.txt");
|
||||
if (!logic.refreshGitTagsFile(tagsPath))
|
||||
{
|
||||
progress.close();
|
||||
QMessageBox::warning(nullptr,
|
||||
QCoreApplication::translate("Launcher", "Git Tag List Failed"),
|
||||
QCoreApplication::translate("Launcher", "Cannot generate tags.txt, but startup will continue:\n%1").arg(logic.errorString()));
|
||||
progress.show();
|
||||
QApplication::processEvents();
|
||||
}
|
||||
}
|
||||
|
||||
if (networkOk && needUpdate)
|
||||
{
|
||||
progress.close();
|
||||
|
||||
Reference in New Issue
Block a user