Commit 48c2120c authored by Jean-Baptiste Kempf's avatar Jean-Baptiste Kempf

Qt4 - Windows registry manipulation. Create the good HKEY where there should...

Qt4 - Windows registry manipulation. Create the good HKEY where there should be, even if the installer didn't do it.
parent 4ab00739
...@@ -638,6 +638,7 @@ void SPrefsPanel::lastfm_Changed( int i_state ) ...@@ -638,6 +638,7 @@ void SPrefsPanel::lastfm_Changed( int i_state )
void SPrefsPanel::assoDialog() void SPrefsPanel::assoDialog()
{ {
QDialog *d = new QDialog( this ); QDialog *d = new QDialog( this );
QGridLayout *assoLayout = new QGridLayout( d ); QGridLayout *assoLayout = new QGridLayout( d );
...@@ -665,17 +666,46 @@ void SPrefsPanel::assoDialog() ...@@ -665,17 +666,46 @@ void SPrefsPanel::assoDialog()
CONNECT( clearButton, clicked(), d, reject() ); CONNECT( clearButton, clicked(), d, reject() );
d->exec(); d->exec();
delete d; delete d;
listAsso.clear();
} }
void addAsso( QVLCRegistry *qvReg, char *psz_ext ) void addAsso( QVLCRegistry *qvReg, char *psz_ext )
{ {
char psz_VLC[] = "VLC"; std::string s_path( "VLC" ); s_path += psz_ext;
std::string s_path2 = s_path;
/* Save a backup if already assigned */
char *psz_value = qvReg->ReadRegistryString( psz_ext, "", "" ); char *psz_value = qvReg->ReadRegistryString( psz_ext, "", "" );
if( strlen( psz_value ) > 0 )
if( psz_value && strlen( psz_value ) > 0 )
qvReg->WriteRegistryString( psz_ext, "VLC.backup", psz_value ); qvReg->WriteRegistryString( psz_ext, "VLC.backup", psz_value );
delete psz_value;
/* Put a "link" to VLC.EXT as default */
qvReg->WriteRegistryString( psz_ext, "", s_path.c_str() );
/* Create the needed Key if they weren't done in the installer */
if( !qvReg->RegistryKeyExists( s_path.c_str() ) )
{
qvReg->WriteRegistryString( psz_ext, "", s_path.c_str() );
qvReg->WriteRegistryString( s_path.c_str(), "", "Media file" );
qvReg->WriteRegistryString( s_path.append( "\\shell" ).c_str() , "", "Play" );
/* Get the installer path */
QVLCRegistry *qvReg2 = new QVLCRegistry( HKEY_LOCAL_MACHINE );
std::string str_temp; str_temp.assign(
qvReg2->ReadRegistryString( "Software\\VideoLAN\\VLC", "", "" ) );
if( str_temp.size() )
{
qvReg->WriteRegistryString( s_path.append( "\\Play\\command" ).c_str(),
"", str_temp.append(" --started-from-file \"%1\"" ).c_str() );
qvReg->WriteRegistryString( psz_ext, "", strcat( psz_VLC, psz_ext ) ); qvReg->WriteRegistryString( s_path2.append( "\\DefaultIcon" ).c_str(),
"", str_temp.append(",0").c_str() );
}
delete qvReg2;
}
} }
void delAsso( QVLCRegistry *qvReg, char *psz_ext ) void delAsso( QVLCRegistry *qvReg, char *psz_ext )
...@@ -683,18 +713,24 @@ void delAsso( QVLCRegistry *qvReg, char *psz_ext ) ...@@ -683,18 +713,24 @@ void delAsso( QVLCRegistry *qvReg, char *psz_ext )
char psz_VLC[] = "VLC"; char psz_VLC[] = "VLC";
char *psz_value = qvReg->ReadRegistryString( psz_ext, "", "" ); char *psz_value = qvReg->ReadRegistryString( psz_ext, "", "" );
if( !strcmp( strcat( psz_VLC, psz_ext ), psz_value ) ) if( psz_value && !strcmp( strcat( psz_VLC, psz_ext ), psz_value ) )
{ {
qvReg->WriteRegistryString( psz_ext, "", free( psz_value );
qvReg->ReadRegistryString( psz_ext, "VLC.backup", "" ) ); psz_value = qvReg->ReadRegistryString( psz_ext, "VLC.backup", "" );
// qvReg->DeletKey( psz_ext, "VLC.backup" ); if( psz_value )
qvReg->WriteRegistryString( psz_ext, "", psz_value );
//qvReg->DeletKey( psz_ext, "VLC.backup" );
} }
delete( psz_value );
} }
void SPrefsPanel::saveAsso() void SPrefsPanel::saveAsso()
{ {
for( int i = 0; i < listAsso.size(); i ++ ) for( int i = 0; i < listAsso.size(); i ++ )
{ {
QVLCRegistry * qvReg = new QVLCRegistry( HKEY_CLASSES_ROOT ); QVLCRegistry * qvReg = new QVLCRegistry( HKEY_CLASSES_ROOT );
if( listAsso[i]->checkState() > 0 ) if( listAsso[i]->checkState() > 0 )
{ {
addAsso( qvReg, qtu( listAsso[i]->text() ) ); addAsso( qvReg, qtu( listAsso[i]->text() ) );
......
...@@ -38,7 +38,7 @@ QVLCRegistry::~QVLCRegistry( void ) ...@@ -38,7 +38,7 @@ QVLCRegistry::~QVLCRegistry( void )
{ {
} }
bool QVLCRegistry::RegistryKeyExists( char *path ) bool QVLCRegistry::RegistryKeyExists( const char *path )
{ {
HKEY keyHandle; HKEY keyHandle;
if( RegOpenKeyEx( m_RootKey, path, 0, KEY_READ, &keyHandle ) == ERROR_SUCCESS ) if( RegOpenKeyEx( m_RootKey, path, 0, KEY_READ, &keyHandle ) == ERROR_SUCCESS )
...@@ -49,7 +49,7 @@ bool QVLCRegistry::RegistryKeyExists( char *path ) ...@@ -49,7 +49,7 @@ bool QVLCRegistry::RegistryKeyExists( char *path )
return false; return false;
} }
bool QVLCRegistry::RegistryValueExists( char *path, char *valueName ) bool QVLCRegistry::RegistryValueExists( const char *path, const char *valueName )
{ {
HKEY keyHandle; HKEY keyHandle;
bool temp = false; bool temp = false;
...@@ -68,7 +68,7 @@ bool QVLCRegistry::RegistryValueExists( char *path, char *valueName ) ...@@ -68,7 +68,7 @@ bool QVLCRegistry::RegistryValueExists( char *path, char *valueName )
return temp; return temp;
} }
void QVLCRegistry::WriteRegistryInt( char *path, char *valueName, int value ) void QVLCRegistry::WriteRegistryInt( const char *path, const char *valueName, int value )
{ {
HKEY keyHandle; HKEY keyHandle;
...@@ -81,7 +81,7 @@ void QVLCRegistry::WriteRegistryInt( char *path, char *valueName, int value ) ...@@ -81,7 +81,7 @@ void QVLCRegistry::WriteRegistryInt( char *path, char *valueName, int value )
} }
} }
void QVLCRegistry::WriteRegistryString( char *path, char *valueName, char *value ) void QVLCRegistry::WriteRegistryString( const char *path, const char *valueName, const char *value )
{ {
HKEY keyHandle; HKEY keyHandle;
...@@ -94,7 +94,7 @@ void QVLCRegistry::WriteRegistryString( char *path, char *valueName, char *value ...@@ -94,7 +94,7 @@ void QVLCRegistry::WriteRegistryString( char *path, char *valueName, char *value
} }
} }
void QVLCRegistry::WriteRegistryDouble( char *path, char *valueName, double value ) void QVLCRegistry::WriteRegistryDouble( const char *path, const char *valueName, double value )
{ {
HKEY keyHandle; HKEY keyHandle;
if( RegCreateKeyEx( m_RootKey, path, 0, NULL, REG_OPTION_NON_VOLATILE, if( RegCreateKeyEx( m_RootKey, path, 0, NULL, REG_OPTION_NON_VOLATILE,
...@@ -105,7 +105,7 @@ void QVLCRegistry::WriteRegistryDouble( char *path, char *valueName, double valu ...@@ -105,7 +105,7 @@ void QVLCRegistry::WriteRegistryDouble( char *path, char *valueName, double valu
} }
} }
int QVLCRegistry::ReadRegistryInt( char *path, char *valueName, int default_value ) { int QVLCRegistry::ReadRegistryInt( const char *path, const char *valueName, int default_value ) {
HKEY keyHandle; HKEY keyHandle;
int tempValue; int tempValue;
DWORD size1; DWORD size1;
...@@ -128,7 +128,7 @@ int QVLCRegistry::ReadRegistryInt( char *path, char *valueName, int default_valu ...@@ -128,7 +128,7 @@ int QVLCRegistry::ReadRegistryInt( char *path, char *valueName, int default_valu
return default_value; return default_value;
} }
char * QVLCRegistry::ReadRegistryString( char *path, char *valueName, char *default_value ) char * QVLCRegistry::ReadRegistryString( const char *path, const char *valueName, char *default_value )
{ {
HKEY keyHandle; HKEY keyHandle;
char *tempValue = NULL; char *tempValue = NULL;
...@@ -161,7 +161,7 @@ char * QVLCRegistry::ReadRegistryString( char *path, char *valueName, char *defa ...@@ -161,7 +161,7 @@ char * QVLCRegistry::ReadRegistryString( char *path, char *valueName, char *defa
return default_value; return default_value;
} }
double QVLCRegistry::ReadRegistryDouble( char *path, char *valueName, double default_value ) double QVLCRegistry::ReadRegistryDouble( const char *path, const char *valueName, double default_value )
{ {
HKEY keyHandle; HKEY keyHandle;
double tempValue; double tempValue;
...@@ -187,4 +187,33 @@ double QVLCRegistry::ReadRegistryDouble( char *path, char *valueName, double def ...@@ -187,4 +187,33 @@ double QVLCRegistry::ReadRegistryDouble( char *path, char *valueName, double def
return default_value; return default_value;
} }
int QVLCRegistry::DeleteValue( char *path, char *valueName )
{
HKEY keyHandle;
long result;
if( (result = RegOpenKeyEx(m_RootKey, path, 0, KEY_WRITE, &keyHandle)) == ERROR_SUCCESS)
{
result = RegDeleteValue(keyHandle, valueName);
RegCloseKey(keyHandle);
}
//ERROR_SUCCESS = ok everything else you have a problem*g*,
return result;
}
long QVLCRegistry::DeleteKey( char *path, char *keyName )
{
HKEY keyHandle;
long result;
if( (result = RegOpenKeyEx(m_RootKey, path, 0, KEY_WRITE, &keyHandle)) == ERROR_SUCCESS)
{
// be warned the key "keyName" will not be deleted if there are subkeys below him, values
// I think are ok and will be recusively deleted, but not keys...
// for this case we have to do a little bit more work!
result = RegDeleteKey(keyHandle, keyName);
RegCloseKey(keyHandle);
}
//ERROR_SUCCESS = ok everything else you have a problem*g*,
return result;
}
#endif /* WIN32 */ #endif /* WIN32 */
...@@ -34,16 +34,18 @@ public: ...@@ -34,16 +34,18 @@ public:
QVLCRegistry(HKEY rootKey); QVLCRegistry(HKEY rootKey);
~QVLCRegistry(void); ~QVLCRegistry(void);
void WriteRegistryInt(char *path, char *valueName, int value); void WriteRegistryInt( const char *path, const char *valueName, int value);
void WriteRegistryString(char *path, char *valueName, char *value); void WriteRegistryString( const char *path, const char *valueName, const char *value);
void WriteRegistryDouble(char *path, char *valueName, double value); void WriteRegistryDouble( const char *path, const char *valueName, double value);
int ReadRegistryInt(char *path, char *valueName, int default_value); int ReadRegistryInt( const char *path, const char *valueName, int default_value);
char * ReadRegistryString(char *path, char *valueName, char *default_value); char * ReadRegistryString( const char *path, const char *valueName, char *default_value);
double ReadRegistryDouble(char *path, char *valueName, double default_value); double ReadRegistryDouble( const char *path, const char *valueName, double default_value);
bool RegistryKeyExists(char *path); bool RegistryKeyExists( const char *path);
bool RegistryValueExists(char *path, char *valueName); bool RegistryValueExists( const char *path, const char *valueName);
int DeleteValue( char *path, char *valueName );
long DeleteKey( char *path, char *keyName );
}; };
#endif #endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment