]> Git Repo - VerusCoin.git/blame - src/qt/winshutdownmonitor.cpp
checkpoints.cpp depends on main, it can use mapBlockIndex directly
[VerusCoin.git] / src / qt / winshutdownmonitor.cpp
CommitLineData
d282c1fb
PK
1// Copyright (c) 2014 The Bitcoin developers
2// Distributed under the MIT/X11 software license, see the accompanying
3// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
5#include "winshutdownmonitor.h"
6
7#if defined(Q_OS_WIN) && QT_VERSION >= 0x050000
8#include "init.h"
674c070e 9#include "util.h"
d282c1fb
PK
10
11#include <windows.h>
12
13#include <QDebug>
14
674c070e
PK
15#include <openssl/rand.h>
16
d282c1fb
PK
17// If we don't want a message to be processed by Qt, return true and set result to
18// the value that the window procedure should return. Otherwise return false.
19bool WinShutdownMonitor::nativeEventFilter(const QByteArray &eventType, void *pMessage, long *pnResult)
20{
21 Q_UNUSED(eventType);
22
23 MSG *pMsg = static_cast<MSG *>(pMessage);
24
674c070e
PK
25 // Seed OpenSSL PRNG with Windows event data (e.g. mouse movements and other user interactions)
26 if (RAND_event(pMsg->message, pMsg->wParam, pMsg->lParam) == 0) {
27 // Warn only once as this is performance-critical
28 static bool warned = false;
29 if (!warned) {
30 LogPrint("%s: OpenSSL RAND_event() failed to seed OpenSSL PRNG with enough data.\n", __func__);
31 warned = true;
32 }
33 }
34
d282c1fb
PK
35 switch(pMsg->message)
36 {
37 case WM_QUERYENDSESSION:
38 {
39 // Initiate a client shutdown after receiving a WM_QUERYENDSESSION and block
40 // Windows session end until we have finished client shutdown.
41 StartShutdown();
42 *pnResult = FALSE;
43 return true;
44 }
45
46 case WM_ENDSESSION:
47 {
48 *pnResult = FALSE;
49 return true;
50 }
51 }
52
53 return false;
54}
55
56void WinShutdownMonitor::registerShutdownBlockReason(const QString& strReason, const HWND& mainWinId)
57{
58 typedef BOOL (WINAPI *PSHUTDOWNBRCREATE)(HWND, LPCWSTR);
59 PSHUTDOWNBRCREATE shutdownBRCreate = (PSHUTDOWNBRCREATE)GetProcAddress(GetModuleHandleA("User32.dll"), "ShutdownBlockReasonCreate");
60 if (shutdownBRCreate == NULL) {
674c070e 61 qWarning() << "registerShutdownBlockReason: GetProcAddress for ShutdownBlockReasonCreate failed";
d282c1fb
PK
62 return;
63 }
64
65 if (shutdownBRCreate(mainWinId, strReason.toStdWString().c_str()))
674c070e 66 qWarning() << "registerShutdownBlockReason: Successfully registered: " + strReason;
d282c1fb 67 else
674c070e 68 qWarning() << "registerShutdownBlockReason: Failed to register: " + strReason;
d282c1fb
PK
69}
70#endif
This page took 0.059649 seconds and 4 git commands to generate.