Fix escaping in scheme creation on Linux and set -workdir

This commit is contained in:
Ilya Fedin 2020-11-15 11:18:23 +04:00 committed by John Preston
parent e64f6f7266
commit c8ce5dfa8b

View file

@ -124,10 +124,12 @@ void PortalAutostart(bool autostart, bool silent = false) {
QVariantMap options; QVariantMap options;
options["reason"] = tr::lng_settings_auto_start(tr::now); options["reason"] = tr::lng_settings_auto_start(tr::now);
options["autostart"] = autostart; options["autostart"] = autostart;
options["commandline"] = QStringList({ options["commandline"] = QStringList{
cExeName(), cExeName(),
qsl("-workdir"),
cWorkingDir(),
qsl("-autostart") qsl("-autostart")
}); };
options["dbus-activatable"] = false; options["dbus-activatable"] = false;
auto message = QDBusMessage::createMethodCall( auto message = QDBusMessage::createMethodCall(
@ -228,6 +230,10 @@ uint FileChooserPortalVersion() {
} }
#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION #endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION
QString EscapeShellInLauncher(const QString &content) {
return EscapeShell(content.toUtf8()).replace('\\', "\\\\");
}
QString FlatpakID() { QString FlatpakID() {
static const auto Result = [] { static const auto Result = [] {
if (!qEnvironmentVariableIsEmpty("FLATPAK_ID")) { if (!qEnvironmentVariableIsEmpty("FLATPAK_ID")) {
@ -291,35 +297,26 @@ bool GenerateDesktopFile(
QFile target(targetFile); QFile target(targetFile);
if (target.open(QIODevice::WriteOnly)) { if (target.open(QIODevice::WriteOnly)) {
if (!Core::UpdaterDisabled()) { fileText = fileText.replace(
fileText = fileText.replace( QRegularExpression(
QRegularExpression( qsl("^TryExec=.*$"),
qsl("^TryExec=.*$"), QRegularExpression::MultilineOption),
QRegularExpression::MultilineOption), qsl("TryExec=%1").arg(
qsl("TryExec=") QString(cExeDir() + cExeName()).replace('\\', "\\\\")));
+ QFile::encodeName(cExeDir() + cExeName())
.replace('\\', "\\\\")); fileText = fileText.replace(
fileText = fileText.replace( QRegularExpression(
QRegularExpression( qsl("^Exec=.*$"),
qsl("^Exec=.*$"), QRegularExpression::MultilineOption),
QRegularExpression::MultilineOption), qsl("Exec=%1 -workdir %2").arg(
qsl("Exec=") EscapeShellInLauncher(cExeDir() + cExeName()),
+ EscapeShell(QFile::encodeName(cExeDir() + cExeName())) EscapeShellInLauncher(cWorkingDir()))
.replace('\\', "\\\\") + (args.isEmpty() ? QString() : ' ' + args));
+ (args.isEmpty() ? QString() : ' ' + args));
} else {
fileText = fileText.replace(
QRegularExpression(
qsl("^Exec=(.*) -- %u$"),
QRegularExpression::MultilineOption),
qsl("Exec=\\1")
+ (args.isEmpty() ? QString() : ' ' + args));
}
target.write(fileText.toUtf8()); target.write(fileText.toUtf8());
target.close(); target.close();
if (IsStaticBinary()) { if (!Core::UpdaterDisabled()) {
DEBUG_LOG(("App Info: removing old .desktop files")); DEBUG_LOG(("App Info: removing old .desktop files"));
QFile::remove(qsl("%1telegram.desktop").arg(targetPath)); QFile::remove(qsl("%1telegram.desktop").arg(targetPath));
QFile::remove(qsl("%1telegramdesktop.desktop").arg(targetPath)); QFile::remove(qsl("%1telegramdesktop.desktop").arg(targetPath));
@ -1217,10 +1214,9 @@ void RegisterCustomScheme(bool force) {
GError *error = nullptr; GError *error = nullptr;
const auto neededCommandlineBuilder = qsl("%1 --") const auto neededCommandlineBuilder = qsl("%1 -workdir %2 --").arg(
.arg(!Core::UpdaterDisabled() QString(EscapeShell(QFile::encodeName(cExeDir() + cExeName()))),
? cExeDir() + cExeName() QString(EscapeShell(QFile::encodeName(cWorkingDir()))));
: cExeName());
const auto neededCommandline = qsl("%1 %u") const auto neededCommandline = qsl("%1 %u")
.arg(neededCommandlineBuilder); .arg(neededCommandlineBuilder);