2014-07-30 19:20:55 +04:00
|
|
|
/**
|
|
|
|
* Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or modify it under
|
|
|
|
* the terms of the GNU Lesser General Public License as published by the Free
|
|
|
|
* Software Foundation; either version 2.1 of the License, or (at your option)
|
|
|
|
* any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
|
|
|
* details.
|
|
|
|
*/
|
|
|
|
|
2015-02-04 21:54:34 +03:00
|
|
|
#include "stdafx.h"
|
2014-07-30 19:20:55 +04:00
|
|
|
|
2015-02-04 21:54:34 +03:00
|
|
|
#include "RegistryUtil.h"
|
2014-07-30 19:20:55 +04:00
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
#define SIZE 4096
|
|
|
|
|
|
|
|
bool RegistryUtil::ReadRegistry(const wchar_t* key, const wchar_t* name, int* result)
|
|
|
|
{
|
2017-01-05 19:28:28 +03:00
|
|
|
wstring* strResult = new wstring();
|
2014-07-30 19:20:55 +04:00
|
|
|
|
2017-01-05 19:28:28 +03:00
|
|
|
if(!ReadRegistry(key, name, strResult))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2014-07-30 19:20:55 +04:00
|
|
|
|
2017-01-05 19:28:28 +03:00
|
|
|
*result = stoi( strResult->c_str() );
|
2014-07-30 19:20:55 +04:00
|
|
|
|
2017-01-05 19:28:28 +03:00
|
|
|
return true;
|
2014-07-30 19:20:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool RegistryUtil::ReadRegistry(const wchar_t* key, const wchar_t* name, wstring* result)
|
|
|
|
{
|
2017-01-05 19:28:28 +03:00
|
|
|
HRESULT hResult;
|
2014-07-30 19:20:55 +04:00
|
|
|
|
2017-01-05 19:28:28 +03:00
|
|
|
HKEY rootKey = NULL;
|
2014-07-30 19:20:55 +04:00
|
|
|
|
2017-01-05 19:28:28 +03:00
|
|
|
hResult = HRESULT_FROM_WIN32(RegOpenKeyEx(HKEY_CURRENT_USER, (LPCWSTR)key, NULL, KEY_READ, &rootKey));
|
2014-07-30 19:20:55 +04:00
|
|
|
|
2017-01-05 19:28:28 +03:00
|
|
|
if(!SUCCEEDED(hResult))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2014-07-30 19:20:55 +04:00
|
|
|
|
2017-01-05 19:28:28 +03:00
|
|
|
wchar_t value[SIZE];
|
|
|
|
DWORD value_length = SIZE;
|
|
|
|
|
2014-07-30 19:20:55 +04:00
|
|
|
hResult = RegQueryValueEx(rootKey, (LPCWSTR)name, NULL, NULL, (LPBYTE)value, &value_length );
|
|
|
|
|
2017-01-05 19:28:28 +03:00
|
|
|
if(!SUCCEEDED(hResult))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2014-07-30 19:20:55 +04:00
|
|
|
|
2017-01-05 19:28:28 +03:00
|
|
|
result->append(value);
|
2014-07-30 19:20:55 +04:00
|
|
|
|
2017-01-05 19:28:28 +03:00
|
|
|
HRESULT hResult2 = RegCloseKey(rootKey);
|
2014-07-30 19:20:55 +04:00
|
|
|
|
2017-01-05 19:28:28 +03:00
|
|
|
if (!SUCCEEDED(hResult2))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2014-07-30 19:20:55 +04:00
|
|
|
|
2017-01-05 19:28:28 +03:00
|
|
|
return true;
|
2014-07-30 19:20:55 +04:00
|
|
|
}
|