added local updater, minor fixes
tests / package-smoke-linux (push) Skipped
tests / package-smoke-windows (push) Skipped
tests / package-smoke-macos (push) Skipped
tests / macos (push) Successful in 1m24s
tests / windows (pull_request) Skipped
tests / macos (pull_request) Skipped
tests / package-smoke-linux (pull_request) Skipped
tests / package-smoke-windows (pull_request) Skipped
tests / package-smoke-macos (pull_request) Skipped
tests / linux (push) Failing after 1m37s
tests / linux (pull_request) Failing after 1m39s
tests / windows (push) Canceled after 0s

Signed-off-by: galeon <dertiellis@gmail.com>
This commit is contained in:
galeon committed 2026-11-05 21:37:23 +03:00
1 parent 98344a1870
commit d4a17a4561
10 files changed
+777 -31

No files matched your search

+19 -18
View File
@@ -579,8 +579,27 @@ Dialog {
}
Row {
anchors.centerIn: parent
//anchors.right: parent.right //возможно добавить смещение вправо как в сезонах
spacing: 12
Button {
text: Loc.t.common.button.close
width: 120; height: 36
enabled: !buildsDialog.backend.switching
opacity: enabled ? 1.0 : 0.45
contentItem: Text {
text: parent.text
color: "#ffffff"
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
}
background: Rectangle {
color: parent.pressed ? "#444444" : "#333333"
radius: 6
}
onClicked: buildsDialog.close()
}
Button {
text: Loc.t.common.button.install
width: 140; height: 36
@@ -618,24 +637,6 @@ Dialog {
}
onClicked: buildsDialog.backend.activeBuildIndex = buildsDialog.editIndex
}
Button {
text: Loc.t.common.button.close
width: 120; height: 36
enabled: !buildsDialog.backend.switching
opacity: enabled ? 1.0 : 0.45
contentItem: Text {
text: parent.text
color: "#ffffff"
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
}
background: Rectangle {
color: parent.pressed ? "#444444" : "#333333"
radius: 6
}
onClicked: buildsDialog.close()
}
}
}
}
+5 -1
View File
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.20)
project(BiLauncher VERSION 1.0.1 LANGUAGES CXX C)
project(BiLauncher VERSION 1.1.0 LANGUAGES CXX C)
# Канал сборки (dev / rc / релиз) не хранится в репозитории, а вычисляется
# при сборке — см. cmake/LauncherVersion.cmake. CI передаёт полную версию:
@@ -91,6 +91,8 @@ qt_add_qml_module(BiLauncher
localization.cpp
launcherbackend.h
launcherbackend.cpp
launcherupdates.h
launcherupdates.cpp
launcherpaths.h
launcherpaths.cpp
minecraftversion.h
@@ -134,6 +136,7 @@ qt_add_qml_module(BiLauncher
Main.qml
DarkCombo.qml
VersionPickerDialog.qml
LauncherVersionsDialog.qml
JavaPickerDialog.qml
LabelledField.qml
BuildsDialog.qml
@@ -142,6 +145,7 @@ qt_add_qml_module(BiLauncher
ProgressPanel.qml
${LAUNCHER_MSA_QML_FILES}
RESOURCES images/Folder/Folder_Active.svg images/Folder/Folder_Idle.svg images/Folder/Folder_Pressed.svg images/Options/Options_active.svg images/Options/Options_Idle.svg images/Options/Options_Pressed.svg images/Play_Button/Play_Active.svg images/Play_Button/Play_Idle.svg images/Play_Button/Play_pressed.svg images/Profile_Box/Asset_23.jpg images/Profile_Box/Asset_23.svg images/Profile_Box/Asset_24.jpg images/Profile_Box/Asset_24.svg images/Profile_Box/Kishka_Profile_Active.svg images/Profile_Box/Kishka_Profile_Idle.svg images/Profile_Box/Kishka_Profile_open.svg images/Scroll/Scroll_Lever.svg images/Scroll/Scroll_palka.svg images/Version_box/Kishka_Profile_Open.svg images/Version_box/Kishka_Ver_Active.svg images/Version_box/Kishka_Ver_idle.svg images/Trash.svg images/Pencil.svg images/GovuztTW8AAHqBf.jpeg images/photo_2025-12-16_15-04-17.jpg images/photo_2025-12-21_02-30-09.jpg i18n/translations.json
RESOURCES images/ExternalLink.svg
RESOURCES images/launcherBackground.png
RESOURCES images/launcherBackground2static.jpg
RESOURCES CHANGELOG.md
+263
View File
@@ -0,0 +1,263 @@
pragma ComponentBehavior: Bound
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
import BiLauncher
Dialog {
id: picker
required property LauncherUpdates updates
property string channel: "release"
property string selectedVersion: ""
readonly property string state: updates.states[channel] ?? ""
readonly property var entries: updates.catalogs[channel] ?? []
function selectChannel(value) {
channel = value
selectedVersion = ""
if (state !== "ready")
updates.refresh(channel)
}
modal: true
anchors.centerIn: parent
width: Math.min(720, parent.width - 24)
height: Math.min(480, parent.height - 24)
padding: 0
closePolicy: updates.installing ? Popup.NoAutoClose : Popup.CloseOnEscape | Popup.CloseOnPressOutside
onAboutToShow: selectChannel(updates.channel === "rc" ? "rc" : "release")
background: Rectangle {
color: "#1e1e1e"
radius: 10
border.color: "#91B315"
}
header: Item {
implicitHeight: 52
Text {
anchors.centerIn: parent
text: Loc.t.app.label.launcherVersions
color: "#ffffff"
font.pixelSize: 17
font.bold: true
}
Rectangle {
anchors.bottom: parent.bottom
width: parent.width
height: 1
color: "#333333"
}
}
contentItem: RowLayout {
spacing: 0
Column {
Layout.preferredWidth: 160
Layout.fillHeight: true
padding: 8
spacing: 4
enabled: !picker.updates.installing
Repeater {
model: [{ key: "release", title: "Release" }, { key: "rc", title: "Release Candidate" }]
delegate: ItemDelegate {
id: channelButton
required property var modelData
width: 144
height: 34
text: modelData.title
contentItem: Text {
text: channelButton.text
color: "#ffffff"
font.pixelSize: 13
verticalAlignment: Text.AlignVCenter
}
background: Rectangle {
radius: 5
color: picker.channel === channelButton.modelData.key ? "#91B315"
: channelButton.hovered || channelButton.activeFocus ? "#2d2d2d" : "transparent"
}
onClicked: picker.selectChannel(modelData.key)
}
}
}
Rectangle {
Layout.preferredWidth: 1
Layout.fillHeight: true
color: "#333333"
}
ColumnLayout {
Layout.fillWidth: true
Layout.fillHeight: true
Layout.margins: 8
spacing: 6
RowLayout {
Layout.fillWidth: true
Layout.leftMargin: 10
Layout.rightMargin: 10
Label {
Layout.fillWidth: true
text: Loc.t.app.label.versionName
color: "#aaaaaa"
}
Label {
Layout.preferredWidth: 110
text: Loc.t.app.label.releaseDate
color: "#aaaaaa"
}
Label {
Layout.preferredWidth: 100
text: Loc.t.app.label.changes
horizontalAlignment: Text.AlignHCenter
color: "#aaaaaa"
}
}
ListView {
id: versionList
Layout.fillWidth: true
Layout.fillHeight: true
clip: true
spacing: 1
model: picker.entries
enabled: !picker.updates.installing
ScrollBar.vertical: ScrollBar {}
delegate: ItemDelegate {
id: versionRow
required property var modelData
readonly property bool isLatest: picker.channel === picker.updates.channel
&& modelData.version === picker.updates.latest
width: versionList.width
height: 36
horizontalPadding: 10
verticalPadding: 0
hoverEnabled: true
onClicked: picker.selectedVersion = modelData.version
background: Rectangle {
radius: 5
color: picker.selectedVersion === versionRow.modelData.version ? "#364514"
: versionRow.hovered || versionRow.activeFocus ? "#2d2d2d" : "#232323"
}
contentItem: RowLayout {
Text {
Layout.fillWidth: true
text: versionRow.modelData.version
color: versionRow.modelData.download ? "#ffffff" : "#aaaaaa"
font.pixelSize: 13
elide: Text.ElideRight
}
Text {
visible: versionRow.isLatest
text: Loc.t.app.status.newVersion
color: "#b9d84f"
font.pixelSize: 11
}
Text {
Layout.preferredWidth: 110
text: Qt.formatDate(versionRow.modelData.date, Qt.locale().dateFormat(Locale.ShortFormat))
color: "#aaaaaa"
font.pixelSize: 12
}
Item {
Layout.preferredWidth: 100
Layout.preferredHeight: 28
Button {
id: changelogButton
anchors.centerIn: parent
width: 28
height: 28
padding: 0
hoverEnabled: true
flat: true
display: AbstractButton.IconOnly
icon.source: "images/ExternalLink.svg"
icon.width: 16
icon.height: 16
icon.color: "#b9d84f"
Accessible.name: Loc.t.app.hint.openChanges
ToolTip.text: Accessible.name
ToolTip.visible: hovered
onClicked: Qt.openUrlExternally(versionRow.modelData.changelog)
}
}
}
}
Label {
anchors.centerIn: parent
visible: picker.state !== "ready" || versionList.count === 0
text: picker.state === "loading" ? Loc.t.app.status.loadingVersions
: picker.state === "error" ? Loc.t.app.error.versionCatalog
: Loc.t.app.status.noVersions
color: "#aaaaaa"
}
}
}
}
footer: Item {
implicitHeight: 60
Rectangle {
width: parent.width
height: 1
color: "#333333"
}
Row {
anchors.centerIn: parent
spacing: 12
Button {
id: closeButton
width: 130
height: 36
text: Loc.t.common.button.close
enabled: !picker.updates.installing
contentItem: Text {
text: closeButton.text
color: "#ffffff"
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
}
background: Rectangle {
color: closeButton.hovered || closeButton.activeFocus ? "#444444" : "#333333"
radius: 6
}
onClicked: picker.close()
}
Button {
id: installButton
width: 170
height: 36
text: picker.updates.installing ? Loc.t.app.status.downloadingInstaller : Loc.t.common.button.install
enabled: !picker.updates.installing && picker.state === "ready"
&& picker.entries.some(entry => entry.version === picker.selectedVersion && entry.download)
opacity: enabled || picker.updates.installing ? 1 : 0.45
contentItem: Text {
text: installButton.text
color: "#ffffff"
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
}
background: Rectangle {
color: installButton.hovered || installButton.activeFocus ? "#a0c51a" : "#91B315"
radius: 6
}
onClicked: picker.updates.install(picker.channel, picker.selectedVersion)
}
}
}
}
+66 -12
View File
@@ -46,6 +46,19 @@ Window {
}
}
LauncherUpdates {
id: launcherUpdates
Component.onCompleted: refresh(channel)
onInstallationFailed: window.showToast(Loc.t.app.error.launcherInstall, "#cc3333", 8000)
}
LauncherVersionsDialog {
id: launcherVersions
objectName: "launcherVersions"
parent: Overlay.overlay
updates: launcherUpdates
}
function showToast(text, color, timeout) {
toastLabel.text = text
toastBackground.color = color
@@ -86,33 +99,74 @@ Window {
anchors.fill: parent
source: "images/launcherBackground.png"
Text {
Button {
id: launcherVersion
x: 8
y: 8
color: "#ffffff"
height: 30
hoverEnabled: true
enabled: !backend.busy && !backend.gameRunning && !backend.switching && !backend.seasonalInstalling
text: Loc.t.app.label.version.arg(Qt.application.version)
font.pixelSize: 12
horizontalPadding: 8
contentItem: Row {
spacing: 6
Text {
anchors.verticalCenter: parent.verticalCenter
text: launcherVersion.text
color: "#ffffff"
font: launcherVersion.font
}
Rectangle {
id: channelBadge
anchors.verticalCenter: parent.verticalCenter
visible: launcherUpdates.channel === "dev" || launcherUpdates.channel === "rc"
width: channelLabel.implicitWidth + 8
height: channelLabel.implicitHeight + 2
radius: 3
color: launcherUpdates.channel === "rc" ? "#c08a1e" : "#b03a3a"
Text {
id: channelLabel
anchors.centerIn: parent
text: launcherUpdates.channel.toUpperCase()
color: "#ffffff"
font.pixelSize: 10
font.bold: true
}
}
}
background: Rectangle {
opacity: 0.36
color: launcherVersion.pressed || launcherVersions.opened ? "#91B315" : "#000000"
radius: 6
border.color: launcherVersion.hovered || launcherVersion.activeFocus ? "#91B315" : color
}
onClicked: launcherVersions.open()
}
Rectangle {
id: channelBadge
readonly property var channel: /-(dev|rc)/.exec(Qt.application.version)
visible: channel !== null
visible: launcherUpdates.latest !== ""
anchors.left: launcherVersion.right
anchors.leftMargin: 6
anchors.verticalCenter: launcherVersion.verticalCenter
width: channelLabel.implicitWidth + 8
height: channelLabel.implicitHeight + 2
radius: 3
color: channel && channel[1] === "rc" ? "#c08a1e" : "#b03a3a"
width: updateLabel.implicitWidth + 12
height: updateLabel.implicitHeight + 6
radius: 4
color: "#4b631c"
Text {
id: channelLabel
id: updateLabel
anchors.centerIn: parent
text: channelBadge.channel ? channelBadge.channel[1].toUpperCase() : ""
text: Loc.t.app.status.newVersion
color: "#ffffff"
font.pixelSize: 10
font.pixelSize: 11
font.bold: true
}
}
+19
View File
@@ -262,6 +262,25 @@ Dialog {
anchors.verticalCenter: parent.verticalCenter
spacing: 12
Button {
id: closeButton
text: Loc.t.common.button.close
width: 120; height: 36
enabled: !seasons.backend.switching
opacity: enabled ? 1.0 : 0.45
contentItem: Text {
text: parent.text
color: "#ffffff"
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
}
background: Rectangle {
color: parent.pressed ? "#444444" : "#333333"
radius: 6
}
onClicked: seasons.close()
}
Button {
id: refreshButton
width: 150
+44
View File
@@ -31,6 +31,50 @@
}
},
"strings": {
"app.label.launcherVersions": {
"ru": "Версии лаунчера",
"en": "Launcher versions"
},
"app.label.versionName": {
"ru": "Версия",
"en": "Version"
},
"app.label.releaseDate": {
"ru": "Дата выпуска",
"en": "Release date"
},
"app.label.changes": {
"ru": "Изменения",
"en": "Changes"
},
"app.hint.openChanges": {
"ru": "Открыть изменения в браузере",
"en": "Open changes in browser"
},
"app.status.newVersion": {
"ru": "Есть новая версия",
"en": "New version available"
},
"app.status.loadingVersions": {
"ru": "Загрузка списка версий…",
"en": "Loading versions…"
},
"app.status.noVersions": {
"ru": "Нет опубликованных версий",
"en": "No published versions"
},
"app.status.downloadingInstaller": {
"ru": "Скачивание…",
"en": "Downloading…"
},
"app.error.versionCatalog": {
"ru": "Не удалось загрузить список версий",
"en": "Could not load the version list"
},
"app.error.launcherInstall": {
"ru": "Не удалось скачать или установить лаунчер",
"en": "Could not download or install the launcher"
},
"app.label.version": {
"ru": "Версия: %1",
"en": "Version: %1"
+5
View File
@@ -0,0 +1,5 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none"
stroke="#b9d84f" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<path d="M11 5H6a2 2 0 0 0-2 2v11a2 2 0 0 0 2 2h11a2 2 0 0 0 2-2v-5"/>
<path d="M14 4h6v6m0-6-9 9"/>
</svg>

After

Width:  |  Height:  |  Size: 271 B

+279
View File
@@ -0,0 +1,279 @@
#include "launcherupdates.h"
#include "launcherversion.h"
#include <QCoreApplication>
#include <QDateTime>
#include <QDir>
#include <QFile>
#include <QFileInfo>
#include <QJsonArray>
#include <QJsonDocument>
#include <QJsonObject>
#include <QNetworkReply>
#include <QProcess>
#include <QRegularExpression>
#include <QSaveFile>
#include <QUrlQuery>
#include <QVersionNumber>
#include <algorithm>
#ifdef Q_OS_WIN
#include <windows.h>
#include <shellapi.h>
#endif
namespace {
const QString origin = QStringLiteral("https://projects-live.galeonworx.com");
const QString repository = origin + QStringLiteral("/galeon/BiLauncher");
QNetworkRequest request(const QUrl &url)
{
QNetworkRequest result(url);
result.setTransferTimeout(30000);
result.setAttribute(QNetworkRequest::RedirectPolicyAttribute, QNetworkRequest::SameOriginRedirectPolicy);
return result;
}
auto versionKey(const QString &version)
{
qsizetype suffix = 0;
const auto number = QVersionNumber::fromString(version, &suffix);
const int candidate = version.mid(suffix + 3).toInt();
return std::pair(number, candidate);
}
QString assetName(const QString &version)
{
const auto prefix = QStringLiteral("BiLauncher-") + version;
#if defined(Q_OS_WIN)
return prefix + QStringLiteral("-win64-setup.exe");
#elif defined(Q_OS_MACOS)
return prefix + QStringLiteral("-macOS-universal.dmg");
#elif defined(Q_OS_LINUX) && defined(Q_PROCESSOR_X86_64)
return prefix + QStringLiteral("-x86_64.AppImage");
#else
return {};
#endif
}
} // namespace
LauncherUpdates::LauncherUpdates(QObject *parent)
: QObject(parent)
{
}
LauncherUpdates::~LauncherUpdates() = default;
QString LauncherUpdates::channel() const
{
return QStringLiteral(LAUNCHER_CHANNEL);
}
void LauncherUpdates::refresh(const QString &channel)
{
if ((channel != "release" && channel != "rc") || m_states.value(channel) == "loading")
return;
m_states.insert(channel, QStringLiteral("loading"));
emit catalogChanged();
fetchPage(channel, 1, {});
}
void LauncherUpdates::fetchPage(const QString &channel, int page, QVariantList entries)
{
QUrl url(origin + QStringLiteral("/api/v1/repos/galeon/BiLauncher/releases"));
QUrlQuery query;
query.addQueryItem(QStringLiteral("draft"), QStringLiteral("false"));
query.addQueryItem(QStringLiteral("pre-release"), channel == "rc" ? QStringLiteral("true") : QStringLiteral("false"));
query.addQueryItem(QStringLiteral("page"), QString::number(page));
query.addQueryItem(QStringLiteral("limit"), QStringLiteral("50"));
url.setQuery(query);
auto *reply = m_network.get(request(url));
connect(reply, &QNetworkReply::finished, this, [this, reply, channel, page, entries = std::move(entries)]() mutable {
reply->deleteLater();
const auto document = QJsonDocument::fromJson(reply->readAll());
if (reply->error() != QNetworkReply::NoError || !document.isArray()) {
qWarning() << "BiLauncher release catalog:" << reply->errorString();
m_states.insert(channel, QStringLiteral("error"));
emit catalogChanged();
return;
}
const auto releases = document.array();
static const QRegularExpression tagPattern(QStringLiteral("^v([0-9]+\\.[0-9]+\\.[0-9]+)(-rc[0-9]+)?$"));
for (const auto &item : releases) {
const auto release = item.toObject();
const auto tag = release.value("tag_name").toString();
const auto match = tagPattern.match(tag);
const bool candidate = channel == "rc";
const bool candidateTag = !match.captured(2).isEmpty();
if (!match.hasMatch() || release.value("draft").toBool()
|| release.value("prerelease").toBool() != candidate
|| candidateTag != candidate)
continue;
const auto version = tag.mid(1);
const auto name = assetName(version);
const auto expectedUrl = repository + QStringLiteral("/releases/download/") + tag + u'/' + name;
qint64 size = 0;
for (const auto &item : release.value("assets").toArray()) {
const auto asset = item.toObject();
if (!name.isEmpty() && asset.value("name").toString() == name
&& asset.value("browser_download_url").toString() == expectedUrl) {
size = asset.value("size").toInteger();
break;
}
}
entries.append(QVariantMap{
{"version", version},
{"date", QDateTime::fromString(release.value("published_at").toString(), Qt::ISODate)},
{"changelog", repository + QStringLiteral("/src/tag/") + tag + QStringLiteral("/CHANGELOG.md")},
{"download", size > 0 ? expectedUrl : QString()},
{"size", size},
});
}
if (!releases.isEmpty()) {
fetchPage(channel, page + 1, std::move(entries));
return;
}
std::sort(entries.begin(), entries.end(), [](const QVariant &a, const QVariant &b) {
return versionKey(a.toMap().value("version").toString()) > versionKey(b.toMap().value("version").toString());
});
if (channel == this->channel()) {
m_latest.clear();
for (const auto &item : std::as_const(entries)) {
const auto entry = item.toMap();
const auto version = entry.value("version").toString();
if (!entry.value("download").toString().isEmpty()
&& versionKey(version) > versionKey(QStringLiteral(LAUNCHER_VERSION))) {
m_latest = version;
break;
}
}
}
m_catalogs.insert(channel, entries);
m_states.insert(channel, QStringLiteral("ready"));
emit catalogChanged();
});
}
void LauncherUpdates::install(const QString &channel, const QString &version)
{
if (installing())
return;
QVariantMap release;
for (const auto &item : m_catalogs.value(channel).toList()) {
if (item.toMap().value("version") == version) {
release = item.toMap();
break;
}
}
const QUrl url(release.value("download").toString());
if (url.isEmpty()) {
emit installationFailed();
return;
}
m_temp = std::make_unique<QTemporaryDir>();
if (!m_temp->isValid()) {
qWarning() << "BiLauncher update:" << m_temp->errorString();
m_temp.reset();
emit installationFailed();
return;
}
const QString path = m_temp->filePath(url.fileName());
m_download = std::make_unique<QFile>(path);
if (!m_download->open(QIODevice::WriteOnly)) {
qWarning() << "BiLauncher update:" << m_download->errorString();
m_download.reset();
m_temp.reset();
emit installationFailed();
return;
}
const qint64 size = release.value("size").toLongLong();
auto *reply = m_network.get(request(url));
reply->setReadBufferSize(256 * 1024);
const auto writeChunk = [this, reply, size] {
const auto chunk = reply->readAll();
if (m_download->pos() + chunk.size() > size || m_download->write(chunk) != chunk.size()) {
qWarning() << "BiLauncher update: failed to write installer";
return false;
}
return true;
};
connect(reply, &QNetworkReply::readyRead, this, [reply, writeChunk] {
if (!writeChunk())
reply->abort();
});
connect(reply, &QNetworkReply::finished, this, [this, reply, path, size, writeChunk] {
reply->deleteLater();
const bool downloaded = reply->error() == QNetworkReply::NoError
&& writeChunk() && m_download->pos() == size && m_download->flush();
m_download.reset();
if (downloaded && startInstallation(path)) {
#if defined(Q_OS_WIN) || defined(Q_OS_MACOS)
m_temp->setAutoRemove(false);
#endif
m_temp.reset();
QCoreApplication::quit();
return;
}
qWarning() << "BiLauncher update failed:" << path << reply->errorString();
m_temp.reset();
emit installationChanged();
emit installationFailed();
});
emit installationChanged();
}
bool LauncherUpdates::startInstallation(const QString &path)
{
#ifdef Q_OS_WIN
const auto nativePath = QDir::toNativeSeparators(path).toStdWString();
return reinterpret_cast<INT_PTR>(
ShellExecuteW(nullptr, L"open", nativePath.c_str(), nullptr, nullptr, SW_SHOWNORMAL)) > 32;
#elif defined(Q_OS_MACOS)
return QProcess::startDetached(QStringLiteral("/usr/bin/open"), {path});
#elif defined(Q_OS_LINUX)
QString destination = qEnvironmentVariable("APPIMAGE");
if (destination.isEmpty()) {
const QDir home = QDir::home();
if (!home.mkpath(QStringLiteral("Applications")))
return false;
destination = home.filePath(QStringLiteral("Applications/BiLauncher.AppImage"));
} else {
destination = QFileInfo(destination).canonicalFilePath();
if (destination.isEmpty())
return false;
}
QFile source(path);
QSaveFile installed(destination);
if (!source.open(QIODevice::ReadOnly) || !installed.open(QIODevice::WriteOnly)
|| !installed.setPermissions(QFileDevice::ReadOwner | QFileDevice::WriteOwner | QFileDevice::ExeOwner
| QFileDevice::ReadGroup | QFileDevice::ExeGroup
| QFileDevice::ReadOther | QFileDevice::ExeOther))
return false;
while (!source.atEnd()) {
const auto chunk = source.read(256 * 1024);
if (chunk.isEmpty() || installed.write(chunk) != chunk.size())
return false;
}
return installed.commit();
#else
return false;
#endif
}
+49
View File
@@ -0,0 +1,49 @@
#pragma once
#include <QNetworkAccessManager>
#include <QTemporaryDir>
#include <QVariantMap>
#include <QtQml/qqmlregistration.h>
#include <memory>
class QFile;
class LauncherUpdates : public QObject
{
Q_OBJECT
QML_ELEMENT
Q_PROPERTY(QString channel READ channel CONSTANT)
Q_PROPERTY(QVariantMap catalogs READ catalogs NOTIFY catalogChanged)
Q_PROPERTY(QVariantMap states READ states NOTIFY catalogChanged)
Q_PROPERTY(QString latest READ latest NOTIFY catalogChanged)
Q_PROPERTY(bool installing READ installing NOTIFY installationChanged)
public:
explicit LauncherUpdates(QObject *parent = nullptr);
~LauncherUpdates() override;
QString channel() const;
QVariantMap catalogs() const { return m_catalogs; }
QVariantMap states() const { return m_states; }
QString latest() const { return m_latest; }
bool installing() const { return bool(m_download); }
Q_INVOKABLE void refresh(const QString &channel);
Q_INVOKABLE void install(const QString &channel, const QString &version);
signals:
void catalogChanged();
void installationChanged();
void installationFailed();
private:
void fetchPage(const QString &channel, int page, QVariantList entries);
bool startInstallation(const QString &path);
QNetworkAccessManager m_network;
QVariantMap m_catalogs;
QVariantMap m_states;
QString m_latest;
std::unique_ptr<QTemporaryDir> m_temp;
std::unique_ptr<QFile> m_download;
};
+28
View File
@@ -8,9 +8,11 @@
#include "fixtures.h"
#include "launcherpaths.h"
#include "launcherversion.h"
#include "localization.h"
#include <QGuiApplication>
#include <QJSValue>
#include <QQmlApplicationEngine>
#include <QQuickStyle>
#include <QQuickWindow>
@@ -66,6 +68,19 @@ private slots:
// Один движок на весь тест, как в приложении: Localization держит указатель
// на JS-движок, создавший синглтон, и второй QQmlApplicationEngine после
// уничтожения первого оставил бы его висячим.
const QString releasesUrl = QStringLiteral(
"https://projects-live.galeonworx.com/api/v1/repos/galeon/BiLauncher/releases");
const bool candidate = QStringLiteral(LAUNCHER_CHANNEL) == "rc";
const auto release = candidate
? R"([{"tag_name":"v1.0.0-rc1","prerelease":true,"published_at":"2026-10-14T10:52:02Z"}])"
: R"([{"tag_name":"v1.0.0","prerelease":false,"published_at":"2026-10-14T10:52:02Z"}])";
m_net.route(releasesUrl, [candidate, release](const FakeRequest &request) {
const auto query = request.queryItems();
if (query.queryItemValue("pre-release") != (candidate ? "true" : "false"))
return FakeResponse::error(400);
return FakeResponse::json(query.queryItemValue("page") == "1" ? release : "[]");
});
QQmlApplicationEngine engine;
QStringList warnings;
connect(&engine, &QQmlEngine::warnings, this, [&](const QList<QQmlError> &list) {
@@ -83,6 +98,19 @@ private slots:
QVERIFY2(warnings.isEmpty(), qPrintable(warnings.join(u'\n')));
QVERIFY2(g_problems.isEmpty(), qPrintable(g_problems.join(u'\n')));
auto *versions = window->findChild<QObject *>(QStringLiteral("launcherVersions"));
QVERIFY(versions);
QVERIFY(QMetaObject::invokeMethod(versions, "open"));
QTRY_COMPARE(versions->property("state").toString(), QStringLiteral("ready"));
const auto entriesProperty = versions->property("entries");
const auto entries = entriesProperty.metaType() == QMetaType::fromType<QJSValue>()
? entriesProperty.value<QJSValue>().toVariant().toList()
: entriesProperty.toList();
QCOMPARE(entries.size(), 1);
QCOMPARE(entries.first().toMap().value("version").toString(),
candidate ? QStringLiteral("1.0.0-rc1") : QStringLiteral("1.0.0"));
QVERIFY(QMetaObject::invokeMethod(versions, "close"));
// Смена языка на лету перестраивает Loc.t — биндинги не должны ломаться.
const QString titleEn = window->title();
Localization::instance().setLanguage(QStringLiteral("ru"));