nextcloud-desktop/shell_integration/windows/OCUtil/RegistryUtil.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

71 lines
1.6 KiB
C++
Raw Normal View History

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.
*/
#include "stdafx.h"
2014-07-30 19:20:55 +04: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)
{
wstring* strResult = new wstring();
2014-07-30 19:20:55 +04:00
if(!ReadRegistry(key, name, strResult))
{
return false;
}
2014-07-30 19:20:55 +04:00
*result = stoi( strResult->c_str() );
2014-07-30 19:20:55 +04:00
return true;
2014-07-30 19:20:55 +04:00
}
bool RegistryUtil::ReadRegistry(const wchar_t* key, const wchar_t* name, wstring* result)
{
HRESULT hResult;
2014-07-30 19:20:55 +04:00
HKEY rootKey = NULL;
2014-07-30 19:20:55 +04:00
hResult = HRESULT_FROM_WIN32(RegOpenKeyEx(HKEY_CURRENT_USER, (LPCWSTR)key, NULL, KEY_READ, &rootKey));
2014-07-30 19:20:55 +04:00
if(!SUCCEEDED(hResult))
{
return false;
}
2014-07-30 19:20:55 +04: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 );
if(!SUCCEEDED(hResult))
{
return false;
}
2014-07-30 19:20:55 +04:00
result->append(value);
2014-07-30 19:20:55 +04:00
HRESULT hResult2 = RegCloseKey(rootKey);
2014-07-30 19:20:55 +04:00
if (!SUCCEEDED(hResult2))
{
return false;
}
2014-07-30 19:20:55 +04:00
return true;
2014-07-30 19:20:55 +04:00
}