mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-01-31 04:06:13 +00:00
Parse command line natively on Windows.
Use CommandLineToArgvW() so that unicode arguments are preserved. This will fix path arguments with unicode symbols in them.
This commit is contained in:
parent
251176df47
commit
e998bd0b3f
@ -26,20 +26,6 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
||||
#include "application.h"
|
||||
|
||||
namespace Core {
|
||||
namespace {
|
||||
|
||||
QStringList ReadArguments(int argc, char *argv[]) {
|
||||
Expects(argc >= 0);
|
||||
|
||||
auto result = QStringList();
|
||||
result.reserve(argc);
|
||||
for (auto i = 0; i != argc; ++i) {
|
||||
result.push_back(fromUtf8Safe(argv[i]));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
std::unique_ptr<Launcher> Launcher::Create(int argc, char *argv[]) {
|
||||
return std::make_unique<Platform::Launcher>(argc, argv);
|
||||
@ -47,12 +33,14 @@ std::unique_ptr<Launcher> Launcher::Create(int argc, char *argv[]) {
|
||||
|
||||
Launcher::Launcher(int argc, char *argv[])
|
||||
: _argc(argc)
|
||||
, _argv(argv)
|
||||
, _arguments(ReadArguments(argc, argv)) {
|
||||
prepareSettings();
|
||||
, _argv(argv) {
|
||||
}
|
||||
|
||||
void Launcher::init() {
|
||||
_arguments = readArguments(_argc, _argv);
|
||||
|
||||
prepareSettings();
|
||||
|
||||
QCoreApplication::setApplicationName(qsl("TelegramDesktop"));
|
||||
|
||||
#ifndef OS_MAC_OLD
|
||||
@ -103,6 +91,21 @@ int Launcher::exec() {
|
||||
return result;
|
||||
}
|
||||
|
||||
QStringList Launcher::readArguments(int argc, char *argv[]) const {
|
||||
Expects(argc >= 0);
|
||||
|
||||
if (const auto native = readArgumentsHook(argc, argv)) {
|
||||
return *native;
|
||||
}
|
||||
|
||||
auto result = QStringList();
|
||||
result.reserve(argc);
|
||||
for (auto i = 0; i != argc; ++i) {
|
||||
result.push_back(fromUtf8Safe(argv[i]));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
QString Launcher::argumentsString() const {
|
||||
return _arguments.join(' ');
|
||||
}
|
||||
|
@ -45,12 +45,20 @@ private:
|
||||
void prepareSettings();
|
||||
void processArguments();
|
||||
|
||||
QStringList readArguments(int argc, char *argv[]) const;
|
||||
virtual base::optional<QStringList> readArgumentsHook(
|
||||
int argc,
|
||||
char *argv[]) const {
|
||||
return base::none;
|
||||
}
|
||||
|
||||
void init();
|
||||
virtual void initHook() {
|
||||
}
|
||||
|
||||
virtual bool launchUpdater(UpdaterLaunch action) = 0;
|
||||
|
||||
|
||||
int _argc;
|
||||
char **_argv;
|
||||
QStringList _arguments;
|
||||
|
@ -23,10 +23,29 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
||||
#include "core/crash_reports.h"
|
||||
#include "platform/platform_specific.h"
|
||||
|
||||
#include <windows.h>
|
||||
#include <shellapi.h>
|
||||
|
||||
namespace Platform {
|
||||
|
||||
base::optional<QStringList> Launcher::readArgumentsHook(
|
||||
int argc,
|
||||
char *argv[]) const {
|
||||
auto count = 0;
|
||||
if (const auto list = CommandLineToArgvW(GetCommandLine(), &count)) {
|
||||
const auto guard = gsl::finally([&] { LocalFree(list); });
|
||||
if (count > 0) {
|
||||
auto result = QStringList();
|
||||
result.reserve(count);
|
||||
for (auto i = 0; i != count; ++i) {
|
||||
result.push_back(QString::fromWCharArray(list[i]));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
return base::none;
|
||||
}
|
||||
|
||||
bool Launcher::launchUpdater(UpdaterLaunch action) {
|
||||
if (cExeName().isEmpty()) {
|
||||
return false;
|
||||
|
@ -29,6 +29,10 @@ public:
|
||||
using Core::Launcher::Launcher;
|
||||
|
||||
private:
|
||||
base::optional<QStringList> readArgumentsHook(
|
||||
int argc,
|
||||
char *argv[]) const override;
|
||||
|
||||
bool launchUpdater(UpdaterLaunch action) override;
|
||||
|
||||
bool launch(
|
||||
|
Loading…
Reference in New Issue
Block a user