Preparing autoupdater

This commit is contained in:
Eric Kotato 2019-09-27 15:33:25 +03:00
parent b19ea0c1e8
commit 082377500d
5 changed files with 47 additions and 40 deletions

View file

@ -19,17 +19,19 @@ bool OnlyAlphaKey = false;
const char *PublicKey = "\
-----BEGIN RSA PUBLIC KEY-----\n\
MIGJAoGBAMA4ViQrjkPZ9xj0lrer3r23JvxOnrtE8nI69XLGSr+sRERz9YnUptnU\n\
BZpkIfKaRcl6XzNJiN28cVwO1Ui5JSa814UAiDHzWUqCaXUiUEQ6NmNTneiGx2sQ\n\
+9PKKlb8mmr3BB9A45ZNwLT6G9AK3+qkZLHojeSA+m84/a6GP4svAgMBAAE=\n\
AAAAB3NzaC1yc2EAAAADAQABAAAAgQC1BIvDUH3Kvxk6A+QnYHTYYI9mrdp7rKFr\n\
B7lHSDhhDnoabdj4kJc7fqs4iiQzvPrT50FdDc6ulKmVwNHgk+Arz9o2ci6v8Zzc\n\
5Yp0F0/sD7tsKgWm0U36AkyIi7HhY79sxLFwgpIYmlHwLVN8NPcsNPw/L5df+fjf\n\
+JqQInPtFQ==\n\
-----END RSA PUBLIC KEY-----\
";
const char *PublicBetaKey = "\
-----BEGIN RSA PUBLIC KEY-----\n\
MIGJAoGBALWu9GGs0HED7KG7BM73CFZ6o0xufKBRQsdnq3lwA8nFQEvmdu+g/I1j\n\
0LQ+0IQO7GW4jAgzF/4+soPDb6uHQeNFrlVx1JS9DZGhhjZ5rf65yg11nTCIHZCG\n\
w/CVnbwQOw0g5GBwwFV3r0uTTvy44xx8XXxk+Qknu4eBCsmrAFNnAgMBAAE=\n\
AAAAB3NzaC1yc2EAAAADAQABAAAAgQD4IzJFh7MZNXeDXDwuY8j5RHXbznZd8h/r\n\
PMaZvDMQlcIVruXWs5AtGb9f9FJ5HoDuIzZEmN8nA6p/k9zY8TcZy9BLCoezI4p8\n\
jFHt2SEs2iMq3av/L+G7wf2dV+UbsNh2nKFqPxFbF2Pcwk62OdyEaysuB0GwjpaC\n\
tvkwYpsl+Q==\n\
-----END RSA PUBLIC KEY-----\
";

View file

