diff options
author | George Hazan <ghazan@miranda.im> | 2022-12-20 13:55:24 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2022-12-20 13:55:24 +0300 |
commit | 8fbc9220b7f3d3a04bbe45d32489ef882821558e (patch) | |
tree | ac22e8d62a5179c4c8573b449968abd9976cd197 /protocols | |
parent | d78fdd24a3f26f928a55f527e0bfbfc5fa069d55 (diff) |
tdlib: more XP compatibility + fix for old Windows SDK versions
Diffstat (limited to 'protocols')
-rw-r--r-- | protocols/Telegram/tdlib/td/tdutils/td/utils/port/FromApp.h | 63 |
1 files changed, 5 insertions, 58 deletions
diff --git a/protocols/Telegram/tdlib/td/tdutils/td/utils/port/FromApp.h b/protocols/Telegram/tdlib/td/tdutils/td/utils/port/FromApp.h index 5b74cc8ba6..ca1f6b5c8f 100644 --- a/protocols/Telegram/tdlib/td/tdutils/td/utils/port/FromApp.h +++ b/protocols/Telegram/tdlib/td/tdutils/td/utils/port/FromApp.h @@ -12,80 +12,27 @@ namespace td { -#if !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP | WINAPI_PARTITION_SYSTEM) -inline HMODULE GetKernelModule() { - static const auto kernel_module = []() -> HMODULE { - MEMORY_BASIC_INFORMATION mbi; - if (VirtualQuery(VirtualQuery, &mbi, sizeof(MEMORY_BASIC_INFORMATION))) { - return reinterpret_cast<HMODULE>(mbi.AllocationBase); - } - return nullptr; - }(); - return kernel_module; -} - -inline HMODULE LoadLibrary(LPCTSTR lpFileName) { - using pLoadLibrary = HMODULE(WINAPI *)(_In_ LPCTSTR); - static const auto proc_load_library = - reinterpret_cast<pLoadLibrary>(GetProcAddress(GetKernelModule(), "LoadLibraryW")); - return proc_load_library(lpFileName); -} - -inline HMODULE GetFromAppModule() { - static const HMODULE from_app_module = LoadLibrary(L"api-ms-win-core-file-fromapp-l1-1-0.dll"); - return from_app_module; -} -#endif - -template <int num, class T> -T *get_from_app_function(const char *name, T *original_func) { -#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP | WINAPI_PARTITION_SYSTEM) - return original_func; -#else - static T *func = [name, original_func]() -> T * { - auto func_pointer = GetProcAddress(GetFromAppModule(), name); - if (func_pointer == nullptr) { - return original_func; - } - return reinterpret_cast<T *>(func_pointer); - }(); - return func; -#endif -} - inline BOOL CreateDirectoryFromAppW(_In_ LPCWSTR lpPathName, _In_opt_ LPSECURITY_ATTRIBUTES lpSecurityAttributes) { - auto func = get_from_app_function<1>("CreateDirectoryFromAppW", &CreateDirectory); - return func(lpPathName, lpSecurityAttributes); + return CreateDirectoryW(lpPathName, lpSecurityAttributes); } inline BOOL RemoveDirectoryFromAppW(_In_ LPCWSTR lpPathName) { - auto func = get_from_app_function<2>("RemoveDirectoryFromAppW", &RemoveDirectory); - return func(lpPathName); + return RemoveDirectoryW(lpPathName); } inline BOOL DeleteFileFromAppW(_In_ LPCWSTR lpFileName) { - auto func = get_from_app_function<3>("DeleteFileFromAppW", &DeleteFile); - return func(lpFileName); + return DeleteFileW(lpFileName); } inline BOOL MoveFileExFromAppW(_In_ LPCWSTR lpExistingFileName, _In_ LPCWSTR lpNewFileName, _In_ DWORD dwFlags) { - auto func = get_from_app_function<4>("MoveFileFromAppW", static_cast<BOOL(WINAPI *)(LPCWSTR, LPCWSTR)>(nullptr)); - if (func == nullptr || (dwFlags & ~MOVEFILE_REPLACE_EXISTING) != 0) { - // if can't find MoveFileFromAppW or have unsupported flags, call MoveFileEx directly - return MoveFileEx(lpExistingFileName, lpNewFileName, dwFlags); - } - if ((dwFlags & MOVEFILE_REPLACE_EXISTING) != 0) { - td::DeleteFileFromAppW(lpNewFileName); - } - return func(lpExistingFileName, lpNewFileName); + return MoveFileEx(lpExistingFileName, lpNewFileName, dwFlags); } inline HANDLE FindFirstFileExFromAppW(_In_ LPCWSTR lpFileName, _In_ FINDEX_INFO_LEVELS fInfoLevelId, _Out_writes_bytes_(sizeof(WIN32_FIND_DATAW)) LPVOID lpFindFileData, _In_ FINDEX_SEARCH_OPS fSearchOp, _Reserved_ LPVOID lpSearchFilter, _In_ DWORD dwAdditionalFlags) { - auto func = get_from_app_function<5>("FindFirstFileExFromAppW", &FindFirstFileEx); - return func(lpFileName, fInfoLevelId, lpFindFileData, fSearchOp, lpSearchFilter, dwAdditionalFlags); + return FindFirstFileEx(lpFileName, fInfoLevelId, lpFindFileData, fSearchOp, lpSearchFilter, dwAdditionalFlags); } } // namespace td |