First checkin of xpinstall into seamonkey

This commit is contained in:
dougt%netscape.com 1999-02-05 00:15:30 +00:00
Родитель 99ca1f4934
Коммит 19f121ec3b
25 изменённых файлов: 7128 добавлений и 0 удалений

814
xpinstall/src/nsInstall.cpp Normal file
Просмотреть файл

@ -0,0 +1,814 @@
/* -*- 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 "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
* the License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*/
#include "nsInstall.h"
#include "nsIDOMInstall.h"
#include "nsIDOMInstallFolder.h"
#include "nsIDOMInstallVersion.h"
#include "nsInstallFile.h"
#include "nscore.h"
#include "nsIFactory.h"
#include "nsISupports.h"
#include "nsVector.h"
#include "prmem.h"
#include "pratom.h"
#include "prefapi.h"
#include "VerReg.h"
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID);
static NS_DEFINE_IID(kIInstall_IID, NS_IDOMINSTALL_IID);
nsInstall::nsInstall()
{
mScriptObject = nsnull;
mVersionInfo = nsnull;
mPackageName = "";
mUserPackageName= "";
mUninstallPackage = PR_FALSE;
mRegisterPackage = PR_FALSE;
NS_INIT_REFCNT();
}
nsInstall::~nsInstall()
{
if (mVersionInfo != nsnull)
delete mVersionInfo;
}
NS_IMETHODIMP
nsInstall::QueryInterface(REFNSIID aIID,void** aInstancePtr)
{
if (aInstancePtr == NULL)
{
return NS_ERROR_NULL_POINTER;
}
// Always NULL result, in case of failure
*aInstancePtr = NULL;
if ( aIID.Equals(kIScriptObjectOwnerIID))
{
*aInstancePtr = (void*) ((nsIScriptObjectOwner*)this);
AddRef();
return NS_OK;
}
else if ( aIID.Equals(kIInstall_IID) )
{
*aInstancePtr = (void*) ((nsIDOMInstall*)this);
AddRef();
return NS_OK;
}
else if ( aIID.Equals(kISupportsIID) )
{
*aInstancePtr = (void*)(nsISupports*)(nsIScriptObjectOwner*)this;
AddRef();
return NS_OK;
}
return NS_NOINTERFACE;
}
NS_IMPL_ADDREF(nsInstall)
NS_IMPL_RELEASE(nsInstall)
NS_IMETHODIMP
nsInstall::GetScriptObject(nsIScriptContext *aContext, void** aScriptObject)
{
NS_PRECONDITION(nsnull != aScriptObject, "null arg");
nsresult res = NS_OK;
if (nsnull == mScriptObject)
{
res = NS_NewScriptInstall( aContext,
(nsISupports *)(nsIDOMInstall*)this,
nsnull,
&mScriptObject);
}
*aScriptObject = mScriptObject;
return res;
}
NS_IMETHODIMP
nsInstall::SetScriptObject(void *aScriptObject)
{
mScriptObject = aScriptObject;
return NS_OK;
}
NS_IMETHODIMP
nsInstall::GetUserPackageName(nsString& aUserPackageName)
{
aUserPackageName = mUserPackageName;
return NS_OK;
}
NS_IMETHODIMP
nsInstall::GetRegPackageName(nsString& aRegPackageName)
{
aRegPackageName = mPackageName;
return NS_OK;
}
NS_IMETHODIMP
nsInstall::AbortInstall()
{
return NS_OK;
}
NS_IMETHODIMP
nsInstall::AddDirectory(const nsString& aRegName, const nsString& aVersion, const nsString& aJarSource, nsIDOMInstallFolder* aFolder, const nsString& aSubdir, PRBool aForceMode, PRInt32* aReturn)
{
return NS_OK;
}
NS_IMETHODIMP
nsInstall::AddSubcomponent(const nsString& aRegName,
nsIDOMInstallVersion* aVersion,
const nsString& aJarSource,
nsIDOMInstallFolder* aFolder,
const nsString& aTargetName,
PRBool aForceMode,
PRInt32* aReturn)
{
nsInstallFile* ie;
nsString* qualifiedRegName;
PRInt32 errcode = SU_SUCCESS;
if ( aJarSource == "null" || aFolder == nsnull)
{
return nsIDOMInstall::SUERR_INVALID_ARGUMENTS;
}
PRInt32 result = SanityCheck();
if (result != nsIDOMInstall::SU_SUCCESS)
{
SaveError( result );
return result;
}
if ( aRegName == "" )
{
// Default subName = location in jar file
qualifiedRegName = GetQualifiedRegName( aJarSource );
}
else
{
qualifiedRegName = GetQualifiedRegName( aRegName );
}
if (qualifiedRegName == nsnull)
{
return SUERR_BAD_PACKAGE_NAME; // this will stop the install script
}
/* Check for existence of the newer version */
PRBool versionNewer = PR_FALSE;
char* qualifiedRegNameString = qualifiedRegName->ToNewCString();
if ( (aForceMode == PR_FALSE ) && (aVersion != nsnull) && ( VR_ValidateComponent( qualifiedRegNameString ) == 0 ) )
{
VERSION versionStruct;
VR_GetVersion( qualifiedRegNameString, &versionStruct );
nsInstallVersion* oldVersion = new nsInstallVersion();
// FIX. Once we move to XPConnect, we can have parameterized constructors.
oldVersion->Init(versionStruct.major,
versionStruct.minor,
versionStruct.release,
versionStruct.build);
PRInt32 areTheyEqual;
aVersion->CompareTo((nsInstallVersion*)oldVersion, &areTheyEqual);
if ( areTheyEqual != nsIDOMInstallVersion::SU_EQUAL )
versionNewer = PR_TRUE;
if( oldVersion )
delete oldVersion;
}
else
{
versionNewer = PR_TRUE;
}
if (qualifiedRegNameString != nsnull)
delete qualifiedRegNameString;
if (versionNewer)
{
char* errorMsg = NULL;
ie = new nsInstallFile( this,
*qualifiedRegName,
aVersion,
aJarSource,
aFolder,
aTargetName,
aForceMode,
&errorMsg );
if (errorMsg == NULL)
{
errorMsg = ScheduleForInstall( ie );
}
if (errorMsg != NULL)
{
SaveError( SUERR_UNEXPECTED_ERROR);
return SUERR_UNEXPECTED_ERROR;
}
}
return NS_OK;
}
NS_IMETHODIMP
nsInstall::DeleteComponent(const nsString& aRegistryName, PRInt32* aReturn)
{
return NS_OK;
}
NS_IMETHODIMP
nsInstall::DeleteFile(nsIDOMInstallFolder* aFolder, const nsString& aRelativeFileName, PRInt32* aReturn)
{
return NS_OK;
}
NS_IMETHODIMP
nsInstall::DiskSpaceAvailable(nsIDOMInstallFolder* aFolder, PRInt32* aReturn)
{
return NS_OK;
}
NS_IMETHODIMP
nsInstall::Execute(const nsString& aJarSource, const nsString& aArgs, PRInt32* aReturn)
{
return NS_OK;
}
NS_IMETHODIMP
nsInstall::FinalizeInstall(PRInt32* aReturn)
{
return NS_OK;
}
NS_IMETHODIMP
nsInstall::Gestalt(const nsString& aSelector, PRInt32* aReturn)
{
return NS_OK;
}
NS_IMETHODIMP
nsInstall::GetComponentFolder(const nsString& aRegName, const nsString& aSubdirectory, nsIDOMInstallFolder** aFolder)
{
return NS_OK;
}
NS_IMETHODIMP
nsInstall::GetFolder(nsIDOMInstallFolder* targetFolder, const nsString& aSubdirectory, nsIDOMInstallFolder** aFolder)
{
return NS_OK;
}
NS_IMETHODIMP
nsInstall::GetLastError(PRInt32* aReturn)
{
return NS_OK;
}
NS_IMETHODIMP
nsInstall::GetWinProfile(nsIDOMInstallFolder* aFolder, const nsString& aFile, PRInt32* aReturn)
{
return NS_OK;
}
NS_IMETHODIMP
nsInstall::GetWinRegistry(PRInt32* aReturn)
{
return NS_OK;
}
NS_IMETHODIMP
nsInstall::Patch(const nsString& aRegName, const nsString& aVersion, const nsString& aJarSource, nsIDOMInstallFolder* aFolder, const nsString& aTargetName, PRInt32* aReturn)
{
return NS_OK;
}
NS_IMETHODIMP
nsInstall::ResetError()
{
mLastError = SU_SUCCESS;
return NS_OK;
}
NS_IMETHODIMP
nsInstall::SetPackageFolder(nsIDOMInstallFolder* aFolder)
{
return NS_OK;
}
/**
* Call this to initialize the update
* Opens the jar file and gets the certificate of the installer
* Opens up the gui, and asks for proper security privileges
*
* @param aUserPackageName
*
* @param aPackageName Full qualified version registry name of the package
* (ex: "/Plugins/Adobe/Acrobat")
* NULL or empty package names are errors
*
* @param inVInfo version of the package installed.
* Can be NULL, in which case package is installed
* without a version. Having a NULL version, this
* package is automatically updated in the future
* (ie. no version check is performed).
*
* @param flags Once was securityLevel(LIMITED_INSTALL or FULL_INSTALL). Now
* can be either NO_STATUS_DLG or NO_FINALIZE_DLG
*/
NS_IMETHODIMP
nsInstall::StartInstall(const nsString& aUserPackageName, const nsString& aPackageName, const nsString& aVersion, PRInt32 aFlags, PRInt32* aReturn)
{
*aReturn = SU_SUCCESS;
ResetError();
ParseFlags(aFlags);
mUserCancelled = PR_FALSE;
mUserPackageName = aUserPackageName;
if ( aPackageName.Equals("") )
{
*aReturn = SUERR_INVALID_ARGUMENTS;
return NS_OK;
}
nsString *tempString = GetQualifiedPackageName( aPackageName );
mPackageName.SetLength(0);
mPackageName.Append( *tempString );
delete tempString;
/* Check to see if the PackageName ends in a '/'. If it does nuke it. */
if (mPackageName.Last() == '/')
{
PRInt32 index = mPackageName.Length();
mPackageName.Truncate(--index);
}
if (mVersionInfo != nsnull)
delete mVersionInfo;
mVersionInfo = new nsInstallVersion();
mVersionInfo->Init(aVersion); /* this will go away when we have params in constructs in XPCOM */
mInstalledFiles = new nsVector();
/* this function should also check security!!! */
*aReturn = OpenJARFile();
if (*aReturn != SU_SUCCESS)
{
/* if we can not continue with the javascript return a JAR error*/
return -1; /* FIX: need real error code */
}
if (mShowProgress)
{
/* Show our window here */
}
// set up default package folder, if any
int err;
char* path = (char*) PR_Malloc(MAXREGPATHLEN);
char* packageNameCString = mPackageName.ToNewCString();
err = VR_GetDefaultDirectory( packageNameCString , MAXREGPATHLEN, path );
delete [] packageNameCString;
if (err != REGERR_OK)
{
PR_FREEIF(path);
path = NULL;
}
if ( path != NULL )
{
mPackageFolder = new nsInstallFolder();
mPackageFolder->Init("Installed", nsString(path), mPackageName);
PR_FREEIF(path);
}
SaveError(*aReturn);
if (*aReturn != SU_SUCCESS)
{
mPackageName = ""; // Reset!
}
return NS_OK;
}
NS_IMETHODIMP
nsInstall::Uninstall(const nsString& aPackageName, PRInt32* aReturn)
{
return NS_OK;
}
NS_IMETHODIMP
nsInstall::ExtractFileFromJar(const nsString& aJarfile, const nsString& aFinalFile, nsString& aTempFile, nsString& aErrorMsg)
{
return NS_OK;
}
/////////////////////////////////////////////////////////////////////////
// Private Methods
/////////////////////////////////////////////////////////////////////////
/**
* ScheduleForInstall
* call this to put an InstallObject on the install queue
* Do not call installedFiles.addElement directly, because this routine also
* handles progress messages
*/
char*
nsInstall::ScheduleForInstall(nsInstallObject* ob)
{
char *errorMsg = NULL;
char *objString = ob->toString();
// flash current item
//SetProgressDialogItem( objString );
PR_FREEIF(objString);
// do any unpacking or other set-up
errorMsg = ob->Prepare();
if (errorMsg != NULL)
{
return errorMsg;
}
// Add to installation list if we haven't thrown out
mInstalledFiles->Add( ob );
// turn on flags for creating the uninstall node and
// the package node for each InstallObject
if (ob->CanUninstall())
mUninstallPackage = PR_TRUE;
if (ob->RegisterPackageNode())
mRegisterPackage = PR_TRUE;
return NULL;
}
void
nsInstall::ParseFlags(int flags)
{
mShowProgress = mShowFinalize = PR_TRUE;
if ((flags & SU_NO_STATUS_DLG) == SU_NO_STATUS_DLG)
{
mShowProgress = PR_FALSE;
}
if ((flags & SU_NO_FINALIZE_DLG) == SU_NO_FINALIZE_DLG)
{
mShowFinalize = PR_FALSE;
}
}
/**
* SanityCheck
*
* This routine checks if the packageName is null. It also checks the flag if the user cancels
* the install progress dialog is set and acccordingly aborts the install.
*/
PRInt32
nsInstall::SanityCheck(void)
{
if ( mPackageName == "" || mUserPackageName == "")
{
return SUERR_INSTALL_NOT_STARTED;
}
if (mUserCancelled)
{
AbortInstall();
SaveError(SUERR_USER_CANCELLED);
return SUERR_USER_CANCELLED;
}
return 0;
}
/**
* GetQualifiedPackageName
*
* This routine converts a package-relative component registry name
* into a full name that can be used in calls to the version registry.
*/
nsString *
nsInstall::GetQualifiedPackageName( const nsString& name )
{
nsString* qualifedName = nsnull;
/* this functions is really messed up. The original checkin is messed as well */
if ( name.Equals( "=USER=/") )
{
qualifedName = CurrentUserNode();
qualifedName->Insert( name, 7 );
}
if (BadRegName(qualifedName))
{
if (qualifedName != nsnull)
{
delete qualifedName;
qualifedName = nsnull;
}
}
return qualifedName;
}
/**
* GetQualifiedRegName
*
* Allocates a new string and returns it. Caller is supposed to free it
*
* This routine converts a package-relative component registry name
* into a full name that can be used in calls to the version registry.
*/
nsString *
nsInstall::GetQualifiedRegName(const nsString& name )
{
nsString *qualifiedRegName;
nsString comm("=COMM=/");
nsString usr ("=USER=/");
if ( name.Compare(comm, PR_TRUE, comm.Length()) == 0 )
{
qualifiedRegName = new nsString( name );
qualifiedRegName->Cut( 0, comm.Length() );
}
else if ( name.Compare(usr, PR_TRUE, usr.Length()) == 0 )
{
qualifiedRegName = new nsString( name );
qualifiedRegName->Cut( 0, usr.Length() );
}
else if ( name[0] != '/' )
{
if (mUserPackageName != "")
{
qualifiedRegName = new nsString(mUserPackageName);
qualifiedRegName += '/';
qualifiedRegName->Append(name);
}
else
{
qualifiedRegName = new nsString(name);
}
}
else
{
qualifiedRegName = new nsString(name);
}
if (BadRegName(qualifiedRegName))
{
delete qualifiedRegName;
qualifiedRegName = NULL;
}
return qualifiedRegName;
}
nsString*
nsInstall::CurrentUserNode()
{
nsString *qualifedName;
nsString *profileName;
char *profname;
int len = MAXREGNAMELEN;
int err;
profname = (char*) PR_Malloc(len);
err = PREF_GetCharPref( "profile.name", profname, &len );
if ( err != PREF_OK )
{
PR_FREEIF(profname);
profname = NULL;
}
profileName = new nsString(profname);
qualifedName = new nsString("/Netscape/Users/");
qualifedName->Append(*profileName);
qualifedName->Append("/");
if (profileName != nsnull)
delete profileName;
return qualifedName;
}
// catch obvious registry name errors proactively
// rather than returning some cryptic libreg error
PRBool
nsInstall::BadRegName(nsString* regName)
{
if (regName == nsnull)
return PR_TRUE;
if ((regName->First() == ' ' ) || (regName->Last() == ' ' ))
return PR_TRUE;
if ( regName->Find("//") != -1 )
return PR_TRUE;
if ( regName->Find(" /") != -1 )
return PR_TRUE;
if ( regName->Find("/ ") != -1 )
return PR_TRUE;
if ( regName->Find("=") != -1 )
return PR_TRUE;
return PR_FALSE;
}
PRInt32
nsInstall::SaveError(PRInt32 errcode)
{
if ( errcode != SU_SUCCESS )
mLastError = errcode;
return errcode;
}
PRInt32
nsInstall::OpenJARFile(void)
{
return SU_SUCCESS;
}
/////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////
static PRInt32 gInstallInstanceCnt = 0;
static PRInt32 gInstallLock = 0;
nsInstallFactory::nsInstallFactory(void)
{
mRefCnt=0;
PR_AtomicIncrement(&gInstallInstanceCnt);
}
nsInstallFactory::~nsInstallFactory(void)
{
PR_AtomicDecrement(&gInstallInstanceCnt);
}
NS_IMETHODIMP
nsInstallFactory::QueryInterface(REFNSIID aIID,void** aInstancePtr)
{
if (aInstancePtr == NULL)
{
return NS_ERROR_NULL_POINTER;
}
// Always NULL result, in case of failure
*aInstancePtr = NULL;
if ( aIID.Equals(kISupportsIID) )
{
*aInstancePtr = (void*) this;
}
else if ( aIID.Equals(kIFactoryIID) )
{
*aInstancePtr = (void*) this;
}
if (aInstancePtr == NULL)
{
return NS_ERROR_NO_INTERFACE;
}
AddRef();
return NS_OK;
}
NS_IMETHODIMP
nsInstallFactory::AddRef(void)
{
return ++mRefCnt;
}
NS_IMETHODIMP
nsInstallFactory::Release(void)
{
if (--mRefCnt ==0)
{
delete this;
return 0; // Don't access mRefCnt after deleting!
}
return mRefCnt;
}
NS_IMETHODIMP
nsInstallFactory::CreateInstance(nsISupports *aOuter, REFNSIID aIID, void **aResult)
{
if (aResult == NULL)
{
return NS_ERROR_NULL_POINTER;
}
*aResult = NULL;
/* do I have to use iSupports? */
nsInstall *inst = new nsInstall();
if (inst == NULL)
return NS_ERROR_OUT_OF_MEMORY;
nsresult result = inst->QueryInterface(aIID, aResult);
if (result != NS_OK)
delete inst;
return result;
}
NS_IMETHODIMP
nsInstallFactory::LockFactory(PRBool aLock)
{
if (aLock)
PR_AtomicIncrement(&gInstallLock);
else
PR_AtomicDecrement(&gInstallLock);
return NS_OK;
}

