init
Some checks failed
Docker. / Ubuntu (push) Has been cancelled
User-agent updater. / User-agent (push) Failing after 15s
Lock Threads / lock (push) Failing after 10s
Waiting for answer. / waiting-for-answer (push) Failing after 22s
Close stale issues and PRs / stale (push) Successful in 13s
Needs user action. / needs-user-action (push) Failing after 8s
Can't reproduce. / cant-reproduce (push) Failing after 8s
Some checks failed
Docker. / Ubuntu (push) Has been cancelled
User-agent updater. / User-agent (push) Failing after 15s
Lock Threads / lock (push) Failing after 10s
Waiting for answer. / waiting-for-answer (push) Failing after 22s
Close stale issues and PRs / stale (push) Successful in 13s
Needs user action. / needs-user-action (push) Failing after 8s
Can't reproduce. / cant-reproduce (push) Failing after 8s
This commit is contained in:
55
Telegram/SourceFiles/_other/startup_task_win.cpp
Normal file
55
Telegram/SourceFiles/_other/startup_task_win.cpp
Normal file
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
This file is part of Telegram Desktop,
|
||||
the official desktop application for the Telegram messaging service.
|
||||
|
||||
For license and copyright information please follow this link:
|
||||
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
*/
|
||||
#include <windows.h>
|
||||
#include <shellapi.h>
|
||||
|
||||
#include <array>
|
||||
#include <string>
|
||||
|
||||
using namespace std;
|
||||
|
||||
constexpr auto kMaxPathLong = 32767;
|
||||
|
||||
[[nodiscard]] std::wstring ExecutableDirectory() {
|
||||
auto exePath = std::array<WCHAR, kMaxPathLong + 1>{ 0 };
|
||||
const auto exeLength = GetModuleFileName(
|
||||
nullptr,
|
||||
exePath.data(),
|
||||
kMaxPathLong + 1);
|
||||
if (!exeLength || exeLength >= kMaxPathLong + 1) {
|
||||
return {};
|
||||
}
|
||||
const auto exe = std::wstring(exePath.data());
|
||||
const auto last1 = exe.find_last_of('\\');
|
||||
const auto last2 = exe.find_last_of('/');
|
||||
const auto last = std::max(
|
||||
(last1 == std::wstring::npos) ? -1 : int(last1),
|
||||
(last2 == std::wstring::npos) ? -1 : int(last2));
|
||||
if (last < 0) {
|
||||
return {};
|
||||
}
|
||||
return exe.substr(0, last);
|
||||
}
|
||||
|
||||
int APIENTRY wWinMain(
|
||||
HINSTANCE instance,
|
||||
HINSTANCE prevInstance,
|
||||
LPWSTR cmdParamarg,
|
||||
int cmdShow) {
|
||||
const auto directory = ExecutableDirectory();
|
||||
if (!directory.empty()) {
|
||||
ShellExecute(
|
||||
nullptr,
|
||||
nullptr,
|
||||
(directory + L"\\Telegram.exe").c_str(),
|
||||
L"-autostart",
|
||||
directory.data(),
|
||||
SW_SHOWNORMAL);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user