@ -202,7 +202,7 @@ bool update() {
writeLog(L"Error: bad update, has Updater.exe! '" + tofname + L"' equal '" + updaterName + L"'");
delFolder();
return false;
} else if (equal(tofname, updateTo + L"Telegram.exe") && exeName != L"Telegram.exe") {
} else if (equal(tofname, updateTo + L"Kotatogram.exe") && exeName != L"Kotatogram.exe") {
wstring fullBinaryPath = updateTo + exeName;
writeLog(L"Target binary found: '" + tofname + L"', changing to '" + fullBinaryPath + L"'");
tofname = fullBinaryPath;
@ -259,7 +259,7 @@ bool update() {
if (!copyResult) {
writeLog(L"Error: failed to copy, asking to retry..");
WCHAR errMsg[2048];
wsprintf(errMsg, L"Failed to update Telegram :(\n%s is not accessible.", tofname.c_str());
wsprintf(errMsg, L"Failed to update Kotatogram :(\n%s is not accessible.", tofname.c_str());
if (MessageBox(0, errMsg, L"Update error!", MB_ICONERROR | MB_RETRYCANCEL) != IDRETRY) {
delFolder();
return false;
@ -305,16 +305,16 @@ void updateRegistry() {
SYSTEMTIME stLocalTime;
GetLocalTime(&stLocalTime);
RegSetValueEx(rkey, L"DisplayVersion", 0, REG_SZ, (const BYTE*)versionStr, ((versionLen / 2) + 1) * sizeof(WCHAR));
wsprintf(nameStr, L"Telegram Desktop version %s", versionStr);
wsprintf(nameStr, L"Kotatogram Desktop version %s", versionStr);
RegSetValueEx(rkey, L"DisplayName", 0, REG_SZ, (const BYTE*)nameStr, (wcslen(nameStr) + 1) * sizeof(WCHAR));
wsprintf(publisherStr, L"Telegram FZ-LLC");
wsprintf(publisherStr, L"Kotatogram");
RegSetValueEx(rkey, L"Publisher", 0, REG_SZ, (const BYTE*)publisherStr, (wcslen(publisherStr) + 1) * sizeof(WCHAR));
wsprintf(icongroupStr, L"Telegram Desktop");
wsprintf(icongroupStr, L"Kotatogram Desktop");
RegSetValueEx(rkey, L"Inno Setup: Icon Group", 0, REG_SZ, (const BYTE*)icongroupStr, (wcslen(icongroupStr) + 1) * sizeof(WCHAR));
wsprintf(dateStr, L"%04d%02d%02d", stLocalTime.wYear, stLocalTime.wMonth, stLocalTime.wDay);
RegSetValueEx(rkey, L"InstallDate", 0, REG_SZ, (const BYTE*)dateStr, (wcslen(dateStr) + 1) * sizeof(WCHAR));
const WCHAR *appURL = L"https://desktop.telegram.org";
const WCHAR *appURL = L"https://t.me/kotatogram";
RegSetValueEx(rkey, L"HelpLink", 0, REG_SZ, (const BYTE*)appURL, (wcslen(appURL) + 1) * sizeof(WCHAR));
RegSetValueEx(rkey, L"URLInfoAbout", 0, REG_SZ, (const BYTE*)appURL, (wcslen(appURL) + 1) * sizeof(WCHAR));
RegSetValueEx(rkey, L"URLUpdateInfo", 0, REG_SZ, (const BYTE*)appURL, (wcslen(appURL) + 1) * sizeof(WCHAR));
@ -377,14 +377,14 @@ int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE prevInstance, LPWSTR cmdPara
exeName = args[i];
for (int j = 0, l = exeName.size(); j < l; ++j) {
if (exeName[j] == L'/' || exeName[j] == L'\\') {
exeName = L"Telegram.exe";
exeName = L"Kotatogram.exe";
break;
}
}
}
}
if (exeName.empty()) {
exeName = L"Telegram.exe";
exeName = L"Kotatogram.exe";
}
if (needupdate) writeLog(L"Need to update!");
if (autostart) writeLog(L"From autostart!");
@ -493,7 +493,7 @@ int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE prevInstance, LPWSTR cmdPara
return 0;
}
static const WCHAR *_programName = L"Telegram Desktop"; // folder in APPDATA, if current path is unavailable for writing
static const WCHAR *_programName = L"Kotatogram Desktop"; // folder in APPDATA, if current path is unavailable for writing
static const WCHAR *_exeName = L"Updater.exe";
LPTOP_LEVEL_EXCEPTION_FILTER _oldWndExceptionFilter = 0;

View file

@ -140,11 +140,12 @@ QString telegramFaqLink() {
}
QString currentVersionText() {
auto result = QString::fromLatin1(AppVersionStr);
auto result = QString::fromLatin1(AppKotatoVersionStr);
if (cAlphaVersion()) {
result += qsl(" alpha %1").arg(cAlphaVersion() % 1000);
} else if (AppBetaVersion) {
result += " beta";
}
result += qsl(" (TDesktop %1)").arg(AppVersionStr);
return result;
}

View file

@ -385,8 +385,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;
}
@ -732,7 +732,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();
@ -887,7 +887,7 @@ void MtpChecker::start() {
return;
}
const auto updaterVersion = Platform::AutoUpdateVersion();
const auto feed = "tdhbcfeed"
const auto feed = "ktghbcfeed"
+ (updaterVersion > 1 ? QString::number(updaterVersion) : QString());
MTP::ResolveChannel(&_mtp, feed, [=](const MTPInputChannel &channel) {
_mtp.send(
@ -989,7 +989,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;
}
@ -1072,7 +1072,7 @@ private:
rpl::event_stream<Progress> _progress;
rpl::event_stream<> _failed;
rpl::event_stream<> _ready;
Implementation _httpImplementation;
//Implementation _httpImplementation;
Implementation _mtpImplementation;
std::shared_ptr<Loader> _activeLoader;
bool _usingMtprotoLoader = (cAlphaVersion() != 0);
@ -1183,7 +1183,7 @@ int Updater::already() const {
}
void Updater::stop() {
_httpImplementation = Implementation();
//_httpImplementation = Implementation();
_mtpImplementation = Implementation();
_activeLoader = nullptr;
_action = Action::Waiting;
@ -1219,9 +1219,9 @@ void Updater::start(bool forceWait) {
}
if (sendRequest) {
startImplementation(
&_httpImplementation,
std::make_unique<HttpChecker>(_testing));
// startImplementation(
// &_httpImplementation,
// std::make_unique<HttpChecker>(_testing));
startImplementation(
&_mtpImplementation,
std::make_unique<MtpChecker>(_mtproto, _testing));
@ -1298,7 +1298,7 @@ void Updater::handleTimeout() {
which.failed = true;
}
};
reset(_httpImplementation);
//reset(_httpImplementation);
reset(_mtpImplementation);
if (!tryLoaders()) {
cSetLastUpdateCheck(0);
@ -1310,7 +1310,8 @@ void Updater::handleTimeout() {
}
bool Updater::tryLoaders() {
if (_httpImplementation.checker || _mtpImplementation.checker) {
//if (_httpImplementation.checker || _mtpImplementation.checker) {
if (_mtpImplementation.checker) {
// Some checkers didn't finish yet.
return true;
}
@ -1339,18 +1340,19 @@ bool Updater::tryLoaders() {
_isLatest.fire({});
}
};
if (_mtpImplementation.failed && _httpImplementation.failed) {
//if (_mtpImplementation.failed && _httpImplementation.failed) {
if (_mtpImplementation.failed) {
_failed.fire({});
return false;
} else if (!_mtpImplementation.loader) {
tryOne(_httpImplementation);
} else if (!_httpImplementation.loader) {
tryOne(_mtpImplementation);
} else {
tryOne(_usingMtprotoLoader
? _mtpImplementation
: _httpImplementation);
_usingMtprotoLoader = !_usingMtprotoLoader;
// } else if (!_mtpImplementation.loader) {
// tryOne(_httpImplementation);
// } else if (!_httpImplementation.loader) {
// tryOne(_mtpImplementation);
// } else {
// tryOne(_usingMtprotoLoader
// ? _mtpImplementation
// : _httpImplementation);
// _usingMtprotoLoader = !_usingMtprotoLoader;
}
return true;
}
@ -1493,8 +1495,8 @@ bool checkReadyUpdate() {
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;
}

View file

@ -19,3 +19,5 @@ constexpr auto AppVersion = 1008009;
constexpr auto AppVersionStr = "1.8.9";
constexpr auto AppBetaVersion = false;
constexpr auto AppAlphaVersion = TDESKTOP_ALPHA_VERSION;
constexpr auto AppKotatoVersion = 1000000;
constexpr auto AppKotatoVersionStr = "1.0";