mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-06-07 06:02:41 -04:00
Created V0.3.x branch and moved the head into the trunk directory.
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@246 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
commit
935745a08e
1318 changed files with 348809 additions and 0 deletions
110
retroshare-gui/src/util/registry.cpp
Normal file
110
retroshare-gui/src/util/registry.cpp
Normal file
|
@ -0,0 +1,110 @@
|
|||
/****************************************************************
|
||||
* RShare is distributed under the following license:
|
||||
*
|
||||
* Copyright (C) 2006, crypton
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
****************************************************************/
|
||||
|
||||
|
||||
|
||||
#include "registry.h"
|
||||
|
||||
/** Returns the value in keyName at keyLocation.
|
||||
* Returns an empty QString if the keyName doesn't exist */
|
||||
QString
|
||||
registry_get_key_value(QString keyLocation, QString keyName)
|
||||
{
|
||||
#if 0
|
||||
HKEY key;
|
||||
char data[255] = {0};
|
||||
DWORD size = sizeof(data);
|
||||
|
||||
/* Open the key for reading (opens new key if it doesn't exist) */
|
||||
if (RegOpenKeyExA(HKEY_CURRENT_USER,
|
||||
qPrintable(keyLocation),
|
||||
0L, KEY_READ, &key) == ERROR_SUCCESS) {
|
||||
|
||||
/* Key exists, so read the value into data */
|
||||
RegQueryValueExA(key, qPrintable(keyName),
|
||||
NULL, NULL, (LPBYTE)data, &size);
|
||||
}
|
||||
|
||||
/* Close anything that was opened */
|
||||
RegCloseKey(key);
|
||||
|
||||
return QString(data);
|
||||
#endif
|
||||
return keyName;
|
||||
|
||||
}
|
||||
|
||||
/** Creates and/or sets the key to the specified value */
|
||||
void
|
||||
registry_set_key_value(QString keyLocation, QString keyName, QString keyValue)
|
||||
{
|
||||
|
||||
#if 0
|
||||
HKEY key;
|
||||
|
||||
/* Open the key for writing (opens new key if it doesn't exist */
|
||||
if (RegOpenKeyExA(HKEY_CURRENT_USER,
|
||||
qPrintable(keyLocation),
|
||||
0, KEY_WRITE, &key) != ERROR_SUCCESS) {
|
||||
|
||||
/* Key didn't exist, so write the newly opened key */
|
||||
RegCreateKeyExA(HKEY_CURRENT_USER,
|
||||
qPrintable(keyLocation),
|
||||
0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL,
|
||||
&key, NULL);
|
||||
}
|
||||
|
||||
/* Save the value in the key */
|
||||
RegSetValueExA(key, qPrintable(keyName), 0, REG_SZ,
|
||||
(BYTE *)qPrintable(keyValue),
|
||||
(DWORD)keyValue.length() + 1); // include null terminator
|
||||
|
||||
/* Close the key */
|
||||
RegCloseKey(key);
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
/** Removes the key from the registry if it exists */
|
||||
void
|
||||
registry_remove_key(QString keyLocation, QString keyName)
|
||||
{
|
||||
|
||||
#if 0
|
||||
|
||||
HKEY key;
|
||||
|
||||
/* Open the key for writing (opens new key if it doesn't exist */
|
||||
if (RegOpenKeyExA(HKEY_CURRENT_USER,
|
||||
qPrintable(keyLocation),
|
||||
0, KEY_SET_VALUE, &key) == ERROR_SUCCESS) {
|
||||
|
||||
/* Key exists so delete it */
|
||||
RegDeleteValueA(key, qPrintable(keyName));
|
||||
}
|
||||
|
||||
/* Close anything that was opened */
|
||||
RegCloseKey(key);
|
||||
|
||||
#endif
|
||||
|
||||
}
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue