diff --git a/Telegram/SourceFiles/boxes/aboutbox.cpp b/Telegram/SourceFiles/boxes/aboutbox.cpp index 913465e84b..87e01f6a3e 100644 --- a/Telegram/SourceFiles/boxes/aboutbox.cpp +++ b/Telegram/SourceFiles/boxes/aboutbox.cpp @@ -107,6 +107,7 @@ void AboutBox::paintEvent(QPaintEvent *e) { paintTitle(p, qsl("Telegram Desktop")); } +#ifndef TDESKTOP_DISABLE_CRASH_REPORTS QString _getCrashReportFile(const QMimeData *m) { if (!m || m->urls().size() != 1) return QString(); @@ -115,19 +116,24 @@ QString _getCrashReportFile(const QMimeData *m) { return file.endsWith(qstr(".telegramcrash"), Qt::CaseInsensitive) ? file : QString(); } +#endif // !TDESKTOP_DISABLE_CRASH_REPORTS void AboutBox::dragEnterEvent(QDragEnterEvent *e) { +#ifndef TDESKTOP_DISABLE_CRASH_REPORTS if (!_getCrashReportFile(e->mimeData()).isEmpty()) { e->setDropAction(Qt::CopyAction); e->accept(); } +#endif } void AboutBox::dropEvent(QDropEvent *e) { +#ifndef TDESKTOP_DISABLE_CRASH_REPORTS if (!_getCrashReportFile(e->mimeData()).isEmpty()) { e->acceptProposedAction(); showCrashReportWindow(_getCrashReportFile(e->mimeData())); } +#endif // !TDESKTOP_DISABLE_CRASH_REPORTS } QString telegramFaqLink() { diff --git a/Telegram/SourceFiles/gui/filedialog.cpp b/Telegram/SourceFiles/gui/filedialog.cpp index b606613d0a..50684f6611 100644 --- a/Telegram/SourceFiles/gui/filedialog.cpp +++ b/Telegram/SourceFiles/gui/filedialog.cpp @@ -149,7 +149,7 @@ bool _filedialogGetFiles(QStringList &files, QByteArray &remoteContent, const QS cSetDialogLastPath(path); Local::writeUserSettings(); } - + if (res == QDialog::Accepted) { if (multipleFiles > 0) { files = dialog.selectedFiles(); @@ -157,9 +157,9 @@ bool _filedialogGetFiles(QStringList &files, QByteArray &remoteContent, const QS files = dialog.selectedFiles().mid(0, 1); } if (multipleFiles >= 0) { -#ifdef Q_OS_WIN +#if defined Q_OS_WIN && !defined Q_OS_WINRT remoteContent = dialog.selectedRemoteContent(); -#endif +#endif // Q_OS_WIN && !Q_OS_WINRT } return true; } diff --git a/Telegram/SourceFiles/gui/text.cpp b/Telegram/SourceFiles/gui/text.cpp index 000c239bdb..da7e31e602 100644 --- a/Telegram/SourceFiles/gui/text.cpp +++ b/Telegram/SourceFiles/gui/text.cpp @@ -1654,6 +1654,7 @@ public: *_getSymbolUpon = true; return false; } else if (_p) { +#ifndef TDESKTOP_WINRT // temp QTextCharFormat format; QTextItemInt gf(glyphs.mid(glyphsStart, glyphsEnd - glyphsStart), &_e->fnt, engine.layoutData->string.unicode() + itemStart, @@ -1662,7 +1663,7 @@ public: gf.width = itemWidth; gf.justified = false; gf.initWithScriptItem(si); - +#endif // !TDESKTOP_WINRT if (_localFrom + itemStart < _selectedTo && _localFrom + itemEnd > _selectedFrom) { QFixed selX = x, selWidth = itemWidth; if (_localFrom + itemEnd > _selectedTo || _localFrom + itemStart < _selectedFrom) { @@ -1703,7 +1704,9 @@ public: _p->fillRect(QRectF(selX.toReal(), _y + _yDelta, selWidth.toReal(), _fontHeight), _textStyle->selectBg->b); } +#ifndef TDESKTOP_WINRT // temp _p->drawTextItem(QPointF(x.toReal(), textY), gf); +#endif // !TDESKTOP_WINRT } x += itemWidth; diff --git a/Telegram/SourceFiles/main.cpp b/Telegram/SourceFiles/main.cpp index b79c0f7adb..85096528f9 100644 --- a/Telegram/SourceFiles/main.cpp +++ b/Telegram/SourceFiles/main.cpp @@ -30,8 +30,10 @@ int main(int argc, char *argv[]) { return psFixPrevious(); } else if (cLaunchMode() == LaunchModeCleanup) { return psCleanup(); +#ifndef TDESKTOP_DISABLE_CRASH_REPORTS } else if (cLaunchMode() == LaunchModeShowCrash) { return showCrashReportWindow(QFileInfo(cStartUrl()).absoluteFilePath()); +#endif // !TDESKTOP_DISABLE_CRASH_REPORTS } // both are finished in Application::closeApplication @@ -72,4 +74,6 @@ int main(int argc, char *argv[]) { SignalHandlers::finish(); PlatformSpecific::finish(); Logs::finish(); + + return result; } diff --git a/Telegram/SourceFiles/pspecific_winrt.cpp b/Telegram/SourceFiles/pspecific_winrt.cpp index 72adf52224..ae9f029a44 100644 --- a/Telegram/SourceFiles/pspecific_winrt.cpp +++ b/Telegram/SourceFiles/pspecific_winrt.cpp @@ -29,35 +29,35 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #include "passcodewidget.h" -#include +//#include #include -#include -#include -#include -#include +//#include +//#include +//#include +//#include -#pragma warning(push) -#pragma warning(disable:4091) -#include -#include -#pragma warning(pop) +//#pragma warning(push) +//#pragma warning(disable:4091) +//#include +//#include +//#pragma warning(pop) -#include -#include -#include -#include +//#include +//#include +//#include +//#include -#include +//#include -#include -#include -#include -#include -#include -#include -#include -#include +//#include +//#include +//#include +//#include +//#include +//#include +//#include +//#include #include @@ -86,10 +86,10 @@ const WCHAR *AppUserModelId() { static const PROPERTYKEY pkey_AppUserModel_ID = { { 0x9F4C2855, 0x9F79, 0x4B39, { 0xA8, 0xD0, 0xE1, 0xD4, 0x2D, 0xE1, 0xD5, 0xF3 } }, 5 }; static const PROPERTYKEY pkey_AppUserModel_StartPinOption = { { 0x9F4C2855, 0x9F79, 0x4B39, { 0xA8, 0xD0, 0xE1, 0xD4, 0x2D, 0xE1, 0xD5, 0xF3 } }, 12 }; -using namespace Microsoft::WRL; -using namespace ABI::Windows::UI::Notifications; -using namespace ABI::Windows::Data::Xml::Dom; -using namespace Windows::Foundation; +//using namespace Microsoft::WRL; +//using namespace ABI::Windows::UI::Notifications; +//using namespace ABI::Windows::Data::Xml::Dom; +//using namespace Windows::Foundation; namespace { QStringList _initLogs; @@ -111,610 +111,610 @@ namespace { UINT tbCreatedMsgId = 0; - ComPtr taskbarList; - - ComPtr toastNotificationManager; - ComPtr toastNotifier; - ComPtr toastNotificationFactory; - struct ToastNotificationPtr { - ToastNotificationPtr() { - } - ToastNotificationPtr(const ComPtr &ptr) : p(ptr) { - } - ComPtr p; - }; - typedef QMap > ToastNotifications; - ToastNotifications toastNotifications; - struct ToastImage { - uint64 until; - QString path; - }; - typedef QMap ToastImages; - ToastImages toastImages; - bool ToastImageSavedFlag = false; - - HWND createTaskbarHider() { - HINSTANCE appinst = (HINSTANCE)GetModuleHandle(0); - HWND hWnd = 0; - - QString cn = QString("TelegramTaskbarHider"); - LPCWSTR _cn = (LPCWSTR)cn.utf16(); - WNDCLASSEX wc; - - wc.cbSize = sizeof(wc); - wc.style = 0; - wc.lpfnWndProc = DefWindowProc; - wc.cbClsExtra = 0; - wc.cbWndExtra = 0; - wc.hInstance = appinst; - wc.hIcon = 0; - wc.hCursor = 0; - wc.hbrBackground = 0; - wc.lpszMenuName = NULL; - wc.lpszClassName = _cn; - wc.hIconSm = 0; - if (!RegisterClassEx(&wc)) { - DEBUG_LOG(("Application Error: could not register taskbar hider window class, error: %1").arg(GetLastError())); - return hWnd; - } - - hWnd = CreateWindowEx(WS_EX_TOOLWINDOW, _cn, 0, WS_POPUP, 0, 0, 0, 0, 0, 0, appinst, 0); - if (!hWnd) { - DEBUG_LOG(("Application Error: could not create taskbar hider window class, error: %1").arg(GetLastError())); - return hWnd; - } - return hWnd; - } - - enum { - _PsShadowMoved = 0x01, - _PsShadowResized = 0x02, - _PsShadowShown = 0x04, - _PsShadowHidden = 0x08, - _PsShadowActivate = 0x10, - }; - - enum { - _PsInitHor = 0x01, - _PsInitVer = 0x02, - }; - - int32 _psSize = 0; - class _PsShadowWindows { - public: - - _PsShadowWindows() : screenDC(0), max_w(0), max_h(0), _x(0), _y(0), _w(0), _h(0), hidden(true), r(0), g(0), b(0), noKeyColor(RGB(255, 255, 255)) { - for (int i = 0; i < 4; ++i) { - dcs[i] = 0; - bitmaps[i] = 0; - hwnds[i] = 0; - } - } - - void setColor(QColor c) { - r = c.red(); - g = c.green(); - b = c.blue(); - - if (!hwnds[0]) return; - Gdiplus::SolidBrush brush(Gdiplus::Color(_alphas[0], r, g, b)); - for (int i = 0; i < 4; ++i) { - Gdiplus::Graphics graphics(dcs[i]); - graphics.SetCompositingMode(Gdiplus::CompositingModeSourceCopy); - if ((i % 2) && _h || !(i % 2) && _w) { - graphics.FillRectangle(&brush, 0, 0, (i % 2) ? _size : _w, (i % 2) ? _h : _size); - } - } - initCorners(); - - _x = _y = _w = _h = 0; - update(_PsShadowMoved | _PsShadowResized); - } - - bool init(QColor c) { - style::rect topLeft = st::wndShadow; - _fullsize = topLeft.width(); - _shift = st::wndShadowShift; - QImage cornersImage(_fullsize, _fullsize, QImage::Format_ARGB32_Premultiplied); - { - QPainter p(&cornersImage); - p.drawPixmap(QPoint(0, 0), App::sprite(), topLeft); - } - if (rtl()) cornersImage = cornersImage.mirrored(true, false); - uchar *bits = cornersImage.bits(); - if (bits) { - for ( - quint32 *p = (quint32*)bits, *end = (quint32*)(bits + cornersImage.byteCount()); - p < end; - ++p - ) { - *p = (*p ^ 0x00ffffff) << 24; - } - } - - _metaSize = _fullsize + 2 * _shift; - _alphas.reserve(_metaSize); - _colors.reserve(_metaSize * _metaSize); - for (int32 j = 0; j < _metaSize; ++j) { - for (int32 i = 0; i < _metaSize; ++i) { - _colors.push_back((i < 2 * _shift || j < 2 * _shift) ? 1 : qMax(BYTE(1), BYTE(cornersImage.pixel(QPoint(i - 2 * _shift, j - 2 * _shift)) >> 24))); - } - } - uchar prev = 0; - for (int32 i = 0; i < _metaSize; ++i) { - uchar a = _colors[(_metaSize - 1) * _metaSize + i]; - if (a < prev) break; - - _alphas.push_back(a); - prev = a; - } - _psSize = _size = _alphas.size() - 2 * _shift; - - setColor(c); - - Gdiplus::GdiplusStartupInput gdiplusStartupInput; - ULONG_PTR gdiplusToken; - Gdiplus::Status gdiRes = Gdiplus::GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL); - - if (gdiRes != Gdiplus::Ok) { - LOG(("Application Error: could not init GDI+, error: %1").arg((int)gdiRes)); - return false; - } - blend.AlphaFormat = AC_SRC_ALPHA; - blend.SourceConstantAlpha = 255; - blend.BlendFlags = 0; - blend.BlendOp = AC_SRC_OVER; - - screenDC = GetDC(0); - if (!screenDC) { - LOG(("Application Error: could not GetDC(0), error: %2").arg(GetLastError())); - return false; - } - - QRect avail(Sandbox::availableGeometry()); - max_w = avail.width(); - if (max_w < st::wndMinWidth) max_w = st::wndMinWidth; - max_h = avail.height(); - if (max_h < st::wndMinHeight) max_h = st::wndMinHeight; - - HINSTANCE appinst = (HINSTANCE)GetModuleHandle(0); - HWND hwnd = App::wnd() ? App::wnd()->psHwnd() : 0; - - for (int i = 0; i < 4; ++i) { - QString cn = QString("TelegramShadow%1").arg(i); - LPCWSTR _cn = (LPCWSTR)cn.utf16(); - WNDCLASSEX wc; - - wc.cbSize = sizeof(wc); - wc.style = 0; - wc.lpfnWndProc = wndProc; - wc.cbClsExtra = 0; - wc.cbWndExtra = 0; - wc.hInstance = appinst; - wc.hIcon = 0; - wc.hCursor = 0; - wc.hbrBackground = 0; - wc.lpszMenuName = NULL; - wc.lpszClassName = _cn; - wc.hIconSm = 0; - if (!RegisterClassEx(&wc)) { - LOG(("Application Error: could not register shadow window class %1, error: %2").arg(i).arg(GetLastError())); - destroy(); - return false; - } - - hwnds[i] = CreateWindowEx(WS_EX_LAYERED | WS_EX_TOOLWINDOW, _cn, 0, WS_POPUP, 0, 0, 0, 0, 0, 0, appinst, 0); - if (!hwnds[i]) { - LOG(("Application Error: could not create shadow window class %1, error: %2").arg(i).arg(GetLastError())); - destroy(); - return false; - } - SetWindowLong(hwnds[i], GWL_HWNDPARENT, (LONG)hwnd); - - dcs[i] = CreateCompatibleDC(screenDC); - if (!dcs[i]) { - LOG(("Application Error: could not create dc for shadow window class %1, error: %2").arg(i).arg(GetLastError())); - destroy(); - return false; - } - - bitmaps[i] = CreateCompatibleBitmap(screenDC, (i % 2) ? _size : max_w, (i % 2) ? max_h : _size); - if (!bitmaps[i]) { - LOG(("Application Error: could not create bitmap for shadow window class %1, error: %2").arg(i).arg(GetLastError())); - destroy(); - return false; - } - - SelectObject(dcs[i], bitmaps[i]); - } - - initCorners(); - return true; - } - - void initCorners(int directions = (_PsInitHor | _PsInitVer)) { - bool hor = (directions & _PsInitHor), ver = (directions & _PsInitVer); - Gdiplus::Graphics graphics0(dcs[0]), graphics1(dcs[1]), graphics2(dcs[2]), graphics3(dcs[3]); - graphics0.SetCompositingMode(Gdiplus::CompositingModeSourceCopy); - graphics1.SetCompositingMode(Gdiplus::CompositingModeSourceCopy); - graphics2.SetCompositingMode(Gdiplus::CompositingModeSourceCopy); - graphics3.SetCompositingMode(Gdiplus::CompositingModeSourceCopy); - - Gdiplus::SolidBrush brush(Gdiplus::Color(_alphas[0], r, g, b)); - if (hor) graphics0.FillRectangle(&brush, 0, 0, _fullsize - (_size - _shift), 2 * _shift); - - if (ver) { - graphics1.FillRectangle(&brush, 0, 0, _size, 2 * _shift); - graphics3.FillRectangle(&brush, 0, 0, _size, 2 * _shift); - graphics1.FillRectangle(&brush, _size - _shift, 2 * _shift, _shift, _fullsize); - graphics3.FillRectangle(&brush, 0, 2 * _shift, _shift, _fullsize); - } - - if (hor) { - for (int j = 2 * _shift; j < _size; ++j) { - for (int k = 0; k < _fullsize - (_size - _shift); ++k) { - brush.SetColor(Gdiplus::Color(_colors[j * _metaSize + k + (_size + _shift)], r, g, b)); - graphics0.FillRectangle(&brush, k, j, 1, 1); - graphics2.FillRectangle(&brush, k, _size - (j - 2 * _shift) - 1, 1, 1); - } - } - for (int j = _size; j < _size + 2 * _shift; ++j) { - for (int k = 0; k < _fullsize - (_size - _shift); ++k) { - brush.SetColor(Gdiplus::Color(_colors[j * _metaSize + k + (_size + _shift)], r, g, b)); - graphics2.FillRectangle(&brush, k, _size - (j - 2 * _shift) - 1, 1, 1); - } - } - } - if (ver) { - for (int j = 2 * _shift; j < _fullsize + 2 * _shift; ++j) { - for (int k = _shift; k < _size; ++k) { - brush.SetColor(Gdiplus::Color(_colors[j * _metaSize + (k + _shift)], r, g, b)); - graphics1.FillRectangle(&brush, _size - k - 1, j, 1, 1); - graphics3.FillRectangle(&brush, k, j, 1, 1); - } - } - } - } - void verCorners(int h, Gdiplus::Graphics *pgraphics1, Gdiplus::Graphics *pgraphics3) { - Gdiplus::SolidBrush brush(Gdiplus::Color(_alphas[0], r, g, b)); - pgraphics1->FillRectangle(&brush, _size - _shift, h - _fullsize, _shift, _fullsize); - pgraphics3->FillRectangle(&brush, 0, h - _fullsize, _shift, _fullsize); - for (int j = 0; j < _fullsize; ++j) { - for (int k = _shift; k < _size; ++k) { - brush.SetColor(Gdiplus::Color(_colors[(j + 2 * _shift) * _metaSize + k + _shift], r, g, b)); - pgraphics1->FillRectangle(&brush, _size - k - 1, h - j - 1, 1, 1); - pgraphics3->FillRectangle(&brush, k, h - j - 1, 1, 1); - } - } - } - void horCorners(int w, Gdiplus::Graphics *pgraphics0, Gdiplus::Graphics *pgraphics2) { - Gdiplus::SolidBrush brush(Gdiplus::Color(_alphas[0], r, g, b)); - pgraphics0->FillRectangle(&brush, w - 2 * _size - (_fullsize - (_size - _shift)), 0, _fullsize - (_size - _shift), 2 * _shift); - for (int j = 2 * _shift; j < _size; ++j) { - for (int k = 0; k < _fullsize - (_size - _shift); ++k) { - brush.SetColor(Gdiplus::Color(_colors[j * _metaSize + k + (_size + _shift)], r, g, b)); - pgraphics0->FillRectangle(&brush, w - 2 * _size - k - 1, j, 1, 1); - pgraphics2->FillRectangle(&brush, w - 2 * _size - k - 1, _size - (j - 2 * _shift) - 1, 1, 1); - } - } - for (int j = _size; j < _size + 2 * _shift; ++j) { - for (int k = 0; k < _fullsize - (_size - _shift); ++k) { - brush.SetColor(Gdiplus::Color(_colors[j * _metaSize + k + (_size + _shift)], r, g, b)); - pgraphics2->FillRectangle(&brush, w - 2 * _size - k - 1, _size - (j - 2 * _shift) - 1, 1, 1); - } - } - } - - void update(int changes, WINDOWPOS *pos = 0) { - HWND hwnd = App::wnd() ? App::wnd()->psHwnd() : 0; - if (!hwnd || !hwnds[0]) return; - - if (changes == _PsShadowActivate) { - for (int i = 0; i < 4; ++i) { - SetWindowPos(hwnds[i], hwnd, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE); - } - return; - } - - if (changes & _PsShadowHidden) { - if (!hidden) { - for (int i = 0; i < 4; ++i) { - hidden = true; - ShowWindow(hwnds[i], SW_HIDE); - } - } - return; - } - if (!App::wnd()->psPosInited()) return; - - int x = _x, y = _y, w = _w, h = _h; - if (pos && (!(pos->flags & SWP_NOMOVE) || !(pos->flags & SWP_NOSIZE) || !(pos->flags & SWP_NOREPOSITION))) { - if (!(pos->flags & SWP_NOMOVE)) { - x = pos->x - _size; - y = pos->y - _size; - } else if (pos->flags & SWP_NOSIZE) { - for (int i = 0; i < 4; ++i) { - SetWindowPos(hwnds[i], hwnd, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE); - } - return; - } - if (!(pos->flags & SWP_NOSIZE)) { - w = pos->cx + 2 * _size; - h = pos->cy + 2 * _size; - } - } else { - RECT r; - GetWindowRect(hwnd, &r); - x = r.left - _size; - y = r.top - _size; - w = r.right + _size - x; - h = r.bottom + _size - y; - } - if (h < 2 * _fullsize + 2 * _shift) { - h = 2 * _fullsize + 2 * _shift; - } - if (w < 2 * (_fullsize + _shift)) { - w = 2 * (_fullsize + _shift); - } - - if (w != _w) { - int from = (_w > 2 * (_fullsize + _shift)) ? (_w - _size - _fullsize - _shift) : (_fullsize - (_size - _shift)); - int to = w - _size - _fullsize - _shift; - if (w > max_w) { - from = _fullsize - (_size - _shift); - max_w *= 2; - for (int i = 0; i < 4; i += 2) { - DeleteObject(bitmaps[i]); - bitmaps[i] = CreateCompatibleBitmap(screenDC, max_w, _size); - SelectObject(dcs[i], bitmaps[i]); - } - initCorners(_PsInitHor); - } - Gdiplus::Graphics graphics0(dcs[0]), graphics2(dcs[2]); - graphics0.SetCompositingMode(Gdiplus::CompositingModeSourceCopy); - graphics2.SetCompositingMode(Gdiplus::CompositingModeSourceCopy); - Gdiplus::SolidBrush brush(Gdiplus::Color(_alphas[0], r, g, b)); - if (to > from) { - graphics0.FillRectangle(&brush, from, 0, to - from, 2 * _shift); - for (int i = 2 * _shift; i < _size; ++i) { - Gdiplus::Pen pen(Gdiplus::Color(_alphas[i], r, g, b)); - graphics0.DrawLine(&pen, from, i, to, i); - graphics2.DrawLine(&pen, from, _size - (i - 2 * _shift) - 1, to, _size - (i - 2 * _shift) - 1); - } - for (int i = _size; i < _size + 2 * _shift; ++i) { - Gdiplus::Pen pen(Gdiplus::Color(_alphas[i], r, g, b)); - graphics2.DrawLine(&pen, from, _size - (i - 2 * _shift) - 1, to, _size - (i - 2 * _shift) - 1); - } - } - if (_w > w) { - graphics0.FillRectangle(&brush, w - _size - _fullsize - _shift, 0, _fullsize - (_size - _shift), _size); - graphics2.FillRectangle(&brush, w - _size - _fullsize - _shift, 0, _fullsize - (_size - _shift), _size); - } - horCorners(w, &graphics0, &graphics2); - POINT p0 = { x + _size, y }, p2 = { x + _size, y + h - _size }, f = { 0, 0 }; - SIZE s = { w - 2 * _size, _size }; - updateWindow(0, &p0, &s); - updateWindow(2, &p2, &s); - } else if (x != _x || y != _y) { - POINT p0 = { x + _size, y }, p2 = { x + _size, y + h - _size }; - updateWindow(0, &p0); - updateWindow(2, &p2); - } else if (h != _h) { - POINT p2 = { x + _size, y + h - _size }; - updateWindow(2, &p2); - } - - if (h != _h) { - int from = (_h > 2 * _fullsize + 2 * _shift) ? (_h - _fullsize) : (_fullsize + 2 * _shift); - int to = h - _fullsize; - if (h > max_h) { - from = (_fullsize + 2 * _shift); - max_h *= 2; - for (int i = 1; i < 4; i += 2) { - DeleteObject(bitmaps[i]); - bitmaps[i] = CreateCompatibleBitmap(dcs[i], _size, max_h); - SelectObject(dcs[i], bitmaps[i]); - } - initCorners(_PsInitVer); - } - Gdiplus::Graphics graphics1(dcs[1]), graphics3(dcs[3]); - graphics1.SetCompositingMode(Gdiplus::CompositingModeSourceCopy); - graphics3.SetCompositingMode(Gdiplus::CompositingModeSourceCopy); - - Gdiplus::SolidBrush brush(Gdiplus::Color(_alphas[0], r, g, b)); - if (to > from) { - graphics1.FillRectangle(&brush, _size - _shift, from, _shift, to - from); - graphics3.FillRectangle(&brush, 0, from, _shift, to - from); - for (int i = 2 * _shift; i < _size + _shift; ++i) { - Gdiplus::Pen pen(Gdiplus::Color(_alphas[i], r, g, b)); - graphics1.DrawLine(&pen, _size + _shift - i - 1, from, _size + _shift - i - 1, to); - graphics3.DrawLine(&pen, i - _shift, from, i - _shift, to); - } - } - if (_h > h) { - graphics1.FillRectangle(&brush, 0, h - _fullsize, _size, _fullsize); - graphics3.FillRectangle(&brush, 0, h - _fullsize, _size, _fullsize); - } - verCorners(h, &graphics1, &graphics3); - - POINT p1 = {x + w - _size, y}, p3 = {x, y}, f = {0, 0}; - SIZE s = { _size, h }; - updateWindow(1, &p1, &s); - updateWindow(3, &p3, &s); - } else if (x != _x || y != _y) { - POINT p1 = { x + w - _size, y }, p3 = { x, y }; - updateWindow(1, &p1); - updateWindow(3, &p3); - } else if (w != _w) { - POINT p1 = { x + w - _size, y }; - updateWindow(1, &p1); - } - _x = x; - _y = y; - _w = w; - _h = h; - - if (hidden && (changes & _PsShadowShown)) { - for (int i = 0; i < 4; ++i) { - SetWindowPos(hwnds[i], hwnd, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW | SWP_NOACTIVATE); - } - hidden = false; - } - } - - void updateWindow(int i, POINT *p, SIZE *s = 0) { - static POINT f = {0, 0}; - if (s) { - UpdateLayeredWindow(hwnds[i], (s ? screenDC : 0), p, s, (s ? dcs[i] : 0), (s ? (&f) : 0), noKeyColor, &blend, ULW_ALPHA); - } else { - SetWindowPos(hwnds[i], 0, p->x, p->y, 0, 0, SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOZORDER); - } - } - - void destroy() { - for (int i = 0; i < 4; ++i) { - if (dcs[i]) DeleteDC(dcs[i]); - if (bitmaps[i]) DeleteObject(bitmaps[i]); - if (hwnds[i]) DestroyWindow(hwnds[i]); - dcs[i] = 0; - bitmaps[i] = 0; - hwnds[i] = 0; - } - if (screenDC) ReleaseDC(0, screenDC); - } - - private: - - int _x, _y, _w, _h; - int _metaSize, _fullsize, _size, _shift; - QVector _alphas, _colors; - - bool hidden; - - HWND hwnds[4]; - HDC dcs[4], screenDC; - HBITMAP bitmaps[4]; - int max_w, max_h; - BLENDFUNCTION blend; - - BYTE r, g, b; - COLORREF noKeyColor; - - static LRESULT CALLBACK _PsShadowWindows::wndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam); - - }; - _PsShadowWindows _psShadowWindows; - - LRESULT CALLBACK _PsShadowWindows::wndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { - if (finished) return DefWindowProc(hwnd, msg, wParam, lParam); - - int i; - for (i = 0; i < 4; ++i) { - if (_psShadowWindows.hwnds[i] && hwnd == _psShadowWindows.hwnds[i]) { - break; - } - } - if (i == 4) return DefWindowProc(hwnd, msg, wParam, lParam); - - switch (msg) { - case WM_CLOSE: - App::wnd()->close(); - break; - - case WM_NCHITTEST: { - int32 xPos = GET_X_LPARAM(lParam), yPos = GET_Y_LPARAM(lParam); - switch (i) { - case 0: return HTTOP; - case 1: return (yPos < _psShadowWindows._y + _psSize) ? HTTOPRIGHT : ((yPos >= _psShadowWindows._y + _psShadowWindows._h - _psSize) ? HTBOTTOMRIGHT : HTRIGHT); - case 2: return HTBOTTOM; - case 3: return (yPos < _psShadowWindows._y + _psSize) ? HTTOPLEFT : ((yPos >= _psShadowWindows._y + _psShadowWindows._h - _psSize) ? HTBOTTOMLEFT : HTLEFT); - } - return HTTRANSPARENT; - } break; - - case WM_NCACTIVATE: return DefWindowProc(hwnd, msg, wParam, lParam); - case WM_NCLBUTTONDOWN: - case WM_NCLBUTTONUP: - case WM_NCLBUTTONDBLCLK: - case WM_NCMBUTTONDOWN: - case WM_NCMBUTTONUP: - case WM_NCMBUTTONDBLCLK: - case WM_NCRBUTTONDOWN: - case WM_NCRBUTTONUP: - case WM_NCRBUTTONDBLCLK: - case WM_NCXBUTTONDOWN: - case WM_NCXBUTTONUP: - case WM_NCXBUTTONDBLCLK: - case WM_NCMOUSEHOVER: - case WM_NCMOUSELEAVE: - case WM_NCMOUSEMOVE: - case WM_NCPOINTERUPDATE: - case WM_NCPOINTERDOWN: - case WM_NCPOINTERUP: - if (App::wnd() && App::wnd()->psHwnd()) { - if (msg == WM_NCLBUTTONDOWN) { - ::SetForegroundWindow(App::wnd()->psHwnd()); - } - LRESULT res = SendMessage(App::wnd()->psHwnd(), msg, wParam, lParam); - return res; - } - return 0; - break; - case WM_ACTIVATE: - if (App::wnd() && App::wnd()->psHwnd() && wParam == WA_ACTIVE) { - if ((HWND)lParam != App::wnd()->psHwnd()) { - ::SetForegroundWindow(hwnd); - ::SetWindowPos(App::wnd()->psHwnd(), hwnd, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE); - } - } - return DefWindowProc(hwnd, msg, wParam, lParam); - break; - default: - return DefWindowProc(hwnd, msg, wParam, lParam); - } - return 0; - } - - QColor _shActive(0, 0, 0), _shInactive(0, 0, 0); - - typedef HRESULT (FAR STDAPICALLTYPE *f_setWindowTheme)(HWND hWnd, LPCWSTR pszSubAppName, LPCWSTR pszSubIdList); - f_setWindowTheme setWindowTheme = 0; - - typedef HRESULT (FAR STDAPICALLTYPE *f_openAs_RunDLL)(HWND hWnd, HINSTANCE hInstance, LPCWSTR lpszCmdLine, int nCmdShow); - f_openAs_RunDLL openAs_RunDLL = 0; - - typedef HRESULT (FAR STDAPICALLTYPE *f_shOpenWithDialog)(HWND hwndParent, const OPENASINFO *poainfo); - f_shOpenWithDialog shOpenWithDialog = 0; - - typedef HRESULT (FAR STDAPICALLTYPE *f_shAssocEnumHandlers)(PCWSTR pszExtra, ASSOC_FILTER afFilter, IEnumAssocHandlers **ppEnumHandler); - f_shAssocEnumHandlers shAssocEnumHandlers = 0; - - typedef HRESULT (FAR STDAPICALLTYPE *f_shCreateItemFromParsingName)(PCWSTR pszPath, IBindCtx *pbc, REFIID riid, void **ppv); - f_shCreateItemFromParsingName shCreateItemFromParsingName = 0; - - typedef BOOL (FAR STDAPICALLTYPE *f_wtsRegisterSessionNotification)(HWND hWnd, DWORD dwFlags); - f_wtsRegisterSessionNotification wtsRegisterSessionNotification = 0; - - typedef BOOL (FAR STDAPICALLTYPE *f_wtsUnRegisterSessionNotification)(HWND hWnd); - f_wtsUnRegisterSessionNotification wtsUnRegisterSessionNotification = 0; - - typedef HRESULT (FAR STDAPICALLTYPE *f_shQueryUserNotificationState)(QUERY_USER_NOTIFICATION_STATE *pquns); - f_shQueryUserNotificationState shQueryUserNotificationState = 0; - - typedef HRESULT (FAR STDAPICALLTYPE *f_setCurrentProcessExplicitAppUserModelID)(__in PCWSTR AppID); - f_setCurrentProcessExplicitAppUserModelID setCurrentProcessExplicitAppUserModelID = 0; - - typedef HRESULT (FAR STDAPICALLTYPE *f_roGetActivationFactory)(_In_ HSTRING activatableClassId, _In_ REFIID iid, _COM_Outptr_ void ** factory); - f_roGetActivationFactory roGetActivationFactory = 0; - - typedef HRESULT (FAR STDAPICALLTYPE *f_windowsCreateStringReference)(_In_reads_opt_(length + 1) PCWSTR sourceString, UINT32 length, _Out_ HSTRING_HEADER * hstringHeader, _Outptr_result_maybenull_ _Result_nullonfailure_ HSTRING * string); - f_windowsCreateStringReference windowsCreateStringReference = 0; - - typedef HRESULT (FAR STDAPICALLTYPE *f_windowsDeleteString)(_In_opt_ HSTRING string); - f_windowsDeleteString windowsDeleteString = 0; - - typedef HRESULT (FAR STDAPICALLTYPE *f_propVariantToString)(_In_ REFPROPVARIANT propvar, _Out_writes_(cch) PWSTR psz, _In_ UINT cch); - f_propVariantToString propVariantToString = 0; + //ComPtr taskbarList; + + //ComPtr toastNotificationManager; + //ComPtr toastNotifier; + //ComPtr toastNotificationFactory; + //struct ToastNotificationPtr { + // ToastNotificationPtr() { + // } + // ToastNotificationPtr(const ComPtr &ptr) : p(ptr) { + // } + // ComPtr p; + //}; + //typedef QMap > ToastNotifications; + //ToastNotifications toastNotifications; + //struct ToastImage { + // uint64 until; + // QString path; + //}; + //typedef QMap ToastImages; + //ToastImages toastImages; + //bool ToastImageSavedFlag = false; + + //HWND createTaskbarHider() { + // HINSTANCE appinst = (HINSTANCE)GetModuleHandle(0); + // HWND hWnd = 0; + + // QString cn = QString("TelegramTaskbarHider"); + // LPCWSTR _cn = (LPCWSTR)cn.utf16(); + // WNDCLASSEX wc; + + // wc.cbSize = sizeof(wc); + // wc.style = 0; + // wc.lpfnWndProc = DefWindowProc; + // wc.cbClsExtra = 0; + // wc.cbWndExtra = 0; + // wc.hInstance = appinst; + // wc.hIcon = 0; + // wc.hCursor = 0; + // wc.hbrBackground = 0; + // wc.lpszMenuName = NULL; + // wc.lpszClassName = _cn; + // wc.hIconSm = 0; + // if (!RegisterClassEx(&wc)) { + // DEBUG_LOG(("Application Error: could not register taskbar hider window class, error: %1").arg(GetLastError())); + // return hWnd; + // } + + // hWnd = CreateWindowEx(WS_EX_TOOLWINDOW, _cn, 0, WS_POPUP, 0, 0, 0, 0, 0, 0, appinst, 0); + // if (!hWnd) { + // DEBUG_LOG(("Application Error: could not create taskbar hider window class, error: %1").arg(GetLastError())); + // return hWnd; + // } + // return hWnd; + //} + + //enum { + // _PsShadowMoved = 0x01, + // _PsShadowResized = 0x02, + // _PsShadowShown = 0x04, + // _PsShadowHidden = 0x08, + // _PsShadowActivate = 0x10, + //}; + + //enum { + // _PsInitHor = 0x01, + // _PsInitVer = 0x02, + //}; + + //int32 _psSize = 0; + //class _PsShadowWindows { + //public: + + // _PsShadowWindows() : screenDC(0), max_w(0), max_h(0), _x(0), _y(0), _w(0), _h(0), hidden(true), r(0), g(0), b(0), noKeyColor(RGB(255, 255, 255)) { + // for (int i = 0; i < 4; ++i) { + // dcs[i] = 0; + // bitmaps[i] = 0; + // hwnds[i] = 0; + // } + // } + + // void setColor(QColor c) { + // r = c.red(); + // g = c.green(); + // b = c.blue(); + + // if (!hwnds[0]) return; + // Gdiplus::SolidBrush brush(Gdiplus::Color(_alphas[0], r, g, b)); + // for (int i = 0; i < 4; ++i) { + // Gdiplus::Graphics graphics(dcs[i]); + // graphics.SetCompositingMode(Gdiplus::CompositingModeSourceCopy); + // if ((i % 2) && _h || !(i % 2) && _w) { + // graphics.FillRectangle(&brush, 0, 0, (i % 2) ? _size : _w, (i % 2) ? _h : _size); + // } + // } + // initCorners(); + + // _x = _y = _w = _h = 0; + // update(_PsShadowMoved | _PsShadowResized); + // } + + // bool init(QColor c) { + // style::rect topLeft = st::wndShadow; + // _fullsize = topLeft.width(); + // _shift = st::wndShadowShift; + // QImage cornersImage(_fullsize, _fullsize, QImage::Format_ARGB32_Premultiplied); + // { + // QPainter p(&cornersImage); + // p.drawPixmap(QPoint(0, 0), App::sprite(), topLeft); + // } + // if (rtl()) cornersImage = cornersImage.mirrored(true, false); + // uchar *bits = cornersImage.bits(); + // if (bits) { + // for ( + // quint32 *p = (quint32*)bits, *end = (quint32*)(bits + cornersImage.byteCount()); + // p < end; + // ++p + // ) { + // *p = (*p ^ 0x00ffffff) << 24; + // } + // } + + // _metaSize = _fullsize + 2 * _shift; + // _alphas.reserve(_metaSize); + // _colors.reserve(_metaSize * _metaSize); + // for (int32 j = 0; j < _metaSize; ++j) { + // for (int32 i = 0; i < _metaSize; ++i) { + // _colors.push_back((i < 2 * _shift || j < 2 * _shift) ? 1 : qMax(BYTE(1), BYTE(cornersImage.pixel(QPoint(i - 2 * _shift, j - 2 * _shift)) >> 24))); + // } + // } + // uchar prev = 0; + // for (int32 i = 0; i < _metaSize; ++i) { + // uchar a = _colors[(_metaSize - 1) * _metaSize + i]; + // if (a < prev) break; + + // _alphas.push_back(a); + // prev = a; + // } + // _psSize = _size = _alphas.size() - 2 * _shift; + + // setColor(c); + + // Gdiplus::GdiplusStartupInput gdiplusStartupInput; + // ULONG_PTR gdiplusToken; + // Gdiplus::Status gdiRes = Gdiplus::GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL); + + // if (gdiRes != Gdiplus::Ok) { + // LOG(("Application Error: could not init GDI+, error: %1").arg((int)gdiRes)); + // return false; + // } + // blend.AlphaFormat = AC_SRC_ALPHA; + // blend.SourceConstantAlpha = 255; + // blend.BlendFlags = 0; + // blend.BlendOp = AC_SRC_OVER; + + // screenDC = GetDC(0); + // if (!screenDC) { + // LOG(("Application Error: could not GetDC(0), error: %2").arg(GetLastError())); + // return false; + // } + + // QRect avail(Sandbox::availableGeometry()); + // max_w = avail.width(); + // if (max_w < st::wndMinWidth) max_w = st::wndMinWidth; + // max_h = avail.height(); + // if (max_h < st::wndMinHeight) max_h = st::wndMinHeight; + + // HINSTANCE appinst = (HINSTANCE)GetModuleHandle(0); + // HWND hwnd = App::wnd() ? App::wnd()->psHwnd() : 0; + + // for (int i = 0; i < 4; ++i) { + // QString cn = QString("TelegramShadow%1").arg(i); + // LPCWSTR _cn = (LPCWSTR)cn.utf16(); + // WNDCLASSEX wc; + + // wc.cbSize = sizeof(wc); + // wc.style = 0; + // wc.lpfnWndProc = wndProc; + // wc.cbClsExtra = 0; + // wc.cbWndExtra = 0; + // wc.hInstance = appinst; + // wc.hIcon = 0; + // wc.hCursor = 0; + // wc.hbrBackground = 0; + // wc.lpszMenuName = NULL; + // wc.lpszClassName = _cn; + // wc.hIconSm = 0; + // if (!RegisterClassEx(&wc)) { + // LOG(("Application Error: could not register shadow window class %1, error: %2").arg(i).arg(GetLastError())); + // destroy(); + // return false; + // } + + // hwnds[i] = CreateWindowEx(WS_EX_LAYERED | WS_EX_TOOLWINDOW, _cn, 0, WS_POPUP, 0, 0, 0, 0, 0, 0, appinst, 0); + // if (!hwnds[i]) { + // LOG(("Application Error: could not create shadow window class %1, error: %2").arg(i).arg(GetLastError())); + // destroy(); + // return false; + // } + // SetWindowLong(hwnds[i], GWL_HWNDPARENT, (LONG)hwnd); + + // dcs[i] = CreateCompatibleDC(screenDC); + // if (!dcs[i]) { + // LOG(("Application Error: could not create dc for shadow window class %1, error: %2").arg(i).arg(GetLastError())); + // destroy(); + // return false; + // } + + // bitmaps[i] = CreateCompatibleBitmap(screenDC, (i % 2) ? _size : max_w, (i % 2) ? max_h : _size); + // if (!bitmaps[i]) { + // LOG(("Application Error: could not create bitmap for shadow window class %1, error: %2").arg(i).arg(GetLastError())); + // destroy(); + // return false; + // } + + // SelectObject(dcs[i], bitmaps[i]); + // } + + // initCorners(); + // return true; + // } + + // void initCorners(int directions = (_PsInitHor | _PsInitVer)) { + // bool hor = (directions & _PsInitHor), ver = (directions & _PsInitVer); + // Gdiplus::Graphics graphics0(dcs[0]), graphics1(dcs[1]), graphics2(dcs[2]), graphics3(dcs[3]); + // graphics0.SetCompositingMode(Gdiplus::CompositingModeSourceCopy); + // graphics1.SetCompositingMode(Gdiplus::CompositingModeSourceCopy); + // graphics2.SetCompositingMode(Gdiplus::CompositingModeSourceCopy); + // graphics3.SetCompositingMode(Gdiplus::CompositingModeSourceCopy); + + // Gdiplus::SolidBrush brush(Gdiplus::Color(_alphas[0], r, g, b)); + // if (hor) graphics0.FillRectangle(&brush, 0, 0, _fullsize - (_size - _shift), 2 * _shift); + + // if (ver) { + // graphics1.FillRectangle(&brush, 0, 0, _size, 2 * _shift); + // graphics3.FillRectangle(&brush, 0, 0, _size, 2 * _shift); + // graphics1.FillRectangle(&brush, _size - _shift, 2 * _shift, _shift, _fullsize); + // graphics3.FillRectangle(&brush, 0, 2 * _shift, _shift, _fullsize); + // } + + // if (hor) { + // for (int j = 2 * _shift; j < _size; ++j) { + // for (int k = 0; k < _fullsize - (_size - _shift); ++k) { + // brush.SetColor(Gdiplus::Color(_colors[j * _metaSize + k + (_size + _shift)], r, g, b)); + // graphics0.FillRectangle(&brush, k, j, 1, 1); + // graphics2.FillRectangle(&brush, k, _size - (j - 2 * _shift) - 1, 1, 1); + // } + // } + // for (int j = _size; j < _size + 2 * _shift; ++j) { + // for (int k = 0; k < _fullsize - (_size - _shift); ++k) { + // brush.SetColor(Gdiplus::Color(_colors[j * _metaSize + k + (_size + _shift)], r, g, b)); + // graphics2.FillRectangle(&brush, k, _size - (j - 2 * _shift) - 1, 1, 1); + // } + // } + // } + // if (ver) { + // for (int j = 2 * _shift; j < _fullsize + 2 * _shift; ++j) { + // for (int k = _shift; k < _size; ++k) { + // brush.SetColor(Gdiplus::Color(_colors[j * _metaSize + (k + _shift)], r, g, b)); + // graphics1.FillRectangle(&brush, _size - k - 1, j, 1, 1); + // graphics3.FillRectangle(&brush, k, j, 1, 1); + // } + // } + // } + // } + // void verCorners(int h, Gdiplus::Graphics *pgraphics1, Gdiplus::Graphics *pgraphics3) { + // Gdiplus::SolidBrush brush(Gdiplus::Color(_alphas[0], r, g, b)); + // pgraphics1->FillRectangle(&brush, _size - _shift, h - _fullsize, _shift, _fullsize); + // pgraphics3->FillRectangle(&brush, 0, h - _fullsize, _shift, _fullsize); + // for (int j = 0; j < _fullsize; ++j) { + // for (int k = _shift; k < _size; ++k) { + // brush.SetColor(Gdiplus::Color(_colors[(j + 2 * _shift) * _metaSize + k + _shift], r, g, b)); + // pgraphics1->FillRectangle(&brush, _size - k - 1, h - j - 1, 1, 1); + // pgraphics3->FillRectangle(&brush, k, h - j - 1, 1, 1); + // } + // } + // } + // void horCorners(int w, Gdiplus::Graphics *pgraphics0, Gdiplus::Graphics *pgraphics2) { + // Gdiplus::SolidBrush brush(Gdiplus::Color(_alphas[0], r, g, b)); + // pgraphics0->FillRectangle(&brush, w - 2 * _size - (_fullsize - (_size - _shift)), 0, _fullsize - (_size - _shift), 2 * _shift); + // for (int j = 2 * _shift; j < _size; ++j) { + // for (int k = 0; k < _fullsize - (_size - _shift); ++k) { + // brush.SetColor(Gdiplus::Color(_colors[j * _metaSize + k + (_size + _shift)], r, g, b)); + // pgraphics0->FillRectangle(&brush, w - 2 * _size - k - 1, j, 1, 1); + // pgraphics2->FillRectangle(&brush, w - 2 * _size - k - 1, _size - (j - 2 * _shift) - 1, 1, 1); + // } + // } + // for (int j = _size; j < _size + 2 * _shift; ++j) { + // for (int k = 0; k < _fullsize - (_size - _shift); ++k) { + // brush.SetColor(Gdiplus::Color(_colors[j * _metaSize + k + (_size + _shift)], r, g, b)); + // pgraphics2->FillRectangle(&brush, w - 2 * _size - k - 1, _size - (j - 2 * _shift) - 1, 1, 1); + // } + // } + // } + + // void update(int changes, WINDOWPOS *pos = 0) { + // HWND hwnd = App::wnd() ? App::wnd()->psHwnd() : 0; + // if (!hwnd || !hwnds[0]) return; + + // if (changes == _PsShadowActivate) { + // for (int i = 0; i < 4; ++i) { + // SetWindowPos(hwnds[i], hwnd, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE); + // } + // return; + // } + + // if (changes & _PsShadowHidden) { + // if (!hidden) { + // for (int i = 0; i < 4; ++i) { + // hidden = true; + // ShowWindow(hwnds[i], SW_HIDE); + // } + // } + // return; + // } + // if (!App::wnd()->psPosInited()) return; + + // int x = _x, y = _y, w = _w, h = _h; + // if (pos && (!(pos->flags & SWP_NOMOVE) || !(pos->flags & SWP_NOSIZE) || !(pos->flags & SWP_NOREPOSITION))) { + // if (!(pos->flags & SWP_NOMOVE)) { + // x = pos->x - _size; + // y = pos->y - _size; + // } else if (pos->flags & SWP_NOSIZE) { + // for (int i = 0; i < 4; ++i) { + // SetWindowPos(hwnds[i], hwnd, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE); + // } + // return; + // } + // if (!(pos->flags & SWP_NOSIZE)) { + // w = pos->cx + 2 * _size; + // h = pos->cy + 2 * _size; + // } + // } else { + // RECT r; + // GetWindowRect(hwnd, &r); + // x = r.left - _size; + // y = r.top - _size; + // w = r.right + _size - x; + // h = r.bottom + _size - y; + // } + // if (h < 2 * _fullsize + 2 * _shift) { + // h = 2 * _fullsize + 2 * _shift; + // } + // if (w < 2 * (_fullsize + _shift)) { + // w = 2 * (_fullsize + _shift); + // } + + // if (w != _w) { + // int from = (_w > 2 * (_fullsize + _shift)) ? (_w - _size - _fullsize - _shift) : (_fullsize - (_size - _shift)); + // int to = w - _size - _fullsize - _shift; + // if (w > max_w) { + // from = _fullsize - (_size - _shift); + // max_w *= 2; + // for (int i = 0; i < 4; i += 2) { + // DeleteObject(bitmaps[i]); + // bitmaps[i] = CreateCompatibleBitmap(screenDC, max_w, _size); + // SelectObject(dcs[i], bitmaps[i]); + // } + // initCorners(_PsInitHor); + // } + // Gdiplus::Graphics graphics0(dcs[0]), graphics2(dcs[2]); + // graphics0.SetCompositingMode(Gdiplus::CompositingModeSourceCopy); + // graphics2.SetCompositingMode(Gdiplus::CompositingModeSourceCopy); + // Gdiplus::SolidBrush brush(Gdiplus::Color(_alphas[0], r, g, b)); + // if (to > from) { + // graphics0.FillRectangle(&brush, from, 0, to - from, 2 * _shift); + // for (int i = 2 * _shift; i < _size; ++i) { + // Gdiplus::Pen pen(Gdiplus::Color(_alphas[i], r, g, b)); + // graphics0.DrawLine(&pen, from, i, to, i); + // graphics2.DrawLine(&pen, from, _size - (i - 2 * _shift) - 1, to, _size - (i - 2 * _shift) - 1); + // } + // for (int i = _size; i < _size + 2 * _shift; ++i) { + // Gdiplus::Pen pen(Gdiplus::Color(_alphas[i], r, g, b)); + // graphics2.DrawLine(&pen, from, _size - (i - 2 * _shift) - 1, to, _size - (i - 2 * _shift) - 1); + // } + // } + // if (_w > w) { + // graphics0.FillRectangle(&brush, w - _size - _fullsize - _shift, 0, _fullsize - (_size - _shift), _size); + // graphics2.FillRectangle(&brush, w - _size - _fullsize - _shift, 0, _fullsize - (_size - _shift), _size); + // } + // horCorners(w, &graphics0, &graphics2); + // POINT p0 = { x + _size, y }, p2 = { x + _size, y + h - _size }, f = { 0, 0 }; + // SIZE s = { w - 2 * _size, _size }; + // updateWindow(0, &p0, &s); + // updateWindow(2, &p2, &s); + // } else if (x != _x || y != _y) { + // POINT p0 = { x + _size, y }, p2 = { x + _size, y + h - _size }; + // updateWindow(0, &p0); + // updateWindow(2, &p2); + // } else if (h != _h) { + // POINT p2 = { x + _size, y + h - _size }; + // updateWindow(2, &p2); + // } + + // if (h != _h) { + // int from = (_h > 2 * _fullsize + 2 * _shift) ? (_h - _fullsize) : (_fullsize + 2 * _shift); + // int to = h - _fullsize; + // if (h > max_h) { + // from = (_fullsize + 2 * _shift); + // max_h *= 2; + // for (int i = 1; i < 4; i += 2) { + // DeleteObject(bitmaps[i]); + // bitmaps[i] = CreateCompatibleBitmap(dcs[i], _size, max_h); + // SelectObject(dcs[i], bitmaps[i]); + // } + // initCorners(_PsInitVer); + // } + // Gdiplus::Graphics graphics1(dcs[1]), graphics3(dcs[3]); + // graphics1.SetCompositingMode(Gdiplus::CompositingModeSourceCopy); + // graphics3.SetCompositingMode(Gdiplus::CompositingModeSourceCopy); + + // Gdiplus::SolidBrush brush(Gdiplus::Color(_alphas[0], r, g, b)); + // if (to > from) { + // graphics1.FillRectangle(&brush, _size - _shift, from, _shift, to - from); + // graphics3.FillRectangle(&brush, 0, from, _shift, to - from); + // for (int i = 2 * _shift; i < _size + _shift; ++i) { + // Gdiplus::Pen pen(Gdiplus::Color(_alphas[i], r, g, b)); + // graphics1.DrawLine(&pen, _size + _shift - i - 1, from, _size + _shift - i - 1, to); + // graphics3.DrawLine(&pen, i - _shift, from, i - _shift, to); + // } + // } + // if (_h > h) { + // graphics1.FillRectangle(&brush, 0, h - _fullsize, _size, _fullsize); + // graphics3.FillRectangle(&brush, 0, h - _fullsize, _size, _fullsize); + // } + // verCorners(h, &graphics1, &graphics3); + + // POINT p1 = {x + w - _size, y}, p3 = {x, y}, f = {0, 0}; + // SIZE s = { _size, h }; + // updateWindow(1, &p1, &s); + // updateWindow(3, &p3, &s); + // } else if (x != _x || y != _y) { + // POINT p1 = { x + w - _size, y }, p3 = { x, y }; + // updateWindow(1, &p1); + // updateWindow(3, &p3); + // } else if (w != _w) { + // POINT p1 = { x + w - _size, y }; + // updateWindow(1, &p1); + // } + // _x = x; + // _y = y; + // _w = w; + // _h = h; + + // if (hidden && (changes & _PsShadowShown)) { + // for (int i = 0; i < 4; ++i) { + // SetWindowPos(hwnds[i], hwnd, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW | SWP_NOACTIVATE); + // } + // hidden = false; + // } + // } + + // void updateWindow(int i, POINT *p, SIZE *s = 0) { + // static POINT f = {0, 0}; + // if (s) { + // UpdateLayeredWindow(hwnds[i], (s ? screenDC : 0), p, s, (s ? dcs[i] : 0), (s ? (&f) : 0), noKeyColor, &blend, ULW_ALPHA); + // } else { + // SetWindowPos(hwnds[i], 0, p->x, p->y, 0, 0, SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOZORDER); + // } + // } + + // void destroy() { + // for (int i = 0; i < 4; ++i) { + // if (dcs[i]) DeleteDC(dcs[i]); + // if (bitmaps[i]) DeleteObject(bitmaps[i]); + // if (hwnds[i]) DestroyWindow(hwnds[i]); + // dcs[i] = 0; + // bitmaps[i] = 0; + // hwnds[i] = 0; + // } + // if (screenDC) ReleaseDC(0, screenDC); + // } + + //private: + + // int _x, _y, _w, _h; + // int _metaSize, _fullsize, _size, _shift; + // QVector _alphas, _colors; + + // bool hidden; + + // HWND hwnds[4]; + // HDC dcs[4], screenDC; + // HBITMAP bitmaps[4]; + // int max_w, max_h; + // BLENDFUNCTION blend; + + // BYTE r, g, b; + // COLORREF noKeyColor; + + // static LRESULT CALLBACK _PsShadowWindows::wndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam); + + //}; + //_PsShadowWindows _psShadowWindows; + + //LRESULT CALLBACK _PsShadowWindows::wndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { + // if (finished) return DefWindowProc(hwnd, msg, wParam, lParam); + + // int i; + // for (i = 0; i < 4; ++i) { + // if (_psShadowWindows.hwnds[i] && hwnd == _psShadowWindows.hwnds[i]) { + // break; + // } + // } + // if (i == 4) return DefWindowProc(hwnd, msg, wParam, lParam); + + // switch (msg) { + // case WM_CLOSE: + // App::wnd()->close(); + // break; + + // case WM_NCHITTEST: { + // int32 xPos = GET_X_LPARAM(lParam), yPos = GET_Y_LPARAM(lParam); + // switch (i) { + // case 0: return HTTOP; + // case 1: return (yPos < _psShadowWindows._y + _psSize) ? HTTOPRIGHT : ((yPos >= _psShadowWindows._y + _psShadowWindows._h - _psSize) ? HTBOTTOMRIGHT : HTRIGHT); + // case 2: return HTBOTTOM; + // case 3: return (yPos < _psShadowWindows._y + _psSize) ? HTTOPLEFT : ((yPos >= _psShadowWindows._y + _psShadowWindows._h - _psSize) ? HTBOTTOMLEFT : HTLEFT); + // } + // return HTTRANSPARENT; + // } break; + + // case WM_NCACTIVATE: return DefWindowProc(hwnd, msg, wParam, lParam); + // case WM_NCLBUTTONDOWN: + // case WM_NCLBUTTONUP: + // case WM_NCLBUTTONDBLCLK: + // case WM_NCMBUTTONDOWN: + // case WM_NCMBUTTONUP: + // case WM_NCMBUTTONDBLCLK: + // case WM_NCRBUTTONDOWN: + // case WM_NCRBUTTONUP: + // case WM_NCRBUTTONDBLCLK: + // case WM_NCXBUTTONDOWN: + // case WM_NCXBUTTONUP: + // case WM_NCXBUTTONDBLCLK: + // case WM_NCMOUSEHOVER: + // case WM_NCMOUSELEAVE: + // case WM_NCMOUSEMOVE: + // case WM_NCPOINTERUPDATE: + // case WM_NCPOINTERDOWN: + // case WM_NCPOINTERUP: + // if (App::wnd() && App::wnd()->psHwnd()) { + // if (msg == WM_NCLBUTTONDOWN) { + // ::SetForegroundWindow(App::wnd()->psHwnd()); + // } + // LRESULT res = SendMessage(App::wnd()->psHwnd(), msg, wParam, lParam); + // return res; + // } + // return 0; + // break; + // case WM_ACTIVATE: + // if (App::wnd() && App::wnd()->psHwnd() && wParam == WA_ACTIVE) { + // if ((HWND)lParam != App::wnd()->psHwnd()) { + // ::SetForegroundWindow(hwnd); + // ::SetWindowPos(App::wnd()->psHwnd(), hwnd, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE); + // } + // } + // return DefWindowProc(hwnd, msg, wParam, lParam); + // break; + // default: + // return DefWindowProc(hwnd, msg, wParam, lParam); + // } + // return 0; + //} + + //QColor _shActive(0, 0, 0), _shInactive(0, 0, 0); + + //typedef HRESULT (FAR STDAPICALLTYPE *f_setWindowTheme)(HWND hWnd, LPCWSTR pszSubAppName, LPCWSTR pszSubIdList); + //f_setWindowTheme setWindowTheme = 0; + + //typedef HRESULT (FAR STDAPICALLTYPE *f_openAs_RunDLL)(HWND hWnd, HINSTANCE hInstance, LPCWSTR lpszCmdLine, int nCmdShow); + //f_openAs_RunDLL openAs_RunDLL = 0; + + //typedef HRESULT (FAR STDAPICALLTYPE *f_shOpenWithDialog)(HWND hwndParent, const OPENASINFO *poainfo); + //f_shOpenWithDialog shOpenWithDialog = 0; + + //typedef HRESULT (FAR STDAPICALLTYPE *f_shAssocEnumHandlers)(PCWSTR pszExtra, ASSOC_FILTER afFilter, IEnumAssocHandlers **ppEnumHandler); + //f_shAssocEnumHandlers shAssocEnumHandlers = 0; + + //typedef HRESULT (FAR STDAPICALLTYPE *f_shCreateItemFromParsingName)(PCWSTR pszPath, IBindCtx *pbc, REFIID riid, void **ppv); + //f_shCreateItemFromParsingName shCreateItemFromParsingName = 0; + + //typedef BOOL (FAR STDAPICALLTYPE *f_wtsRegisterSessionNotification)(HWND hWnd, DWORD dwFlags); + //f_wtsRegisterSessionNotification wtsRegisterSessionNotification = 0; + + //typedef BOOL (FAR STDAPICALLTYPE *f_wtsUnRegisterSessionNotification)(HWND hWnd); + //f_wtsUnRegisterSessionNotification wtsUnRegisterSessionNotification = 0; + + //typedef HRESULT (FAR STDAPICALLTYPE *f_shQueryUserNotificationState)(QUERY_USER_NOTIFICATION_STATE *pquns); + //f_shQueryUserNotificationState shQueryUserNotificationState = 0; + + //typedef HRESULT (FAR STDAPICALLTYPE *f_setCurrentProcessExplicitAppUserModelID)(__in PCWSTR AppID); + //f_setCurrentProcessExplicitAppUserModelID setCurrentProcessExplicitAppUserModelID = 0; + + //typedef HRESULT (FAR STDAPICALLTYPE *f_roGetActivationFactory)(_In_ HSTRING activatableClassId, _In_ REFIID iid, _COM_Outptr_ void ** factory); + //f_roGetActivationFactory roGetActivationFactory = 0; + + //typedef HRESULT (FAR STDAPICALLTYPE *f_windowsCreateStringReference)(_In_reads_opt_(length + 1) PCWSTR sourceString, UINT32 length, _Out_ HSTRING_HEADER * hstringHeader, _Outptr_result_maybenull_ _Result_nullonfailure_ HSTRING * string); + //f_windowsCreateStringReference windowsCreateStringReference = 0; + + //typedef HRESULT (FAR STDAPICALLTYPE *f_windowsDeleteString)(_In_opt_ HSTRING string); + //f_windowsDeleteString windowsDeleteString = 0; + + //typedef HRESULT (FAR STDAPICALLTYPE *f_propVariantToString)(_In_ REFPROPVARIANT propvar, _Out_writes_(cch) PWSTR psz, _In_ UINT cch); + //f_propVariantToString propVariantToString = 0; template bool loadFunction(HINSTANCE dll, LPCSTR name, TFunction &func) { @@ -735,63 +735,63 @@ namespace { setupPropSys(); setupCombase(); - useTheme = !!setWindowTheme; + //useTheme = !!setWindowTheme; } void setupUx() { - HINSTANCE procId = LoadLibrary(L"UXTHEME.DLL"); + //HINSTANCE procId = LoadLibrary(L"UXTHEME.DLL"); - loadFunction(procId, "SetWindowTheme", setWindowTheme); + //loadFunction(procId, "SetWindowTheme", setWindowTheme); } void setupShell() { - HINSTANCE procId = LoadLibrary(L"SHELL32.DLL"); - setupOpenWith(procId); - setupOpenAs(procId); - setupShellapi(procId); - setupAppUserModel(procId); + //HINSTANCE procId = LoadLibrary(L"SHELL32.DLL"); + //setupOpenWith(procId); + //setupOpenAs(procId); + //setupShellapi(procId); + //setupAppUserModel(procId); } void setupOpenWith(HINSTANCE procId) { - if (!loadFunction(procId, "SHAssocEnumHandlers", shAssocEnumHandlers)) return; - if (!loadFunction(procId, "SHCreateItemFromParsingName", shCreateItemFromParsingName)) return; - useOpenWith = true; + //if (!loadFunction(procId, "SHAssocEnumHandlers", shAssocEnumHandlers)) return; + //if (!loadFunction(procId, "SHCreateItemFromParsingName", shCreateItemFromParsingName)) return; + //useOpenWith = true; } void setupOpenAs(HINSTANCE procId) { - if (!loadFunction(procId, "SHOpenWithDialog", shOpenWithDialog) && !loadFunction(procId, "OpenAs_RunDLLW", openAs_RunDLL)) return; - useOpenAs = true; + //if (!loadFunction(procId, "SHOpenWithDialog", shOpenWithDialog) && !loadFunction(procId, "OpenAs_RunDLLW", openAs_RunDLL)) return; + //useOpenAs = true; } void setupShellapi(HINSTANCE procId) { - if (!loadFunction(procId, "SHQueryUserNotificationState", shQueryUserNotificationState)) return; - useShellapi = true; + //if (!loadFunction(procId, "SHQueryUserNotificationState", shQueryUserNotificationState)) return; + //useShellapi = true; } void setupAppUserModel(HINSTANCE procId) { - if (!loadFunction(procId, "SetCurrentProcessExplicitAppUserModelID", setCurrentProcessExplicitAppUserModelID)) return; + //if (!loadFunction(procId, "SetCurrentProcessExplicitAppUserModelID", setCurrentProcessExplicitAppUserModelID)) return; } void setupWtsapi() { - HINSTANCE procId = LoadLibrary(L"WTSAPI32.DLL"); + //HINSTANCE procId = LoadLibrary(L"WTSAPI32.DLL"); - if (!loadFunction(procId, "WTSRegisterSessionNotification", wtsRegisterSessionNotification)) return; - if (!loadFunction(procId, "WTSUnRegisterSessionNotification", wtsUnRegisterSessionNotification)) return; - useWtsapi = true; + //if (!loadFunction(procId, "WTSRegisterSessionNotification", wtsRegisterSessionNotification)) return; + //if (!loadFunction(procId, "WTSUnRegisterSessionNotification", wtsUnRegisterSessionNotification)) return; + //useWtsapi = true; } void setupCombase() { - if (!setCurrentProcessExplicitAppUserModelID) return; + //if (!setCurrentProcessExplicitAppUserModelID) return; - HINSTANCE procId = LoadLibrary(L"COMBASE.DLL"); - setupToast(procId); + //HINSTANCE procId = LoadLibrary(L"COMBASE.DLL"); + //setupToast(procId); } void setupPropSys() { - HINSTANCE procId = LoadLibrary(L"PROPSYS.DLL"); - if (!loadFunction(procId, "PropVariantToString", propVariantToString)) return; + //HINSTANCE procId = LoadLibrary(L"PROPSYS.DLL"); + //if (!loadFunction(procId, "PropVariantToString", propVariantToString)) return; } void setupToast(HINSTANCE procId) { - if (!propVariantToString) return; - if (QSysInfo::windowsVersion() < QSysInfo::WV_WINDOWS8) return; - if (!loadFunction(procId, "RoGetActivationFactory", roGetActivationFactory)) return; + //if (!propVariantToString) return; + //if (QSysInfo::windowsVersion() < QSysInfo::WV_WINDOWS8) return; + //if (!loadFunction(procId, "RoGetActivationFactory", roGetActivationFactory)) return; - HINSTANCE otherProcId = LoadLibrary(L"api-ms-win-core-winrt-string-l1-1-0.dll"); - if (!loadFunction(otherProcId, "WindowsCreateStringReference", windowsCreateStringReference)) return; - if (!loadFunction(otherProcId, "WindowsDeleteString", windowsDeleteString)) return; + //HINSTANCE otherProcId = LoadLibrary(L"api-ms-win-core-winrt-string-l1-1-0.dll"); + //if (!loadFunction(otherProcId, "WindowsCreateStringReference", windowsCreateStringReference)) return; + //if (!loadFunction(otherProcId, "WindowsDeleteString", windowsDeleteString)) return; - useToast = true; + //useToast = true; } }; _PsInitializer _psInitializer; @@ -817,12 +817,12 @@ namespace { } bool mainWindowEvent(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, LRESULT *result) { - if (tbCreatedMsgId && msg == tbCreatedMsgId) { - HRESULT hr = CoCreateInstance(CLSID_TaskbarList, nullptr, CLSCTX_ALL, IID_PPV_ARGS(&taskbarList)); - if (!SUCCEEDED(hr)) { - taskbarList.Reset(); - } - } + //if (tbCreatedMsgId && msg == tbCreatedMsgId) { + // HRESULT hr = CoCreateInstance(CLSID_TaskbarList, nullptr, CLSCTX_ALL, IID_PPV_ARGS(&taskbarList)); + // if (!SUCCEEDED(hr)) { + // taskbarList.Reset(); + // } + //} switch (msg) { case WM_TIMECHANGE: { @@ -845,12 +845,12 @@ namespace { if (LOWORD(wParam) == WA_CLICKACTIVE) { App::wnd()->inactivePress(true); } - if (LOWORD(wParam) != WA_INACTIVE) { - _psShadowWindows.setColor(_shActive); - _psShadowWindows.update(_PsShadowActivate); - } else { - _psShadowWindows.setColor(_shInactive); - } + //if (LOWORD(wParam) != WA_INACTIVE) { + // _psShadowWindows.setColor(_shActive); + // _psShadowWindows.update(_PsShadowActivate); + //} else { + // _psShadowWindows.setColor(_shInactive); + //} if (Global::started()) { QMetaObject::invokeMethod(App::wnd(), "updateCounter", Qt::QueuedConnection); App::wnd()->update(); @@ -859,39 +859,39 @@ namespace { case WM_NCPAINT: if (QSysInfo::WindowsVersion >= QSysInfo::WV_WINDOWS8) return false; *result = 0; return true; - case WM_NCCALCSIZE: { - WINDOWPLACEMENT wp; - wp.length = sizeof(WINDOWPLACEMENT); - if (GetWindowPlacement(hWnd, &wp) && wp.showCmd == SW_SHOWMAXIMIZED) { - LPNCCALCSIZE_PARAMS params = (LPNCCALCSIZE_PARAMS)lParam; - LPRECT r = (wParam == TRUE) ? ¶ms->rgrc[0] : (LPRECT)lParam; - HMONITOR hMonitor = MonitorFromPoint({ (r->left + r->right) / 2, (r->top + r->bottom) / 2 }, MONITOR_DEFAULTTONEAREST); - if (hMonitor) { - MONITORINFO mi; - mi.cbSize = sizeof(mi); - if (GetMonitorInfo(hMonitor, &mi)) { - *r = mi.rcWork; - } - } - } - *result = 0; - return true; - } + //case WM_NCCALCSIZE: { + // WINDOWPLACEMENT wp; + // wp.length = sizeof(WINDOWPLACEMENT); + // if (GetWindowPlacement(hWnd, &wp) && wp.showCmd == SW_SHOWMAXIMIZED) { + // LPNCCALCSIZE_PARAMS params = (LPNCCALCSIZE_PARAMS)lParam; + // LPRECT r = (wParam == TRUE) ? ¶ms->rgrc[0] : (LPRECT)lParam; + // HMONITOR hMonitor = MonitorFromPoint({ (r->left + r->right) / 2, (r->top + r->bottom) / 2 }, MONITOR_DEFAULTTONEAREST); + // if (hMonitor) { + // MONITORINFO mi; + // mi.cbSize = sizeof(mi); + // if (GetMonitorInfo(hMonitor, &mi)) { + // *r = mi.rcWork; + // } + // } + // } + // *result = 0; + // return true; + //} - case WM_NCACTIVATE: { - *result = DefWindowProc(hWnd, msg, wParam, -1); - } return true; + //case WM_NCACTIVATE: { + // *result = DefWindowProc(hWnd, msg, wParam, -1); + //} return true; - case WM_WINDOWPOSCHANGING: - case WM_WINDOWPOSCHANGED: { - WINDOWPLACEMENT wp; - wp.length = sizeof(WINDOWPLACEMENT); - if (GetWindowPlacement(hWnd, &wp) && (wp.showCmd == SW_SHOWMAXIMIZED || wp.showCmd == SW_SHOWMINIMIZED)) { - _psShadowWindows.update(_PsShadowHidden); - } else { - _psShadowWindows.update(_PsShadowMoved | _PsShadowResized, (WINDOWPOS*)lParam); - } - } return false; + //case WM_WINDOWPOSCHANGING: + //case WM_WINDOWPOSCHANGED: { + // WINDOWPLACEMENT wp; + // wp.length = sizeof(WINDOWPLACEMENT); + // if (GetWindowPlacement(hWnd, &wp) && (wp.showCmd == SW_SHOWMAXIMIZED || wp.showCmd == SW_SHOWMINIMIZED)) { + // _psShadowWindows.update(_PsShadowHidden); + // } else { + // _psShadowWindows.update(_PsShadowMoved | _PsShadowResized, (WINDOWPOS*)lParam); + // } + //} return false; case WM_SIZE: { if (App::wnd()) { @@ -908,93 +908,93 @@ namespace { App::wnd()->psUpdatedPosition(); } App::wnd()->psUpdateMargins(); - int changes = (wParam == SIZE_MINIMIZED || wParam == SIZE_MAXIMIZED) ? _PsShadowHidden : (_PsShadowResized | _PsShadowShown); - _psShadowWindows.update(changes); + //int changes = (wParam == SIZE_MINIMIZED || wParam == SIZE_MAXIMIZED) ? _PsShadowHidden : (_PsShadowResized | _PsShadowShown); + //_psShadowWindows.update(changes); } } } return false; - case WM_SHOWWINDOW: { - LONG style = GetWindowLong(hWnd, GWL_STYLE); - int changes = _PsShadowResized | ((wParam && !(style & (WS_MAXIMIZE | WS_MINIMIZE))) ? _PsShadowShown : _PsShadowHidden); - _psShadowWindows.update(changes); - } return false; + //case WM_SHOWWINDOW: { + // LONG style = GetWindowLong(hWnd, GWL_STYLE); + // int changes = _PsShadowResized | ((wParam && !(style & (WS_MAXIMIZE | WS_MINIMIZE))) ? _PsShadowShown : _PsShadowHidden); + // _psShadowWindows.update(changes); + //} return false; case WM_MOVE: { - _psShadowWindows.update(_PsShadowMoved); + //_psShadowWindows.update(_PsShadowMoved); App::wnd()->psUpdatedPosition(); } return false; - case WM_NCHITTEST: { - POINTS p = MAKEPOINTS(lParam); - RECT r; - GetWindowRect(hWnd, &r); - HitTestType res = App::wnd()->hitTest(QPoint(p.x - r.left + dleft, p.y - r.top + dtop)); - switch (res) { - case HitTestClient: - case HitTestSysButton: *result = HTCLIENT; break; - case HitTestIcon: *result = HTCAPTION; break; - case HitTestCaption: *result = HTCAPTION; break; - case HitTestTop: *result = HTTOP; break; - case HitTestTopRight: *result = HTTOPRIGHT; break; - case HitTestRight: *result = HTRIGHT; break; - case HitTestBottomRight: *result = HTBOTTOMRIGHT; break; - case HitTestBottom: *result = HTBOTTOM; break; - case HitTestBottomLeft: *result = HTBOTTOMLEFT; break; - case HitTestLeft: *result = HTLEFT; break; - case HitTestTopLeft: *result = HTTOPLEFT; break; - case HitTestNone: - default: *result = HTTRANSPARENT; break; - }; - } return true; + //case WM_NCHITTEST: { + // POINTS p = MAKEPOINTS(lParam); + // RECT r; + // GetWindowRect(hWnd, &r); + // HitTestType res = App::wnd()->hitTest(QPoint(p.x - r.left + dleft, p.y - r.top + dtop)); + // switch (res) { + // case HitTestClient: + // case HitTestSysButton: *result = HTCLIENT; break; + // case HitTestIcon: *result = HTCAPTION; break; + // case HitTestCaption: *result = HTCAPTION; break; + // case HitTestTop: *result = HTTOP; break; + // case HitTestTopRight: *result = HTTOPRIGHT; break; + // case HitTestRight: *result = HTRIGHT; break; + // case HitTestBottomRight: *result = HTBOTTOMRIGHT; break; + // case HitTestBottom: *result = HTBOTTOM; break; + // case HitTestBottomLeft: *result = HTBOTTOMLEFT; break; + // case HitTestLeft: *result = HTLEFT; break; + // case HitTestTopLeft: *result = HTTOPLEFT; break; + // case HitTestNone: + // default: *result = HTTRANSPARENT; break; + // }; + //} return true; - case WM_NCRBUTTONUP: { - SendMessage(hWnd, WM_SYSCOMMAND, SC_MOUSEMENU, lParam); - } return true; + //case WM_NCRBUTTONUP: { + // SendMessage(hWnd, WM_SYSCOMMAND, SC_MOUSEMENU, lParam); + //} return true; - case WM_NCLBUTTONDOWN: { - POINTS p = MAKEPOINTS(lParam); - RECT r; - GetWindowRect(hWnd, &r); - HitTestType res = App::wnd()->hitTest(QPoint(p.x - r.left + dleft, p.y - r.top + dtop)); - switch (res) { - case HitTestIcon: - if (menuHidden && getms() < menuHidden + 10) { - menuHidden = 0; - if (getms() < menuShown + GetDoubleClickTime()) { - App::wnd()->close(); - } - } else { - QRect icon = App::wnd()->iconRect(); - p.x = r.left - dleft + icon.left(); - p.y = r.top - dtop + icon.top() + icon.height(); - App::wnd()->psUpdateSysMenu(App::wnd()->windowHandle()->windowState()); - menuShown = getms(); - menuHidden = 0; - TrackPopupMenu(App::wnd()->psMenu(), TPM_LEFTALIGN | TPM_TOPALIGN | TPM_LEFTBUTTON, p.x, p.y, 0, hWnd, 0); - menuHidden = getms(); - } - return true; - }; - } return false; + //case WM_NCLBUTTONDOWN: { + // POINTS p = MAKEPOINTS(lParam); + // RECT r; + // GetWindowRect(hWnd, &r); + // HitTestType res = App::wnd()->hitTest(QPoint(p.x - r.left + dleft, p.y - r.top + dtop)); + // switch (res) { + // case HitTestIcon: + // if (menuHidden && getms() < menuHidden + 10) { + // menuHidden = 0; + // if (getms() < menuShown + GetDoubleClickTime()) { + // App::wnd()->close(); + // } + // } else { + // QRect icon = App::wnd()->iconRect(); + // p.x = r.left - dleft + icon.left(); + // p.y = r.top - dtop + icon.top() + icon.height(); + // App::wnd()->psUpdateSysMenu(App::wnd()->windowHandle()->windowState()); + // menuShown = getms(); + // menuHidden = 0; + // TrackPopupMenu(App::wnd()->psMenu(), TPM_LEFTALIGN | TPM_TOPALIGN | TPM_LEFTBUTTON, p.x, p.y, 0, hWnd, 0); + // menuHidden = getms(); + // } + // return true; + // }; + //} return false; - case WM_NCLBUTTONDBLCLK: { - POINTS p = MAKEPOINTS(lParam); - RECT r; - GetWindowRect(hWnd, &r); - HitTestType res = App::wnd()->hitTest(QPoint(p.x - r.left + dleft, p.y - r.top + dtop)); - switch (res) { - case HitTestIcon: App::wnd()->close(); return true; - }; - } return false; + //case WM_NCLBUTTONDBLCLK: { + // POINTS p = MAKEPOINTS(lParam); + // RECT r; + // GetWindowRect(hWnd, &r); + // HitTestType res = App::wnd()->hitTest(QPoint(p.x - r.left + dleft, p.y - r.top + dtop)); + // switch (res) { + // case HitTestIcon: App::wnd()->close(); return true; + // }; + //} return false; - case WM_SYSCOMMAND: { - if (wParam == SC_MOUSEMENU) { - POINTS p = MAKEPOINTS(lParam); - App::wnd()->psUpdateSysMenu(App::wnd()->windowHandle()->windowState()); - TrackPopupMenu(App::wnd()->psMenu(), TPM_LEFTALIGN | TPM_TOPALIGN | TPM_LEFTBUTTON, p.x, p.y, 0, hWnd, 0); - } - } return false; + //case WM_SYSCOMMAND: { + // if (wParam == SC_MOUSEMENU) { + // POINTS p = MAKEPOINTS(lParam); + // App::wnd()->psUpdateSysMenu(App::wnd()->windowHandle()->windowState()); + // TrackPopupMenu(App::wnd()->psMenu(), TPM_LEFTALIGN | TPM_TOPALIGN | TPM_LEFTBUTTON, p.x, p.y, 0, hWnd, 0); + // } + //} return false; case WM_COMMAND: { if (HIWORD(wParam)) return false; @@ -1015,9 +1015,21 @@ namespace { }; -PsMainWindow::PsMainWindow(QWidget *parent) : QMainWindow(parent), ps_hWnd(0), ps_menu(0), icon256(qsl(":/gui/art/icon256.png")), iconbig256(qsl(":/gui/art/iconbig256.png")), wndIcon(QPixmap::fromImage(icon256, Qt::ColorOnly)), - ps_iconBig(0), ps_iconSmall(0), ps_iconOverlay(0), trayIcon(0), trayIconMenu(0), posInited(false), ps_tbHider_hWnd(createTaskbarHider()) { - tbCreatedMsgId = RegisterWindowMessage(L"TaskbarButtonCreated"); +PsMainWindow::PsMainWindow(QWidget *parent) : QMainWindow(parent) +, ps_hWnd(0) +, ps_menu(0) +, icon256(qsl(":/gui/art/icon256.png")) +, iconbig256(qsl(":/gui/art/iconbig256.png")) +, wndIcon(QPixmap::fromImage(icon256, Qt::ColorOnly)) +, ps_iconBig(0) +, ps_iconSmall(0) +, ps_iconOverlay(0) +, trayIcon(0) +, trayIconMenu(0) +, posInited(false) +//, ps_tbHider_hWnd(createTaskbarHider()) +{ + //tbCreatedMsgId = RegisterWindowMessage(L"TaskbarButtonCreated"); connect(&ps_cleanNotifyPhotosTimer, SIGNAL(timeout()), this, SLOT(psCleanNotifyPhotos())); } @@ -1034,23 +1046,23 @@ void PsMainWindow::psCleanNotifyPhotosIn(int32 dt) { } void PsMainWindow::psCleanNotifyPhotos() { - uint64 ms = getms(true), minuntil = 0; - for (ToastImages::iterator i = toastImages.begin(); i != toastImages.end();) { - if (!i->until) { - ++i; - continue; - } - if (i->until <= ms) { - QFile(i->path).remove(); - i = toastImages.erase(i); - } else { - if (!minuntil || minuntil > i->until) { - minuntil = i->until; - } - ++i; - } - } - if (minuntil) psCleanNotifyPhotosIn(int32(minuntil - ms)); + //uint64 ms = getms(true), minuntil = 0; + //for (ToastImages::iterator i = toastImages.begin(); i != toastImages.end();) { + // if (!i->until) { + // ++i; + // continue; + // } + // if (i->until <= ms) { + // QFile(i->path).remove(); + // i = toastImages.erase(i); + // } else { + // if (!minuntil || minuntil > i->until) { + // minuntil = i->until; + // } + // ++i; + // } + //} + //if (minuntil) psCleanNotifyPhotosIn(int32(minuntil - ms)); } void PsMainWindow::psRefreshTaskbarIcon() { @@ -1091,19 +1103,19 @@ void PsMainWindow::psUpdateWorkmode() { switch (cWorkMode()) { case dbiwmWindowAndTray: { psSetupTrayIcon(); - HWND psOwner = (HWND)GetWindowLong(ps_hWnd, GWL_HWNDPARENT); - if (psOwner) { - SetWindowLong(ps_hWnd, GWL_HWNDPARENT, 0); - psRefreshTaskbarIcon(); - } + //HWND psOwner = (HWND)GetWindowLong(ps_hWnd, GWL_HWNDPARENT); + //if (psOwner) { + // SetWindowLong(ps_hWnd, GWL_HWNDPARENT, 0); + // psRefreshTaskbarIcon(); + //} } break; case dbiwmTrayOnly: { psSetupTrayIcon(); - HWND psOwner = (HWND)GetWindowLong(ps_hWnd, GWL_HWNDPARENT); - if (!psOwner) { - SetWindowLong(ps_hWnd, GWL_HWNDPARENT, (LONG)ps_tbHider_hWnd); - } + //HWND psOwner = (HWND)GetWindowLong(ps_hWnd, GWL_HWNDPARENT); + //if (!psOwner) { + // SetWindowLong(ps_hWnd, GWL_HWNDPARENT, (LONG)ps_tbHider_hWnd); + //} } break; case dbiwmWindowOnly: { @@ -1113,11 +1125,11 @@ void PsMainWindow::psUpdateWorkmode() { } trayIcon = 0; - HWND psOwner = (HWND)GetWindowLong(ps_hWnd, GWL_HWNDPARENT); - if (psOwner) { - SetWindowLong(ps_hWnd, GWL_HWNDPARENT, 0); - psRefreshTaskbarIcon(); - } + //HWND psOwner = (HWND)GetWindowLong(ps_hWnd, GWL_HWNDPARENT); + //if (psOwner) { + // SetWindowLong(ps_hWnd, GWL_HWNDPARENT, 0); + // psRefreshTaskbarIcon(); + //} } break; } } @@ -1142,29 +1154,29 @@ void PsMainWindow::psUpdateCounter() { QIcon iconSmall, iconBig; iconSmall.addPixmap(QPixmap::fromImage(iconWithCounter(16, counter, bg, true), Qt::ColorOnly)); iconSmall.addPixmap(QPixmap::fromImage(iconWithCounter(32, counter, bg, true), Qt::ColorOnly)); - iconBig.addPixmap(QPixmap::fromImage(iconWithCounter(32, taskbarList.Get() ? 0 : counter, bg, false), Qt::ColorOnly)); - iconBig.addPixmap(QPixmap::fromImage(iconWithCounter(64, taskbarList.Get() ? 0 : counter, bg, false), Qt::ColorOnly)); + //iconBig.addPixmap(QPixmap::fromImage(iconWithCounter(32, taskbarList.Get() ? 0 : counter, bg, false), Qt::ColorOnly)); + //iconBig.addPixmap(QPixmap::fromImage(iconWithCounter(64, taskbarList.Get() ? 0 : counter, bg, false), Qt::ColorOnly)); if (trayIcon) { trayIcon->setIcon(iconSmall); } setWindowTitle((counter > 0) ? qsl("Telegram (%1)").arg(counter) : qsl("Telegram")); - psDestroyIcons(); - ps_iconSmall = _qt_createHIcon(iconSmall, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON)); - ps_iconBig = _qt_createHIcon(iconBig, GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON)); - SendMessage(ps_hWnd, WM_SETICON, 0, (LPARAM)ps_iconSmall); - SendMessage(ps_hWnd, WM_SETICON, 1, (LPARAM)(ps_iconBig ? ps_iconBig : ps_iconSmall)); - if (taskbarList.Get()) { - if (counter > 0) { - QIcon iconOverlay; - iconOverlay.addPixmap(QPixmap::fromImage(iconWithCounter(-16, counter, bg, false), Qt::ColorOnly)); - iconOverlay.addPixmap(QPixmap::fromImage(iconWithCounter(-32, counter, bg, false), Qt::ColorOnly)); - ps_iconOverlay = _qt_createHIcon(iconOverlay, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON)); - } - QString description = counter > 0 ? QString("%1 unread messages").arg(counter) : qsl("No unread messages"); - taskbarList->SetOverlayIcon(ps_hWnd, ps_iconOverlay, description.toStdWString().c_str()); - } - SetWindowPos(ps_hWnd, 0, 0, 0, 0, 0, SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE); + //psDestroyIcons(); + //ps_iconSmall = _qt_createHIcon(iconSmall, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON)); + //ps_iconBig = _qt_createHIcon(iconBig, GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON)); + //SendMessage(ps_hWnd, WM_SETICON, 0, (LPARAM)ps_iconSmall); + //SendMessage(ps_hWnd, WM_SETICON, 1, (LPARAM)(ps_iconBig ? ps_iconBig : ps_iconSmall)); + //if (taskbarList.Get()) { + // if (counter > 0) { + // QIcon iconOverlay; + // iconOverlay.addPixmap(QPixmap::fromImage(iconWithCounter(-16, counter, bg, false), Qt::ColorOnly)); + // iconOverlay.addPixmap(QPixmap::fromImage(iconWithCounter(-32, counter, bg, false), Qt::ColorOnly)); + // ps_iconOverlay = _qt_createHIcon(iconOverlay, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON)); + // } + // QString description = counter > 0 ? QString("%1 unread messages").arg(counter) : qsl("No unread messages"); + // taskbarList->SetOverlayIcon(ps_hWnd, ps_iconOverlay, description.toStdWString().c_str()); + //} + //SetWindowPos(ps_hWnd, 0, 0, 0, 0, 0, SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE); } void PsMainWindow::psUpdateDelegate() { @@ -1180,14 +1192,14 @@ namespace { _In_ LPRECT lprcMonitor, _In_ LPARAM dwData ) { - MONITORINFOEX info; - info.cbSize = sizeof(info); - GetMonitorInfo(hMonitor, &info); - if (dwData == hashCrc32(info.szDevice, sizeof(info.szDevice))) { - enumMonitor = hMonitor; - enumMonitorWork = info.rcWork; - return FALSE; - } + //MONITORINFOEX info; + //info.cbSize = sizeof(info); + //GetMonitorInfo(hMonitor, &info); + //if (dwData == hashCrc32(info.szDevice, sizeof(info.szDevice))) { + // enumMonitor = hMonitor; + // enumMonitorWork = info.rcWork; + // return FALSE; + //} return TRUE; } } @@ -1203,7 +1215,7 @@ void PsMainWindow::psInitSize() { if (pos.w && pos.h) { if (pos.y < 0) pos.y = 0; enumMonitor = 0; - EnumDisplayMonitors(0, 0, &_monitorEnumProc, pos.moncrc); + //EnumDisplayMonitors(0, 0, &_monitorEnumProc, pos.moncrc); if (enumMonitor) { int32 w = enumMonitorWork.right - enumMonitorWork.left, h = enumMonitorWork.bottom - enumMonitorWork.top; if (w >= st::wndMinWidth && h >= st::wndMinHeight) { @@ -1222,7 +1234,7 @@ void PsMainWindow::psInitSize() { } bool InitToastManager(); -bool CreateToast(PeerData *peer, int32 msgId, bool showpix, const QString &title, const QString &subtitle, const QString &msg); +//bool CreateToast(PeerData *peer, int32 msgId, bool showpix, const QString &title, const QString &subtitle, const QString &msg); void CheckPinnedAppUserModelId(); void CleanupAppUserModelIdShortcut(); @@ -1235,13 +1247,12 @@ void PsMainWindow::psInitFrameless() { if (!ps_hWnd) return; - if (useWtsapi) wtsRegisterSessionNotification(ps_hWnd, NOTIFY_FOR_THIS_SESSION); + //if (useWtsapi) wtsRegisterSessionNotification(ps_hWnd, NOTIFY_FOR_THIS_SESSION); if (frameless) { setWindowFlags(Qt::FramelessWindowHint); } -// RegisterApplicationRestart(NULL, 0); if (!InitToastManager()) { useToast = false; } @@ -1258,26 +1269,26 @@ void PsMainWindow::psSavePosition(Qt::WindowState state) { if (state == Qt::WindowMaximized) { curPos.maximized = 1; } else { - RECT w; - GetWindowRect(ps_hWnd, &w); - curPos.x = w.left; - curPos.y = w.top; - curPos.w = w.right - w.left; - curPos.h = w.bottom - w.top; + //RECT w; + //GetWindowRect(ps_hWnd, &w); + //curPos.x = w.left; + //curPos.y = w.top; + //curPos.w = w.right - w.left; + //curPos.h = w.bottom - w.top; curPos.maximized = 0; } - HMONITOR hMonitor = MonitorFromWindow(ps_hWnd, MONITOR_DEFAULTTONEAREST); - if (hMonitor) { - MONITORINFOEX info; - info.cbSize = sizeof(info); - GetMonitorInfo(hMonitor, &info); - if (!curPos.maximized) { - curPos.x -= info.rcWork.left; - curPos.y -= info.rcWork.top; - } - curPos.moncrc = hashCrc32(info.szDevice, sizeof(info.szDevice)); - } + //HMONITOR hMonitor = MonitorFromWindow(ps_hWnd, MONITOR_DEFAULTTONEAREST); + //if (hMonitor) { + // MONITORINFOEX info; + // info.cbSize = sizeof(info); + // GetMonitorInfo(hMonitor, &info); + // if (!curPos.maximized) { + // curPos.x -= info.rcWork.left; + // curPos.y -= info.rcWork.top; + // } + // curPos.moncrc = hashCrc32(info.szDevice, sizeof(info.szDevice)); + //} if (curPos.w >= st::wndMinWidth && curPos.h >= st::wndMinHeight) { if (curPos.x != pos.x || curPos.y != pos.y || curPos.w != pos.w || curPos.h != pos.h || curPos.moncrc != pos.moncrc || curPos.maximized != pos.maximized) { @@ -1303,12 +1314,12 @@ void PsMainWindow::psFirstShow() { cSetCustomNotifies(true); } - _psShadowWindows.init(_shActive); + //_psShadowWindows.init(_shActive); finished = false; psUpdateMargins(); - _psShadowWindows.update(_PsShadowHidden); + //_psShadowWindows.update(_PsShadowHidden); bool showShadows = true; show(); @@ -1330,7 +1341,7 @@ void PsMainWindow::psFirstShow() { posInited = true; if (showShadows) { - _psShadowWindows.update(_PsShadowMoved | _PsShadowResized | _PsShadowShown); + //_psShadowWindows.update(_PsShadowMoved | _PsShadowResized | _PsShadowShown); } } @@ -1340,7 +1351,7 @@ bool PsMainWindow::psHandleTitle() { void PsMainWindow::psInitSysMenu() { Qt::WindowStates states = windowState(); - ps_menu = GetSystemMenu(ps_hWnd, FALSE); + //ps_menu = GetSystemMenu(ps_hWnd, FALSE); psUpdateSysMenu(windowHandle()->windowState()); } @@ -1353,98 +1364,98 @@ void PsMainWindow::psUpdateSysMenu(Qt::WindowState state) { } else if (state == Qt::WindowMinimized) { menuToDisable = SC_MINIMIZE; } - int itemCount = GetMenuItemCount(ps_menu); - for (int i = 0; i < itemCount; ++i) { - MENUITEMINFO itemInfo = {0}; - itemInfo.cbSize = sizeof(itemInfo); - itemInfo.fMask = MIIM_TYPE | MIIM_STATE | MIIM_ID; - if (GetMenuItemInfo(ps_menu, i, TRUE, &itemInfo)) { - if (itemInfo.fType & MFT_SEPARATOR) { - continue; - } - if (itemInfo.wID && !(itemInfo.fState & MFS_DEFAULT)) { - UINT fOldState = itemInfo.fState, fState = itemInfo.fState & ~MFS_DISABLED; - if (itemInfo.wID == SC_CLOSE) { - fState |= MFS_DEFAULT; - } else if (itemInfo.wID == menuToDisable || (itemInfo.wID != SC_MINIMIZE && itemInfo.wID != SC_MAXIMIZE && itemInfo.wID != SC_RESTORE)) { - fState |= MFS_DISABLED; - } - itemInfo.fMask = MIIM_STATE; - itemInfo.fState = fState; - if (!SetMenuItemInfo(ps_menu, i, TRUE, &itemInfo)) { - DEBUG_LOG(("PS Error: could not set state %1 to menu item %2, old state %3, error %4").arg(fState).arg(itemInfo.wID).arg(fOldState).arg(GetLastError())); - DestroyMenu(ps_menu); - ps_menu = 0; - break; - } - } - } else { - DEBUG_LOG(("PS Error: could not get state, menu item %1 of %2, error %3").arg(i).arg(itemCount).arg(GetLastError())); - DestroyMenu(ps_menu); - ps_menu = 0; - break; - } - } + //int itemCount = GetMenuItemCount(ps_menu); + //for (int i = 0; i < itemCount; ++i) { + // MENUITEMINFO itemInfo = {0}; + // itemInfo.cbSize = sizeof(itemInfo); + // itemInfo.fMask = MIIM_TYPE | MIIM_STATE | MIIM_ID; + // if (GetMenuItemInfo(ps_menu, i, TRUE, &itemInfo)) { + // if (itemInfo.fType & MFT_SEPARATOR) { + // continue; + // } + // if (itemInfo.wID && !(itemInfo.fState & MFS_DEFAULT)) { + // UINT fOldState = itemInfo.fState, fState = itemInfo.fState & ~MFS_DISABLED; + // if (itemInfo.wID == SC_CLOSE) { + // fState |= MFS_DEFAULT; + // } else if (itemInfo.wID == menuToDisable || (itemInfo.wID != SC_MINIMIZE && itemInfo.wID != SC_MAXIMIZE && itemInfo.wID != SC_RESTORE)) { + // fState |= MFS_DISABLED; + // } + // itemInfo.fMask = MIIM_STATE; + // itemInfo.fState = fState; + // if (!SetMenuItemInfo(ps_menu, i, TRUE, &itemInfo)) { + // DEBUG_LOG(("PS Error: could not set state %1 to menu item %2, old state %3, error %4").arg(fState).arg(itemInfo.wID).arg(fOldState).arg(GetLastError())); + // DestroyMenu(ps_menu); + // ps_menu = 0; + // break; + // } + // } + // } else { + // DEBUG_LOG(("PS Error: could not get state, menu item %1 of %2, error %3").arg(i).arg(itemCount).arg(GetLastError())); + // DestroyMenu(ps_menu); + // ps_menu = 0; + // break; + // } + //} } void PsMainWindow::psUpdateMargins() { if (!ps_hWnd) return; - RECT r, a; + //RECT r, a; - GetClientRect(ps_hWnd, &r); - a = r; + //GetClientRect(ps_hWnd, &r); + //a = r; - LONG style = GetWindowLong(ps_hWnd, GWL_STYLE), styleEx = GetWindowLong(ps_hWnd, GWL_EXSTYLE); - AdjustWindowRectEx(&a, style, false, styleEx); - QMargins margins = QMargins(a.left - r.left, a.top - r.top, r.right - a.right, r.bottom - a.bottom); - if (style & WS_MAXIMIZE) { - RECT w, m; - GetWindowRect(ps_hWnd, &w); - m = w; + //LONG style = GetWindowLong(ps_hWnd, GWL_STYLE), styleEx = GetWindowLong(ps_hWnd, GWL_EXSTYLE); + //AdjustWindowRectEx(&a, style, false, styleEx); + //QMargins margins = QMargins(a.left - r.left, a.top - r.top, r.right - a.right, r.bottom - a.bottom); + //if (style & WS_MAXIMIZE) { + // RECT w, m; + // GetWindowRect(ps_hWnd, &w); + // m = w; - HMONITOR hMonitor = MonitorFromRect(&w, MONITOR_DEFAULTTONEAREST); - if (hMonitor) { - MONITORINFO mi; - mi.cbSize = sizeof(mi); - GetMonitorInfo(hMonitor, &mi); - m = mi.rcWork; - } + // HMONITOR hMonitor = MonitorFromRect(&w, MONITOR_DEFAULTTONEAREST); + // if (hMonitor) { + // MONITORINFO mi; + // mi.cbSize = sizeof(mi); + // GetMonitorInfo(hMonitor, &mi); + // m = mi.rcWork; + // } - dleft = w.left - m.left; - dtop = w.top - m.top; + // dleft = w.left - m.left; + // dtop = w.top - m.top; - margins.setLeft(margins.left() - w.left + m.left); - margins.setRight(margins.right() - m.right + w.right); - margins.setBottom(margins.bottom() - m.bottom + w.bottom); - margins.setTop(margins.top() - w.top + m.top); - } else { - dleft = dtop = 0; - } + // margins.setLeft(margins.left() - w.left + m.left); + // margins.setRight(margins.right() - m.right + w.right); + // margins.setBottom(margins.bottom() - m.bottom + w.bottom); + // margins.setTop(margins.top() - w.top + m.top); + //} else { + // dleft = dtop = 0; + //} - QPlatformNativeInterface *i = QGuiApplication::platformNativeInterface(); - i->setWindowProperty(windowHandle()->handle(), qsl("WindowsCustomMargins"), QVariant::fromValue(margins)); - if (!themeInited) { - themeInited = true; - if (useTheme) { - if (QSysInfo::WindowsVersion < QSysInfo::WV_WINDOWS8) { - setWindowTheme(ps_hWnd, L" ", L" "); - QApplication::setStyle(QStyleFactory::create(qsl("Windows"))); - } - } - } + //QPlatformNativeInterface *i = QGuiApplication::platformNativeInterface(); + //i->setWindowProperty(windowHandle()->handle(), qsl("WindowsCustomMargins"), QVariant::fromValue(margins)); + //if (!themeInited) { + // themeInited = true; + // if (useTheme) { + // if (QSysInfo::WindowsVersion < QSysInfo::WV_WINDOWS8) { + // setWindowTheme(ps_hWnd, L" ", L" "); + // QApplication::setStyle(QStyleFactory::create(qsl("Windows"))); + // } + // } + //} } void PsMainWindow::psFlash() { - if (GetForegroundWindow() == ps_hWnd) return; + //if (GetForegroundWindow() == ps_hWnd) return; - FLASHWINFO info; - info.cbSize = sizeof(info); - info.hwnd = ps_hWnd; - info.dwFlags = FLASHW_ALL; - info.dwTimeout = 0; - info.uCount = 1; - FlashWindowEx(&info); + //FLASHWINFO info; + //info.cbSize = sizeof(info); + //info.hwnd = ps_hWnd; + //info.dwFlags = FLASHW_ALL; + //info.dwTimeout = 0; + //info.uCount = 1; + //FlashWindowEx(&info); } HWND PsMainWindow::psHwnd() const { @@ -1456,40 +1467,40 @@ HMENU PsMainWindow::psMenu() const { } void PsMainWindow::psDestroyIcons() { - if (ps_iconBig) { - DestroyIcon(ps_iconBig); - ps_iconBig = 0; - } - if (ps_iconSmall) { - DestroyIcon(ps_iconSmall); - ps_iconSmall = 0; - } - if (ps_iconOverlay) { - DestroyIcon(ps_iconOverlay); - ps_iconOverlay = 0; - } + //if (ps_iconBig) { + // DestroyIcon(ps_iconBig); + // ps_iconBig = 0; + // } + // if (ps_iconSmall) { + // DestroyIcon(ps_iconSmall); + // ps_iconSmall = 0; + // } + //if (ps_iconOverlay) { + // DestroyIcon(ps_iconOverlay); + // ps_iconOverlay = 0; + //} } PsMainWindow::~PsMainWindow() { - if (useWtsapi) { - QPlatformNativeInterface *i = QGuiApplication::platformNativeInterface(); - if (HWND hWnd = static_cast(i->nativeResourceForWindow(QByteArrayLiteral("handle"), windowHandle()))) { - wtsUnRegisterSessionNotification(hWnd); - } - } + //if (useWtsapi) { + // QPlatformNativeInterface *i = QGuiApplication::platformNativeInterface(); + // if (HWND hWnd = static_cast(i->nativeResourceForWindow(QByteArrayLiteral("handle"), windowHandle()))) { + // wtsUnRegisterSessionNotification(hWnd); + // } + //} - if (taskbarList) taskbarList.Reset(); + //if (taskbarList) taskbarList.Reset(); - toastNotifications.clear(); - if (toastNotificationManager) toastNotificationManager.Reset(); - if (toastNotifier) toastNotifier.Reset(); - if (toastNotificationFactory) toastNotificationFactory.Reset(); + //toastNotifications.clear(); + //if (toastNotificationManager) toastNotificationManager.Reset(); + //if (toastNotifier) toastNotifier.Reset(); + //if (toastNotificationFactory) toastNotificationFactory.Reset(); finished = true; - if (ps_menu) DestroyMenu(ps_menu); + //if (ps_menu) DestroyMenu(ps_menu); psDestroyIcons(); - _psShadowWindows.destroy(); - if (ps_tbHider_hWnd) DestroyWindow(ps_tbHider_hWnd); + //_psShadowWindows.destroy(); + //if (ps_tbHider_hWnd) DestroyWindow(ps_tbHider_hWnd); } namespace { @@ -1501,15 +1512,15 @@ QRect psDesktopRect() { uint64 tnow = getms(); if (tnow > _monitorLastGot + 1000 || tnow < _monitorLastGot) { _monitorLastGot = tnow; - HMONITOR hMonitor = MonitorFromWindow(App::wnd()->psHwnd(), MONITOR_DEFAULTTONEAREST); - if (hMonitor) { - MONITORINFOEX info; - info.cbSize = sizeof(info); - GetMonitorInfo(hMonitor, &info); - _monitorRect = QRect(info.rcWork.left, info.rcWork.top, info.rcWork.right - info.rcWork.left, info.rcWork.bottom - info.rcWork.top); - } else { + //HMONITOR hMonitor = MonitorFromWindow(App::wnd()->psHwnd(), MONITOR_DEFAULTTONEAREST); + //if (hMonitor) { + // MONITORINFOEX info; + // info.cbSize = sizeof(info); + // GetMonitorInfo(hMonitor, &info); + // _monitorRect = QRect(info.rcWork.left, info.rcWork.top, info.rcWork.right - info.rcWork.left, info.rcWork.bottom - info.rcWork.top); + //} else { _monitorRect = QApplication::desktop()->availableGeometry(App::wnd()); - } + //} } return _monitorRect; } @@ -1524,28 +1535,28 @@ void PsMainWindow::psActivateNotify(NotifyWindow *w) { } void PsMainWindow::psClearNotifies(PeerId peerId) { - if (!toastNotifier) return; + //if (!toastNotifier) return; - if (peerId) { - ToastNotifications::iterator i = toastNotifications.find(peerId); - if (i != toastNotifications.cend()) { - QMap temp = i.value(); - toastNotifications.erase(i); + //if (peerId) { + // ToastNotifications::iterator i = toastNotifications.find(peerId); + // if (i != toastNotifications.cend()) { + // QMap temp = i.value(); + // toastNotifications.erase(i); - for (QMap::const_iterator j = temp.cbegin(), e = temp.cend(); j != e; ++j) { - toastNotifier->Hide(j->p.Get()); - } - } - } else { - ToastNotifications temp = toastNotifications; - toastNotifications.clear(); + // for (QMap::const_iterator j = temp.cbegin(), e = temp.cend(); j != e; ++j) { + // toastNotifier->Hide(j->p.Get()); + // } + // } + //} else { + // ToastNotifications temp = toastNotifications; + // toastNotifications.clear(); - for (ToastNotifications::const_iterator i = temp.cbegin(), end = temp.cend(); i != end; ++i) { - for (QMap::const_iterator j = i->cbegin(), e = i->cend(); j != e; ++j) { - toastNotifier->Hide(j->p.Get()); - } - } - } + // for (ToastNotifications::const_iterator i = temp.cbegin(), end = temp.cend(); i != end; ++i) { + // for (QMap::const_iterator j = i->cbegin(), e = i->cend(); j != e; ++j) { + // toastNotifier->Hide(j->p.Get()); + // } + // } + //} } void PsMainWindow::psNotifyShown(NotifyWindow *w) { @@ -1557,7 +1568,7 @@ void PsMainWindow::psPlatformNotify(HistoryItem *item, int32 fwdCount) { bool showpix = (!App::passcoded() && cNotifyView() <= dbinvShowName); QString msg = (!App::passcoded() && cNotifyView() <= dbinvShowPreview) ? (fwdCount < 2 ? item->notificationText() : lng_forward_messages(lt_count, fwdCount)) : lang(lng_notification_preview); - CreateToast(item->history()->peer, item->id, showpix, title, subtitle, msg); +// CreateToast(item->history()->peer, item->id, showpix, title, subtitle, msg); } QAbstractNativeEventFilter *psNativeEventFilter() { @@ -1571,40 +1582,40 @@ void psDeleteDir(const QString &dir) { WCHAR path[4096]; memcpy(path, wDir.c_str(), (wDir.size() + 1) * sizeof(WCHAR)); path[wDir.size() + 1] = 0; - SHFILEOPSTRUCT file_op = { - NULL, - FO_DELETE, - path, - L"", - FOF_NOCONFIRMATION | - FOF_NOERRORUI | - FOF_SILENT, - false, - 0, - L"" - }; - int res = SHFileOperation(&file_op); + //SHFILEOPSTRUCT file_op = { + // NULL, + // FO_DELETE, + // path, + // L"", + // FOF_NOCONFIRMATION | + // FOF_NOERRORUI | + // FOF_SILENT, + // false, + // 0, + // L"" + //}; + //int res = SHFileOperation(&file_op); } namespace { BOOL CALLBACK _ActivateProcess(HWND hWnd, LPARAM lParam) { - uint64 &processId(*(uint64*)lParam); + //uint64 &processId(*(uint64*)lParam); - DWORD dwProcessId; - ::GetWindowThreadProcessId(hWnd, &dwProcessId); + //DWORD dwProcessId; + //::GetWindowThreadProcessId(hWnd, &dwProcessId); - if ((uint64)dwProcessId == processId) { // found top-level window - static const int32 nameBufSize = 1024; - WCHAR nameBuf[nameBufSize]; - int32 len = GetWindowText(hWnd, nameBuf, nameBufSize); - if (len && len < nameBufSize) { - if (QRegularExpression(qsl("^Telegram(\\s*\\(\\d+\\))?$")).match(QString::fromStdWString(nameBuf)).hasMatch()) { - BOOL res = ::SetForegroundWindow(hWnd); - ::SetFocus(hWnd); - return FALSE; - } - } - } + //if ((uint64)dwProcessId == processId) { // found top-level window + // static const int32 nameBufSize = 1024; + // WCHAR nameBuf[nameBufSize]; + // int32 len = GetWindowText(hWnd, nameBuf, nameBufSize); + // if (len && len < nameBufSize) { + // if (QRegularExpression(qsl("^Telegram(\\s*\\(\\d+\\))?$")).match(QString::fromStdWString(nameBuf)).hasMatch()) { + // BOOL res = ::SetForegroundWindow(hWnd); + // ::SetFocus(hWnd); + // return FALSE; + // } + // } + //} return TRUE; } } @@ -1619,30 +1630,32 @@ void psUserActionDone() { } bool psIdleSupported() { - LASTINPUTINFO lii; - lii.cbSize = sizeof(LASTINPUTINFO); - return GetLastInputInfo(&lii); + //LASTINPUTINFO lii; + //lii.cbSize = sizeof(LASTINPUTINFO); + //return GetLastInputInfo(&lii); + return false; } uint64 psIdleTime() { - LASTINPUTINFO lii; - lii.cbSize = sizeof(LASTINPUTINFO); - return GetLastInputInfo(&lii) ? (GetTickCount() - lii.dwTime) : (getms(true) - _lastUserAction); + //LASTINPUTINFO lii; + //lii.cbSize = sizeof(LASTINPUTINFO); + //return GetLastInputInfo(&lii) ? (GetTickCount() - lii.dwTime) : (getms(true) - _lastUserAction); + return (getms(true) - _lastUserAction); } bool psSkipAudioNotify() { - QUERY_USER_NOTIFICATION_STATE state; - if (useShellapi && SUCCEEDED(shQueryUserNotificationState(&state))) { - if (state == QUNS_NOT_PRESENT || state == QUNS_PRESENTATION_MODE) return true; - } + //QUERY_USER_NOTIFICATION_STATE state; + //if (useShellapi && SUCCEEDED(shQueryUserNotificationState(&state))) { + // if (state == QUNS_NOT_PRESENT || state == QUNS_PRESENTATION_MODE) return true; + //} return sessionLoggedOff; } bool psSkipDesktopNotify() { - QUERY_USER_NOTIFICATION_STATE state; - if (useShellapi && SUCCEEDED(shQueryUserNotificationState(&state))) { - if (state == QUNS_PRESENTATION_MODE || state == QUNS_RUNNING_D3D_FULL_SCREEN/* || state == QUNS_BUSY*/) return true; - } + //QUERY_USER_NOTIFICATION_STATE state; + //if (useShellapi && SUCCEEDED(shQueryUserNotificationState(&state))) { + // if (state == QUNS_PRESENTATION_MODE || state == QUNS_RUNNING_D3D_FULL_SCREEN/* || state == QUNS_BUSY*/) return true; + //} return false; } @@ -1656,17 +1669,17 @@ void psClearInitLogs() { void psActivateProcess(uint64 pid) { if (pid) { - ::EnumWindows((WNDENUMPROC)_ActivateProcess, (LPARAM)&pid); + //::EnumWindows((WNDENUMPROC)_ActivateProcess, (LPARAM)&pid); } } QString psCurrentCountry() { - int chCount = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SISO3166CTRYNAME, 0, 0); - if (chCount && chCount < 128) { - WCHAR wstrCountry[128]; - int len = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SISO3166CTRYNAME, wstrCountry, chCount); - return len ? QString::fromStdWString(std::wstring(wstrCountry)) : QString::fromLatin1(DefaultCountry); - } + //int chCount = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SISO3166CTRYNAME, 0, 0); + //if (chCount && chCount < 128) { + // WCHAR wstrCountry[128]; + // int len = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SISO3166CTRYNAME, wstrCountry, chCount); + // return len ? QString::fromStdWString(std::wstring(wstrCountry)) : QString::fromLatin1(DefaultCountry); + //} return QString::fromLatin1(DefaultCountry); } @@ -1792,56 +1805,56 @@ namespace { } QString psCurrentLanguage() { - int chCount = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SNAME, 0, 0); - if (chCount && chCount < 128) { - WCHAR wstrLocale[128]; - int len = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SNAME, wstrLocale, chCount); - if (!len) return QString::fromLatin1(DefaultLanguage); - QString locale = QString::fromStdWString(std::wstring(wstrLocale)); - QRegularExpressionMatch m = QRegularExpression("(^|[^a-z])([a-z]{2})-").match(locale); - if (m.hasMatch()) { - return m.captured(2); - } - } - chCount = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_ILANGUAGE, 0, 0); - if (chCount && chCount < 128) { - WCHAR wstrLocale[128]; - int len = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_ILANGUAGE, wstrLocale, chCount), lngId = 0; - if (len < 5) return QString::fromLatin1(DefaultLanguage); + //int chCount = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SNAME, 0, 0); + //if (chCount && chCount < 128) { + // WCHAR wstrLocale[128]; + // int len = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SNAME, wstrLocale, chCount); + // if (!len) return QString::fromLatin1(DefaultLanguage); + // QString locale = QString::fromStdWString(std::wstring(wstrLocale)); + // QRegularExpressionMatch m = QRegularExpression("(^|[^a-z])([a-z]{2})-").match(locale); + // if (m.hasMatch()) { + // return m.captured(2); + // } + //} + //chCount = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_ILANGUAGE, 0, 0); + //if (chCount && chCount < 128) { + // WCHAR wstrLocale[128]; + // int len = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_ILANGUAGE, wstrLocale, chCount), lngId = 0; + // if (len < 5) return QString::fromLatin1(DefaultLanguage); - for (int i = 0; i < 4; ++i) { - WCHAR ch = wstrLocale[i]; - lngId *= 16; - if (ch >= WCHAR('0') && ch <= WCHAR('9')) { - lngId += (ch - WCHAR('0')); - } else if (ch >= WCHAR('A') && ch <= WCHAR('F')) { - lngId += (10 + ch - WCHAR('A')); - } else { - return QString::fromLatin1(DefaultLanguage); - } - } - return langById(lngId); - } + // for (int i = 0; i < 4; ++i) { + // WCHAR ch = wstrLocale[i]; + // lngId *= 16; + // if (ch >= WCHAR('0') && ch <= WCHAR('9')) { + // lngId += (ch - WCHAR('0')); + // } else if (ch >= WCHAR('A') && ch <= WCHAR('F')) { + // lngId += (10 + ch - WCHAR('A')); + // } else { + // return QString::fromLatin1(DefaultLanguage); + // } + // } + // return langById(lngId); + //} return QString::fromLatin1(DefaultLanguage); } QString psAppDataPath() { static const int maxFileLen = MAX_PATH * 10; - WCHAR wstrPath[maxFileLen]; - if (GetEnvironmentVariable(L"APPDATA", wstrPath, maxFileLen)) { - QDir appData(QString::fromStdWString(std::wstring(wstrPath))); - return appData.absolutePath() + '/' + QString::fromWCharArray(AppName) + '/'; - } + //WCHAR wstrPath[maxFileLen]; + //if (GetEnvironmentVariable(L"APPDATA", wstrPath, maxFileLen)) { + // QDir appData(QString::fromStdWString(std::wstring(wstrPath))); + // return appData.absolutePath() + '/' + QString::fromWCharArray(AppName) + '/'; + //} return QString(); } QString psAppDataPathOld() { static const int maxFileLen = MAX_PATH * 10; - WCHAR wstrPath[maxFileLen]; - if (GetEnvironmentVariable(L"APPDATA", wstrPath, maxFileLen)) { - QDir appData(QString::fromStdWString(std::wstring(wstrPath))); - return appData.absolutePath() + '/' + QString::fromWCharArray(AppNameOld) + '/'; - } + //WCHAR wstrPath[maxFileLen]; + //if (GetEnvironmentVariable(L"APPDATA", wstrPath, maxFileLen)) { + // QDir appData(QString::fromStdWString(std::wstring(wstrPath))); + // return appData.absolutePath() + '/' + QString::fromWCharArray(AppNameOld) + '/'; + //} return QString(); } @@ -1850,30 +1863,30 @@ QString psDownloadPath() { } QString psCurrentExeDirectory(int argc, char *argv[]) { - LPWSTR *args; - int argsCount; - args = CommandLineToArgvW(GetCommandLine(), &argsCount); - if (args) { - QFileInfo info(QDir::fromNativeSeparators(QString::fromWCharArray(args[0]))); - if (info.isFile()) { - return info.absoluteDir().absolutePath() + '/'; - } - LocalFree(args); - } + //LPWSTR *args; + //int argsCount; + //args = CommandLineToArgvW(GetCommandLine(), &argsCount); + //if (args) { + // QFileInfo info(QDir::fromNativeSeparators(QString::fromWCharArray(args[0]))); + // if (info.isFile()) { + // return info.absoluteDir().absolutePath() + '/'; + // } + // LocalFree(args); + //} return QString(); } QString psCurrentExeName(int argc, char *argv[]) { - LPWSTR *args; - int argsCount; - args = CommandLineToArgvW(GetCommandLine(), &argsCount); - if (args) { - QFileInfo info(QDir::fromNativeSeparators(QString::fromWCharArray(args[0]))); - if (info.isFile()) { - return info.fileName(); - } - LocalFree(args); - } + //LPWSTR *args; + //int argsCount; + //args = CommandLineToArgvW(GetCommandLine(), &argsCount); + //if (args) { + // QFileInfo info(QDir::fromNativeSeparators(QString::fromWCharArray(args[0]))); + // if (info.isFile()) { + // return info.fileName(); + // } + // LocalFree(args); + //} return QString(); } @@ -1900,50 +1913,50 @@ int psCleanup() { void psDoFixPrevious() { try { - static const int bufSize = 4096; - DWORD checkType, checkSize = bufSize * 2; - WCHAR checkStr[bufSize]; + //static const int bufSize = 4096; + //DWORD checkType, checkSize = bufSize * 2; + //WCHAR checkStr[bufSize]; - QString appId = QString::fromStdWString(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); - QString oldKeyStr2 = QString("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\%1_is1").arg(appId); - HKEY newKey1, newKey2, oldKey1, oldKey2; - LSTATUS newKeyRes1 = RegOpenKeyEx(HKEY_CURRENT_USER, newKeyStr1.toStdWString().c_str(), 0, KEY_READ, &newKey1); - LSTATUS newKeyRes2 = RegOpenKeyEx(HKEY_CURRENT_USER, newKeyStr2.toStdWString().c_str(), 0, KEY_READ, &newKey2); - LSTATUS oldKeyRes1 = RegOpenKeyEx(HKEY_LOCAL_MACHINE, oldKeyStr1.toStdWString().c_str(), 0, KEY_READ, &oldKey1); - LSTATUS oldKeyRes2 = RegOpenKeyEx(HKEY_LOCAL_MACHINE, oldKeyStr2.toStdWString().c_str(), 0, KEY_READ, &oldKey2); + //QString appId = QString::fromStdWString(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); + //QString oldKeyStr2 = QString("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\%1_is1").arg(appId); + //HKEY newKey1, newKey2, oldKey1, oldKey2; + //LSTATUS newKeyRes1 = RegOpenKeyEx(HKEY_CURRENT_USER, newKeyStr1.toStdWString().c_str(), 0, KEY_READ, &newKey1); + //LSTATUS newKeyRes2 = RegOpenKeyEx(HKEY_CURRENT_USER, newKeyStr2.toStdWString().c_str(), 0, KEY_READ, &newKey2); + //LSTATUS oldKeyRes1 = RegOpenKeyEx(HKEY_LOCAL_MACHINE, oldKeyStr1.toStdWString().c_str(), 0, KEY_READ, &oldKey1); + //LSTATUS oldKeyRes2 = RegOpenKeyEx(HKEY_LOCAL_MACHINE, oldKeyStr2.toStdWString().c_str(), 0, KEY_READ, &oldKey2); - bool existNew1 = (newKeyRes1 == ERROR_SUCCESS) && (RegQueryValueEx(newKey1, L"InstallDate", 0, &checkType, (BYTE*)checkStr, &checkSize) == ERROR_SUCCESS); checkSize = bufSize * 2; - bool existNew2 = (newKeyRes2 == ERROR_SUCCESS) && (RegQueryValueEx(newKey2, L"InstallDate", 0, &checkType, (BYTE*)checkStr, &checkSize) == ERROR_SUCCESS); checkSize = bufSize * 2; - bool existOld1 = (oldKeyRes1 == ERROR_SUCCESS) && (RegQueryValueEx(oldKey1, L"InstallDate", 0, &checkType, (BYTE*)checkStr, &checkSize) == ERROR_SUCCESS); checkSize = bufSize * 2; - bool existOld2 = (oldKeyRes2 == ERROR_SUCCESS) && (RegQueryValueEx(oldKey2, L"InstallDate", 0, &checkType, (BYTE*)checkStr, &checkSize) == ERROR_SUCCESS); checkSize = bufSize * 2; + //bool existNew1 = (newKeyRes1 == ERROR_SUCCESS) && (RegQueryValueEx(newKey1, L"InstallDate", 0, &checkType, (BYTE*)checkStr, &checkSize) == ERROR_SUCCESS); checkSize = bufSize * 2; + //bool existNew2 = (newKeyRes2 == ERROR_SUCCESS) && (RegQueryValueEx(newKey2, L"InstallDate", 0, &checkType, (BYTE*)checkStr, &checkSize) == ERROR_SUCCESS); checkSize = bufSize * 2; + //bool existOld1 = (oldKeyRes1 == ERROR_SUCCESS) && (RegQueryValueEx(oldKey1, L"InstallDate", 0, &checkType, (BYTE*)checkStr, &checkSize) == ERROR_SUCCESS); checkSize = bufSize * 2; + //bool existOld2 = (oldKeyRes2 == ERROR_SUCCESS) && (RegQueryValueEx(oldKey2, L"InstallDate", 0, &checkType, (BYTE*)checkStr, &checkSize) == ERROR_SUCCESS); checkSize = bufSize * 2; - if (newKeyRes1 == ERROR_SUCCESS) RegCloseKey(newKey1); - if (newKeyRes2 == ERROR_SUCCESS) RegCloseKey(newKey2); - if (oldKeyRes1 == ERROR_SUCCESS) RegCloseKey(oldKey1); - if (oldKeyRes2 == ERROR_SUCCESS) RegCloseKey(oldKey2); + //if (newKeyRes1 == ERROR_SUCCESS) RegCloseKey(newKey1); + //if (newKeyRes2 == ERROR_SUCCESS) RegCloseKey(newKey2); + //if (oldKeyRes1 == ERROR_SUCCESS) RegCloseKey(oldKey1); + //if (oldKeyRes2 == ERROR_SUCCESS) RegCloseKey(oldKey2); - if (existNew1 || existNew2) { - oldKeyRes1 = existOld1 ? RegDeleteKey(HKEY_LOCAL_MACHINE, oldKeyStr1.toStdWString().c_str()) : ERROR_SUCCESS; - oldKeyRes2 = existOld2 ? RegDeleteKey(HKEY_LOCAL_MACHINE, oldKeyStr2.toStdWString().c_str()) : ERROR_SUCCESS; - } + //if (existNew1 || existNew2) { + // oldKeyRes1 = existOld1 ? RegDeleteKey(HKEY_LOCAL_MACHINE, oldKeyStr1.toStdWString().c_str()) : ERROR_SUCCESS; + // oldKeyRes2 = existOld2 ? RegDeleteKey(HKEY_LOCAL_MACHINE, oldKeyStr2.toStdWString().c_str()) : ERROR_SUCCESS; + //} - QString userDesktopLnk, commonDesktopLnk; - WCHAR userDesktopFolder[MAX_PATH], commonDesktopFolder[MAX_PATH]; - HRESULT userDesktopRes = SHGetFolderPath(0, CSIDL_DESKTOPDIRECTORY, 0, SHGFP_TYPE_CURRENT, userDesktopFolder); - HRESULT commonDesktopRes = SHGetFolderPath(0, CSIDL_COMMON_DESKTOPDIRECTORY, 0, SHGFP_TYPE_CURRENT, commonDesktopFolder); - if (SUCCEEDED(userDesktopRes)) { - userDesktopLnk = QString::fromWCharArray(userDesktopFolder) + "\\Telegram.lnk"; - } - if (SUCCEEDED(commonDesktopRes)) { - commonDesktopLnk = QString::fromWCharArray(commonDesktopFolder) + "\\Telegram.lnk"; - } - QFile userDesktopFile(userDesktopLnk), commonDesktopFile(commonDesktopLnk); - if (QFile::exists(userDesktopLnk) && QFile::exists(commonDesktopLnk) && userDesktopLnk != commonDesktopLnk) { - bool removed = QFile::remove(commonDesktopLnk); - } + //QString userDesktopLnk, commonDesktopLnk; + //WCHAR userDesktopFolder[MAX_PATH], commonDesktopFolder[MAX_PATH]; + //HRESULT userDesktopRes = SHGetFolderPath(0, CSIDL_DESKTOPDIRECTORY, 0, SHGFP_TYPE_CURRENT, userDesktopFolder); + //HRESULT commonDesktopRes = SHGetFolderPath(0, CSIDL_COMMON_DESKTOPDIRECTORY, 0, SHGFP_TYPE_CURRENT, commonDesktopFolder); + //if (SUCCEEDED(userDesktopRes)) { + // userDesktopLnk = QString::fromWCharArray(userDesktopFolder) + "\\Telegram.lnk"; + //} + //if (SUCCEEDED(commonDesktopRes)) { + // commonDesktopLnk = QString::fromWCharArray(commonDesktopFolder) + "\\Telegram.lnk"; + //} + //QFile userDesktopFile(userDesktopLnk), commonDesktopFile(commonDesktopLnk); + //if (QFile::exists(userDesktopLnk) && QFile::exists(commonDesktopLnk) && userDesktopLnk != commonDesktopLnk) { + // bool removed = QFile::remove(commonDesktopLnk); + //} } catch (...) { } } @@ -1961,176 +1974,176 @@ int psFixPrevious() { } void psPostprocessFile(const QString &name) { - std::wstring zoneFile = QDir::toNativeSeparators(name).toStdWString() + L":Zone.Identifier"; - HANDLE f = CreateFile(zoneFile.c_str(), GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0); - if (f == INVALID_HANDLE_VALUE) { // :( - return; - } + //std::wstring zoneFile = QDir::toNativeSeparators(name).toStdWString() + L":Zone.Identifier"; + //HANDLE f = CreateFile(zoneFile.c_str(), GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0); + //if (f == INVALID_HANDLE_VALUE) { // :( + // return; + //} - const char data[] = "[ZoneTransfer]\r\nZoneId=3\r\n"; + //const char data[] = "[ZoneTransfer]\r\nZoneId=3\r\n"; - DWORD written = 0; - BOOL result = WriteFile(f, data, sizeof(data), &written, NULL); - CloseHandle(f); + //DWORD written = 0; + //BOOL result = WriteFile(f, data, sizeof(data), &written, NULL); + //CloseHandle(f); - if (!result || written != sizeof(data)) { // :( - return; - } + //if (!result || written != sizeof(data)) { // :( + // return; + //} } namespace { - struct OpenWithApp { - OpenWithApp(const QString &name, HBITMAP icon, IAssocHandler *handler) : name(name), icon(icon), handler(handler) { - } - OpenWithApp(const QString &name, IAssocHandler *handler) : name(name), icon(0), handler(handler) { - } - void destroy() { - if (icon) DeleteBitmap(icon); - if (handler) handler->Release(); - } - QString name; - HBITMAP icon; - IAssocHandler *handler; - }; + //struct OpenWithApp { + // OpenWithApp(const QString &name, HBITMAP icon, IAssocHandler *handler) : name(name), icon(icon), handler(handler) { + // } + // OpenWithApp(const QString &name, IAssocHandler *handler) : name(name), icon(0), handler(handler) { + // } + // void destroy() { + // if (icon) DeleteBitmap(icon); + // if (handler) handler->Release(); + // } + // QString name; + // HBITMAP icon; + // IAssocHandler *handler; + //}; - bool OpenWithAppLess(const OpenWithApp &a, const OpenWithApp &b) { - return a.name < b.name; - } + //bool OpenWithAppLess(const OpenWithApp &a, const OpenWithApp &b) { + // return a.name < b.name; + //} - HBITMAP _iconToBitmap(LPWSTR icon, int iconindex) { - if (!icon) return 0; - WCHAR tmpIcon[4096]; - if (icon[0] == L'@' && SUCCEEDED(SHLoadIndirectString(icon, tmpIcon, 4096, 0))) { - icon = tmpIcon; - } - int32 w = GetSystemMetrics(SM_CXSMICON), h = GetSystemMetrics(SM_CYSMICON); + //HBITMAP _iconToBitmap(LPWSTR icon, int iconindex) { + // if (!icon) return 0; + // WCHAR tmpIcon[4096]; + // if (icon[0] == L'@' && SUCCEEDED(SHLoadIndirectString(icon, tmpIcon, 4096, 0))) { + // icon = tmpIcon; + // } + // int32 w = GetSystemMetrics(SM_CXSMICON), h = GetSystemMetrics(SM_CYSMICON); - HICON ico = ExtractIcon(0, icon, iconindex); - if (!ico) { - if (!iconindex) { // try to read image - QImage img(QString::fromWCharArray(icon)); - if (!img.isNull()) { - return qt_pixmapToWinHBITMAP(QPixmap::fromImage(img.scaled(w, h, Qt::IgnoreAspectRatio, Qt::SmoothTransformation)), /* HBitmapAlpha */ 2); - } - } - return 0; - } + // HICON ico = ExtractIcon(0, icon, iconindex); + // if (!ico) { + // if (!iconindex) { // try to read image + // QImage img(QString::fromWCharArray(icon)); + // if (!img.isNull()) { + // return qt_pixmapToWinHBITMAP(QPixmap::fromImage(img.scaled(w, h, Qt::IgnoreAspectRatio, Qt::SmoothTransformation)), /* HBitmapAlpha */ 2); + // } + // } + // return 0; + // } - HDC screenDC = GetDC(0), hdc = CreateCompatibleDC(screenDC); - HBITMAP result = CreateCompatibleBitmap(screenDC, w, h); - HGDIOBJ was = SelectObject(hdc, result); - DrawIconEx(hdc, 0, 0, ico, w, h, 0, NULL, DI_NORMAL); - SelectObject(hdc, was); - DeleteDC(hdc); - ReleaseDC(0, screenDC); + // HDC screenDC = GetDC(0), hdc = CreateCompatibleDC(screenDC); + // HBITMAP result = CreateCompatibleBitmap(screenDC, w, h); + // HGDIOBJ was = SelectObject(hdc, result); + // DrawIconEx(hdc, 0, 0, ico, w, h, 0, NULL, DI_NORMAL); + // SelectObject(hdc, was); + // DeleteDC(hdc); + // ReleaseDC(0, screenDC); - DestroyIcon(ico); + // DestroyIcon(ico); - return (HBITMAP)CopyImage(result, IMAGE_BITMAP, 0, 0, LR_DEFAULTSIZE | LR_CREATEDIBSECTION); -// return result; - } + // return (HBITMAP)CopyImage(result, IMAGE_BITMAP, 0, 0, LR_DEFAULTSIZE | LR_CREATEDIBSECTION); + //} } bool psShowOpenWithMenu(int x, int y, const QString &file) { if (!useOpenWith || !App::wnd()) return false; - bool result = false; - QList handlers; - IShellItem* pItem = nullptr; - if (SUCCEEDED(shCreateItemFromParsingName(QDir::toNativeSeparators(file).toStdWString().c_str(), nullptr, IID_PPV_ARGS(&pItem)))) { - IEnumAssocHandlers *assocHandlers = 0; - if (SUCCEEDED(pItem->BindToHandler(nullptr, BHID_EnumAssocHandlers, IID_PPV_ARGS(&assocHandlers)))) { - HRESULT hr = S_FALSE; - do - { - IAssocHandler *handler = 0; - ULONG ulFetched = 0; - hr = assocHandlers->Next(1, &handler, &ulFetched); - if (FAILED(hr) || hr == S_FALSE || !ulFetched) break; + //bool result = false; + //QList handlers; + //IShellItem* pItem = nullptr; + //if (SUCCEEDED(shCreateItemFromParsingName(QDir::toNativeSeparators(file).toStdWString().c_str(), nullptr, IID_PPV_ARGS(&pItem)))) { + // IEnumAssocHandlers *assocHandlers = 0; + // if (SUCCEEDED(pItem->BindToHandler(nullptr, BHID_EnumAssocHandlers, IID_PPV_ARGS(&assocHandlers)))) { + // HRESULT hr = S_FALSE; + // do + // { + // IAssocHandler *handler = 0; + // ULONG ulFetched = 0; + // hr = assocHandlers->Next(1, &handler, &ulFetched); + // if (FAILED(hr) || hr == S_FALSE || !ulFetched) break; - LPWSTR name = 0; - if (SUCCEEDED(handler->GetUIName(&name))) { - LPWSTR icon = 0; - int iconindex = 0; - if (SUCCEEDED(handler->GetIconLocation(&icon, &iconindex)) && icon) { - handlers.push_back(OpenWithApp(QString::fromWCharArray(name), _iconToBitmap(icon, iconindex), handler)); - CoTaskMemFree(icon); - } else { - handlers.push_back(OpenWithApp(QString::fromWCharArray(name), handler)); - } - CoTaskMemFree(name); - } else { - handler->Release(); - } - } while (hr != S_FALSE); - assocHandlers->Release(); - } + // LPWSTR name = 0; + // if (SUCCEEDED(handler->GetUIName(&name))) { + // LPWSTR icon = 0; + // int iconindex = 0; + // if (SUCCEEDED(handler->GetIconLocation(&icon, &iconindex)) && icon) { + // handlers.push_back(OpenWithApp(QString::fromWCharArray(name), _iconToBitmap(icon, iconindex), handler)); + // CoTaskMemFree(icon); + // } else { + // handlers.push_back(OpenWithApp(QString::fromWCharArray(name), handler)); + // } + // CoTaskMemFree(name); + // } else { + // handler->Release(); + // } + // } while (hr != S_FALSE); + // assocHandlers->Release(); + // } - if (!handlers.isEmpty()) { - HMENU menu = CreatePopupMenu(); - std::sort(handlers.begin(), handlers.end(), OpenWithAppLess); - for (int32 i = 0, l = handlers.size(); i < l; ++i) { - MENUITEMINFO menuInfo = { 0 }; - menuInfo.cbSize = sizeof(menuInfo); - menuInfo.fMask = MIIM_STRING | MIIM_DATA | MIIM_ID; - menuInfo.fType = MFT_STRING; - menuInfo.wID = i + 1; - if (handlers.at(i).icon) { - menuInfo.fMask |= MIIM_BITMAP; - menuInfo.hbmpItem = handlers.at(i).icon; - } + // if (!handlers.isEmpty()) { + // HMENU menu = CreatePopupMenu(); + // std::sort(handlers.begin(), handlers.end(), OpenWithAppLess); + // for (int32 i = 0, l = handlers.size(); i < l; ++i) { + // MENUITEMINFO menuInfo = { 0 }; + // menuInfo.cbSize = sizeof(menuInfo); + // menuInfo.fMask = MIIM_STRING | MIIM_DATA | MIIM_ID; + // menuInfo.fType = MFT_STRING; + // menuInfo.wID = i + 1; + // if (handlers.at(i).icon) { + // menuInfo.fMask |= MIIM_BITMAP; + // menuInfo.hbmpItem = handlers.at(i).icon; + // } - QString name = handlers.at(i).name; - if (name.size() > 512) name = name.mid(0, 512); - WCHAR nameArr[1024]; - name.toWCharArray(nameArr); - nameArr[name.size()] = 0; - menuInfo.dwTypeData = nameArr; - InsertMenuItem(menu, GetMenuItemCount(menu), TRUE, &menuInfo); - } - MENUITEMINFO sepInfo = { 0 }; - sepInfo.cbSize = sizeof(sepInfo); - sepInfo.fMask = MIIM_STRING | MIIM_DATA; - sepInfo.fType = MFT_SEPARATOR; - InsertMenuItem(menu, GetMenuItemCount(menu), true, &sepInfo); + // QString name = handlers.at(i).name; + // if (name.size() > 512) name = name.mid(0, 512); + // WCHAR nameArr[1024]; + // name.toWCharArray(nameArr); + // nameArr[name.size()] = 0; + // menuInfo.dwTypeData = nameArr; + // InsertMenuItem(menu, GetMenuItemCount(menu), TRUE, &menuInfo); + // } + // MENUITEMINFO sepInfo = { 0 }; + // sepInfo.cbSize = sizeof(sepInfo); + // sepInfo.fMask = MIIM_STRING | MIIM_DATA; + // sepInfo.fType = MFT_SEPARATOR; + // InsertMenuItem(menu, GetMenuItemCount(menu), true, &sepInfo); - MENUITEMINFO menuInfo = { 0 }; - menuInfo.cbSize = sizeof(menuInfo); - menuInfo.fMask = MIIM_STRING | MIIM_DATA | MIIM_ID; - menuInfo.fType = MFT_STRING; - menuInfo.wID = handlers.size() + 1; + // MENUITEMINFO menuInfo = { 0 }; + // menuInfo.cbSize = sizeof(menuInfo); + // menuInfo.fMask = MIIM_STRING | MIIM_DATA | MIIM_ID; + // menuInfo.fType = MFT_STRING; + // menuInfo.wID = handlers.size() + 1; - QString name = lang(lng_wnd_choose_program_menu); - if (name.size() > 512) name = name.mid(0, 512); - WCHAR nameArr[1024]; - name.toWCharArray(nameArr); - nameArr[name.size()] = 0; - menuInfo.dwTypeData = nameArr; - InsertMenuItem(menu, GetMenuItemCount(menu), TRUE, &menuInfo); + // QString name = lang(lng_wnd_choose_program_menu); + // if (name.size() > 512) name = name.mid(0, 512); + // WCHAR nameArr[1024]; + // name.toWCharArray(nameArr); + // nameArr[name.size()] = 0; + // menuInfo.dwTypeData = nameArr; + // InsertMenuItem(menu, GetMenuItemCount(menu), TRUE, &menuInfo); - int sel = TrackPopupMenu(menu, TPM_LEFTALIGN | TPM_TOPALIGN | TPM_LEFTBUTTON | TPM_RETURNCMD, x, y, 0, App::wnd()->psHwnd(), 0); - DestroyMenu(menu); + // int sel = TrackPopupMenu(menu, TPM_LEFTALIGN | TPM_TOPALIGN | TPM_LEFTBUTTON | TPM_RETURNCMD, x, y, 0, App::wnd()->psHwnd(), 0); + // DestroyMenu(menu); - if (sel > 0) { - if (sel <= handlers.size()) { - IDataObject *dataObj = 0; - if (SUCCEEDED(pItem->BindToHandler(nullptr, BHID_DataObject, IID_PPV_ARGS(&dataObj))) && dataObj) { - handlers.at(sel - 1).handler->Invoke(dataObj); - dataObj->Release(); - result = true; - } - } - } else { - result = true; - } - for (int i = 0, l = handlers.size(); i < l; ++i) { - handlers[i].destroy(); - } - } + // if (sel > 0) { + // if (sel <= handlers.size()) { + // IDataObject *dataObj = 0; + // if (SUCCEEDED(pItem->BindToHandler(nullptr, BHID_DataObject, IID_PPV_ARGS(&dataObj))) && dataObj) { + // handlers.at(sel - 1).handler->Invoke(dataObj); + // dataObj->Release(); + // result = true; + // } + // } + // } else { + // result = true; + // } + // for (int i = 0, l = handlers.size(); i < l; ++i) { + // handlers[i].destroy(); + // } + // } - pItem->Release(); - } - return result; + // pItem->Release(); + //} + //return result; + return false; } void psOpenFile(const QString &name, bool openWith) { @@ -2138,27 +2151,27 @@ void psOpenFile(const QString &name, bool openWith) { std::wstring wname = mailtoScheme ? name.toStdWString() : QDir::toNativeSeparators(name).toStdWString(); if (openWith && useOpenAs) { - if (shOpenWithDialog) { - OPENASINFO info; - info.oaifInFlags = OAIF_ALLOW_REGISTRATION | OAIF_REGISTER_EXT | OAIF_EXEC; - if (mailtoScheme) info.oaifInFlags |= OAIF_FILE_IS_URI | OAIF_URL_PROTOCOL; - info.pcszClass = NULL; - info.pcszFile = wname.c_str(); - shOpenWithDialog(0, &info); - } else { - openAs_RunDLL(0, 0, wname.c_str(), SW_SHOWNORMAL); - } + //if (shOpenWithDialog) { + // OPENASINFO info; + // info.oaifInFlags = OAIF_ALLOW_REGISTRATION | OAIF_REGISTER_EXT | OAIF_EXEC; + // if (mailtoScheme) info.oaifInFlags |= OAIF_FILE_IS_URI | OAIF_URL_PROTOCOL; + // info.pcszClass = NULL; + // info.pcszFile = wname.c_str(); + // shOpenWithDialog(0, &info); + //} else { + // openAs_RunDLL(0, 0, wname.c_str(), SW_SHOWNORMAL); + //} } else { - ShellExecute(0, L"open", wname.c_str(), 0, 0, SW_SHOWNORMAL); + //ShellExecute(0, L"open", wname.c_str(), 0, 0, SW_SHOWNORMAL); } + QDesktopServices::openUrl(QUrl::fromLocalFile(name)); } void psShowInFolder(const QString &name) { - QString nameEscaped = QDir::toNativeSeparators(name).replace('"', qsl("\"\"")); - ShellExecute(0, 0, qsl("explorer").toStdWString().c_str(), (qsl("/select,") + nameEscaped).toStdWString().c_str(), 0, SW_SHOWNORMAL); + //QString nameEscaped = QDir::toNativeSeparators(name).replace('"', qsl("\"\"")); + //ShellExecute(0, 0, qsl("explorer").toStdWString().c_str(), (qsl("/select,") + nameEscaped).toStdWString().c_str(), 0, SW_SHOWNORMAL); } - namespace PlatformSpecific { void start() { @@ -2168,9 +2181,9 @@ namespace PlatformSpecific { delete _psEventFilter; _psEventFilter = 0; - if (ToastImageSavedFlag) { - psDeleteDir(cWorkingDir() + qsl("tdata/temp")); - } + //if (ToastImageSavedFlag) { + // psDeleteDir(cWorkingDir() + qsl("tdata/temp")); + //} } namespace ThirdParty { @@ -2184,74 +2197,74 @@ namespace PlatformSpecific { } 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; - } - LOG((str).arg(code).arg(QString::fromStdWString(errorText))); - if (errorText != errorTextDefault) { - LocalFree(errorText); - } - } + //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; + // } + // LOG((str).arg(code).arg(QString::fromStdWString(errorText))); + // if (errorText != errorTextDefault) { + // LocalFree(errorText); + // } + //} - bool _psOpenRegKey(LPCWSTR key, PHKEY rkey) { - DEBUG_LOG(("App Info: opening reg key %1..").arg(QString::fromStdWString(key))); - LSTATUS status = RegOpenKeyEx(HKEY_CURRENT_USER, key, 0, KEY_QUERY_VALUE | KEY_WRITE, rkey); - if (status != ERROR_SUCCESS) { - if (status == ERROR_FILE_NOT_FOUND) { - status = RegCreateKeyEx(HKEY_CURRENT_USER, key, 0, 0, REG_OPTION_NON_VOLATILE, KEY_QUERY_VALUE | KEY_WRITE, 0, rkey, 0); - if (status != ERROR_SUCCESS) { - QString msg = qsl("App Error: could not create '%1' registry key, error %2").arg(QString::fromStdWString(key)).arg(qsl("%1: %2")); - _psLogError(msg.toUtf8().constData(), status); - return false; - } - } else { - QString msg = qsl("App Error: could not open '%1' registry key, error %2").arg(QString::fromStdWString(key)).arg(qsl("%1: %2")); - _psLogError(msg.toUtf8().constData(), status); - return false; - } - } - return true; - } + //bool _psOpenRegKey(LPCWSTR key, PHKEY rkey) { + // DEBUG_LOG(("App Info: opening reg key %1..").arg(QString::fromStdWString(key))); + // LSTATUS status = RegOpenKeyEx(HKEY_CURRENT_USER, key, 0, KEY_QUERY_VALUE | KEY_WRITE, rkey); + // if (status != ERROR_SUCCESS) { + // if (status == ERROR_FILE_NOT_FOUND) { + // status = RegCreateKeyEx(HKEY_CURRENT_USER, key, 0, 0, REG_OPTION_NON_VOLATILE, KEY_QUERY_VALUE | KEY_WRITE, 0, rkey, 0); + // if (status != ERROR_SUCCESS) { + // QString msg = qsl("App Error: could not create '%1' registry key, error %2").arg(QString::fromStdWString(key)).arg(qsl("%1: %2")); + // _psLogError(msg.toUtf8().constData(), status); + // return false; + // } + // } else { + // QString msg = qsl("App Error: could not open '%1' registry key, error %2").arg(QString::fromStdWString(key)).arg(qsl("%1: %2")); + // _psLogError(msg.toUtf8().constData(), status); + // return false; + // } + // } + // return true; + //} - bool _psSetKeyValue(HKEY rkey, LPCWSTR value, QString v) { - static const int bufSize = 4096; - DWORD defaultType, defaultSize = bufSize * 2; - WCHAR defaultStr[bufSize] = { 0 }; - if (RegQueryValueEx(rkey, value, 0, &defaultType, (BYTE*)defaultStr, &defaultSize) != ERROR_SUCCESS || defaultType != REG_SZ || defaultSize != (v.size() + 1) * 2 || QString::fromStdWString(defaultStr) != v) { - WCHAR tmp[bufSize] = { 0 }; - if (!v.isEmpty()) wsprintf(tmp, v.replace(QChar('%'), qsl("%%")).toStdWString().c_str()); - LSTATUS status = RegSetValueEx(rkey, value, 0, REG_SZ, (BYTE*)tmp, (wcslen(tmp) + 1) * sizeof(WCHAR)); - if (status != ERROR_SUCCESS) { - QString msg = qsl("App Error: could not set %1, error %2").arg(value ? ('\'' + QString::fromStdWString(value) + '\'') : qsl("(Default)")).arg("%1: %2"); - _psLogError(msg.toUtf8().constData(), status); - return false; - } - } - return true; - } + //bool _psSetKeyValue(HKEY rkey, LPCWSTR value, QString v) { + // static const int bufSize = 4096; + // DWORD defaultType, defaultSize = bufSize * 2; + // WCHAR defaultStr[bufSize] = { 0 }; + // if (RegQueryValueEx(rkey, value, 0, &defaultType, (BYTE*)defaultStr, &defaultSize) != ERROR_SUCCESS || defaultType != REG_SZ || defaultSize != (v.size() + 1) * 2 || QString::fromStdWString(defaultStr) != v) { + // WCHAR tmp[bufSize] = { 0 }; + // if (!v.isEmpty()) wsprintf(tmp, v.replace(QChar('%'), qsl("%%")).toStdWString().c_str()); + // LSTATUS status = RegSetValueEx(rkey, value, 0, REG_SZ, (BYTE*)tmp, (wcslen(tmp) + 1) * sizeof(WCHAR)); + // if (status != ERROR_SUCCESS) { + // QString msg = qsl("App Error: could not set %1, error %2").arg(value ? ('\'' + QString::fromStdWString(value) + '\'') : qsl("(Default)")).arg("%1: %2"); + // _psLogError(msg.toUtf8().constData(), status); + // return false; + // } + // } + // return true; + //} } void RegisterCustomScheme() { #ifndef TDESKTOP_DISABLE_REGISTER_CUSTOM_SCHEME DEBUG_LOG(("App Info: Checking custom scheme 'tg'..")); - HKEY rkey; - QString exe = QDir::toNativeSeparators(cExeDir() + cExeName()); + //HKEY rkey; + //QString exe = QDir::toNativeSeparators(cExeDir() + cExeName()); - if (!_psOpenRegKey(L"Software\\Classes\\tg", &rkey)) return; - if (!_psSetKeyValue(rkey, L"URL Protocol", QString())) return; - if (!_psSetKeyValue(rkey, 0, qsl("URL:Telegram Link"))) return; + //if (!_psOpenRegKey(L"Software\\Classes\\tg", &rkey)) return; + //if (!_psSetKeyValue(rkey, L"URL Protocol", QString())) return; + //if (!_psSetKeyValue(rkey, 0, qsl("URL:Telegram Link"))) return; - if (!_psOpenRegKey(L"Software\\Classes\\tg\\DefaultIcon", &rkey)) return; - if (!_psSetKeyValue(rkey, 0, '"' + exe + qsl(",1\""))) return; + //if (!_psOpenRegKey(L"Software\\Classes\\tg\\DefaultIcon", &rkey)) return; + //if (!_psSetKeyValue(rkey, 0, '"' + exe + qsl(",1\""))) return; - if (!_psOpenRegKey(L"Software\\Classes\\tg\\shell", &rkey)) return; - if (!_psOpenRegKey(L"Software\\Classes\\tg\\shell\\open", &rkey)) return; - if (!_psOpenRegKey(L"Software\\Classes\\tg\\shell\\open\\command", &rkey)) return; - if (!_psSetKeyValue(rkey, 0, '"' + exe + qsl("\" -workdir \"") + cWorkingDir() + qsl("\" -- \"%1\""))) return; + //if (!_psOpenRegKey(L"Software\\Classes\\tg\\shell", &rkey)) return; + //if (!_psOpenRegKey(L"Software\\Classes\\tg\\shell\\open", &rkey)) return; + //if (!_psOpenRegKey(L"Software\\Classes\\tg\\shell\\open\\command", &rkey)) return; + //if (!_psSetKeyValue(rkey, 0, '"' + exe + qsl("\" -workdir \"") + cWorkingDir() + qsl("\" -- \"%1\""))) return; #endif } @@ -2273,12 +2286,12 @@ void psExecUpdater() { QString updater(QDir::toNativeSeparators(updaterPath)), wdir(QDir::toNativeSeparators(cWorkingDir())); - DEBUG_LOG(("Application Info: executing %1 %2").arg(cExeDir() + "Updater.exe").arg(targs)); - HINSTANCE r = ShellExecute(0, cWriteProtected() ? L"runas" : 0, updater.toStdWString().c_str(), targs.toStdWString().c_str(), wdir.isEmpty() ? 0 : wdir.toStdWString().c_str(), SW_SHOWNORMAL); - if (long(r) < 32) { - DEBUG_LOG(("Application Error: failed to execute %1, working directory: '%2', result: %3").arg(updater).arg(wdir).arg(long(r))); - psDeleteDir(cWorkingDir() + qsl("tupdates/temp")); - } + //DEBUG_LOG(("Application Info: executing %1 %2").arg(cExeDir() + "Updater.exe").arg(targs)); + //HINSTANCE r = ShellExecute(0, cWriteProtected() ? L"runas" : 0, updater.toStdWString().c_str(), targs.toStdWString().c_str(), wdir.isEmpty() ? 0 : wdir.toStdWString().c_str(), SW_SHOWNORMAL); + //if (long(r) < 32) { + // DEBUG_LOG(("Application Error: failed to execute %1, working directory: '%2', result: %3").arg(updater).arg(wdir).arg(long(r))); + // psDeleteDir(cWorkingDir() + qsl("tupdates/temp")); + //} } void psExecTelegram(const QString &crashreport) { @@ -2296,66 +2309,66 @@ void psExecTelegram(const QString &crashreport) { DEBUG_LOG(("Application Info: executing %1 %2").arg(cExeDir() + cExeName()).arg(targs)); Logs::closeMain(); SignalHandlers::finish(); - HINSTANCE r = ShellExecute(0, 0, telegram.toStdWString().c_str(), targs.toStdWString().c_str(), wdir.isEmpty() ? 0 : wdir.toStdWString().c_str(), SW_SHOWNORMAL); - if (long(r) < 32) { - DEBUG_LOG(("Application Error: failed to execute %1, working directory: '%2', result: %3").arg(telegram).arg(wdir).arg(long(r))); - } + //HINSTANCE r = ShellExecute(0, 0, telegram.toStdWString().c_str(), targs.toStdWString().c_str(), wdir.isEmpty() ? 0 : wdir.toStdWString().c_str(), SW_SHOWNORMAL); + //if (long(r) < 32) { + // DEBUG_LOG(("Application Error: failed to execute %1, working directory: '%2', result: %3").arg(telegram).arg(wdir).arg(long(r))); + //} } void _manageAppLnk(bool create, bool silent, int path_csidl, const wchar_t *args, const wchar_t *description) { - 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"); - if (create) { - ComPtr shellLink; - hr = CoCreateInstance(CLSID_ShellLink, nullptr, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&shellLink)); - if (SUCCEEDED(hr)) { - ComPtr persistFile; + //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"); + // if (create) { + // ComPtr shellLink; + // hr = CoCreateInstance(CLSID_ShellLink, nullptr, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&shellLink)); + // if (SUCCEEDED(hr)) { + // ComPtr persistFile; - QString exe = QDir::toNativeSeparators(cExeDir() + cExeName()), dir = QDir::toNativeSeparators(QDir(cWorkingDir()).absolutePath()); - shellLink->SetArguments(args); - shellLink->SetPath(exe.toStdWString().c_str()); - shellLink->SetWorkingDirectory(dir.toStdWString().c_str()); - shellLink->SetDescription(description); + // QString exe = QDir::toNativeSeparators(cExeDir() + cExeName()), dir = QDir::toNativeSeparators(QDir(cWorkingDir()).absolutePath()); + // shellLink->SetArguments(args); + // shellLink->SetPath(exe.toStdWString().c_str()); + // shellLink->SetWorkingDirectory(dir.toStdWString().c_str()); + // shellLink->SetDescription(description); - ComPtr propertyStore; - hr = shellLink.As(&propertyStore); - if (SUCCEEDED(hr)) { - PROPVARIANT appIdPropVar; - hr = InitPropVariantFromString(AppUserModelId(), &appIdPropVar); - if (SUCCEEDED(hr)) { - hr = propertyStore->SetValue(pkey_AppUserModel_ID, appIdPropVar); - PropVariantClear(&appIdPropVar); - if (SUCCEEDED(hr)) { - hr = propertyStore->Commit(); - } - } - } + // ComPtr propertyStore; + // hr = shellLink.As(&propertyStore); + // if (SUCCEEDED(hr)) { + // PROPVARIANT appIdPropVar; + // hr = InitPropVariantFromString(AppUserModelId(), &appIdPropVar); + // if (SUCCEEDED(hr)) { + // hr = propertyStore->SetValue(pkey_AppUserModel_ID, appIdPropVar); + // PropVariantClear(&appIdPropVar); + // if (SUCCEEDED(hr)) { + // hr = propertyStore->Commit(); + // } + // } + // } - hr = shellLink.As(&persistFile); - if (SUCCEEDED(hr)) { - hr = persistFile->Save(lnk.toStdWString().c_str(), TRUE); - } else { - if (!silent) LOG(("App Error: could not create interface IID_IPersistFile %1").arg(hr)); - } - } else { - if (!silent) LOG(("App Error: could not create instance of IID_IShellLink %1").arg(hr)); - } - } else { - QFile::remove(lnk); - } - } else { - if (!silent) LOG(("App Error: could not get CSIDL %1 folder %2").arg(path_csidl).arg(hr)); - } + // hr = shellLink.As(&persistFile); + // if (SUCCEEDED(hr)) { + // hr = persistFile->Save(lnk.toStdWString().c_str(), TRUE); + // } else { + // if (!silent) LOG(("App Error: could not create interface IID_IPersistFile %1").arg(hr)); + // } + // } else { + // if (!silent) LOG(("App Error: could not create instance of IID_IShellLink %1").arg(hr)); + // } + // } else { + // QFile::remove(lnk); + // } + //} else { + // if (!silent) LOG(("App Error: could not get CSIDL %1 folder %2").arg(path_csidl).arg(hr)); + //} } void psAutoStart(bool start, bool silent) { - _manageAppLnk(start, silent, CSIDL_STARTUP, L"-autostart", L"Telegram autorun link.\nYou can disable autorun in Telegram settings."); + //_manageAppLnk(start, silent, CSIDL_STARTUP, L"-autostart", L"Telegram autorun link.\nYou can disable autorun in Telegram settings."); } void psSendToMenu(bool send, bool silent) { - _manageAppLnk(send, silent, CSIDL_SENDTO, L"-sendpath", L"Telegram send to link.\nYou can disable send to menu item in Telegram settings."); + //_manageAppLnk(send, silent, CSIDL_SENDTO, L"-sendpath", L"Telegram send to link.\nYou can disable send to menu item in Telegram settings."); } void psUpdateOverlayed(TWidget *widget) { @@ -2372,1111 +2385,514 @@ void psUpdateOverlayed(TWidget *widget) { 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; - -typedef BOOL(FAR STDAPICALLTYPE *t_SymCleanup)( - _In_ HANDLE hProcess -); -t_SymCleanup symCleanup = 0; - -typedef PVOID (FAR STDAPICALLTYPE *t_SymFunctionTableAccess64)( - _In_ HANDLE hProcess, - _In_ DWORD64 AddrBase -); -t_SymFunctionTableAccess64 symFunctionTableAccess64 = 0; - -typedef BOOL (FAR STDAPICALLTYPE *t_SymGetLineFromAddr64)( - _In_ HANDLE hProcess, - _In_ DWORD64 dwAddr, - _Out_ PDWORD pdwDisplacement, - _Out_ PIMAGEHLP_LINEW64 Line -); -t_SymGetLineFromAddr64 symGetLineFromAddr64 = 0; - -typedef DWORD64 (FAR STDAPICALLTYPE *t_SymGetModuleBase64)( - _In_ HANDLE hProcess, - _In_ DWORD64 qwAddr -); -t_SymGetModuleBase64 symGetModuleBase64 = 0; - -typedef BOOL (FAR STDAPICALLTYPE *t_SymGetModuleInfo64)( - _In_ HANDLE hProcess, - _In_ DWORD64 qwAddr, - _Out_ PIMAGEHLP_MODULEW64 ModuleInfo -); -t_SymGetModuleInfo64 symGetModuleInfo64 = 0; - -typedef DWORD (FAR STDAPICALLTYPE *t_SymGetOptions)( - VOID -); -t_SymGetOptions symGetOptions = 0; - -typedef DWORD (FAR STDAPICALLTYPE *t_SymSetOptions)( - _In_ DWORD SymOptions -); -t_SymSetOptions symSetOptions = 0; - -typedef BOOL (FAR STDAPICALLTYPE *t_SymGetSymFromAddr64)( - IN HANDLE hProcess, - IN DWORD64 dwAddr, - OUT PDWORD64 pdwDisplacement, - OUT PIMAGEHLP_SYMBOL64 Symbol -); -t_SymGetSymFromAddr64 symGetSymFromAddr64 = 0; - -typedef BOOL (FAR STDAPICALLTYPE *t_SymInitialize)( - _In_ HANDLE hProcess, - _In_opt_ PCWSTR UserSearchPath, - _In_ BOOL fInvadeProcess -); -t_SymInitialize symInitialize = 0; - -typedef DWORD64 (FAR STDAPICALLTYPE *t_SymLoadModule64)( - _In_ HANDLE hProcess, - _In_opt_ HANDLE hFile, - _In_opt_ PCSTR ImageName, - _In_opt_ PCSTR ModuleName, - _In_ DWORD64 BaseOfDll, - _In_ DWORD SizeOfDll -); -t_SymLoadModule64 symLoadModule64; - -typedef BOOL (FAR STDAPICALLTYPE *t_StackWalk64)( - _In_ DWORD MachineType, - _In_ HANDLE hProcess, - _In_ HANDLE hThread, - _Inout_ LPSTACKFRAME64 StackFrame, - _Inout_ PVOID ContextRecord, - _In_opt_ PREAD_PROCESS_MEMORY_ROUTINE64 ReadMemoryRoutine, - _In_opt_ PFUNCTION_TABLE_ACCESS_ROUTINE64 FunctionTableAccessRoutine, - _In_opt_ PGET_MODULE_BASE_ROUTINE64 GetModuleBaseRoutine, - _In_opt_ PTRANSLATE_ADDRESS_ROUTINE64 TranslateAddress -); -t_StackWalk64 stackWalk64 = 0; - -typedef DWORD (FAR STDAPICALLTYPE *t_UnDecorateSymbolName)( - PCSTR DecoratedName, - PSTR UnDecoratedName, - DWORD UndecoratedLength, - DWORD Flags -); -t_UnDecorateSymbolName unDecorateSymbolName = 0; - -typedef BOOL(FAR STDAPICALLTYPE *t_SymGetSearchPath)( - _In_ HANDLE hProcess, - _Out_writes_(SearchPathLength) PWSTR SearchPath, - _In_ DWORD SearchPathLength -); -t_SymGetSearchPath symGetSearchPath = 0; - -BOOL __stdcall ReadProcessMemoryRoutine64( - _In_ HANDLE hProcess, - _In_ DWORD64 qwBaseAddress, - _Out_writes_bytes_(nSize) PVOID lpBuffer, - _In_ DWORD nSize, - _Out_ LPDWORD lpNumberOfBytesRead -) { - SIZE_T st; - BOOL bRet = ReadProcessMemory(hProcess, (LPVOID)qwBaseAddress, lpBuffer, nSize, &st); - *lpNumberOfBytesRead = (DWORD)st; - - return bRet; -} - -// **************************************** ToolHelp32 ************************ -#define MAX_MODULE_NAME32 255 -#define TH32CS_SNAPMODULE 0x00000008 -#pragma pack( push, 8 ) -typedef struct tagMODULEENTRY32 -{ - DWORD dwSize; - DWORD th32ModuleID; // This module - DWORD th32ProcessID; // owning process - DWORD GlblcntUsage; // Global usage count on the module - DWORD ProccntUsage; // Module usage count in th32ProcessID's context - BYTE * modBaseAddr; // Base address of module in th32ProcessID's context - DWORD modBaseSize; // Size in bytes of module starting at modBaseAddr - HMODULE hModule; // The hModule of this module in th32ProcessID's context - char szModule[MAX_MODULE_NAME32 + 1]; - char szExePath[MAX_PATH]; -} MODULEENTRY32; -typedef MODULEENTRY32 *PMODULEENTRY32; -typedef MODULEENTRY32 *LPMODULEENTRY32; -#pragma pack( pop ) - -typedef HANDLE (FAR STDAPICALLTYPE *t_CreateToolhelp32Snapshot)(DWORD dwFlags, DWORD th32ProcessID); -t_CreateToolhelp32Snapshot createToolhelp32Snapshot = 0; - -typedef BOOL (FAR STDAPICALLTYPE *t_Module32First)(HANDLE hSnapshot, LPMODULEENTRY32 lpme); -t_Module32First module32First = 0; - -typedef BOOL (FAR STDAPICALLTYPE *t_Module32Next)(HANDLE hSnapshot, LPMODULEENTRY32 lpme); -t_Module32Next module32Next = 0; - -bool LoadDbgHelp(bool extended = false) { - if (stackWalk64 && (!extended || symInitialize)) return true; - - HMODULE hDll = 0; - - WCHAR szTemp[4096]; - if (GetModuleFileName(NULL, szTemp, 4096) > 0) { - wcscat_s(szTemp, L".local"); - if (GetFileAttributes(szTemp) == INVALID_FILE_ATTRIBUTES) { - // ".local" file does not exist, so we can try to load the dbghelp.dll from the "Debugging Tools for Windows" - if (GetEnvironmentVariable(L"ProgramFiles", szTemp, 4096) > 0) { - wcscat_s(szTemp, L"\\Debugging Tools for Windows\\dbghelp.dll"); - // now check if the file exists: - if (GetFileAttributes(szTemp) != INVALID_FILE_ATTRIBUTES) { - hDll = LoadLibrary(szTemp); - } - } - // Still not found? Then try to load the 64-Bit version: - if (!hDll && (GetEnvironmentVariable(L"ProgramFiles", szTemp, 4096) > 0)) { - wcscat_s(szTemp, L"\\Debugging Tools for Windows 64-Bit\\dbghelp.dll"); - if (GetFileAttributes(szTemp) != INVALID_FILE_ATTRIBUTES) { - hDll = LoadLibrary(szTemp); - } - } - } - } - if (!hDll) { - hDll = LoadLibrary(L"DBGHELP.DLL"); - } - - if (!hDll) return false; - - stackWalk64 = (t_StackWalk64)GetProcAddress(hDll, "StackWalk64"); - symFunctionTableAccess64 = (t_SymFunctionTableAccess64)GetProcAddress(hDll, "SymFunctionTableAccess64"); - symGetModuleBase64 = (t_SymGetModuleBase64)GetProcAddress(hDll, "SymGetModuleBase64"); - - if (!stackWalk64 || - !symFunctionTableAccess64 || - !symGetModuleBase64) { - stackWalk64 = 0; - return false; - } - - if (extended) { - HANDLE hProcess = GetCurrentProcess(); - DWORD dwProcessId = GetCurrentProcessId(); - - symGetLineFromAddr64 = (t_SymGetLineFromAddr64)GetProcAddress(hDll, "SymGetLineFromAddrW64"); - symGetModuleInfo64 = (t_SymGetModuleInfo64)GetProcAddress(hDll, "SymGetModuleInfoW64"); - symGetSymFromAddr64 = (t_SymGetSymFromAddr64)GetProcAddress(hDll, "SymGetSymFromAddr64"); - unDecorateSymbolName = (t_UnDecorateSymbolName)GetProcAddress(hDll, "UnDecorateSymbolName"); - symInitialize = (t_SymInitialize)GetProcAddress(hDll, "SymInitializeW"); - symCleanup = (t_SymCleanup)GetProcAddress(hDll, "SymCleanup"); - symGetSearchPath = (t_SymGetSearchPath)GetProcAddress(hDll, "SymGetSearchPathW"); - symGetOptions = (t_SymGetOptions)GetProcAddress(hDll, "SymGetOptions"); - symSetOptions = (t_SymSetOptions)GetProcAddress(hDll, "SymSetOptions"); - symLoadModule64 = (t_SymLoadModule64)GetProcAddress(hDll, "SymLoadModule64"); - if (!symGetModuleInfo64 || - !symGetLineFromAddr64 || - !symGetSymFromAddr64 || - !unDecorateSymbolName || - !symInitialize || - !symCleanup || - !symGetOptions || - !symSetOptions || - !symLoadModule64) { - symInitialize = 0; - return false; - } - - const size_t nSymPathLen = 10 * MAX_PATH; - WCHAR szSymPath[nSymPathLen] = { 0 }; - - wcscat_s(szSymPath, nSymPathLen, L".;..;"); - - WCHAR szTemp[MAX_PATH + 1] = { 0 }; - if (GetCurrentDirectory(MAX_PATH, szTemp) > 0) { - wcscat_s(szSymPath, nSymPathLen, szTemp); - wcscat_s(szSymPath, nSymPathLen, L";"); - } - - if (GetModuleFileName(NULL, szTemp, MAX_PATH) > 0) { - for (WCHAR *p = (szTemp + wcslen(szTemp) - 1); p >= szTemp; --p) { - if ((*p == '\\') || (*p == '/') || (*p == ':')) { - *p = 0; - break; - } - } - if (wcslen(szTemp) > 0) { - wcscat_s(szSymPath, nSymPathLen, szTemp); - wcscat_s(szSymPath, nSymPathLen, L";"); - } - } - if (GetEnvironmentVariable(L"_NT_SYMBOL_PATH", szTemp, MAX_PATH) > 0) { - wcscat_s(szSymPath, nSymPathLen, szTemp); - wcscat_s(szSymPath, nSymPathLen, L";"); - } - if (GetEnvironmentVariable(L"_NT_ALTERNATE_SYMBOL_PATH", szTemp, MAX_PATH) > 0) { - wcscat_s(szSymPath, nSymPathLen, szTemp); - wcscat_s(szSymPath, nSymPathLen, L";"); - } - if (GetEnvironmentVariable(L"SYSTEMROOT", szTemp, MAX_PATH) > 0) { - wcscat_s(szSymPath, nSymPathLen, szTemp); - wcscat_s(szSymPath, nSymPathLen, L";"); - - // also add the "system32"-directory: - wcscat_s(szTemp, MAX_PATH, L"\\system32"); - wcscat_s(szSymPath, nSymPathLen, szTemp); - wcscat_s(szSymPath, nSymPathLen, L";"); - } - - if (GetEnvironmentVariable(L"SYSTEMDRIVE", szTemp, MAX_PATH) > 0) { - wcscat_s(szSymPath, nSymPathLen, L"SRV*"); - wcscat_s(szSymPath, nSymPathLen, szTemp); - wcscat_s(szSymPath, nSymPathLen, L"\\websymbols*http://msdl.microsoft.com/download/symbols;"); - } else { - wcscat_s(szSymPath, nSymPathLen, L"SRV*c:\\websymbols*http://msdl.microsoft.com/download/symbols;"); - } - - if (symInitialize(hProcess, szSymPath, FALSE) == FALSE) { - symInitialize = 0; - return false; - } - - DWORD symOptions = symGetOptions(); - symOptions |= SYMOPT_LOAD_LINES; - symOptions |= SYMOPT_FAIL_CRITICAL_ERRORS; - symOptions = symSetOptions(symOptions); - - const WCHAR *dllname[] = { L"kernel32.dll", L"tlhelp32.dll" }; - HINSTANCE hToolhelp = NULL; - - HANDLE hSnap; - MODULEENTRY32 me; - me.dwSize = sizeof(me); - BOOL keepGoing; - size_t i; - - for (i = 0; i < (sizeof(dllname) / sizeof(dllname[0])); i++) { - hToolhelp = LoadLibrary(dllname[i]); - if (!hToolhelp) continue; - - createToolhelp32Snapshot = (t_CreateToolhelp32Snapshot)GetProcAddress(hToolhelp, "CreateToolhelp32Snapshot"); - module32First = (t_Module32First)GetProcAddress(hToolhelp, "Module32First"); - module32Next = (t_Module32Next)GetProcAddress(hToolhelp, "Module32Next"); - if (createToolhelp32Snapshot && module32First && module32Next) { - break; // found the functions! - } - FreeLibrary(hToolhelp); - hToolhelp = NULL; - } - - if (hToolhelp == NULL) { - return false; - } - - hSnap = createToolhelp32Snapshot(TH32CS_SNAPMODULE, dwProcessId); - if (hSnap == (HANDLE)-1) - return FALSE; - - keepGoing = !!module32First(hSnap, &me); - int cnt = 0; - while (keepGoing) { - symLoadModule64(hProcess, 0, me.szExePath, me.szModule, (DWORD64)me.modBaseAddr, me.modBaseSize); - ++cnt; - keepGoing = !!module32Next(hSnap, &me); - } - CloseHandle(hSnap); - FreeLibrary(hToolhelp); - - return (cnt > 0); - } - - return true; -} - -struct StackEntry { - DWORD64 offset; // if 0, we have no valid entry - CHAR name[StackEntryMaxNameLength]; - CHAR undName[StackEntryMaxNameLength]; - CHAR undFullName[StackEntryMaxNameLength]; - DWORD64 offsetFromSmybol; - DWORD offsetFromLine; - DWORD lineNumber; - WCHAR lineFileName[StackEntryMaxNameLength]; - DWORD symType; - LPCSTR symTypeString; - WCHAR moduleName[StackEntryMaxNameLength]; - DWORD64 baseOfImage; - WCHAR loadedImageName[StackEntryMaxNameLength]; -}; - -enum StackEntryType { - StackEntryFirst, - StackEntryNext, - StackEntryLast, -}; - -char GetModuleInfoData[2 * sizeof(IMAGEHLP_MODULEW64)]; -BOOL _getModuleInfo(HANDLE hProcess, DWORD64 baseAddr, IMAGEHLP_MODULEW64 *pModuleInfo) { - pModuleInfo->SizeOfStruct = sizeof(IMAGEHLP_MODULEW64); - - memcpy(GetModuleInfoData, pModuleInfo, sizeof(IMAGEHLP_MODULEW64)); - if (symGetModuleInfo64(hProcess, baseAddr, (IMAGEHLP_MODULEW64*)GetModuleInfoData) != FALSE) { - // only copy as much memory as is reserved... - memcpy(pModuleInfo, GetModuleInfoData, sizeof(IMAGEHLP_MODULEW64)); - pModuleInfo->SizeOfStruct = sizeof(IMAGEHLP_MODULEW64); - return TRUE; - } - return FALSE; -} - void psWriteDump() { } -char ImageHlpSymbol64[sizeof(IMAGEHLP_SYMBOL64) + StackEntryMaxNameLength]; -QString psPrepareCrashDump(const QByteArray &crashdump, QString dumpfile) { - if (!LoadDbgHelp(true)) { - return qsl("ERROR: could not init dbghelp.dll!"); - } - - HANDLE hProcess = GetCurrentProcess(); - - QString initial = QString::fromUtf8(crashdump), result; - QStringList lines = initial.split('\n'); - result.reserve(initial.size()); - int32 i = 0, l = lines.size(); - QString versionstr; - uint64 version = 0, betaversion = 0; - for (; i < l; ++i) { - result.append(lines.at(i)).append('\n'); - QString line = lines.at(i).trimmed(); - if (line.startsWith(qstr("Version: "))) { - versionstr = line.mid(qstr("Version: ").size()).trimmed(); - version = versionstr.toULongLong(); - if (versionstr.endsWith(qstr("beta"))) { - if (version % 1000) { - betaversion = version; - } else { - version /= 1000; - } - } - ++i; - break; - } - } - - // maybe need to launch another executable - QString tolaunch; - if ((betaversion && betaversion != cBetaVersion()) || (!betaversion && version && version != AppVersion)) { - QString path = cExeDir(); - QRegularExpressionMatch m = QRegularExpression("deploy/\\d+\\.\\d+/\\d+\\.\\d+\\.\\d+(/|\\.dev/|_\\d+/)(Telegram/)?$").match(path); - if (m.hasMatch()) { - QString base = path.mid(0, m.capturedStart()) + qstr("deploy/"); - int32 major = version / 1000000, minor = (version % 1000000) / 1000, micro = (version % 1000); - base += qsl("%1.%2/%3.%4.%5").arg(major).arg(minor).arg(major).arg(minor).arg(micro); - if (betaversion) { - base += qsl("_%1").arg(betaversion); - } else if (QDir(base + qstr(".dev")).exists()) { - base += qstr(".dev"); - } - if (QFile(base + qstr("/Telegram/Telegram.exe")).exists()) { - base += qstr("/Telegram"); - } - tolaunch = base + qstr("Telegram.exe"); - } - } - if (!tolaunch.isEmpty()) { - result.append(qsl("ERROR: for this crashdump executable '%1' should be used!").arg(tolaunch)); - } - - while (i < l) { - for (; i < l; ++i) { - result.append(lines.at(i)).append('\n'); - QString line = lines.at(i).trimmed(); - if (line == qstr("Backtrace:")) { - ++i; - break; - } - } - - IMAGEHLP_SYMBOL64 *pSym = NULL; - IMAGEHLP_MODULEW64 Module; - IMAGEHLP_LINEW64 Line; - - pSym = (IMAGEHLP_SYMBOL64*)ImageHlpSymbol64; - memset(pSym, 0, sizeof(IMAGEHLP_SYMBOL64) + StackEntryMaxNameLength); - pSym->SizeOfStruct = sizeof(IMAGEHLP_SYMBOL64); - pSym->MaxNameLength = StackEntryMaxNameLength; - - memset(&Line, 0, sizeof(Line)); - Line.SizeOfStruct = sizeof(Line); - - memset(&Module, 0, sizeof(Module)); - Module.SizeOfStruct = sizeof(Module); - - StackEntry csEntry; - for (int32 start = i; i < l; ++i) { - QString line = lines.at(i).trimmed(); - if (line.isEmpty()) break; - - result.append(qsl("%1. ").arg(i + 1 - start)); - if (!QRegularExpression(qsl("^\\d+$")).match(line).hasMatch()) { - if (!lines.at(i).startsWith(qstr("ERROR: "))) { - result.append(qstr("BAD LINE: ")); - } - result.append(line).append('\n'); - continue; - } - - DWORD64 address = line.toULongLong(); - - csEntry.offset = address; - csEntry.name[0] = 0; - csEntry.undName[0] = 0; - csEntry.undFullName[0] = 0; - csEntry.offsetFromSmybol = 0; - csEntry.offsetFromLine = 0; - csEntry.lineFileName[0] = 0; - csEntry.lineNumber = 0; - csEntry.loadedImageName[0] = 0; - csEntry.moduleName[0] = 0; - - if (symGetSymFromAddr64(hProcess, address, &(csEntry.offsetFromSmybol), pSym) != FALSE) { - // TODO: Mache dies sicher...! - strcpy_s(csEntry.name, pSym->Name); - - unDecorateSymbolName(pSym->Name, csEntry.undName, StackEntryMaxNameLength, UNDNAME_NAME_ONLY); - unDecorateSymbolName(pSym->Name, csEntry.undFullName, StackEntryMaxNameLength, UNDNAME_COMPLETE); - - if (symGetLineFromAddr64) { - if (symGetLineFromAddr64(hProcess, address, &(csEntry.offsetFromLine), &Line) != FALSE) { - csEntry.lineNumber = Line.LineNumber; - - // TODO: Mache dies sicher...! - wcscpy_s(csEntry.lineFileName, Line.FileName); - } - } - } else { - result.append("ERROR: could not get Sym from Addr! for ").append(QString::number(address)).append('\n'); - continue; - } - - if (_getModuleInfo(hProcess, address, &Module) != FALSE) { - // TODO: Mache dies sicher...! - wcscpy_s(csEntry.moduleName, Module.ModuleName); - } - if (csEntry.name[0] == 0) { - strcpy_s(csEntry.name, "(function-name not available)"); - } - if (csEntry.undName[0] != 0) { - strcpy_s(csEntry.name, csEntry.undName); - } - if (csEntry.undFullName[0] != 0) { - strcpy_s(csEntry.name, csEntry.undFullName); - } - if (csEntry.lineFileName[0] == 0) { - if (csEntry.moduleName[0] == 0) { - wcscpy_s(csEntry.moduleName, L"module-name not available"); - } - result.append(csEntry.name).append(qsl(" (%1) 0x%3").arg(QString::fromWCharArray(csEntry.moduleName)).arg(address, 0, 16)).append('\n'); - } else { - QString file = QString::fromWCharArray(csEntry.lineFileName).toLower(); - int32 index = file.indexOf(qstr("tbuild\\tdesktop\\telegram\\")); - if (index >= 0) { - file = file.mid(index + qstr("tbuild\\tdesktop\\telegram\\").size()); - if (file.startsWith(qstr("sourcefiles\\"))) { - file = file.mid(qstr("sourcefiles\\").size()); - } - } - result.append(csEntry.name).append(qsl(" (%1 - %2) 0x%3").arg(file).arg(csEntry.lineNumber).arg(address, 0, 16)).append('\n'); - } - } - } - - symCleanup(hProcess); - return result; -} - -void psWriteStackTrace() { - if (!LoadDbgHelp()) { - SignalHandlers::dump() << "ERROR: Could not load dbghelp.dll!\n"; - return; - } - - HANDLE hThread = GetCurrentThread(), hProcess = GetCurrentProcess(); - const CONTEXT *context = NULL; - LPVOID pUserData = NULL; - - CONTEXT c; - int frameNum; - - memset(&c, 0, sizeof(CONTEXT)); - c.ContextFlags = CONTEXT_FULL; - RtlCaptureContext(&c); - - // init STACKFRAME for first call - STACKFRAME64 s; // in/out stackframe - memset(&s, 0, sizeof(s)); - DWORD imageType; -#ifdef _M_IX86 - // normally, call ImageNtHeader() and use machine info from PE header - imageType = IMAGE_FILE_MACHINE_I386; - s.AddrPC.Offset = c.Eip; - s.AddrPC.Mode = AddrModeFlat; - s.AddrFrame.Offset = c.Ebp; - s.AddrFrame.Mode = AddrModeFlat; - s.AddrStack.Offset = c.Esp; - s.AddrStack.Mode = AddrModeFlat; -#elif _M_X64 - imageType = IMAGE_FILE_MACHINE_AMD64; - s.AddrPC.Offset = c.Rip; - s.AddrPC.Mode = AddrModeFlat; - s.AddrFrame.Offset = c.Rsp; - s.AddrFrame.Mode = AddrModeFlat; - s.AddrStack.Offset = c.Rsp; - s.AddrStack.Mode = AddrModeFlat; -#elif _M_IA64 - imageType = IMAGE_FILE_MACHINE_IA64; - s.AddrPC.Offset = c.StIIP; - s.AddrPC.Mode = AddrModeFlat; - s.AddrFrame.Offset = c.IntSp; - s.AddrFrame.Mode = AddrModeFlat; - s.AddrBStore.Offset = c.RsBSP; - s.AddrBStore.Mode = AddrModeFlat; - s.AddrStack.Offset = c.IntSp; - s.AddrStack.Mode = AddrModeFlat; -#else -#error "Platform not supported!" -#endif - - for (frameNum = 0; frameNum < 1024; ++frameNum) { - // get next stack frame (StackWalk64(), SymFunctionTableAccess64(), SymGetModuleBase64()) - // if this returns ERROR_INVALID_ADDRESS (487) or ERROR_NOACCESS (998), you can - // assume that either you are done, or that the stack is so hosed that the next - // deeper frame could not be found. - // CONTEXT need not to be suplied if imageTyp is IMAGE_FILE_MACHINE_I386! - if (!stackWalk64(imageType, hProcess, hThread, &s, &c, ReadProcessMemoryRoutine64, symFunctionTableAccess64, symGetModuleBase64, NULL)) { - SignalHandlers::dump() << "ERROR: Call to StackWalk64() failed!\n"; - return; - } - - if (s.AddrPC.Offset == s.AddrReturn.Offset) { - SignalHandlers::dump() << s.AddrPC.Offset << "\n"; - SignalHandlers::dump() << "ERROR: StackWalk64() endless callstack!"; - return; - } - if (s.AddrPC.Offset != 0) { // we seem to have a valid PC - SignalHandlers::dump() << s.AddrPC.Offset << "\n"; - } - - if (s.AddrReturn.Offset == 0) { - break; - } - } -} - -class StringReferenceWrapper { -public: - - StringReferenceWrapper(_In_reads_(length) PCWSTR stringRef, _In_ UINT32 length) throw() { - HRESULT hr = windowsCreateStringReference(stringRef, length, &_header, &_hstring); - if (!SUCCEEDED(hr)) { - RaiseException(static_cast(STATUS_INVALID_PARAMETER), EXCEPTION_NONCONTINUABLE, 0, nullptr); - } - } - - ~StringReferenceWrapper() { - windowsDeleteString(_hstring); - } - - template - StringReferenceWrapper(_In_reads_(N) wchar_t const (&stringRef)[N]) throw() { - UINT32 length = N - 1; - HRESULT hr = windowsCreateStringReference(stringRef, length, &_header, &_hstring); - if (!SUCCEEDED(hr)) { - RaiseException(static_cast(STATUS_INVALID_PARAMETER), EXCEPTION_NONCONTINUABLE, 0, nullptr); - } - } - - template - StringReferenceWrapper(_In_reads_(_) wchar_t(&stringRef)[_]) throw() { - UINT32 length; - HRESULT hr = SizeTToUInt32(wcslen(stringRef), &length); - if (!SUCCEEDED(hr)) { - RaiseException(static_cast(STATUS_INVALID_PARAMETER), EXCEPTION_NONCONTINUABLE, 0, nullptr); - } - - windowsCreateStringReference(stringRef, length, &_header, &_hstring); - } - - HSTRING Get() const throw() { - return _hstring; - } - -private: - HSTRING _hstring; - HSTRING_HEADER _header; - -}; - -HRESULT SetNodeValueString(_In_ HSTRING inputString, _In_ IXmlNode *node, _In_ IXmlDocument *xml) { - ComPtr inputText; - - HRESULT hr = xml->CreateTextNode(inputString, &inputText); - if (!SUCCEEDED(hr)) return hr; - ComPtr inputTextNode; - - hr = inputText.As(&inputTextNode); - if (!SUCCEEDED(hr)) return hr; - - ComPtr pAppendedChild; - return node->AppendChild(inputTextNode.Get(), &pAppendedChild); -} - -HRESULT SetAudioSilent(_In_ IXmlDocument *toastXml) { - ComPtr nodeList; - HRESULT hr = toastXml->GetElementsByTagName(StringReferenceWrapper(L"audio").Get(), &nodeList); - if (!SUCCEEDED(hr)) return hr; - - ComPtr audioNode; - hr = nodeList->Item(0, &audioNode); - if (!SUCCEEDED(hr)) return hr; - - if (audioNode) { - ComPtr audioElement; - hr = audioNode.As(&audioElement); - if (!SUCCEEDED(hr)) return hr; - - hr = audioElement->SetAttribute(StringReferenceWrapper(L"silent").Get(), StringReferenceWrapper(L"true").Get()); - if (!SUCCEEDED(hr)) return hr; - } else { - ComPtr audioElement; - hr = toastXml->CreateElement(StringReferenceWrapper(L"audio").Get(), &audioElement); - if (!SUCCEEDED(hr)) return hr; - - hr = audioElement->SetAttribute(StringReferenceWrapper(L"silent").Get(), StringReferenceWrapper(L"true").Get()); - if (!SUCCEEDED(hr)) return hr; - - ComPtr audioNode; - hr = audioElement.As(&audioNode); - if (!SUCCEEDED(hr)) return hr; - - ComPtr nodeList; - hr = toastXml->GetElementsByTagName(StringReferenceWrapper(L"toast").Get(), &nodeList); - if (!SUCCEEDED(hr)) return hr; - - ComPtr toastNode; - hr = nodeList->Item(0, &toastNode); - if (!SUCCEEDED(hr)) return hr; - - ComPtr appendedNode; - hr = toastNode->AppendChild(audioNode.Get(), &appendedNode); - } - return hr; -} - -HRESULT SetImageSrc(_In_z_ const wchar_t *imagePath, _In_ IXmlDocument *toastXml) { - wchar_t imageSrc[MAX_PATH] = L"file:///"; - HRESULT hr = StringCchCat(imageSrc, ARRAYSIZE(imageSrc), imagePath); - if (!SUCCEEDED(hr)) return hr; - - ComPtr nodeList; - hr = toastXml->GetElementsByTagName(StringReferenceWrapper(L"image").Get(), &nodeList); - if (!SUCCEEDED(hr)) return hr; - - ComPtr imageNode; - hr = nodeList->Item(0, &imageNode); - if (!SUCCEEDED(hr)) return hr; - - ComPtr attributes; - hr = imageNode->get_Attributes(&attributes); - if (!SUCCEEDED(hr)) return hr; - - ComPtr srcAttribute; - hr = attributes->GetNamedItem(StringReferenceWrapper(L"src").Get(), &srcAttribute); - if (!SUCCEEDED(hr)) return hr; - - return SetNodeValueString(StringReferenceWrapper(imageSrc).Get(), srcAttribute.Get(), toastXml); -} - -typedef ABI::Windows::Foundation::ITypedEventHandler DesktopToastActivatedEventHandler; -typedef ABI::Windows::Foundation::ITypedEventHandler DesktopToastDismissedEventHandler; -typedef ABI::Windows::Foundation::ITypedEventHandler DesktopToastFailedEventHandler; - -class ToastEventHandler : public Implements { -public: - - ToastEventHandler::ToastEventHandler(const PeerId &peer, MsgId msg) : _ref(1), _peerId(peer), _msgId(msg) { - } - ~ToastEventHandler() { - } - - // DesktopToastActivatedEventHandler - IFACEMETHODIMP Invoke(_In_ IToastNotification *sender, _In_ IInspectable* args) { - ToastNotifications::iterator i = toastNotifications.find(_peerId); - if (i != toastNotifications.cend()) { - i.value().remove(_msgId); - if (i.value().isEmpty()) { - toastNotifications.erase(i); - } - } - if (App::wnd()) { - History *history = App::history(_peerId); - - App::wnd()->showFromTray(); - if (App::passcoded()) { - App::wnd()->setInnerFocus(); - App::wnd()->notifyClear(); - } else { - App::wnd()->hideSettings(); - bool tomsg = !history->peer->isUser() && (_msgId > 0); - if (tomsg) { - HistoryItem *item = App::histItemById(peerToChannel(_peerId), _msgId); - if (!item || !item->mentionsMe()) { - tomsg = false; - } - } - Ui::showPeerHistory(history, tomsg ? _msgId : ShowAtUnreadMsgId); - App::wnd()->notifyClear(history); - } - SetForegroundWindow(App::wnd()->psHwnd()); - } - return S_OK; - } - - // DesktopToastDismissedEventHandler - IFACEMETHODIMP Invoke(_In_ IToastNotification *sender, _In_ IToastDismissedEventArgs *e) { - ToastDismissalReason tdr; - if (SUCCEEDED(e->get_Reason(&tdr))) { - switch (tdr) { - case ToastDismissalReason_ApplicationHidden: - break; - case ToastDismissalReason_UserCanceled: - case ToastDismissalReason_TimedOut: - default: - ToastNotifications::iterator i = toastNotifications.find(_peerId); - if (i != toastNotifications.cend()) { - i.value().remove(_msgId); - if (i.value().isEmpty()) { - toastNotifications.erase(i); - } - } - break; - } - } - return S_OK; - } - - // DesktopToastFailedEventHandler - IFACEMETHODIMP Invoke(_In_ IToastNotification *sender, _In_ IToastFailedEventArgs *e) { - ToastNotifications::iterator i = toastNotifications.find(_peerId); - if (i != toastNotifications.cend()) { - i.value().remove(_msgId); - if (i.value().isEmpty()) { - toastNotifications.erase(i); - } - } - return S_OK; - } - - // IUnknown - IFACEMETHODIMP_(ULONG) AddRef() { - return InterlockedIncrement(&_ref); - } - - IFACEMETHODIMP_(ULONG) Release() { - ULONG l = InterlockedDecrement(&_ref); - if (l == 0) delete this; - return l; - } - - IFACEMETHODIMP QueryInterface(_In_ REFIID riid, _COM_Outptr_ void **ppv) { - if (IsEqualIID(riid, IID_IUnknown)) - *ppv = static_cast(static_cast(this)); - else if (IsEqualIID(riid, __uuidof(DesktopToastActivatedEventHandler))) - *ppv = static_cast(this); - else if (IsEqualIID(riid, __uuidof(DesktopToastDismissedEventHandler))) - *ppv = static_cast(this); - else if (IsEqualIID(riid, __uuidof(DesktopToastFailedEventHandler))) - *ppv = static_cast(this); - else *ppv = nullptr; - - if (*ppv) { - reinterpret_cast(*ppv)->AddRef(); - return S_OK; - } - - return E_NOINTERFACE; - } - -private: - - ULONG _ref; - PeerId _peerId; - MsgId _msgId; -}; - -template -_Check_return_ __inline HRESULT _1_GetActivationFactory(_In_ HSTRING activatableClassId, _COM_Outptr_ T** factory) { - return roGetActivationFactory(activatableClassId, IID_INS_ARGS(factory)); -} - -template -inline HRESULT wrap_GetActivationFactory(_In_ HSTRING activatableClassId, _Inout_ Details::ComPtrRef factory) throw() { - return _1_GetActivationFactory(activatableClassId, factory.ReleaseAndGetAddressOf()); -} - -QString toastImage(const StorageKey &key, PeerData *peer) { - uint64 ms = getms(true); - ToastImages::iterator i = toastImages.find(key); - if (i != toastImages.cend()) { - if (i->until) { - i->until = ms + NotifyDeletePhotoAfter; - if (App::wnd()) App::wnd()->psCleanNotifyPhotosIn(-NotifyDeletePhotoAfter); - } - } else { - ToastImage v; - if (key.first) { - v.until = ms + NotifyDeletePhotoAfter; - if (App::wnd()) App::wnd()->psCleanNotifyPhotosIn(-NotifyDeletePhotoAfter); - } else { - v.until = 0; - } - v.path = cWorkingDir() + qsl("tdata/temp/") + QString::number(MTP::nonce(), 16) + qsl(".png"); - if (key.first || key.second) { - peer->saveUserpic(v.path); - } else { - App::wnd()->iconLarge().save(v.path, "PNG"); - } - i = toastImages.insert(key, v); - ToastImageSavedFlag = true; - } - return i->path; -} - -bool CreateToast(PeerData *peer, int32 msgId, bool showpix, const QString &title, const QString &subtitle, const QString &msg) { - if (!useToast || !toastNotificationManager || !toastNotifier || !toastNotificationFactory) return false; - - ComPtr toastXml; - bool withSubtitle = !subtitle.isEmpty(); - - HRESULT hr = toastNotificationManager->GetTemplateContent(withSubtitle ? ToastTemplateType_ToastImageAndText04 : ToastTemplateType_ToastImageAndText02, &toastXml); - if (!SUCCEEDED(hr)) return false; - - hr = SetAudioSilent(toastXml.Get()); - if (!SUCCEEDED(hr)) return false; - - StorageKey key; - QString imagePath; - if (showpix) { - key = peer->userpicUniqueKey(); - } else { - key = StorageKey(0, 0); - } - QString image = toastImage(key, peer); - std::wstring wimage = QDir::toNativeSeparators(image).toStdWString(); - - hr = SetImageSrc(wimage.c_str(), toastXml.Get()); - if (!SUCCEEDED(hr)) return false; - - ComPtr nodeList; - hr = toastXml->GetElementsByTagName(StringReferenceWrapper(L"text").Get(), &nodeList); - if (!SUCCEEDED(hr)) return false; - - UINT32 nodeListLength; - hr = nodeList->get_Length(&nodeListLength); - if (!SUCCEEDED(hr)) return false; - - if (nodeListLength < (withSubtitle ? 3U : 2U)) return false; - - { - ComPtr textNode; - hr = nodeList->Item(0, &textNode); - if (!SUCCEEDED(hr)) return false; - - std::wstring wtitle = title.toStdWString(); - hr = SetNodeValueString(StringReferenceWrapper(wtitle.data(), wtitle.size()).Get(), textNode.Get(), toastXml.Get()); - if (!SUCCEEDED(hr)) return false; - } - if (withSubtitle) { - ComPtr textNode; - hr = nodeList->Item(1, &textNode); - if (!SUCCEEDED(hr)) return false; - - std::wstring wsubtitle = subtitle.toStdWString(); - hr = SetNodeValueString(StringReferenceWrapper(wsubtitle.data(), wsubtitle.size()).Get(), textNode.Get(), toastXml.Get()); - if (!SUCCEEDED(hr)) return false; - } - { - ComPtr textNode; - hr = nodeList->Item(withSubtitle ? 2 : 1, &textNode); - if (!SUCCEEDED(hr)) return false; - - std::wstring wmsg = msg.toStdWString(); - hr = SetNodeValueString(StringReferenceWrapper(wmsg.data(), wmsg.size()).Get(), textNode.Get(), toastXml.Get()); - if (!SUCCEEDED(hr)) return false; - } - - ComPtr toast; - hr = toastNotificationFactory->CreateToastNotification(toastXml.Get(), &toast); - if (!SUCCEEDED(hr)) return false; - - EventRegistrationToken activatedToken, dismissedToken, failedToken; - ComPtr eventHandler(new ToastEventHandler(peer->id, msgId)); - - hr = toast->add_Activated(eventHandler.Get(), &activatedToken); - if (!SUCCEEDED(hr)) return false; - - hr = toast->add_Dismissed(eventHandler.Get(), &dismissedToken); - if (!SUCCEEDED(hr)) return false; - - hr = toast->add_Failed(eventHandler.Get(), &failedToken); - if (!SUCCEEDED(hr)) return false; - - ToastNotifications::iterator i = toastNotifications.find(peer->id); - if (i != toastNotifications.cend()) { - QMap::iterator j = i->find(msgId); - if (j != i->cend()) { - ComPtr notify = j->p; - i->erase(j); - toastNotifier->Hide(notify.Get()); - i = toastNotifications.find(peer->id); - } - } - if (i == toastNotifications.cend()) { - i = toastNotifications.insert(peer->id, QMap()); - } - hr = toastNotifier->Show(toast.Get()); - if (!SUCCEEDED(hr)) { - i = toastNotifications.find(peer->id); - if (i != toastNotifications.cend() && i->isEmpty()) toastNotifications.erase(i); - return false; - } - toastNotifications[peer->id].insert(msgId, toast); - - return true; -} +//class StringReferenceWrapper { +//public: +// +// StringReferenceWrapper(_In_reads_(length) PCWSTR stringRef, _In_ UINT32 length) throw() { +// HRESULT hr = windowsCreateStringReference(stringRef, length, &_header, &_hstring); +// if (!SUCCEEDED(hr)) { +// RaiseException(static_cast(STATUS_INVALID_PARAMETER), EXCEPTION_NONCONTINUABLE, 0, nullptr); +// } +// } +// +// ~StringReferenceWrapper() { +// windowsDeleteString(_hstring); +// } +// +// template +// StringReferenceWrapper(_In_reads_(N) wchar_t const (&stringRef)[N]) throw() { +// UINT32 length = N - 1; +// HRESULT hr = windowsCreateStringReference(stringRef, length, &_header, &_hstring); +// if (!SUCCEEDED(hr)) { +// RaiseException(static_cast(STATUS_INVALID_PARAMETER), EXCEPTION_NONCONTINUABLE, 0, nullptr); +// } +// } +// +// template +// StringReferenceWrapper(_In_reads_(_) wchar_t(&stringRef)[_]) throw() { +// UINT32 length; +// HRESULT hr = SizeTToUInt32(wcslen(stringRef), &length); +// if (!SUCCEEDED(hr)) { +// RaiseException(static_cast(STATUS_INVALID_PARAMETER), EXCEPTION_NONCONTINUABLE, 0, nullptr); +// } +// +// windowsCreateStringReference(stringRef, length, &_header, &_hstring); +// } +// +// HSTRING Get() const throw() { +// return _hstring; +// } +// +//private: +// HSTRING _hstring; +// HSTRING_HEADER _header; +// +//}; + +//HRESULT SetNodeValueString(_In_ HSTRING inputString, _In_ IXmlNode *node, _In_ IXmlDocument *xml) { +// ComPtr inputText; +// +// HRESULT hr = xml->CreateTextNode(inputString, &inputText); +// if (!SUCCEEDED(hr)) return hr; +// ComPtr inputTextNode; +// +// hr = inputText.As(&inputTextNode); +// if (!SUCCEEDED(hr)) return hr; +// +// ComPtr pAppendedChild; +// return node->AppendChild(inputTextNode.Get(), &pAppendedChild); +//} + +//HRESULT SetAudioSilent(_In_ IXmlDocument *toastXml) { +// ComPtr nodeList; +// HRESULT hr = toastXml->GetElementsByTagName(StringReferenceWrapper(L"audio").Get(), &nodeList); +// if (!SUCCEEDED(hr)) return hr; +// +// ComPtr audioNode; +// hr = nodeList->Item(0, &audioNode); +// if (!SUCCEEDED(hr)) return hr; +// +// if (audioNode) { +// ComPtr audioElement; +// hr = audioNode.As(&audioElement); +// if (!SUCCEEDED(hr)) return hr; +// +// hr = audioElement->SetAttribute(StringReferenceWrapper(L"silent").Get(), StringReferenceWrapper(L"true").Get()); +// if (!SUCCEEDED(hr)) return hr; +// } else { +// ComPtr audioElement; +// hr = toastXml->CreateElement(StringReferenceWrapper(L"audio").Get(), &audioElement); +// if (!SUCCEEDED(hr)) return hr; +// +// hr = audioElement->SetAttribute(StringReferenceWrapper(L"silent").Get(), StringReferenceWrapper(L"true").Get()); +// if (!SUCCEEDED(hr)) return hr; +// +// ComPtr audioNode; +// hr = audioElement.As(&audioNode); +// if (!SUCCEEDED(hr)) return hr; +// +// ComPtr nodeList; +// hr = toastXml->GetElementsByTagName(StringReferenceWrapper(L"toast").Get(), &nodeList); +// if (!SUCCEEDED(hr)) return hr; +// +// ComPtr toastNode; +// hr = nodeList->Item(0, &toastNode); +// if (!SUCCEEDED(hr)) return hr; +// +// ComPtr appendedNode; +// hr = toastNode->AppendChild(audioNode.Get(), &appendedNode); +// } +// return hr; +//} + +//HRESULT SetImageSrc(_In_z_ const wchar_t *imagePath, _In_ IXmlDocument *toastXml) { +// wchar_t imageSrc[MAX_PATH] = L"file:///"; +// HRESULT hr = StringCchCat(imageSrc, ARRAYSIZE(imageSrc), imagePath); +// if (!SUCCEEDED(hr)) return hr; +// +// ComPtr nodeList; +// hr = toastXml->GetElementsByTagName(StringReferenceWrapper(L"image").Get(), &nodeList); +// if (!SUCCEEDED(hr)) return hr; +// +// ComPtr imageNode; +// hr = nodeList->Item(0, &imageNode); +// if (!SUCCEEDED(hr)) return hr; +// +// ComPtr attributes; +// hr = imageNode->get_Attributes(&attributes); +// if (!SUCCEEDED(hr)) return hr; +// +// ComPtr srcAttribute; +// hr = attributes->GetNamedItem(StringReferenceWrapper(L"src").Get(), &srcAttribute); +// if (!SUCCEEDED(hr)) return hr; +// +// return SetNodeValueString(StringReferenceWrapper(imageSrc).Get(), srcAttribute.Get(), toastXml); +//} + +//typedef ABI::Windows::Foundation::ITypedEventHandler DesktopToastActivatedEventHandler; +//typedef ABI::Windows::Foundation::ITypedEventHandler DesktopToastDismissedEventHandler; +//typedef ABI::Windows::Foundation::ITypedEventHandler DesktopToastFailedEventHandler; + +//class ToastEventHandler : public Implements { +//public: +// +// ToastEventHandler::ToastEventHandler(const PeerId &peer, MsgId msg) : _ref(1), _peerId(peer), _msgId(msg) { +// } +// ~ToastEventHandler() { +// } +// +// // DesktopToastActivatedEventHandler +// IFACEMETHODIMP Invoke(_In_ IToastNotification *sender, _In_ IInspectable* args) { +// ToastNotifications::iterator i = toastNotifications.find(_peerId); +// if (i != toastNotifications.cend()) { +// i.value().remove(_msgId); +// if (i.value().isEmpty()) { +// toastNotifications.erase(i); +// } +// } +// if (App::wnd()) { +// History *history = App::history(_peerId); +// +// App::wnd()->showFromTray(); +// if (App::passcoded()) { +// App::wnd()->setInnerFocus(); +// App::wnd()->notifyClear(); +// } else { +// App::wnd()->hideSettings(); +// bool tomsg = !history->peer->isUser() && (_msgId > 0); +// if (tomsg) { +// HistoryItem *item = App::histItemById(peerToChannel(_peerId), _msgId); +// if (!item || !item->mentionsMe()) { +// tomsg = false; +// } +// } +// Ui::showPeerHistory(history, tomsg ? _msgId : ShowAtUnreadMsgId); +// App::wnd()->notifyClear(history); +// } +// //SetForegroundWindow(App::wnd()->psHwnd()); +// } +// return S_OK; +// } +// +// // DesktopToastDismissedEventHandler +// IFACEMETHODIMP Invoke(_In_ IToastNotification *sender, _In_ IToastDismissedEventArgs *e) { +// ToastDismissalReason tdr; +// if (SUCCEEDED(e->get_Reason(&tdr))) { +// switch (tdr) { +// case ToastDismissalReason_ApplicationHidden: +// break; +// case ToastDismissalReason_UserCanceled: +// case ToastDismissalReason_TimedOut: +// default: +// ToastNotifications::iterator i = toastNotifications.find(_peerId); +// if (i != toastNotifications.cend()) { +// i.value().remove(_msgId); +// if (i.value().isEmpty()) { +// toastNotifications.erase(i); +// } +// } +// break; +// } +// } +// return S_OK; +// } +// +// // DesktopToastFailedEventHandler +// IFACEMETHODIMP Invoke(_In_ IToastNotification *sender, _In_ IToastFailedEventArgs *e) { +// ToastNotifications::iterator i = toastNotifications.find(_peerId); +// if (i != toastNotifications.cend()) { +// i.value().remove(_msgId); +// if (i.value().isEmpty()) { +// toastNotifications.erase(i); +// } +// } +// return S_OK; +// } +// +// // IUnknown +// IFACEMETHODIMP_(ULONG) AddRef() { +// return InterlockedIncrement(&_ref); +// } +// +// IFACEMETHODIMP_(ULONG) Release() { +// ULONG l = InterlockedDecrement(&_ref); +// if (l == 0) delete this; +// return l; +// } +// +// IFACEMETHODIMP QueryInterface(_In_ REFIID riid, _COM_Outptr_ void **ppv) { +// if (IsEqualIID(riid, IID_IUnknown)) +// *ppv = static_cast(static_cast(this)); +// else if (IsEqualIID(riid, __uuidof(DesktopToastActivatedEventHandler))) +// *ppv = static_cast(this); +// else if (IsEqualIID(riid, __uuidof(DesktopToastDismissedEventHandler))) +// *ppv = static_cast(this); +// else if (IsEqualIID(riid, __uuidof(DesktopToastFailedEventHandler))) +// *ppv = static_cast(this); +// else *ppv = nullptr; +// +// if (*ppv) { +// reinterpret_cast(*ppv)->AddRef(); +// return S_OK; +// } +// +// return E_NOINTERFACE; +// } +// +//private: +// +// ULONG _ref; +// PeerId _peerId; +// MsgId _msgId; +//}; +// +//template +//_Check_return_ __inline HRESULT _1_GetActivationFactory(_In_ HSTRING activatableClassId, _COM_Outptr_ T** factory) { +// return roGetActivationFactory(activatableClassId, IID_INS_ARGS(factory)); +//} +// +//template +//inline HRESULT wrap_GetActivationFactory(_In_ HSTRING activatableClassId, _Inout_ Details::ComPtrRef factory) throw() { +// return _1_GetActivationFactory(activatableClassId, factory.ReleaseAndGetAddressOf()); +//} + +//QString toastImage(const StorageKey &key, PeerData *peer) { +// uint64 ms = getms(true); +// ToastImages::iterator i = toastImages.find(key); +// if (i != toastImages.cend()) { +// if (i->until) { +// i->until = ms + NotifyDeletePhotoAfter; +// if (App::wnd()) App::wnd()->psCleanNotifyPhotosIn(-NotifyDeletePhotoAfter); +// } +// } else { +// ToastImage v; +// if (key.first) { +// v.until = ms + NotifyDeletePhotoAfter; +// if (App::wnd()) App::wnd()->psCleanNotifyPhotosIn(-NotifyDeletePhotoAfter); +// } else { +// v.until = 0; +// } +// v.path = cWorkingDir() + qsl("tdata/temp/") + QString::number(MTP::nonce(), 16) + qsl(".png"); +// if (key.first || key.second) { +// peer->saveUserpic(v.path); +// } else { +// App::wnd()->iconLarge().save(v.path, "PNG"); +// } +// i = toastImages.insert(key, v); +// ToastImageSavedFlag = true; +// } +// return i->path; +//} + +//bool CreateToast(PeerData *peer, int32 msgId, bool showpix, const QString &title, const QString &subtitle, const QString &msg) { +// if (!useToast || !toastNotificationManager || !toastNotifier || !toastNotificationFactory) return false; +// +// ComPtr toastXml; +// bool withSubtitle = !subtitle.isEmpty(); +// +// HRESULT hr = toastNotificationManager->GetTemplateContent(withSubtitle ? ToastTemplateType_ToastImageAndText04 : ToastTemplateType_ToastImageAndText02, &toastXml); +// if (!SUCCEEDED(hr)) return false; +// +// //hr = SetAudioSilent(toastXml.Get()); +// //if (!SUCCEEDED(hr)) return false; +// +// StorageKey key; +// QString imagePath; +// if (showpix) { +// key = peer->userpicUniqueKey(); +// } else { +// key = StorageKey(0, 0); +// } +// QString image = toastImage(key, peer); +// std::wstring wimage = QDir::toNativeSeparators(image).toStdWString(); +// +// //hr = SetImageSrc(wimage.c_str(), toastXml.Get()); +// //if (!SUCCEEDED(hr)) return false; +// +// ComPtr nodeList; +// //hr = toastXml->GetElementsByTagName(StringReferenceWrapper(L"text").Get(), &nodeList); +// //if (!SUCCEEDED(hr)) return false; +// +// UINT32 nodeListLength; +// hr = nodeList->get_Length(&nodeListLength); +// if (!SUCCEEDED(hr)) return false; +// +// if (nodeListLength < (withSubtitle ? 3U : 2U)) return false; +// +// { +// ComPtr textNode; +// hr = nodeList->Item(0, &textNode); +// if (!SUCCEEDED(hr)) return false; +// +// std::wstring wtitle = title.toStdWString(); +// //hr = SetNodeValueString(StringReferenceWrapper(wtitle.data(), wtitle.size()).Get(), textNode.Get(), toastXml.Get()); +// //if (!SUCCEEDED(hr)) return false; +// } +// if (withSubtitle) { +// ComPtr textNode; +// hr = nodeList->Item(1, &textNode); +// if (!SUCCEEDED(hr)) return false; +// +// std::wstring wsubtitle = subtitle.toStdWString(); +// //hr = SetNodeValueString(StringReferenceWrapper(wsubtitle.data(), wsubtitle.size()).Get(), textNode.Get(), toastXml.Get()); +// //if (!SUCCEEDED(hr)) return false; +// } +// { +// ComPtr textNode; +// hr = nodeList->Item(withSubtitle ? 2 : 1, &textNode); +// if (!SUCCEEDED(hr)) return false; +// +// std::wstring wmsg = msg.toStdWString(); +// //hr = SetNodeValueString(StringReferenceWrapper(wmsg.data(), wmsg.size()).Get(), textNode.Get(), toastXml.Get()); +// //if (!SUCCEEDED(hr)) return false; +// } +// +// ComPtr toast; +// hr = toastNotificationFactory->CreateToastNotification(toastXml.Get(), &toast); +// if (!SUCCEEDED(hr)) return false; +// +// //EventRegistrationToken activatedToken, dismissedToken, failedToken; +// //ComPtr eventHandler(new ToastEventHandler(peer->id, msgId)); +// +// //hr = toast->add_Activated(eventHandler.Get(), &activatedToken); +// //if (!SUCCEEDED(hr)) return false; +// +// //hr = toast->add_Dismissed(eventHandler.Get(), &dismissedToken); +// //if (!SUCCEEDED(hr)) return false; +// +// //hr = toast->add_Failed(eventHandler.Get(), &failedToken); +// //if (!SUCCEEDED(hr)) return false; +// +// ToastNotifications::iterator i = toastNotifications.find(peer->id); +// if (i != toastNotifications.cend()) { +// QMap::iterator j = i->find(msgId); +// if (j != i->cend()) { +// ComPtr notify = j->p; +// i->erase(j); +// toastNotifier->Hide(notify.Get()); +// i = toastNotifications.find(peer->id); +// } +// } +// if (i == toastNotifications.cend()) { +// i = toastNotifications.insert(peer->id, QMap()); +// } +// hr = toastNotifier->Show(toast.Get()); +// if (!SUCCEEDED(hr)) { +// i = toastNotifications.find(peer->id); +// if (i != toastNotifications.cend() && i->isEmpty()) toastNotifications.erase(i); +// return false; +// } +// toastNotifications[peer->id].insert(msgId, toast); +// +// return true; +//} QString pinnedPath() { - static const int maxFileLen = MAX_PATH * 10; - WCHAR wstrPath[maxFileLen]; - if (GetEnvironmentVariable(L"APPDATA", wstrPath, maxFileLen)) { - QDir appData(QString::fromStdWString(std::wstring(wstrPath))); - return appData.absolutePath() + qsl("/Microsoft/Internet Explorer/Quick Launch/User Pinned/TaskBar/"); - } + //static const int maxFileLen = MAX_PATH * 10; + //WCHAR wstrPath[maxFileLen]; + //if (GetEnvironmentVariable(L"APPDATA", wstrPath, maxFileLen)) { + // QDir appData(QString::fromStdWString(std::wstring(wstrPath))); + // return appData.absolutePath() + qsl("/Microsoft/Internet Explo7rer/Quick Launch/User Pinned/TaskBar/"); + //} return QString(); } void CheckPinnedAppUserModelId() { - if (!propVariantToString) return; + //if (!propVariantToString) return; - static const int maxFileLen = MAX_PATH * 10; + //static const int maxFileLen = MAX_PATH * 10; - HRESULT hr = CoInitialize(0); - if (!SUCCEEDED(hr)) return; + //HRESULT hr = CoInitialize(0); + //if (!SUCCEEDED(hr)) return; - QString path = pinnedPath(); - std::wstring p = QDir::toNativeSeparators(path).toStdWString(); + //QString path = pinnedPath(); + //std::wstring p = QDir::toNativeSeparators(path).toStdWString(); - WCHAR src[MAX_PATH]; - GetModuleFileName(GetModuleHandle(0), src, MAX_PATH); - BY_HANDLE_FILE_INFORMATION srcinfo = { 0 }; - HANDLE srcfile = CreateFile(src, 0x00, 0x00, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); - if (srcfile == INVALID_HANDLE_VALUE) return; - BOOL srcres = GetFileInformationByHandle(srcfile, &srcinfo); - CloseHandle(srcfile); - if (!srcres) return; - LOG(("Checking..")); - WIN32_FIND_DATA findData; - HANDLE findHandle = FindFirstFileEx((p + L"*").c_str(), FindExInfoStandard, &findData, FindExSearchNameMatch, 0, 0); - if (findHandle == INVALID_HANDLE_VALUE) { - LOG(("Init Error: could not find files in pinned folder")); - return; - } - do { - std::wstring fname = p + findData.cFileName; - LOG(("Checking %1").arg(QString::fromStdWString(fname))); - if (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { - continue; - } else { - DWORD attributes = GetFileAttributes(fname.c_str()); - if (attributes >= 0xFFFFFFF) continue; // file does not exist + //WCHAR src[MAX_PATH]; + //GetModuleFileName(GetModuleHandle(0), src, MAX_PATH); + //BY_HANDLE_FILE_INFORMATION srcinfo = { 0 }; + //HANDLE srcfile = CreateFile(src, 0x00, 0x00, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + //if (srcfile == INVALID_HANDLE_VALUE) return; + //BOOL srcres = GetFileInformationByHandle(srcfile, &srcinfo); + //CloseHandle(srcfile); + //if (!srcres) return; + //LOG(("Checking..")); + //WIN32_FIND_DATA findData; + //HANDLE findHandle = FindFirstFileEx((p + L"*").c_str(), FindExInfoStandard, &findData, FindExSearchNameMatch, 0, 0); + //if (findHandle == INVALID_HANDLE_VALUE) { + // LOG(("Init Error: could not find files in pinned folder")); + // return; + //} + //do { + // std::wstring fname = p + findData.cFileName; + // LOG(("Checking %1").arg(QString::fromStdWString(fname))); + // if (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { + // continue; + // } else { + // DWORD attributes = GetFileAttributes(fname.c_str()); + // if (attributes >= 0xFFFFFFF) continue; // file does not exist - ComPtr shellLink; - HRESULT hr = CoCreateInstance(CLSID_ShellLink, nullptr, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&shellLink)); - if (!SUCCEEDED(hr)) continue; + // ComPtr shellLink; + // HRESULT hr = CoCreateInstance(CLSID_ShellLink, nullptr, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&shellLink)); + // if (!SUCCEEDED(hr)) continue; - ComPtr persistFile; - hr = shellLink.As(&persistFile); - if (!SUCCEEDED(hr)) continue; + // ComPtr persistFile; + // hr = shellLink.As(&persistFile); + // if (!SUCCEEDED(hr)) continue; - hr = persistFile->Load(fname.c_str(), STGM_READWRITE); - if (!SUCCEEDED(hr)) continue; + // hr = persistFile->Load(fname.c_str(), STGM_READWRITE); + // if (!SUCCEEDED(hr)) continue; - WCHAR dst[MAX_PATH]; - hr = shellLink->GetPath(dst, MAX_PATH, 0, 0); - if (!SUCCEEDED(hr)) continue; + // WCHAR dst[MAX_PATH]; + // hr = shellLink->GetPath(dst, MAX_PATH, 0, 0); + // if (!SUCCEEDED(hr)) continue; - BY_HANDLE_FILE_INFORMATION dstinfo = { 0 }; - HANDLE dstfile = CreateFile(dst, 0x00, 0x00, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); - if (dstfile == INVALID_HANDLE_VALUE) continue; - BOOL dstres = GetFileInformationByHandle(dstfile, &dstinfo); - CloseHandle(dstfile); - if (!dstres) continue; + // BY_HANDLE_FILE_INFORMATION dstinfo = { 0 }; + // HANDLE dstfile = CreateFile(dst, 0x00, 0x00, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + // if (dstfile == INVALID_HANDLE_VALUE) continue; + // BOOL dstres = GetFileInformationByHandle(dstfile, &dstinfo); + // CloseHandle(dstfile); + // if (!dstres) continue; - if (srcinfo.dwVolumeSerialNumber == dstinfo.dwVolumeSerialNumber && srcinfo.nFileIndexLow == dstinfo.nFileIndexLow && srcinfo.nFileIndexHigh == dstinfo.nFileIndexHigh) { - ComPtr propertyStore; - hr = shellLink.As(&propertyStore); - if (!SUCCEEDED(hr)) return; + // if (srcinfo.dwVolumeSerialNumber == dstinfo.dwVolumeSerialNumber && srcinfo.nFileIndexLow == dstinfo.nFileIndexLow && srcinfo.nFileIndexHigh == dstinfo.nFileIndexHigh) { + // ComPtr propertyStore; + // hr = shellLink.As(&propertyStore); + // if (!SUCCEEDED(hr)) return; - PROPVARIANT appIdPropVar; - hr = propertyStore->GetValue(pkey_AppUserModel_ID, &appIdPropVar); - if (!SUCCEEDED(hr)) return; - LOG(("Reading..")); - WCHAR already[MAX_PATH]; - hr = propVariantToString(appIdPropVar, already, MAX_PATH); - if (SUCCEEDED(hr)) { - if (std::wstring(AppUserModelId()) == already) { - LOG(("Already!")); - PropVariantClear(&appIdPropVar); - return; - } - } - if (appIdPropVar.vt != VT_EMPTY) { - PropVariantClear(&appIdPropVar); - return; - } - PropVariantClear(&appIdPropVar); + // PROPVARIANT appIdPropVar; + // hr = propertyStore->GetValue(pkey_AppUserModel_ID, &appIdPropVar); + // if (!SUCCEEDED(hr)) return; + // LOG(("Reading..")); + // WCHAR already[MAX_PATH]; + // hr = propVariantToString(appIdPropVar, already, MAX_PATH); + // if (SUCCEEDED(hr)) { + // if (std::wstring(AppUserModelId()) == already) { + // LOG(("Already!")); + // PropVariantClear(&appIdPropVar); + // return; + // } + // } + // if (appIdPropVar.vt != VT_EMPTY) { + // PropVariantClear(&appIdPropVar); + // return; + // } + // PropVariantClear(&appIdPropVar); - hr = InitPropVariantFromString(AppUserModelId(), &appIdPropVar); - if (!SUCCEEDED(hr)) return; + // hr = InitPropVariantFromString(AppUserModelId(), &appIdPropVar); + // if (!SUCCEEDED(hr)) return; - hr = propertyStore->SetValue(pkey_AppUserModel_ID, appIdPropVar); - PropVariantClear(&appIdPropVar); - if (!SUCCEEDED(hr)) return; + // hr = propertyStore->SetValue(pkey_AppUserModel_ID, appIdPropVar); + // PropVariantClear(&appIdPropVar); + // if (!SUCCEEDED(hr)) return; - hr = propertyStore->Commit(); - if (!SUCCEEDED(hr)) return; + // hr = propertyStore->Commit(); + // if (!SUCCEEDED(hr)) return; - if (persistFile->IsDirty() == S_OK) { - persistFile->Save(fname.c_str(), TRUE); - } - return; - } - } - } while (FindNextFile(findHandle, &findData)); - DWORD errorCode = GetLastError(); - if (errorCode && errorCode != ERROR_NO_MORE_FILES) { // everything is found - LOG(("Init Error: could not find some files in pinned folder")); - return; - } - FindClose(findHandle); + // if (persistFile->IsDirty() == S_OK) { + // persistFile->Save(fname.c_str(), TRUE); + // } + // return; + // } + // } + //} while (FindNextFile(findHandle, &findData)); + //DWORD errorCode = GetLastError(); + //if (errorCode && errorCode != ERROR_NO_MORE_FILES) { // everything is found + // LOG(("Init Error: could not find some files in pinned folder")); + // return; + //} + //FindClose(findHandle); } QString systemShortcutPath() { - static const int maxFileLen = MAX_PATH * 10; - WCHAR wstrPath[maxFileLen]; - if (GetEnvironmentVariable(L"APPDATA", wstrPath, maxFileLen)) { - QDir appData(QString::fromStdWString(std::wstring(wstrPath))); - return appData.absolutePath() + qsl("/Microsoft/Windows/Start Menu/Programs/"); - } + //static const int maxFileLen = MAX_PATH * 10; + //WCHAR wstrPath[maxFileLen]; + //if (GetEnvironmentVariable(L"APPDATA", wstrPath, maxFileLen)) { + // QDir appData(QString::fromStdWString(std::wstring(wstrPath))); + // return appData.absolutePath() + qsl("/Microsoft/Windows/Start Menu/Programs/"); + //} return QString(); } @@ -3486,28 +2902,28 @@ void CleanupAppUserModelIdShortcut() { QString path = systemShortcutPath() + qsl("Telegram.lnk"); std::wstring p = QDir::toNativeSeparators(path).toStdWString(); - DWORD attributes = GetFileAttributes(p.c_str()); - if (attributes >= 0xFFFFFFF) return; // file does not exist + //DWORD attributes = GetFileAttributes(p.c_str()); + //if (attributes >= 0xFFFFFFF) return; // file does not exist - ComPtr shellLink; - HRESULT hr = CoCreateInstance(CLSID_ShellLink, nullptr, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&shellLink)); - if (!SUCCEEDED(hr)) return; + //ComPtr shellLink; + //HRESULT hr = CoCreateInstance(CLSID_ShellLink, nullptr, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&shellLink)); + //if (!SUCCEEDED(hr)) return; - ComPtr persistFile; - hr = shellLink.As(&persistFile); - if (!SUCCEEDED(hr)) return; + //ComPtr persistFile; + //hr = shellLink.As(&persistFile); + //if (!SUCCEEDED(hr)) return; - hr = persistFile->Load(p.c_str(), STGM_READWRITE); - if (!SUCCEEDED(hr)) return; + //hr = persistFile->Load(p.c_str(), STGM_READWRITE); + //if (!SUCCEEDED(hr)) return; - WCHAR szGotPath[MAX_PATH]; - WIN32_FIND_DATA wfd; - hr = shellLink->GetPath(szGotPath, MAX_PATH, (WIN32_FIND_DATA*)&wfd, SLGP_SHORTPATH); - if (!SUCCEEDED(hr)) return; + //WCHAR szGotPath[MAX_PATH]; + //WIN32_FIND_DATA wfd; + //hr = shellLink->GetPath(szGotPath, MAX_PATH, (WIN32_FIND_DATA*)&wfd, SLGP_SHORTPATH); + //if (!SUCCEEDED(hr)) return; - if (QDir::toNativeSeparators(cExeDir() + cExeName()).toStdWString() == szGotPath) { - QFile().remove(path); - } + //if (QDir::toNativeSeparators(cExeDir() + cExeName()).toStdWString() == szGotPath) { + // QFile().remove(path); + //} } bool ValidateAppUserModelIdShortcutAt(const QString &path) { @@ -3515,55 +2931,55 @@ bool ValidateAppUserModelIdShortcutAt(const QString &path) { std::wstring p = QDir::toNativeSeparators(path).toStdWString(); - DWORD attributes = GetFileAttributes(p.c_str()); - if (attributes >= 0xFFFFFFF) return false; // file does not exist + //DWORD attributes = GetFileAttributes(p.c_str()); + //if (attributes >= 0xFFFFFFF) return false; // file does not exist - ComPtr shellLink; - HRESULT hr = CoCreateInstance(CLSID_ShellLink, nullptr, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&shellLink)); - if (!SUCCEEDED(hr)) return false; + //ComPtr shellLink; + //HRESULT hr = CoCreateInstance(CLSID_ShellLink, nullptr, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&shellLink)); + //if (!SUCCEEDED(hr)) return false; - ComPtr persistFile; - hr = shellLink.As(&persistFile); - if (!SUCCEEDED(hr)) return false; + //ComPtr persistFile; + //hr = shellLink.As(&persistFile); + //if (!SUCCEEDED(hr)) return false; - hr = persistFile->Load(p.c_str(), STGM_READWRITE); - if (!SUCCEEDED(hr)) return false; + //hr = persistFile->Load(p.c_str(), STGM_READWRITE); + //if (!SUCCEEDED(hr)) return false; - ComPtr propertyStore; - hr = shellLink.As(&propertyStore); - if (!SUCCEEDED(hr)) return false; + //ComPtr propertyStore; + //hr = shellLink.As(&propertyStore); + //if (!SUCCEEDED(hr)) return false; - PROPVARIANT appIdPropVar; - hr = propertyStore->GetValue(pkey_AppUserModel_ID, &appIdPropVar); - if (!SUCCEEDED(hr)) return false; + //PROPVARIANT appIdPropVar; + //hr = propertyStore->GetValue(pkey_AppUserModel_ID, &appIdPropVar); + //if (!SUCCEEDED(hr)) return false; - WCHAR already[MAX_PATH]; - hr = propVariantToString(appIdPropVar, already, MAX_PATH); - if (SUCCEEDED(hr)) { - if (std::wstring(AppUserModelId()) == already) { - PropVariantClear(&appIdPropVar); - return true; - } - } - if (appIdPropVar.vt != VT_EMPTY) { - PropVariantClear(&appIdPropVar); - return false; - } - PropVariantClear(&appIdPropVar); + //WCHAR already[MAX_PATH]; + //hr = propVariantToString(appIdPropVar, already, MAX_PATH); + //if (SUCCEEDED(hr)) { + // if (std::wstring(AppUserModelId()) == already) { + // PropVariantClear(&appIdPropVar); + // return true; + // } + //} + //if (appIdPropVar.vt != VT_EMPTY) { + // PropVariantClear(&appIdPropVar); + // return false; + //} + //PropVariantClear(&appIdPropVar); - hr = InitPropVariantFromString(AppUserModelId(), &appIdPropVar); - if (!SUCCEEDED(hr)) return false; + //hr = InitPropVariantFromString(AppUserModelId(), &appIdPropVar); + //if (!SUCCEEDED(hr)) return false; - hr = propertyStore->SetValue(pkey_AppUserModel_ID, appIdPropVar); - PropVariantClear(&appIdPropVar); - if (!SUCCEEDED(hr)) return false; + //hr = propertyStore->SetValue(pkey_AppUserModel_ID, appIdPropVar); + //PropVariantClear(&appIdPropVar); + //if (!SUCCEEDED(hr)) return false; - hr = propertyStore->Commit(); - if (!SUCCEEDED(hr)) return false; + //hr = propertyStore->Commit(); + //if (!SUCCEEDED(hr)) return false; - if (persistFile->IsDirty() == S_OK) { - persistFile->Save(p.c_str(), TRUE); - } + //if (persistFile->IsDirty() == S_OK) { + // persistFile->Save(p.c_str(), TRUE); + //} return true; } @@ -3585,66 +3001,66 @@ bool ValidateAppUserModelIdShortcut() { if (ValidateAppUserModelIdShortcutAt(path)) return true; } - ComPtr shellLink; - HRESULT hr = CoCreateInstance(CLSID_ShellLink, nullptr, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&shellLink)); - if (!SUCCEEDED(hr)) return false; + //ComPtr shellLink; + //HRESULT hr = CoCreateInstance(CLSID_ShellLink, nullptr, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&shellLink)); + //if (!SUCCEEDED(hr)) return false; - hr = shellLink->SetPath(QDir::toNativeSeparators(cExeDir() + cExeName()).toStdWString().c_str()); - if (!SUCCEEDED(hr)) return false; + //hr = shellLink->SetPath(QDir::toNativeSeparators(cExeDir() + cExeName()).toStdWString().c_str()); + //if (!SUCCEEDED(hr)) return false; - hr = shellLink->SetArguments(L""); - if (!SUCCEEDED(hr)) return false; + //hr = shellLink->SetArguments(L""); + //if (!SUCCEEDED(hr)) return false; - hr = shellLink->SetWorkingDirectory(QDir::toNativeSeparators(QDir(cWorkingDir()).absolutePath()).toStdWString().c_str()); - if (!SUCCEEDED(hr)) return false; + //hr = shellLink->SetWorkingDirectory(QDir::toNativeSeparators(QDir(cWorkingDir()).absolutePath()).toStdWString().c_str()); + //if (!SUCCEEDED(hr)) return false; - ComPtr propertyStore; - hr = shellLink.As(&propertyStore); - if (!SUCCEEDED(hr)) return false; + //ComPtr propertyStore; + //hr = shellLink.As(&propertyStore); + //if (!SUCCEEDED(hr)) return false; - PROPVARIANT appIdPropVar; - hr = InitPropVariantFromString(AppUserModelId(), &appIdPropVar); - if (!SUCCEEDED(hr)) return false; + //PROPVARIANT appIdPropVar; + //hr = InitPropVariantFromString(AppUserModelId(), &appIdPropVar); + //if (!SUCCEEDED(hr)) return false; - hr = propertyStore->SetValue(pkey_AppUserModel_ID, appIdPropVar); - PropVariantClear(&appIdPropVar); - if (!SUCCEEDED(hr)) return false; + //hr = propertyStore->SetValue(pkey_AppUserModel_ID, appIdPropVar); + //PropVariantClear(&appIdPropVar); + //if (!SUCCEEDED(hr)) return false; - PROPVARIANT startPinPropVar; - hr = InitPropVariantFromUInt32(APPUSERMODEL_STARTPINOPTION_NOPINONINSTALL, &startPinPropVar); - if (!SUCCEEDED(hr)) return false; + //PROPVARIANT startPinPropVar; + //hr = InitPropVariantFromUInt32(APPUSERMODEL_STARTPINOPTION_NOPINONINSTALL, &startPinPropVar); + //if (!SUCCEEDED(hr)) return false; - hr = propertyStore->SetValue(pkey_AppUserModel_StartPinOption, startPinPropVar); - PropVariantClear(&startPinPropVar); - if (!SUCCEEDED(hr)) return false; + //hr = propertyStore->SetValue(pkey_AppUserModel_StartPinOption, startPinPropVar); + //PropVariantClear(&startPinPropVar); + //if (!SUCCEEDED(hr)) return false; - hr = propertyStore->Commit(); - if (!SUCCEEDED(hr)) return false; + //hr = propertyStore->Commit(); + //if (!SUCCEEDED(hr)) return false; - ComPtr persistFile; - hr = shellLink.As(&persistFile); - if (!SUCCEEDED(hr)) return false; + //ComPtr persistFile; + //hr = shellLink.As(&persistFile); + //if (!SUCCEEDED(hr)) return false; - hr = persistFile->Save(QDir::toNativeSeparators(path).toStdWString().c_str(), TRUE); - if (!SUCCEEDED(hr)) return false; + //hr = persistFile->Save(QDir::toNativeSeparators(path).toStdWString().c_str(), TRUE); + //if (!SUCCEEDED(hr)) return false; return true; } bool InitToastManager() { if (!useToast || !ValidateAppUserModelIdShortcut()) return false; - if (!SUCCEEDED(setCurrentProcessExplicitAppUserModelID(AppUserModelId()))) { - return false; - } - if (!SUCCEEDED(wrap_GetActivationFactory(StringReferenceWrapper(RuntimeClass_Windows_UI_Notifications_ToastNotificationManager).Get(), &toastNotificationManager))) { - return false; - } - if (!SUCCEEDED(toastNotificationManager->CreateToastNotifierWithId(StringReferenceWrapper(AppUserModelId(), wcslen(AppUserModelId())).Get(), &toastNotifier))) { - return false; - } - if (!SUCCEEDED(wrap_GetActivationFactory(StringReferenceWrapper(RuntimeClass_Windows_UI_Notifications_ToastNotification).Get(), &toastNotificationFactory))) { - return false; - } + //if (!SUCCEEDED(setCurrentProcessExplicitAppUserModelID(AppUserModelId()))) { + // return false; + //} + //if (!SUCCEEDED(wrap_GetActivationFactory(StringReferenceWrapper(RuntimeClass_Windows_UI_Notifications_ToastNotificationManager).Get(), &toastNotificationManager))) { + // return false; + //} + //if (!SUCCEEDED(toastNotificationManager->CreateToastNotifierWithId(StringReferenceWrapper(AppUserModelId(), wcslen(AppUserModelId())).Get(), &toastNotifier))) { + // return false; + //} + //if (!SUCCEEDED(wrap_GetActivationFactory(StringReferenceWrapper(RuntimeClass_Windows_UI_Notifications_ToastNotification).Get(), &toastNotificationFactory))) { + // return false; + //} QDir().mkpath(cWorkingDir() + qsl("tdata/temp")); return true; } @@ -3652,3 +3068,7 @@ bool InitToastManager() { bool psLaunchMaps(const LocationCoords &coords) { return QDesktopServices::openUrl(qsl("bingmaps:?lvl=16&collection=point.%1_%2_Point").arg(coords.lat).arg(coords.lon)); } + +bool qt_sendSpontaneousEvent(QObject *receiver, QEvent *ev) { + return QCoreApplication::sendSpontaneousEvent(receiver, ev); +} diff --git a/Telegram/SourceFiles/pspecific_winrt.h b/Telegram/SourceFiles/pspecific_winrt.h index 0f149ad290..75238b7895 100644 --- a/Telegram/SourceFiles/pspecific_winrt.h +++ b/Telegram/SourceFiles/pspecific_winrt.h @@ -104,7 +104,7 @@ protected: private: HWND ps_hWnd; - HWND ps_tbHider_hWnd; +// HWND ps_tbHider_hWnd; HMENU ps_menu; HICON ps_iconBig, ps_iconSmall, ps_iconOverlay; @@ -115,7 +115,6 @@ private: void psWriteDump(); void psWriteStackTrace(); -QString psPrepareCrashDump(const QByteArray &crashdump, QString dumpfile); void psDeleteDir(const QString &dir); diff --git a/Telegram/SourceFiles/stdafx.cpp b/Telegram/SourceFiles/stdafx.cpp index 53a464500f..987153bf23 100644 --- a/Telegram/SourceFiles/stdafx.cpp +++ b/Telegram/SourceFiles/stdafx.cpp @@ -21,10 +21,13 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #include "stdafx.h" #include -#ifdef Q_OS_WIN +#ifdef Q_OS_WINRT +//Q_IMPORT_PLUGIN(QWinRTIntegrationPlugin) +//Q_IMPORT_PLUGIN(QWbmpPlugin) +#elif defined Q_OS_WIN // Q_OS_WINRT Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin) Q_IMPORT_PLUGIN(QWebpPlugin) -#elif defined Q_OS_MAC +#elif defined Q_OS_MAC // Q_OS_WIN Q_IMPORT_PLUGIN(QGenericEnginePlugin) Q_IMPORT_PLUGIN(QCocoaIntegrationPlugin) Q_IMPORT_PLUGIN(QDDSPlugin) @@ -36,7 +39,7 @@ Q_IMPORT_PLUGIN(QTgaPlugin) Q_IMPORT_PLUGIN(QTiffPlugin) Q_IMPORT_PLUGIN(QWbmpPlugin) Q_IMPORT_PLUGIN(QWebpPlugin) -#elif defined Q_OS_LINUX +#elif defined Q_OS_LINUX // Q_OS_LINUX Q_IMPORT_PLUGIN(QComposePlatformInputContextPlugin) Q_IMPORT_PLUGIN(QIbusPlatformInputContextPlugin) Q_IMPORT_PLUGIN(QFcitxPlatformInputContextPlugin) diff --git a/Telegram/SourceFiles/stdafx.h b/Telegram/SourceFiles/stdafx.h index 22bc151150..da667bb396 100644 --- a/Telegram/SourceFiles/stdafx.h +++ b/Telegram/SourceFiles/stdafx.h @@ -18,11 +18,20 @@ to link the code of portions of this program with the OpenSSL library. Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org */ +#ifdef TDESKTOP_WINRT + +#include +#include + +#else // TDESKTOP_WINRT + #define __HUGE #define PSAPI_VERSION 1 // fix WinXP #define __STDC_FORMAT_MACROS // fix breakpad for mac +#endif // else of TDESKTOP_WINRT + #ifdef __cplusplus #include @@ -43,9 +52,9 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #ifdef Q_OS_WIN // use Lzma SDK for win #include -#else +#else // Q_OS_WIN #include -#endif +#endif // else of Q_OS_WIN extern "C" { diff --git a/Telegram/SourceFiles/window.cpp b/Telegram/SourceFiles/window.cpp index b14e63cefb..ff088c2696 100644 --- a/Telegram/SourceFiles/window.cpp +++ b/Telegram/SourceFiles/window.cpp @@ -82,9 +82,9 @@ NotifyWindow::NotifyWindow(HistoryItem *msg, int32 x, int32 y, int32 fwdCount) : , history(msg->history()) , item(msg) , fwdCount(fwdCount) -#ifdef Q_OS_WIN +#if defined Q_OS_WIN && !defined Q_OS_WINRT , started(GetTickCount()) -#endif +#endif // Q_OS_WIN && !Q_OS_WINRT , close(this, st::notifyClose) , alphaDuration(st::notifyFastAnim) , posDuration(st::notifyFastAnim) @@ -126,7 +126,7 @@ NotifyWindow::NotifyWindow(HistoryItem *msg, int32 x, int32 y, int32 fwdCount) : } void NotifyWindow::checkLastInput() { -#ifdef Q_OS_WIN +#if defined Q_OS_WIN && !defined Q_OS_WINRT LASTINPUTINFO lii; lii.cbSize = sizeof(LASTINPUTINFO); BOOL res = GetLastInputInfo(&lii); @@ -135,14 +135,14 @@ void NotifyWindow::checkLastInput() { } else { inputTimer.start(300); } -#else +#else // Q_OS_WIN && !Q_OS_WINRT // TODO if (true) { hideTimer.start(st::notifyWaitLongHide); } else { inputTimer.start(300); } -#endif +#endif // else for Q_OS_WIN && !Q_OS_WINRT } void NotifyWindow::moveTo(int32 x, int32 y, int32 index) { @@ -3096,6 +3096,7 @@ void ShowCrashReportWindow::closeEvent(QCloseEvent *e) { deleteLater(); } +#ifndef TDESKTOP_DISABLE_CRASH_REPORTS int showCrashReportWindow(const QString &crashdump) { QString text; @@ -3120,3 +3121,4 @@ int showCrashReportWindow(const QString &crashdump) { ShowCrashReportWindow *wnd = new ShowCrashReportWindow(text); return app.exec(); } +#endif // !TDESKTOP_DISABLE_CRASH_REPORTS diff --git a/Telegram/SourceFiles/window.h b/Telegram/SourceFiles/window.h index 29b8566f9b..cecad8cf73 100644 --- a/Telegram/SourceFiles/window.h +++ b/Telegram/SourceFiles/window.h @@ -98,9 +98,9 @@ public slots: private: -#ifdef Q_OS_WIN +#if defined Q_OS_WIN && !defined Q_OS_WINRT DWORD started; -#endif +#endif // Q_OS_WIN && !Q_OS_WINRT History *history; HistoryItem *item; int32 fwdCount; @@ -573,4 +573,6 @@ private: }; +#ifndef TDESKTOP_DISABLE_CRASH_REPORTS int showCrashReportWindow(const QString &crashdump); +#endif // !TDESKTOP_DISABLE_CRASH_REPORTS