111
xpinstall/src/nsInstall.h Normal file
Просмотреть файл

@ -0,0 +1,111 @@
#ifndef __NS_INSTALL_H__
#define __NS_INSTALL_H__
#include "nscore.h"
#include "nsString.h"
#include "nsIFactory.h"
#include "nsISupports.h"
#include "nsIScriptObjectOwner.h"
#include "nsVector.h"
#include "nsIDOMInstall.h"
#include "nsInstallObject.h"
#include "nsSoftwareUpdate.h"
#include "nsInstallFolder.h"
#include "nsInstallVersion.h"
class nsInstall: public nsIScriptObjectOwner, public nsIDOMInstall
{
public:
static const nsIID& IID() { static nsIID iid = NS_SoftwareUpdateInstall_CID; return iid; }
nsInstall();
~nsInstall();
NS_DECL_ISUPPORTS
NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject);
NS_IMETHOD SetScriptObject(void* aScriptObject);
NS_IMETHOD GetUserPackageName(nsString& aUserPackageName);
NS_IMETHOD GetRegPackageName(nsString& aRegPackageName);
NS_IMETHOD AbortInstall();
NS_IMETHOD AddDirectory(const nsString& aRegName, const nsString& aVersion, const nsString& aJarSource, nsIDOMInstallFolder* aFolder, const nsString& aSubdir, PRBool aForceMode, PRInt32* aReturn);
NS_IMETHOD AddSubcomponent(const nsString& aRegName, nsIDOMInstallVersion* aVersion, const nsString& aJarSource, nsIDOMInstallFolder* aFolder, const nsString& aTargetName, PRBool aForceMode, PRInt32* aReturn);
NS_IMETHOD DeleteComponent(const nsString& aRegistryName, PRInt32* aReturn);
NS_IMETHOD DeleteFile(nsIDOMInstallFolder* aFolder, const nsString& aRelativeFileName, PRInt32* aReturn);
NS_IMETHOD DiskSpaceAvailable(nsIDOMInstallFolder* aFolder, PRInt32* aReturn);
NS_IMETHOD Execute(const nsString& aJarSource, const nsString& aArgs, PRInt32* aReturn);
NS_IMETHOD FinalizeInstall(PRInt32* aReturn);
NS_IMETHOD Gestalt(const nsString& aSelector, PRInt32* aReturn);
NS_IMETHOD GetComponentFolder(const nsString& aRegName, const nsString& aSubdirectory, nsIDOMInstallFolder** aFolder);
NS_IMETHOD GetFolder(nsIDOMInstallFolder* aTargetFolder, const nsString& aSubdirectory, nsIDOMInstallFolder** aFolder);
NS_IMETHOD GetLastError(PRInt32* aReturn);
NS_IMETHOD GetWinProfile(nsIDOMInstallFolder* aFolder, const nsString& aFile, PRInt32* aReturn);
NS_IMETHOD GetWinRegistry(PRInt32* aReturn);
NS_IMETHOD Patch(const nsString& aRegName, const nsString& aVersion, const nsString& aJarSource, nsIDOMInstallFolder* aFolder, const nsString& aTargetName, PRInt32* aReturn);
NS_IMETHOD ResetError();
NS_IMETHOD SetPackageFolder(nsIDOMInstallFolder* aFolder);
NS_IMETHOD StartInstall(const nsString& aUserPackageName, const nsString& aPackageName, const nsString& aVersion, PRInt32 aFlags, PRInt32* aReturn);
NS_IMETHOD Uninstall(const nsString& aPackageName, PRInt32* aReturn);
/*needs to be noscript*/
NS_IMETHOD ExtractFileFromJar(const nsString& aJarfile, const nsString& aFinalFile, nsString& aTempFile, nsString& aErrorMsg);
private:
void *mScriptObject;
PRBool mUserCancelled;
PRBool mShowProgress;
PRBool mShowFinalize;
PRBool mUninstallPackage;
PRBool mRegisterPackage;
nsString mPackageName; /* Name of the package we are installing */
nsString mUserPackageName; /* User-readable package name */
nsInstallVersion* mVersionInfo; /* Component version info */
nsInstallFolder* mPackageFolder;
nsVector* mInstalledFiles;
PRInt32 mLastError;
void ParseFlags(int flags);
PRInt32 SanityCheck(void);
nsString * GetQualifiedRegName( const nsString& name );
nsString* GetQualifiedPackageName( const nsString& name );
nsString* CurrentUserNode();
PRBool BadRegName(nsString* regName);
PRInt32 SaveError(PRInt32 errcode);
PRInt32 OpenJARFile(void);
char* ScheduleForInstall(nsInstallObject* ob);
};
class nsInstallFactory : public nsIFactory
{
public:
nsInstallFactory();
~nsInstallFactory();
NS_DECL_ISUPPORTS
NS_IMETHOD CreateInstance(nsISupports *aOuter,
REFNSIID aIID,
void **aResult);
NS_IMETHOD LockFactory(PRBool aLock);
};
#endif

Просмотреть файл

@ -0,0 +1,126 @@
/* -*- 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 "xp.h"
#include "xpgetstr.h"
#include "plstr.h"
#include "prmem.h"
#include "nsString.h"
#include "nsInstallErrorMessages.h"
char *
nsInstallErrorMessages::GetErrorMsg(int id, char* arg1)
{
char* errorMsg = "";
char* tag = XP_GetString(id);
PR_ASSERT(tag != NULL);
errorMsg = PL_strcat(tag, arg1);
return errorMsg;
}
char *
nsInstallErrorMessages::GetErrorMsg(int id, nsString* arg1, int reason)
{
char* errorMsg = "";
char* ptr;
char* tag = XP_GetString(id);
PR_ASSERT(tag != NULL);
char* argMsg = "";
if (argMsg)
argMsg = arg1->ToNewCString();
ptr = PR_sprintf_append(errorMsg, "%s %s %d", tag, argMsg, reason);
delete argMsg;
errorMsg = PL_strdup(ptr);
delete ptr;
return errorMsg;
}
char *
nsInstallErrorMessages::GetErrorMsg(char *str, int err)
{
char* errorMsg = "";
char* ptr;
PR_ASSERT(str != NULL);
ptr = PR_sprintf_append(errorMsg, "%s %d", str, err);
errorMsg = PL_strdup(ptr);
delete ptr;
return errorMsg;
}
char *
nsInstallErrorMessages::GetErrorMsg(int id, int reason)
{
char* msg;
char* ptr;
char* tag = XP_GetString(id);
PR_ASSERT(tag != NULL);
ptr = PR_sprintf_append(msg, "%s %d", tag, reason);
msg = PL_strdup(ptr);
delete ptr;
return msg;
}
char *
nsInstallErrorMessages::GetString(int id)
{
char *str = XP_GetString(id);
PR_ASSERT(str != NULL);
return PL_strdup(str);
}
char *
nsInstallErrorMessages::GetString(int id, char* arg1)
{
char* msg=NULL;
char* tag = XP_GetString(id);
PR_ASSERT(tag != NULL);
if (arg1)
{
msg = PL_strcat(msg, tag);
msg = PL_strcat(msg, arg1);
}
else
{
msg = PL_strcat(msg, tag);
}
return msg;
}
char *
nsInstallErrorMessages::GetString(int id, nsString* arg1)
{
char* msg=NULL;
char* tag = XP_GetString(id);
PR_ASSERT(tag != NULL);
char* argMsg = "";
msg = PL_strcat(msg, tag);
if (arg1)
{
argMsg = arg1->ToNewCString();
msg = PL_strcat(msg, argMsg);
delete argMsg;
}
return msg;
}

Просмотреть файл

@ -0,0 +1,39 @@
/* -*- 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 nsInstallErrorMessages_h__
#define nsInstallErrorMessages_h__
#include "nsString.h"
class nsInstallErrorMessages
{
public:
static char * GetErrorMsg(int id, char* arg1);
static char * GetErrorMsg(int id, nsString* arg1, int reason);
static char * GetErrorMsg(char *str, int err);
static char * GetErrorMsg(int id, int reason);
static char * GetString(int id);
static char * GetString(int id, char* arg1);
static char * GetString(int id, nsString* arg1);
};
#endif

Просмотреть файл

@ -0,0 +1,507 @@
/* -*- 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.
*/
#if defined(XP_MAC)
#include <stat.h>
#else
#include <sys/stat.h>
#endif
#include "prio.h"
#include "prmem.h"
#include "plstr.h"
#include "VerReg.h"
#include "nsInstallFile.h"
#include "nsIDOMInstall.h"
#include "nsIDOMInstallFolder.h"
#include "nsIDOMInstallVersion.h"
#include "nsInstallErrorMessages.h"
static PRBool endsWith(nsString* str, char* string_to_find);
static PRBool endsWith(nsString* str, char* string_to_find)
{
PRBool found = PR_FALSE;
if (str) {
int len = strlen(".zip");
int size = str->Length();
int offset = str->RFind(string_to_find, PR_FALSE);
if (offset == (size - len))
found = PR_TRUE;
}
return found;
}
/* Public Methods */
/* Constructor
inInstall - softUpdate object we belong to
inComponentName - full path of the registry component
inVInfo - full version info
inJarLocation - location inside the JAR file
inFinalFileSpec - final location on disk
*/
nsInstallFile::nsInstallFile(nsIDOMInstall* inInstall,
const nsString& inVRName,
nsIDOMInstallVersion* inVInfo,
const nsString& inJarLocation,
nsIDOMInstallFolder* folderSpec,
const nsString& inPartialPath,
PRBool forceInstall,
char* *errorMsg)
: nsInstallObject(inInstall)
{
mTempFile = nsnull;
mFinalFile = nsnull;
mUpgradeFile = PR_FALSE;
if ((folderSpec == NULL) || (inInstall == NULL) ||
(inVInfo == NULL))
{
*errorMsg = nsInstallErrorMessages::GetErrorMsg( "Invalid arguments to the constructor",
nsIDOMInstall::SUERR_INVALID_ARGUMENTS);
return;
}
mVersionRegistryName = new nsString(inVRName);
mJarLocation = new nsString(inJarLocation);
mVersionInfo = inVInfo; /* XXX: Who owns and who free's this object. Is it nsSoftwareUpdate?? */
mForceInstall = forceInstall;
folderSpec->IsJavaCapable(&mJavaInstall);
mFinalFile = new nsString();
folderSpec->MakeFullPath(inPartialPath, *mFinalFile);
mReplaceFile = DoesFileExist();
nsString regPackageName;
mInstall->GetRegPackageName(regPackageName);
// determine Child status
if ( regPackageName == "" )
{
// in the "current communicator package" absolute pathnames (start
// with slash) indicate shared files -- all others are children
mChildFile = ( mVersionRegistryName->CharAt(0) != '/' );
}
else
{
//mChildFile = mVersionRegistryName.startsWith(regPackageName);
/* Because nsString doesn't support startWith, implemented the following. Waiting for approval */
if (mVersionRegistryName->Find(regPackageName) == 0)
{
mChildFile = true;
}
else
{
mChildFile = false;
}
}
}
nsInstallFile::~nsInstallFile()
{
delete mVersionRegistryName;
delete mJarLocation;
if (mTempFile)
delete mTempFile;
if (mFinalFile)
delete mFinalFile;
}
/* Prepare
* Extracts file out of the JAR archive into the temp directory
*/
char* nsInstallFile::Prepare()
{
char *errorMsg = NULL;
if (mInstall == NULL)
{
errorMsg = nsInstallErrorMessages::GetErrorMsg("nsSoftwareUpdate object is null",
nsIDOMInstall::SUERR_INVALID_ARGUMENTS);
return errorMsg;
}
if (mJarLocation == NULL)
{
errorMsg = nsInstallErrorMessages::GetErrorMsg("JAR file is null",
nsIDOMInstall::SUERR_INVALID_ARGUMENTS);
return errorMsg;
}
if (mFinalFile == NULL)
{
errorMsg = nsInstallErrorMessages::GetErrorMsg("folderSpec's full path (mFinalFile) was null",
nsIDOMInstall::SUERR_INVALID_ARGUMENTS);
return errorMsg;
}
nsString errString;
mInstall->ExtractFileFromJar(*mJarLocation, *mFinalFile, *mTempFile, errString);
if (errString != "")
{
return errString.ToNewCString();
}
return NULL;
}
/* Complete
* Completes the install:
* - move the downloaded file to the final location
* - updates the registry
*/
char* nsInstallFile::Complete()
{
int err;
int refCount;
int rc;
if (mInstall == NULL)
{
return nsInstallErrorMessages::GetErrorMsg("nsSoftwareUpdate object is null",
nsIDOMInstall::SUERR_INVALID_ARGUMENTS);
}
if (mVersionRegistryName == NULL)
{
return nsInstallErrorMessages::GetErrorMsg("version registry name is null",
nsIDOMInstall::SUERR_INVALID_ARGUMENTS);
}
if (mFinalFile == NULL)
{
return nsInstallErrorMessages::GetErrorMsg("folderSpec's full path (mFinalFile) is null",
nsIDOMInstall::SUERR_INVALID_ARGUMENTS);
}
/* Check the security for our target */
err = NativeComplete();
char *vr_name = mVersionRegistryName->ToNewCString();
char *final_file = mFinalFile->ToNewCString();
// Add java archives to the classpath. Don't add if we're
// replacing an existing file -- it'll already be there.
if ( mJavaInstall && !mReplaceFile )
{
PRBool found_zip = endsWith(mFinalFile, ".zip");
PRBool found_jar = endsWith(mFinalFile, ".jar");;
if (found_zip || found_jar)
{
AddToClasspath( mFinalFile );
}
}
nsString regPackageName;
mInstall->GetRegPackageName(regPackageName);
// Register file and log for Uninstall
if ( 0 == err || nsIDOMInstall::SU_REBOOT_NEEDED == err )
{
// we ignore all registry errors because they're not
// important enough to abort an otherwise OK install.
if (!mChildFile)
{
int found;
if (regPackageName != "")
{
char *reg_package_name = regPackageName.ToNewCString();
found = VR_UninstallFileExistsInList( reg_package_name, vr_name );
delete reg_package_name;
}
else
{
found = VR_UninstallFileExistsInList( "", vr_name );
}
if (found != REGERR_OK)
mUpgradeFile = PR_FALSE;
else
mUpgradeFile = PR_TRUE;
}
else if (REGERR_OK == VR_InRegistry(vr_name))
{
mUpgradeFile = PR_TRUE;
}
else
{
mUpgradeFile = PR_FALSE;
}
err = VR_GetRefCount( vr_name, &refCount );
if ( err != REGERR_OK )
{
refCount = 0;
}
if (!mUpgradeFile)
{
if (refCount != 0)
{
rc = 1 + refCount;
nsString tempString;
mVersionInfo->ToString(tempString);
VR_Install( vr_name, final_file, (char*)(PRUnichar*) tempString, PR_FALSE );
VR_SetRefCount( vr_name, rc );
}
else
{
if (mReplaceFile)
{
nsString tempString;
mVersionInfo->ToString(tempString);
VR_Install( vr_name, final_file, (char*)(PRUnichar*) tempString, PR_FALSE);
VR_SetRefCount( vr_name, 2 );
}
else
{
nsString tempString;
mVersionInfo->ToString(tempString);
VR_Install( vr_name, final_file, (char*)(PRUnichar*) tempString, PR_FALSE );
VR_SetRefCount( vr_name, 1 );
}
}
}
else if (mUpgradeFile)
{
if (refCount == 0)
{
nsString tempString;
mVersionInfo->ToString(tempString);
VR_Install( vr_name, final_file, (char*)(PRUnichar*) tempString, PR_FALSE );
VR_SetRefCount( vr_name, 1 );
}
else
{
nsString tempString;
mVersionInfo->ToString(tempString);
VR_Install( vr_name, final_file, (char*)(PRUnichar*) tempString, PR_FALSE );
VR_SetRefCount( vr_name, 0 );
}
}
if ( !mChildFile && !mUpgradeFile )
{
if (regPackageName != "")
{
char *reg_package_name = regPackageName.ToNewCString();
VR_UninstallAddFileToList( reg_package_name, vr_name );
delete reg_package_name;
}
else
{
VR_UninstallAddFileToList( "", vr_name );
}
}
}
delete vr_name;
delete final_file;
if ( err != 0 )
{
return nsInstallErrorMessages::GetErrorMsg(nsIDOMInstall::SU_INSTALL_FILE_UNEXPECTED_MSG_ID, mFinalFile, err);
}
return NULL;
}
void nsInstallFile::Abort()
{
char* currentName;
int result;
/* Get the names */
if (mTempFile == NULL)
return;
currentName = mTempFile->ToNewCString();
result = PR_Delete(currentName);
PR_ASSERT(result == 0); /* XXX: need to fe_deletefilelater() or something */
delete currentName;
}
char* nsInstallFile::toString()
{
if (mReplaceFile)
{
return nsInstallErrorMessages::GetString(nsIDOMInstall::SU_DETAILS_REPLACE_FILE_MSG_ID, mFinalFile);
}
else
{
return nsInstallErrorMessages::GetString(nsIDOMInstall::SU_DETAILS_INSTALL_FILE_MSG_ID, mFinalFile);
}
}
/* Private Methods */
/* Complete
* copies the file to its final location
* Tricky, we need to create the directories
*/
int nsInstallFile::NativeComplete()
{
char* currentName = NULL;
char* finalName = NULL;
int result = 0;
if (mTempFile == nsnull)
{
return -1;
}
/* Get the names */
currentName = mTempFile->ToNewCString();
finalName = mFinalFile->ToNewCString();
if ( finalName == NULL || currentName == NULL )
{
/* memory or JRI problems */
result = -1;
goto end;
}
if ( PL_strcmp(finalName, currentName) == 0 )
{
/* No need to rename, they are the same */
result = 0;
}
else
{
struct stat finfo;
if (stat(finalName, &finfo) != 0)
{
PR_Rename(currentName, finalName);
}
else
{
/* Target exists, can't trust XP_FileRename--do platform
* specific stuff in FE_ReplaceExistingFile()
*/
result = -1;
}
}
if (result != 0)
{
struct stat finfo;
if (stat(finalName, &finfo) == 0)
{
/* File already exists, need to remove the original */
// result = FE_ReplaceExistingFile(currentName, xpURL, finalName, xpURL, mForceInstall);
if ( result == nsIDOMInstall::SU_REBOOT_NEEDED )
{
}
}
else
{
/* Directory might not exist, check and create if necessary */
char separator;
char * end;
separator = '/';
end = PL_strrchr(finalName, separator);
if (end)
{
end[0] = 0;
// FIX- this need to be made recursive?
result = PR_MkDir( finalName, 0);
end[0] = separator;
if ( 0 == result )
{
// FIX - this may not work on UNIX between different
// filesystems!
result = PR_Rename(currentName, finalName);
}
}
}
}
end:
delete [] finalName;
delete [] currentName;
return result;
}
void nsInstallFile::AddToClasspath(nsString* file)
{
if ( file != NULL ) {
char *final_file = file->ToNewCString();
// JVM_AddToClassPath(final_file);
delete final_file;
}
}
/* Finds out if the file exists
*/
PRBool nsInstallFile::DoesFileExist()
{
if (mFinalFile == nsnull)
return PR_FALSE;
char* finalName = mFinalFile->ToNewCString();
struct stat finfo;
if ( stat(finalName, &finfo) != -1)
{
delete [] finalName;
return PR_TRUE;
}
delete [] finalName;
return PR_FALSE;
}
/* CanUninstall
* InstallFile() installs files which can be uninstalled,
* hence this function returns true.
*/
PRBool
nsInstallFile::CanUninstall()
{
return TRUE;
}
/* RegisterPackageNode
* InstallFile() installs files which need to be registered,
* hence this function returns true.
*/
PRBool
nsInstallFile::RegisterPackageNode()
{
return TRUE;
}

