store updateKey in resource table
authorVolker Birk <vb@pep-project.org>
Tue, 21 Jun 2016 19:24:54 +0200
changeset 110c643437f9b61
parent 109 8df335509e5c
child 111 b89e8368e968
store updateKey in resource table
GateKeeper.cpp
GateKeeper.h
pEpCOMServerAdapter.cpp
pEpCOMServerAdapter.h
pEpCOMServerAdapter.rc
pEpCOMServerAdapter.vcxproj
pEpCOMServerAdapter.vcxproj.filters
resource.h
     1.1 --- a/GateKeeper.cpp	Mon Jun 20 16:40:46 2016 +0200
     1.2 +++ b/GateKeeper.cpp	Tue Jun 21 19:24:54 2016 +0200
     1.3 @@ -1,6 +1,7 @@
     1.4  #include "stdafx.h"
     1.5  
     1.6  #include "GateKeeper.h"
     1.7 +#include "pEpCOMServerAdapter.h"
     1.8  
     1.9  using namespace std;
    1.10  
    1.11 @@ -78,6 +79,11 @@
    1.12  
    1.13      void GateKeeper::keep_plugin()
    1.14      {
    1.15 +        while (!_self->m_bComInitialized)
    1.16 +            Sleep(1);
    1.17 +
    1.18 +        MessageBox(NULL, _T("test"), _T("keep_plugin"), MB_ICONINFORMATION | MB_TOPMOST);
    1.19 +
    1.20          DWORD value;
    1.21          DWORD size;
    1.22  
    1.23 @@ -91,6 +97,28 @@
    1.24          }
    1.25      }
    1.26  
    1.27 +    string GateKeeper::updateKey()
    1.28 +    {
    1.29 +        static string key;
    1.30 +
    1.31 +        if (key.length() == 0) {
    1.32 +            HRSRC res = FindResource(_self->hModule(), MAKEINTRESOURCE(IRD_UPDATEKEY), RT_RCDATA);
    1.33 +            assert(res);
    1.34 +            if (!res)
    1.35 +                throw runtime_error("FindResource: IRD_UPDATEKEY");
    1.36 +
    1.37 +            HGLOBAL hRes = LoadResource(_self->hModule(), res);
    1.38 +            assert(hRes);
    1.39 +            if (!hRes)
    1.40 +                throw runtime_error("LoadResource: IRD_UPDATEKEY");
    1.41 +
    1.42 +            key = string((char *)LockResource(hRes), SizeofResource(_self->hModule(), res));
    1.43 +            UnlockResource(hRes);
    1.44 +        }
    1.45 +
    1.46 +        return key;
    1.47 +    }
    1.48 +
    1.49      GateKeeper::product_list& GateKeeper::registered_products()
    1.50      {
    1.51          static product_list products;
     2.1 --- a/GateKeeper.h	Mon Jun 20 16:40:46 2016 +0200
     2.2 +++ b/GateKeeper.h	Tue Jun 21 19:24:54 2016 +0200
     2.3 @@ -37,6 +37,7 @@
     2.4  
     2.5          void keep_plugin();
     2.6  
     2.7 +        string updateKey();
     2.8          string handshake(HINTERNET hUrl);
     2.9          void update_product(product p, DWORD context);
    2.10          product_list& registered_products();
    2.11 @@ -50,6 +51,6 @@
    2.12          HKEY hkUpdater;
    2.13          HINTERNET internet;
    2.14  
    2.15 -        CpEpCOMServerAdapterModule * const _self;
    2.16 +        CpEpCOMServerAdapterModule * _self;
    2.17      };
    2.18  }
     3.1 --- a/pEpCOMServerAdapter.cpp	Mon Jun 20 16:40:46 2016 +0200
     3.2 +++ b/pEpCOMServerAdapter.cpp	Tue Jun 21 19:24:54 2016 +0200
     3.3 @@ -3,38 +3,14 @@
     3.4  
     3.5  #include "stdafx.h"
     3.6  #include "resource.h"
     3.7 -#include "pEpCOMServerAdapter_i.h"
     3.8  #include "xdlldata.h"
     3.9  
    3.10  #include "GateKeeper.h"
    3.11 +#include "pEpCOMServerAdapter.h"
    3.12  
    3.13  using namespace ATL;
    3.14  using namespace std;
    3.15  
    3.16 -class CpEpCOMServerAdapterModule : public ATL::CAtlExeModuleT< CpEpCOMServerAdapterModule >
    3.17 -{
    3.18 -public:
    3.19 -    CpEpCOMServerAdapterModule() : ATL::CAtlExeModuleT< CpEpCOMServerAdapterModule >(), gatekeeper_thread(NULL)
    3.20 -    {
    3.21 -        try {
    3.22 -            gatekeeper_thread = new thread(gatekeeper, this);
    3.23 -            gatekeeper_thread->detach();
    3.24 -        }
    3.25 -        catch (system_error&) {
    3.26 -
    3.27 -        }
    3.28 -    }
    3.29 -
    3.30 -	DECLARE_LIBID(LIBID_pEpCOMServerAdapterLib)
    3.31 -	DECLARE_REGISTRY_APPID_RESOURCEID(IDR_PEPCOMSERVERADAPTER, "{B3480081-82C0-4EE4-9AA1-3F513C9D78DD}")
    3.32 -
    3.33 -protected:
    3.34 -    static void gatekeeper(CpEpCOMServerAdapterModule * const self);
    3.35 -
    3.36 -private:
    3.37 -    thread *gatekeeper_thread;
    3.38 -};
    3.39 -
    3.40  void CpEpCOMServerAdapterModule::gatekeeper(CpEpCOMServerAdapterModule * const self)
    3.41  {
    3.42      pEp::GateKeeper keeper(self);
    3.43 @@ -44,9 +20,11 @@
    3.44  CpEpCOMServerAdapterModule _AtlModule;
    3.45  
    3.46  //
    3.47 -extern "C" int WINAPI _tWinMain(HINSTANCE /*hInstance*/, HINSTANCE /*hPrevInstance*/, 
    3.48 +extern "C" int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, 
    3.49  								LPTSTR /*lpCmdLine*/, int nShowCmd)
    3.50  {
    3.51 +    _AtlModule.hModule(hInstance);
    3.52 +    _AtlModule.start_gatekeeper();
    3.53 +
    3.54      return _AtlModule.WinMain(nShowCmd);
    3.55  }
    3.56 -
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/pEpCOMServerAdapter.h	Tue Jun 21 19:24:54 2016 +0200
     4.3 @@ -0,0 +1,44 @@
     4.4 +#include "stdafx.h"
     4.5 +
     4.6 +#include "pEpCOMServerAdapter_i.h"
     4.7 +
     4.8 +using namespace ATL;
     4.9 +using namespace std;
    4.10 +
    4.11 +class CpEpCOMServerAdapterModule : public ATL::CAtlExeModuleT< CpEpCOMServerAdapterModule > {
    4.12 +public:
    4.13 +    CpEpCOMServerAdapterModule() : ATL::CAtlExeModuleT< CpEpCOMServerAdapterModule >(), gatekeeper_thread(NULL), _hModule(NULL)
    4.14 +    {
    4.15 +    }
    4.16 +
    4.17 +    DECLARE_LIBID(LIBID_pEpCOMServerAdapterLib)
    4.18 +    DECLARE_REGISTRY_APPID_RESOURCEID(IDR_PEPCOMSERVERADAPTER, "{B3480081-82C0-4EE4-9AA1-3F513C9D78DD}")
    4.19 +
    4.20 +    HMODULE hModule()
    4.21 +    {
    4.22 +        return _hModule;
    4.23 +    }
    4.24 +
    4.25 +    void hModule(HMODULE m)
    4.26 +    {
    4.27 +        _hModule = m;
    4.28 +    }
    4.29 +
    4.30 +    void start_gatekeeper()
    4.31 +    {
    4.32 +        try {
    4.33 +            gatekeeper_thread = new thread(gatekeeper, this);
    4.34 +            gatekeeper_thread->detach();
    4.35 +        }
    4.36 +        catch (system_error&) {
    4.37 +
    4.38 +        }
    4.39 +    }
    4.40 +
    4.41 +protected:
    4.42 +    static void gatekeeper(CpEpCOMServerAdapterModule * self);
    4.43 +
    4.44 +private:
    4.45 +    thread *gatekeeper_thread;
    4.46 +    HMODULE _hModule;
    4.47 +};
     5.1 Binary file pEpCOMServerAdapter.rc has changed
     6.1 --- a/pEpCOMServerAdapter.vcxproj	Mon Jun 20 16:40:46 2016 +0200
     6.2 +++ b/pEpCOMServerAdapter.vcxproj	Tue Jun 21 19:24:54 2016 +0200
     6.3 @@ -154,6 +154,7 @@
     6.4      <ClInclude Include="CpEpEngine.h" />
     6.5      <ClInclude Include="GateKeeper.h" />
     6.6      <ClInclude Include="locked_queue.hh" />
     6.7 +    <ClInclude Include="pEpCOMServerAdapter.h" />
     6.8      <ClInclude Include="pEpCOMServerAdapter_i.h" />
     6.9      <ClInclude Include="pEp_utility.h" />
    6.10      <ClInclude Include="Resource.h" />
    6.11 @@ -173,6 +174,7 @@
    6.12      <None Include="..\..\pep_for_outlook\pep\pep_test.snk" />
    6.13      <None Include="pEpCOMServerAdapter.rgs" />
    6.14      <None Include="pEpEngine.rgs" />
    6.15 +    <None Include="updatekey.bin" />
    6.16    </ItemGroup>
    6.17    <ItemGroup>
    6.18      <Midl Include="pEpCOMServerAdapter.idl" />
     7.1 --- a/pEpCOMServerAdapter.vcxproj.filters	Mon Jun 20 16:40:46 2016 +0200
     7.2 +++ b/pEpCOMServerAdapter.vcxproj.filters	Tue Jun 21 19:24:54 2016 +0200
     7.3 @@ -78,6 +78,9 @@
     7.4      <ClInclude Include="GateKeeper.h">
     7.5        <Filter>Header Files</Filter>
     7.6      </ClInclude>
     7.7 +    <ClInclude Include="pEpCOMServerAdapter.h">
     7.8 +      <Filter>Header Files</Filter>
     7.9 +    </ClInclude>
    7.10    </ItemGroup>
    7.11    <ItemGroup>
    7.12      <ResourceCompile Include="pEpCOMServerAdapter.rc">
    7.13 @@ -95,6 +98,9 @@
    7.14        <Filter>Resource Files</Filter>
    7.15      </None>
    7.16      <None Include="..\..\pep_for_outlook\pep\pep_test.snk" />
    7.17 +    <None Include="updatekey.bin">
    7.18 +      <Filter>Resource Files</Filter>
    7.19 +    </None>
    7.20    </ItemGroup>
    7.21    <ItemGroup>
    7.22      <Midl Include="pEpCOMServerAdapter.idl">
     8.1 Binary file resource.h has changed