@ -21,50 +21,53 @@
using namespace std ;
using namespace NLMISC ;
void deleteKey ( HKEY hKey , const TCHAR * name )
void deleteKey ( HKEY hKey , const TCHAR * name )
{
HKEY subKey ;
if ( RegOpenKey ( hKey , name , & subKey ) = = ERROR_SUCCESS )
if ( RegOpenKey ( hKey , name , & subKey ) = = ERROR_SUCCESS )
{
TCHAR subName [ 512 ] ;
while ( RegEnumKey ( subKey , 0 , subName , 512 ) = = ERROR_SUCCESS )
while ( RegEnumKey ( subKey , 0 , subName , 512 ) = = ERROR_SUCCESS )
{
deleteKey ( subKey , subName ) ;
deleteKey ( subKey , subName ) ;
}
nlverify ( RegDeleteKey ( hKey , name ) = = ERROR_SUCCESS ) ;
nlverify ( RegDeleteKey ( hKey , name ) = = ERROR_SUCCESS ) ;
}
}
// Register an application
bool RegisterApp ( const char * appName , const char * appDescription , const char * icon , int iconIndex )
bool RegisterApp ( const char * appName , const char * appDescription , const char * icon , int iconIndex )
{
// Create the app key
HKEY hKey ;
if ( RegCreateKey ( HKEY_CLASSES_ROOT , appName, & hKey ) = = ERROR_SUCCESS )
if ( RegCreateKey ( HKEY_CLASSES_ROOT , nlUtf8ToTStr( appName) , & hKey ) = = ERROR_SUCCESS )
{
// Set the description
RegSetValue ( hKey , " " , REG_SZ , appDescription , strlen ( appDescription ) ) ;
tstring tAppDescription = utf8ToTStr ( appDescription ) ;
RegSetValue ( hKey , _T ( " " ) , REG_SZ , tAppDescription . c_str ( ) , ( tAppDescription . size ( ) + 1 ) * sizeof ( TCHAR ) ) ;
// Create the icon
HKEY hKey2 ;
if ( RegCreateKey ( hKey , " DefaultIcon " , & hKey2 ) = = ERROR_SUCCESS )
if ( RegCreateKey ( hKey , _T ( " DefaultIcon " ) , & hKey2 ) = = ERROR_SUCCESS )
{
// Set the description
char tmp [ 512 ] ;
smprintf ( tmp , 512 , " %s,%d " , icon , iconIndex ) ;
RegSetValue ( hKey2 , " " , REG_SZ , tmp , strlen ( tmp ) ) ;
smprintf ( tmp , 512 , " %s,%d " , icon , iconIndex ) ;
tstring ttmp = utf8ToTStr ( tmp ) ;
RegSetValue ( hKey2 , _T ( " " ) , REG_SZ , ttmp . c_str ( ) , ( ttmp . size ( ) + 1 ) * sizeof ( TCHAR ) ) ;
}
// Create the shell/open/command
if ( RegCreateKey ( hKey , " shell " , & hKey ) = = ERROR_SUCCESS )
if ( RegCreateKey ( hKey , _T ( " shell " ) , & hKey ) = = ERROR_SUCCESS )
{
if ( RegCreateKey ( hKey , " open " , & hKey ) = = ERROR_SUCCESS )
if ( RegCreateKey ( hKey , _T ( " open " ) , & hKey ) = = ERROR_SUCCESS )
{
if ( RegCreateKey ( hKey , " command " , & hKey ) = = ERROR_SUCCESS )
if ( RegCreateKey ( hKey , _T ( " command " ) , & hKey ) = = ERROR_SUCCESS )
{
// Set the description
string tmp = string ( icon ) + " \" %1 \" " ;
RegSetValue ( hKey , " " , REG_SZ , tmp . c_str ( ) , tmp . size ( ) ) ;
string tmp = string ( icon ) + " \" %1 \" " ;
tstring ttmp = utf8ToTStr ( tmp ) ;
RegSetValue ( hKey , _T ( " " ) , REG_SZ , ttmp . c_str ( ) , ( ttmp . size ( ) + 1 ) * sizeof ( TCHAR ) ) ;
}
}
}
@ -75,43 +78,44 @@ bool RegisterApp (const char *appName, const char *appDescription, const char *i
}
// Unregister an application
bool UnregisterApp ( const char * appName )
bool UnregisterApp ( const char * appName )
{
// Delete the app key
deleteKey ( HKEY_CLASSES_ROOT , appName) ;
deleteKey ( HKEY_CLASSES_ROOT , nlUtf8ToTStr( appName) ) ;
return true ;
}
// Unregister an application command
bool UnregisterAppCommand ( const char * appName , const char * command )
bool UnregisterAppCommand ( const char * appName , const char * command )
{
// Create the app key
HKEY hKey ;
if ( RegOpenKey ( HKEY_CLASSES_ROOT , appName, & hKey ) = = ERROR_SUCCESS )
if ( RegOpenKey ( HKEY_CLASSES_ROOT , nlUtf8ToTStr( appName) , & hKey ) = = ERROR_SUCCESS )
{
// Create the icon
char tmp [ 512 ] ;
smprintf ( tmp , 512 , " shell \\ %s " , command ) ;
deleteKey ( hKey , tmp) ;
smprintf ( tmp , 512 , " shell \\ %s " , command ) ;
deleteKey ( hKey , nlUtf8ToTStr( tmp) ) ;
return true ;
}
return false ;
}
// Register an application command
bool RegisterAppCommand ( const char * appName , const char * command , const char * app )
bool RegisterAppCommand ( const char * appName , const char * command , const char * app )
{
// Create the app key
HKEY hKey ;
if ( RegCreateKey ( HKEY_CLASSES_ROOT , appName, & hKey ) = = ERROR_SUCCESS )
if ( RegCreateKey ( HKEY_CLASSES_ROOT , nlUtf8ToTStr( appName) , & hKey ) = = ERROR_SUCCESS )
{
// Create the icon
char tmp [ 512 ] ;
smprintf ( tmp , 512 , " shell \\ %s \\ command " , command ) ;
if ( RegCreateKey ( hKey , tmp, & hKey ) = = ERROR_SUCCESS )
smprintf ( tmp , 512 , " shell \\ %s \\ command " , command ) ;
if ( RegCreateKey ( hKey , nlUtf8ToTStr( tmp) , & hKey ) = = ERROR_SUCCESS )
{
// Set the description
RegSetValue ( hKey , " " , REG_SZ , app , strlen ( app ) ) ;
tstring tapp = utf8ToTStr ( app ) ;
RegSetValue ( hKey , _T ( " " ) , REG_SZ , tapp . c_str ( ) , ( tapp . size ( ) + 1 ) * sizeof ( TCHAR ) ) ;
}
return true ;
}
@ -119,41 +123,43 @@ bool RegisterAppCommand (const char *appName, const char *command, const char *a
}
// Unregister an application DDE command
bool UnregisterDDECommand ( const char * appName , const char * command )
bool UnregisterDDECommand ( const char * appName , const char * command )
{
// Create the app key
HKEY hKey ;
if ( RegOpenKey ( HKEY_CLASSES_ROOT , appName, & hKey ) = = ERROR_SUCCESS )
if ( RegOpenKey ( HKEY_CLASSES_ROOT , nlUtf8ToTStr( appName) , & hKey ) = = ERROR_SUCCESS )
{
// Create the icon
char tmp [ 512 ] ;
smprintf ( tmp , 512 , " shell \\ %s \\ ddeexec " , command ) ;
deleteKey ( hKey , tmp) ;
smprintf ( tmp , 512 , " shell \\ %s \\ ddeexec " , command ) ;
deleteKey ( hKey , nlUtf8ToTStr( tmp) ) ;
}
return false ;
}
// Register an application DDE command
bool RegisterDDECommand ( const char * appName , const char * command , const char * ddeCommand , const char * application )
bool RegisterDDECommand ( const char * appName , const char * command , const char * ddeCommand , const char * application )
{
// Create the app key
HKEY hKey ;
if ( RegCreateKey ( HKEY_CLASSES_ROOT , appName, & hKey ) = = ERROR_SUCCESS )
if ( RegCreateKey ( HKEY_CLASSES_ROOT , nlUtf8ToTStr( appName) , & hKey ) = = ERROR_SUCCESS )
{
// Create the icon
char tmp [ 512 ] ;
smprintf ( tmp , 512 , " shell \\ %s \\ ddeexec " , command ) ;
if ( RegCreateKey ( hKey , tmp, & hKey ) = = ERROR_SUCCESS )
smprintf ( tmp , 512 , " shell \\ %s \\ ddeexec " , command ) ;
if ( RegCreateKey ( hKey , nlUtf8ToTStr( tmp) , & hKey ) = = ERROR_SUCCESS )
{
// Set the description
RegSetValue ( hKey , " " , REG_SZ , ddeCommand , strlen ( ddeCommand ) ) ;
tstring tddeCommand = utf8ToTStr ( ddeCommand ) ;
RegSetValue ( hKey , _T ( " " ) , REG_SZ , tddeCommand . c_str ( ) , ( tddeCommand . size ( ) + 1 ) * sizeof ( TCHAR ) ) ;
HKEY hKey2 ;
if ( RegCreateKey ( hKey , " application " , & hKey2 ) = = ERROR_SUCCESS )
if ( RegCreateKey ( hKey , _T ( " application " ) , & hKey2 ) = = ERROR_SUCCESS )
{
RegSetValue ( hKey2 , " " , REG_SZ , application , strlen ( application ) ) ;
if ( RegCreateKey ( hKey , " topic " , & hKey2 ) = = ERROR_SUCCESS )
tstring tapplication = utf8ToTStr ( application ) ;
RegSetValue ( hKey2 , _T ( " " ) , REG_SZ , tapplication . c_str ( ) , ( tapplication . size ( ) + 1 ) * sizeof ( TCHAR ) ) ;
if ( RegCreateKey ( hKey , _T ( " topic " ) , & hKey2 ) = = ERROR_SUCCESS )
{
RegSetValue ( hKey2 , " " , REG_SZ , " system " , strlen ( " system " ) ) ;
RegSetValue ( hKey2 , _T ( " " ) , REG_SZ , _T ( " system " ) , ( strlen ( " system " ) + 1 ) * sizeof ( TCHAR ) ) ;
return true ;
}
}
@ -163,28 +169,29 @@ bool RegisterDDECommand (const char *appName, const char *command, const char *d
}
// Register a file extension
bool RegisterShellFileExt ( const char * ext , const char * appName )
bool RegisterShellFileExt ( const char * ext , const char * appName )
{
// Remove key in explorer registry if exist
HKEY hKey ;
string key = " Software \\ Microsoft \\ Windows \\ CurrentVersion \\ Explorer \\ FileExts \\ " + string ( ext ) ;
deleteKey ( HKEY_CURRENT_USER , key . c_str ( ) ) ;
string key = " Software \\ Microsoft \\ Windows \\ CurrentVersion \\ Explorer \\ FileExts \\ " + string ( ext ) ;
deleteKey ( HKEY_CURRENT_USER , nlUtf8ToTStr ( key ) ) ;
// Create the app key
if ( RegCreateKey ( HKEY_CLASSES_ROOT , ext, & hKey ) = = ERROR_SUCCESS )
if ( RegCreateKey ( HKEY_CLASSES_ROOT , nlUtf8ToTStr( ext) , & hKey ) = = ERROR_SUCCESS )
{
// Set the description
RegSetValue ( hKey , " " , REG_SZ , appName , strlen ( appName ) ) ;
tstring tAppName = utf8ToTStr ( appName ) ;
RegSetValue ( hKey , _T ( " " ) , REG_SZ , tAppName . c_str ( ) , ( tAppName . size ( ) + 1 ) * sizeof ( TCHAR ) ) ;
return true ;
}
return false ;
}
// Register a file extension
bool UnregisterShellFileExt ( const char * ext )
bool UnregisterShellFileExt ( const char * ext )
{
// Delete the app key
if ( RegDeleteKey ( HKEY_CLASSES_ROOT , ext) = = ERROR_SUCCESS )
if ( RegDeleteKey ( HKEY_CLASSES_ROOT , nlUtf8ToTStr( ext) ) = = ERROR_SUCCESS )
{
return true ;
}