C++ implementation of Java objects. These files are not part of the build system yet.

This commit is contained in:
raman%netscape.com 1998-08-17 00:45:51 +00:00
parent c20de2fd12
commit d3c21cfc93
15 changed files with 2324 additions and 0 deletions

View File

@ -0,0 +1,315 @@
/* -*- 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 "prmem.h"
#include "prmon.h"
#include "prlog.h"
#include "fe_proto.h"
#include "xp_str.h"
#include "prefapi.h"
#include "proto.h"
#include "prprf.h"
#include "prthread.h"
#include "nsFolderSpec.h"
#include "nsSUError.h"
#include "xp.h"
#include "su_folderspec.h"
#ifndef MAX_PATH
#if defined(XP_WIN) || defined(XP_OS2)
#define MAX_PATH _MAX_PATH
#endif
#ifdef XP_UNIX
#ifdef NSPR20
#include "md/prosdep.h"
#else
#include "prosdep.h"
#endif
#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
extern int SU_INSTALL_ASK_FOR_DIRECTORY;
PR_BEGIN_EXTERN_C
/* Public Methods */
/* Constructor
*/
nsFolderSpec::nsFolderSpec(char* inFolderID , char* inVRPath, char* inPackageName)
{
urlPath = folderID = versionRegistryPath = userPackageName = NULL;
folderID = PR_sprintf_append(folderID, "%s", inFolderID);
versionRegistryPath = PR_sprintf_append(versionRegistryPath, "%s", inVRPath);
userPackageName = PR_sprintf_append(userPackageName, "%s", inPackageName);
}
nsFolderSpec::~nsFolderSpec(void)
{
if (folderID)
PR_Free(folderID);
if (versionRegistryPath)
PR_Free(versionRegistryPath);
if (userPackageName)
PR_Free(userPackageName);
if (urlPath)
PR_Free(urlPath);
}
/*
* GetDirectoryPath
* returns full path to the directory in the standard URL form
*/
char* nsFolderSpec::GetDirectoryPath(char* *errorMsg)
{
if (urlPath == NULL) {
if (XP_STRCMP(folderID, "User Pick") == 0) {
// Default package folder
// Try the version registry default path first
// urlPath = VersionRegistry.getDefaultDirectory( versionRegistryPath );
// if (urlPath == NULL)
urlPath = PickDefaultDirectory(errorMsg);
} else if (XP_STRCMP(folderID, "Installed") == 0) {
// Then use the Version Registry path
urlPath = PR_sprintf_append(urlPath, "%s", versionRegistryPath);
} else {
// Built-in folder
int err = NativeGetDirectoryPath();
if (err != 0)
// XXX: Get the String after converting the error to an id
*errorMsg = SU_GetErrorMsg1(err, folderID);
}
}
return urlPath;
}
/**
* Returns full path to a file. Makes sure that the full path is bellow
* this directory (security measure
* @param relativePath relative path
* @return full path to a file
*/
char* nsFolderSpec::MakeFullPath(char* relativePath, char* *errorMsg)
{
// Security check. Make sure that we do not have '.. in the name
// if ( (GetSecurityTargetID() == SoftwareUpdate.LIMITED_INSTALL) &&
// ( relativePath.regionMatches(0, "..", 0, 2)))
// throw new SoftUpdateException(Strings.error_IllegalPath(), SoftwareUpdate.ILLEGAL_RELATIVE_PATH );
char *fullPath=NULL;
char *dir_path;
*errorMsg = NULL;
dir_path = GetDirectoryPath(errorMsg);
if (errorMsg != NULL) {
return NULL;
}
fullPath = PR_sprintf_append(fullPath, "%s%s", dir_path, GetNativePath(relativePath));
return fullPath;
}
char* nsFolderSpec::toString()
{
char *errorMsg = NULL;
char* path = GetDirectoryPath(&errorMsg);
if (errorMsg != NULL)
path = NULL;
return path;
}
/* Private Methods */
/* PickDefaultDirectory
* asks the user for the default directory for the package
* stores the choice
*/
char* nsFolderSpec::PickDefaultDirectory(char* *errorMsg)
{
urlPath = NativePickDefaultDirectory(errorMsg);
if (urlPath == NULL)
*errorMsg = SU_GetErrorMsg1(nsSoftUpdateError_INVALID_PATH_ERR, folderID);
return urlPath;
}
/* Private Native Methods */
/* NativeGetDirectoryPath
* gets a platform-specific directory path
* stores it in urlPath
*/
int nsFolderSpec::NativeGetDirectoryPath()
{
su_DirSpecID folderDirSpecID;
char* folderPath = NULL;
/* Get the name of the package to prompt for */
folderDirSpecID = MapNameToEnum(folderID);
switch (folderDirSpecID)
{
case eBadFolder:
return nsSoftUpdateError_INVALID_PATH_ERR;
case eCurrentUserFolder:
{
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);
XP_FREEIF(platformDir);
}
}
break;
default:
/* Get the FE path */
folderPath = FE_GetDirectoryPath(folderDirSpecID);
break;
}
/* Store it in the object */
if (folderPath != NULL) {
urlPath = NULL;
urlPath = PR_sprintf_append(urlPath, "%s", folderPath);
XP_FREE(folderPath);
return 0;
}
return nsSoftUpdateError_INVALID_PATH_ERR;
}
/* GetNativePath
* returns a native equivalent of a XP directory path
*/
char* nsFolderSpec::GetNativePath(char* path)
{
char *xpPath, *p;
char pathSeparator;
#define XP_PATH_SEPARATOR '/'
#ifdef XP_WIN
pathSeparator = '\\';
#elif defined(XP_MAC)
pathSeparator = ':';
#else /* XP_UNIX */
pathSeparator = '/';
#endif
p = xpPath = path;
/*
* Traverse XP path and replace XP_PATH_SEPARATOR with
* the platform native equivalent
*/
if ( p == NULL )
{
xpPath = "";
}
else
{
while ( *p )
{
if ( *p == XP_PATH_SEPARATOR )
*p = pathSeparator;
++p;
}
}
return xpPath;
}
/*
* NativePickDefaultDirectory
* Platform-specific implementation of GetDirectoryPath
*/
char* nsFolderSpec::NativePickDefaultDirectory(char* *errorMsg)
{
su_PickDirTimer callback;
char * packageName;
char prompt[200];
callback.context = XP_FindSomeContext();
callback.fileName = NULL;
callback.done = FALSE;
/* Get the name of the package to prompt for */
packageName = userPackageName;
if (packageName)
{
/* In Java thread now, and need to call FE_PromptForFileName
* from the main thread
* post an event on a timer, and busy-wait until it completes.
*/
PR_snprintf(prompt, 200, XP_GetString(SU_INSTALL_ASK_FOR_DIRECTORY), packageName);
callback.prompt = prompt;
FE_SetTimeout( pickDirectoryCallback, &callback, 1 );
while (!callback.done) /* Busy loop for now */
PR_Yield(); /* java_lang_Thread_yield(WHAT?); */
}
return callback.fileName;
}
PRBool nsFolderSpec::NativeIsJavaDir()
{
int i;
char* folderName;
/* Get the name of the package to prompt for */
folderName = folderID;
#ifdef XXX
PR_ASSERT( folderName );
if ( folderName != NULL) {
for (i=0; DirectoryTable[i].directoryName[0] != 0; i++ ) {
if ( strcmp(folderName, DirectoryTable[i].directoryName) == 0 )
return DirectoryTable[i].bJavaDir;
}
}
#endif
return PR_FALSE;
}
PR_END_EXTERN_C

