Read autoupdate prefix from config.

This commit is contained in:
John Preston 2018-05-03 09:39:10 +03:00
parent 62c812858e
commit ad1f089802
5 changed files with 63 additions and 7 deletions

View file

@ -712,8 +712,8 @@ sendMediaFileThumbSkip: 10px;
sendMediaFileNameTop: 7px;
sendMediaFileStatusTop: 37px;
proxyUsePadding: margins(22px, 0px, 22px, 12px);
proxyTryIPv6Padding: margins(22px, 12px, 22px, 0px);
proxyUsePadding: margins(22px, 8px, 22px, 12px);
proxyTryIPv6Padding: margins(22px, 12px, 22px, 8px);
proxyRowPadding: margins(22px, 8px, 8px, 8px);
proxyRowIconSkip: 32px;
proxyRowSkip: 2px;

View file

@ -31,7 +31,6 @@ namespace {
constexpr auto kCheckTimeout = TimeMs(10000);
constexpr auto kMaxResponseSize = 1024 * 1024;
const auto kUpdateUrl = "http://updates.tdesktop.com";
#ifdef Q_OS_WIN
using VersionInt = DWORD;
@ -397,7 +396,7 @@ bool Updater::checkResponse(const QByteArray &response) {
startDownloadThread(
bestAvailableVersion,
bestIsAvailableBeta,
kUpdateUrl + bestLink);
Local::readAutoupdatePrefix() + bestLink);
return true;
}
@ -515,7 +514,7 @@ void Updater::start(bool forceWait) {
if (sendRequest) {
clearSentRequest();
auto url = QUrl(kUpdateUrl + QString("/current"));
auto url = QUrl(Local::readAutoupdatePrefix() + qstr("/current"));
DEBUG_LOG(("Update Info: requesting update state from '%1'"
).arg(url.toDisplayString()));
const auto request = QNetworkRequest(url);

View file

@ -620,7 +620,7 @@ void Instance::Private::configLoadDone(const MTPConfig &result) {
_configLoader.reset();
_lastConfigLoadedTime = getms(true);
auto &data = result.c_config();
const auto &data = result.c_config();
DEBUG_LOG(("MTP Info: got config, chat_size_max: %1, date: %2, test_mode: %3, this_dc: %4, dc_options.length: %5").arg(data.vchat_size_max.v).arg(data.vdate.v).arg(mtpIsTrue(data.vtest_mode)).arg(data.vthis_dc.v).arg(data.vdc_options.v.size()));
if (data.vdc_options.v.empty()) {
LOG(("MTP Error: config with empty dc_options received!"));
@ -659,8 +659,14 @@ void Instance::Private::configLoadDone(const MTPConfig &result) {
}
Global::SetBlockedMode(data.is_blocked_mode());
Lang::CurrentCloudManager().setSuggestedLanguage(data.has_suggested_lang_code() ? qs(data.vsuggested_lang_code) : QString());
const auto lang = data.has_suggested_lang_code()
? qs(data.vsuggested_lang_code)
: QString();
Lang::CurrentCloudManager().setSuggestedLanguage(lang);
if (data.has_autoupdate_url_prefix()) {
Local::writeAutoupdatePrefix(qs(data.vautoupdate_url_prefix));
}
Local::writeSettings();
_configExpiresAt = getms(true)

View file

@ -2517,6 +2517,54 @@ void writeMtpData() {
_writeMtpData();
}
const QString &AutoupdatePrefix(const QString &replaceWith = {}) {
static auto value = QString();
if (!replaceWith.isEmpty()) {
value = replaceWith;
}
return value;
}
QString autoupdatePrefixFile() {
return cWorkingDir() + "tdata/prefix";
}
const QString &readAutoupdatePrefixRaw() {
const auto &result = AutoupdatePrefix();
if (!result.isEmpty()) {
return result;
}
QFile f(autoupdatePrefixFile());
if (f.open(QIODevice::ReadOnly)) {
const auto value = QString::fromUtf8(f.readAll());
if (!value.isEmpty()) {
return AutoupdatePrefix(value);
}
}
return AutoupdatePrefix("http://updates.tdesktop.com");
}
void writeAutoupdatePrefix(const QString &prefix) {
const auto current = readAutoupdatePrefixRaw();
if (current != prefix) {
AutoupdatePrefix(prefix);
QFile f(autoupdatePrefixFile());
if (f.open(QIODevice::WriteOnly)) {
f.write(prefix.toUtf8());
f.close();
}
if (cAutoUpdate()) {
Core::UpdateChecker checker;
checker.start();
}
}
}
QString readAutoupdatePrefix() {
auto result = readAutoupdatePrefixRaw();
return result.replace(QRegularExpression("/+$"), QString());
}
void reset() {
if (_localLoader) {
_localLoader->stop();

View file

@ -27,6 +27,9 @@ void writeSettings();
void writeUserSettings();
void writeMtpData();
void writeAutoupdatePrefix(const QString &prefix);
QString readAutoupdatePrefix();
void reset();
bool checkPasscode(const QByteArray &passcode);