102600 r=curt sr=dveditz a=rjesup@wgate.com adt1.0.0
add winreg.enumKeys and winreg.enumValueNames to nsInstall git-svn-id: svn://10.0.0.236/trunk@118336 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
parent
b6c7fd58ec
commit
bbae75d397
@ -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}
|
||||
};
|
||||
|
||||
|
||||
@ -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)
|
||||
{
|
||||
|
||||
@ -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);
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user