View File

@ -0,0 +1,24 @@
/* -*- 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 "nsInstallDelete.h"
PR_BEGIN_EXTERN_C
PR_END_EXTERN_C

View File

@ -0,0 +1,24 @@
/* -*- 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 "nsInstallExecute.h"
PR_BEGIN_EXTERN_C
PR_END_EXTERN_C

View File

@ -0,0 +1,446 @@
/* -*- 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 "nsCRT.h"
#include "xp.h"
#include "nsInstallFile.h"
#include "nsVersionRegistry.h"
#include "nsSUError.h"
#include "nsSoftUpdateEnums.h"
#include "nsPrivilegeManager.h"
#include "nsTarget.h"
PR_BEGIN_EXTERN_C
/* 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::nsInstallFile(nsSoftwareUpdate* inSoftUpdate,
char* inVRName,
nsVersionInfo* inVInfo,
char* inJarLocation,
nsFolderSpec* folderSpec,
char* inPartialPath,
PRBool forceInstall,
char* *errorMsg) : nsInstallObject(inSoftUpdate)
{
tempFile = NULL;
vrName = NULL;
jarLocation = NULL;
versionInfo = NULL;
finalFile = NULL;
regPackageName = NULL;
userPackageName = NULL;
target = NULL;
force = PR_FALSE;
bJavaDir = PR_FALSE;
replace = PR_FALSE;
bChild = PR_FALSE;
bUpgrade = PR_FALSE;
vrName = new nsString(inVRName);
versionInfo = inVInfo;
jarLocation = new nsString(inJarLocation);
force = forceInstall;
char* temp = folderSpec->MakeFullPath( inPartialPath, errorMsg );
if (temp != NULL) {
finalFile = new nsString(temp);
}
bJavaDir = folderSpec->IsJavaCapable();
/* Request impersonation privileges */
nsTarget* impersonation = nsTarget::findTarget(IMPERSONATOR);
nsPrivilegeManager* privMgr = nsPrivilegeManager::getPrivilegeManager();
/* XXX: We are using security to display the dialog. Thus depth may not matter */
if ((privMgr != NULL) && (impersonation != NULL)) {
privMgr->enablePrivilege(impersonation, 1);
/* check the security permissions */
target = nsTarget::findTarget(INSTALL_PRIV);
if (target != NULL) {
/* XXX: we need a way to indicate that a dialog box should appear. */
privMgr->enablePrivilege(target, softUpdate->GetPrincipal(), 1);
}
}
temp = inSoftUpdate->GetUserPackageName();
if (temp != NULL) {
userPackageName = new nsString(temp);
}
temp = inSoftUpdate->GetRegPackageName();
if (temp != NULL) {
regPackageName = new nsString(temp);
}
// determine Child status
if ( regPackageName == NULL ) {
// in the "current communicator package" absolute pathnames (start
// with slash) indicate shared files -- all others are children
bChild = ( vrName->CharAt(0) != '/' );
} else {
//bChild = vrName.startsWith(regPackageName);
/* Because nsString doesn't support startWith, implemented the following. Waiting for approval */
bChild = (nsCRT::strncmp((PRUnichar*)vrName, (PRUnichar*)regPackageName,
nsCRT::strlen((PRUnichar*)regPackageName)) == 0);
}
replace = NativeDoesFileExist();
}
nsInstallFile::~nsInstallFile()
{
delete vrName;
delete jarLocation;
if (finalFile)
delete finalFile;
if (userPackageName)
delete userPackageName;
if (regPackageName)
delete regPackageName;
if (tempFile)
delete tempFile;
}
/* Prepare
* Extracts file out of the JAR archive into the temp directory
*/
char* nsInstallFile::Prepare()
{
char *errorMsg = NULL;
// XXX: Make the following security code into a function.
/* Request impersonation privileges */
nsTarget* impersonation = nsTarget::findTarget(IMPERSONATOR);
nsPrivilegeManager* privMgr = nsPrivilegeManager::getPrivilegeManager();
/* XXX: We are using security to display the dialog. Thus depth may not matter */
if ((privMgr != NULL) && (impersonation != NULL)) {
PRBool allowed = privMgr->enablePrivilege(impersonation, 1);
if (allowed == PR_FALSE) {
errorMsg = SU_GetErrorMsg3("Permssion was denied", nsSoftUpdateError_ACCESS_DENIED);
return errorMsg;
}
/* check the security permissions */
if (target != NULL) {
/* XXX: we need a way to indicate that a dialog box should appear. */
PRBool allowed = privMgr->enablePrivilege(target, softUpdate->GetPrincipal(), 1);
if (allowed == PR_FALSE) {
errorMsg = SU_GetErrorMsg3("Permssion was denied", nsSoftUpdateError_ACCESS_DENIED);
return errorMsg;
}
}
}
char* jarLocationCharPtr = jarLocation->ToNewCString();
char* finalFileCharPtr = finalFile->ToNewCString();
char* temp = softUpdate->ExtractJARFile(jarLocationCharPtr, finalFileCharPtr, &errorMsg);
delete jarLocationCharPtr;
delete finalFileCharPtr;
if (errorMsg != NULL) {
return errorMsg;
}
if (temp != NULL) {
tempFile = new nsString(temp);
free(temp);
}
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;
/* Check the security for our target */
// XXX: Make the following security code into a function.
/* Request impersonation privileges */
nsTarget* impersonation = nsTarget::findTarget(IMPERSONATOR);
nsPrivilegeManager* privMgr = nsPrivilegeManager::getPrivilegeManager();
/* XXX: We are using security to display the dialog. Thus depth may not matter */
if ((privMgr != NULL) && (impersonation != NULL)) {
privMgr->enablePrivilege(impersonation, 1);
/* check the security permissions */
if (target != NULL) {
/* XXX: we need a way to indicate that a dialog box should appear. */
privMgr->enablePrivilege(target, softUpdate->GetPrincipal(), 1);
}
}
err = NativeComplete();
if ((privMgr != NULL) && (target != NULL)) {
privMgr->revertPrivilege(target, 1);
}
// Add java archives to the classpath. Don't add if we're
// replacing an existing file -- it'll already be there.
if ( bJavaDir && !replace ) {
PRBool found_zip = PR_FALSE;
PRBool found_jar = PR_FALSE;
int len = strlen(".zip");
int size = finalFile->Length();
int offset = finalFile->RFind(".zip", PR_FALSE);
if (offset == (size - len))
found_zip = PR_TRUE;
offset = finalFile->RFind(".jar", PR_FALSE);
if (offset == (size - len))
found_jar = PR_TRUE;
if (found_zip || found_jar) {
AddToClasspath( finalFile );
}
}
// Register file and log for Uninstall
if ( 0 == err || nsSoftwareUpdate_REBOOT_NEEDED == err ) {
// we ignore all registry errors because they're not
// important enough to abort an otherwise OK install.
if (!bChild) {
int found;
/* XXX: Fix it. memeory leak */
found = nsVersionRegistry::uninstallFileExists(regPackageName->ToNewCString(), vrName->ToNewCString());
if (found != REGERR_OK)
bUpgrade = false;
else
bUpgrade = true;
} else if (REGERR_OK == nsVersionRegistry::inRegistry(vrName->ToNewCString())) {
bUpgrade = true;
} else {
bUpgrade = false;
}
refCount = nsVersionRegistry::getRefCount(vrName->ToNewCString());
if (!bUpgrade) {
if (refCount != 0) {
rc = 1 + refCount;
nsVersionRegistry::installComponent(vrName->ToNewCString(), finalFile->ToNewCString(), versionInfo, rc );
} else {
if (replace)
nsVersionRegistry::installComponent(vrName->ToNewCString(), finalFile->ToNewCString(), versionInfo, 2);
else
nsVersionRegistry::installComponent(vrName->ToNewCString(), finalFile->ToNewCString(), versionInfo, 1);
}
} else if (bUpgrade) {
if (refCount == 0) {
nsVersionRegistry::installComponent(vrName->ToNewCString(), finalFile->ToNewCString(), versionInfo, 1);
} else {
nsVersionRegistry::installComponent(vrName->ToNewCString(), finalFile->ToNewCString(), versionInfo );
}
}
if ( !bChild && !bUpgrade ) {
nsVersionRegistry::uninstallAddFile(regPackageName->ToNewCString(), vrName->ToNewCString());
}
}
if ( err != 0 ) {
return SU_GetErrorMsg2(err, finalFile);
}
return NULL;
}
void nsInstallFile::Abort()
{
NativeAbort();
}
char* nsInstallFile::toString()
{
#ifdef XXX
if (replace) {
return SU_GetString2(details_ReplaceFile_MSG_ID, finalFile);
} else {
return SU_GetString2(details_InstallFile_MSG_ID, finalFile);
}
#else
return NULL;
#endif
}
/* Private Methods */
/* Private Native Methods */
void nsInstallFile::NativeAbort()
{
char* currentName;
int result;
/* Get the names */
currentName = tempFile->ToNewCString();
result = XP_FileRemove(currentName, xpURL);
XP_ASSERT(result == 0); /* XXX: need to fe_deletefilelater() or something */
delete currentName;
}
/* NativeComplete
* copies the file to its final location
* Tricky, we need to create the directories
*/
int nsInstallFile::NativeComplete()
{
char* currentName;
char* finalName = NULL;
char* finalNamePlatform;
int result = 0;
/* Get the names */
currentName = tempFile->ToNewCString();
finalNamePlatform = finalFile->ToNewCString();
finalName = XP_PlatformFileToURL(finalNamePlatform);
if ( finalName == NULL || currentName == NULL ) {
/* memory or JRI problems */
result = -1;
goto end;
} else {
/* convert finalName name to xpURL form by stripping "file://" */
char *temp = XP_STRDUP(&finalName[7]);
XP_FREE(finalName);
finalName = temp;
}
if (finalName != NULL) {
if ( XP_STRCMP(finalName, currentName) == 0 ) {
/* No need to rename, they are the same */
result = 0;
} else {
XP_StatStruct s;
if ( XP_Stat( finalName, &s, xpURL ) != 0 ) {
/* Target file doesn't exist, try to rename file */
result = XP_FileRename(currentName, xpURL, finalName, xpURL);
} else {
/* Target exists, can't trust XP_FileRename--do platform
* specific stuff in FE_ReplaceExistingFile()
*/
result = -1;
}
}
} else {
/* memory problem */
result = -1;
}
if (result != 0) {
XP_StatStruct s;
if ( XP_Stat( finalName, &s, xpURL ) == 0 ) {
/* File already exists, need to remove the original */
result = FE_ReplaceExistingFile(currentName, xpURL, finalName, xpURL, force);
if ( result == nsSoftwareUpdate_REBOOT_NEEDED ) {
#ifdef XP_WIN16
if (!utilityScheduled) {
utilityScheduled = PR_TRUE;
FE_ScheduleRenameUtility();
}
#endif
}
} else {
/* Directory might not exist, check and create if necessary */
char separator;
char * end;
separator = '/';
end = XP_STRRCHR(finalName, separator);
if (end) {
end[0] = 0;
result = XP_MakeDirectoryR( finalName, xpURL);
end[0] = separator;
if ( 0 == result )
result = XP_FileRename(currentName, xpURL, finalName, xpURL);
}
}
#ifdef XP_UNIX
/* Last try, can't rename() across file systems on UNIX */
if ( -1 == result ) {
result = FE_CopyFile(currentName, finalName);
}
#endif
}
end:
XP_FREEIF(finalName);
delete currentName;
delete finalNamePlatform;
return result;
}
/* Finds out if the file exists
*/
PRBool nsInstallFile::NativeDoesFileExist()
{
char* fileName;
char* fileNamePlatform;
int32 err;
XP_StatStruct statinfo;
XP_Bool exists = FALSE;
fileNamePlatform = finalFile->ToNewCString();
fileName = XP_PlatformFileToURL(fileNamePlatform);
if (fileName != NULL) {
char * temp = XP_STRDUP(&fileName[7]);
XP_FREEIF(fileName);
fileName = temp;
if (fileName) {
err = XP_Stat(fileName, &statinfo, xpURL);
if (err != -1) {
exists = PR_TRUE;
}
}
}
XP_FREEIF(fileName);
delete fileNamePlatform;
return exists;
}
void nsInstallFile::AddToClasspath(nsString* file)
{
if ( file != NULL ) {
/* XXX: What should we do?
LJ_AddToClassPath((PRUnichar*)file);
*/
}
}
PR_END_EXTERN_C

