diff --git a/Telegram/SourceFiles/_other/updater.cpp b/Telegram/SourceFiles/_other/updater.cpp index dbcce31379..35dd767b44 100644 --- a/Telegram/SourceFiles/_other/updater.cpp +++ b/Telegram/SourceFiles/_other/updater.cpp @@ -30,18 +30,26 @@ bool equal(const wstring &a, const wstring &b) { void updateError(const WCHAR *msg, DWORD errorCode) { WCHAR errMsg[2048]; - LPWSTR errorText = NULL, errorTextDefault = L"(Unknown error)"; - FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, errorCode, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPWSTR)&errorText, 0, 0); - if (!errorText) { - errorText = errorTextDefault; - } + LPWSTR errorTextFormatted = nullptr; + auto formatFlags = FORMAT_MESSAGE_FROM_SYSTEM + | FORMAT_MESSAGE_ALLOCATE_BUFFER + | FORMAT_MESSAGE_IGNORE_INSERTS; + FormatMessage( + formatFlags, + NULL, + errorCode, + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), + (LPWSTR)&errorTextFormatted, + 0, + 0); + auto errorText = errorTextFormatted + ? errorTextFormatted + : L"(Unknown error)"; wsprintf(errMsg, L"%s, error code: %d\nError message: %s", msg, errorCode, errorText); MessageBox(0, errMsg, L"Update error!", MB_ICONERROR); - if (errorText != errorTextDefault) { - LocalFree(errorText); - } + LocalFree(errorTextFormatted); } HANDLE _logFile = 0; @@ -309,20 +317,20 @@ void updateRegistry() { WCHAR nameStr[bufSize], dateStr[bufSize], publisherStr[bufSize], icongroupStr[bufSize]; SYSTEMTIME stLocalTime; GetLocalTime(&stLocalTime); - RegSetValueEx(rkey, L"DisplayVersion", 0, REG_SZ, (BYTE*)versionStr, ((versionLen / 2) + 1) * sizeof(WCHAR)); + RegSetValueEx(rkey, L"DisplayVersion", 0, REG_SZ, (const BYTE*)versionStr, ((versionLen / 2) + 1) * sizeof(WCHAR)); wsprintf(nameStr, L"Telegram Desktop version %s", versionStr); - RegSetValueEx(rkey, L"DisplayName", 0, REG_SZ, (BYTE*)nameStr, (wcslen(nameStr) + 1) * sizeof(WCHAR)); + RegSetValueEx(rkey, L"DisplayName", 0, REG_SZ, (const BYTE*)nameStr, (wcslen(nameStr) + 1) * sizeof(WCHAR)); wsprintf(publisherStr, L"Telegram Messenger LLP"); - RegSetValueEx(rkey, L"Publisher", 0, REG_SZ, (BYTE*)publisherStr, (wcslen(publisherStr) + 1) * sizeof(WCHAR)); + RegSetValueEx(rkey, L"Publisher", 0, REG_SZ, (const BYTE*)publisherStr, (wcslen(publisherStr) + 1) * sizeof(WCHAR)); wsprintf(icongroupStr, L"Telegram Desktop"); - RegSetValueEx(rkey, L"Inno Setup: Icon Group", 0, REG_SZ, (BYTE*)icongroupStr, (wcslen(icongroupStr) + 1) * sizeof(WCHAR)); + RegSetValueEx(rkey, L"Inno Setup: Icon Group", 0, REG_SZ, (const BYTE*)icongroupStr, (wcslen(icongroupStr) + 1) * sizeof(WCHAR)); wsprintf(dateStr, L"%04d%02d%02d", stLocalTime.wYear, stLocalTime.wMonth, stLocalTime.wDay); - RegSetValueEx(rkey, L"InstallDate", 0, REG_SZ, (BYTE*)dateStr, (wcslen(dateStr) + 1) * sizeof(WCHAR)); + RegSetValueEx(rkey, L"InstallDate", 0, REG_SZ, (const BYTE*)dateStr, (wcslen(dateStr) + 1) * sizeof(WCHAR)); - WCHAR *appURL = L"https://desktop.telegram.org"; - RegSetValueEx(rkey, L"HelpLink", 0, REG_SZ, (BYTE*)appURL, (wcslen(appURL) + 1) * sizeof(WCHAR)); - RegSetValueEx(rkey, L"URLInfoAbout", 0, REG_SZ, (BYTE*)appURL, (wcslen(appURL) + 1) * sizeof(WCHAR)); - RegSetValueEx(rkey, L"URLUpdateInfo", 0, REG_SZ, (BYTE*)appURL, (wcslen(appURL) + 1) * sizeof(WCHAR)); + const WCHAR *appURL = L"https://desktop.telegram.org"; + RegSetValueEx(rkey, L"HelpLink", 0, REG_SZ, (const BYTE*)appURL, (wcslen(appURL) + 1) * sizeof(WCHAR)); + RegSetValueEx(rkey, L"URLInfoAbout", 0, REG_SZ, (const BYTE*)appURL, (wcslen(appURL) + 1) * sizeof(WCHAR)); + RegSetValueEx(rkey, L"URLUpdateInfo", 0, REG_SZ, (const BYTE*)appURL, (wcslen(appURL) + 1) * sizeof(WCHAR)); } } } diff --git a/Telegram/SourceFiles/platform/win/main_window_win.cpp b/Telegram/SourceFiles/platform/win/main_window_win.cpp index 33f6b5ae63..02ef443571 100644 --- a/Telegram/SourceFiles/platform/win/main_window_win.cpp +++ b/Telegram/SourceFiles/platform/win/main_window_win.cpp @@ -526,7 +526,7 @@ private: BYTE r = 0, g = 0, b = 0; COLORREF noKeyColor; - static LRESULT CALLBACK _PsShadowWindows::wndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam); + static LRESULT CALLBACK wndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam); }; _PsShadowWindows _psShadowWindows; diff --git a/Telegram/SourceFiles/platform/win/notifications_manager_win.cpp b/Telegram/SourceFiles/platform/win/notifications_manager_win.cpp index 1c67bf2997..bf0525682e 100644 --- a/Telegram/SourceFiles/platform/win/notifications_manager_win.cpp +++ b/Telegram/SourceFiles/platform/win/notifications_manager_win.cpp @@ -209,10 +209,16 @@ typedef ABI::Windows::Foundation::ITypedEventHandler DesktopToastDismissedEventHandler; typedef ABI::Windows::Foundation::ITypedEventHandler DesktopToastFailedEventHandler; -class ToastEventHandler : public Implements { +class ToastEventHandler : public Implements< + DesktopToastActivatedEventHandler, + DesktopToastDismissedEventHandler, + DesktopToastFailedEventHandler> { public: // We keep a weak pointer to a member field of native notifications manager. - ToastEventHandler::ToastEventHandler(const std::shared_ptr &guarded, const PeerId &peer, MsgId msg) + ToastEventHandler( + const std::shared_ptr &guarded, + const PeerId &peer, + MsgId msg) : _peerId(peer) , _msgId(msg) , _weak(guarded) { @@ -607,8 +613,8 @@ void queryQuietHours() { return; } - LPTSTR lpKeyName = L"Software\\Microsoft\\Windows\\CurrentVersion\\Notifications\\Settings"; - LPTSTR lpValueName = L"NOC_GLOBAL_SETTING_TOASTS_ENABLED"; + LPCWSTR lpKeyName = L"Software\\Microsoft\\Windows\\CurrentVersion\\Notifications\\Settings"; + LPCWSTR lpValueName = L"NOC_GLOBAL_SETTING_TOASTS_ENABLED"; HKEY key; auto result = RegOpenKeyEx(HKEY_CURRENT_USER, lpKeyName, 0, KEY_READ, &key); if (result != ERROR_SUCCESS) { diff --git a/Telegram/SourceFiles/platform/win/specific_win.cpp b/Telegram/SourceFiles/platform/win/specific_win.cpp index 9d04deaafe..eef41923bb 100644 --- a/Telegram/SourceFiles/platform/win/specific_win.cpp +++ b/Telegram/SourceFiles/platform/win/specific_win.cpp @@ -532,15 +532,23 @@ QString SystemLanguage() { namespace { void _psLogError(const char *str, LSTATUS code) { - LPTSTR errorText = NULL, errorTextDefault = L"(Unknown error)"; - FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, code, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR)&errorText, 0, 0); - if (!errorText) { - errorText = errorTextDefault; - } + LPWSTR errorTextFormatted = nullptr; + auto formatFlags = FORMAT_MESSAGE_FROM_SYSTEM + | FORMAT_MESSAGE_ALLOCATE_BUFFER + | FORMAT_MESSAGE_IGNORE_INSERTS; + FormatMessage( + formatFlags, + NULL, + code, + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), + (LPTSTR)&errorTextFormatted, + 0, + 0); + auto errorText = errorTextFormatted + ? errorTextFormatted + : L"(Unknown error)"; LOG((str).arg(code).arg(QString::fromStdWString(errorText))); - if (errorText != errorTextDefault) { - LocalFree(errorText); - } + LocalFree(errorTextFormatted); } bool _psOpenRegKey(LPCWSTR key, PHKEY rkey) { diff --git a/Telegram/SourceFiles/rpl/variable.h b/Telegram/SourceFiles/rpl/variable.h index 049a468798..f98a5a3d17 100644 --- a/Telegram/SourceFiles/rpl/variable.h +++ b/Telegram/SourceFiles/rpl/variable.h @@ -24,6 +24,26 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org #include namespace rpl { +namespace details { + +template +struct supports_equality_compare { + template + static auto test(const U *u, const V *v) + -> decltype(*u == *v, details::true_t()); + static details::false_t test(...); + static constexpr bool value + = (sizeof(test( + (std::decay_t*)nullptr, + (std::decay_t*)nullptr + )) == sizeof(details::true_t)); +}; + +template +constexpr bool supports_equality_compare_v + = supports_equality_compare::value; + +} // namespace details template class variable final { @@ -86,30 +106,14 @@ public: } private: - template - struct supports_equality_compare { - template - static auto test(const U *u, const V *v) - -> decltype(*u == *v, details::true_t()); - static details::false_t test(...); - static constexpr bool value - = (sizeof(test( - (std::decay_t*)nullptr, - (std::decay_t*)nullptr - )) == sizeof(details::true_t)); - }; - template - static constexpr bool supports_equality_compare_v - = supports_equality_compare::value; - template variable &assign(OtherType &&data) { - if constexpr (supports_equality_compare_v) { + if constexpr (details::supports_equality_compare_v) { if (!(_data == data)) { _data = std::forward(data); _changes.fire_copy(_data); } - } else if constexpr (supports_equality_compare_v) { + } else if constexpr (details::supports_equality_compare_v) { auto old = std::move(_data); _data = std::forward(data); if (!(_data == old)) { diff --git a/Telegram/SourceFiles/ui/text/text.cpp b/Telegram/SourceFiles/ui/text/text.cpp index 10c7962b60..3b655aa029 100644 --- a/Telegram/SourceFiles/ui/text/text.cpp +++ b/Telegram/SourceFiles/ui/text/text.cpp @@ -663,8 +663,13 @@ private: }; void computeLinkText(const QString &linkData, QString *outLinkText, LinkDisplayStatus *outDisplayStatus) { - QUrl url(linkData), good(url.isValid() ? url.toEncoded() : ""); - QString readable = good.isValid() ? good.toDisplayString() : linkData; + auto url = QUrl(linkData); + auto good = QUrl(url.isValid() + ? url.toEncoded() + : QByteArray()); + auto readable = good.isValid() + ? good.toDisplayString() + : linkData; *outLinkText = _t->_st->font->elided(readable, st::linkCropLimit); *outDisplayStatus = (*outLinkText == readable) ? LinkDisplayedFull : LinkDisplayedElided; } diff --git a/Telegram/gyp/settings_win.gypi b/Telegram/gyp/settings_win.gypi index 247e3afd72..be93f25a66 100644 --- a/Telegram/gyp/settings_win.gypi +++ b/Telegram/gyp/settings_win.gypi @@ -37,6 +37,7 @@ 'DebugInformationFormat': '3', # Program Database (/Zi) 'AdditionalOptions': [ '/std:c++latest', + '/permissive-', '/MP', # Enable multi process build. '/EHsc', # Catch C++ exceptions only, extern C functions never throw a C++ exception. '/WX', # Treat warnings as errors.