Просмотреть файл

@ -0,0 +1,87 @@
/* -*- 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 nsInstallFile_h__
#define nsInstallFile_h__
#include "prtypes.h"
#include "nsString.h"
#include "nsInstallObject.h"
#include "nsIDOMInstall.h"
#include "nsIDOMInstallFolder.h"
#include "nsIDOMInstallVersion.h"
class nsInstallFile : public nsInstallObject
{
public:
/*************************************************************
* Public Methods
*
* Constructor
* inSoftUpdate - softUpdate object we belong to
* inComponentName - full path of the registry component
* inVInfo - full version info
* inJarLocation - location inside the JAR file
* inFinalFileSpec - final location on disk
*************************************************************/
nsInstallFile( nsIDOMInstall* inInstall,
const nsString& inVRName,
nsIDOMInstallVersion* inVInfo,
const nsString& inJarLocation,
nsIDOMInstallFolder* folderSpec,
const nsString& inPartialPath,
PRBool forceInstall,
char**errorMsg);
virtual ~nsInstallFile();
char* Prepare();
char* Complete();
void Abort();
char* toString();
PRBool CanUninstall();
PRBool RegisterPackageNode();
private:
/* Private Fields */
nsIDOMInstallVersion* mVersionInfo; /* Version info for this file*/
nsString* mJarLocation; /* Location in the JAR */
nsString* mTempFile; /* temporary file location */
nsString* mFinalFile; /* final file destination */
nsString* mVersionRegistryName; /* full version path */
PRBool mForceInstall; /* whether install is forced */
PRBool mJavaInstall; /* whether file is installed to a Java directory */
PRBool mReplaceFile; /* whether file exists */
PRBool mChildFile; /* whether file is a child */
PRBool mUpgradeFile; /* whether file is an upgrade */
int NativeComplete();
PRBool DoesFileExist();
void AddToClasspath(nsString* file);
};
#endif /* nsInstallFile_h__ */

Просмотреть файл

@ -0,0 +1,499 @@
/* -*- 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 "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
* the License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*/
#include "nsSoftwareUpdate.h"
#include "nsInstallFolder.h"
#include "nsIDOMInstallFolder.h"
#include "nscore.h"
#include "nsIFactory.h"
#include "nsISupports.h"
#include "nsIScriptGlobalObject.h"
#include "prefapi.h"
#include "pratom.h"
#include "prprf.h"
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID);
static NS_DEFINE_IID(kIInstallFolder_IID, NS_IDOMINSTALLFOLDER_IID);
#ifndef MAX_PATH
#if defined(XP_WIN) || defined(XP_OS2)
#define MAX_PATH _MAX_PATH
#endif
#ifdef XP_UNIX
#if defined(HPUX) || defined(SCO)
/*
** HPUX: PATH_MAX is defined in <limits.h> to be 1023, but they
** recommend that it not be used, and that pathconf() be
** used to determine the maximum at runtime.
** SCO: This is what MAXPATHLEN is set to in <arpa/ftp.h> and
** NL_MAXPATHLEN in <nl_types.h>. PATH_MAX is defined in
** <limits.h> to be 256, but the comments in that file
** claim the setting is wrong.
*/
#define MAX_PATH 1024
#else
#define MAX_PATH PATH_MAX
#endif
#endif
#endif
typedef enum su_SecurityLevel {
eOneFolderAccess,
eAllFolderAccess
} su_SecurityLevel;
struct su_DirectoryTable
{
char * directoryName; /* The formal directory name */
PRInt32 folderEnum; /* Directory ID */
PRBool bJavaDir; /* TRUE is a Java-capable directory */
};
/*
* Directory manipulation
*
* DirectoryTable holds the info about built-in directories:
* Text name, security level, enum
*/
struct su_DirectoryTable DirectoryTable[] =
{
{"Plugins", nsIDOMInstallFolder::PluginFolder, PR_TRUE},
{"Program", nsIDOMInstallFolder::ProgramFolder, PR_FALSE},
{"Communicator", nsIDOMInstallFolder::CommunicatorFolder, PR_FALSE},
{"User Pick", nsIDOMInstallFolder::PackageFolder, PR_FALSE},
{"Temporary", nsIDOMInstallFolder::TemporaryFolder, PR_FALSE},
{"Installed", nsIDOMInstallFolder::InstalledFolder, PR_FALSE},
{"Current User", nsIDOMInstallFolder::CurrentUserFolder, PR_FALSE},
{"NetHelp", nsIDOMInstallFolder::NetHelpFolder, PR_FALSE},
{"OS Drive", nsIDOMInstallFolder::OSDriveFolder, PR_FALSE},
{"File URL", nsIDOMInstallFolder::FileURLFolder, PR_FALSE},
{"Netscape Java Bin", nsIDOMInstallFolder::JavaBinFolder, PR_FALSE},
{"Netscape Java Classes", nsIDOMInstallFolder::JavaClassesFolder, PR_TRUE},
{"Java Download", nsIDOMInstallFolder::JavaDownloadFolder, PR_TRUE},
{"Win System", nsIDOMInstallFolder::Win_SystemFolder, PR_FALSE},
{"Win System16", nsIDOMInstallFolder::Win_System16Folder, PR_FALSE},
{"Windows", nsIDOMInstallFolder::Win_WindowsFolder, PR_FALSE},
{"Mac System", nsIDOMInstallFolder::Mac_SystemFolder, PR_FALSE},
{"Mac Desktop", nsIDOMInstallFolder::Mac_DesktopFolder, PR_FALSE},
{"Mac Trash", nsIDOMInstallFolder::Mac_TrashFolder, PR_FALSE},
{"Mac Startup", nsIDOMInstallFolder::Mac_StartupFolder, PR_FALSE},
{"Mac Shutdown", nsIDOMInstallFolder::Mac_ShutdownFolder, PR_FALSE},
{"Mac Apple Menu", nsIDOMInstallFolder::Mac_AppleMenuFolder, PR_FALSE},
{"Mac Control Panel", nsIDOMInstallFolder::Mac_ControlPanelFolder, PR_FALSE},
{"Mac Extension", nsIDOMInstallFolder::Mac_ExtensionFolder, PR_FALSE},
{"Mac Fonts", nsIDOMInstallFolder::Mac_FontsFolder, PR_FALSE},
{"Mac Preferences", nsIDOMInstallFolder::Mac_PreferencesFolder, PR_FALSE},
{"Unix Local", nsIDOMInstallFolder::Unix_LocalFolder, PR_FALSE},
{"Unix Lib", nsIDOMInstallFolder::Unix_LibFolder, PR_FALSE},
{"", nsIDOMInstallFolder::BadFolder, PR_FALSE} /* Termination */
};
nsInstallFolder::nsInstallFolder()
{
mScriptObject = nsnull;
char *errorMsg = NULL;
mUrlPath = mFolderID = mVersionRegistryPath = mUserPackageName = nsnull;
NS_INIT_REFCNT();
}
nsInstallFolder::~nsInstallFolder()
{
}
NS_IMETHODIMP
nsInstallFolder::QueryInterface(REFNSIID aIID,void** aInstancePtr)
{
if (aInstancePtr == NULL)
{
return NS_ERROR_NULL_POINTER;
}
// Always NULL result, in case of failure
*aInstancePtr = NULL;
if ( aIID.Equals(kIScriptObjectOwnerIID))
{
*aInstancePtr = (void*) ((nsIScriptObjectOwner*)this);
AddRef();
return NS_OK;
}
else if ( aIID.Equals(kIInstallFolder_IID) )
{
*aInstancePtr = (void*) ((nsIDOMInstallFolder*)this);
AddRef();
return NS_OK;
}
else if ( aIID.Equals(kISupportsIID) )
{
*aInstancePtr = (void*)(nsISupports*)(nsIScriptObjectOwner*)this;
AddRef();
return NS_OK;
}
return NS_NOINTERFACE;
}
NS_IMPL_ADDREF(nsInstallFolder)
NS_IMPL_RELEASE(nsInstallFolder)
NS_IMETHODIMP
nsInstallFolder::GetScriptObject(nsIScriptContext *aContext, void** aScriptObject)
{
NS_PRECONDITION(nsnull != aScriptObject, "null arg");
nsresult res = NS_OK;
if (nsnull == mScriptObject)
{
res = NS_NewScriptInstallFolder( aContext,
(nsISupports *)(nsIDOMInstallFolder*)this,
nsnull,
&mScriptObject);
}
*aScriptObject = mScriptObject;
return res;
}
NS_IMETHODIMP
nsInstallFolder::SetScriptObject(void *aScriptObject)
{
mScriptObject = aScriptObject;
return NS_OK;
}
// this will go away when our constructors can have parameters.
NS_IMETHODIMP
nsInstallFolder::Init(const nsString& aFolderID, const nsString& aVrPatch, const nsString& aPackageName)
{
/* Since urlPath is set to NULL, this FolderSpec is essentially the error message */
if ( aFolderID == "null" || aVrPatch == "null" || aPackageName == "null")
{
return NS_OK; // should we stop the script?
}
mFolderID = new nsString(aFolderID);
mVersionRegistryPath = new nsString(aVrPatch);
mUserPackageName = new nsString(aPackageName);
/* Setting the urlPath to a real file patch. */
SetDirectoryPath( &mUrlPath );
return NS_OK;
}
NS_IMETHODIMP
nsInstallFolder::GetDirectoryPath(nsString& aDirectoryPath)
{
aDirectoryPath.SetLength(0);
aDirectoryPath.Append(*mUrlPath);
return NS_OK;
}
NS_IMETHODIMP
nsInstallFolder::MakeFullPath(const nsString& aRelativePath, nsString& aFullPath)
{
nsString *tempString = GetNativePath(aRelativePath);
aFullPath.SetLength(0);
aFullPath.Append( *mUrlPath );
aFullPath.Append( *tempString );
if (tempString)
delete tempString;
return NS_OK;
}
NS_IMETHODIMP
nsInstallFolder::IsJavaCapable(PRBool* aReturn)
{
*aReturn = PR_FALSE; // FIX: what are we going to do here.
return -1;
}
NS_IMETHODIMP
nsInstallFolder::ToString(nsString& aFolderString)
{
return GetDirectoryPath(aFolderString);
}
void
nsInstallFolder::SetDirectoryPath(nsString** aFolderString)
{
if ( mFolderID->EqualsIgnoreCase("User Pick") )
{
PickDefaultDirectory(&mUrlPath);
}
else if ( mFolderID->EqualsIgnoreCase("Installed") )
{
mUrlPath = mVersionRegistryPath->ToNewString();
}
else
{
PRInt32 folderDirSpecID;
char* folderPath = NULL;
folderDirSpecID = MapNameToEnum(mFolderID);
switch (folderDirSpecID)
{
case nsIDOMInstallFolder::BadFolder:
folderPath = NULL;
break;
case nsIDOMInstallFolder::CurrentUserFolder:
{
char dir[MAX_PATH];
int len = MAX_PATH;
if ( PREF_GetCharPref("profile.directory", dir, &len) == PREF_NOERROR)
{
// char * platformDir = WH_FileName(dir, xpURL);
// if (platformDir)
// folderPath = AppendSlashToDirPath(platformDir);
// PR_FREEIF(platformDir);
}
}
break;
default:
/* Get the FE path */
// folderPath = FE_GetDirectoryPath(folderDirSpecID);
break;
}
}
}
nsString* nsInstallFolder::GetNativePath(const nsString& path)
{
char pathSeparator;
char xp_pathSeparator = '/';
#ifdef XP_WIN
pathSeparator = '\\';
#elif defined(XP_MAC)
pathSeparator = ':';
#else /* XP_UNIX */
pathSeparator = '/';
#endif
nsString *xpPath = new nsString(path);
PRInt32 offset = xpPath->FindCharInSet(&xp_pathSeparator);
while (offset != -1)
{
xpPath[offset] = pathSeparator;
offset = xpPath->FindCharInSet(&xp_pathSeparator, offset);
}
return xpPath;
}
void nsInstallFolder::PickDefaultDirectory(nsString** aFolderString)
{
return; //FIX: Need to put up a dialog here!
}
PRBool nsInstallFolder::IsJavaDir(void)
{
for (int i=0; DirectoryTable[i].directoryName[0] != 0; i++ )
{
if ( mFolderID->EqualsIgnoreCase(DirectoryTable[i].directoryName) )
return DirectoryTable[i].bJavaDir;
}
return PR_FALSE;
}
/* MapNameToEnum
* maps name from the directory table to its enum */
PRInt32
nsInstallFolder::MapNameToEnum(nsString* name)
{
int i = 0;
if ( name == nsnull )
return nsIDOMInstallFolder::BadFolder;
while ( DirectoryTable[i].directoryName[0] != 0 )
{
if ( name->EqualsIgnoreCase(DirectoryTable[i].directoryName) )
return DirectoryTable[i].folderEnum;
i++;
}
return nsIDOMInstallFolder::BadFolder;
}
/*
Makes sure that the path ends with a slash (or other platform end character)
*/
void
nsInstallFolder::AppendSlashToDirPath(nsString* dirPath)
{
char pathSeparator;
#ifdef XP_WIN
pathSeparator = '\\';
#elif defined(XP_MAC)
pathSeparator = ':';
#else /* XP_UNIX */
pathSeparator = '/';
#endif
if ( dirPath->CharAt( dirPath->Last() ) != pathSeparator )
{
dirPath += pathSeparator;
}
}
/////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////
static PRInt32 gInstallFolderInstanceCnt = 0;
static PRInt32 gInstallFolderLock = 0;
nsInstallFolderFactory::nsInstallFolderFactory(void)
{
mRefCnt=0;
PR_AtomicIncrement(&gInstallFolderInstanceCnt);
}
nsInstallFolderFactory::~nsInstallFolderFactory(void)
{
PR_AtomicDecrement(&gInstallFolderInstanceCnt);
}
NS_IMETHODIMP
nsInstallFolderFactory::QueryInterface(REFNSIID aIID,void** aInstancePtr)
{
if (aInstancePtr == NULL)
{
return NS_ERROR_NULL_POINTER;
}
// Always NULL result, in case of failure
*aInstancePtr = NULL;
if ( aIID.Equals(kISupportsIID) )
{
*aInstancePtr = (void*) this;
}
else if ( aIID.Equals(kIFactoryIID) )
{
*aInstancePtr = (void*) this;
}
if (aInstancePtr == NULL)
{
return NS_ERROR_NO_INTERFACE;
}
AddRef();
return NS_OK;
}
NS_IMETHODIMP
nsInstallFolderFactory::AddRef(void)
{
return ++mRefCnt;
}
NS_IMETHODIMP
nsInstallFolderFactory::Release(void)
{
if (--mRefCnt ==0)
{
delete this;
return 0; // Don't access mRefCnt after deleting!
}
return mRefCnt;
}
NS_IMETHODIMP
nsInstallFolderFactory::CreateInstance(nsISupports *aOuter, REFNSIID aIID, void **aResult)
{
if (aResult == NULL)
{
return NS_ERROR_NULL_POINTER;
}
*aResult = NULL;
/* do I have to use iSupports? */
nsInstallFolder *inst = new nsInstallFolder();
if (inst == NULL)
return NS_ERROR_OUT_OF_MEMORY;
nsresult result = inst->QueryInterface(aIID, aResult);
if (result != NS_OK)
delete inst;
return result;
}
NS_IMETHODIMP
nsInstallFolderFactory::LockFactory(PRBool aLock)
{
if (aLock)
PR_AtomicIncrement(&gInstallFolderLock);
else
PR_AtomicDecrement(&gInstallFolderLock);
return NS_OK;
}

Просмотреть файл

@ -0,0 +1,71 @@
#ifndef __NS_INSTALLFOLDER_H__
#define __NS_INSTALLFOLDER_H__
#include "nscore.h"
#include "nsString.h"
#include "nsIFactory.h"
#include "nsISupports.h"
#include "nsIScriptObjectOwner.h"
#include "nsIDOMInstallFolder.h"
#include "nsSoftwareUpdate.h"
#include "prtypes.h"
class nsInstallFolder: public nsIScriptObjectOwner, public nsIDOMInstallFolder
{
public:
static const nsIID& IID() { static nsIID iid = NS_SoftwareUpdateInstallFolder_CID; return iid; }
nsInstallFolder();
~nsInstallFolder();
NS_DECL_ISUPPORTS
NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject);
NS_IMETHOD SetScriptObject(void* aScriptObject);
NS_IMETHOD Init(const nsString& aFolderID, const nsString& aVrPatch, const nsString& aPackageName);
NS_IMETHOD GetDirectoryPath(nsString& aDirectoryPath);
NS_IMETHOD MakeFullPath(const nsString& aRelativePath, nsString& aFullPath);
NS_IMETHOD IsJavaCapable(PRBool* aReturn);
NS_IMETHOD ToString(nsString& aFolderString);
private:
void *mScriptObject;
nsString* mUrlPath; // Full path to the directory. Used to cache results from GetDirectoryPath
nsString* mFolderID; // Unique string specifying a folder
nsString* mVersionRegistryPath; // Version registry path of the package
nsString* mUserPackageName; // Name of the package presented to the user
void SetDirectoryPath(nsString** aFolderString);
void PickDefaultDirectory(nsString** aFolderString);
nsString* GetNativePath(const nsString& path);
PRInt32 MapNameToEnum(nsString* name);
void AppendSlashToDirPath(nsString* dirPath);
PRBool IsJavaDir(void);
};
class nsInstallFolderFactory : public nsIFactory
{
public:
nsInstallFolderFactory();
~nsInstallFolderFactory();
NS_DECL_ISUPPORTS
NS_IMETHOD CreateInstance(nsISupports *aOuter,
REFNSIID aIID,
void **aResult);
NS_IMETHOD LockFactory(PRBool aLock);
};
#endif