View File

@ -0,0 +1,24 @@
/* -*- 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 "nsInstallPath.h"
PR_BEGIN_EXTERN_C
PR_END_EXTERN_C

View File

@ -0,0 +1,88 @@
/* -*- 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 "prprf.h"
#include "nsSUError.h"
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
char * SU_GetErrorMsg1(int id, char* arg1)
{
char* errorMsg=NULL;
char* tag = XP_GetString(id);
PR_ASSERT(tag != NULL);
errorMsg = PR_sprintf_append(errorMsg, tag, arg1);
return errorMsg;
}
char * SU_GetErrorMsg2(int id, nsString* arg1)
{
char* errorMsg=NULL;
char* tag = XP_GetString(id);
PR_ASSERT(tag != NULL);
char* argMsg = arg1->ToNewCString();
errorMsg = PR_sprintf_append(errorMsg, tag, argMsg);
delete argMsg;
return errorMsg;
}
char * SU_GetErrorMsg3(char *str, int err)
{
char* errorMsg=NULL;
PR_ASSERT(str != NULL);
errorMsg = PR_sprintf_append(errorMsg, "%s %d", str, err);
return errorMsg;
}
char * SU_GetString(int id)
{
char *str = XP_GetString(id);
PR_ASSERT(str != NULL);
return XP_STRDUP(str);
}
char * SU_GetString1(int id, char* arg1)
{
char* msg=NULL;
char* tag = XP_GetString(id);
PR_ASSERT(tag != NULL);
msg = PR_sprintf_append(msg, tag, arg1);
return msg;
}
char * SU_GetString2(int id, nsString* arg1)
{
char* msg=NULL;
char* tag = XP_GetString(id);
PR_ASSERT(tag != NULL);
char* argMsg = arg1->ToNewCString();
msg = PR_sprintf_append(msg, tag, argMsg);
delete argMsg;
return msg;
}
#ifdef __cplusplus
} /* extern "C" */
#endif /* __cplusplus */

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,24 @@
/* -*- 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 "nsTrigger.h"
PR_BEGIN_EXTERN_C
PR_END_EXTERN_C

View File

@ -0,0 +1,150 @@
/* -*- 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 "prmem.h"
#include "prmon.h"
#include "prlog.h"
#include "prefapi.h"
#include "prprf.h"
#include "nsVersionInfo.h"
#include "nsString.h"
PR_BEGIN_EXTERN_C
/* Public Methods */
nsVersionInfo::nsVersionInfo(PRInt32 maj, PRInt32 min, PRInt32 rel, PRInt32 bld, PRInt32 checksum)
{
major = maj;
minor = min;
release = rel;
build = bld;
check = checksum;
}
nsVersionInfo::nsVersionInfo(char* versionArg)
{
PRInt32 errorCode;
nsString version(versionArg);
int dot = version.Find('.', 0);
if ( dot == -1 ) {
major = version.ToInteger(&errorCode);
}
else {
nsString majorStr;
version.Mid(majorStr, 0, dot);
major = majorStr.ToInteger(&errorCode);
int prev = dot+1;
dot = version.Find('.',prev);
if ( dot == -1 ) {
nsString minorStr;
version.Mid(minorStr, prev, version.Length() - prev);
minor = minorStr.ToInteger(&errorCode);
}
else {
nsString minorStr;
version.Mid(minorStr, prev, dot - prev);
minor = minorStr.ToInteger(&errorCode);
prev = dot+1;
dot = version.Find('.',prev);
if ( dot == -1 ) {
nsString releaseStr;
version.Mid(releaseStr, prev, version.Length() - prev);
release = releaseStr.ToInteger(&errorCode);
}
else {
nsString releaseStr;
version.Mid(releaseStr, prev, dot - prev);
release = releaseStr.ToInteger(&errorCode);
prev = dot+1;
if ( version.Length() > dot ) {
nsString buildStr;
version.Mid(buildStr, prev, version.Length() - prev);
build = buildStr.ToInteger(&errorCode);
}
}
}
}
}
nsVersionInfo::~nsVersionInfo()
{
}
/* Text representation of the version info */
char* nsVersionInfo::toString()
{
char *result=NULL;
result = PR_sprintf_append(result, "%d.%d.%d.%d", major, minor, release, build);
return result;
}
/*
* compareTo() -- Compares version info.
* Returns -n, 0, n, where n = {1-4}
*/
nsVersionEnum nsVersionInfo::compareTo(nsVersionInfo* vi)
{
nsVersionEnum diff;
if ( vi == NULL ) {
diff = nsVersionEnum_MAJOR_DIFF;
}
else if ( major == vi->major ) {
if ( minor == vi->minor ) {
if ( release == vi->release ) {
if ( build == vi->build )
diff = nsVersionEnum_EQUAL;
else if ( build > vi->build )
diff = nsVersionEnum_BLD_DIFF;
else
diff = -nsVersionEnum_BLD_DIFF;
}
else if ( release > vi->release )
diff = nsVersionEnum_REL_DIFF;
else
diff = -nsVersionEnum_REL_DIFF;
}
else if ( minor > vi->minor )
diff = nsVersionEnum_MINOR_DIFF;
else
diff = -nsVersionEnum_MINOR_DIFF;
}
else if ( major > vi->major )
diff = nsVersionEnum_MAJOR_DIFF;
else
diff = -nsVersionEnum_MAJOR_DIFF;
return diff;
}
nsVersionEnum nsVersionInfo::compareTo(char* version)
{
return compareTo(new nsVersionInfo(version));
}
nsVersionEnum nsVersionInfo::compareTo(PRInt32 maj, PRInt32 min, PRInt32 rel, PRInt32 bld)
{
return compareTo(new nsVersionInfo(maj, min, rel, bld, 0));
}
PR_END_EXTERN_C

View File

@ -0,0 +1,24 @@
/* -*- 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 "nsVersionRegistry.h"
PR_BEGIN_EXTERN_C
PR_END_EXTERN_C

View File

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

View File

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

View File

@ -0,0 +1,24 @@
/* -*- 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 "nsWinReg.h"
PR_BEGIN_EXTERN_C
PR_END_EXTERN_C

View File

@ -0,0 +1,24 @@
/* -*- 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 "nsWinRegItem.h"
PR_BEGIN_EXTERN_C
PR_END_EXTERN_C

View File

@ -0,0 +1,24 @@
/* -*- 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 "nsWinRegValue.h"
PR_BEGIN_EXTERN_C
PR_END_EXTERN_C