2
0
mirror of https://github.com/kotatogram/kotatogram-desktop synced 2025-08-31 06:35:14 +00:00

[Core] Versioning and updater

This commit is contained in:
RadRussianRus
2022-08-16 19:45:15 +03:00
committed by Eric Kotato
parent ce6c49daeb
commit 4a0be1a2ec
23 changed files with 558 additions and 88 deletions

View File

@@ -7,7 +7,11 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#include "core/changelogs.h"
#include "kotato/kotato_lang.h"
#include "kotato/kotato_version.h"
#include "storage/localstorage.h"
#include "lang/lang_keys.h"
#include "lang/lang_instance.h"
#include "core/application.h"
#include "main/main_domain.h"
#include "main/main_session.h"
@@ -45,14 +49,18 @@ std::map<int, const char*> BetaLogs() {
} // namespace
Changelogs::Changelogs(not_null<Main::Session*> session, int oldVersion)
Changelogs::Changelogs(not_null<Main::Session*> session, int oldVersion, int oldKotatoVersion)
: _session(session)
, _oldVersion(oldVersion) {
, _oldVersion(oldVersion)
, _oldKotatoVersion(oldKotatoVersion) {
LOG(("Previous Kotatogram version: %1").arg(_oldKotatoVersion));
_session->data().chatsListChanges(
) | rpl::filter([](Data::Folder *folder) {
return !folder;
}) | rpl::start_with_next([=] {
requestCloudLogs();
addKotatoLogs();
}, _chatsSubscription);
}
@@ -60,12 +68,42 @@ std::unique_ptr<Changelogs> Changelogs::Create(
not_null<Main::Session*> session) {
auto &local = Core::App().domain().local();
const auto oldVersion = local.oldVersion();
const auto oldKotatoVersion = Local::oldKotatoVersion();
local.clearOldVersion();
return (oldVersion > 0 && oldVersion < AppVersion)
? std::make_unique<Changelogs>(session, oldVersion)
return (oldVersion != 0
&& oldKotatoVersion < AppKotatoVersion)
? std::make_unique<Changelogs>(session, oldVersion, oldKotatoVersion)
: nullptr;
}
void Changelogs::addKotatoLogs() {
_chatsSubscription.destroy();
if (_addedSomeLocal) {
return;
}
auto baseLang = Lang::GetInstance().baseId();
auto currentLang = Lang::Id();
QString channelLink;
for (const auto language : { "ru", "uk", "be" }) {
if (baseLang.startsWith(QLatin1String(language)) || currentLang == QString(language)) {
channelLink = "https://t.me/kotatogram_ru";
break;
}
}
if (channelLink.isEmpty()) {
channelLink = "https://t.me/kotatogram";
}
const auto text = ktr("ktg_new_version",
{ "version", QString::fromLatin1(AppKotatoVersionStr) },
{ "td_version", QString::fromLatin1(AppVersionStr) },
{ "link", channelLink });
addLocalLog(text.trimmed());
}
void Changelogs::requestCloudLogs() {
_chatsSubscription.destroy();
@@ -100,7 +138,7 @@ void Changelogs::requestCloudLogs() {
}
void Changelogs::addLocalLogs() {
if (AppBetaVersion || cAlphaVersion()) {
if (AppKotatoBetaVersion || cAlphaVersion()) {
addBetaLogs();
}
if (!_addedSomeLocal) {

View File

@@ -20,12 +20,13 @@ namespace Core {
class Changelogs final : public base::has_weak_ptr {
public:
Changelogs(not_null<Main::Session*> session, int oldVersion);
Changelogs(not_null<Main::Session*> session, int oldVersion, int oldKotatoVersion);
static std::unique_ptr<Changelogs> Create(
not_null<Main::Session*> session);
private:
void addKotatoLogs();
void requestCloudLogs();
void addLocalLogs();
void addLocalLog(const QString &text);
@@ -34,6 +35,7 @@ private:
const not_null<Main::Session*> _session;
const int _oldVersion = 0;
const int _oldKotatoVersion = 0;
rpl::lifetime _chatsSubscription;
bool _addedSomeLocal = false;

View File

@@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#include "core/crash_report_window.h"
#include "kotato/kotato_version.h"
#include "core/crash_reports.h"
#include "core/application.h"
#include "core/sandbox.h"
@@ -333,7 +334,7 @@ LastCrashedWindow::LastCrashedWindow(
}
if (_sendingState != SendingNoReport) {
QString version = getReportField(qstr("version"), qstr("Version:"));
QString current = cAlphaVersion() ? u"-%1"_q.arg(cAlphaVersion()) : QString::number(AppVersion);
QString current = cAlphaVersion() ? u"-%1"_q.arg(cAlphaVersion()) : QString::number(AppKotatoVersion);
if (version != current) { // currently don't accept crash reports from not current app version
_sendingState = SendingNoReport;
}
@@ -502,7 +503,7 @@ QString LastCrashedWindow::getReportField(const QLatin1String &name, const QLati
QString data = lines.at(i).trimmed().mid(prefix.size()).trimmed();
if (name == qstr("version")) {
if (data.endsWith(qstr(" alpha"))) {
if (data.endsWith(qstr(" %1").arg(AppKotatoTestBranch))) {
data = QString::number(-data.replace(QRegularExpression(u"[^\\d]"_q), "").toLongLong());
} else {
data = QString::number(data.replace(QRegularExpression(u"[^\\d]"_q), "").toLongLong());
@@ -714,7 +715,7 @@ void LastCrashedWindow::updateControls() {
if (_sendingState == SendingTooOld || _sendingState == SendingUnofficial) {
QString verStr = getReportField(qstr("version"), qstr("Version:"));
qint64 ver = verStr.isEmpty() ? 0 : verStr.toLongLong();
if (!ver || (ver == AppVersion) || (ver < 0 && (-ver / 1000) == AppVersion)) {
if (!ver || (ver == AppKotatoVersion) || (ver < 0 && (-ver / 1000) == AppKotatoVersion)) {
h += _getApp.height() + padding;
_getApp.show();
h -= _yourReportName.height() + padding; // hide report name

View File

@@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#include "core/crash_reports.h"
#include "kotato/kotato_version.h"
#include "platform/platform_specific.h"
#include "base/platform/base_platform_info.h"
#include "core/launcher.h"
@@ -318,10 +319,10 @@ void StartCatching() {
ProcessAnnotations["Binary"] = cExeName().toUtf8().constData();
ProcessAnnotations["ApiId"] = QString::number(ApiId).toUtf8().constData();
ProcessAnnotations["Version"] = (cAlphaVersion()
? u"%1 alpha"_q.arg(cAlphaVersion())
? u"%1 %2"_q.arg(cAlphaVersion()).arg(AppKotatoTestBranch)
: (AppBetaVersion
? u"%1 beta"_q
: u"%1"_q).arg(AppVersion)).toUtf8().constData();
: u"%1"_q).arg(AppKotatoVersion)).toUtf8().constData();
ProcessAnnotations["Launched"] = QDateTime::currentDateTime().toString("dd.MM.yyyy hh:mm:ss").toUtf8().constData();
ProcessAnnotations["Platform"] = PlatformString().toUtf8().constData();
ProcessAnnotations["UserTag"] = QString::number(Core::Launcher::Instance().installationTag(), 16).toUtf8().constData();

View File

@@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#include "core/launcher.h"
#include "kotato/kotato_version.h"
#include "platform/platform_launcher.h"
#include "platform/platform_specific.h"
#include "base/options.h"
@@ -161,7 +162,7 @@ void ComputeInstallBetaVersions() {
if (f.open(QIODevice::ReadOnly)) {
cSetInstallBetaVersion(f.read(1) != "0");
}
} else if (AppBetaVersion) {
} else if (AppKotatoBetaVersion) {
WriteInstallBetaVersionsSetting();
}
}
@@ -232,10 +233,13 @@ bool CheckPortableVersionFolder() {
const auto portable = cExeDir() + u"TelegramForcePortable"_q;
QFile key(portable + u"/tdata/alpha"_q);
if (cAlphaVersion()) {
/*
Assert(*AlphaPrivateKey != 0);
*/
cForceWorkingDir(portable);
QDir().mkpath(cWorkingDir() + u"tdata"_q);
/*
cSetAlphaPrivateKey(QByteArray(AlphaPrivateKey));
if (!key.open(QIODevice::WriteOnly)) {
LOG(("FATAL: Could not open '%1' for writing private key!"
@@ -245,6 +249,7 @@ bool CheckPortableVersionFolder() {
QDataStream dataStream(&key);
dataStream.setVersion(QDataStream::Qt_5_3);
dataStream << quint64(cRealAlphaVersion()) << cAlphaPrivateKey();
*/
return true;
}
if (!QDir(portable).exists()) {

View File

@@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#include "core/update_checker.h"
#include "kotato/kotato_version.h"
#include "platform/platform_specific.h"
#include "base/platform/base_platform_info.h"
#include "base/platform/base_platform_file_utilities.h"
@@ -309,7 +310,7 @@ bool UnpackUpdate(const QString &filepath) {
RSA *pbKey = [] {
const auto bio = MakeBIO(
const_cast<char*>(
AppBetaVersion
AppKotatoBetaVersion
? UpdatesPublicBetaKey
: UpdatesPublicKey),
-1);
@@ -326,7 +327,7 @@ bool UnpackUpdate(const QString &filepath) {
pbKey = [] {
const auto bio = MakeBIO(
const_cast<char*>(
AppBetaVersion
AppKotatoBetaVersion
? UpdatesPublicKey
: UpdatesPublicBetaKey),
-1);
@@ -427,8 +428,8 @@ bool UnpackUpdate(const QString &filepath) {
LOG(("Update Error: downloaded alpha version %1 is not greater, than mine %2").arg(alphaVersion).arg(cAlphaVersion()));
return false;
}
} else if (int32(version) <= AppVersion) {
LOG(("Update Error: downloaded version %1 is not greater, than mine %2").arg(version).arg(AppVersion));
} else if (int32(version) <= AppKotatoVersion) {
LOG(("Update Error: downloaded version %1 is not greater, than mine %2").arg(version).arg(AppKotatoVersion));
return false;
}
@@ -558,7 +559,7 @@ bool ParseCommonMap(
const auto types = (*it).toObject();
const auto list = [&]() -> std::vector<QString> {
if (cAlphaVersion()) {
return { "alpha", "beta", "stable" };
return { AppKotatoTestBranch };
} else if (cInstallBetaVersion()) {
return { "beta", "stable" };
}
@@ -581,7 +582,7 @@ bool ParseCommonMap(
if (version == map.constEnd()) {
continue;
}
const auto isAvailableAlpha = (type == "alpha");
const auto isAvailableAlpha = (type == AppKotatoTestBranch);
const auto availableVersion = [&] {
if ((*version).isString()) {
const auto string = (*version).toString();
@@ -652,10 +653,8 @@ HttpChecker::HttpChecker(bool testing) : Checker(testing) {
}
void HttpChecker::start() {
const auto updaterVersion = Platform::AutoUpdateVersion();
const auto path = Local::readAutoupdatePrefix()
+ qstr("/current")
+ (updaterVersion > 1 ? QString::number(updaterVersion) : QString());
+ qstr("/current");
auto url = QUrl(path);
DEBUG_LOG(("Update Info: requesting update state"));
const auto request = QNetworkRequest(url);
@@ -777,7 +776,7 @@ QString HttpChecker::validateLatestUrl(
QString url) const {
const auto myVersion = isAvailableAlpha
? cAlphaVersion()
: uint64(AppVersion);
: uint64(AppKotatoVersion);
const auto validVersion = (cAlphaVersion() || !isAvailableAlpha);
if (!validVersion || availableVersion <= myVersion) {
return QString();
@@ -933,9 +932,7 @@ void MtpChecker::start() {
crl::on_main(this, [=] { fail(); });
return;
}
const auto updaterVersion = Platform::AutoUpdateVersion();
const auto feed = "tdhbcfeed"
+ (updaterVersion > 1 ? QString::number(updaterVersion) : QString());
const auto feed = "ktghbcfeed";
MTP::ResolveChannel(&_mtp, feed, [=](
const MTPInputChannel &channel) {
_mtp.send(
@@ -1037,7 +1034,7 @@ auto MtpChecker::parseText(const QByteArray &text) const
auto MtpChecker::validateLatestLocation(
uint64 availableVersion,
const FileLocation &location) const -> FileLocation {
const auto myVersion = uint64(AppVersion);
const auto myVersion = uint64(AppKotatoVersion);
return (availableVersion <= myVersion) ? FileLocation() : location;
}
@@ -1532,17 +1529,17 @@ bool checkReadyUpdate() {
if (versionNum == 0x7FFFFFFF) { // alpha version
quint64 alphaVersion = 0;
if (fVersion.read((char*)&alphaVersion, sizeof(quint64)) != sizeof(quint64)) {
LOG(("Update Error: cant read alpha version from file '%1'").arg(versionPath));
LOG(("Update Error: cant read test version from file '%1'").arg(versionPath));
ClearAll();
return false;
}
if (!cAlphaVersion() || alphaVersion <= cAlphaVersion()) {
LOG(("Update Error: cant install alpha version %1 having alpha version %2").arg(alphaVersion).arg(cAlphaVersion()));
LOG(("Update Error: cant install test version %1 having %2 version %3").arg(alphaVersion).arg(AppKotatoTestBranch).arg(cAlphaVersion()));
ClearAll();
return false;
}
} else if (versionNum <= AppVersion) {
LOG(("Update Error: cant install version %1 having version %2").arg(versionNum).arg(AppVersion));
} else if (versionNum <= AppKotatoVersion) {
LOG(("Update Error: cant install version %1 having version %2").arg(versionNum).arg(AppKotatoVersion));
ClearAll();
return false;
}
@@ -1673,7 +1670,7 @@ void UpdateApplication() {
QString countAlphaVersionSignature(uint64 version) { // duplicated in packer.cpp
if (cAlphaPrivateKey().isEmpty()) {
LOG(("Error: Trying to count alpha version signature without alpha private key!"));
//LOG(("Error: Trying to count alpha version signature without alpha private key!"));
return QString();
}