Просмотреть файл

@ -0,0 +1,51 @@
/* -*- 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 nsInstallObject_h__
#define nsInstallObject_h__
#include "prtypes.h"
#include "nsIDOMInstall.h"
class nsInstallObject
{
public:
/* Public Methods */
nsInstallObject(nsIDOMInstall* inInstall) {mInstall = inInstall; }
/* Override with your set-up action */
virtual char* Prepare() = 0;
/* Override with your Completion action */
virtual char* Complete() = 0;
/* Override with an explanatory string for the progress dialog */
virtual char* toString() = 0;
/* Override with your clean-up function */
virtual void Abort() = 0;
/* should these be protected? */
virtual PRBool CanUninstall() = 0;
virtual PRBool RegisterPackageNode() = 0;
protected:
nsIDOMInstall* mInstall;
};
#endif /* nsInstallObject_h__ */

Просмотреть файл

@ -0,0 +1,248 @@
/* -*- 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 "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
* the License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*/
#include "nsSoftwareUpdate.h"
#include "nsSoftwareUpdateStream.h"
#include "nsInstallTrigger.h"
#include "nsIDOMInstallTriggerGlobal.h"
#include "nscore.h"
#include "nsIFactory.h"
#include "nsISupports.h"
#include "nsIScriptGlobalObject.h"
#include "pratom.h"
#include "prefapi.h"
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID);
static NS_DEFINE_IID(kIInstallTrigger_IID, NS_IDOMINSTALLTRIGGERGLOBAL_IID);
nsInstallTrigger::nsInstallTrigger()
{
mScriptObject = nsnull;
NS_INIT_REFCNT();
}
nsInstallTrigger::~nsInstallTrigger()
{
}
NS_IMETHODIMP
nsInstallTrigger::QueryInterface(REFNSIID aIID,void** aInstancePtr)
{
if (aInstancePtr == NULL)
{
return NS_ERROR_NULL_POINTER;
}
// Always NULL result, in case of failure
*aInstancePtr = NULL;
if ( aIID.Equals(kIScriptObjectOwnerIID))
{
*aInstancePtr = (void*) ((nsIScriptObjectOwner*)this);
AddRef();
return NS_OK;
}
else if ( aIID.Equals(kIInstallTrigger_IID) )
{
*aInstancePtr = (void*) ((nsIDOMInstallTriggerGlobal*)this);
AddRef();
return NS_OK;
}
else if ( aIID.Equals(kISupportsIID) )
{
*aInstancePtr = (void*)(nsISupports*)(nsIScriptObjectOwner*)this;
AddRef();
return NS_OK;
}
return NS_NOINTERFACE;
}
NS_IMPL_ADDREF(nsInstallTrigger)
NS_IMPL_RELEASE(nsInstallTrigger)
NS_IMETHODIMP
nsInstallTrigger::GetScriptObject(nsIScriptContext *aContext, void** aScriptObject)
{
NS_PRECONDITION(nsnull != aScriptObject, "null arg");
nsresult res = NS_OK;
if (nsnull == mScriptObject)
{
nsIScriptGlobalObject *global = aContext->GetGlobalObject();
res = NS_NewScriptInstallTriggerGlobal( aContext,
(nsISupports *)(nsIDOMInstallTriggerGlobal*)this,
(nsISupports *)global,
&mScriptObject);
NS_IF_RELEASE(global);
}
*aScriptObject = mScriptObject;
return res;
}
NS_IMETHODIMP
nsInstallTrigger::SetScriptObject(void *aScriptObject)
{
mScriptObject = aScriptObject;
return NS_OK;
}
NS_IMETHODIMP
nsInstallTrigger::UpdateEnabled(PRBool* aReturn)
{
PREF_GetBoolPref( AUTOUPDATE_ENABLE_PREF, aReturn);
return NS_OK;
}
NS_IMETHODIMP
nsInstallTrigger::StartSoftwareUpdate(const nsString& aURL, PRInt32* aReturn)
{
nsString location = "C:\\temp\\test.jar";
*aReturn = su_DownloadJar(aURL, location);
return NS_OK;
}
NS_IMETHODIMP
nsInstallTrigger::ConditionalSoftwareUpdate(const nsString& aURL, const nsString& aRegName, PRInt32 aDiffLevel, const nsString& aVersion, PRInt32 aMode, PRInt32* aReturn)
{
return NS_OK;
}
NS_IMETHODIMP
nsInstallTrigger::CompareVersion(const nsString& aRegName, const nsString& aVersion, PRInt32* aReturn)
{
return NS_OK;
}
/////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////
static PRInt32 gInstallTriggerInstanceCnt = 0;
static PRInt32 gInstallTriggerLock = 0;
nsInstallTriggerFactory::nsInstallTriggerFactory(void)
{
mRefCnt=0;
PR_AtomicIncrement(&gInstallTriggerInstanceCnt);
}
nsInstallTriggerFactory::~nsInstallTriggerFactory(void)
{
PR_AtomicDecrement(&gInstallTriggerInstanceCnt);
}
NS_IMETHODIMP
nsInstallTriggerFactory::QueryInterface(REFNSIID aIID,void** aInstancePtr)
{
if (aInstancePtr == NULL)
{
return NS_ERROR_NULL_POINTER;
}
// Always NULL result, in case of failure
*aInstancePtr = NULL;
if ( aIID.Equals(kISupportsIID) )
{
*aInstancePtr = (void*) this;
}
else if ( aIID.Equals(kIFactoryIID) )
{
*aInstancePtr = (void*) this;
}
if (aInstancePtr == NULL)
{
return NS_ERROR_NO_INTERFACE;
}
AddRef();
return NS_OK;
}
NS_IMETHODIMP
nsInstallTriggerFactory::AddRef(void)
{
return ++mRefCnt;
}
NS_IMETHODIMP
nsInstallTriggerFactory::Release(void)
{
if (--mRefCnt ==0)
{
delete this;
return 0; // Don't access mRefCnt after deleting!
}
return mRefCnt;
}
NS_IMETHODIMP
nsInstallTriggerFactory::CreateInstance(nsISupports *aOuter, REFNSIID aIID, void **aResult)
{
if (aResult == NULL)
{
return NS_ERROR_NULL_POINTER;
}
*aResult = NULL;
/* do I have to use iSupports? */
nsInstallTrigger *inst = new nsInstallTrigger();
if (inst == NULL)
return NS_ERROR_OUT_OF_MEMORY;
nsresult result = inst->QueryInterface(aIID, aResult);
if (result != NS_OK)
delete inst;
return result;
}
NS_IMETHODIMP
nsInstallTriggerFactory::LockFactory(PRBool aLock)
{
if (aLock)
PR_AtomicIncrement(&gInstallTriggerLock);
else
PR_AtomicDecrement(&gInstallTriggerLock);
return NS_OK;
}

Просмотреть файл

@ -0,0 +1,59 @@
#ifndef __NS_INSTALLTRIGGER_H__
#define __NS_INSTALLTRIGGER_H__
#include "nscore.h"
#include "nsString.h"
#include "nsIFactory.h"
#include "nsISupports.h"
#include "nsIScriptObjectOwner.h"
#include "nsIDOMInstallTriggerGlobal.h"
#include "nsSoftwareUpdate.h"
#include "prtypes.h"
#include "nsHashtable.h"
#include "nsVector.h"
class nsInstallTrigger: public nsIScriptObjectOwner, public nsIDOMInstallTriggerGlobal
{
public:
static const nsIID& IID() { static nsIID iid = NS_SoftwareUpdateInstallTrigger_CID; return iid; }
nsInstallTrigger();
~nsInstallTrigger();
NS_DECL_ISUPPORTS
NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject);
NS_IMETHOD SetScriptObject(void* aScriptObject);
NS_IMETHOD UpdateEnabled(PRBool* aReturn);
NS_IMETHOD StartSoftwareUpdate(const nsString& aURL, PRInt32* aReturn);
NS_IMETHOD ConditionalSoftwareUpdate(const nsString& aURL, const nsString& aRegName, PRInt32 aDiffLevel, const nsString& aVersion, PRInt32 aMode, PRInt32* aReturn);
NS_IMETHOD CompareVersion(const nsString& aRegName, const nsString& aVersion, PRInt32* aReturn);
private:
void *mScriptObject;
};
class nsInstallTriggerFactory : public nsIFactory
{
public:
nsInstallTriggerFactory();
~nsInstallTriggerFactory();
NS_DECL_ISUPPORTS
NS_IMETHOD CreateInstance(nsISupports *aOuter,
REFNSIID aIID,
void **aResult);
NS_IMETHOD LockFactory(PRBool aLock);
};
#endif

Просмотреть файл

@ -0,0 +1,434 @@
/* -*- 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 "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
* the License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*/
#include "nsSoftwareUpdate.h"
#include "nsInstallVersion.h"
#include "nsIDOMInstallVersion.h"
#include "nscore.h"
#include "nsIFactory.h"
#include "nsISupports.h"
#include "nsIScriptGlobalObject.h"
#include "pratom.h"
#include "prprf.h"
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID);
static NS_DEFINE_IID(kIInstallVersion_IID, NS_IDOMINSTALLVERSION_IID);
nsInstallVersion::nsInstallVersion()
{
mScriptObject = nsnull;
NS_INIT_REFCNT();
}
nsInstallVersion::~nsInstallVersion()
{
}
NS_IMETHODIMP
nsInstallVersion::QueryInterface(REFNSIID aIID,void** aInstancePtr)
{
if (aInstancePtr == NULL)
{
return NS_ERROR_NULL_POINTER;
}
// Always NULL result, in case of failure
*aInstancePtr = NULL;
if ( aIID.Equals(kIScriptObjectOwnerIID))
{
*aInstancePtr = (void*) ((nsIScriptObjectOwner*)this);
AddRef();
return NS_OK;
}
else if ( aIID.Equals(kIInstallVersion_IID) )
{
*aInstancePtr = (void*) ((nsIDOMInstallVersion*)this);
AddRef();
return NS_OK;
}
else if ( aIID.Equals(kISupportsIID) )
{
*aInstancePtr = (void*)(nsISupports*)(nsIScriptObjectOwner*)this;
AddRef();
return NS_OK;
}
return NS_NOINTERFACE;
}
NS_IMPL_ADDREF(nsInstallVersion)
NS_IMPL_RELEASE(nsInstallVersion)
NS_IMETHODIMP
nsInstallVersion::GetScriptObject(nsIScriptContext *aContext, void** aScriptObject)
{
NS_PRECONDITION(nsnull != aScriptObject, "null arg");
nsresult res = NS_OK;
if (nsnull == mScriptObject)
{
res = NS_NewScriptInstallVersion(aContext,
(nsISupports *)(nsIDOMInstallVersion*)this,
nsnull,
&mScriptObject);
}
*aScriptObject = mScriptObject;
return res;
}
NS_IMETHODIMP
nsInstallVersion::SetScriptObject(void *aScriptObject)
{
mScriptObject = aScriptObject;
return NS_OK;
}
// this will go away when our constructors can have parameters.
NS_IMETHODIMP
nsInstallVersion::Init(PRInt32 aMajor, PRInt32 aMinor, PRInt32 aRelease, PRInt32 aBuild)
{
major = aMajor;
minor = aMinor;
release = aRelease;
build = aBuild;
return NS_OK;
}
NS_IMETHODIMP
nsInstallVersion::Init(const nsString& version)
{
PRInt32 errorCode;
PRInt32 aMajor, aMinor, aRelease, aBuild;
major = minor = release = build = 0;
errorCode = nsInstallVersion::StringToVersionNumbers(version, &aMajor, &aMinor, &aRelease, &aBuild);
if (errorCode == NS_OK)
{
Init(aMajor, aMinor, aRelease, aBuild);
}
return NS_OK;
}
NS_IMETHODIMP
nsInstallVersion::GetMajor(PRInt32* aMajor)
{
*aMajor = major;
return NS_OK;
}
NS_IMETHODIMP
nsInstallVersion::SetMajor(PRInt32 aMajor)
{
major = aMajor;
return NS_OK;
}
NS_IMETHODIMP
nsInstallVersion::GetMinor(PRInt32* aMinor)
{
*aMinor = minor;
return NS_OK;
}
NS_IMETHODIMP
nsInstallVersion::SetMinor(PRInt32 aMinor)
{
minor = aMinor;
return NS_OK;
}
NS_IMETHODIMP
nsInstallVersion::GetRelease(PRInt32* aRelease)
{
*aRelease = release;
return NS_OK;
}
NS_IMETHODIMP
nsInstallVersion::SetRelease(PRInt32 aRelease)
{
release = aRelease;
return NS_OK;
}
NS_IMETHODIMP
nsInstallVersion::GetBuild(PRInt32* aBuild)
{
*aBuild = build;
return NS_OK;
}
NS_IMETHODIMP
nsInstallVersion::SetBuild(PRInt32 aBuild)
{
build = aBuild;
return NS_OK;
}
NS_IMETHODIMP
nsInstallVersion::CompareTo(nsIDOMInstallVersion* aVersion, PRInt32* aReturn)
{
PRInt32 aMajor, aMinor, aRelease, aBuild;
aVersion->GetMajor(&aMajor);
aVersion->GetMinor(&aMinor);
aVersion->GetRelease(&aRelease);
aVersion->GetBuild(&aBuild);
CompareTo(aMajor, aMinor, aRelease, aBuild, aReturn);
return NS_OK;
}
NS_IMETHODIMP
nsInstallVersion::CompareTo(const nsString& aAString, PRInt32* aReturn)
{
return NS_OK;
}
NS_IMETHODIMP
nsInstallVersion::CompareTo(PRInt32 aMajor, PRInt32 aMinor, PRInt32 aRelease, PRInt32 aBuild, PRInt32* aReturn)
{
int diff;
if ( major == aMajor )
{
if ( minor == aMinor )
{
if ( release == aRelease )
{
if ( build == aBuild )
diff = SU_EQUAL;
else if ( build > aBuild )
diff = SU_BLD_DIFF;
else
diff = SU_BLD_DIFF_MINUS;
}
else if ( release > aRelease )
diff = SU_REL_DIFF;
else
diff = SU_REL_DIFF_MINUS;
}
else if ( minor > aMinor )
diff = SU_MINOR_DIFF;
else
diff = SU_MINOR_DIFF_MINUS;
}
else if ( major > aMajor )
diff = SU_MAJOR_DIFF;
else
diff = SU_MAJOR_DIFF_MINUS;
*aReturn = diff;
return NS_OK;
}
NS_IMETHODIMP
nsInstallVersion::ToString(nsString& aReturn)
{
char *result=NULL;
result = PR_sprintf_append(result, "%d.%d.%d.%d", major, minor, release, build);
aReturn = result;
return NS_OK;
}
nsresult
nsInstallVersion::StringToVersionNumbers(const nsString& version, PRInt32 *aMajor, PRInt32 *aMinor, PRInt32 *aRelease, PRInt32 *aBuild)
{
PRInt32 errorCode;
int dot = version.Find('.', 0);
if ( dot == -1 )
{
*aMajor = version.ToInteger(&errorCode);
}
else
{
nsString majorStr;
version.Mid(majorStr, 0, dot);
*aMajor = majorStr.ToInteger(&errorCode);
int prev = dot+1;
dot = version.Find('.',prev);
if ( dot == -1 )
{
nsString minorStr;
version.Mid(minorStr, prev, version.Length() - prev);
*aMinor = minorStr.ToInteger(&errorCode);
}
else
{
nsString minorStr;
version.Mid(minorStr, prev, dot - prev);
*aMinor = minorStr.ToInteger(&errorCode);
prev = dot+1;
dot = version.Find('.',prev);
if ( dot == -1 )
{
nsString releaseStr;
version.Mid(releaseStr, prev, version.Length() - prev);
*aRelease = releaseStr.ToInteger(&errorCode);
}
else
{
nsString releaseStr;
version.Mid(releaseStr, prev, dot - prev);
*aRelease = releaseStr.ToInteger(&errorCode);
prev = dot+1;
if ( version.Length() > dot )
{
nsString buildStr;
version.Mid(buildStr, prev, version.Length() - prev);
*aBuild = buildStr.ToInteger(&errorCode);
}
}
}
}
return errorCode;
}
/////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////
static PRInt32 gInstallVersionInstanceCnt = 0;
static PRInt32 gInstallVersionLock = 0;
nsInstallVersionFactory::nsInstallVersionFactory(void)
{
mRefCnt=0;
PR_AtomicIncrement(&gInstallVersionInstanceCnt);
}
nsInstallVersionFactory::~nsInstallVersionFactory(void)
{
PR_AtomicDecrement(&gInstallVersionInstanceCnt);
}
NS_IMETHODIMP
nsInstallVersionFactory::QueryInterface(REFNSIID aIID,void** aInstancePtr)
{
if (aInstancePtr == NULL)
{
return NS_ERROR_NULL_POINTER;
}
// Always NULL result, in case of failure
*aInstancePtr = NULL;
if ( aIID.Equals(kISupportsIID) )
{
*aInstancePtr = (void*) this;
}
else if ( aIID.Equals(kIFactoryIID) )
{
*aInstancePtr = (void*) this;
}
if (aInstancePtr == NULL)
{
return NS_ERROR_NO_INTERFACE;
}
AddRef();
return NS_OK;
}
NS_IMETHODIMP
nsInstallVersionFactory::AddRef(void)
{
return ++mRefCnt;
}
NS_IMETHODIMP
nsInstallVersionFactory::Release(void)
{
if (--mRefCnt ==0)
{
delete this;
return 0; // Don't access mRefCnt after deleting!
}
return mRefCnt;
}
NS_IMETHODIMP
nsInstallVersionFactory::CreateInstance(nsISupports *aOuter, REFNSIID aIID, void **aResult)
{
if (aResult == NULL)
{
return NS_ERROR_NULL_POINTER;
}
*aResult = NULL;
/* do I have to use iSupports? */
nsInstallVersion *inst = new nsInstallVersion();
if (inst == NULL)
return NS_ERROR_OUT_OF_MEMORY;
nsresult result = inst->QueryInterface(aIID, aResult);
if (result != NS_OK)
delete inst;
return result;
}
NS_IMETHODIMP
nsInstallVersionFactory::LockFactory(PRBool aLock)
{
if (aLock)
PR_AtomicIncrement(&gInstallVersionLock);
else
PR_AtomicDecrement(&gInstallVersionLock);
return NS_OK;
}

