diff --git a/mozilla/xpinstall/src/nsJSWinReg.cpp b/mozilla/xpinstall/src/nsJSWinReg.cpp index 8fd21127690..82e19f542dd 100644 --- a/mozilla/xpinstall/src/nsJSWinReg.cpp +++ b/mozilla/xpinstall/src/nsJSWinReg.cpp @@ -455,6 +455,100 @@ WinRegGetValueString(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsva return JS_TRUE; } +// +// Native method enumValueNames +// +PR_STATIC_CALLBACK(JSBool) +WinRegEnumValueNames(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsWinReg* nativeThis = (nsWinReg*)JS_GetPrivate(cx, obj); + nsAutoString nativeRet; + nsAutoString b0; + int32 b1; + + *rval = JSVAL_NULL; + + // If there's no private data, this must be the prototype, so ignore + if(nsnull == nativeThis) + { + return JS_TRUE; + } + + if(argc >= 2) + { + // public String enumValueNames ( String subkey, + // Int index); + + ConvertJSValToStr(b0, cx, argv[0]); + + if(JS_ValueToInt32(cx, argv[1], &b1)) + { + if ( NS_OK == nativeThis->EnumValueNames(b0, b1, nativeRet) ) + { + ConvertStrToJSVal(nativeRet, cx, rval); + } + } + else + { + JS_ReportWarning(cx, "WinReg.enumValueNames - Parameter 2 must be a number"); + } + } + else + { + JS_ReportWarning(cx, "WinReg.enumValueNames() - Too few parameters"); + } + + return JS_TRUE; +} + + +// +// Native method enumKeys +// +PR_STATIC_CALLBACK(JSBool) +WinRegEnumKeys(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsWinReg* nativeThis = (nsWinReg*)JS_GetPrivate(cx, obj); + nsAutoString nativeRet; + nsAutoString b0; + int32 b1; + + *rval = JSVAL_NULL; + + // If there's no private data, this must be the prototype, so ignore + if(nsnull == nativeThis) + { + return JS_TRUE; + } + + if(argc >= 2) + { + // public String enumKeys ( String subkey, + // Int index); + + ConvertJSValToStr(b0, cx, argv[0]); + + if(JS_ValueToInt32(cx, argv[1], &b1)) + { + if ( NS_OK == nativeThis->EnumKeys(b0, b1, nativeRet) ) + { + ConvertStrToJSVal(nativeRet, cx, rval); + } + } + else + { + JS_ReportWarning(cx, "WinReg.enumKeys() - Parameter 2 must be a number"); + } + } + else + { + JS_ReportWarning(cx, "WinReg.enumKeys() - Too few parameters"); + } + + return JS_TRUE; +} + + // // Native method SetValueNumber // @@ -700,6 +794,8 @@ static JSFunctionSpec WinRegMethods[] = {"getValueNumber", WinRegGetValueNumber, 2}, {"setValue", WinRegSetValue, 3}, {"getValue", WinRegGetValue, 2}, + {"enumKeys", WinRegEnumKeys, 2}, + {"enumValueNames", WinRegEnumValueNames, 2}, {0} }; diff --git a/mozilla/xpinstall/src/nsWinReg.cpp b/mozilla/xpinstall/src/nsWinReg.cpp index 0fa12fafee2..3075bf7b697 100644 --- a/mozilla/xpinstall/src/nsWinReg.cpp +++ b/mozilla/xpinstall/src/nsWinReg.cpp @@ -175,6 +175,84 @@ nsWinReg::GetValueString(const nsString& subkey, const nsString& valname, nsStri return NS_OK; } +PRInt32 +nsWinReg::EnumValueNames(const nsString& aSubkey, PRInt32 aIndex, nsString &aReturn) +{ + char namebuf[MAX_BUF]; + HKEY root; + HKEY newkey; + LONG result; + DWORD namesize = sizeof(namebuf); + char subkeyCString[MAX_BUF]; + unsigned short returnBuf[MAX_BUF]; + PRInt32 rv = NS_ERROR_FAILURE; + + subkeyCString[0] = 0; + returnBuf[0] = 0; + namebuf[0] = 0; + + ::WideCharToMultiByte(CP_ACP, 0, + aSubkey.get(), -1, + subkeyCString, sizeof subkeyCString, NULL, NULL); + + root = (HKEY) mRootKey; + result = RegOpenKeyEx( root, subkeyCString, 0, KEY_READ, &newkey ); + + if ( ERROR_SUCCESS == result ) { + result = RegEnumValue( newkey, aIndex, namebuf, &namesize, nsnull, 0, 0, 0 ); + RegCloseKey( newkey ); + + if ( ERROR_SUCCESS == result ) { + if ( ::MultiByteToWideChar(CP_ACP, 0, namebuf, -1, returnBuf, MAX_BUF) ) + { + aReturn.Assign(returnBuf); + rv = NS_OK; + } + } + } + + return rv; +} + +PRInt32 +nsWinReg::EnumKeys(const nsString& aSubkey, PRInt32 aIndex, nsString &aReturn) +{ + char keybuf[MAX_BUF]; + HKEY root; + HKEY newkey; + LONG result; + DWORD type = REG_SZ; + char subkeyCString[MAX_BUF]; + unsigned short returnBuf[MAX_BUF]; + PRInt32 rv = NS_ERROR_FAILURE; + + subkeyCString[0] = 0; + returnBuf[0] = 0; + keybuf[0] = 0; + + ::WideCharToMultiByte(CP_ACP, 0, + aSubkey.get(), -1, + subkeyCString, sizeof subkeyCString, NULL, NULL); + + root = (HKEY) mRootKey; + result = RegOpenKeyEx( root, subkeyCString, 0, KEY_READ, &newkey ); + + if ( ERROR_SUCCESS == result ) { + result = RegEnumKey( newkey, aIndex, keybuf, sizeof keybuf ); + RegCloseKey( newkey ); + + if ( ERROR_SUCCESS == result ) { + if ( ::MultiByteToWideChar(CP_ACP, 0, keybuf, -1, returnBuf, MAX_BUF) ) + { + aReturn.Assign(returnBuf); + rv = NS_OK; + } + } + } + + return rv; +} + PRInt32 nsWinReg::SetValueNumber(const nsString& subkey, const nsString& valname, PRInt32 value, PRInt32* aReturn) { diff --git a/mozilla/xpinstall/src/nsWinReg.h b/mozilla/xpinstall/src/nsWinReg.h index be9e6d016a9..3f8972c6407 100644 --- a/mozilla/xpinstall/src/nsWinReg.h +++ b/mozilla/xpinstall/src/nsWinReg.h @@ -59,6 +59,11 @@ #include "nsInstall.h" #define _MAXKEYVALUE_ 8196 + +#ifndef MAX_BUF +#define MAX_BUF 4096 +#endif + class nsWinReg { public: @@ -88,6 +93,8 @@ class nsWinReg PRInt32 GetValueNumber(const nsString& subkey, const nsString& valname, PRInt32* aReturn); PRInt32 SetValue(const nsString& subkey, const nsString& valname, nsWinRegValue* value, PRInt32* aReturn); PRInt32 GetValue(const nsString& subkey, const nsString& valname, nsWinRegValue** aReturn); + PRInt32 EnumValueNames(const nsString& keyname, PRInt32 index, nsString &aReturn); + PRInt32 EnumKeys(const nsString& keyname, PRInt32 index, nsString &aReturn); nsInstall* InstallObject(void);