mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-15 21:57:10 +02:00
Don't check dll-s if "SetDefaultDllDirectories" is available.
This commit is contained in:
parent
5b2db4112f
commit
148af59615
6 changed files with 27 additions and 149 deletions
|
@ -1399,6 +1399,13 @@ if ((NOT DESKTOP_APP_DISABLE_AUTOUPDATE OR APPLE) AND NOT build_macstore AND NOT
|
|||
set_target_properties(Updater PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${output_folder})
|
||||
|
||||
if (WIN32)
|
||||
get_filename_component(lib_base_loc lib_base REALPATH)
|
||||
nice_target_sources(Updater ${lib_base_loc}
|
||||
PRIVATE
|
||||
base/platform/win/base_windows_safe_library.cpp
|
||||
base/platform/win/base_windows_safe_library.h
|
||||
)
|
||||
target_include_directories(Updater PRIVATE ${lib_base_loc})
|
||||
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
|
||||
target_link_options(Updater
|
||||
PRIVATE
|
||||
|
|
|
@ -7,69 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
*/
|
||||
#include "updater.h"
|
||||
|
||||
using Handle = HINSTANCE;
|
||||
|
||||
Handle SafeLoadLibrary(const wchar_t *name, bool required = false) {
|
||||
static const auto SystemPath = [] {
|
||||
WCHAR buffer[MAX_PATH + 1] = { 0 };
|
||||
return GetSystemDirectory(buffer, MAX_PATH)
|
||||
? std::wstring(buffer)
|
||||
: std::wstring();
|
||||
}();
|
||||
static const auto WindowsPath = [] {
|
||||
WCHAR buffer[MAX_PATH + 1] = { 0 };
|
||||
return GetWindowsDirectory(buffer, MAX_PATH)
|
||||
? std::wstring(buffer)
|
||||
: std::wstring();
|
||||
}();
|
||||
const auto tryPath = [&](const std::wstring &path) {
|
||||
if (!path.empty()) {
|
||||
const auto full = path + L'\\' + name;
|
||||
if (const auto result = Handle(LoadLibrary(full.c_str()))) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
return Handle();
|
||||
};
|
||||
if (const auto result1 = tryPath(SystemPath)) {
|
||||
return result1;
|
||||
} else if (const auto result2 = tryPath(WindowsPath)) {
|
||||
return result2;
|
||||
} else if (required) {
|
||||
const auto text = L"Could not load required DLL '"
|
||||
+ std::wstring(name)
|
||||
+ L"'!";
|
||||
MessageBox(nullptr, text.c_str(), L"Fatal Error", MB_ICONERROR);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
[[nodiscard]] bool Init() {
|
||||
// Remove the current directory from the DLL search order.
|
||||
SetDllDirectory(L"");
|
||||
|
||||
const auto required = {
|
||||
L"user32.dll",
|
||||
L"advapi32.dll",
|
||||
L"shell32.dll",
|
||||
L"ole32.dll",
|
||||
L"shlwapi.dll",
|
||||
L"propsys.dll",
|
||||
};
|
||||
const auto optional = {
|
||||
L"profapi.dll",
|
||||
L"cryptbase.dll",
|
||||
};
|
||||
for (const auto lib : required) {
|
||||
if (!SafeLoadLibrary(lib, true)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
for (const auto lib : optional) {
|
||||
SafeLoadLibrary(lib);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
#include "base/platform/win/base_windows_safe_library.h"
|
||||
|
||||
bool _debug = false;
|
||||
|
||||
|
@ -393,9 +331,7 @@ void updateRegistry() {
|
|||
}
|
||||
|
||||
int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE prevInstance, LPWSTR cmdParamarg, int cmdShow) {
|
||||
if (!Init()) {
|
||||
return -1;
|
||||
}
|
||||
base::Platform::InitDynamicLibraries();
|
||||
|
||||
openLog();
|
||||
|
||||
|
|
|
@ -75,14 +75,6 @@ bool finished = true;
|
|||
QMargins simpleMargins, margins;
|
||||
HICON bigIcon = 0, smallIcon = 0, overlayIcon = 0;
|
||||
|
||||
class _PsInitializer {
|
||||
public:
|
||||
_PsInitializer() {
|
||||
Dlls::start();
|
||||
}
|
||||
};
|
||||
_PsInitializer _psInitializer;
|
||||
|
||||
BOOL CALLBACK _ActivateProcess(HWND hWnd, LPARAM lParam) {
|
||||
uint64 &processId(*(uint64*)lParam);
|
||||
|
||||
|
@ -104,7 +96,7 @@ BOOL CALLBACK _ActivateProcess(HWND hWnd, LPARAM lParam) {
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace
|
||||
|
||||
void psActivateProcess(uint64 pid) {
|
||||
if (pid) {
|
||||
|
@ -244,7 +236,6 @@ void start() {
|
|||
} // namespace ThirdParty
|
||||
|
||||
void start() {
|
||||
Dlls::init();
|
||||
}
|
||||
|
||||
void finish() {
|
||||
|
|
|
@ -16,72 +16,16 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
|
||||
namespace Platform {
|
||||
namespace Dlls {
|
||||
namespace {
|
||||
|
||||
using base::Platform::SafeLoadLibrary;
|
||||
using base::Platform::LoadMethod;
|
||||
struct SafeIniter {
|
||||
SafeIniter();
|
||||
};
|
||||
|
||||
void init() {
|
||||
static bool inited = false;
|
||||
if (inited) return;
|
||||
inited = true;
|
||||
SafeIniter::SafeIniter() {
|
||||
base::Platform::InitDynamicLibraries();
|
||||
|
||||
base::Platform::CheckDynamicLibraries();
|
||||
|
||||
// Remove the current directory from the DLL search order.
|
||||
SetDllDirectory(L"");
|
||||
|
||||
const auto required = {
|
||||
u"secur32.dll"_q,
|
||||
u"winmm.dll"_q,
|
||||
u"ws2_32.dll"_q,
|
||||
u"user32.dll"_q,
|
||||
u"gdi32.dll"_q,
|
||||
u"advapi32.dll"_q,
|
||||
u"shell32.dll"_q,
|
||||
u"ole32.dll"_q,
|
||||
u"oleaut32.dll"_q,
|
||||
u"shlwapi.dll"_q,
|
||||
u"iphlpapi.dll"_q,
|
||||
u"gdiplus.dll"_q,
|
||||
u"version.dll"_q,
|
||||
u"dwmapi.dll"_q,
|
||||
u"crypt32.dll"_q,
|
||||
u"bcrypt.dll"_q,
|
||||
u"imm32.dll"_q,
|
||||
u"netapi32.dll"_q,
|
||||
u"userenv.dll"_q,
|
||||
u"wtsapi32.dll"_q,
|
||||
u"propsys.dll"_q,
|
||||
u"psapi.dll"_q,
|
||||
u"uxtheme.dll"_q,
|
||||
};
|
||||
const auto optional = {
|
||||
u"dbghelp.dll"_q,
|
||||
u"dbgcore.dll"_q,
|
||||
u"winsta.dll"_q,
|
||||
u"uxtheme.dll"_q,
|
||||
u"igdumdim32.dll"_q,
|
||||
u"amdhdl32.dll"_q,
|
||||
u"combase.dll"_q,
|
||||
u"rstrtmgr.dll"_q,
|
||||
u"d3d9.dll"_q,
|
||||
u"d3d11.dll"_q,
|
||||
u"dxgi.dll"_q,
|
||||
u"profapi.dll"_q,
|
||||
u"cryptbase.dll"_q,
|
||||
};
|
||||
for (const auto &lib : required) {
|
||||
SafeLoadLibrary(lib, true);
|
||||
}
|
||||
for (const auto &lib : optional) {
|
||||
SafeLoadLibrary(lib);
|
||||
}
|
||||
}
|
||||
|
||||
void start() {
|
||||
init();
|
||||
|
||||
const auto LibShell32 = SafeLoadLibrary(u"shell32.dll"_q);
|
||||
const auto LibShell32 = LoadLibrary(L"shell32.dll");
|
||||
LOAD_SYMBOL(LibShell32, SHAssocEnumHandlers);
|
||||
LOAD_SYMBOL(LibShell32, SHCreateItemFromParsingName);
|
||||
LOAD_SYMBOL(LibShell32, SHOpenWithDialog);
|
||||
|
@ -90,7 +34,7 @@ void start() {
|
|||
LOAD_SYMBOL(LibShell32, SHChangeNotify);
|
||||
LOAD_SYMBOL(LibShell32, SetCurrentProcessExplicitAppUserModelID);
|
||||
|
||||
const auto LibUxTheme = SafeLoadLibrary(u"uxtheme.dll"_q);
|
||||
const auto LibUxTheme = LoadLibrary(L"uxtheme.dll");
|
||||
LOAD_SYMBOL(LibUxTheme, SetWindowTheme);
|
||||
//if (IsWindows10OrGreater()) {
|
||||
// static const auto kSystemVersion = QOperatingSystemVersion::current();
|
||||
|
@ -108,24 +52,27 @@ void start() {
|
|||
// }
|
||||
//}
|
||||
|
||||
const auto LibWtsApi32 = SafeLoadLibrary(u"wtsapi32.dll"_q);
|
||||
const auto LibWtsApi32 = LoadLibrary(L"wtsapi32.dll");
|
||||
LOAD_SYMBOL(LibWtsApi32, WTSRegisterSessionNotification);
|
||||
LOAD_SYMBOL(LibWtsApi32, WTSUnRegisterSessionNotification);
|
||||
|
||||
const auto LibPropSys = SafeLoadLibrary(u"propsys.dll"_q);
|
||||
const auto LibPropSys = LoadLibrary(L"propsys.dll");
|
||||
LOAD_SYMBOL(LibPropSys, PropVariantToString);
|
||||
LOAD_SYMBOL(LibPropSys, PSStringFromPropertyKey);
|
||||
|
||||
const auto LibDwmApi = SafeLoadLibrary(u"dwmapi.dll"_q);
|
||||
const auto LibDwmApi = LoadLibrary(L"dwmapi.dll");
|
||||
LOAD_SYMBOL(LibDwmApi, DwmIsCompositionEnabled);
|
||||
LOAD_SYMBOL(LibDwmApi, DwmSetWindowAttribute);
|
||||
|
||||
const auto LibPsApi = SafeLoadLibrary(u"psapi.dll"_q);
|
||||
const auto LibPsApi = LoadLibrary(L"psapi.dll");
|
||||
LOAD_SYMBOL(LibPsApi, GetProcessMemoryInfo);
|
||||
|
||||
const auto LibUser32 = SafeLoadLibrary(u"user32.dll"_q);
|
||||
const auto LibUser32 = LoadLibrary(L"user32.dll");
|
||||
LOAD_SYMBOL(LibUser32, SetWindowCompositionAttribute);
|
||||
}
|
||||
|
||||
SafeIniter kSafeIniter;
|
||||
|
||||
} // namespace
|
||||
} // namespace Dlls
|
||||
} // namespace Platform
|
||||
|
|
|
@ -22,9 +22,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
namespace Platform {
|
||||
namespace Dlls {
|
||||
|
||||
void init();
|
||||
void start();
|
||||
|
||||
// UXTHEME.DLL
|
||||
inline HRESULT(__stdcall *SetWindowTheme)(
|
||||
HWND hWnd,
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 9255d7103857395e91c2e546edbf8eaed86da4ca
|
||||
Subproject commit 7577f063a6c6075dcee5556de9e1f96d07b2a12d
|
Loading…
Add table
Reference in a new issue