bug 341006 Close registry keys that are opened, and don't check rc twice

r+sr=neil
This commit is contained in:
cbiesinger%web.de 2006-06-10 14:17:23 +00:00
Родитель d25fff9774
Коммит 1ed0be95fd
1 изменённых файлов: 72 добавлений и 72 удалений

Просмотреть файл

@ -219,80 +219,79 @@ static void setWindowsXP() {
// set registered as "Start Menu internet apps." These entries go
// under the subkey MOZILLA.EXE (or whatever the name of this executable is),
// that subkey name is generated by the utility function shortAppName.
if ( rc == ERROR_SUCCESS ) {
// The next 3 go under this subkey.
nsCAutoString subkey( baseKey + NS_LITERAL_CSTRING( "\\" ) + shortAppName() );
// Pretty name. This goes into the LocalizedString value. It is the
// name of the executable (preceded by '@'), followed by ",-nnn" where
// nnn is the resource identifier of the string in the .exe. That value
// comes from nsINativeAppSupportWin.h.
char buffer[ _MAX_PATH + 8 ]; // Path, plus '@', comma, minus, and digits (5)
_snprintf( buffer, sizeof buffer, "@%s,-%d", thisApplication().get(), IDS_STARTMENU_APPNAME );
RegistryEntry tmp_entry1( HKEY_LOCAL_MACHINE,
subkey.get(),
"LocalizedString",
buffer );
tmp_entry1.set();
// Default icon (from .exe resource).
RegistryEntry tmp_entry2( HKEY_LOCAL_MACHINE,
nsCAutoString( subkey + NS_LITERAL_CSTRING( "\\DefaultIcon" ) ).get(),
::RegCloseKey(key);
// The next 3 go under this subkey.
nsCAutoString subkey( baseKey + NS_LITERAL_CSTRING( "\\" ) + shortAppName() );
// Pretty name. This goes into the LocalizedString value. It is the
// name of the executable (preceded by '@'), followed by ",-nnn" where
// nnn is the resource identifier of the string in the .exe. That value
// comes from nsINativeAppSupportWin.h.
char buffer[ _MAX_PATH + 8 ]; // Path, plus '@', comma, minus, and digits (5)
_snprintf( buffer, sizeof buffer, "@%s,-%d", thisApplication().get(), IDS_STARTMENU_APPNAME );
RegistryEntry tmp_entry1( HKEY_LOCAL_MACHINE,
subkey.get(),
"LocalizedString",
buffer );
tmp_entry1.set();
// Default icon (from .exe resource).
RegistryEntry tmp_entry2( HKEY_LOCAL_MACHINE,
nsCAutoString( subkey + NS_LITERAL_CSTRING( "\\DefaultIcon" ) ).get(),
"",
nsCAutoString( thisApplication() + NS_LITERAL_CSTRING( ",0" ) ).get() );
tmp_entry2.set();
// Command to open.
RegistryEntry tmp_entry3( HKEY_LOCAL_MACHINE,
nsCAutoString( subkey + NS_LITERAL_CSTRING( "\\shell\\open\\command" ) ).get(),
"",
thisApplication().get() );
tmp_entry3.set();
// "Properties" verb. The default value is the text that will appear in the menu.
// The default value under the command subkey is the name of this application, with
// arguments to cause the Preferences window to appear.
nsCOMPtr<nsIStringBundleService> bundleService( do_GetService( "@mozilla.org/intl/stringbundle;1" ) );
nsCOMPtr<nsIStringBundle> bundle;
nsXPIDLString label;
if ( bundleService &&
NS_SUCCEEDED( bundleService->CreateBundle( "chrome://global-platform/locale/nsWindowsHooks.properties",
getter_AddRefs( bundle ) ) ) &&
NS_SUCCEEDED( bundle->GetStringFromName( NS_LITERAL_STRING( "prefsLabel" ).get(), getter_Copies( label ) ) ) ) {
// Set the label that will appear in the start menu context menu.
RegistryEntry tmp_entry4( HKEY_LOCAL_MACHINE,
nsCAutoString( subkey + NS_LITERAL_CSTRING( "\\shell\\properties" ) ).get(),
"",
nsCAutoString( thisApplication() + NS_LITERAL_CSTRING( ",0" ) ).get() );
tmp_entry2.set();
// Command to open.
RegistryEntry tmp_entry3( HKEY_LOCAL_MACHINE,
nsCAutoString( subkey + NS_LITERAL_CSTRING( "\\shell\\open\\command" ) ).get(),
"",
thisApplication().get() );
tmp_entry3.set();
// "Properties" verb. The default value is the text that will appear in the menu.
// The default value under the command subkey is the name of this application, with
// arguments to cause the Preferences window to appear.
nsCOMPtr<nsIStringBundleService> bundleService( do_GetService( "@mozilla.org/intl/stringbundle;1" ) );
nsCOMPtr<nsIStringBundle> bundle;
nsXPIDLString label;
if ( bundleService &&
NS_SUCCEEDED( bundleService->CreateBundle( "chrome://global-platform/locale/nsWindowsHooks.properties",
getter_AddRefs( bundle ) ) ) &&
NS_SUCCEEDED( bundle->GetStringFromName( NS_LITERAL_STRING( "prefsLabel" ).get(), getter_Copies( label ) ) ) ) {
// Set the label that will appear in the start menu context menu.
RegistryEntry tmp_entry4( HKEY_LOCAL_MACHINE,
nsCAutoString( subkey + NS_LITERAL_CSTRING( "\\shell\\properties" ) ).get(),
"",
NS_ConvertUTF16toUTF8( label ).get() );
tmp_entry4.set();
}
RegistryEntry tmp_entry5( HKEY_LOCAL_MACHINE,
nsCAutoString( subkey + NS_LITERAL_CSTRING( "\\shell\\properties\\command" ) ).get(),
"", nsCAutoString( thisApplication() +
NS_LITERAL_CSTRING(" -chrome \"chrome://communicator/content/pref/pref.xul\"") ).get()
);
tmp_entry5.set();
// Now we need to select our application as the default start menu internet application.
// This is accomplished by first trying to store our subkey name in
// HKLM\Software\Clients\StartMenuInternet's default value. See
// http://support.microsoft.com/directory/article.asp?ID=KB;EN-US;Q297878 for detail.
SavedRegistryEntry hklmAppEntry( HKEY_LOCAL_MACHINE, baseKey.get(), "", shortAppName().get() );
hklmAppEntry.set();
// That may or may not have worked (depending on whether we have sufficient access).
if ( hklmAppEntry.currentSetting() == hklmAppEntry.setting ) {
// We've set the hklm entry, so we can delete the one under hkcu.
SavedRegistryEntry tmp_entry6( HKEY_CURRENT_USER, baseKey.get(), "", 0 );
tmp_entry6.set();
} else {
// All we can do is set the default start menu internet app for this user.
SavedRegistryEntry tmp_entry7( HKEY_CURRENT_USER, baseKey.get(), "", shortAppName().get() );
}
// Notify the system of the changes.
::SendMessageTimeout( HWND_BROADCAST,
WM_SETTINGCHANGE,
0,
(LPARAM)MOZ_CLIENT_BROWSER_KEY,
SMTO_NORMAL|SMTO_ABORTIFHUNG,
MOZ_HWND_BROADCAST_MSG_TIMEOUT,
NULL);
NS_ConvertUTF16toUTF8( label ).get() );
tmp_entry4.set();
}
RegistryEntry tmp_entry5( HKEY_LOCAL_MACHINE,
nsCAutoString( subkey + NS_LITERAL_CSTRING( "\\shell\\properties\\command" ) ).get(),
"", nsCAutoString( thisApplication() +
NS_LITERAL_CSTRING(" -chrome \"chrome://communicator/content/pref/pref.xul\"") ).get()
);
tmp_entry5.set();
// Now we need to select our application as the default start menu internet application.
// This is accomplished by first trying to store our subkey name in
// HKLM\Software\Clients\StartMenuInternet's default value. See
// http://support.microsoft.com/directory/article.asp?ID=KB;EN-US;Q297878 for detail.
SavedRegistryEntry hklmAppEntry( HKEY_LOCAL_MACHINE, baseKey.get(), "", shortAppName().get() );
hklmAppEntry.set();
// That may or may not have worked (depending on whether we have sufficient access).
if ( hklmAppEntry.currentSetting() == hklmAppEntry.setting ) {
// We've set the hklm entry, so we can delete the one under hkcu.
SavedRegistryEntry tmp_entry6( HKEY_CURRENT_USER, baseKey.get(), "", 0 );
tmp_entry6.set();
} else {
// All we can do is set the default start menu internet app for this user.
SavedRegistryEntry tmp_entry7( HKEY_CURRENT_USER, baseKey.get(), "", shortAppName().get() );
}
// Notify the system of the changes.
::SendMessageTimeout( HWND_BROADCAST,
WM_SETTINGCHANGE,
0,
(LPARAM)MOZ_CLIENT_BROWSER_KEY,
SMTO_NORMAL|SMTO_ABORTIFHUNG,
MOZ_HWND_BROADCAST_MSG_TIMEOUT,
NULL);
}
}
@ -324,6 +323,7 @@ nsresult RegistryEntry::reset() {
LONG rc = ::RegOpenKey( baseKey, keyName.get(), &key );
if ( rc == ERROR_SUCCESS ) {
rc = ::RegDeleteValue( key, valueNameArg() );
::RegCloseKey(key);
#ifdef DEBUG_law
if ( rc == ERROR_SUCCESS ) printf( "Deleting key=%s\n", (const char*)fullName().get() );
#endif