initial checkin for install.WinProfile object code for windows platform only

git-svn-id: svn://10.0.0.236/trunk@31512 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
ssu%netscape.com 1999-05-13 23:31:16 +00:00
parent f509d70dc1
commit 2cf78714ce
6 changed files with 604 additions and 0 deletions

View File

@ -0,0 +1,216 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "jsapi.h"
#include "nscore.h"
#include "nsIScriptContext.h"
#include "nsString.h"
#include "nsInstall.h"
#include "nsWinProfile.h"
#include "nsJSWinProfile.h"
static void PR_CALLBACK WinProfileCleanup(JSContext *cx, JSObject *obj);
extern void nsCvrtJSValToStr(nsString& aString,
JSContext* aContext,
jsval aValue);
extern void nsCvrtStrToJSVal(const nsString& aProp,
JSContext* aContext,
jsval* aReturn);
extern PRBool nsCvrtJSValToBool(PRBool* aProp,
JSContext* aContext,
jsval aValue);
extern PRBool nsCvrtJSValToObj(nsISupports** aSupports,
REFNSIID aIID,
const nsString& aTypeName,
JSContext* aContext,
jsval aValue);
static void PR_CALLBACK WinProfileCleanup(JSContext *cx, JSObject *obj)
{
nsWinProfile *nativeThis = (nsWinProfile*)JS_GetPrivate(cx, obj);
delete nativeThis;
}
/***********************************************************************************/
// Native mothods for WinProfile functions
//
// Native method GetString
//
PR_STATIC_CALLBACK(JSBool)
WinProfileGetString(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsWinProfile *nativeThis = (nsWinProfile*)JS_GetPrivate(cx, obj);
nsString nativeRet;
nsAutoString b0;
nsAutoString 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 int getString ( String section,
// String key);
nsCvrtJSValToStr(b0, cx, argv[0]);
nsCvrtJSValToStr(b1, cx, argv[1]);
if(NS_OK != nativeThis->getString(b0, b1, &nativeRet))
{
return JS_FALSE;
}
nsCvrtStrToJSVal(nativeRet, cx, rval);
}
else
{
JS_ReportError(cx, "WinProfile.getString() parameters error");
return JS_FALSE;
}
return JS_TRUE;
}
//
// Native method WriteString
//
PR_STATIC_CALLBACK(JSBool)
WinProfileWriteString(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsWinProfile *nativeThis = (nsWinProfile*)JS_GetPrivate(cx, obj);
PRInt32 nativeRet;
nsAutoString b0;
nsAutoString b1;
nsAutoString b2;
*rval = JSVAL_NULL;
// If there's no private data, this must be the prototype, so ignore
if(nsnull == nativeThis)
{
return JS_TRUE;
}
if(argc >= 3)
{
// public int writeString ( String section,
// String key,
// String value);
nsCvrtJSValToStr(b0, cx, argv[0]);
nsCvrtJSValToStr(b1, cx, argv[1]);
nsCvrtJSValToStr(b2, cx, argv[2]);
if(NS_OK != nativeThis->writeString(b0, b1, b2, &nativeRet))
{
return JS_FALSE;
}
*rval = INT_TO_JSVAL(nativeRet);
}
else
{
JS_ReportError(cx, "WinProfile.writeString() parameters error");
return JS_FALSE;
}
return JS_TRUE;
}
//
// WinProfile constructor
//
PR_STATIC_CALLBACK(JSBool)
WinProfile(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
return JS_FALSE;
}
/***********************************************************************/
//
// class for WinProfile
//
JSClass WinProfileClass = {
"WinProfile",
JSCLASS_HAS_PRIVATE,
JS_PropertyStub,
JS_PropertyStub,
JS_PropertyStub,
JS_PropertyStub,
JS_EnumerateStub,
JS_ResolveStub,
JS_ConvertStub,
WinProfileCleanup
;
static JSConstDoubleSpec winprofile_constants[] =
{
// { nsWinProfile::HKEY_CLASSES_ROOT, "HKEY_CLASSES_ROOT" },
// { nsWinProfile::HKEY_CURRENT_USER, "HKEY_CURRENT_USER" },
// { nsWinProfile::HKEY_LOCAL_MACHINE, "HKEY_LOCAL_MACHINE" },
// { nsWinProfile::HKEY_USERS, "HKEY_USERS" },
{0}
};
//
// WinProfile class methods
//
static JSFunctionSpec WinProfileMethods[] =
{
{"getString", WinProfileGetString, 2},
{"writeString", WinProfileWriteString, 3},
{0}
};
PRInt32
InitWinProfilePrototype(JSContext *jscontext, JSObject *global, JSObject **winProfilePrototype)
{
*winProfilePrototype = JS_InitClass( jscontext, // context
global, // global object
nsnull, // parent proto
&WinProfileClass, // JSClass
nsnull, // JSNative ctor
0, // ctor args
nsnull, // proto props
nsnull, // proto funcs
nsnull, // ctor props (static)
WinProfileMethods); // ctor funcs (static)
if(nsnull == *winProfilePrototype)
{
return NS_ERROR_FAILURE;
}
if(PR_FALSE == JS_DefineConstDoubles(jscontext, *winProfilePrototype, winProfile_constants))
return NS_ERROR_FAILURE;
return NS_OK;
}

View File

@ -0,0 +1,25 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef __NS_JSWINREG_H__
#define __NS_JSWINREG_H__
PRInt32
InitWinRegPrototype(JSContext *jscontext, JSObject *global, JSObject **winRegPrototype);
#endif

View File

@ -0,0 +1,109 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "nsWinProfile.h"
#include "nsWinProfileItem.h"
#include "nspr.h"
#include <windows.h>
/* 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);
}
PRInt32
nsWinProfile::getString(nsString section, nsString key, nsString* aReturn )
{
*aReturn = nativeGetString(section, key);
return NS_OK;
}
PRInt32
nsWinProfile::writeString( char* section, char* key, char* value, PRInt32* aReturn )
{
nsWinProfileItem* wi = new nsWinProfileItem(this, section, key, value);
if(wi == NULL)
return PR_FALSE;
su->ScheduleForInstall(wi);
return NS_OK;
}
nsString* nsWinProfile::getFilename()
{
return filename;
}
nsInstall* nsWinProfile::installObject()
{
return su;
}
PRInt32
nsWinProfile::finalWriteString( char* section, char* key, char* value )
{
/* do we need another security check here? */
return nativeWriteString(section, key, value);
}
/* Private Methods */
PRInt32
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(nsString section, nsString key )
{
int numChars;
char valbuf[STRBUFLEN];
char* value = NULL;
/* make sure conversions worked */
if(section != "nsnull" && key != "nsnull" && 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;
}

View File

@ -0,0 +1,74 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef nsWinProfile_h__
#define nsWinProfile_h__
#include "prtypes.h"
#include "nsInstall.h"
#include "nsFolderSpec.h"
struct nsWinProfile {
public:
/* Public Fields */
/* Public Methods */
nsWinProfile( nsSoftwareUpdate* suObj, nsFolderSpec* folder, char* file );
/**
* Schedules a write into a windows "ini" file. "Value" can be
* null to delete the value, but we don't support deleting an entire
* section via a null "key". The actual write takes place during
* SoftwareUpdate.FinalizeInstall();
*
* @return false for failure, true for success
*/
PRInt32 writeString( char* section, char* key, char* value, PRInt32* aReturn );
/**
* Reads a value from a windows "ini" file. We don't support using
* a null "key" to return a list of keys--you have to know what you want
*
* @return String value from INI, "" if not found, null if error
*/
PRInt32 getString( char* section, char* key, nsString* aReturn );
char* getFilename();
nsInstall* softUpdate();
int finalWriteString( char* section, char* key, char* value );
private:
/* Private Fields */
char* filename;
nsInstall* su;
nsUserTarget* target;
/* Private Methods */
int nativeWriteString( char* section, char* key, char* value );
char* nativeGetString( char* section, char* key );
};
#endif /* nsWinProfile_h__ */

View File

@ -0,0 +1,103 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#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;
}
/* CanUninstall
* WinProfileItem() does not install any files which can be uninstalled,
* hence this function returns false.
*/
PRBool
nsWinProfileItem::CanUninstall()
{
return FALSE;
}
/* RegisterPackageNode
* WinProfileItem() installs files which need to be registered,
* hence this function returns true.
*/
PRBool
nsWinProfileItem::RegisterPackageNode()
{
return TRUE;
}
PR_END_EXTERN_C

View File

@ -0,0 +1,77 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef nsWinProfileItem_h__
#define nsWinProfileItem_h__
#include "prtypes.h"
#include "nsSoftwareUpdate.h"
#include "nsInstallObject.h"
#include "nsWinProfile.h"
PR_BEGIN_EXTERN_C
class nsWinProfileItem : public nsInstallObject {
public:
/* Public Fields */
/* Public Methods */
nsWinProfileItem(nsWinProfile* profileObj,
char* sectionName,
char* keyName,
char* val);
/**
* Completes the install:
* - writes the data into the .INI file
*/
char* Complete();
float GetInstallOrder();
char* toString();
// no need for special clean-up
void Abort();
// no need for set-up
char* Prepare();
/* should these be protected? */
PRBool CanUninstall();
PRBool RegisterPackageNode();
private:
/* Private Fields */
nsWinProfile* profile; // initiating profile object
char* section; // Name of section
char* key; // Name of key
char* value; // data to write
/* Private Methods */
};
PR_END_EXTERN_C
#endif /* nsWinProfileItem_h__ */