if ( rc == ERROR_FILE_NOT_FOUND ) { rc = ::RegCreateKey( baseKey, keyName.get(), &key ); } if ( rc == ERROR_SUCCESS ) { if ( isNull && setting.IsEmpty() ) {   rc = ::RegDeleteValue( key, valueNameArg() ); if ( rc == ERROR_SUCCESS ) { result = NS_OK; } } else { NS_ConvertUTF8toUTF16 utf16Setting(setting); if (!IsNT()) {  char buffer[4096] = { 0 }; DWORD len = sizeof buffer; rc = ::RegQueryValueExA( key, valueNameArg(), NULL, NULL, (LPBYTE)buffer, &len ); nsCAutoString cSetting; NS_CopyUnicodeToNative(utf16Setting, cSetting); if ( rc != ERROR_SUCCESS || !cSetting.Equals(buffer)) { rc = ::RegSetValueExA( key, valueNameArg(), 0, REG_SZ, (LPBYTE)cSetting.get(), cSetting.Length() ); #ifdef DEBUG_law NS_WARN_IF_FALSE( rc == ERROR_SUCCESS, fullName().get() ); #endif if ( rc == ERROR_SUCCESS ) { result = NS_OK; } } else {  result = NS_OK; } } else {  PRUnichar buffer[4096] = { 0 }; DWORD len = sizeof buffer; NS_ConvertASCIItoUTF16 wValueName(valueNameArg()); rc = ::RegQueryValueExW( key, wValueName.get(), NULL, NULL, (LPBYTE)buffer, &len ); if ( rc != ERROR_SUCCESS || !utf16Setting.Equals(buffer) ) { rc = ::RegSetValueExW( key, wValueName.get(), 0, REG_SZ, (LPBYTE) (utf16Setting.get()), utf16Setting.Length() * 2); if ( rc == ERROR_SUCCESS ) { result = NS_OK; } } else {  result = NS_OK; } } } ::RegCloseKey( key ); } else { #ifdef DEBUG_law NS_WARN_IF_FALSE( rc == ERROR_SUCCESS, fullName().get() ); #endif } return result;
DDERegistryEntry( protocol.get() ).set();  ProtocolIconRegistryEntry( protocol.get() ).set();  return rv;
nsresult RegistryEntry::set() {#ifdef DEBUG_lawif ( isNull && setting.IsEmpty() ) printf( "Deleting %s\n", fullName().get() );else printf( "Setting %s=%s\n", fullName().get(), setting.get() );#endif    nsresult result = NS_ERROR_FAILURE;    HKEY   key;    LONG   rc = ::RegOpenKey( baseKey, keyName.get(), &key );    // See if key doesn't exist yet...    if ( rc == ERROR_FILE_NOT_FOUND ) {        rc = ::RegCreateKey( baseKey, keyName.get(), &key );    }    if ( rc == ERROR_SUCCESS ) {        if ( isNull && setting.IsEmpty() ) {            // This means we need to actually remove the value, not merely set it to an            // empty string.            rc = ::RegDeleteValue( key, valueNameArg() );            if ( rc == ERROR_SUCCESS ) {                result = NS_OK;            }        } else {            NS_ConvertUTF8toUTF16 utf16Setting(setting);            if (!IsNT()) {                // Get current value to see if it is set properly already.               char buffer[4096] = { 0 };               DWORD len = sizeof buffer;               rc = ::RegQueryValueExA( key, valueNameArg(), NULL, NULL,                    (LPBYTE)buffer, &len );               nsCAutoString cSetting;               NS_CopyUnicodeToNative(utf16Setting, cSetting);               if ( rc != ERROR_SUCCESS || !cSetting.Equals(buffer)) {                   rc = ::RegSetValueExA( key, valueNameArg(), 0, REG_SZ,                        (LPBYTE)cSetting.get(), cSetting.Length() );#ifdef DEBUG_law                   NS_WARN_IF_FALSE( rc == ERROR_SUCCESS, fullName().get() );#endif                   if ( rc == ERROR_SUCCESS ) {                      result = NS_OK;                   }               } else {                   // Already has desired setting.                   result = NS_OK;               }           } else {                // Get current value to see if it is set properly already.               PRUnichar buffer[4096] = { 0 };               DWORD len = sizeof buffer;               NS_ConvertASCIItoUTF16 wValueName(valueNameArg());               rc = ::RegQueryValueExW( key, wValueName.get(), NULL,                    NULL, (LPBYTE)buffer, &len );               if ( rc != ERROR_SUCCESS || !utf16Setting.Equals(buffer) ) {                   rc = ::RegSetValueExW( key, wValueName.get(), 0, REG_SZ,                        (LPBYTE) (utf16Setting.get()),                        utf16Setting.Length() * 2);                   if ( rc == ERROR_SUCCESS ) {                      result = NS_OK;                   }               } else {                   // Already has desired setting.                   result = NS_OK;               }           }  // NT        }        ::RegCloseKey( key );    } else {#ifdef DEBUG_lawNS_WARN_IF_FALSE( rc == ERROR_SUCCESS, fullName().get() );#endif    }    return result;}