зеркало из https://github.com/mozilla/gecko-dev.git
Ported Java to C++ src files
This commit is contained in:
Родитель
fc48b58ad2
Коммит
0e053148eb
|
@ -17,8 +17,107 @@
|
|||
*/
|
||||
|
||||
#include "nsWinProfile.h"
|
||||
#include "nsWinProfileItem.h"
|
||||
#include "xp.h"
|
||||
#include "xp_str.h"
|
||||
|
||||
PR_BEGIN_EXTERN_C
|
||||
|
||||
/* Public Methods */
|
||||
|
||||
nsWinProfile::nsWinProfile( nsSoftwareUpdate* suObj, nsFolderSpec* folder, char* file )
|
||||
{
|
||||
filename = folder->MakeFullPath(file, NULL); /* can I pass NULL here? */
|
||||
su = suObj;
|
||||
principal = suObj->GetPrincipal();
|
||||
privMgr = nsPrivilegeManager::getPrivilegeManager();
|
||||
impersonation = nsTarget::findTarget(IMPERSONATOR);
|
||||
target = (nsUserTarget*)nsTarget::findTarget(INSTALL_PRIV);
|
||||
}
|
||||
|
||||
PRBool nsWinProfile::writeString( char* section, char* key, char* value )
|
||||
{
|
||||
if(resolvePrivileges())
|
||||
{
|
||||
nsWinProfileItem* wi = new nsWinProfileItem(this, section, key, value);
|
||||
if(wi == NULL)
|
||||
return FALSE;
|
||||
su->ScheduleForInstall(wi);
|
||||
return TRUE;
|
||||
}
|
||||
else
|
||||
return FALSE;
|
||||
|
||||
}
|
||||
|
||||
char* nsWinProfile::getString( char* section, char* key )
|
||||
{
|
||||
if(resolvePrivileges())
|
||||
{
|
||||
return nativeGetString(section, key);
|
||||
}
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char* nsWinProfile::getFilename()
|
||||
{
|
||||
return filename;
|
||||
}
|
||||
|
||||
nsSoftwareUpdate* nsWinProfile::softUpdate()
|
||||
{
|
||||
return su;
|
||||
}
|
||||
|
||||
int nsWinProfile::finalWriteString( char* section, char* key, char* value )
|
||||
{
|
||||
/* do we need another security check here? */
|
||||
return nativeWriteString(section, key, value);
|
||||
}
|
||||
|
||||
/* Private Methods */
|
||||
|
||||
int nsWinProfile::nativeWriteString( char* section, char* key, char* value )
|
||||
{
|
||||
int success = 0;
|
||||
|
||||
/* make sure conversions worked */
|
||||
if ( section != NULL && key != NULL && filename != NULL )
|
||||
success = WritePrivateProfileString( section, key, value, filename );
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
#define STRBUFLEN 255
|
||||
|
||||
char* nsWinProfile::nativeGetString( char* section, char* key )
|
||||
{
|
||||
int numChars;
|
||||
char valbuf[STRBUFLEN];
|
||||
char* value = NULL;
|
||||
|
||||
/* make sure conversions worked */
|
||||
if ( section != NULL && key != NULL && filename != NULL ) {
|
||||
numChars = GetPrivateProfileString( section, key, "",
|
||||
valbuf, STRBUFLEN, filename );
|
||||
|
||||
/* if the value fit in the buffer */
|
||||
if ( numChars < STRBUFLEN ) {
|
||||
value = XP_STRDUP(valbuf);
|
||||
}
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
PRBool nsWinProfile::resolvePrivileges()
|
||||
{
|
||||
if(privMgr->enablePrivilege(impersonation, 1) &&
|
||||
privMgr->enablePrivilege(target, principal, 1))
|
||||
return TRUE;
|
||||
else
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
PR_END_EXTERN_C
|
||||
|
|
|
@ -17,8 +17,64 @@
|
|||
*/
|
||||
|
||||
#include "nsWinProfileItem.h"
|
||||
#include "xp.h"
|
||||
#include "xp_str.h"
|
||||
|
||||
PR_BEGIN_EXTERN_C
|
||||
|
||||
/* Public Methods */
|
||||
|
||||
nsWinProfileItem::nsWinProfileItem(nsWinProfile* profileObj,
|
||||
char* sectionName, char* keyName,
|
||||
char* val) : nsInstallObject(profileObj->softUpdate())
|
||||
{
|
||||
profile = profileObj;
|
||||
section = XP_STRDUP(sectionName);
|
||||
key = XP_STRDUP(keyName);
|
||||
value = XP_STRDUP(val);
|
||||
}
|
||||
|
||||
char* nsWinProfileItem::Complete()
|
||||
{
|
||||
profile->finalWriteString(section, key, value);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
float nsWinProfileItem::GetInstallOrder()
|
||||
{
|
||||
return 4;
|
||||
}
|
||||
|
||||
char* nsWinProfileItem::toString()
|
||||
{
|
||||
PRInt32 len;
|
||||
char* result;
|
||||
char* filename = profile->getFilename();
|
||||
|
||||
len = XP_STRLEN("Write ") + XP_STRLEN(filename) +
|
||||
XP_STRLEN(": [") + XP_STRLEN(section) + XP_STRLEN("] ") +
|
||||
XP_STRLEN(key) + XP_STRLEN("=") + XP_STRLEN(value);
|
||||
|
||||
result = (char*)XP_ALLOC((len+1)*sizeof(char));
|
||||
XP_STRCAT(result, "Write ");
|
||||
XP_STRCAT(result, filename);
|
||||
XP_STRCAT(result, ": [");
|
||||
XP_STRCAT(result, section);
|
||||
XP_STRCAT(result, "] ");
|
||||
XP_STRCAT(result, key);
|
||||
XP_STRCAT(result, "=");
|
||||
XP_STRCAT(result, value);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void nsWinProfileItem::Abort()
|
||||
{
|
||||
}
|
||||
|
||||
char* nsWinProfileItem::Prepare()
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
PR_END_EXTERN_C
|
||||
|
|
|
@ -17,8 +17,330 @@
|
|||
*/
|
||||
|
||||
#include "nsWinReg.h"
|
||||
#include "nsWinRegItem.h"
|
||||
#include <windows.h> /* is this needed? */
|
||||
#include "xp.h"
|
||||
#include "xp_str.h"
|
||||
|
||||
PR_BEGIN_EXTERN_C
|
||||
|
||||
/* Public Methods */
|
||||
|
||||
nsWinReg::nsWinReg(nsSoftwareUpdate* suObj)
|
||||
{
|
||||
su = suObj;
|
||||
principal = suObj->GetPrincipal();
|
||||
privMgr = nsPrivilegeManager::getPrivilegeManager();
|
||||
impersonation = nsTarget::findTarget(IMPERSONATOR);
|
||||
target = (nsUserTarget*)nsTarget::findTarget(INSTALL_PRIV);
|
||||
}
|
||||
|
||||
void nsWinReg::setRootKey(PRInt32 key)
|
||||
{
|
||||
rootkey = key;
|
||||
}
|
||||
|
||||
PRInt32 nsWinReg::createKey(char* subkey, char* classname)
|
||||
{
|
||||
resolvePrivileges();
|
||||
|
||||
nsWinRegItem* wi = new nsWinRegItem(this, rootkey, NS_WIN_REG_CREATE, subkey, classname, NULL);
|
||||
if(wi == NULL)
|
||||
return (-1);
|
||||
su->ScheduleForInstall(wi);
|
||||
return 0;
|
||||
}
|
||||
|
||||
PRInt32 nsWinReg::deleteKey(char* subkey)
|
||||
{
|
||||
resolvePrivileges();
|
||||
|
||||
nsWinRegItem* wi = new nsWinRegItem(this, rootkey, NS_WIN_REG_DELETE, subkey, NULL, NULL);
|
||||
if(wi == NULL)
|
||||
return (-1);
|
||||
su->ScheduleForInstall(wi);
|
||||
return 0;
|
||||
}
|
||||
|
||||
PRInt32 nsWinReg::deleteValue(char* subkey, char* valname)
|
||||
{
|
||||
resolvePrivileges();
|
||||
|
||||
nsWinRegItem* wi = new nsWinRegItem(this, rootkey, NS_WIN_REG_DELETE_VAL, subkey, valname, NULL);
|
||||
if(wi == NULL)
|
||||
return (-1);
|
||||
su->ScheduleForInstall(wi);
|
||||
return 0;
|
||||
}
|
||||
|
||||
PRInt32 nsWinReg::setValueString(char* subkey, char* valname, char* value)
|
||||
{
|
||||
resolvePrivileges();
|
||||
|
||||
nsWinRegItem* wi = new nsWinRegItem(this, rootkey, NS_WIN_REG_SET_VAL_STRING, subkey, valname, (char*) value);
|
||||
if(wi == NULL)
|
||||
return (-1);
|
||||
su->ScheduleForInstall(wi);
|
||||
return 0;
|
||||
}
|
||||
|
||||
char* nsWinReg::getValueString(char* subkey, char* valname)
|
||||
{
|
||||
resolvePrivileges();
|
||||
|
||||
return nativeGetValueString(subkey, valname);
|
||||
}
|
||||
|
||||
PRInt32 nsWinReg::setValue(char* subkey, char* valname, nsWinRegValue* value)
|
||||
{
|
||||
resolvePrivileges();
|
||||
|
||||
nsWinRegItem* wi = new nsWinRegItem(this, rootkey, NS_WIN_REG_SET_VAL, subkey, valname, (nsWinRegValue*)value);
|
||||
if(wi == NULL)
|
||||
return (-1);
|
||||
su->ScheduleForInstall(wi);
|
||||
return 0;
|
||||
}
|
||||
|
||||
nsWinRegValue* nsWinReg::getValue(char* subkey, char* valname)
|
||||
{
|
||||
resolvePrivileges();
|
||||
|
||||
return nativeGetValue(subkey, valname);
|
||||
}
|
||||
|
||||
nsSoftwareUpdate* nsWinReg::softUpdate()
|
||||
{
|
||||
return su;
|
||||
}
|
||||
|
||||
PRInt32 nsWinReg::finalCreateKey(PRInt32 root, char* subkey, char* classname)
|
||||
{
|
||||
setRootKey(root);
|
||||
return nativeCreateKey(subkey, classname);
|
||||
}
|
||||
|
||||
PRInt32 nsWinReg::finalDeleteKey(PRInt32 root, char* subkey)
|
||||
{
|
||||
setRootKey(root);
|
||||
return nativeDeleteKey(subkey);
|
||||
}
|
||||
|
||||
PRInt32 nsWinReg::finalDeleteValue(PRInt32 root, char* subkey, char* valname)
|
||||
{
|
||||
setRootKey(root);
|
||||
return nativeDeleteValue(subkey, valname);
|
||||
}
|
||||
|
||||
PRInt32 nsWinReg::finalSetValueString(PRInt32 root, char* subkey, char* valname, char* value)
|
||||
{
|
||||
setRootKey(root);
|
||||
return nativeSetValueString(subkey, valname, value);
|
||||
}
|
||||
|
||||
PRInt32 nsWinReg::finalSetValue(PRInt32 root, char* subkey, char* valname, nsWinRegValue* value)
|
||||
{
|
||||
setRootKey(root);
|
||||
return nativeSetValue(subkey, valname, value);
|
||||
}
|
||||
|
||||
|
||||
/* Private Methods */
|
||||
|
||||
PRInt32 nsWinReg::nativeCreateKey(char* subkey, char* classname)
|
||||
{
|
||||
HKEY root, newkey;
|
||||
LONG result;
|
||||
ULONG disposition;
|
||||
|
||||
#ifdef WIN32
|
||||
root = (HKEY) rootkey;
|
||||
|
||||
result = RegCreateKeyEx( root, subkey, 0, classname, REG_OPTION_NON_VOLATILE,
|
||||
KEY_ALL_ACCESS, NULL, &newkey, &disposition );
|
||||
#else
|
||||
result = RegCreateKey( HKEY_CLASSES_ROOT, subkey, &newkey );
|
||||
#endif
|
||||
|
||||
if (ERROR_SUCCESS == result ) {
|
||||
RegCloseKey( newkey );
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
PRInt32 nsWinReg::nativeDeleteKey(char* subkey)
|
||||
{
|
||||
HKEY root;
|
||||
|
||||
#ifdef WIN32
|
||||
root = (HKEY) rootkey;
|
||||
#else
|
||||
root = HKEY_CLASSES_ROOT;
|
||||
#endif
|
||||
|
||||
return RegDeleteKey( root, subkey );
|
||||
}
|
||||
|
||||
PRInt32 nsWinReg::nativeDeleteValue(char* subkey, char* valname)
|
||||
{
|
||||
#if defined (WIN32) || defined (XP_OS2)
|
||||
HKEY root, newkey;
|
||||
LONG result;
|
||||
|
||||
root = (HKEY) rootkey;
|
||||
|
||||
result = RegOpenKeyEx( root, subkey, 0, KEY_WRITE, &newkey );
|
||||
|
||||
if ( ERROR_SUCCESS == result ) {
|
||||
result = RegDeleteValue( newkey, valname );
|
||||
|
||||
RegCloseKey( newkey );
|
||||
}
|
||||
|
||||
return result;
|
||||
#else
|
||||
return ERROR_INVALID_PARAMETER;
|
||||
#endif
|
||||
}
|
||||
|
||||
PRInt32 nsWinReg::nativeSetValueString(char* subkey, char* valname, char* value)
|
||||
{
|
||||
HKEY root;
|
||||
HKEY newkey;
|
||||
LONG result;
|
||||
DWORD length;
|
||||
|
||||
#ifdef WIN32
|
||||
|
||||
root = (HKEY) rootkey;
|
||||
|
||||
result = RegOpenKeyEx( root, subkey, 0, KEY_ALL_ACCESS, &newkey );
|
||||
|
||||
if ( ERROR_SUCCESS == result ) {
|
||||
result = RegSetValueEx( newkey, valname, 0, REG_SZ, (unsigned char*)value, length );
|
||||
|
||||
RegCloseKey( newkey );
|
||||
}
|
||||
#else
|
||||
result = RegSetValue( HKEY_CLASSES_ROOT, subkey, REG_SZ, value, length );
|
||||
#endif
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
#define STRBUFLEN 255
|
||||
|
||||
char* nsWinReg::nativeGetValueString(char* subkey, char* valname)
|
||||
{
|
||||
unsigned char valbuf[STRBUFLEN];
|
||||
HKEY root;
|
||||
HKEY newkey;
|
||||
LONG result;
|
||||
DWORD type = REG_SZ;
|
||||
DWORD length = STRBUFLEN;
|
||||
char* value;
|
||||
|
||||
|
||||
#ifdef WIN32
|
||||
|
||||
root = (HKEY) rootkey;
|
||||
|
||||
result = RegOpenKeyEx( root, subkey, 0, KEY_ALL_ACCESS, &newkey );
|
||||
|
||||
if ( ERROR_SUCCESS == result ) {
|
||||
result = RegQueryValueEx( newkey, valname, NULL, &type, valbuf, &length );
|
||||
|
||||
RegCloseKey( newkey );
|
||||
}
|
||||
#else
|
||||
result = RegQueryValue( HKEY_CLASSES_ROOT, subkey, valbuf, &length );
|
||||
#endif
|
||||
|
||||
if ( ERROR_SUCCESS == result && type == REG_SZ ) {
|
||||
value = XP_STRDUP((char*)valbuf);
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
PRInt32 nsWinReg::nativeSetValue(char* subkey, char* valname, nsWinRegValue* value)
|
||||
{
|
||||
#if defined (WIN32) || defined (XP_OS2)
|
||||
HKEY root;
|
||||
HKEY newkey;
|
||||
LONG result;
|
||||
DWORD length;
|
||||
DWORD type;
|
||||
unsigned char* data;
|
||||
|
||||
|
||||
root = (HKEY) rootkey;
|
||||
|
||||
result = RegOpenKeyEx( root, subkey, 0, KEY_ALL_ACCESS, &newkey );
|
||||
|
||||
if ( ERROR_SUCCESS == result ) {
|
||||
|
||||
type = (DWORD)value->type;
|
||||
data = (unsigned char*)value->data;
|
||||
length = (DWORD)value->data_length;
|
||||
|
||||
|
||||
result = RegSetValueEx( newkey, valname, 0, type, data, length);
|
||||
|
||||
RegCloseKey( newkey );
|
||||
}
|
||||
|
||||
return result;
|
||||
#else
|
||||
return ERROR_INVALID_PARAMETER;
|
||||
#endif
|
||||
}
|
||||
|
||||
nsWinRegValue* nsWinReg::nativeGetValue(char* subkey, char* valname)
|
||||
{
|
||||
#if defined (WIN32) || defined (XP_OS2)
|
||||
unsigned char valbuf[STRBUFLEN];
|
||||
HKEY root;
|
||||
HKEY newkey;
|
||||
LONG result;
|
||||
DWORD length=STRBUFLEN;
|
||||
DWORD type;
|
||||
char* data;
|
||||
nsWinRegValue* value = NULL;
|
||||
|
||||
root = (HKEY) rootkey;
|
||||
|
||||
result = RegOpenKeyEx( root, subkey, 0, KEY_ALL_ACCESS, &newkey );
|
||||
|
||||
if ( ERROR_SUCCESS == result ) {
|
||||
|
||||
result = RegQueryValueEx( newkey, valname, NULL, &type, valbuf, &length );
|
||||
|
||||
if ( ERROR_SUCCESS == result ) {
|
||||
data = XP_STRDUP((char*)valbuf);
|
||||
length = XP_STRLEN(data);
|
||||
|
||||
value = new nsWinRegValue(type, (void*)data, length);
|
||||
}
|
||||
|
||||
RegCloseKey( newkey );
|
||||
}
|
||||
|
||||
return value;
|
||||
#else
|
||||
return NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
PRBool nsWinReg::resolvePrivileges()
|
||||
{
|
||||
if(privMgr->enablePrivilege(impersonation, 1) &&
|
||||
privMgr->enablePrivilege(target, principal, 1))
|
||||
return TRUE;
|
||||
else
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
PR_END_EXTERN_C
|
||||
|
|
|
@ -17,8 +17,222 @@
|
|||
*/
|
||||
|
||||
#include "nsWinRegItem.h"
|
||||
#include "xp.h"
|
||||
#include "xp_str.h"
|
||||
#include <windows.h>
|
||||
|
||||
PR_BEGIN_EXTERN_C
|
||||
|
||||
/* Public Methods */
|
||||
|
||||
nsWinRegItem::nsWinRegItem(nsWinReg* regObj, PRInt32 root, PRInt32 action, char* sub, char* valname, void* val)
|
||||
: nsInstallObject(regObj->softUpdate())
|
||||
{
|
||||
reg = regObj;
|
||||
command = action;
|
||||
rootkey = root;
|
||||
|
||||
/* I'm assuming we need to copy these */
|
||||
subkey = XP_STRDUP(sub);
|
||||
name = XP_STRDUP(valname);
|
||||
value = XP_STRDUP((char*)val);
|
||||
|
||||
}
|
||||
|
||||
char* nsWinRegItem::Complete()
|
||||
{
|
||||
switch (command) {
|
||||
case NS_WIN_REG_CREATE:
|
||||
reg->finalCreateKey(rootkey, subkey, name);
|
||||
break;
|
||||
case NS_WIN_REG_DELETE:
|
||||
reg->finalDeleteKey(rootkey, subkey);
|
||||
break;
|
||||
case NS_WIN_REG_DELETE_VAL:
|
||||
reg->finalDeleteValue(rootkey, subkey, name);
|
||||
break;
|
||||
case NS_WIN_REG_SET_VAL_STRING:
|
||||
reg->finalSetValueString(rootkey, subkey, name, (char*)value);
|
||||
break;
|
||||
case NS_WIN_REG_SET_VAL:
|
||||
reg->finalSetValue(rootkey, subkey, name, (nsWinRegValue*)value);
|
||||
break;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
float nsWinRegItem::GetInstallOrder()
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
|
||||
#define kCRK "Create Registry Key "
|
||||
#define kDRK "Delete Registry key "
|
||||
#define kDRV "Delete Registry value "
|
||||
#define kSRV "Store Registry value "
|
||||
#define kUNK "Unknown "
|
||||
|
||||
char* nsWinRegItem::toString()
|
||||
{
|
||||
char* keyString;
|
||||
char* result;
|
||||
PRInt32 len;
|
||||
|
||||
switch(command)
|
||||
{
|
||||
case NS_WIN_REG_CREATE:
|
||||
keyString = keystr(rootkey, subkey, NULL);
|
||||
len = XP_STRLEN(kCRK) + XP_STRLEN(keyString);
|
||||
result = (char*)XP_ALLOC((len+1)*sizeof(char));
|
||||
XP_STRCAT(result, kCRK);
|
||||
XP_STRCAT(result, keyString);
|
||||
XP_FREE(keyString);
|
||||
return result;
|
||||
case NS_WIN_REG_DELETE:
|
||||
keyString = keystr(rootkey, subkey, NULL);
|
||||
len = XP_STRLEN(kDRK) + XP_STRLEN(keyString);
|
||||
result = (char*)XP_ALLOC((len+1)*sizeof(char));
|
||||
XP_STRCAT(result, kDRK);
|
||||
XP_STRCAT(result, keyString);
|
||||
XP_FREE(keyString);
|
||||
return result;
|
||||
case NS_WIN_REG_DELETE_VAL:
|
||||
keyString = keystr(rootkey, subkey, name);
|
||||
len = XP_STRLEN(kDRV) + XP_STRLEN(keyString);
|
||||
result = (char*)XP_ALLOC((len+1)*sizeof(char));
|
||||
XP_STRCAT(result, kDRV);
|
||||
XP_STRCAT(result, keyString);
|
||||
XP_FREE(keyString);
|
||||
return result;
|
||||
case NS_WIN_REG_SET_VAL_STRING:
|
||||
keyString = keystr(rootkey, subkey, name);
|
||||
len = XP_STRLEN(kSRV) + XP_STRLEN(keyString);
|
||||
result = (char*)XP_ALLOC((len+1)*sizeof(char));
|
||||
XP_STRCAT(result, kSRV);
|
||||
XP_STRCAT(result, keyString);
|
||||
XP_FREE(keyString);
|
||||
return result;
|
||||
case NS_WIN_REG_SET_VAL:
|
||||
keyString = keystr(rootkey, subkey, name);
|
||||
len = XP_STRLEN(kSRV) + XP_STRLEN(keyString);
|
||||
result = (char*)XP_ALLOC((len+1)*sizeof(char));
|
||||
XP_STRCAT(result, kSRV);
|
||||
XP_STRCAT(result, keyString);
|
||||
XP_FREE(keyString);
|
||||
return result;
|
||||
default:
|
||||
keyString = keystr(rootkey, subkey, name);
|
||||
len = XP_STRLEN(kUNK) + XP_STRLEN(keyString);
|
||||
result = (char*)XP_ALLOC((len+1)*sizeof(char));
|
||||
XP_STRCAT(result, kUNK);
|
||||
XP_STRCAT(result, keyString);
|
||||
XP_FREE(keyString);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
char* nsWinRegItem::Prepare()
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void nsWinRegItem::Abort()
|
||||
{
|
||||
}
|
||||
|
||||
/* Private Methods */
|
||||
|
||||
char* nsWinRegItem::keystr(PRInt32 root, char* subkey, char* name)
|
||||
{
|
||||
char* rootstr;
|
||||
char* rootnum;
|
||||
char* finalstr;
|
||||
PRInt32 rootlen, finallen;
|
||||
|
||||
switch(root)
|
||||
{
|
||||
case (int)(HKEY_CLASSES_ROOT) :
|
||||
rootstr = XP_STRDUP("\\HKEY_CLASSES_ROOT\\");
|
||||
break;
|
||||
case (int)(HKEY_CURRENT_USER) :
|
||||
rootstr = XP_STRDUP("\\HKEY_CURRENT_USER\\");
|
||||
break;
|
||||
case (int)(HKEY_LOCAL_MACHINE) :
|
||||
rootstr = XP_STRDUP("\\HKEY_LOCAL_MACHINE\\");
|
||||
break;
|
||||
case (int)(HKEY_USERS) :
|
||||
rootstr = XP_STRDUP("\\HKEY_USERS\\");
|
||||
break;
|
||||
default:
|
||||
rootnum = itoa(root);
|
||||
rootlen = XP_STRLEN(rootnum) + XP_STRLEN("\\#\\");
|
||||
rootstr = (char*)XP_ALLOC((rootlen+1)*sizeof(char));
|
||||
XP_STRCAT(rootstr, "\\#");
|
||||
XP_STRCAT(rootstr, rootnum);
|
||||
XP_STRCAT(rootstr, "\\");
|
||||
break;
|
||||
}
|
||||
if(name == NULL)
|
||||
{
|
||||
finallen = XP_STRLEN(rootstr) + XP_STRLEN(subkey);
|
||||
finalstr = (char*)XP_ALLOC((finallen+1)*sizeof(char));
|
||||
XP_STRCAT(finalstr, rootstr);
|
||||
XP_STRCAT(finalstr, subkey);
|
||||
XP_FREE(rootstr);
|
||||
return finalstr;
|
||||
}
|
||||
else
|
||||
{
|
||||
finallen = XP_STRLEN(rootstr) + XP_STRLEN(subkey) + XP_STRLEN(name) + 3;
|
||||
finalstr = (char*)XP_ALLOC((finallen+1)*sizeof(char));
|
||||
XP_STRCAT(finalstr, rootstr);
|
||||
XP_STRCAT(finalstr, subkey);
|
||||
XP_STRCAT(finalstr, " [");
|
||||
XP_STRCAT(finalstr, name);
|
||||
XP_STRCAT(finalstr, "]");
|
||||
XP_FREE(rootstr);
|
||||
return finalstr;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
char* nsWinRegItem::itoa(PRInt32 n)
|
||||
{
|
||||
char* s;
|
||||
int i, sign;
|
||||
if((sign = n) < 0)
|
||||
n = -n;
|
||||
i = 0;
|
||||
|
||||
s = (char*)XP_ALLOC(sizeof(char));
|
||||
|
||||
do
|
||||
{
|
||||
s = (char*)XP_REALLOC(s, (i+1)*sizeof(char));
|
||||
s[i++] = n%10 + '0';
|
||||
s[i] = '\0';
|
||||
} while ((n/=10) > 0);
|
||||
|
||||
if(sign < 0)
|
||||
{
|
||||
s = (char*)XP_REALLOC(s, (i+1)*sizeof(char));
|
||||
s[i++] = '-';
|
||||
}
|
||||
s[i] = '\0';
|
||||
reverseString(s);
|
||||
return s;
|
||||
}
|
||||
|
||||
void nsWinRegItem::reverseString(char* s)
|
||||
{
|
||||
int c, i, j;
|
||||
|
||||
for(i=0, j=strlen(s)-1; i<j; i++, j--)
|
||||
{
|
||||
c = s[i];
|
||||
s[i] = s[j];
|
||||
s[j] = c;
|
||||
}
|
||||
}
|
||||
|
||||
PR_END_EXTERN_C
|
||||
|
|
Загрузка…
Ссылка в новой задаче