Use /permissive- flag for Visual Studio builds.

This commit is contained in:
John Preston 2017-11-11 21:53:23 +04:00
parent aa160e775c
commit 5c12b0e5fa
7 changed files with 82 additions and 50 deletions

View File

@ -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));
}
}
}

View File

@ -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;

View File

@ -209,10 +209,16 @@ typedef ABI::Windows::Foundation::ITypedEventHandler<ToastNotification*, ::IInsp
typedef ABI::Windows::Foundation::ITypedEventHandler<ToastNotification*, ToastDismissedEventArgs*> DesktopToastDismissedEventHandler;
typedef ABI::Windows::Foundation::ITypedEventHandler<ToastNotification*, ToastFailedEventArgs*> DesktopToastFailedEventHandler;
class ToastEventHandler : public Implements<DesktopToastActivatedEventHandler, DesktopToastDismissedEventHandler, DesktopToastFailedEventHandler> {
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<Manager*> &guarded, const PeerId &peer, MsgId msg)
ToastEventHandler(
const std::shared_ptr<Manager*> &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) {

View File

@ -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) {

View File

@ -24,6 +24,26 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
#include <rpl/event_stream.h>
namespace rpl {
namespace details {
template <typename A, typename B>
struct supports_equality_compare {
template <typename U, typename V>
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<A>*)nullptr,
(std::decay_t<B>*)nullptr
)) == sizeof(details::true_t));
};
template <typename A, typename B>
constexpr bool supports_equality_compare_v
= supports_equality_compare<A, B>::value;
} // namespace details
template <typename Type>
class variable final {
@ -86,30 +106,14 @@ public:
}
private:
template <typename A, typename B>
struct supports_equality_compare {
template <typename U, typename V>
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<A>*)nullptr,
(std::decay_t<B>*)nullptr
)) == sizeof(details::true_t));
};
template <typename A, typename B>
static constexpr bool supports_equality_compare_v
= supports_equality_compare<A, B>::value;
template <typename OtherType>
variable &assign(OtherType &&data) {
if constexpr (supports_equality_compare_v<Type, OtherType>) {
if constexpr (details::supports_equality_compare_v<Type, OtherType>) {
if (!(_data == data)) {
_data = std::forward<OtherType>(data);
_changes.fire_copy(_data);
}
} else if constexpr (supports_equality_compare_v<Type, Type>) {
} else if constexpr (details::supports_equality_compare_v<Type, Type>) {
auto old = std::move(_data);
_data = std::forward<OtherType>(data);
if (!(_data == old)) {

View File

@ -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;
}

View File

@ -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.