Просмотреть файл

@ -0,0 +1,76 @@
#ifndef __NS_INSTALLVERSION_H__
#define __NS_INSTALLVERSION_H__
#include "nscore.h"
#include "nsString.h"
#include "nsIFactory.h"
#include "nsISupports.h"
#include "nsIScriptObjectOwner.h"
#include "nsIDOMInstallVersion.h"
#include "nsSoftwareUpdate.h"
#include "prtypes.h"
class nsInstallVersion: public nsIScriptObjectOwner, public nsIDOMInstallVersion
{
public:
static const nsIID& IID() { static nsIID iid = NS_SoftwareUpdateInstallVersion_CID; return iid; }
nsInstallVersion();
~nsInstallVersion();
NS_DECL_ISUPPORTS
NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject);
NS_IMETHOD SetScriptObject(void* aScriptObject);
NS_IMETHOD Init(PRInt32 aMajor, PRInt32 aMinor, PRInt32 aRelease, PRInt32 aBuild);
NS_IMETHOD Init(const nsString& aVersionString);
NS_IMETHOD GetMajor(PRInt32* aMajor);
NS_IMETHOD SetMajor(PRInt32 aMajor);
NS_IMETHOD GetMinor(PRInt32* aMinor);
NS_IMETHOD SetMinor(PRInt32 aMinor);
NS_IMETHOD GetRelease(PRInt32* aRelease);
NS_IMETHOD SetRelease(PRInt32 aRelease);
NS_IMETHOD GetBuild(PRInt32* aBuild);
NS_IMETHOD SetBuild(PRInt32 aBuild);
NS_IMETHOD ToString(nsString& aReturn);
NS_IMETHOD CompareTo(nsIDOMInstallVersion* aVersion, PRInt32* aReturn);
NS_IMETHOD CompareTo(PRInt32 aMajor, PRInt32 aMinor, PRInt32 aRelease, PRInt32 aBuild, PRInt32* aReturn);
NS_IMETHOD CompareTo(const nsString& aString, PRInt32* aReturn);
static nsresult StringToVersionNumbers(const nsString& version, PRInt32 *aMajor, PRInt32 *aMinor, PRInt32 *aRelease, PRInt32 *aBuild);
private:
void *mScriptObject;
PRInt32 major;
PRInt32 minor;
PRInt32 release;
PRInt32 build;
};
class nsInstallVersionFactory : public nsIFactory
{
public:
nsInstallVersionFactory();
~nsInstallVersionFactory();
NS_DECL_ISUPPORTS
NS_IMETHOD CreateInstance(nsISupports *aOuter,
REFNSIID aIID,
void **aResult);
NS_IMETHOD LockFactory(PRBool aLock);
};
#endif

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -0,0 +1,594 @@
/* -*- 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.
*/
/* AUTO-GENERATED. DO NOT EDIT!!! */
#include "jsapi.h"
#include "nsJSUtils.h"
#include "nscore.h"
#include "nsIScriptContext.h"
#include "nsIJSScriptObject.h"
#include "nsIScriptObjectOwner.h"
#include "nsIScriptGlobalObject.h"
#include "nsIPtr.h"
#include "nsString.h"
#include "nsIDOMInstallFolder.h"
#include "nsIScriptNameSpaceManager.h"
#include "nsRepository.h"
#include "nsDOMCID.h"
static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID);
static NS_DEFINE_IID(kIJSScriptObjectIID, NS_IJSSCRIPTOBJECT_IID);
static NS_DEFINE_IID(kIScriptGlobalObjectIID, NS_ISCRIPTGLOBALOBJECT_IID);
static NS_DEFINE_IID(kIInstallFolderIID, NS_IDOMINSTALLFOLDER_IID);
NS_DEF_PTR(nsIDOMInstallFolder);
/***********************************************************************/
//
// InstallFolder Properties Getter
//
PR_STATIC_CALLBACK(JSBool)
GetInstallFolderProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
{
nsIDOMInstallFolder *a = (nsIDOMInstallFolder*)JS_GetPrivate(cx, obj);
// If there's no private data, this must be the prototype, so ignore
if (nsnull == a) {
return JS_TRUE;
}
if (JSVAL_IS_INT(id)) {
switch(JSVAL_TO_INT(id)) {
case 0:
default:
return nsJSUtils::nsCallJSScriptObjectGetProperty(a, cx, id, vp);
}
}
else {
return nsJSUtils::nsCallJSScriptObjectGetProperty(a, cx, id, vp);
}
return PR_TRUE;
}
/***********************************************************************/
//
// InstallFolder Properties Setter
//
PR_STATIC_CALLBACK(JSBool)
SetInstallFolderProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
{
nsIDOMInstallFolder *a = (nsIDOMInstallFolder*)JS_GetPrivate(cx, obj);
// If there's no private data, this must be the prototype, so ignore
if (nsnull == a) {
return JS_TRUE;
}
if (JSVAL_IS_INT(id)) {
switch(JSVAL_TO_INT(id)) {
case 0:
default:
return nsJSUtils::nsCallJSScriptObjectSetProperty(a, cx, id, vp);
}
}
else {
return nsJSUtils::nsCallJSScriptObjectSetProperty(a, cx, id, vp);
}
return PR_TRUE;
}
//
// InstallFolder finalizer
//
PR_STATIC_CALLBACK(void)
FinalizeInstallFolder(JSContext *cx, JSObject *obj)
{
nsJSUtils::nsGenericFinalize(cx, obj);
}
//
// InstallFolder enumerate
//
PR_STATIC_CALLBACK(JSBool)
EnumerateInstallFolder(JSContext *cx, JSObject *obj)
{
return nsJSUtils::nsGenericEnumerate(cx, obj);
}
//
// InstallFolder resolve
//
PR_STATIC_CALLBACK(JSBool)
ResolveInstallFolder(JSContext *cx, JSObject *obj, jsval id)
{
return nsJSUtils::nsGenericResolve(cx, obj, id);
}
//
// Native method Init
//
PR_STATIC_CALLBACK(JSBool)
InstallFolderInit(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMInstallFolder *nativeThis = (nsIDOMInstallFolder*)JS_GetPrivate(cx, obj);
JSBool rBool = JS_FALSE;
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) {
nsJSUtils::nsConvertJSValToString(b0, cx, argv[0]);
nsJSUtils::nsConvertJSValToString(b1, cx, argv[1]);
nsJSUtils::nsConvertJSValToString(b2, cx, argv[2]);
if (NS_OK != nativeThis->Init(b0, b1, b2)) {
return JS_FALSE;
}
*rval = JSVAL_VOID;
}
else {
JS_ReportError(cx, "Function init requires 3 parameters");
return JS_FALSE;
}
return JS_TRUE;
}
//
// Native method GetDirectoryPath
//
PR_STATIC_CALLBACK(JSBool)
InstallFolderGetDirectoryPath(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMInstallFolder *nativeThis = (nsIDOMInstallFolder*)JS_GetPrivate(cx, obj);
JSBool rBool = JS_FALSE;
nsAutoString b0;
*rval = JSVAL_NULL;
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
if (argc >= 1) {
nsJSUtils::nsConvertJSValToString(b0, cx, argv[0]);
if (NS_OK != nativeThis->GetDirectoryPath(b0)) {
return JS_FALSE;
}
*rval = JSVAL_VOID;
}
else {
JS_ReportError(cx, "Function GetDirectoryPath requires 1 parameters");
return JS_FALSE;
}
return JS_TRUE;
}
//
// Native method MakeFullPath
//
PR_STATIC_CALLBACK(JSBool)
InstallFolderMakeFullPath(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMInstallFolder *nativeThis = (nsIDOMInstallFolder*)JS_GetPrivate(cx, obj);
JSBool rBool = JS_FALSE;
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) {
nsJSUtils::nsConvertJSValToString(b0, cx, argv[0]);
nsJSUtils::nsConvertJSValToString(b1, cx, argv[1]);
if (NS_OK != nativeThis->MakeFullPath(b0, b1)) {
return JS_FALSE;
}
*rval = JSVAL_VOID;
}
else {
JS_ReportError(cx, "Function MakeFullPath requires 2 parameters");
return JS_FALSE;
}
return JS_TRUE;
}
//
// Native method IsJavaCapable
//
PR_STATIC_CALLBACK(JSBool)
InstallFolderIsJavaCapable(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMInstallFolder *nativeThis = (nsIDOMInstallFolder*)JS_GetPrivate(cx, obj);
JSBool rBool = JS_FALSE;
PRBool nativeRet;
*rval = JSVAL_NULL;
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
if (argc >= 0) {
if (NS_OK != nativeThis->IsJavaCapable(&nativeRet)) {
return JS_FALSE;
}
*rval = BOOLEAN_TO_JSVAL(nativeRet);
}
else {
JS_ReportError(cx, "Function IsJavaCapable requires 0 parameters");
return JS_FALSE;
}
return JS_TRUE;
}
//
// Native method ToString
//
PR_STATIC_CALLBACK(JSBool)
InstallFolderToString(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMInstallFolder *nativeThis = (nsIDOMInstallFolder*)JS_GetPrivate(cx, obj);
JSBool rBool = JS_FALSE;
nsAutoString b0;
*rval = JSVAL_NULL;
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
if (argc >= 1) {
nsJSUtils::nsConvertJSValToString(b0, cx, argv[0]);
if (NS_OK != nativeThis->ToString(b0)) {
return JS_FALSE;
}
*rval = JSVAL_VOID;
}
else {
JS_ReportError(cx, "Function ToString requires 1 parameters");
return JS_FALSE;
}
return JS_TRUE;
}
/***********************************************************************/
//
// class for InstallFolder
//
JSClass InstallFolderClass = {
"InstallFolder",
JSCLASS_HAS_PRIVATE,
JS_PropertyStub,
JS_PropertyStub,
GetInstallFolderProperty,
SetInstallFolderProperty,
EnumerateInstallFolder,
ResolveInstallFolder,
JS_ConvertStub,
FinalizeInstallFolder
};
//
// InstallFolder class properties
//
static JSPropertySpec InstallFolderProperties[] =
{
{0}
};
//
// InstallFolder class methods
//
static JSFunctionSpec InstallFolderMethods[] =
{
{"init", InstallFolderInit, 3},
{"GetDirectoryPath", InstallFolderGetDirectoryPath, 1},
{"MakeFullPath", InstallFolderMakeFullPath, 2},
{"IsJavaCapable", InstallFolderIsJavaCapable, 0},
{"ToString", InstallFolderToString, 1},
{0}
};
//
// InstallFolder constructor
//
PR_STATIC_CALLBACK(JSBool)
InstallFolder(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsresult result;
nsIID classID;
nsIScriptContext* context = (nsIScriptContext*)JS_GetContextPrivate(cx);
nsIScriptNameSpaceManager* manager;
nsIDOMInstallFolder *nativeThis;
nsIScriptObjectOwner *owner = nsnull;
static NS_DEFINE_IID(kIDOMInstallFolderIID, NS_IDOMINSTALLFOLDER_IID);
result = context->GetNameSpaceManager(&manager);
if (NS_OK != result) {
return JS_FALSE;
}
result = manager->LookupName("InstallFolder", PR_TRUE, classID);
NS_RELEASE(manager);
if (NS_OK != result) {
return JS_FALSE;
}
result = nsRepository::CreateInstance(classID,
nsnull,
kIDOMInstallFolderIID,
(void **)&nativeThis);
if (NS_OK != result) {
return JS_FALSE;
}
// XXX We should be calling Init() on the instance
result = nativeThis->QueryInterface(kIScriptObjectOwnerIID, (void **)&owner);
if (NS_OK != result) {
NS_RELEASE(nativeThis);
return JS_FALSE;
}
owner->SetScriptObject((void *)obj);
JS_SetPrivate(cx, obj, nativeThis);
NS_RELEASE(owner);
return JS_TRUE;
}
//
// InstallFolder class initialization
//
nsresult NS_InitInstallFolderClass(nsIScriptContext *aContext, void **aPrototype)
{
JSContext *jscontext = (JSContext *)aContext->GetNativeContext();
JSObject *proto = nsnull;
JSObject *constructor = nsnull;
JSObject *parent_proto = nsnull;
JSObject *global = JS_GetGlobalObject(jscontext);
jsval vp;
if ((PR_TRUE != JS_LookupProperty(jscontext, global, "InstallFolder", &vp)) ||
!JSVAL_IS_OBJECT(vp) ||
((constructor = JSVAL_TO_OBJECT(vp)) == nsnull) ||
(PR_TRUE != JS_LookupProperty(jscontext, JSVAL_TO_OBJECT(vp), "prototype", &vp)) ||
!JSVAL_IS_OBJECT(vp)) {
proto = JS_InitClass(jscontext, // context
global, // global object
parent_proto, // parent proto
&InstallFolderClass, // JSClass
InstallFolder, // JSNative ctor
0, // ctor args
InstallFolderProperties, // proto props
InstallFolderMethods, // proto funcs
nsnull, // ctor props (static)
nsnull); // ctor funcs (static)
if (nsnull == proto) {
return NS_ERROR_FAILURE;
}
if ((PR_TRUE == JS_LookupProperty(jscontext, global, "InstallFolder", &vp)) &&
JSVAL_IS_OBJECT(vp) &&
((constructor = JSVAL_TO_OBJECT(vp)) != nsnull)) {
vp = INT_TO_JSVAL(nsIDOMInstallFolder::BadFolder);
JS_SetProperty(jscontext, constructor, "BadFolder", &vp);
vp = INT_TO_JSVAL(nsIDOMInstallFolder::PluginFolder);
JS_SetProperty(jscontext, constructor, "PluginFolder", &vp);
vp = INT_TO_JSVAL(nsIDOMInstallFolder::ProgramFolder);
JS_SetProperty(jscontext, constructor, "ProgramFolder", &vp);
vp = INT_TO_JSVAL(nsIDOMInstallFolder::PackageFolder);
JS_SetProperty(jscontext, constructor, "PackageFolder", &vp);
vp = INT_TO_JSVAL(nsIDOMInstallFolder::TemporaryFolder);
JS_SetProperty(jscontext, constructor, "TemporaryFolder", &vp);
vp = INT_TO_JSVAL(nsIDOMInstallFolder::CommunicatorFolder);
JS_SetProperty(jscontext, constructor, "CommunicatorFolder", &vp);
vp = INT_TO_JSVAL(nsIDOMInstallFolder::InstalledFolder);
JS_SetProperty(jscontext, constructor, "InstalledFolder", &vp);
vp = INT_TO_JSVAL(nsIDOMInstallFolder::CurrentUserFolder);
JS_SetProperty(jscontext, constructor, "CurrentUserFolder", &vp);
vp = INT_TO_JSVAL(nsIDOMInstallFolder::NetHelpFolder);
JS_SetProperty(jscontext, constructor, "NetHelpFolder", &vp);
vp = INT_TO_JSVAL(nsIDOMInstallFolder::OSDriveFolder);
JS_SetProperty(jscontext, constructor, "OSDriveFolder", &vp);
vp = INT_TO_JSVAL(nsIDOMInstallFolder::FileURLFolder);
JS_SetProperty(jscontext, constructor, "FileURLFolder", &vp);
vp = INT_TO_JSVAL(nsIDOMInstallFolder::JavaBinFolder);
JS_SetProperty(jscontext, constructor, "JavaBinFolder", &vp);
vp = INT_TO_JSVAL(nsIDOMInstallFolder::JavaClassesFolder);
JS_SetProperty(jscontext, constructor, "JavaClassesFolder", &vp);
vp = INT_TO_JSVAL(nsIDOMInstallFolder::JavaDownloadFolder);
JS_SetProperty(jscontext, constructor, "JavaDownloadFolder", &vp);
vp = INT_TO_JSVAL(nsIDOMInstallFolder::Win_WindowsFolder);
JS_SetProperty(jscontext, constructor, "Win_WindowsFolder", &vp);
vp = INT_TO_JSVAL(nsIDOMInstallFolder::Win_SystemFolder);
JS_SetProperty(jscontext, constructor, "Win_SystemFolder", &vp);
vp = INT_TO_JSVAL(nsIDOMInstallFolder::Win_System16Folder);
JS_SetProperty(jscontext, constructor, "Win_System16Folder", &vp);
vp = INT_TO_JSVAL(nsIDOMInstallFolder::Mac_SystemFolder);
JS_SetProperty(jscontext, constructor, "Mac_SystemFolder", &vp);
vp = INT_TO_JSVAL(nsIDOMInstallFolder::Mac_DesktopFolder);
JS_SetProperty(jscontext, constructor, "Mac_DesktopFolder", &vp);
vp = INT_TO_JSVAL(nsIDOMInstallFolder::Mac_TrashFolder);
JS_SetProperty(jscontext, constructor, "Mac_TrashFolder", &vp);
vp = INT_TO_JSVAL(nsIDOMInstallFolder::Mac_StartupFolder);
JS_SetProperty(jscontext, constructor, "Mac_StartupFolder", &vp);
vp = INT_TO_JSVAL(nsIDOMInstallFolder::Mac_ShutdownFolder);
JS_SetProperty(jscontext, constructor, "Mac_ShutdownFolder", &vp);
vp = INT_TO_JSVAL(nsIDOMInstallFolder::Mac_AppleMenuFolder);
JS_SetProperty(jscontext, constructor, "Mac_AppleMenuFolder", &vp);
vp = INT_TO_JSVAL(nsIDOMInstallFolder::Mac_ControlPanelFolder);
JS_SetProperty(jscontext, constructor, "Mac_ControlPanelFolder", &vp);
vp = INT_TO_JSVAL(nsIDOMInstallFolder::Mac_ExtensionFolder);
JS_SetProperty(jscontext, constructor, "Mac_ExtensionFolder", &vp);
vp = INT_TO_JSVAL(nsIDOMInstallFolder::Mac_FontsFolder);
JS_SetProperty(jscontext, constructor, "Mac_FontsFolder", &vp);
vp = INT_TO_JSVAL(nsIDOMInstallFolder::Mac_PreferencesFolder);
JS_SetProperty(jscontext, constructor, "Mac_PreferencesFolder", &vp);
vp = INT_TO_JSVAL(nsIDOMInstallFolder::Unix_LocalFolder);
JS_SetProperty(jscontext, constructor, "Unix_LocalFolder", &vp);
vp = INT_TO_JSVAL(nsIDOMInstallFolder::Unix_LibFolder);
JS_SetProperty(jscontext, constructor, "Unix_LibFolder", &vp);
}
}
else if ((nsnull != constructor) && JSVAL_IS_OBJECT(vp)) {
proto = JSVAL_TO_OBJECT(vp);
}
else {
return NS_ERROR_FAILURE;
}
if (aPrototype) {
*aPrototype = proto;
}
return NS_OK;
}
//
// Method for creating a new InstallFolder JavaScript object
//
extern "C" NS_DOM nsresult NS_NewScriptInstallFolder(nsIScriptContext *aContext, nsISupports *aSupports, nsISupports *aParent, void **aReturn)
{
NS_PRECONDITION(nsnull != aContext && nsnull != aSupports && nsnull != aReturn, "null argument to NS_NewScriptInstallFolder");
JSObject *proto;
JSObject *parent;
nsIScriptObjectOwner *owner;
JSContext *jscontext = (JSContext *)aContext->GetNativeContext();
nsresult result = NS_OK;
nsIDOMInstallFolder *aInstallFolder;
if (nsnull == aParent) {
parent = nsnull;
}
else if (NS_OK == aParent->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) {
if (NS_OK != owner->GetScriptObject(aContext, (void **)&parent)) {
NS_RELEASE(owner);
return NS_ERROR_FAILURE;
}
NS_RELEASE(owner);
}
else {
return NS_ERROR_FAILURE;
}
if (NS_OK != NS_InitInstallFolderClass(aContext, (void **)&proto)) {
return NS_ERROR_FAILURE;
}
result = aSupports->QueryInterface(kIInstallFolderIID, (void **)&aInstallFolder);
if (NS_OK != result) {
return result;
}
// create a js object for this class
*aReturn = JS_NewObject(jscontext, &InstallFolderClass, proto, parent);
if (nsnull != *aReturn) {
// connect the native object to the js object
JS_SetPrivate(jscontext, (JSObject *)*aReturn, aInstallFolder);
}
else {
NS_RELEASE(aInstallFolder);
return NS_ERROR_FAILURE;
}
return NS_OK;
}

