1.1 --- a/CMainWindow.cpp Thu Jul 02 20:20:56 2020 +0200
1.2 +++ b/CMainWindow.cpp Thu Jul 02 22:47:58 2020 +0200
1.3 @@ -1,5 +1,6 @@
1.4 #include "stdafx.h"
1.5 #include "CMainWindow.h"
1.6 +#include "GateKeeper.h"
1.7
1.8 static const GUID nidGUID =
1.9 { 0xa4dbdbe1, 0x4051, 0x4d89, { 0xb1, 0x17, 0x62, 0x82, 0x18, 0x5a, 0x61, 0x5c } };
1.10 @@ -40,8 +41,6 @@
1.11 return S_OK;
1.12 }
1.13
1.14 -HMENU _menuContext = NULL;
1.15 -
1.16 LRESULT CMainWindow::OnNotification(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
1.17 {
1.18 auto event = LOWORD(lParam);
1.19 @@ -50,7 +49,10 @@
1.20 auto y = GET_Y_LPARAM(wParam);
1.21
1.22 HMENU menuContext;
1.23 + HMENU _menuContext = NULL;
1.24 +
1.25 MENUINFO info;
1.26 + BOOL enabled;
1.27
1.28 switch (event) {
1.29 case WM_CONTEXTMENU:
1.30 @@ -62,11 +64,16 @@
1.31 info.dwStyle = MNS_AUTODISMISS | MNS_NOTIFYBYPOS;
1.32 SetMenuInfo(menuContext, &info);
1.33 _menuContext = GetSubMenu(menuContext, 0);
1.34 +
1.35 + enabled = pEp::GateKeeper::gatekeeper()->update_enabled();
1.36 + CheckMenuItem(_menuContext, ID_POPUP_SCHEDULEUPDATES, enabled ? MF_CHECKED : MF_UNCHECKED);
1.37 +
1.38 SetForegroundWindow(m_hWnd); // this is utter nonsense, but required by TrackPopupMenuEx
1.39 POINT point;
1.40 GetCursorPos(&point);
1.41 TrackPopupMenuEx(_menuContext, TPM_LEFTALIGN | TPM_BOTTOMALIGN, point.x, point.y, m_hWnd, NULL);
1.42 PostMessage(WM_NULL, 0, 0); // this is utter nonsense, but required by TrackPopupMenuEx
1.43 +
1.44 DestroyMenu(menuContext);
1.45 bHandled = true;
1.46 break;
1.47 @@ -79,11 +86,13 @@
1.48 }
1.49
1.50 static const auto UPDATE_NOW = 1;
1.51 +static const auto SCHEDULE_UPDATES = 3;
1.52
1.53 LRESULT CMainWindow::OnMenuCommand(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
1.54 {
1.55 auto index = wParam;
1.56 HMENU hMenu = (HMENU)lParam;
1.57 + BOOL enabled;
1.58
1.59 switch (index) {
1.60 case UPDATE_NOW:
1.61 @@ -91,6 +100,14 @@
1.62 bHandled = true;
1.63 break;
1.64
1.65 + case SCHEDULE_UPDATES:
1.66 + enabled = !pEp::GateKeeper::gatekeeper()->update_enabled();
1.67 + if (enabled)
1.68 + pEp::GateKeeper::gatekeeper()->enable_update();
1.69 + else
1.70 + pEp::GateKeeper::gatekeeper()->disable_update();
1.71 + CheckMenuItem(hMenu, ID_POPUP_SCHEDULEUPDATES, enabled ? MF_CHECKED : MF_UNCHECKED);
1.72 +
1.73 default:
1.74 bHandled = false;
1.75 }
2.1 --- a/GateKeeper.cpp Thu Jul 02 20:20:56 2020 +0200
2.2 +++ b/GateKeeper.cpp Thu Jul 02 22:47:58 2020 +0200
2.3 @@ -182,7 +182,8 @@
2.4
2.5 if (now > next) {
2.6 next = now + GateKeeper::cycle;
2.7 - keep_updated();
2.8 + if (update_enabled())
2.9 + keep_updated();
2.10 }
2.11
2.12 Sleep(waiting);
2.13 @@ -344,6 +345,41 @@
2.14 return result;
2.15 }
2.16
2.17 + void GateKeeper::enable_update()
2.18 + {
2.19 + LONG lResult = RegOpenKeyEx(cu, updater_reg_path, 0, KEY_WRITE, &hkUpdater);
2.20 + if (lResult != ERROR_SUCCESS)
2.21 + return;
2.22 +
2.23 + lResult = RegSetValueExW(hkUpdater, NULL, 0, REG_SZ, (const BYTE *) _T("1"), sizeof(TCHAR)*2);
2.24 + }
2.25 +
2.26 + void GateKeeper::disable_update()
2.27 + {
2.28 + LONG lResult = RegOpenKeyEx(cu, updater_reg_path, 0, KEY_WRITE, &hkUpdater);
2.29 + if (lResult != ERROR_SUCCESS)
2.30 + return;
2.31 +
2.32 + lResult = RegSetValueEx(hkUpdater, NULL, 0, REG_SZ, (const BYTE *) _T("0"), sizeof(TCHAR) * 2);
2.33 + }
2.34 +
2.35 + bool GateKeeper::update_enabled()
2.36 + {
2.37 + bool enabled = true;
2.38 +
2.39 + DWORD esize;
2.40 + RegGetValue(cu, updater_reg_path, NULL, RRF_RT_REG_SZ, NULL, NULL, &esize);
2.41 + if (esize) {
2.42 + TCHAR* edata = new TCHAR[esize];
2.43 + RegGetValue(cu, updater_reg_path, NULL, RRF_RT_REG_SZ, NULL, edata, &esize);
2.44 + if (tstring(edata) == _T("0"))
2.45 + enabled = false;
2.46 + delete[] edata;
2.47 + }
2.48 +
2.49 + return enabled;
2.50 + }
2.51 +
2.52 GateKeeper::product_list GateKeeper::registered_products()
2.53 {
2.54 product_list products;
3.1 --- a/GateKeeper.h Thu Jul 02 20:20:56 2020 +0200
3.2 +++ b/GateKeeper.h Thu Jul 02 22:47:58 2020 +0200
3.3 @@ -39,6 +39,10 @@
3.4 product_list registered_products();
3.5 bool update_product(product p, DWORD context = 0);
3.6
3.7 + bool update_enabled();
3.8 + void enable_update();
3.9 + void disable_update();
3.10 +
3.11 static GateKeeper *gatekeeper() { return the_gatekeeper; }
3.12
3.13 protected:
4.1 Binary file pEpCOMServerAdapter.rc has changed