From 725b2f99ce534028435e3ef1dfa30b283c480318 Mon Sep 17 00:00:00 2001 From: "dp%netscape.com" Date: Wed, 9 Jun 1999 19:16:38 +0000 Subject: [PATCH] Well Known Component Registry in /component.reg implemented. git-svn-id: svn://10.0.0.236/trunk@34441 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/modules/libreg/xpcom/nsRegistry.cpp | 71 +++++++++++++++++---- mozilla/xpcom/components/nsIRegistry.h | 10 ++- mozilla/xpcom/components/nsRegistry.cpp | 71 +++++++++++++++++---- 3 files changed, 126 insertions(+), 26 deletions(-) diff --git a/mozilla/modules/libreg/xpcom/nsRegistry.cpp b/mozilla/modules/libreg/xpcom/nsRegistry.cpp index 32f98b1280e..2a5edb5f9a8 100644 --- a/mozilla/modules/libreg/xpcom/nsRegistry.cpp +++ b/mozilla/modules/libreg/xpcom/nsRegistry.cpp @@ -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. | diff --git a/mozilla/xpcom/components/nsIRegistry.h b/mozilla/xpcom/components/nsIRegistry.h index 36839175d5c..e8e58d2f605 100644 --- a/mozilla/xpcom/components/nsIRegistry.h +++ b/mozilla/xpcom/components/nsIRegistry.h @@ -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; diff --git a/mozilla/xpcom/components/nsRegistry.cpp b/mozilla/xpcom/components/nsRegistry.cpp index 32f98b1280e..2a5edb5f9a8 100644 --- a/mozilla/xpcom/components/nsRegistry.cpp +++ b/mozilla/xpcom/components/nsRegistry.cpp @@ -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. |