diff --git a/Telegram/SourceFiles/config.h b/Telegram/SourceFiles/config.h index 1b707ab268..30afebbf6b 100644 --- a/Telegram/SourceFiles/config.h +++ b/Telegram/SourceFiles/config.h @@ -23,11 +23,11 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #include "core/version.h" #include "settings.h" -static const wchar_t *AppNameOld = L"Telegram Win (Unofficial)"; -static const wchar_t *AppName = L"Telegram Desktop"; +constexpr str_const AppNameOld = "Telegram Win (Unofficial)"; +constexpr str_const AppName = "Telegram Desktop"; -static const wchar_t *AppId = L"{53F49750-6209-4FBF-9CA8-7A333C87D1ED}"; // used in updater.cpp and Setup.iss for Windows -static const wchar_t *AppFile = L"Telegram"; +constexpr str_const AppId = "{53F49750-6209-4FBF-9CA8-7A333C87D1ED}"; // used in updater.cpp and Setup.iss for Windows +constexpr str_const AppFile = "Telegram"; enum { MTPShortBufferSize = 65535, // of ints, 256 kb diff --git a/Telegram/SourceFiles/core/basic_types.h b/Telegram/SourceFiles/core/basic_types.h index af03d5808d..0e2d05e645 100644 --- a/Telegram/SourceFiles/core/basic_types.h +++ b/Telegram/SourceFiles/core/basic_types.h @@ -213,6 +213,10 @@ private: }; +inline QString str_const_toString(const str_const &str) { + return QString::fromUtf8(str.c_str(), str.size()); +} + template inline void accumulate_max(T &a, const T &b) { if (a < b) a = b; } diff --git a/Telegram/SourceFiles/core/version.h b/Telegram/SourceFiles/core/version.h index cce86ebad5..4f4c0a7102 100644 --- a/Telegram/SourceFiles/core/version.h +++ b/Telegram/SourceFiles/core/version.h @@ -24,7 +24,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #define BETA_VERSION_MACRO (0ULL) -static constexpr int AppVersion = 9047; -static constexpr str_const AppVersionStr = "0.9.47"; -static constexpr bool AppAlphaVersion = true; -static constexpr uint64 AppBetaVersion = BETA_VERSION_MACRO; +constexpr int AppVersion = 9047; +constexpr str_const AppVersionStr = "0.9.47"; +constexpr bool AppAlphaVersion = true; +constexpr uint64 AppBetaVersion = BETA_VERSION_MACRO; diff --git a/Telegram/SourceFiles/mainwindow.cpp b/Telegram/SourceFiles/mainwindow.cpp index 650b49047d..94277b6a38 100644 --- a/Telegram/SourceFiles/mainwindow.cpp +++ b/Telegram/SourceFiles/mainwindow.cpp @@ -1110,7 +1110,7 @@ bool MainWindow::minimizeToTray() { hide(); if (cPlatform() == dbipWindows && trayIcon && !cSeenTrayTooltip()) { - trayIcon->showMessage(QString::fromStdWString(AppName), lang(lng_tray_icon_text), QSystemTrayIcon::Information, 10000); + trayIcon->showMessage(str_const_toString(AppName), lang(lng_tray_icon_text), QSystemTrayIcon::Information, 10000); cSetSeenTrayTooltip(true); Local::writeSettings(); } diff --git a/Telegram/SourceFiles/pspecific_linux.cpp b/Telegram/SourceFiles/pspecific_linux.cpp index 33ea2346f0..4fb50519fc 100644 --- a/Telegram/SourceFiles/pspecific_linux.cpp +++ b/Telegram/SourceFiles/pspecific_linux.cpp @@ -563,7 +563,7 @@ void PsMainWindow::psSetupTrayIcon() { QIcon icon(QPixmap::fromImage(App::wnd()->iconLarge(), Qt::ColorOnly)); trayIcon->setIcon(icon); - trayIcon->setToolTip(QString::fromStdWString(AppName)); + trayIcon->setToolTip(str_const_toString(AppName)); connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(toggleTray(QSystemTrayIcon::ActivationReason)), Qt::UniqueConnection); connect(trayIcon, SIGNAL(messageClicked()), this, SLOT(showFromTray())); App::wnd()->updateTrayMenu(); @@ -1171,7 +1171,7 @@ QString psAppDataPath() { } QString psDownloadPath() { - return QStandardPaths::writableLocation(QStandardPaths::DownloadLocation) + '/' + QString::fromWCharArray(AppName) + '/'; + return QStandardPaths::writableLocation(QStandardPaths::DownloadLocation) + '/' + str_const_toString(AppName) + '/'; } QString psCurrentExeDirectory(int argc, char *argv[]) { diff --git a/Telegram/SourceFiles/pspecific_mac.cpp b/Telegram/SourceFiles/pspecific_mac.cpp index 91b2124b12..6def077cd7 100644 --- a/Telegram/SourceFiles/pspecific_mac.cpp +++ b/Telegram/SourceFiles/pspecific_mac.cpp @@ -116,7 +116,7 @@ void PsMainWindow::psSetupTrayIcon() { icon.addPixmap(QPixmap::fromImage(psTrayIcon(true), Qt::ColorOnly), QIcon::Selected); trayIcon->setIcon(icon); - trayIcon->setToolTip(QString::fromStdWString(AppName)); + trayIcon->setToolTip(str_const_toString(AppName)); connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(toggleTray(QSystemTrayIcon::ActivationReason)), Qt::UniqueConnection); App::wnd()->updateTrayMenu(); } diff --git a/Telegram/SourceFiles/pspecific_mac_p.mm b/Telegram/SourceFiles/pspecific_mac_p.mm index 574e017794..3dc9e5ee18 100644 --- a/Telegram/SourceFiles/pspecific_mac_p.mm +++ b/Telegram/SourceFiles/pspecific_mac_p.mm @@ -1041,7 +1041,7 @@ double objc_appkitVersion() { QString objc_appDataPath() { NSURL *url = [[NSFileManager defaultManager] URLForDirectory:NSApplicationSupportDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:YES error:nil]; if (url) { - return QString::fromUtf8([[url path] fileSystemRepresentation]) + '/' + QString::fromWCharArray(AppName) + '/'; + return QString::fromUtf8([[url path] fileSystemRepresentation]) + '/' + str_const_toString(AppName) + '/'; } return QString(); } @@ -1049,7 +1049,7 @@ QString objc_appDataPath() { QString objc_downloadPath() { NSURL *url = [[NSFileManager defaultManager] URLForDirectory:NSDownloadsDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:YES error:nil]; if (url) { - return QString::fromUtf8([[url path] fileSystemRepresentation]) + '/' + QString::fromWCharArray(AppName) + '/'; + return QString::fromUtf8([[url path] fileSystemRepresentation]) + '/' + str_const_toString(AppName) + '/'; } return QString(); } diff --git a/Telegram/SourceFiles/pspecific_win.cpp b/Telegram/SourceFiles/pspecific_win.cpp index 07155067f5..be6675c1d0 100644 --- a/Telegram/SourceFiles/pspecific_win.cpp +++ b/Telegram/SourceFiles/pspecific_win.cpp @@ -1075,7 +1075,7 @@ void PsMainWindow::psSetupTrayIcon() { QIcon icon(QPixmap::fromImage(App::wnd()->iconLarge(), Qt::ColorOnly)); trayIcon->setIcon(icon); - trayIcon->setToolTip(QString::fromStdWString(AppName)); + trayIcon->setToolTip(str_const_toString(AppName)); connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(toggleTray(QSystemTrayIcon::ActivationReason)), Qt::UniqueConnection); connect(trayIcon, SIGNAL(messageClicked()), this, SLOT(showFromTray())); App::wnd()->updateTrayMenu(); @@ -1829,7 +1829,7 @@ QString psAppDataPath() { WCHAR wstrPath[maxFileLen]; if (GetEnvironmentVariable(L"APPDATA", wstrPath, maxFileLen)) { QDir appData(QString::fromStdWString(std::wstring(wstrPath))); - return appData.absolutePath() + '/' + QString::fromWCharArray(AppName) + '/'; + return appData.absolutePath() + '/' + str_const_toString(AppName) + '/'; } return QString(); } @@ -1839,13 +1839,13 @@ QString psAppDataPathOld() { WCHAR wstrPath[maxFileLen]; if (GetEnvironmentVariable(L"APPDATA", wstrPath, maxFileLen)) { QDir appData(QString::fromStdWString(std::wstring(wstrPath))); - return appData.absolutePath() + '/' + QString::fromWCharArray(AppNameOld) + '/'; + return appData.absolutePath() + '/' + str_const_toString(AppNameOld) + '/'; } return QString(); } QString psDownloadPath() { - return QStandardPaths::writableLocation(QStandardPaths::DownloadLocation) + '/' + QString::fromWCharArray(AppName) + '/'; + return QStandardPaths::writableLocation(QStandardPaths::DownloadLocation) + '/' + str_const_toString(AppName) + '/'; } QString psCurrentExeDirectory(int argc, char *argv[]) { @@ -1903,7 +1903,7 @@ void psDoFixPrevious() { DWORD checkType, checkSize = bufSize * 2; WCHAR checkStr[bufSize]; - QString appId = QString::fromStdWString(AppId); + QString appId = str_const_toString(AppId); QString newKeyStr1 = QString("Software\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\%1_is1").arg(appId); QString newKeyStr2 = QString("Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\%1_is1").arg(appId); QString oldKeyStr1 = QString("SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\%1_is1").arg(appId); @@ -2305,7 +2305,7 @@ void _manageAppLnk(bool create, bool silent, int path_csidl, const wchar_t *args WCHAR startupFolder[MAX_PATH]; HRESULT hr = SHGetFolderPath(0, path_csidl, 0, SHGFP_TYPE_CURRENT, startupFolder); if (SUCCEEDED(hr)) { - QString lnk = QString::fromWCharArray(startupFolder) + '\\' + QString::fromWCharArray(AppFile) + qsl(".lnk"); + QString lnk = QString::fromWCharArray(startupFolder) + '\\' + str_const_toString(AppFile) + qsl(".lnk"); if (create) { ComPtr shellLink; hr = CoCreateInstance(CLSID_ShellLink, nullptr, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&shellLink)); @@ -2368,9 +2368,6 @@ void psUpdateOverlayed(TWidget *widget) { if (!wv) widget->setAttribute(Qt::WA_WState_Visible, false); } -static const WCHAR *_programName = AppName; // folder in APPDATA, if current path is unavailable for writing -static const WCHAR *_exeName = L"Telegram.exe"; - // Stack walk code is inspired by http://www.codeproject.com/Articles/11132/Walking-the-callstack static const int StackEntryMaxNameLength = MAX_SYM_NAME + 1; diff --git a/Telegram/SourceFiles/pspecific_winrt.cpp b/Telegram/SourceFiles/pspecific_winrt.cpp index 816e62d223..76a8eb1cf2 100644 --- a/Telegram/SourceFiles/pspecific_winrt.cpp +++ b/Telegram/SourceFiles/pspecific_winrt.cpp @@ -1088,7 +1088,7 @@ void PsMainWindow::psSetupTrayIcon() { QIcon icon(QPixmap::fromImage(App::wnd()->iconLarge(), Qt::ColorOnly)); trayIcon->setIcon(icon); - trayIcon->setToolTip(QString::fromStdWString(AppName)); + trayIcon->setToolTip(str_const_toString(AppName)); connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(toggleTray(QSystemTrayIcon::ActivationReason)), Qt::UniqueConnection); connect(trayIcon, SIGNAL(messageClicked()), this, SLOT(showFromTray())); App::wnd()->updateTrayMenu(); @@ -1843,7 +1843,7 @@ QString psAppDataPath() { //WCHAR wstrPath[maxFileLen]; //if (GetEnvironmentVariable(L"APPDATA", wstrPath, maxFileLen)) { // QDir appData(QString::fromStdWString(std::wstring(wstrPath))); - // return appData.absolutePath() + '/' + QString::fromWCharArray(AppName) + '/'; + // return appData.absolutePath() + '/' + str_const_toString(AppName) + '/'; //} return QString(); } @@ -1853,13 +1853,13 @@ QString psAppDataPathOld() { //WCHAR wstrPath[maxFileLen]; //if (GetEnvironmentVariable(L"APPDATA", wstrPath, maxFileLen)) { // QDir appData(QString::fromStdWString(std::wstring(wstrPath))); - // return appData.absolutePath() + '/' + QString::fromWCharArray(AppNameOld) + '/'; + // return appData.absolutePath() + '/' + str_const_toString(AppNameOld) + '/'; //} return QString(); } QString psDownloadPath() { - return QStandardPaths::writableLocation(QStandardPaths::DownloadLocation) + '/' + QString::fromWCharArray(AppName) + '/'; + return QStandardPaths::writableLocation(QStandardPaths::DownloadLocation) + '/' + str_const_toString(AppName) + '/'; } QString psCurrentExeDirectory(int argc, char *argv[]) { @@ -1917,7 +1917,7 @@ void psDoFixPrevious() { //DWORD checkType, checkSize = bufSize * 2; //WCHAR checkStr[bufSize]; - //QString appId = QString::fromStdWString(AppId); + //QString appId = str_const_toString(AppId); //QString newKeyStr1 = QString("Software\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\%1_is1").arg(appId); //QString newKeyStr2 = QString("Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\%1_is1").arg(appId); //QString oldKeyStr1 = QString("SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\%1_is1").arg(appId); @@ -2319,7 +2319,7 @@ void _manageAppLnk(bool create, bool silent, int path_csidl, const wchar_t *args //WCHAR startupFolder[MAX_PATH]; //HRESULT hr = SHGetFolderPath(0, path_csidl, 0, SHGFP_TYPE_CURRENT, startupFolder); //if (SUCCEEDED(hr)) { - // QString lnk = QString::fromWCharArray(startupFolder) + '\\' + QString::fromWCharArray(AppFile) + qsl(".lnk"); + // QString lnk = QString::fromWCharArray(startupFolder) + '\\' + str_const_toString(AppFile) + qsl(".lnk"); // if (create) { // ComPtr shellLink; // hr = CoCreateInstance(CLSID_ShellLink, nullptr, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&shellLink)); @@ -2382,9 +2382,6 @@ void psUpdateOverlayed(TWidget *widget) { if (!wv) widget->setAttribute(Qt::WA_WState_Visible, false); } -static const WCHAR *_programName = AppName; // folder in APPDATA, if current path is unavailable for writing -static const WCHAR *_exeName = L"Telegram.exe"; - void psWriteDump() { }