pEpCOMServerAdapter.cpp
changeset 87 f0ce6a1a7118
parent 86 e18b34f4b9cc
child 88 659d0fc5bc30
     1.1 --- a/pEpCOMServerAdapter.cpp	Sat Jun 18 21:26:51 2016 +0200
     1.2 +++ b/pEpCOMServerAdapter.cpp	Sun Jun 19 01:04:41 2016 +0200
     1.3 @@ -35,7 +35,13 @@
     1.4  
     1.5      GateKeeper(CpEpCOMServerAdapterModule * const self) : _self(self), now(time(NULL)), next(now + time_diff())
     1.6      {
     1.7 +        LONG lResult = RegOpenCurrentUser(KEY_READ, &cu);
     1.8 +        assert(lResult == ERROR_SUCCESS);
     1.9 +    }
    1.10  
    1.11 +    ~GateKeeper()
    1.12 +    {
    1.13 +        RegCloseKey(cu);
    1.14      }
    1.15  
    1.16      void keep();
    1.17 @@ -43,20 +49,26 @@
    1.18      void keep_plugin();
    1.19      void keep_updated();
    1.20  
    1.21 +protected:
    1.22 +    static const LPCTSTR plugin_reg_path;
    1.23 +    static const LPCTSTR plugin_reg_value_name;
    1.24 +
    1.25  private:
    1.26      time_t now;
    1.27      time_t next;
    1.28 +    HKEY cu;
    1.29  
    1.30      CpEpCOMServerAdapterModule * const _self;
    1.31  };
    1.32  
    1.33 +const LPCTSTR GateKeeper::plugin_reg_path = _T("Software\\Microsoft\\Office\\Outlook\\Addins\\pEp");
    1.34 +const LPCTSTR GateKeeper::plugin_reg_value_name = _T("LoadBehavior");
    1.35 +
    1.36  void GateKeeper::keep()
    1.37  {
    1.38      while (1) {
    1.39          keep_plugin();
    1.40  
    1.41 -        Sleep(10000);
    1.42 -        
    1.43          now = time(NULL);
    1.44          assert(now != -1);
    1.45          
    1.46 @@ -64,12 +76,25 @@
    1.47              next = now + GateKeeper::cycle;
    1.48              keep_updated();
    1.49          }
    1.50 +
    1.51 +        Sleep(10000);
    1.52      }
    1.53  }
    1.54  
    1.55  void GateKeeper::keep_plugin()
    1.56  {
    1.57 +    DWORD value;
    1.58 +    DWORD size;
    1.59 +    LONG lResult = RegGetValue(cu, plugin_reg_path, plugin_reg_value_name, RRF_RT_REG_DWORD, NULL, &value, &size);
    1.60  
    1.61 +    assert(lResult == ERROR_SUCCESS);
    1.62 +    if (lResult != ERROR_SUCCESS)
    1.63 +        return;
    1.64 +
    1.65 +    if (value != 3) {
    1.66 +        lResult = RegSetValue(cu, plugin_reg_path, RRF_RT_REG_DWORD, plugin_reg_value_name, 3);
    1.67 +        assert(lResult == ERROR_SUCCESS);
    1.68 +    }
    1.69  }
    1.70  
    1.71  void GateKeeper::keep_updated()