Просмотреть файл

@ -0,0 +1,458 @@
/* -*- 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.
*/
/* AUTO-GENERATED. DO NOT EDIT!!! */
#include "jsapi.h"
#include "nsJSUtils.h"
#include "nscore.h"
#include "nsIScriptContext.h"
#include "nsIJSScriptObject.h"
#include "nsIScriptObjectOwner.h"
#include "nsIScriptGlobalObject.h"
#include "nsIPtr.h"
#include "nsString.h"
#include "nsIDOMInstallTriggerGlobal.h"
static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID);
static NS_DEFINE_IID(kIJSScriptObjectIID, NS_IJSSCRIPTOBJECT_IID);
static NS_DEFINE_IID(kIScriptGlobalObjectIID, NS_ISCRIPTGLOBALOBJECT_IID);
static NS_DEFINE_IID(kIInstallTriggerGlobalIID, NS_IDOMINSTALLTRIGGERGLOBAL_IID);
NS_DEF_PTR(nsIDOMInstallTriggerGlobal);
/***********************************************************************/
//
// InstallTriggerGlobal Properties Getter
//
PR_STATIC_CALLBACK(JSBool)
GetInstallTriggerGlobalProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
{
nsIDOMInstallTriggerGlobal *a = (nsIDOMInstallTriggerGlobal*)JS_GetPrivate(cx, obj);
// If there's no private data, this must be the prototype, so ignore
if (nsnull == a) {
return JS_TRUE;
}
if (JSVAL_IS_INT(id)) {
switch(JSVAL_TO_INT(id)) {
case 0:
default:
return nsJSUtils::nsCallJSScriptObjectGetProperty(a, cx, id, vp);
}
}
else {
return nsJSUtils::nsCallJSScriptObjectGetProperty(a, cx, id, vp);
}
return PR_TRUE;
}
/***********************************************************************/
//
// InstallTriggerGlobal Properties Setter
//
PR_STATIC_CALLBACK(JSBool)
SetInstallTriggerGlobalProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
{
nsIDOMInstallTriggerGlobal *a = (nsIDOMInstallTriggerGlobal*)JS_GetPrivate(cx, obj);
// If there's no private data, this must be the prototype, so ignore
if (nsnull == a) {
return JS_TRUE;
}
if (JSVAL_IS_INT(id)) {
switch(JSVAL_TO_INT(id)) {
case 0:
default:
return nsJSUtils::nsCallJSScriptObjectSetProperty(a, cx, id, vp);
}
}
else {
return nsJSUtils::nsCallJSScriptObjectSetProperty(a, cx, id, vp);
}
return PR_TRUE;
}
//
// InstallTriggerGlobal finalizer
//
PR_STATIC_CALLBACK(void)
FinalizeInstallTriggerGlobal(JSContext *cx, JSObject *obj)
{
nsJSUtils::nsGenericFinalize(cx, obj);
}
//
// InstallTriggerGlobal enumerate
//
PR_STATIC_CALLBACK(JSBool)
EnumerateInstallTriggerGlobal(JSContext *cx, JSObject *obj)
{
return nsJSUtils::nsGenericEnumerate(cx, obj);
}
//
// InstallTriggerGlobal resolve
//
PR_STATIC_CALLBACK(JSBool)
ResolveInstallTriggerGlobal(JSContext *cx, JSObject *obj, jsval id)
{
return nsJSUtils::nsGenericResolve(cx, obj, id);
}
//
// Native method UpdateEnabled
//
PR_STATIC_CALLBACK(JSBool)
InstallTriggerGlobalUpdateEnabled(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMInstallTriggerGlobal *nativeThis = (nsIDOMInstallTriggerGlobal*)JS_GetPrivate(cx, obj);
JSBool rBool = JS_FALSE;
PRBool nativeRet;
*rval = JSVAL_NULL;
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
if (argc >= 0) {
if (NS_OK != nativeThis->UpdateEnabled(&nativeRet)) {
return JS_FALSE;
}
*rval = BOOLEAN_TO_JSVAL(nativeRet);
}
else {
JS_ReportError(cx, "Function UpdateEnabled requires 0 parameters");
return JS_FALSE;
}
return JS_TRUE;
}
//
// Native method StartSoftwareUpdate
//
PR_STATIC_CALLBACK(JSBool)
InstallTriggerGlobalStartSoftwareUpdate(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMInstallTriggerGlobal *nativeThis = (nsIDOMInstallTriggerGlobal*)JS_GetPrivate(cx, obj);
JSBool rBool = JS_FALSE;
PRInt32 nativeRet;
nsAutoString b0;
*rval = JSVAL_NULL;
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
if (argc >= 1) {
nsJSUtils::nsConvertJSValToString(b0, cx, argv[0]);
if (NS_OK != nativeThis->StartSoftwareUpdate(b0, &nativeRet)) {
return JS_FALSE;
}
*rval = INT_TO_JSVAL(nativeRet);
}
else {
JS_ReportError(cx, "Function StartSoftwareUpdate requires 1 parameters");
return JS_FALSE;
}
return JS_TRUE;
}
//
// Native method ConditionalSoftwareUpdate
//
PR_STATIC_CALLBACK(JSBool)
InstallTriggerGlobalConditionalSoftwareUpdate(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMInstallTriggerGlobal *nativeThis = (nsIDOMInstallTriggerGlobal*)JS_GetPrivate(cx, obj);
JSBool rBool = JS_FALSE;
PRInt32 nativeRet;
nsAutoString b0;
nsAutoString b1;
PRInt32 b2;
nsAutoString b3;
PRInt32 b4;
*rval = JSVAL_NULL;
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
if (argc >= 5) {
nsJSUtils::nsConvertJSValToString(b0, cx, argv[0]);
nsJSUtils::nsConvertJSValToString(b1, cx, argv[1]);
if (!JS_ValueToInt32(cx, argv[2], (int32 *)&b2)) {
JS_ReportError(cx, "Parameter must be a number");
return JS_FALSE;
}
nsJSUtils::nsConvertJSValToString(b3, cx, argv[3]);
if (!JS_ValueToInt32(cx, argv[4], (int32 *)&b4)) {
JS_ReportError(cx, "Parameter must be a number");
return JS_FALSE;
}
if (NS_OK != nativeThis->ConditionalSoftwareUpdate(b0, b1, b2, b3, b4, &nativeRet)) {
return JS_FALSE;
}
*rval = INT_TO_JSVAL(nativeRet);
}
else {
JS_ReportError(cx, "Function ConditionalSoftwareUpdate requires 5 parameters");
return JS_FALSE;
}
return JS_TRUE;
}
//
// Native method CompareVersion
//
PR_STATIC_CALLBACK(JSBool)
InstallTriggerGlobalCompareVersion(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMInstallTriggerGlobal *nativeThis = (nsIDOMInstallTriggerGlobal*)JS_GetPrivate(cx, obj);
JSBool rBool = JS_FALSE;
PRInt32 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) {
nsJSUtils::nsConvertJSValToString(b0, cx, argv[0]);
nsJSUtils::nsConvertJSValToString(b1, cx, argv[1]);
if (NS_OK != nativeThis->CompareVersion(b0, b1, &nativeRet)) {
return JS_FALSE;
}
*rval = INT_TO_JSVAL(nativeRet);
}
else {
JS_ReportError(cx, "Function CompareVersion requires 2 parameters");
return JS_FALSE;
}
return JS_TRUE;
}
/***********************************************************************/
//
// class for InstallTriggerGlobal
//
JSClass InstallTriggerGlobalClass = {
"InstallTriggerGlobal",
JSCLASS_HAS_PRIVATE,
JS_PropertyStub,
JS_PropertyStub,
GetInstallTriggerGlobalProperty,
SetInstallTriggerGlobalProperty,
EnumerateInstallTriggerGlobal,
ResolveInstallTriggerGlobal,
JS_ConvertStub,
FinalizeInstallTriggerGlobal
};
//
// InstallTriggerGlobal class properties
//
static JSPropertySpec InstallTriggerGlobalProperties[] =
{
{0}
};
//
// InstallTriggerGlobal class methods
//
static JSFunctionSpec InstallTriggerGlobalMethods[] =
{
{"UpdateEnabled", InstallTriggerGlobalUpdateEnabled, 0},
{"StartSoftwareUpdate", InstallTriggerGlobalStartSoftwareUpdate, 1},
{"ConditionalSoftwareUpdate", InstallTriggerGlobalConditionalSoftwareUpdate, 5},
{"CompareVersion", InstallTriggerGlobalCompareVersion, 2},
{0}
};
//
// InstallTriggerGlobal constructor
//
PR_STATIC_CALLBACK(JSBool)
InstallTriggerGlobal(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
return JS_FALSE;
}
//
// InstallTriggerGlobal class initialization
//
nsresult NS_InitInstallTriggerGlobalClass(nsIScriptContext *aContext, void **aPrototype)
{
JSContext *jscontext = (JSContext *)aContext->GetNativeContext();
JSObject *proto = nsnull;
JSObject *constructor = nsnull;
JSObject *parent_proto = nsnull;
JSObject *global = JS_GetGlobalObject(jscontext);
jsval vp;
if ((PR_TRUE != JS_LookupProperty(jscontext, global, "InstallTriggerGlobal", &vp)) ||
!JSVAL_IS_OBJECT(vp) ||
((constructor = JSVAL_TO_OBJECT(vp)) == nsnull) ||
(PR_TRUE != JS_LookupProperty(jscontext, JSVAL_TO_OBJECT(vp), "prototype", &vp)) ||
!JSVAL_IS_OBJECT(vp)) {
proto = JS_InitClass(jscontext, // context
global, // global object
parent_proto, // parent proto
&InstallTriggerGlobalClass, // JSClass
InstallTriggerGlobal, // JSNative ctor
0, // ctor args
InstallTriggerGlobalProperties, // proto props
InstallTriggerGlobalMethods, // proto funcs
nsnull, // ctor props (static)
nsnull); // ctor funcs (static)
if (nsnull == proto) {
return NS_ERROR_FAILURE;
}
if ((PR_TRUE == JS_LookupProperty(jscontext, global, "InstallTriggerGlobal", &vp)) &&
JSVAL_IS_OBJECT(vp) &&
((constructor = JSVAL_TO_OBJECT(vp)) != nsnull)) {
vp = INT_TO_JSVAL(nsIDOMInstallTriggerGlobal::MAJOR_DIFF);
JS_SetProperty(jscontext, constructor, "MAJOR_DIFF", &vp);
vp = INT_TO_JSVAL(nsIDOMInstallTriggerGlobal::MINOR_DIFF);
JS_SetProperty(jscontext, constructor, "MINOR_DIFF", &vp);
vp = INT_TO_JSVAL(nsIDOMInstallTriggerGlobal::REL_DIFF);
JS_SetProperty(jscontext, constructor, "REL_DIFF", &vp);
vp = INT_TO_JSVAL(nsIDOMInstallTriggerGlobal::BLD_DIFF);
JS_SetProperty(jscontext, constructor, "BLD_DIFF", &vp);
vp = INT_TO_JSVAL(nsIDOMInstallTriggerGlobal::EQUAL);
JS_SetProperty(jscontext, constructor, "EQUAL", &vp);
}
}
else if ((nsnull != constructor) && JSVAL_IS_OBJECT(vp)) {
proto = JSVAL_TO_OBJECT(vp);
}
else {
return NS_ERROR_FAILURE;
}
if (aPrototype) {
*aPrototype = proto;
}
return NS_OK;
}
//
// Method for creating a new InstallTriggerGlobal JavaScript object
//
extern "C" NS_DOM nsresult NS_NewScriptInstallTriggerGlobal(nsIScriptContext *aContext, nsISupports *aSupports, nsISupports *aParent, void **aReturn)
{
NS_PRECONDITION(nsnull != aContext && nsnull != aSupports && nsnull != aReturn, "null argument to NS_NewScriptInstallTriggerGlobal");
JSObject *proto;
JSObject *parent;
nsIScriptObjectOwner *owner;
JSContext *jscontext = (JSContext *)aContext->GetNativeContext();
nsresult result = NS_OK;
nsIDOMInstallTriggerGlobal *aInstallTriggerGlobal;
if (nsnull == aParent) {
parent = nsnull;
}
else if (NS_OK == aParent->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) {
if (NS_OK != owner->GetScriptObject(aContext, (void **)&parent)) {
NS_RELEASE(owner);
return NS_ERROR_FAILURE;
}
NS_RELEASE(owner);
}
else {
return NS_ERROR_FAILURE;
}
if (NS_OK != NS_InitInstallTriggerGlobalClass(aContext, (void **)&proto)) {
return NS_ERROR_FAILURE;
}
result = aSupports->QueryInterface(kIInstallTriggerGlobalIID, (void **)&aInstallTriggerGlobal);
if (NS_OK != result) {
return result;
}
// create a js object for this class
*aReturn = JS_NewObject(jscontext, &InstallTriggerGlobalClass, proto, parent);
if (nsnull != *aReturn) {
// connect the native object to the js object
JS_SetPrivate(jscontext, (JSObject *)*aReturn, aInstallTriggerGlobal);
}
else {
NS_RELEASE(aInstallTriggerGlobal);
return NS_ERROR_FAILURE;
}
return NS_OK;
}

Просмотреть файл

