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

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

@@ -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();