1 /*****************************************************************************
2 * registry.cpp: Windows Registry Manipulation
3 ****************************************************************************
4 * Copyright (C) 2008 the VideoLAN team
5 * $Id: input_slider.cpp 24525 2008-01-23 21:50:58Z courmisch $
7 * Authors: Andre Weber <WeberAndre # gmx - de>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
28 #include "registry.hpp"
30 QVLCRegistry::QVLCRegistry( HKEY rootKey )
35 QVLCRegistry::~QVLCRegistry( void )
39 bool QVLCRegistry::RegistryKeyExists( char *path )
42 if( RegOpenKeyEx( m_RootKey, path, 0, KEY_READ, &keyHandle ) == ERROR_SUCCESS )
44 RegCloseKey( keyHandle );
50 bool QVLCRegistry::RegistryValueExists( char *path, char *valueName )
57 if( RegOpenKeyEx( m_RootKey, path, 0, KEY_READ, &keyHandle ) == ERROR_SUCCESS )
59 if( RegQueryValueEx( keyHandle, valueName, NULL,
60 &valueType, NULL, &size1 ) == ERROR_SUCCESS )
64 RegCloseKey( keyHandle );
69 void QVLCRegistry::WriteRegistryInt( char *path, char *valueName, int value )
73 if( RegCreateKeyEx( m_RootKey, path, 0, NULL, REG_OPTION_NON_VOLATILE,
74 KEY_WRITE, NULL, &keyHandle, NULL ) == ERROR_SUCCESS )
76 RegSetValueEx( keyHandle, valueName, 0, REG_DWORD,
77 (LPBYTE)&value, sizeof( int ) );
78 RegCloseKey( keyHandle );
82 void QVLCRegistry::WriteRegistryString( char *path, char *valueName, char *value )
86 if( RegCreateKeyEx( m_RootKey, path, 0, NULL, REG_OPTION_NON_VOLATILE,
87 KEY_WRITE, NULL, &keyHandle, NULL ) == ERROR_SUCCESS )
89 RegSetValueEx( keyHandle, valueName, 0, REG_SZ, (LPBYTE)value,
90 (DWORD)( strlen( value ) + 1 ) );
91 RegCloseKey( keyHandle );
95 void QVLCRegistry::WriteRegistryDouble( char *path, char *valueName, double value )
98 if( RegCreateKeyEx( m_RootKey, path, 0, NULL, REG_OPTION_NON_VOLATILE,
99 KEY_WRITE, NULL, &keyHandle, NULL ) == ERROR_SUCCESS )
101 RegSetValueEx( keyHandle, valueName, 0, REG_BINARY, (LPBYTE)&value, sizeof( double ) );
102 RegCloseKey( keyHandle );
106 int QVLCRegistry::ReadRegistryInt( char *path, char *valueName, int default_value ) {
112 if( RegOpenKeyEx( m_RootKey, path, 0, KEY_READ, &keyHandle ) == ERROR_SUCCESS )
114 if( RegQueryValueEx( keyHandle, valueName, NULL, &valueType, NULL, &size1 ) == ERROR_SUCCESS )
116 if( valueType == REG_DWORD )
118 if( RegQueryValueEx( keyHandle, valueName, NULL, &valueType, (LPBYTE)&tempValue, &size1 ) == ERROR_SUCCESS )
120 default_value = tempValue;
124 RegCloseKey( keyHandle );
126 return default_value;
129 char * QVLCRegistry::ReadRegistryString( char *path, char *valueName, char *default_value )
132 char *tempValue = NULL;
136 if( RegOpenKeyEx( m_RootKey, path, 0, KEY_READ, &keyHandle ) == ERROR_SUCCESS )
138 if( RegQueryValueEx( keyHandle, valueName, NULL, &valueType, NULL, &size1 ) == ERROR_SUCCESS )
140 if( valueType == REG_SZ )
143 tempValue = ( char * )malloc( size1+1 ); // +1 für NullByte`?
144 if( RegQueryValueEx( keyHandle, valueName, NULL, &valueType, (LPBYTE)tempValue, &size1 ) == ERROR_SUCCESS )
146 default_value = tempValue;
150 RegCloseKey( keyHandle );
152 if( tempValue == NULL )
154 // wenn tempValue nicht aus registry gelesen wurde dafür sorgen das ein neuer String mit der Kopie von DefaultValue
155 // geliefert wird - das macht das Handling des Rückgabewertes der Funktion einfacher - immer schön mit free freigeben!
156 default_value = strdup( default_value );
159 return default_value;
162 double QVLCRegistry::ReadRegistryDouble( char *path, char *valueName, double default_value )
169 if( RegOpenKeyEx( m_RootKey, path, 0, KEY_READ, &keyHandle ) == ERROR_SUCCESS )
171 if( RegQueryValueEx( keyHandle, valueName, NULL, &valueType,
172 NULL, &size1 ) == ERROR_SUCCESS )
174 if( ( valueType == REG_BINARY ) && ( size1 == sizeof( double ) ) )
176 if( RegQueryValueEx( keyHandle, valueName, NULL, &valueType,
177 (LPBYTE)&tempValue, &size1 ) == ERROR_SUCCESS )
179 default_value = tempValue;
183 RegCloseKey( keyHandle );
185 return default_value;