@ -0,0 +1,577 @@
/* -*- 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.
*/
/* AUTO-GENERATED. DO NOT EDIT!!! */
#include "jsapi.h"
#include "nsJSUtils.h"
#include "nscore.h"
#include "nsIScriptContext.h"
#include "nsIJSScriptObject.h"
#include "nsIScriptObjectOwner.h"
#include "nsIScriptGlobalObject.h"
#include "nsIPtr.h"
#include "nsString.h"
#include "nsIDOMInstallVersion.h"
#include "nsIScriptNameSpaceManager.h"
#include "nsRepository.h"
#include "nsDOMCID.h"
static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID);
static NS_DEFINE_IID(kIJSScriptObjectIID, NS_IJSSCRIPTOBJECT_IID);
static NS_DEFINE_IID(kIScriptGlobalObjectIID, NS_ISCRIPTGLOBALOBJECT_IID);
static NS_DEFINE_IID(kIInstallVersionIID, NS_IDOMINSTALLVERSION_IID);
NS_DEF_PTR(nsIDOMInstallVersion);
//
// InstallVersion property ids
//
enum InstallVersion_slots {
INSTALLVERSION_MAJOR = -1,
INSTALLVERSION_MINOR = -2,
INSTALLVERSION_RELEASE = -3,
INSTALLVERSION_BUILD = -4
};
/***********************************************************************/
//
// InstallVersion Properties Getter
//
PR_STATIC_CALLBACK(JSBool)
GetInstallVersionProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
{
nsIDOMInstallVersion *a = (nsIDOMInstallVersion*)JS_GetPrivate(cx, obj);
// If there's no private data, this must be the prototype, so ignore
if (nsnull == a) {
return JS_TRUE;
}
if (JSVAL_IS_INT(id)) {
switch(JSVAL_TO_INT(id)) {
case INSTALLVERSION_MAJOR:
{
PRInt32 prop;
if (NS_OK == a->GetMajor(&prop)) {
*vp = INT_TO_JSVAL(prop);
}
else {
return JS_FALSE;
}
break;
}
case INSTALLVERSION_MINOR:
{
PRInt32 prop;
if (NS_OK == a->GetMinor(&prop)) {
*vp = INT_TO_JSVAL(prop);
}
else {
return JS_FALSE;
}
break;
}
case INSTALLVERSION_RELEASE:
{
PRInt32 prop;
if (NS_OK == a->GetRelease(&prop)) {
*vp = INT_TO_JSVAL(prop);
}
else {
return JS_FALSE;
}
break;
}
case INSTALLVERSION_BUILD:
{
PRInt32 prop;
if (NS_OK == a->GetBuild(&prop)) {
*vp = INT_TO_JSVAL(prop);
}
else {
return JS_FALSE;
}
break;
}
default:
return nsJSUtils::nsCallJSScriptObjectGetProperty(a, cx, id, vp);
}
}
else {
return nsJSUtils::nsCallJSScriptObjectGetProperty(a, cx, id, vp);
}
return PR_TRUE;
}
/***********************************************************************/
//
// InstallVersion Properties Setter
//
PR_STATIC_CALLBACK(JSBool)
SetInstallVersionProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
{
nsIDOMInstallVersion *a = (nsIDOMInstallVersion*)JS_GetPrivate(cx, obj);
// If there's no private data, this must be the prototype, so ignore
if (nsnull == a) {
return JS_TRUE;
}
if (JSVAL_IS_INT(id)) {
switch(JSVAL_TO_INT(id)) {
case INSTALLVERSION_MAJOR:
{
PRInt32 prop;
int32 temp;
if (JSVAL_IS_NUMBER(*vp) && JS_ValueToInt32(cx, *vp, &temp)) {
prop = (PRInt32)temp;
}
else {
JS_ReportError(cx, "Parameter must be a number");
return JS_FALSE;
}
a->SetMajor(prop);
break;
}
case INSTALLVERSION_MINOR:
{
PRInt32 prop;
int32 temp;
if (JSVAL_IS_NUMBER(*vp) && JS_ValueToInt32(cx, *vp, &temp)) {
prop = (PRInt32)temp;
}
else {
JS_ReportError(cx, "Parameter must be a number");
return JS_FALSE;
}
a->SetMinor(prop);
break;
}
case INSTALLVERSION_RELEASE:
{
PRInt32 prop;
int32 temp;
if (JSVAL_IS_NUMBER(*vp) && JS_ValueToInt32(cx, *vp, &temp)) {
prop = (PRInt32)temp;
}
else {
JS_ReportError(cx, "Parameter must be a number");
return JS_FALSE;
}
a->SetRelease(prop);
break;
}
case INSTALLVERSION_BUILD:
{
PRInt32 prop;
int32 temp;
if (JSVAL_IS_NUMBER(*vp) && JS_ValueToInt32(cx, *vp, &temp)) {
prop = (PRInt32)temp;
}
else {
JS_ReportError(cx, "Parameter must be a number");
return JS_FALSE;
}
a->SetBuild(prop);
break;
}
default:
return nsJSUtils::nsCallJSScriptObjectSetProperty(a, cx, id, vp);
}
}
else {
return nsJSUtils::nsCallJSScriptObjectSetProperty(a, cx, id, vp);
}
return PR_TRUE;
}
//
// InstallVersion finalizer
//
PR_STATIC_CALLBACK(void)
FinalizeInstallVersion(JSContext *cx, JSObject *obj)
{
nsJSUtils::nsGenericFinalize(cx, obj);
}
//
// InstallVersion enumerate
//
PR_STATIC_CALLBACK(JSBool)
EnumerateInstallVersion(JSContext *cx, JSObject *obj)
{
return nsJSUtils::nsGenericEnumerate(cx, obj);
}
//
// InstallVersion resolve
//
PR_STATIC_CALLBACK(JSBool)
ResolveInstallVersion(JSContext *cx, JSObject *obj, jsval id)
{
return nsJSUtils::nsGenericResolve(cx, obj, id);
}
//
// Native method Init
//
PR_STATIC_CALLBACK(JSBool)
InstallVersionInit(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMInstallVersion *nativeThis = (nsIDOMInstallVersion*)JS_GetPrivate(cx, obj);
JSBool rBool = JS_FALSE;
nsAutoString b0;
*rval = JSVAL_NULL;
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
if (argc >= 1) {
nsJSUtils::nsConvertJSValToString(b0, cx, argv[0]);
if (NS_OK != nativeThis->Init(b0)) {
return JS_FALSE;
}
*rval = JSVAL_VOID;
}
else {
JS_ReportError(cx, "Function init requires 1 parameters");
return JS_FALSE;
}
return JS_TRUE;
}
//
// Native method ToString
//
PR_STATIC_CALLBACK(JSBool)
InstallVersionToString(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMInstallVersion *nativeThis = (nsIDOMInstallVersion*)JS_GetPrivate(cx, obj);
JSBool rBool = JS_FALSE;
nsAutoString nativeRet;
*rval = JSVAL_NULL;
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
if (argc >= 0) {
if (NS_OK != nativeThis->ToString(nativeRet)) {
return JS_FALSE;
}
nsJSUtils::nsConvertStringToJSVal(nativeRet, cx, rval);
}
else {
JS_ReportError(cx, "Function toString requires 0 parameters");
return JS_FALSE;
}
return JS_TRUE;
}
//
// Native method CompareTo
//
PR_STATIC_CALLBACK(JSBool)
InstallVersionCompareTo(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMInstallVersion *nativeThis = (nsIDOMInstallVersion*)JS_GetPrivate(cx, obj);
JSBool rBool = JS_FALSE;
PRInt32 nativeRet;
nsIDOMInstallVersionPtr b0;
*rval = JSVAL_NULL;
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
if (argc >= 1) {
if (JS_FALSE == nsJSUtils::nsConvertJSValToObject((nsISupports **)&b0,
kIInstallVersionIID,
"InstallVersion",
cx,
argv[0])) {
return JS_FALSE;
}
if (NS_OK != nativeThis->CompareTo(b0, &nativeRet)) {
return JS_FALSE;
}
*rval = INT_TO_JSVAL(nativeRet);
}
else {
JS_ReportError(cx, "Function compareTo requires 1 parameters");
return JS_FALSE;
}
return JS_TRUE;
}
/***********************************************************************/
//
// class for InstallVersion
//
JSClass InstallVersionClass = {
"InstallVersion",
JSCLASS_HAS_PRIVATE,
JS_PropertyStub,
JS_PropertyStub,
GetInstallVersionProperty,
SetInstallVersionProperty,
EnumerateInstallVersion,
ResolveInstallVersion,
JS_ConvertStub,
FinalizeInstallVersion
};
//
// InstallVersion class properties
//
static JSPropertySpec InstallVersionProperties[] =
{
{"major", INSTALLVERSION_MAJOR, JSPROP_ENUMERATE},
{"minor", INSTALLVERSION_MINOR, JSPROP_ENUMERATE},
{"release", INSTALLVERSION_RELEASE, JSPROP_ENUMERATE},
{"build", INSTALLVERSION_BUILD, JSPROP_ENUMERATE},
{0}
};
//
// InstallVersion class methods
//
static JSFunctionSpec InstallVersionMethods[] =
{
{"init", InstallVersionInit, 1},
{"toString", InstallVersionToString, 0},
{"compareTo", InstallVersionCompareTo, 1},
{0}
};
//
// InstallVersion constructor
//
PR_STATIC_CALLBACK(JSBool)
InstallVersion(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsresult result;
nsIID classID;
nsIScriptContext* context = (nsIScriptContext*)JS_GetContextPrivate(cx);
nsIScriptNameSpaceManager* manager;
nsIDOMInstallVersion *nativeThis;
nsIScriptObjectOwner *owner = nsnull;
static NS_DEFINE_IID(kIDOMInstallVersionIID, NS_IDOMINSTALLVERSION_IID);
result = context->GetNameSpaceManager(&manager);
if (NS_OK != result) {
return JS_FALSE;
}
result = manager->LookupName("InstallVersion", PR_TRUE, classID);
NS_RELEASE(manager);
if (NS_OK != result) {
return JS_FALSE;
}
result = nsRepository::CreateInstance(classID,
nsnull,
kIDOMInstallVersionIID,
(void **)&nativeThis);
if (NS_OK != result) {
return JS_FALSE;
}
// XXX We should be calling Init() on the instance
result = nativeThis->QueryInterface(kIScriptObjectOwnerIID, (void **)&owner);
if (NS_OK != result) {
NS_RELEASE(nativeThis);
return JS_FALSE;
}
owner->SetScriptObject((void *)obj);
JS_SetPrivate(cx, obj, nativeThis);
NS_RELEASE(owner);
return JS_TRUE;
}
//
// InstallVersion class initialization
//
nsresult NS_InitInstallVersionClass(nsIScriptContext *aContext, void **aPrototype)
{
JSContext *jscontext = (JSContext *)aContext->GetNativeContext();
JSObject *proto = nsnull;
JSObject *constructor = nsnull;
JSObject *parent_proto = nsnull;
JSObject *global = JS_GetGlobalObject(jscontext);
jsval vp;
if ((PR_TRUE != JS_LookupProperty(jscontext, global, "InstallVersion", &vp)) ||
!JSVAL_IS_OBJECT(vp) ||
((constructor = JSVAL_TO_OBJECT(vp)) == nsnull) ||
(PR_TRUE != JS_LookupProperty(jscontext, JSVAL_TO_OBJECT(vp), "prototype", &vp)) ||
!JSVAL_IS_OBJECT(vp)) {
proto = JS_InitClass(jscontext, // context
global, // global object
parent_proto, // parent proto
&InstallVersionClass, // JSClass
InstallVersion, // JSNative ctor
0, // ctor args
InstallVersionProperties, // proto props
InstallVersionMethods, // proto funcs
nsnull, // ctor props (static)
nsnull); // ctor funcs (static)
if (nsnull == proto) {
return NS_ERROR_FAILURE;
}
if ((PR_TRUE == JS_LookupProperty(jscontext, global, "InstallVersion", &vp)) &&
JSVAL_IS_OBJECT(vp) &&
((constructor = JSVAL_TO_OBJECT(vp)) != nsnull)) {
vp = INT_TO_JSVAL(nsIDOMInstallVersion::SU_EQUAL);
JS_SetProperty(jscontext, constructor, "SU_EQUAL", &vp);
vp = INT_TO_JSVAL(nsIDOMInstallVersion::SU_BLD_DIFF);
JS_SetProperty(jscontext, constructor, "SU_BLD_DIFF", &vp);
vp = INT_TO_JSVAL(nsIDOMInstallVersion::SU_BLD_DIFF_MINUS);
JS_SetProperty(jscontext, constructor, "SU_BLD_DIFF_MINUS", &vp);
vp = INT_TO_JSVAL(nsIDOMInstallVersion::SU_REL_DIFF);
JS_SetProperty(jscontext, constructor, "SU_REL_DIFF", &vp);
vp = INT_TO_JSVAL(nsIDOMInstallVersion::SU_REL_DIFF_MINUS);
JS_SetProperty(jscontext, constructor, "SU_REL_DIFF_MINUS", &vp);
vp = INT_TO_JSVAL(nsIDOMInstallVersion::SU_MINOR_DIFF);
JS_SetProperty(jscontext, constructor, "SU_MINOR_DIFF", &vp);
vp = INT_TO_JSVAL(nsIDOMInstallVersion::SU_MINOR_DIFF_MINUS);
JS_SetProperty(jscontext, constructor, "SU_MINOR_DIFF_MINUS", &vp);
vp = INT_TO_JSVAL(nsIDOMInstallVersion::SU_MAJOR_DIFF);
JS_SetProperty(jscontext, constructor, "SU_MAJOR_DIFF", &vp);
vp = INT_TO_JSVAL(nsIDOMInstallVersion::SU_MAJOR_DIFF_MINUS);
JS_SetProperty(jscontext, constructor, "SU_MAJOR_DIFF_MINUS", &vp);
}
}
else if ((nsnull != constructor) && JSVAL_IS_OBJECT(vp)) {
proto = JSVAL_TO_OBJECT(vp);
}
else {
return NS_ERROR_FAILURE;
}
if (aPrototype) {
*aPrototype = proto;
}
return NS_OK;
}
//
// Method for creating a new InstallVersion JavaScript object
//
extern "C" NS_DOM nsresult NS_NewScriptInstallVersion(nsIScriptContext *aContext, nsISupports *aSupports, nsISupports *aParent, void **aReturn)
{
NS_PRECONDITION(nsnull != aContext && nsnull != aSupports && nsnull != aReturn, "null argument to NS_NewScriptInstallVersion");
JSObject *proto;
JSObject *parent;
nsIScriptObjectOwner *owner;
JSContext *jscontext = (JSContext *)aContext->GetNativeContext();
nsresult result = NS_OK;
nsIDOMInstallVersion *aInstallVersion;
if (nsnull == aParent) {
parent = nsnull;
}
else if (NS_OK == aParent->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) {
if (NS_OK != owner->GetScriptObject(aContext, (void **)&parent)) {
NS_RELEASE(owner);
return NS_ERROR_FAILURE;
}
NS_RELEASE(owner);
}
else {
return NS_ERROR_FAILURE;
}
if (NS_OK != NS_InitInstallVersionClass(aContext, (void **)&proto)) {
return NS_ERROR_FAILURE;
}
result = aSupports->QueryInterface(kIInstallVersionIID, (void **)&aInstallVersion);
if (NS_OK != result) {
return result;
}
// create a js object for this class
*aReturn = JS_NewObject(jscontext, &InstallVersionClass, proto, parent);
if (nsnull != *aReturn) {
// connect the native object to the js object
JS_SetPrivate(jscontext, (JSObject *)*aReturn, aInstallVersion);
}
else {
NS_RELEASE(aInstallVersion);
return NS_ERROR_FAILURE;
}
return NS_OK;
}

Просмотреть файл

@ -0,0 +1,468 @@
/* -*- 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 "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
* the License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*/
#include "nscore.h"
#include "nsIFactory.h"
#include "nsISupports.h"
#include "pratom.h"
#include "nsRepository.h"
#include "VerReg.h"
#include "nsIScriptObjectOwner.h"
#include "nsIScriptGlobalObject.h"
/* For Javascript Namespace Access */
#include "nsDOMCID.h"
#include "nsIServiceManager.h"
#include "nsINameSpaceManager.h"
#include "nsIScriptNameSetRegistry.h"
#include "nsIScriptNameSpaceManager.h"
#include "nsIScriptExternalNameSet.h"
/* Network */
#include "net.h"
#include "nsSoftwareUpdateIIDs.h"
#include "nsSoftwareUpdate.h"
#include "nsSoftwareUpdateStream.h"
#include "nsSoftwareUpdateRun.h"
#include "nsIDOMInstall.h"
#include "nsInstall.h"
#include "nsIDOMInstallTriggerGlobal.h"
#include "nsInstallTrigger.h"
#include "nsIDOMInstallVersion.h"
#include "nsInstallVersion.h"
#include "nsIDOMInstallFolder.h"
#include "nsInstallFolder.h"
////////////////////////////////////////////////////////////////////////////////
// Globals
////////////////////////////////////////////////////////////////////////////////
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID);
static NS_DEFINE_IID(kIScriptNameSetRegistryIID, NS_ISCRIPTNAMESETREGISTRY_IID);
static NS_DEFINE_IID(kCScriptNameSetRegistryCID, NS_SCRIPT_NAMESET_REGISTRY_CID);
static NS_DEFINE_IID(kIScriptExternalNameSetIID, NS_ISCRIPTEXTERNALNAMESET_IID);
static NS_DEFINE_IID(kISoftwareUpdate_IID, NS_ISOFTWAREUPDATE_IID);
static NS_DEFINE_IID(kSoftwareUpdate_CID, NS_SoftwareUpdate_CID);
static NS_DEFINE_IID(kIInstall_IID, NS_IDOMINSTALL_IID);
static NS_DEFINE_IID(kInstall_CID, NS_SoftwareUpdateInstall_CID);
static NS_DEFINE_IID(kIInstallTrigger_IID, NS_IDOMINSTALLTRIGGERGLOBAL_IID);
static NS_DEFINE_IID(kInstallTrigger_CID, NS_SoftwareUpdateInstallTrigger_CID);
static NS_DEFINE_IID(kIInstallVersion_IID, NS_IDOMINSTALLVERSION_IID);
static NS_DEFINE_IID(kInstallVersion_CID, NS_SoftwareUpdateInstallVersion_CID);
static NS_DEFINE_IID(kIInstallFolder_IID, NS_IDOMINSTALLFOLDER_IID);
static NS_DEFINE_IID(kInstallFolder_CID, NS_SoftwareUpdateInstallFolder_CID);
static PRInt32 gInstanceCnt = 0;
static PRInt32 gLockCnt = 0;
nsSoftwareUpdate::nsSoftwareUpdate()
{
}
nsSoftwareUpdate::~nsSoftwareUpdate()
{
}
NS_IMETHODIMP
nsSoftwareUpdate::QueryInterface(REFNSIID aIID,void** aInstancePtr)
{
if (aInstancePtr == NULL)
{
return NS_ERROR_NULL_POINTER;
}
// Always NULL result, in case of failure
*aInstancePtr = NULL;
if ( aIID.Equals(kISoftwareUpdate_IID) )
{
*aInstancePtr = (void*)(nsISoftwareUpdate*)this;
AddRef();
return NS_OK;
}
else if ( aIID.Equals(kISupportsIID) )
{
*aInstancePtr = (void*)(nsISupports*)this;
AddRef();
return NS_OK;
}
return NS_NOINTERFACE;
}
NS_IMPL_ADDREF(nsSoftwareUpdate)
NS_IMPL_RELEASE(nsSoftwareUpdate)
NS_IMETHODIMP
nsSoftwareUpdate::Startup()
{
/***************************************/
/* Add us to the Javascript Name Space */
/***************************************/
// FIX: Only add the Trigger Object to the JS NameSpace. Then when before we run
// the InstallScript, add our other objects to just that env.
nsIScriptNameSetRegistry *registry;
nsresult result = nsServiceManager::GetService(kCScriptNameSetRegistryCID,
kIScriptNameSetRegistryIID,
(nsISupports **)&registry);
if (NS_OK == result)
{
nsSoftwareUpdateNameSet* nameSet = new nsSoftwareUpdateNameSet();
registry->AddExternalNameSet(nameSet);
/* FIX - do we need to release this service? When we do, it get deleted,and our name is lost. */
}
/***************************************/
/* Register us with NetLib */
/***************************************/
// FIX
/***************************************/
/* Startup the Version Registry */
/***************************************/
//FIX we need an api that will get us this data
VR_SetRegDirectory("C:\\temp\\");
NR_StartupRegistry(); /* startup the registry; if already started, this will essentially be a noop */
/***************************************/
/* Stupid Hack to test js env*/
/***************************************/
RunInstallJS("c:\\temp\\test.js");
DeleteScheduledNodes();
return NS_OK;
}
NS_IMETHODIMP
nsSoftwareUpdate::Shutdown()
{
NR_ShutdownRegistry();
return NS_OK;
}
nsresult
nsSoftwareUpdate::DeleteScheduledNodes()
{
return NS_OK;
}
/////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////
static PRInt32 gSoftwareUpdateInstanceCnt = 0;
static PRInt32 gSoftwareUpdateLock = 0;
nsSoftwareUpdateFactory::nsSoftwareUpdateFactory(void)
{
mRefCnt=0;
PR_AtomicIncrement(&gSoftwareUpdateInstanceCnt);
}
nsSoftwareUpdateFactory::~nsSoftwareUpdateFactory(void)
{
PR_AtomicDecrement(&gSoftwareUpdateInstanceCnt);
}
NS_IMETHODIMP
nsSoftwareUpdateFactory::QueryInterface(REFNSIID aIID,void** aInstancePtr)
{
if (aInstancePtr == NULL)
{
return NS_ERROR_NULL_POINTER;
}
// Always NULL result, in case of failure
*aInstancePtr = NULL;
if ( aIID.Equals(kISupportsIID) )
{
*aInstancePtr = (void*) this;
}
else if ( aIID.Equals(kIFactoryIID) )
{
*aInstancePtr = (void*) this;
}
if (aInstancePtr == NULL)
{
return NS_ERROR_NO_INTERFACE;
}
AddRef();
return NS_OK;
}
NS_IMETHODIMP
nsSoftwareUpdateFactory::AddRef(void)
{
return ++mRefCnt;
}
NS_IMETHODIMP
nsSoftwareUpdateFactory::Release(void)
{
if (--mRefCnt ==0)
{
delete this;
return 0; // Don't access mRefCnt after deleting!
}
return mRefCnt;
}
NS_IMETHODIMP
nsSoftwareUpdateFactory::CreateInstance(nsISupports *aOuter, REFNSIID aIID, void **aResult)
{
if (aResult == NULL)
{
return NS_ERROR_NULL_POINTER;
}
*aResult = NULL;
nsSoftwareUpdate *inst = new nsSoftwareUpdate();
if (inst == NULL)
return NS_ERROR_OUT_OF_MEMORY;
nsresult result = inst->QueryInterface(aIID, aResult);
if (result != NS_OK)
delete inst;
return result;
}
NS_IMETHODIMP
nsSoftwareUpdateFactory::LockFactory(PRBool aLock)
{
if (aLock)
PR_AtomicIncrement(&gSoftwareUpdateLock);
else
PR_AtomicDecrement(&gSoftwareUpdateLock);
return NS_OK;
}
////////////////////////////////////////////////////////////////////////////////
// nsSoftwareUpdateNameSet
////////////////////////////////////////////////////////////////////////////////
nsSoftwareUpdateNameSet::nsSoftwareUpdateNameSet()
{
NS_INIT_REFCNT();
}
nsSoftwareUpdateNameSet::~nsSoftwareUpdateNameSet()
{
}
NS_IMPL_ISUPPORTS(nsSoftwareUpdateNameSet, kIScriptExternalNameSetIID);
NS_IMETHODIMP
nsSoftwareUpdateNameSet::InitializeClasses(nsIScriptContext* aScriptContext)
{
nsresult result = NS_OK;
result = NS_InitInstallClass(aScriptContext, nsnull);
if (result != NS_OK) return result;
result = NS_InitInstallVersionClass(aScriptContext, nsnull);
if (result != NS_OK) return result;
result = NS_InitInstallFolderClass(aScriptContext, nsnull);
if (result != NS_OK) return result;
result = NS_InitInstallTriggerGlobalClass(aScriptContext, nsnull);
return result;
}
NS_IMETHODIMP
nsSoftwareUpdateNameSet::AddNameSet(nsIScriptContext* aScriptContext)
{
nsresult result = NS_OK;
nsIScriptNameSpaceManager* manager;
result = aScriptContext->GetNameSpaceManager(&manager);
if (NS_OK == result)
{
result = manager->RegisterGlobalName("Install",
kInstall_CID,
PR_TRUE);
if (result != NS_OK) return result;
result = manager->RegisterGlobalName("InstallVersion",
kInstallVersion_CID,
PR_TRUE);
if (result != NS_OK) return result;
result = manager->RegisterGlobalName("InstallFolder",
kInstallFolder_CID,
PR_TRUE);
if (result != NS_OK) return result;
result = manager->RegisterGlobalName("InstallTrigger",
kInstallTrigger_CID,
PR_FALSE);
}
if (manager != nsnull)
NS_RELEASE(manager);
return result;
}
////////////////////////////////////////////////////////////////////////////////
// DLL Entry Points:
////////////////////////////////////////////////////////////////////////////////
extern "C" NS_EXPORT PRBool
NSCanUnload(void)
{
return PRBool (gInstanceCnt == 0 && gLockCnt == 0);
}
extern "C" NS_EXPORT nsresult
NSRegisterSelf(const char *path)
{
nsRepository::RegisterFactory(kSoftwareUpdate_CID, path, PR_TRUE, PR_TRUE);
nsRepository::RegisterFactory(kInstall_CID, path, PR_TRUE, PR_TRUE);
nsRepository::RegisterFactory(kInstallTrigger_CID, path, PR_TRUE, PR_TRUE);
nsRepository::RegisterFactory(kInstallVersion_CID, path, PR_TRUE, PR_TRUE);
nsRepository::RegisterFactory(kInstallFolder_CID, path, PR_TRUE, PR_TRUE);
return NS_OK;
}
extern "C" NS_EXPORT nsresult
NSUnregisterSelf(const char *path)
{
nsRepository::UnregisterFactory(kSoftwareUpdate_CID, path);
nsRepository::UnregisterFactory(kInstall_CID, path);
nsRepository::UnregisterFactory(kInstallTrigger_CID, path);
nsRepository::UnregisterFactory(kInstallVersion_CID, path);
nsRepository::UnregisterFactory(kInstallFolder_CID, path);
return NS_OK;
}
extern "C" NS_EXPORT nsresult
NSGetFactory(const nsCID &aClass, nsISupports* serviceMgr, nsIFactory **aFactory)
{
if (aFactory == NULL)
{
return NS_ERROR_NULL_POINTER;
}
*aFactory = NULL;
nsISupports *inst;
if ( aClass.Equals(kInstall_CID) )
{
inst = new nsInstallFactory();
}
else if (aClass.Equals(kInstallTrigger_CID) )
{
inst = new nsInstallTriggerFactory();
}
else if (aClass.Equals(kInstallFolder_CID) )
{
inst = new nsInstallFolderFactory();
}
else if (aClass.Equals(kInstallVersion_CID) )
{
inst = new nsInstallVersionFactory();
}
else if (aClass.Equals(kSoftwareUpdate_CID) )
{
inst = new nsSoftwareUpdateFactory();
}
else
{
return NS_ERROR_ILLEGAL_VALUE;
}
if (inst == NULL)
{
return NS_ERROR_OUT_OF_MEMORY;
}
nsresult res = inst->QueryInterface(kIFactoryIID, (void**) aFactory);
if (res != NS_OK)
{
delete inst;
}
return res;
}

