mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-25 22:01:30 +00:00
Well Known Component Registry in <exedir>/component.reg implemented.
This commit is contained in:
parent
1df18c6339
commit
891afaf041
@ -18,6 +18,7 @@
|
||||
|
||||
#include "nsIRegistry.h"
|
||||
#include "nsIEnumerator.h"
|
||||
#include "nsSpecialSystemDirectory.h"
|
||||
#include "NSReg.h"
|
||||
#include "prmem.h"
|
||||
#include "prlock.h"
|
||||
@ -36,6 +37,7 @@ struct nsRegistry : public nsIRegistry {
|
||||
|
||||
// This class implements the nsIRegistry interface functions.
|
||||
NS_IMETHOD Open( const char *regFile = 0 );
|
||||
NS_IMETHOD OpenWellKnownRegistry( uint32 regid );
|
||||
NS_IMETHOD OpenDefault();
|
||||
NS_IMETHOD Close();
|
||||
|
||||
@ -310,6 +312,18 @@ static void reginfo2Length( const REGINFO &in, uint32 &out ) {
|
||||
}
|
||||
}
|
||||
|
||||
/*-------------------------------- PR_strdup -----------------------------------
|
||||
| Utility function that does PR_Malloc and copies argument string. Caller |
|
||||
| must do PR_Free. |
|
||||
------------------------------------------------------------------------------*/
|
||||
static char *PR_strdup( const char *in ) {
|
||||
char *result = (char*)PR_Malloc( strlen( in ) + 1 );
|
||||
if ( result ) {
|
||||
strcpy( result, in );
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/*----------------------------------- IIDs -------------------------------------
|
||||
| Static IID values for each imterface implemented here; required by the |
|
||||
| NS_IMPL_ISUPPORTS macro. |
|
||||
@ -385,6 +399,51 @@ NS_IMETHODIMP nsRegistry::Open( const char *regFile ) {
|
||||
return regerr2nsresult( mErr );
|
||||
}
|
||||
|
||||
/*----------------------------- nsRegistry::OpenWellKnownRegistry --------------
|
||||
| Takes a registry id and maps that to a file name for opening. We first check |
|
||||
| to see if a registry file is already open and close it if so. |
|
||||
------------------------------------------------------------------------------*/
|
||||
NS_IMETHODIMP nsRegistry::OpenWellKnownRegistry( uint32 regid ) {
|
||||
// Ensure existing registry is closed.
|
||||
Close();
|
||||
|
||||
nsSpecialSystemDirectory reg(nsSpecialSystemDirectory::OS_CurrentProcessDirectory);
|
||||
PRBool foundReg = PR_FALSE;
|
||||
|
||||
switch ( (WellKnownRegistry) regid ) {
|
||||
case ApplicationComponentRegistry:
|
||||
#ifdef XP_MAC
|
||||
reg += "Component Registry";
|
||||
#else
|
||||
reg += "component.reg";
|
||||
#endif /* XP_MAC */
|
||||
foundReg = PR_TRUE;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (foundReg == PR_FALSE) {
|
||||
return NS_ERROR_REG_BADTYPE;
|
||||
}
|
||||
|
||||
// WARNING:
|
||||
// regNSPRPath and regFile need to have the same scope
|
||||
// since the regFile will point to data in regNSPRPath
|
||||
nsNSPRPath regNSPRPath(reg);
|
||||
const char *regFile = (const char *) regNSPRPath;
|
||||
|
||||
#ifdef DEBUG_dp
|
||||
printf("nsRegistry: Opening std registry %s\n", regFile);
|
||||
#endif /* DEBUG_dp */
|
||||
PR_Lock(mregLock);
|
||||
mErr = NR_RegOpen((char*)regFile, &mReg );
|
||||
PR_Unlock(mregLock);
|
||||
// Convert the result.
|
||||
return regerr2nsresult( mErr );
|
||||
}
|
||||
|
||||
/*-------------------------- nsRegistry::OpenDefault ---------------------------
|
||||
| Open the "default" registry; in the case of this libreg-based implementation |
|
||||
| that is done by passing a null file name pointer to NR_RegOpen. |
|
||||
@ -1120,18 +1179,6 @@ nsRegistryNode::nsRegistryNode( HREG hReg, RKEY key, REGENUM slot )
|
||||
}
|
||||
|
||||
|
||||
/*-------------------------------- PR_strdup -----------------------------------
|
||||
| Utility function that does PR_Malloc and copies argument string. Caller |
|
||||
| must do PR_Free. |
|
||||
------------------------------------------------------------------------------*/
|
||||
static char *PR_strdup( const char *in ) {
|
||||
char *result = (char*)PR_Malloc( strlen( in ) + 1 );
|
||||
if ( result ) {
|
||||
strcpy( result, in );
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/*-------------------------- nsRegistryNode::GetName ---------------------------
|
||||
| If we haven't fetched it yet, get the name of the corresponding subkey now, |
|
||||
| using NR_RegEnumSubkeys. |
|
||||
|
@ -138,14 +138,19 @@ struct nsIRegistry : public nsISupports {
|
||||
--------------------------------------------------------------------------*/
|
||||
typedef uint32 Key;
|
||||
|
||||
enum { Users = 1, Common = 2, CurrentUser = 3 };
|
||||
enum WellKnownKeys { Users = 1, Common = 2, CurrentUser = 3 };
|
||||
|
||||
enum WellKnownRegistry {
|
||||
ApplicationComponentRegistry = 1
|
||||
};
|
||||
|
||||
struct ValueInfo {
|
||||
DataType type;
|
||||
uint32 length;
|
||||
};
|
||||
|
||||
static const nsIID& GetIID() { static nsIID iid = NS_IREGISTRY_IID; return iid; }
|
||||
|
||||
static const nsIID& GetIID() { static nsIID iid = NS_IREGISTRY_IID; return iid; }
|
||||
|
||||
/*--------------------------- Opening/Closing ------------------------------
|
||||
| These functions open the specified registry file (Open() with a non-null |
|
||||
@ -160,6 +165,7 @@ struct nsIRegistry : public nsISupports {
|
||||
| Close() function. |
|
||||
--------------------------------------------------------------------------*/
|
||||
NS_IMETHOD Open( const char *regFile = 0 ) = 0;
|
||||
NS_IMETHOD OpenWellKnownRegistry( uint32 regid ) = 0;
|
||||
NS_IMETHOD OpenDefault() = 0;
|
||||
NS_IMETHOD Close() = 0;
|
||||
|
||||
|
@ -18,6 +18,7 @@
|
||||
|
||||
#include "nsIRegistry.h"
|
||||
#include "nsIEnumerator.h"
|
||||
#include "nsSpecialSystemDirectory.h"
|
||||
#include "NSReg.h"
|
||||
#include "prmem.h"
|
||||
#include "prlock.h"
|
||||
@ -36,6 +37,7 @@ struct nsRegistry : public nsIRegistry {
|
||||
|
||||
// This class implements the nsIRegistry interface functions.
|
||||
NS_IMETHOD Open( const char *regFile = 0 );
|
||||
NS_IMETHOD OpenWellKnownRegistry( uint32 regid );
|
||||
NS_IMETHOD OpenDefault();
|
||||
NS_IMETHOD Close();
|
||||
|
||||
@ -310,6 +312,18 @@ static void reginfo2Length( const REGINFO &in, uint32 &out ) {
|
||||
}
|
||||
}
|
||||
|
||||
/*-------------------------------- PR_strdup -----------------------------------
|
||||
| Utility function that does PR_Malloc and copies argument string. Caller |
|
||||
| must do PR_Free. |
|
||||
------------------------------------------------------------------------------*/
|
||||
static char *PR_strdup( const char *in ) {
|
||||
char *result = (char*)PR_Malloc( strlen( in ) + 1 );
|
||||
if ( result ) {
|
||||
strcpy( result, in );
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/*----------------------------------- IIDs -------------------------------------
|
||||
| Static IID values for each imterface implemented here; required by the |
|
||||
| NS_IMPL_ISUPPORTS macro. |
|
||||
@ -385,6 +399,51 @@ NS_IMETHODIMP nsRegistry::Open( const char *regFile ) {
|
||||
return regerr2nsresult( mErr );
|
||||
}
|
||||
|
||||
/*----------------------------- nsRegistry::OpenWellKnownRegistry --------------
|
||||
| Takes a registry id and maps that to a file name for opening. We first check |
|
||||
| to see if a registry file is already open and close it if so. |
|
||||
------------------------------------------------------------------------------*/
|
||||
NS_IMETHODIMP nsRegistry::OpenWellKnownRegistry( uint32 regid ) {
|
||||
// Ensure existing registry is closed.
|
||||
Close();
|
||||
|
||||
nsSpecialSystemDirectory reg(nsSpecialSystemDirectory::OS_CurrentProcessDirectory);
|
||||
PRBool foundReg = PR_FALSE;
|
||||
|
||||
switch ( (WellKnownRegistry) regid ) {
|
||||
case ApplicationComponentRegistry:
|
||||
#ifdef XP_MAC
|
||||
reg += "Component Registry";
|
||||
#else
|
||||
reg += "component.reg";
|
||||
#endif /* XP_MAC */
|
||||
foundReg = PR_TRUE;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (foundReg == PR_FALSE) {
|
||||
return NS_ERROR_REG_BADTYPE;
|
||||
}
|
||||
|
||||
// WARNING:
|
||||
// regNSPRPath and regFile need to have the same scope
|
||||
// since the regFile will point to data in regNSPRPath
|
||||
nsNSPRPath regNSPRPath(reg);
|
||||
const char *regFile = (const char *) regNSPRPath;
|
||||
|
||||
#ifdef DEBUG_dp
|
||||
printf("nsRegistry: Opening std registry %s\n", regFile);
|
||||
#endif /* DEBUG_dp */
|
||||
PR_Lock(mregLock);
|
||||
mErr = NR_RegOpen((char*)regFile, &mReg );
|
||||
PR_Unlock(mregLock);
|
||||
// Convert the result.
|
||||
return regerr2nsresult( mErr );
|
||||
}
|
||||
|
||||
/*-------------------------- nsRegistry::OpenDefault ---------------------------
|
||||
| Open the "default" registry; in the case of this libreg-based implementation |
|
||||
| that is done by passing a null file name pointer to NR_RegOpen. |
|
||||
@ -1120,18 +1179,6 @@ nsRegistryNode::nsRegistryNode( HREG hReg, RKEY key, REGENUM slot )
|
||||
}
|
||||
|
||||
|
||||
/*-------------------------------- PR_strdup -----------------------------------
|
||||
| Utility function that does PR_Malloc and copies argument string. Caller |
|
||||
| must do PR_Free. |
|
||||
------------------------------------------------------------------------------*/
|
||||
static char *PR_strdup( const char *in ) {
|
||||
char *result = (char*)PR_Malloc( strlen( in ) + 1 );
|
||||
if ( result ) {
|
||||
strcpy( result, in );
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/*-------------------------- nsRegistryNode::GetName ---------------------------
|
||||
| If we haven't fetched it yet, get the name of the corresponding subkey now, |
|
||||
| using NR_RegEnumSubkeys. |
|
||||
|
Loading…
Reference in New Issue
Block a user