diff --git a/Telegram/SourceFiles/platform/win/specific_win.cpp b/Telegram/SourceFiles/platform/win/specific_win.cpp index b94a114c9..1c81313de 100644 --- a/Telegram/SourceFiles/platform/win/specific_win.cpp +++ b/Telegram/SourceFiles/platform/win/specific_win.cpp @@ -96,6 +96,50 @@ BOOL CALLBACK _ActivateProcess(HWND hWnd, LPARAM lParam) { return TRUE; } +void DeleteMyModules() { + constexpr auto kMaxPathLong = 32767; + auto exePath = std::array{ 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; + } + const auto modules = exe.substr(0, last + 1) + L"modules"; + const auto deleteOne = [&](const wchar_t *name, const wchar_t *arch) { + const auto path = modules + L'\\' + arch + L'\\' + name; + DeleteFile(path.c_str()); + }; + const auto deleteBoth = [&](const wchar_t *name) { + deleteOne(name, L"x86"); + deleteOne(name, L"x64"); + }; + const auto removeOne = [&](const std::wstring &name) { + const auto path = modules + L'\\' + name; + RemoveDirectory(path.c_str()); + }; + const auto removeBoth = [&](const std::wstring &name) { + removeOne(L"x86\\" + name); + removeOne(L"x64\\" + name); + }; + deleteBoth(L"d3d\\d3dcompiler_47.dll"); + + removeBoth(L"d3d"); + removeOne(L"x86"); + removeOne(L"x64"); + RemoveDirectory(modules.c_str()); +} + } // namespace void psActivateProcess(uint64 pid) { @@ -133,6 +177,7 @@ void psDoCleanup() { psAutoStart(false, true); psSendToMenu(false, true); AppUserModelId::cleanupShortcut(); + DeleteMyModules(); } catch (...) { } } @@ -231,6 +276,7 @@ void StartOpenSSL() { void start() { StartOpenSSL(); + Dlls::CheckLoadedModules(); } } // namespace ThirdParty diff --git a/Telegram/SourceFiles/platform/win/windows_dlls.cpp b/Telegram/SourceFiles/platform/win/windows_dlls.cpp index a9169befd..7a461ca30 100644 --- a/Telegram/SourceFiles/platform/win/windows_dlls.cpp +++ b/Telegram/SourceFiles/platform/win/windows_dlls.cpp @@ -14,6 +14,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #define LOAD_SYMBOL(lib, name) ::base::Platform::LoadMethod(lib, #name, name) +bool DirectXResolveCompiler(); + namespace Platform { namespace Dlls { namespace { @@ -74,5 +76,30 @@ SafeIniter::SafeIniter() { SafeIniter kSafeIniter; } // namespace + +void CheckLoadedModules() { + if (DirectXResolveCompiler()) { + auto LibD3DCompiler = HMODULE(); + if (GetModuleHandleEx(0, L"d3dcompiler_47.dll", &LibD3DCompiler)) { + constexpr auto kMaxPathLong = 32767; + auto path = std::array{ 0 }; + const auto length = GetModuleFileName( + LibD3DCompiler, + path.data(), + kMaxPathLong); + if (length > 0 && length < kMaxPathLong) { + LOG(("Using DirectX compiler '%1'." + ).arg(QString::fromWCharArray(path.data()))); + } else { + LOG(("Error: Could not resolve DirectX compiler path.")); + } + } else { + LOG(("Error: Could not resolve DirectX compiler module.")); + } + } else { + LOG(("Error: Could not resolve DirectX compiler library.")); + } +} + } // namespace Dlls } // namespace Platform diff --git a/Telegram/SourceFiles/platform/win/windows_dlls.h b/Telegram/SourceFiles/platform/win/windows_dlls.h index 15fab5d43..c28c06384 100644 --- a/Telegram/SourceFiles/platform/win/windows_dlls.h +++ b/Telegram/SourceFiles/platform/win/windows_dlls.h @@ -22,6 +22,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL namespace Platform { namespace Dlls { +void CheckLoadedModules(); + // UXTHEME.DLL inline HRESULT(__stdcall *SetWindowTheme)( HWND hWnd, diff --git a/Telegram/build/build.bat b/Telegram/build/build.bat index 80cc5167d..6826f3b85 100644 --- a/Telegram/build/build.bat +++ b/Telegram/build/build.bat @@ -206,7 +206,13 @@ if %BuildUWP% equ 0 ( ) ) - call Packer.exe -version %VersionForPacker% -path %BinaryName%.exe -path Updater.exe -target %BuildTarget% %AlphaBetaParam% + if %Build64% neq 0 ( + set "ModulesFolder=x64" + ) else ( + set "ModulesFolder=x86" + ) + + call Packer.exe -version %VersionForPacker% -path %BinaryName%.exe -path Updater.exe -path "modules\!ModulesFolder!\d3d\d3dcompiler_47.dll" -target %BuildTarget% %AlphaBetaParam% if %errorlevel% neq 0 goto error if %AlphaVersion% neq 0 ( diff --git a/Telegram/build/setup.iss b/Telegram/build/setup.iss index c18dd374c..1c7d7fd33 100644 --- a/Telegram/build/setup.iss +++ b/Telegram/build/setup.iss @@ -36,10 +36,14 @@ DisableProgramGroupPage=no ArchitecturesAllowed=x64 ArchitecturesInstallIn64BitMode=x64 OutputBaseFilename=tsetup-x64.{#MyAppVersionFull} +#define ArchModulesFolder "x64" #else OutputBaseFilename=tsetup.{#MyAppVersionFull} +#define ArchModulesFolder "x86" #endif +#define ModulesFolder "modules\{#ArchModulesFolder}" + [Languages] Name: "english"; MessagesFile: "compiler:Default.isl" Name: "it"; MessagesFile: "compiler:Languages\Italian.isl" @@ -58,6 +62,7 @@ Name: "quicklaunchicon"; Description: "{cm:CreateQuickLaunchIcon}"; GroupDescrip [Files] Source: "{#ReleasePath}\Telegram.exe"; DestDir: "{app}"; Flags: ignoreversion Source: "{#ReleasePath}\Updater.exe"; DestDir: "{app}"; Flags: ignoreversion +Source: "{#ReleasePath}\{#ModulesFolder}\d3d\d3dcompiler_47.dll; DestDir: "{app}\{#ModulesFolder}\d3d"; Flags: ignoreversion ; NOTE: Don't use "Flags: ignoreversion" on any shared system files [Icons] @@ -78,6 +83,7 @@ Type: filesandordirs; Name: "{app}\tupdates" Type: filesandordirs; Name: "{app}\tdata" Type: filesandordirs; Name: "{app}\tcache" Type: filesandordirs; Name: "{app}\tdumps" +Type: filesandordirs; Name: "{app}\modules" Type: dirifempty; Name: "{app}" Type: files; Name: "{userappdata}\{#MyAppName}\data" Type: files; Name: "{userappdata}\{#MyAppName}\data_config" @@ -87,6 +93,7 @@ Type: filesandordirs; Name: "{userappdata}\{#MyAppName}\tupdates" Type: filesandordirs; Name: "{userappdata}\{#MyAppName}\tdata" Type: filesandordirs; Name: "{userappdata}\{#MyAppName}\tcache" Type: filesandordirs; Name: "{userappdata}\{#MyAppName}\tdumps" +Type: filesandordirs; Name: "{userappdata}\{#MyAppName}\modules" Type: dirifempty; Name: "{userappdata}\{#MyAppName}" [Code] diff --git a/cmake b/cmake index 46a49caa2..fe0d8a184 160000 --- a/cmake +++ b/cmake @@ -1 +1 @@ -Subproject commit 46a49caa21c16d3cc563798b8c26ba936cdd30e3 +Subproject commit fe0d8a184134850bf1476096c09564290188d470