Use QStandardPaths to find the externalupdater config

That should be more convenient for everyone and cross-platform...
This commit is contained in:
Ilya Fedin 2023-08-15 06:29:46 +04:00 committed by John Preston
parent 7b4a542890
commit 27b443b24d

View file

@ -20,6 +20,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "base/options.h" #include "base/options.h"
#include <QtCore/QLoggingCategory> #include <QtCore/QLoggingCategory>
#include <QtCore/QStandardPaths>
namespace Core { namespace Core {
namespace { namespace {
@ -115,16 +116,26 @@ void ComputeDebugMode() {
} }
void ComputeExternalUpdater() { void ComputeExternalUpdater() {
QFile file(u"/etc/tdesktop/externalupdater"_q); auto locations = QStandardPaths::standardLocations(
QStandardPaths::AppDataLocation);
if (file.exists() && file.open(QIODevice::ReadOnly)) { if (locations.isEmpty()) {
QTextStream fileStream(&file); locations << QString();
while (!fileStream.atEnd()) { }
const auto path = fileStream.readLine(); locations[0] = QDir::cleanPath(cWorkingDir());
locations << QDir::cleanPath(cExeDir());
if (path == (cExeDir() + cExeName())) { for (const auto &location : locations) {
SetUpdaterDisabledAtStartup(); const auto dir = location + u"/externalupdater.d"_q;
return; for (const auto &info : QDir(dir).entryInfoList(QDir::Files)) {
QFile file(info.absoluteFilePath());
if (file.open(QIODevice::ReadOnly)) {
QTextStream fileStream(&file);
while (!fileStream.atEnd()) {
const auto path = fileStream.readLine();
if (path == (cExeDir() + cExeName())) {
SetUpdaterDisabledAtStartup();
return;
}
}
} }
} }
} }