Browse Source

enable / disable schedule updates

COM-121
Volker Birk 2 years ago
parent
commit
e576f0c6da
4 changed files with 60 additions and 3 deletions
  1. +19
    -2
      CMainWindow.cpp
  2. +37
    -1
      GateKeeper.cpp
  3. +4
    -0
      GateKeeper.h
  4. BIN
      pEpCOMServerAdapter.rc

+ 19
- 2
CMainWindow.cpp View File

@ -1,5 +1,6 @@
#include "stdafx.h"
#include "CMainWindow.h"
#include "GateKeeper.h"
static const GUID nidGUID =
{ 0xa4dbdbe1, 0x4051, 0x4d89, { 0xb1, 0x17, 0x62, 0x82, 0x18, 0x5a, 0x61, 0x5c } };
@ -40,8 +41,6 @@ LRESULT CMainWindow::OnDestroy(UINT, WPARAM, LPARAM, BOOL&)
return S_OK;
}
HMENU _menuContext = NULL;
LRESULT CMainWindow::OnNotification(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
auto event = LOWORD(lParam);
@ -50,7 +49,10 @@ LRESULT CMainWindow::OnNotification(UINT nMsg, WPARAM wParam, LPARAM lParam, BOO
auto y = GET_Y_LPARAM(wParam);
HMENU menuContext;
HMENU _menuContext = NULL;
MENUINFO info;
BOOL enabled;
switch (event) {
case WM_CONTEXTMENU:
@ -62,11 +64,16 @@ LRESULT CMainWindow::OnNotification(UINT nMsg, WPARAM wParam, LPARAM lParam, BOO
info.dwStyle = MNS_AUTODISMISS | MNS_NOTIFYBYPOS;
SetMenuInfo(menuContext, &info);
_menuContext = GetSubMenu(menuContext, 0);
enabled = pEp::GateKeeper::gatekeeper()->update_enabled();
CheckMenuItem(_menuContext, ID_POPUP_SCHEDULEUPDATES, enabled ? MF_CHECKED : MF_UNCHECKED);
SetForegroundWindow(m_hWnd); // this is utter nonsense, but required by TrackPopupMenuEx
POINT point;
GetCursorPos(&point);
TrackPopupMenuEx(_menuContext, TPM_LEFTALIGN | TPM_BOTTOMALIGN, point.x, point.y, m_hWnd, NULL);
PostMessage(WM_NULL, 0, 0); // this is utter nonsense, but required by TrackPopupMenuEx
DestroyMenu(menuContext);
bHandled = true;
break;
@ -79,11 +86,13 @@ LRESULT CMainWindow::OnNotification(UINT nMsg, WPARAM wParam, LPARAM lParam, BOO
}
static const auto UPDATE_NOW = 1;
static const auto SCHEDULE_UPDATES = 3;
LRESULT CMainWindow::OnMenuCommand(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
auto index = wParam;
HMENU hMenu = (HMENU)lParam;
BOOL enabled;
switch (index) {
case UPDATE_NOW:
@ -91,6 +100,14 @@ LRESULT CMainWindow::OnMenuCommand(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL
bHandled = true;
break;
case SCHEDULE_UPDATES:
enabled = !pEp::GateKeeper::gatekeeper()->update_enabled();
if (enabled)
pEp::GateKeeper::gatekeeper()->enable_update();
else
pEp::GateKeeper::gatekeeper()->disable_update();
CheckMenuItem(hMenu, ID_POPUP_SCHEDULEUPDATES, enabled ? MF_CHECKED : MF_UNCHECKED);
default:
bHandled = false;
}


+ 37
- 1
GateKeeper.cpp View File

@ -182,7 +182,8 @@ namespace pEp {
if (now > next) {
next = now + GateKeeper::cycle;
keep_updated();
if (update_enabled())
keep_updated();
}
Sleep(waiting);
@ -344,6 +345,41 @@ namespace pEp {
return result;
}
void GateKeeper::enable_update()
{
LONG lResult = RegOpenKeyEx(cu, updater_reg_path, 0, KEY_WRITE, &hkUpdater);
if (lResult != ERROR_SUCCESS)
return;
lResult = RegSetValueExW(hkUpdater, NULL, 0, REG_SZ, (const BYTE *) _T("1"), sizeof(TCHAR)*2);
}
void GateKeeper::disable_update()
{
LONG lResult = RegOpenKeyEx(cu, updater_reg_path, 0, KEY_WRITE, &hkUpdater);
if (lResult != ERROR_SUCCESS)
return;
lResult = RegSetValueEx(hkUpdater, NULL, 0, REG_SZ, (const BYTE *) _T("0"), sizeof(TCHAR) * 2);
}
bool GateKeeper::update_enabled()
{
bool enabled = true;
DWORD esize;
RegGetValue(cu, updater_reg_path, NULL, RRF_RT_REG_SZ, NULL, NULL, &esize);
if (esize) {
TCHAR* edata = new TCHAR[esize];
RegGetValue(cu, updater_reg_path, NULL, RRF_RT_REG_SZ, NULL, edata, &esize);
if (tstring(edata) == _T("0"))
enabled = false;
delete[] edata;
}
return enabled;
}
GateKeeper::product_list GateKeeper::registered_products()
{
product_list products;


+ 4
- 0
GateKeeper.h View File

@ -39,6 +39,10 @@ namespace pEp {
product_list registered_products();
bool update_product(product p, DWORD context = 0);
bool update_enabled();
void enable_update();
void disable_update();
static GateKeeper *gatekeeper() { return the_gatekeeper; }
protected:


BIN
pEpCOMServerAdapter.rc View File


Loading…
Cancel
Save