GateKeeper.cpp
changeset 208 35eb7b0492ac
parent 207 d5d291166c76
child 209 dbc6c02c9755
     1.1 --- a/GateKeeper.cpp	Sun Nov 13 08:13:54 2016 +0100
     1.2 +++ b/GateKeeper.cpp	Sun Nov 13 08:45:29 2016 +0100
     1.3 @@ -122,6 +122,8 @@
     1.4          : _self(self), now(time(NULL)), next(now + time_diff()), hkUpdater(NULL), hkPluginStart(NULL),
     1.5              internet(NULL), hAES(NULL), hRSA(NULL)
     1.6      {
     1.7 +		DeleteFile(get_lockFile().c_str());
     1.8 +
     1.9          LONG lResult = RegOpenCurrentUser(KEY_READ, &cu);
    1.10          assert(lResult == ERROR_SUCCESS);
    1.11          if (lResult == ERROR_SUCCESS)
    1.12 @@ -377,11 +379,12 @@
    1.13  		}
    1.14      }
    1.15  
    1.16 -    void GateKeeper::update_product(product p, DWORD context)
    1.17 -    {
    1.18 -		{
    1.19 -			const tstring _fileName = _T("\\pEpSetup.lck");
    1.20 +	tstring GateKeeper::get_lockFile()
    1.21 +	{
    1.22 +		static const tstring _fileName = _T("\\pEpSetup.lck");
    1.23 +		static tstring fileName;
    1.24  
    1.25 +		if (fileName.length() == 0) {
    1.26  			unique_ptr < TCHAR[] > _pathName(new TCHAR[MAX_PATH + 1]);
    1.27  			DWORD size = GetTempPath(MAX_PATH, _pathName.get());
    1.28  			if (size > MAX_PATH - _fileName.size())
    1.29 @@ -389,14 +392,21 @@
    1.30  
    1.31  			tstring fileName(_pathName.get());
    1.32  			fileName += _fileName;
    1.33 +		}
    1.34  
    1.35 -			HANDLE file = CreateFile(fileName.c_str(), GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL);
    1.36 +		return fileName;
    1.37 +	}
    1.38 +
    1.39 +    void GateKeeper::update_product(product p, DWORD context)
    1.40 +    {
    1.41 +		{
    1.42 +			HANDLE file = CreateFile(get_lockFile().c_str(), GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL);
    1.43  			if (file == INVALID_HANDLE_VALUE) {
    1.44  				return;
    1.45  			}
    1.46  			else {
    1.47  				CloseHandle(file);
    1.48 -				DeleteFile(fileName.c_str());
    1.49 +				DeleteFile(get_lockFile().c_str());
    1.50  			}
    1.51  		}
    1.52