From 1ef21c1927b82918ded34b03c19cd87626149428 Mon Sep 17 00:00:00 2001 From: "racham%netscape.com" Date: Wed, 7 Oct 1998 10:31:25 +0000 Subject: [PATCH] BUG327094 : PREF callbacks replaces the Netscape Registry calls. Problem of deleting an existing profile is corrected. git-svn-id: svn://10.0.0.236/trunk@12186 18797224-902f-48f8-a5cc-f745e15eee43 --- .../cmd/dialup/win/aswplugn/src/profile.cpp | 636 +----------------- 1 file changed, 37 insertions(+), 599 deletions(-) diff --git a/mozilla/cmd/dialup/win/aswplugn/src/profile.cpp b/mozilla/cmd/dialup/win/aswplugn/src/profile.cpp index 8b038afada8..79abbd92874 100644 --- a/mozilla/cmd/dialup/win/aswplugn/src/profile.cpp +++ b/mozilla/cmd/dialup/win/aswplugn/src/profile.cpp @@ -19,26 +19,14 @@ #include #include "plugin.h" -// Netscape Registry header file -#include "NSReg.h" - +//preference call backs +#include "prefapi.h" + #include "xp_mem.h" -// resource include -#ifdef WIN32 // **************************** WIN32 ***************************** #include "resource.h" #include #include -#else // **************************** WIN16 ***************************** -#include "asw16res.h" -#include -#include -#include - -#define INI_USER_SECTION "Users" -#define INI_USERADDINFO_SECTION "Users Additional Info" -#define INI_CURRUSER_KEY "CurrentUser" -#endif // !WIN32 #define MAX_PATH_LENGTH 256 @@ -47,12 +35,7 @@ #include "java_lang_String.h" extern const char *GetStringPlatformChars(JRIEnv *env, struct java_lang_String *string); - - void GetProfileDirectory(char *profilePath); -REGERR CopyNetscapeRegKey(HREG hReg, RKEY key, const char *path, RKEY newKey, char *newPath); -REGERR DeleteKeyTree(HREG hReg, RKEY key, const char *path); - //******************************************************************************** // @@ -65,84 +48,22 @@ native_netscape_npasw_SetupPlugin_SECURE_0005fGetCurrentProfileDirectory(JRIEnv* struct netscape_npasw_SetupPlugin* self) { struct java_lang_String *profilePath = NULL; - char buf[MAX_PATH_LENGTH]; + int bufSize=256; + char buf[256]; buf[0] = '\0'; -#ifdef WIN32 // ***************************** WIN32 ******************************** - HREG reg; - RKEY rKey1, rKey2; - - char *keyPath = (char *)malloc(sizeof(char) * 512); - - assert(keyPath); - if (!keyPath) - return NULL; - - strcpy(keyPath, "Netscape/ProfileManager"); - - // Open Netscape Registry - if (REGERR_OK == NR_RegOpen(NULL, ®)) + if(PREF_OK == PREF_GetCharPref("profile.directory", buf, &bufSize)) { - // Get the handle to the common information - if (REGERR_OK == NR_RegGetKey(reg, ROOTKEY_COMMON, keyPath, &rKey1)) - { - //Get the current user profile - if (REGERR_OK == NR_RegGetEntryString(reg, rKey1, "LastNetscapeUser", buf, MAX_PATH_LENGTH)) - { - //Get the handle to the current profile - if( REGERR_OK == NR_RegGetKey(reg, ROOTKEY_USERS, buf, &rKey2)) - { - // Get the current profile location - if (REGERR_OK == NR_RegGetEntryString(reg, rKey2, "ProfileLocation", (char *)buf, MAX_PATH_LENGTH)) - { - // make sure we append the last '\' in the profile dir path - strcat(buf, "\\"); - - profilePath = JRI_NewStringPlatform(env, buf, strlen(buf), NULL, 0); - - if (REGERR_OK == NR_RegSetEntryString(reg, rKey2, "Temporary", "Temporary")) - { - trace("profile.cpp : GetCurrentProfileDirectiory : Temp flag set for Current User profile directory"); - } - else - { - trace("profile.cpp : GetCurrentProfileDirectiory : Error in setting Temp flag to Current User profile location"); - } - - NR_RegClose(reg); - } - else - { - trace("profile.cpp : GetCurrentProfileDirectiory : Error in obtaining Current User profile location"); - } - } - else - { - trace("profile.cpp : GetCurrentProfileDirectory : Could not obtain handle to ROOTKEY_USERS"); - } - } - else - { - trace("profile.cpp : GetCurrentProfileDirectory : Error in obtaining Current User profile"); - } - } - else - { - trace("profile.cpp : GetCurrentProfileDirectory : Could not obtain handle to ROOTKEY_COMMON"); - } + // make sure we append the last '\' in the profile dir path + strcat(buf, "\\"); + trace("profile.cpp : GetCurrentProfileDirectory : Got the Current User profile = %s", buf); } else { - trace("profile.cpp : GetCurrentProfileDirectory : Could not open Netscape Registry"); + trace("profile.cpp : GetCurrentProfileDirectory : Error in obtaining Current User profile"); } - free(keyPath); -#else // ***************************** WIN16 ******************************** - - GetProfileDirectory(buf); - profilePath = JRI_NewStringUTF(env, buf, strlen(buf)); - -#endif + profilePath = JRI_NewStringPlatform(env, buf, strlen(buf), NULL, 0); return (struct java_lang_String *)profilePath; } @@ -159,191 +80,51 @@ native_netscape_npasw_SetupPlugin_SECURE_0005fGetCurrentProfileName(JRIEnv* env, struct netscape_npasw_SetupPlugin* self) { struct java_lang_String *profileName = NULL; - char buf[MAX_PATH_LENGTH]; + int bufSize=256; + char buf[256]; buf[0] = '\0'; - - -#ifdef WIN32 // ***************************** WIN32 ******************************** - - HREG reg; - RKEY rKey; - - // Open Netscape Registry - if (REGERR_OK == NR_RegOpen(NULL, ®)) + if(PREF_OK == PREF_GetCharPref("profile.name", buf, &bufSize)) { - // finds the user profile path in registry - if (REGERR_OK == NR_RegGetKey(reg, ROOTKEY_COMMON, "Netscape/ProfileManager", &rKey)) - { - //Get the current user profile - if (REGERR_OK == NR_RegGetEntryString(reg, rKey, "LastNetscapeUser", buf, MAX_PATH_LENGTH)) - { - profileName = JRI_NewStringPlatform(env, buf, strlen(buf), NULL, 0); - - NR_RegClose(reg); - } - else - { - trace("profile.cpp : GetCurrentProfileName : Error in obtaining Current User profile location"); - } - } - else - { - trace("profile.cpp : GetCurrentProfileName : Could not obtain handle to ROOTKEY_COMMON"); - } + trace("profile.cpp : GetCurrentProfileDirectory : Got the Current profile name = %s", buf); } else { - trace("profile.cpp : GetCurrentProfileName : Could not open Netscape Registry"); + trace("profile.cpp : GetCurrentProfileName : Error in obtaining Current User profile"); } -#else // ***************************** WIN16 ******************************** - - // get current profile name - GetPrivateProfileString(INI_USERADDINFO_SECTION, INI_CURRUSER_KEY, - "\0", buf, (int) bufsize, INI_NETSCAPE_FILE); - assert('\0' != buf[0]); - if ('\0' == '\0') - return NULL; profileName = JRI_NewStringPlatform(env, buf, strlen(buf), NULL, 0); -#endif - return (struct java_lang_String *)profileName; } - - //******************************************************************************** -// copyRegKeys // -// copies registry keys +// GetProfileDirectory +// +// gets the current profile directory //******************************************************************************** -#ifdef WIN32 -BOOL CopyRegKeys(HKEY hKeyOldName, - HKEY hKeyNewName, - DWORD subkeys, - DWORD maxSubKeyLen, - DWORD maxClassLen, - DWORD values, - DWORD maxValueNameLen, - DWORD maxValueLen, - char *OldPath, - char *NewPath) +void GetProfileDirectory(char *profilePath) { - BOOL Err = FALSE; - DWORD index; + int bufSize=256; + char buf[256]; + buf[0] = '\0'; - // first loop through and copies all the value keys - if (values > 0) { - - DWORD valueNameSize = maxValueNameLen + 1; - char *valueName = (char *)malloc(sizeof(char) * valueNameSize); - DWORD dataSize = maxValueLen + 1; - unsigned char *data = (unsigned char *)malloc(sizeof(char) * dataSize); - DWORD type; - - if ((valueName) && (data)) { - - for (index=0; index 0) { - - char OldSubkeyPath[260]; - char NewSubkeyPath[260]; - HKEY hkeyOldSubkey; - HKEY hkeyNewSubkey; - - for (index=0; index