Просмотреть файл

@ -0,0 +1,61 @@
#ifndef nsSoftwareUpdate_h___
#define nsSoftwareUpdate_h___
#include "nsSoftwareUpdateIIDs.h"
#include "nsISoftwareUpdate.h"
#include "nscore.h"
#include "nsIFactory.h"
#include "nsISupports.h"
#include "nsIScriptExternalNameSet.h"
class nsSoftwareUpdate: public nsISoftwareUpdate
{
public:
static const nsIID& IID() { static nsIID iid = NS_SoftwareUpdateInstall_CID; return iid; }
nsSoftwareUpdate();
~nsSoftwareUpdate();
NS_DECL_ISUPPORTS
NS_IMETHOD Startup();
NS_IMETHOD Shutdown();
private:
nsresult DeleteScheduledNodes();
};
class nsSoftwareUpdateNameSet : public nsIScriptExternalNameSet
{
public:
nsSoftwareUpdateNameSet();
~nsSoftwareUpdateNameSet();
NS_DECL_ISUPPORTS
NS_IMETHOD InitializeClasses(nsIScriptContext* aScriptContext);
NS_IMETHOD AddNameSet(nsIScriptContext* aScriptContext);
};
#define AUTOUPDATE_ENABLE_PREF "autoupdate.enabled"
#define AUTOUPDATE_CONFIRM_PREF "autoupdate.confirm_install"
#define CHARSET_HEADER "Charset"
#define CONTENT_ENCODING_HEADER "Content-encoding"
#define INSTALLER_HEADER "Install-Script"
#define MOCHA_CONTEXT_PREFIX "autoinstall:"
#define REG_SOFTUPDT_DIR "Netscape/Communicator/SoftwareUpdate/"
#define LAST_REGPACK_TIME "LastRegPackTime"
/* error codes */
#define su_ErrInvalidArgs -1
#define su_ErrUnknownInstaller -2
#define su_ErrInternalError -3
#define su_ErrBadScript -4
#define su_JarError -5
#define su_DiskSpaceError -6
#endif

Просмотреть файл

@ -0,0 +1,75 @@
/* -*- 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 "nsSoftwareUpdateQueue.h"
#include "prmem.h"
/*
* This struct represents one entry in a queue setup to hold download
* requests if there are more than one.
*/
typedef struct su_QItem
{
struct su_QItem * next;
struct su_QItem * prev;
su_startCallback * QItem;
} su_QItem;
static su_QItem * Qhead = NULL;
static su_QItem * Qtail = NULL;
PRBool QInsert( su_startCallback * Item )
{
su_QItem *p = (su_QItem*) PR_MALLOC( sizeof (su_QItem));
if (p == NULL)
return FALSE;
p->QItem = Item;
p->next = Qhead;
p->prev = NULL;
if (Qhead != NULL)
Qhead->prev = p;
Qhead = p;
if (Qtail == NULL) /* First Item inserted in Q? */
Qtail = p;
return TRUE;
}
su_startCallback *QGetItem(void)
{
su_QItem *Qtemp = Qtail;
if (Qtemp != NULL)
{
su_startCallback *p = NULL;
Qtail = Qtemp->prev;
if (Qtail == NULL) /* Last Item deleted from Q? */
Qhead = NULL;
else
Qtail->next = NULL;
p = Qtemp->QItem;
PR_FREEIF(Qtemp);
return p;
}
return NULL;
}

Просмотреть файл

@ -0,0 +1,51 @@
/* -*- 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 _NS_SOFTWAREUPDATEQUEUE_H__
#define _NS_SOFTWAREUPDATEQUEUE_H__
#include "ntypes.h" /* for MWContext */
typedef void (*SoftUpdateCompletionFunction) (int result, void * closure);
/* a struct to hold the arguments */
struct su_startCallback_
{
char * url;
char * name;
SoftUpdateCompletionFunction f;
void * completionClosure;
int32 flags;
MWContext * context;
};
typedef su_startCallback_ su_startCallback;
NSPR_BEGIN_EXTERN_C
PRBool QInsert( su_startCallback * Item );
su_startCallback *QGetItem(void);
NSPR_END_EXTERN_C
#endif

Просмотреть файл

@ -0,0 +1,134 @@
#include "nsSoftwareUpdate.h"
#include "nsSoftwareUpdateRun.h"
#include <sys/stat.h>
#include "nspr.h"
#include "nsRepository.h"
#include "nsIBrowserWindow.h"
#include "nsIWebShell.h"
#include "nsIScriptContext.h"
#include "nsIScriptContextOwner.h"
static NS_DEFINE_IID(kBrowserWindowCID, NS_BROWSER_WINDOW_CID);
static NS_DEFINE_IID(kIBrowserWindowIID, NS_IBROWSER_WINDOW_IID);
static NS_DEFINE_IID(kIScriptContextOwnerIID, NS_ISCRIPTCONTEXTOWNER_IID);
/* su_ReadFileIntoBuffer
* given a file name, reads it into buffer
* returns an error code
*/
static short ReadFileIntoBuffer(char * fileName, char** buffer, unsigned long *bufferSize)
{
PRFileDesc* file;
struct stat st;
short result = 0;
if ( stat( fileName, &st) != 0 )
{
result = su_ErrInternalError;
goto fail;
}
*bufferSize = st.st_size + 1;
*buffer = (char*) PR_MALLOC( *bufferSize);
if (*buffer == NULL)
{
result = -1;
goto fail;
}
memset(*buffer, '\0', *bufferSize);
file = PR_Open(fileName, PR_RDONLY, 0644);
if ( file == NULL)
{
result = su_ErrInternalError;
goto fail;
}
if ( PR_Read(file, *buffer, *bufferSize ) != st.st_size )
{
result = su_ErrInternalError;
PR_Close( file );
goto fail;
}
PR_Close( file );
return result;
fail:
if (*buffer != NULL)
delete( *buffer);
*buffer = NULL;
return result;
}
int RunInstallJS(char* installJSFile)
{
nsIBrowserWindow *aWindow;
nsIWebShell *aWebShell;
nsresult rv = nsRepository::CreateInstance( kBrowserWindowCID,
nsnull,
kIBrowserWindowIID,
(void**) &aWindow);
if (rv == NS_OK)
{
nsRect rect(0, 0, 275, 300);
rv = aWindow->Init(nsnull, nsnull, rect, PRUint32(0), PR_FALSE);
if (rv == NS_OK)
{
rv = aWindow->GetWebShell(aWebShell);
/* FIX: Display a window here...(ie.OpenURL)
What about silent/forced installs?
*/
nsAutoString retval;
PRBool isUndefined;
nsIScriptContextOwner* scriptContextOwner;
if (NS_OK == aWebShell->QueryInterface( kIScriptContextOwnerIID,
(void**)&scriptContextOwner))
{
const char* url = "";
nsIScriptContext* scriptContext;
nsresult res = scriptContextOwner->GetScriptContext(&scriptContext);
if (NS_OK == res)
{
char* buffer;
unsigned long bufferLength;
ReadFileIntoBuffer(installJSFile, &buffer, &bufferLength);
scriptContext->EvaluateString(nsString(buffer), nsnull, 0, retval, &isUndefined);
PR_FREEIF(buffer);
NS_RELEASE(scriptContext);
}
NS_RELEASE(scriptContextOwner);
}
}
}
aWindow->Release();
return 0;
}

Просмотреть файл

@ -0,0 +1,6 @@
#ifndef __NS_SoftwareUpdateRun_H__
#define __NS_SoftwareUpdateRun_H__
int RunInstallJS(char* filename);
#endif

Просмотреть файл

@ -0,0 +1,184 @@
/* -*- 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 "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
* the License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*/
#include "nsSoftwareUpdate.h"
#include "nsSoftwareUpdateStream.h"
#include "nscore.h"
#include "nsISupports.h"
#include "nsIURL.h"
#include "nsINetlibURL.h"
#include "nsINetService.h"
#include "nsIInputStream.h"
#include "nsIStreamListener.h"
nsresult
su_DownloadJar(const nsString& aUrlString, const nsString& aSaveLocationString)
{
long result=0;
nsIURL *pURL;
char* locationCString;
nsSoftwareUpdateListener *aListener;
////////////////////////////
// Create the URL object...
////////////////////////////
pURL = NULL;
result = NS_NewURL(&pURL, aUrlString);
if (result != NS_OK)
{
return result;
}
aListener = new nsSoftwareUpdateListener();
locationCString = aSaveLocationString.ToNewCString();
aListener->SetListenerInfo(locationCString);
delete [] locationCString;
result = NS_OpenURL(pURL, aListener);
/* If the open failed... */
if (NS_OK != result)
{
return result;
}
}
nsSoftwareUpdateListener::nsSoftwareUpdateListener()
{
NS_INIT_REFCNT();
}
nsSoftwareUpdateListener::~nsSoftwareUpdateListener()
{
if (mOutFileDesc != NULL)
PR_Close(mOutFileDesc);
}
NS_IMPL_ISUPPORTS( nsSoftwareUpdateListener, kIStreamListenerIID )
NS_IMETHODIMP
nsSoftwareUpdateListener::GetBindInfo(nsIURL* aURL, nsStreamBindingInfo* info)
{
return NS_OK;
}
NS_IMETHODIMP
nsSoftwareUpdateListener::OnProgress( nsIURL* aURL,
PRUint32 Progress,
PRUint32 ProgressMax)
{
return NS_OK;
}
NS_IMETHODIMP
nsSoftwareUpdateListener::OnStatus(nsIURL* aURL,
const PRUnichar* aMsg)
{
return NS_OK;
}
NS_IMETHODIMP
nsSoftwareUpdateListener::OnStartBinding(nsIURL* aURL,
const char *aContentType)
{
return NS_OK;
}
NS_IMETHODIMP
nsSoftwareUpdateListener::OnStopBinding(nsIURL* aURL,
nsresult status,
const PRUnichar* aMsg)
{
nsresult result = NS_OK;
switch( status )
{
case NS_BINDING_SUCCEEDED:
/* Extract the Installer Script from the jar */
/* Open the script up */
PR_Close(mOutFileDesc);
break;
case NS_BINDING_FAILED:
case NS_BINDING_ABORTED:
PR_Close(mOutFileDesc);
break;
default:
result = NS_ERROR_ILLEGAL_VALUE;
}
return result;
}
#define BUF_SIZE 1024
NS_IMETHODIMP
nsSoftwareUpdateListener::OnDataAvailable(nsIURL* aURL, nsIInputStream *pIStream, PRUint32 length)
{
PRUint32 len;
nsresult err;
char buffer[BUF_SIZE];
do
{
err = pIStream->Read(buffer, 0, BUF_SIZE, &len);
if (err == NS_OK)
{
if( PR_Write(mOutFileDesc, buffer, len) == -1 )
{
/* Error */
return -1;
}
}
} while (len > 0 && err == NS_OK);
return 0;
}
NS_IMETHODIMP
nsSoftwareUpdateListener::SetListenerInfo(char* fileName)
{
mOutFileDesc = PR_Open(fileName, PR_CREATE_FILE | PR_RDWR, 0644);
if(mOutFileDesc == NULL)
{
return -1;
};
return NS_OK;
}

Просмотреть файл

@ -0,0 +1,65 @@
/* -*- 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 _NS_SOFTWAREUPDATESTREAM_H__
#define _NS_SOFTWAREUPDATESTREAM_H__
#include "nscore.h"
#include "nsISupports.h"
#include "nsString.h"
#include "nsIURL.h"
#include "nsINetlibURL.h"
#include "nsINetService.h"
#include "nsIInputStream.h"
#include "nsIStreamListener.h"
static NS_DEFINE_IID(kInetServiceIID, NS_INETSERVICE_IID);
static NS_DEFINE_IID(kInetServiceCID, NS_NETSERVICE_CID);
static NS_DEFINE_IID(kInetLibURLIID, NS_INETLIBURL_IID);
static NS_DEFINE_IID(kIStreamListenerIID, NS_ISTREAMLISTENER_IID);
extern "C" nsresult su_DownloadJar(const nsString& aUrlString, const nsString& aSaveLocationString );
class nsSoftwareUpdateListener : public nsIStreamListener
{
public:
NS_DECL_ISUPPORTS
nsSoftwareUpdateListener();
NS_IMETHOD GetBindInfo(nsIURL* aURL, nsStreamBindingInfo* info);
NS_IMETHOD OnProgress(nsIURL* aURL, PRUint32 Progress, PRUint32 ProgressMax);
NS_IMETHOD OnStatus(nsIURL* aURL, const PRUnichar* aMsg);
NS_IMETHOD OnStartBinding(nsIURL* aURL, const char *aContentType);
NS_IMETHOD OnDataAvailable(nsIURL* aURL, nsIInputStream *pIStream, PRUint32 length);
NS_IMETHOD OnStopBinding(nsIURL* aURL, nsresult status, const PRUnichar* aMsg);
NS_METHOD SetListenerInfo(char* aUrlString);
protected:
~nsSoftwareUpdateListener();
private:
PRFileDesc *mOutFileDesc;
};
#endif