Bug 406807: Remove unneccesary parts of xpinstall. r=bsmedberg, sr=dveditz, a=damons

This commit is contained in:
dtownsend@oxymoronical.com 2008-01-29 18:00:45 -08:00
Родитель f4ba7775de
Коммит f4ca9dc4a6
113 изменённых файлов: 323 добавлений и 27712 удалений

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

@ -519,9 +519,7 @@ MAKEFILES_xpcom_tests="
MAKEFILES_xpinstall="
xpinstall/Makefile
xpinstall/public/Makefile
xpinstall/res/Makefile
xpinstall/src/Makefile
xpinstall/stub/Makefile
"
MAKEFILES_xpfe="

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

@ -129,10 +129,6 @@
#include "nsINIParser.h"
#ifdef MOZ_XPINSTALL
#include "InstallCleanupDefines.h"
#endif
#include <stdlib.h>
#ifdef XP_UNIX
@ -1158,69 +1154,6 @@ DumpHelp()
DumpArbitraryHelp();
}
#ifdef MOZ_XPINSTALL
// don't modify aAppDir directly... clone it first
static int
VerifyInstallation(nsIFile* aAppDir)
{
static const char lastResortMessage[] =
"A previous install did not complete correctly. Finishing install.";
// Maximum allowed / used length of alert message is 255 chars, due to restrictions on Mac.
// Please make sure that file contents and fallback_alert_text are at most 255 chars.
char message[256];
PRInt32 numRead = 0;
const char *messageToShow = lastResortMessage;
nsresult rv;
nsCOMPtr<nsIFile> messageFile;
rv = aAppDir->Clone(getter_AddRefs(messageFile));
if (NS_SUCCEEDED(rv)) {
messageFile->AppendNative(NS_LITERAL_CSTRING("res"));
messageFile->AppendNative(CLEANUP_MESSAGE_FILENAME);
PRFileDesc* fd = 0;
nsCOMPtr<nsILocalFile> lf (do_QueryInterface(messageFile));
if (lf) {
rv = lf->OpenNSPRFileDesc(PR_RDONLY, 0664, &fd);
if (NS_SUCCEEDED(rv)) {
numRead = PR_Read(fd, message, sizeof(message)-1);
if (numRead > 0) {
message[numRead] = 0;
messageToShow = message;
}
}
}
}
ShowOSAlert(messageToShow);
nsCOMPtr<nsIFile> cleanupUtility;
aAppDir->Clone(getter_AddRefs(cleanupUtility));
if (!cleanupUtility) return 1;
cleanupUtility->AppendNative(CLEANUP_UTIL);
ScopedXPCOMStartup xpcom;
rv = xpcom.Initialize();
if (NS_FAILED(rv)) return 1;
{ // extra scoping needed to release things before xpcom shutdown
//Create the process framework to run the cleanup utility
nsCOMPtr<nsIProcess> cleanupProcess
(do_CreateInstance(NS_PROCESS_CONTRACTID));
rv = cleanupProcess->Init(cleanupUtility);
if (NS_FAILED(rv)) return 1;
rv = cleanupProcess->Run(PR_FALSE,nsnull, 0, nsnull);
if (NS_FAILED(rv)) return 1;
}
return 0;
}
#endif
#ifdef DEBUG_warren
#ifdef XP_WIN
#define _CRTDBG_MAP_ALLOC
@ -2876,33 +2809,6 @@ XRE_main(int argc, char* argv[], const nsXREAppData* aAppData)
return 1;
}
#ifdef MOZ_XPINSTALL
//----------------------------------------------------------------
// We need to check if a previous installation occured and
// if so, make sure it finished and cleaned up correctly.
//
// If there is an xpicleanup.dat file left around, that means the
// previous installation did not finish correctly. We must cleanup
// before a valid mozilla can run.
//
// Show the user a platform-specific Alert message, then spawn the
// xpicleanup utility, then exit.
//----------------------------------------------------------------
{
nsCOMPtr<nsIFile> registryFile;
rv = dirProvider.GetAppDir()->Clone(getter_AddRefs(registryFile));
if (NS_SUCCEEDED(rv)) {
registryFile->AppendNative(CLEANUP_REGISTRY);
PRBool exists;
rv = registryFile->Exists(&exists);
if (NS_SUCCEEDED(rv) && exists) {
return VerifyInstallation(dirProvider.GetAppDir());
}
}
}
#endif
#ifdef MOZ_ENABLE_XREMOTE
// handle -remote now that xpcom is fired up

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

@ -24,6 +24,7 @@
# Daniel Veditz <dveditz@netscape.com>
# Douglas Turner <dougt@netscape.com>
# Samir Gehani <sgehani@netscape.com>
# Dave Townsend <dtownsend@oxymoronical.com>
#
# Alternatively, the contents of this file may be used under the terms of
# either of the GNU General Public License Version 2 or later (the "GPL"),
@ -47,14 +48,6 @@ VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = xpinstall
DIRS = public src cleanup
ifndef MOZ_ENABLE_LIBXUL
DIRS += stub
endif
ifndef MOZ_XUL_APP
DIRS += res
endif
DIRS = public src
include $(topsrcdir)/config/rules.mk

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

@ -1,155 +0,0 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (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/MPL/
*
* 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 Navigator.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corp.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Don Bragg <dbragg@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "InstallCleanup.h"
int PerformScheduledTasks(HREG reg)
{
int deleteComplete = DONE;
int replaceComplete = DONE;
deleteComplete = DeleteScheduledFiles( reg );
replaceComplete = ReplaceScheduledFiles( reg );
if ((deleteComplete == DONE) && (replaceComplete == DONE))
return DONE;
else
return TRY_LATER;
}
//----------------------------------------------------------------------------
// ReplaceScheduledFiles
//----------------------------------------------------------------------------
int ReplaceScheduledFiles( HREG reg )
{
RKEY key;
int rv = DONE;
/* replace files if any listed */
if (REGERR_OK == NR_RegGetKey(reg,ROOTKEY_PRIVATE,REG_REPLACE_LIST_KEY,&key))
{
char keyname[MAXREGNAMELEN];
char doomedFile[MAXREGPATHLEN];
char srcFile[MAXREGPATHLEN];
uint32 bufsize;
REGENUM state = 0;
while (REGERR_OK == NR_RegEnumSubkeys( reg, key, &state,
keyname, sizeof(keyname), REGENUM_CHILDREN))
{
bufsize = sizeof(srcFile);
REGERR err1 = NR_RegGetEntry( reg, (RKEY)state,
REG_REPLACE_SRCFILE, &srcFile, &bufsize);
bufsize = sizeof(doomedFile);
REGERR err2 = NR_RegGetEntry( reg, (RKEY)state,
REG_REPLACE_DESTFILE, &doomedFile, &bufsize);
if ( err1 == REGERR_OK && err2 == REGERR_OK )
{
int result = NativeReplaceFile( srcFile, doomedFile );
if (result == DONE)
{
// This one is done
NR_RegDeleteKey( reg, key, keyname );
}
}
}
/* delete list node if empty */
state = 0;
if (REGERR_NOMORE == NR_RegEnumSubkeys( reg, key, &state, keyname,
sizeof(keyname), REGENUM_CHILDREN ))
{
NR_RegDeleteKey(reg, ROOTKEY_PRIVATE, REG_REPLACE_LIST_KEY);
rv = DONE;
}
else
{
rv = TRY_LATER;
}
}
return rv;
}
//----------------------------------------------------------------------------
// DeleteScheduledFiles
//----------------------------------------------------------------------------
int DeleteScheduledFiles( HREG reg )
{
REGERR err;
RKEY key;
REGENUM state = 0;
int rv = DONE;
/* perform scheduled file deletions */
if (REGERR_OK == NR_RegGetKey(reg,ROOTKEY_PRIVATE,REG_DELETE_LIST_KEY,&key))
{
// the delete key exists, so we loop through its children
// and try to delete all the listed files
char namebuf[MAXREGNAMELEN];
char valbuf[MAXREGPATHLEN];
while (REGERR_OK == NR_RegEnumEntries( reg, key, &state, namebuf,
sizeof(namebuf), 0 ) )
{
uint32 bufsize = sizeof(valbuf); // gets changed, must reset
err = NR_RegGetEntry( reg, key, namebuf, valbuf, &bufsize );
if ( err == REGERR_OK )
{
rv = NativeDeleteFile(valbuf);
if (rv == DONE)
NR_RegDeleteEntry( reg, key, namebuf);
}
}
/* delete list node if empty */
state = 0;
err = NR_RegEnumEntries(reg, key, &state, namebuf, sizeof(namebuf), 0);
if ( err == REGERR_NOMORE )
{
NR_RegDeleteKey(reg, ROOTKEY_PRIVATE, REG_DELETE_LIST_KEY);
rv = DONE;
}
else
{
rv = TRY_LATER;
}
}
return rv;
}

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

@ -1,56 +0,0 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (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/MPL/
*
* 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 Navigator.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corp.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Don Bragg <dbragg@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef INSTALL_CLEANUP_H
#define INSTALL_CLEANUP_H
#include <stdlib.h>
#include <stdio.h>
#include "prtypes.h"
#include "VerReg.h"
#define DONE 0
#define TRY_LATER -1
int PerformScheduledTasks(HREG);
int DeleteScheduledFiles(HREG);
int ReplaceScheduledFiles(HREG);
int NativeReplaceFile(const char* replacementFile, const char* doomedFile );
int NativeDeleteFile(const char* aFileToDelete);
#endif //INSTALL_CLEANUP_H

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

@ -1,62 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (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/MPL/
*
* 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 the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef INSTALLCLEANUPDEFINES_H
#define INSTALLCLEANUPDEFINES_H
// simple hack for xpicleanup.exe
#ifndef NS_LITERAL_CSTRING
#define NS_LITERAL_CSTRING(x) (x)
#endif
#define CLEANUP_MESSAGE_FILENAME NS_LITERAL_CSTRING("cmessage.txt")
#define CLEANUP_REGISTRY NS_LITERAL_CSTRING("xpicleanup.dat")
#if defined (XP_WIN)
#define CLEANUP_UTIL NS_LITERAL_CSTRING("xpicleanup.exe")
#elif defined (XP_OS2)
#define CLEANUP_UTIL NS_LITERAL_CSTRING("xpicleanup.exe")
#else
#define CLEANUP_UTIL NS_LITERAL_CSTRING("xpicleanup")
#endif
#endif

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

@ -1,558 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (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/MPL/
*
* 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 the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Don Bragg <dbragg@netscape.com>
* Samir Gehani <sgehani@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <MacTypes.h>
#include "MoreFiles.h"
#include "MoreFilesExtras.h"
#include "FullPath.h"
#include <AppleEvents.h>
#include <Gestalt.h>
#include <TextUtils.h>
#include <Folders.h>
#include <Processes.h>
#include <Resources.h>
#include <Aliases.h>
#include "InstallCleanup.h"
#include "InstallCleanupDefines.h"
#define kSleepMax 60 // sleep 1 second
Boolean gAppleEventsFlag, gQuitFlag;
long gSleepVal;
int strcasecmp(const char *str1, const char *str2);
OSErr GetFSSpecFromPath(char *aPath, FSSpec *aSpec);
void my_c2pstrcpy(Str255 aDstPStr, const char *aSrcCStr);
OSErr GetCWD(short *aVRefNum, long *aDirID);
OSErr GetCleanupReg(FSSpec *aCleanupReg);
int strcasecmp(const char *str1, const char *str2)
{
char currentChar1, currentChar2;
while (1) {
currentChar1 = *str1;
currentChar2 = *str2;
if ((currentChar1 >= 'a') && (currentChar1 <= 'z'))
currentChar1 += ('A' - 'a');
if ((currentChar2 >= 'a') && (currentChar2 <= 'z'))
currentChar2 += ('A' - 'a');
if (currentChar1 == '\0')
break;
if (currentChar1 != currentChar2)
return currentChar1 - currentChar2;
str1++;
str2++;
}
return currentChar1 - currentChar2;
}
OSErr GetFSSpecFromPath(const char *aPath, FSSpec *aSpec)
{
if (!aPath || !aSpec)
return paramErr;
// 1> verify path is not an empty string
// 2> verify path has leaf
// 3> verify path does not start with leading ':'
if ((!*aPath) ||
(*(aPath + strlen(aPath) - 1) == ':') ||
(*aPath == ':'))
{
return paramErr;
}
// path is kosher: get FSSpec for it
return FSpLocationFromFullPath(strlen(aPath), (const void *) aPath, aSpec);
}
void
my_c2pstrcpy(Str255 aDstPStr, const char *aSrcCStr)
{
if (!aSrcCStr)
return;
memcpy(&aDstPStr[1], aSrcCStr, strlen(aSrcCStr) > 255 ? 255 : strlen(aSrcCStr));
aDstPStr[0] = strlen(aSrcCStr);
}
OSErr
GetCWD(short *aVRefNum, long *aDirID)
{
OSErr err = noErr;
ProcessSerialNumber psn;
ProcessInfoRec pInfo;
FSSpec tmp;
if (!aVRefNum || !aDirID)
return paramErr;
*aVRefNum = 0;
*aDirID = 0;
/* get cwd based on curr ps info */
if (!(err = GetCurrentProcess(&psn)))
{
pInfo.processName = nil;
pInfo.processAppSpec = &tmp;
pInfo.processInfoLength = (sizeof(ProcessInfoRec));
if(!(err = GetProcessInformation(&psn, &pInfo)))
{
*aVRefNum = pInfo.processAppSpec->vRefNum;
*aDirID = pInfo.processAppSpec->parID;
}
}
return err;
}
OSErr
GetCleanupReg(FSSpec *aCleanupReg)
{
OSErr err = noErr;
short efVRefNum = 0;
long efDirID = 0;
if (!aCleanupReg)
return paramErr;
err = GetCWD(&efVRefNum, &efDirID);
if (err == noErr)
{
Str255 pCleanupReg;
my_c2pstrcpy(pCleanupReg, CLEANUP_REGISTRY);
err = FSMakeFSSpec(efVRefNum, efDirID, pCleanupReg, aCleanupReg);
}
return err;
}
#pragma mark -
//----------------------------------------------------------------------------
// Native Mac file deletion function
//----------------------------------------------------------------------------
int NativeDeleteFile(const char* aFileToDelete)
{
OSErr err;
FSSpec delSpec;
if (!aFileToDelete)
return DONE;
// stat the file
err = GetFSSpecFromPath(aFileToDelete, &delSpec);
if (err != noErr)
{
// return fine if it doesn't exist
return DONE;
}
// else try to delete it
err = FSpDelete(&delSpec);
if (err != noErr)
{
// tell user to try again later if deletion failed
return TRY_LATER;
}
return DONE;
}
//----------------------------------------------------------------------------
// Native Mac file replacement function
//----------------------------------------------------------------------------
int NativeReplaceFile(const char* aReplacementFile, const char* aDoomedFile )
{
OSErr err;
FSSpec replSpec, doomSpec, tgtDirSpec;
long dirID;
Boolean isDir;
if (!aReplacementFile || !aDoomedFile)
return DONE;
err = GetFSSpecFromPath(aReplacementFile, &replSpec);
if (err != noErr)
return DONE;
// stat replacement file
err = FSpGetDirectoryID(&replSpec, &dirID, &isDir);
if (err != noErr || isDir)
{
// return fine if it doesn't exist
return DONE;
}
// check if the replacement file and doomed file are the same
if (strcasecmp(aReplacementFile, aDoomedFile) == 0)
{
// return fine if they are the same
return DONE;
}
// try and delete doomed file (NOTE: this call also stats)
err = GetFSSpecFromPath(aDoomedFile, &doomSpec);
if (err == noErr)
{
// (will even try to delete a dir with this name)
err = FSpDelete(&doomSpec);
// if deletion failed tell user to try again later
if (err != noErr)
return TRY_LATER;
}
// get the target dir spec (parent directory of doomed file)
err = FSMakeFSSpec(doomSpec.vRefNum, doomSpec.parID, "\p", &tgtDirSpec);
if (err == noErr)
{
// now try and move replacment file to path of doomed file
err = FSpMoveRename(&replSpec, &tgtDirSpec, doomSpec.name);
if (err != noErr)
{
// if move failed tell user to try agian later
return TRY_LATER;
}
}
return DONE;
}
#pragma mark -
//----------------------------------------------------------------------------
// Routines for recovery on reboot
//----------------------------------------------------------------------------
OSErr
GetProgramSpec(FSSpecPtr aProgSpec)
{
OSErr err = noErr;
ProcessSerialNumber psn;
ProcessInfoRec pInfo;
if (!aProgSpec)
return paramErr;
/* get cwd based on curr ps info */
if (!(err = GetCurrentProcess(&psn)))
{
pInfo.processName = nil;
pInfo.processAppSpec = aProgSpec;
pInfo.processInfoLength = (sizeof(ProcessInfoRec));
err = GetProcessInformation(&psn, &pInfo);
}
return err;
}
void
PutAliasInStartupItems(FSSpecPtr aAlias)
{
OSErr err;
FSSpec fsProg, fsAlias;
long strtDirID = 0;
short strtVRefNum = 0;
FInfo info;
AliasHandle aliasH;
if (!aAlias)
return;
// find cwd
err = GetProgramSpec(&fsProg);
if (err != noErr)
return; // fail silently
// get startup items folder
err = FindFolder(kOnSystemDisk, kStartupFolderType, kCreateFolder,
&strtVRefNum, &strtDirID);
if (err != noErr)
return;
// check that an alias to ourselves doesn't already
// exist in the Startup Items folder
err = FSMakeFSSpec(strtVRefNum, strtDirID, fsProg.name, &fsAlias);
if (err == noErr)
{
// one's already there; not sure it's us so delete and recreate
// (being super paranoid; but hey it's a mac)
err = FSpDelete(&fsAlias);
if (err != noErr)
return; // fail silently
}
// create the alias file
err = NewAliasMinimal(&fsProg, &aliasH);
if (err != noErr)
return;
FSpGetFInfo(&fsProg, &info);
FSpCreateResFile(&fsAlias, info.fdCreator, info.fdType, smRoman);
short refNum = FSpOpenResFile(&fsAlias, fsRdWrPerm);
if (refNum != -1)
{
UseResFile(refNum);
AddResource((Handle)aliasH, rAliasType, 0, fsAlias.name);
ReleaseResource((Handle)aliasH);
UpdateResFile(refNum);
CloseResFile(refNum);
}
else
{
ReleaseResource((Handle)aliasH);
FSpDelete(&fsAlias);
return; // non-fatal error
}
// mark newly created file as an alias file
FSpGetFInfo(&fsAlias, &info);
info.fdFlags |= kIsAlias;
FSpSetFInfo(&fsAlias, &info);
*aAlias = fsAlias;
}
void
RemoveAliasFromStartupItems(FSSpecPtr aAlias)
{
// try to delete the alias
FSpDelete(aAlias);
}
#pragma mark -
//----------------------------------------------------------------------------
// Apple event handlers to be installed
//----------------------------------------------------------------------------
static pascal OSErr DoAEOpenApplication(const AppleEvent * theAppleEvent, AppleEvent * replyAppleEvent, long refCon)
{
#pragma unused (theAppleEvent, replyAppleEvent, refCon)
return noErr;
}
static pascal OSErr DoAEOpenDocuments(const AppleEvent * theAppleEvent, AppleEvent * replyAppleEvent, long refCon)
{
#pragma unused (theAppleEvent, replyAppleEvent, refCon)
return errAEEventNotHandled;
}
static pascal OSErr DoAEPrintDocuments(const AppleEvent * theAppleEvent, AppleEvent * replyAppleEvent, long refCon)
{
#pragma unused (theAppleEvent, replyAppleEvent, refCon)
return errAEEventNotHandled;
}
static pascal OSErr DoAEQuitApplication(const AppleEvent * theAppleEvent, AppleEvent * replyAppleEvent, long refCon)
{
#pragma unused (theAppleEvent, replyAppleEvent, refCon)
gQuitFlag = true;
return noErr;
}
//----------------------------------------------------------------------------
// install Apple event handlers
//----------------------------------------------------------------------------
static void InitAppleEventsStuff(void)
{
OSErr retCode;
if (gAppleEventsFlag) {
retCode = AEInstallEventHandler(kCoreEventClass, kAEOpenApplication,
NewAEEventHandlerUPP(DoAEOpenApplication), 0, false);
if (retCode == noErr)
retCode = AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments,
NewAEEventHandlerUPP(DoAEOpenDocuments), 0, false);
if (retCode == noErr)
retCode = AEInstallEventHandler(kCoreEventClass, kAEPrintDocuments,
NewAEEventHandlerUPP(DoAEPrintDocuments), 0, false);
if (retCode == noErr)
retCode = AEInstallEventHandler(kCoreEventClass, kAEQuitApplication,
NewAEEventHandlerUPP(DoAEQuitApplication), 0, false);
if (retCode != noErr) DebugStr("\pInstall event handler failed");
// a better way to indicate an error is to post a notification
}
}
//----------------------------------------------------------------------------
// high-level event dispatching
//----------------------------------------------------------------------------
static void DoHighLevelEvent(EventRecord * theEventRecPtr)
{
(void) AEProcessAppleEvent(theEventRecPtr);
}
#pragma mark -
void main(void)
{
OSErr retCode;
long gestResponse;
FSSpec aliasToSelf;
FSSpec fsCleanupReg;
EventRecord mainEventRec;
Boolean eventFlag, bDone = false, bHaveCleanupReg = false;
HREG reg;
int rv = DONE;
#if !TARGET_CARBON
// initialize QuickDraw globals
InitGraf(&qd.thePort);
#endif
// initialize application globals
gQuitFlag = false;
gSleepVal = kSleepMax;
// is the Apple Event Manager available?
retCode = Gestalt(gestaltAppleEventsAttr, &gestResponse);
if (retCode == noErr &&
(gestResponse & (1 << gestaltAppleEventsPresent)) != 0)
gAppleEventsFlag = true;
else gAppleEventsFlag = false;
// install Apple event handlers
InitAppleEventsStuff();
// put an alias to ourselves in the Startup Items folder
// so that if we are shutdown before finishing we do our
// tasks at startup
FSMakeFSSpec(0, 0, "\p", &aliasToSelf); // initialize
PutAliasInStartupItems(&aliasToSelf);
if ( REGERR_OK == NR_StartupRegistry() )
{
char *regName = "";
Boolean regNameAllocd = false;
Handle pathH = 0;
short pathLen = 0;
// check if XPICleanup data file exists
retCode = GetCleanupReg(&fsCleanupReg);
if (retCode == noErr)
{
bHaveCleanupReg = true;
// get full path to give to libreg open routine
retCode = FSpGetFullPath(&fsCleanupReg, &pathLen, &pathH);
if (retCode == noErr && pathH)
{
HLock(pathH);
if (*pathH)
{
regName = (char *) malloc(sizeof(char) * (pathLen + 1));
if (regName)
regNameAllocd = true;
else
retCode = memFullErr;
strncpy(regName, *pathH, pathLen);
*(regName + pathLen) = 0;
}
HUnlock(pathH);
DisposeHandle(pathH);
}
}
if ( (retCode == noErr) && (REGERR_OK == NR_RegOpen(regName, &reg)) )
{
// main event loop
while (!gQuitFlag)
{
eventFlag = WaitNextEvent(everyEvent, &mainEventRec, gSleepVal, nil);
if (mainEventRec.what == kHighLevelEvent)
DoHighLevelEvent(&mainEventRec);
rv = PerformScheduledTasks(reg);
if (rv == DONE)
{
bDone = true;
gQuitFlag = true;
}
}
NR_RegClose(&reg);
NR_ShutdownRegistry();
}
if (regNameAllocd)
free(regName);
}
// clean up the alias to ouselves since we have
// completed our tasks successfully
if (bDone)
{
if (bHaveCleanupReg)
FSpDelete(&fsCleanupReg);
RemoveAliasFromStartupItems(&aliasToSelf);
}
}

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

@ -1,144 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (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/MPL/
*
* 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 the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Don Bragg <dbragg@netscape.com>
* IBM Corp.
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "InstallCleanup.h"
#include "InstallCleanupDefines.h"
#define INCL_DOSERRORS
#define INCL_DOS
#include <os2.h>
#include <string.h>
#include <sys/stat.h>
//----------------------------------------------------------------------------
// Native OS/2 file deletion function
//----------------------------------------------------------------------------
int NativeDeleteFile(const char* aFileToDelete)
{
struct stat st;
if (stat(aFileToDelete, &st) != 0)
{
return DONE;// No file to delete, do nothing.
}
else
{
if(DosDelete(aFileToDelete) != NO_ERROR)
return TRY_LATER;
}
return DONE;
}
//----------------------------------------------------------------------------
// Native OS/2 file replacement function
//----------------------------------------------------------------------------
int NativeReplaceFile(const char* replacementFile, const char* doomedFile )
{
// replacement file must exist, doomed file doesn't have to
struct stat st;
if (stat(replacementFile, &st) != 0)
return DONE;
// don't have to do anything if the files are the same
if (stricmp(replacementFile, doomedFile) == 0)
return DONE;
if (DosDelete(doomedFile) != NO_ERROR)
{
if (stat(doomedFile, &st) == 0)
return TRY_LATER;
}
// doomedFile is gone move new file into place
if (DosMove(replacementFile, doomedFile) != NO_ERROR)
return TRY_LATER; // this shouldn't happen
return DONE;
}
int main(int argc, char *argv[], char *envp[])
{
HREG reg;
BOOL foundSpecialFile = FALSE;
struct stat st;
int status = DONE;
if ( REGERR_OK == NR_StartupRegistry())
{
char regFilePath[CCHMAXPATH];
strcpy(regFilePath, argv[0]);
char* lastSlash = strrchr(regFilePath, '\\');
if (lastSlash) {
// path does contain backslash
lastSlash++;
*lastSlash = 0; // strip off the executable name
} else {
// no backslash in path, just strip off everything
*regFilePath = 0;
}
strcat(regFilePath, CLEANUP_REGISTRY); // append reg file name
if (stat(regFilePath, &st) != 0)
strcpy(regFilePath, ""); // an empty reg file tells RegOpen to get the "default"
else
foundSpecialFile = TRUE;
if ( REGERR_OK == NR_RegOpen(regFilePath, &reg) )
{
int numAttempts = 0;
do
{
status = PerformScheduledTasks(reg);
if (status != DONE) {
DosSleep(1000); // Sleep for 1 second
numAttempts++;
}
} while ((status == TRY_LATER) && numAttempts <= 5);
NR_RegClose(&reg);
}
NR_ShutdownRegistry();
if (status == DONE) {
DosDelete(regFilePath);
}
}
return(0);
}

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

@ -1,120 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (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/MPL/
*
* 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 the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Don Bragg <dbragg@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "InstallCleanup.h"
#include <sys/stat.h>
#include <unistd.h>
#include <string.h>
//----------------------------------------------------------------------------
// Native Unix file deletion function
//----------------------------------------------------------------------------
int NativeDeleteFile(const char* aFileToDelete)
{
struct stat fileStack;
if (stat(aFileToDelete, &fileStack) != 0)
{
return DONE;// No file to delete, do nothing.
}
else
{
if(unlink(aFileToDelete) != 0)
return TRY_LATER;
}
return DONE;
}
//----------------------------------------------------------------------------
// Native Unix file replacement function
//----------------------------------------------------------------------------
int NativeReplaceFile(const char* replacementFile, const char* doomedFile )
{
struct stat fileStack;
// replacement file must exist, doomed file doesn't have to
if (stat(replacementFile, &fileStack) != 0)
return DONE;
// don't have to do anything if the files are the same
if (strcmp(replacementFile, doomedFile) == 0)
return DONE;
if (unlink(doomedFile) != 0)
{
if (stat(doomedFile, &fileStack) == 0)
return TRY_LATER;
}
else
{
// doomedFile is gone move new file into place
if (rename(replacementFile, doomedFile) != 0)
return TRY_LATER; // this shouldn't happen
}
return DONE;
}
int main(int argc,char* argv[])
{
HREG reg;
int status = DONE;
struct stat fileStack;
if ( REGERR_OK == NR_StartupRegistry())
{
char regFilePath[256];
strcpy(regFilePath, argv[0]);
strcat(regFilePath, ".dat");
if ( stat(regFilePath, &fileStack) != 0)
regFilePath[0] = '\0';
if ( REGERR_OK == NR_RegOpen(regFilePath, &reg) )
{
do {
status = PerformScheduledTasks(reg);
if (status != DONE)
sleep(1);
} while (status == TRY_LATER);
NR_RegClose(&reg);
}
NR_ShutdownRegistry();
unlink(regFilePath);
}
return(0);
}

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

@ -1,161 +0,0 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (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/MPL/
*
* 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 Navigator.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corp.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Don Bragg <dbragg@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "InstallCleanup.h"
#include "InstallCleanupDefines.h"
#include <windows.h>
#include <string.h>
//----------------------------------------------------------------------------
// Native Windows file deletion function
//----------------------------------------------------------------------------
int NativeDeleteFile(const char* aFileToDelete)
{
if (GetFileAttributes(aFileToDelete) == 0xFFFFFFFF)
{
return DONE;// No file to delete, do nothing.
}
else
{
if(!DeleteFile(aFileToDelete))
return TRY_LATER;
}
return DONE;
}
//----------------------------------------------------------------------------
// Native Windows file replacement function
//----------------------------------------------------------------------------
int NativeReplaceFile(const char* replacementFile, const char* doomedFile )
{
// replacement file must exist, doomed file doesn't have to
if (GetFileAttributes(replacementFile) == 0xFFFFFFFF)
return DONE;
// don't have to do anything if the files are the same
if (CompareString(LOCALE_SYSTEM_DEFAULT,
NORM_IGNORECASE | SORT_STRINGSORT,
replacementFile, -1,
doomedFile, -1) == CSTR_EQUAL)
return DONE;
if (!DeleteFile(doomedFile))
{
if (GetFileAttributes(doomedFile) != 0xFFFFFFFF) // file exists
return TRY_LATER;
}
// doomedFile is gone move new file into place
if (!MoveFile(replacementFile, doomedFile))
return TRY_LATER; // this shouldn't happen
return DONE;
}
int WINAPI WinMain( HINSTANCE, HINSTANCE, LPSTR args, int)
{
HREG reg;
HKEY hkRunOnceHandle;
DWORD dwDisp;
bool foundSpecialFile = FALSE;
int status = DONE;
if ( REGERR_OK == NR_StartupRegistry())
{
DWORD charsWritten;
char appPath[_MAX_PATH];
charsWritten = GetModuleFileName(NULL, appPath, _MAX_PATH);
if (charsWritten > 0)
{
char regFilePath[_MAX_PATH];
strcpy(regFilePath, appPath);
char* lastSlash = strrchr(regFilePath, '\\');
if (lastSlash) {
// path does contain backslash
lastSlash++;
*lastSlash = 0; // strip off the executable name
} else {
// no backslash in path, just strip off everything
*regFilePath = 0;
}
strcat(regFilePath, CLEANUP_REGISTRY); //append reg file name
if ( GetFileAttributes(regFilePath) == 0xFFFFFFFF ) // file doesn't exist
strcpy(regFilePath, ""); // an empty reg file tells RegOpen to get the "default"
else
foundSpecialFile = TRUE;
if ( REGERR_OK == NR_RegOpen(regFilePath, &reg) )
{
RegCreateKeyEx(HKEY_CURRENT_USER,
"Software\\Microsoft\\Windows\\CurrentVersion\\RunOnce",
0,
NULL,
REG_OPTION_NON_VOLATILE,
KEY_WRITE,
NULL,
&hkRunOnceHandle,
&dwDisp);
LPCTSTR cleanupKeyName = "mozilla_cleanup";
RegSetValueEx(hkRunOnceHandle,
cleanupKeyName,
0,
REG_SZ,
(const unsigned char*)appPath,
strlen(appPath));
do
{
status = PerformScheduledTasks(reg);
if (status != DONE)
Sleep(1000); // Sleep for 1 second
} while (status == TRY_LATER);
RegDeleteValue(hkRunOnceHandle, cleanupKeyName);
NR_RegClose(&reg);
}
NR_ShutdownRegistry();
DeleteFile(regFilePath);
}
}
return(0);
}

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

@ -1,96 +0,0 @@
#
# ***** BEGIN LICENSE BLOCK *****
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
#
# The contents of this file are subject to the Mozilla Public License Version
# 1.1 (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/MPL/
#
# 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, released
# March 31, 1998.
#
# The Initial Developer of the Original Code is
# Netscape Communications Corporation.
# Portions created by the Initial Developer are Copyright (C) 1998
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
# Samir Gehani <sgehani@netscape.com>
#
# Alternatively, the contents of this file may be used under the terms of
# either of the GNU General Public License Version 2 or later (the "GPL"),
# or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
# in which case the provisions of the GPL or the LGPL are applicable instead
# of those above. If you wish to allow use of your version of this file only
# under the terms of either the GPL or the LGPL, and not to allow others to
# use your version of this file under the terms of the MPL, indicate your
# decision by deleting the provisions above and replace them with the notice
# and other provisions required by the GPL or the LGPL. If you do not delete
# the provisions above, a recipient may use your version of this file under
# the terms of any one of the MPL, the GPL or the LGPL.
#
# ***** END LICENSE BLOCK *****
DEPTH = ../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = xpinstall
PROGRAM = xpicleanup$(BIN_SUFFIX)
GRE_MODULE = 1
REQUIRES = libreg \
$(NULL)
CPPSRCS = \
InstallCleanup.cpp \
$(NULL)
EXPORTS = InstallCleanupDefines.h \
$(NULL)
ifeq ($(OS_ARCH),OS2)
CPPSRCS += InstallCleanupOS2.cpp
else
ifeq ($(OS_ARCH),WINNT)
CPPSRCS += InstallCleanupWin.cpp
MOZ_WINCONSOLE = 0
USE_STATIC_LIBS = 1
else
CPPSRCS += InstallCleanupUnix.cpp
endif
endif
LIBS = \
$(DEPTH)/modules/libreg/standalone/$(LIB_PREFIX)mozregsa_s.$(LIB_SUFFIX) \
$(NULL)
DEFINES += -DSTANDALONE_REGISTRY
include $(topsrcdir)/config/rules.mk
ifneq (,$(filter mac cocoa,$(MOZ_WIDGET_TOOLKIT)))
LIBS += $(DEPTH)/xpcom/MoreFiles/$(LIB_PREFIX)macmorefiles_s.$(LIB_SUFFIX)
LDFLAGS += $(TK_LIBS)
endif
ifeq ($(OS_ARCH),WINNT)
ifndef GNU_CC
LDFLAGS += /SUBSYSTEM:WINDOWS
endif
endif
libs::
$(INSTALL) $(srcdir)/cmessage.txt $(DIST)/bin/res
install::
$(SYSINSTALL) $(IFLAGS1) $(srcdir)/cmessage.txt $(DESTDIR)$(mozappdir)/res

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

@ -1 +0,0 @@
The program must close to allow a previous installation attempt to complete. Please restart.

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

@ -23,6 +23,7 @@
# Contributor(s):
# Daniel Veditz <dveditz@netscape.com>
# Douglas Turner <dougt@netscape.com>
# Dave Townsend <dtownsend@oxymoronical.com>
#
# Alternatively, the contents of this file may be used under the terms of
# either of the GNU General Public License Version 2 or later (the "GPL"),
@ -51,19 +52,14 @@ GRE_MODULE = 1
XPIDLSRCS = \
nsIXPIDialogService.idl \
nsIXPIProgressDialog.idl \
nsIXPINotifier.idl \
nsIXPInstallManager.idl \
nsIXPIInstallInfo.idl \
nsPIXPIProxy.idl \
nsPIXPIStubHook.idl \
nsPICertNotification.idl \
$(NULL)
EXPORTS = \
nsIDOMInstallTriggerGlobal.h \
nsIDOMInstallVersion.h \
nsSoftwareUpdateIIDs.h \
nsISoftwareUpdate.h \
$(NULL)
PREF_JS_EXPORTS = $(srcdir)/xpinstall.js

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

@ -20,6 +20,7 @@
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Dave Townsend <dtownsend@oxymoronical.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
@ -46,8 +47,8 @@
#define NS_IDOMINSTALLTRIGGERGLOBAL_IID \
{ 0xe8c7941c, 0xaaa0, 0x4faf, \
{0x83, 0xe8, 0x01, 0xbe, 0x8b, 0xbe, 0x8a, 0x57}}
{ 0x23bb93a4, 0xdaee, 0x4a47, \
{0x87, 0xe76, 0xb1, 0x72, 0x35, 0x86, 0x2d, 0xac}}
class nsIDOMInstallTriggerGlobal : public nsISupports {
public:
@ -69,18 +70,6 @@ public:
NS_IMETHOD StartInstall(nsIXPIInstallInfo* aInstallInfo, PRBool* aReturn)=0;
NS_IMETHOD Install(nsIScriptGlobalObject* globalObject, nsXPITriggerInfo* aInfo, PRBool* aReturn)=0;
NS_IMETHOD InstallChrome(nsIScriptGlobalObject* globalObject, PRUint32 aType, nsXPITriggerItem* aItem, PRBool* aReturn)=0;
NS_IMETHOD StartSoftwareUpdate(nsIScriptGlobalObject* globalObject, const nsString& aURL, PRInt32 aFlags, PRBool* aReturn)=0;
NS_IMETHOD CompareVersion(const nsString& aRegName, PRInt32 aMajor, PRInt32 aMinor, PRInt32 aRelease, PRInt32 aBuild, PRInt32* aReturn)=0;
NS_IMETHOD CompareVersion(const nsString& aRegName, const nsString& aVersion, PRInt32* aReturn)=0;
NS_IMETHOD CompareVersion(const nsString& aRegName, nsIDOMInstallVersion* aVersion, PRInt32* aReturn)=0;
NS_IMETHOD GetVersion(const nsString& component, nsString& version)=0;
};
NS_DEFINE_STATIC_IID_ACCESSOR(nsIDOMInstallTriggerGlobal,

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

@ -1,127 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (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/MPL/
*
* 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.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/* AUTO-GENERATED. DO NOT EDIT!!! */
#ifndef nsIDOMInstallVersion_h__
#define nsIDOMInstallVersion_h__
#include "nsISupports.h"
#include "nsString.h"
#include "nsIScriptContext.h"
class nsIDOMInstallVersion;
#define NS_IDOMINSTALLVERSION_IID \
{ 0x18c2f986, 0xb09f, 0x11d2, \
{0xbc, 0xde, 0x00, 0x80, 0x5f, 0x0e, 0x13, 0x53}}
class nsIDOMInstallVersion : public nsISupports {
public:
NS_DECLARE_STATIC_IID_ACCESSOR(NS_IDOMINSTALLVERSION_IID)
enum {
EQUAL = 0,
BLD_DIFF = 1,
BLD_DIFF_MINUS = -1,
REL_DIFF = 2,
REL_DIFF_MINUS = -2,
MINOR_DIFF = 3,
MINOR_DIFF_MINUS = -3,
MAJOR_DIFF = 4,
MAJOR_DIFF_MINUS = -4
};
NS_IMETHOD GetMajor(PRInt32* aMajor)=0;
NS_IMETHOD SetMajor(PRInt32 aMajor)=0;
NS_IMETHOD GetMinor(PRInt32* aMinor)=0;
NS_IMETHOD SetMinor(PRInt32 aMinor)=0;
NS_IMETHOD GetRelease(PRInt32* aRelease)=0;
NS_IMETHOD SetRelease(PRInt32 aRelease)=0;
NS_IMETHOD GetBuild(PRInt32* aBuild)=0;
NS_IMETHOD SetBuild(PRInt32 aBuild)=0;
NS_IMETHOD Init(const nsString& aVersionString)=0;
NS_IMETHOD ToString(nsString& aReturn)=0;
NS_IMETHOD CompareTo(nsIDOMInstallVersion* aVersionObject, PRInt32* aReturn)=0;
NS_IMETHOD CompareTo(const nsString& aString, PRInt32* aReturn)=0;
NS_IMETHOD CompareTo(PRInt32 aMajor, PRInt32 aMinor, PRInt32 aRelease, PRInt32 aBuild, PRInt32* aReturn)=0;
};
NS_DEFINE_STATIC_IID_ACCESSOR(nsIDOMInstallVersion, NS_IDOMINSTALLVERSION_IID)
#define NS_DECL_IDOMINSTALLVERSION \
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 Init(const nsString& aVersionString); \
NS_IMETHOD ToString(nsString& aReturn); \
NS_IMETHOD CompareTo(nsIDOMInstallVersion* aVersionObject, PRInt32* aReturn); \
NS_IMETHOD CompareTo(const nsString& aString, PRInt32* aReturn); \
NS_IMETHOD CompareTo(PRInt32 aMajor, PRInt32 aMinor, PRInt32 aRelease, PRInt32 aBuild, PRInt32* aReturn); \
#define NS_FORWARD_IDOMINSTALLVERSION(_to) \
NS_IMETHOD GetMajor(PRInt32* aMajor) { return _to##GetMajor(aMajor); } \
NS_IMETHOD SetMajor(PRInt32 aMajor) { return _to##SetMajor(aMajor); } \
NS_IMETHOD GetMinor(PRInt32* aMinor) { return _to##GetMinor(aMinor); } \
NS_IMETHOD SetMinor(PRInt32 aMinor) { return _to##SetMinor(aMinor); } \
NS_IMETHOD GetRelease(PRInt32* aRelease) { return _to##GetRelease(aRelease); } \
NS_IMETHOD SetRelease(PRInt32 aRelease) { return _to##SetRelease(aRelease); } \
NS_IMETHOD GetBuild(PRInt32* aBuild) { return _to##GetBuild(aBuild); } \
NS_IMETHOD SetBuild(PRInt32 aBuild) { return _to##SetBuild(aBuild); } \
NS_IMETHOD Init(const nsString& aVersionString) { return _to##Init(aVersionString); } \
NS_IMETHOD ToString(nsString& aReturn) { return _to##ToString(aReturn); } \
NS_IMETHOD CompareTo(nsIDOMInstallVersion* aVersionObject, PRInt32* aReturn) { return _to##CompareTo(aVersionObject, aReturn); } \
NS_IMETHOD CompareTo(const nsString& aString, PRInt32* aReturn) { return _to##CompareTo(aString, aReturn); } \
NS_IMETHOD CompareTo(PRInt32 aMajor, PRInt32 aMinor, PRInt32 aRelease, PRInt32 aBuild, PRInt32* aReturn) { return _to##CompareTo(aMajor, aMinor, aRelease, aBuild, aReturn); } \
extern nsresult NS_InitInstallVersionClass(nsIScriptContext *aContext, void **aPrototype);
extern "C" nsresult NS_NewScriptInstallVersion(nsIScriptContext *aContext, nsISupports *aSupports, nsISupports *aParent, void **aReturn);
#endif // nsIDOMInstallVersion_h__

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

@ -1,106 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (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/MPL/
*
* 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, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Daniel Veditz <dveditz@netscape.com>
* Douglas Turner <dougt@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsISoftwareUpdate_h__
#define nsISoftwareUpdate_h__
#include "nsISupports.h"
#include "nsIFactory.h"
#include "nsIXPINotifier.h"
#include "nsCOMPtr.h"
#include "nsIModule.h"
#include "nsIGenericFactory.h"
#include "nsILocalFile.h"
#include "nsDirectoryServiceUtils.h"
#include "nsDirectoryServiceDefs.h"
#define NS_IXPINSTALLCOMPONENT_CONTRACTID "@mozilla.org/xpinstall;1"
#define NS_IXPINSTALLCOMPONENT_CLASSNAME "Mozilla XPInstall Component"
#define XPINSTALL_ENABLE_PREF "xpinstall.enabled"
#define XPINSTALL_WHITELIST_ADD "xpinstall.whitelist.add"
#define XPINSTALL_WHITELIST_ADD_103 "xpinstall.whitelist.add.103"
#define XPINSTALL_WHITELIST_REQUIRED "xpinstall.whitelist.required"
#define XPINSTALL_BLACKLIST_ADD "xpinstall.blacklist.add"
#define XPI_NO_NEW_THREAD 0x1000
#define NS_ISOFTWAREUPDATE_IID \
{ 0xfc7c086f, \
0xdae0, \
0x45e0, \
{0x99, 0x10, 0xd5, 0xda, 0x91, 0xc8, 0x27, 0x46}\
}
class nsIPrincipal;
class nsISoftwareUpdate : public nsISupports
{
public:
NS_DECLARE_STATIC_IID_ACCESSOR(NS_ISOFTWAREUPDATE_IID)
NS_IMETHOD InstallJar(nsIFile* localFile,
const PRUnichar* URL,
const PRUnichar* arguments,
nsIPrincipal* aPrincipalDisplayed,
PRUint32 flags,
nsIXPIListener* aListener = 0) = 0;
NS_IMETHOD InstallChrome(PRUint32 aType,
nsIFile* aFile,
const PRUnichar* URL,
const PRUnichar* aName,
PRBool aSelect,
nsIXPIListener* aListener = 0) = 0;
NS_IMETHOD RegisterListener(nsIXPIListener *aListener) = 0;
/* FIX: these should be in a private interface */
virtual void InstallJarCallBack() = 0;
NS_IMETHOD GetMasterListener(nsIXPIListener **aListener) = 0;
NS_IMETHOD SetActiveListener(nsIXPIListener *aListener) = 0;
};
NS_DEFINE_STATIC_IID_ACCESSOR(nsISoftwareUpdate, NS_ISOFTWAREUPDATE_IID)
#endif // nsISoftwareUpdate_h__

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

@ -1,45 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (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/MPL/
*
* 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, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsISupports.idl"
[uuid(6cb61472-042c-11d4-ac85-00c04fa0d26b)]
interface nsIUpdateNotification : nsISupports
{
void displayUpdateDialog();
};

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

@ -1,52 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (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/MPL/
*
* 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, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2000
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Douglas Turner <dougt@netscape.com>
* Daniel Veditz <dveditz@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsISupports.idl"
[uuid(eea90d40-b059-11d2-915e-c12b696c9333)]
interface nsIXPIListener : nsISupports
{
void onInstallStart(in wstring URL);
void onInstallDone(in wstring URL, in long status);
void onPackageNameSet(in wstring URL, in wstring UIPackageName, in wstring version);
void onItemScheduled(in wstring message );
void onFinalizeProgress(in wstring message, in long itemNum, in long totNum );
void onLogComment(in wstring comment);
};

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

@ -1,104 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (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/MPL/
*
* 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, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998-2001
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Daniel Veditz <dveditz@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsISupports.idl"
/**
* nsPIXPIProxy
*
* Used to handle miscellaneous things that XPInstall needs to perform
* over on the main UI thread.
*/
[scriptable,uuid(6F9D2890-167D-11d5-8DAF-000064657374)]
interface nsPIXPIProxy : nsISupports
{
void refreshPlugins(in boolean reloadPages);
void notifyRestartNeeded();
/**
* Puts up an alert dialog with an OK button.
*
* @param title
* Text to appear in the title of the dialog.
* @param text
* Text to appear in the body of the dialog.
*/
void alert(in wstring title, in wstring text);
/**
* Puts up a dialog with up to 3 buttons and an optional, labeled checkbox.
*
* @param aDialogTitle
* Text to appear in the title of the dialog.
* @param aText
* Text to appear in the body of the dialog.
* @param aButtonFlags
* A combination of Button Flags.
* @param aButton0Title
* Used when button 0 uses TITLE_IS_STRING
* @param aButton1Title
* Used when button 1 uses TITLE_IS_STRING
* @param aButton2Title
* Used when button 2 uses TITLE_IS_STRING
* @param aCheckMsg
* Text to appear with the checkbox. Null if no checkbox.
* @param aCheckState
* Contains the initial checked state of the checkbox when this method
* is called and the final checked state after this method returns.
*
* @return index of the button pressed.
*
* Buttons are numbered 0 - 2. The implementation can decide whether the
* sequence goes from right to left or left to right. Button 0 is the
* default button unless one of the Button Default Flags is specified.
*
* The value for aButtonFlags is constructed using the constants defined by
* nsIPromptService.
*
* @see nsIPromptService
*/
PRInt32 confirmEx(in wstring aDialogTitle,
in wstring aText,
in unsigned long aButtonFlags,
in wstring aButton0Title,
in wstring aButton1Title,
in wstring aButton2Title,
in wstring aCheckMsg,
inout boolean aCheckState);
};

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

@ -1,54 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (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/MPL/
*
* 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, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Daniel Veditz <dveditz@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsISupports.idl"
interface nsIFile;
/**
* nsPIXPIStubHook
*
* Used by the Install Wizard to point at the eventual target dir and
* override the default assumption that the wizard itself is the program.
*/
[uuid(089929F0-4ED9-11d3-ABDD-000064657374)]
interface nsPIXPIStubHook : nsISupports
{
void StubInitialize(in nsIFile dir, in string logName);
};

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

@ -22,6 +22,7 @@
* Contributor(s):
* Daniel Veditz <dveditz@netscape.com>
* Douglas Turner <dougt@netscape.com>
* Dave Townsend <dtownsend@oxymoronical.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
@ -40,22 +41,6 @@
#ifndef nsSoftwareUpdateIIDs_h___
#define nsSoftwareUpdateIIDs_h___
#define NS_SoftwareUpdate_CID \
{ /* 18c2f989-b09f-11d2-bcde-00805f0e1353 */ \
0x18c2f989, \
0xb09f, \
0x11d2, \
{0xbc, 0xde, 0x00, 0x80, 0x5f, 0x0e, 0x13, 0x53} \
}
#define NS_SoftwareUpdateInstall_CID \
{ /* 18c2f98b-b09f-11d2-bcde-00805f0e1353 */ \
0x18c2f98b, \
0xb09f, \
0x11d2, \
{0xbc, 0xde, 0x00, 0x80, 0x5f, 0x0e, 0x13, 0x53} \
}
#define NS_SoftwareUpdateInstallTrigger_CID \
{ /* 18c2f98d-b09f-11d2-bcde-00805f0e1353 */ \
0x18c2f98d, \
@ -64,14 +49,6 @@
{0xbc, 0xde, 0x00, 0x80, 0x5f, 0x0e, 0x13, 0x53} \
}
#define NS_SoftwareUpdateInstallVersion_CID \
{ /* 18c2f98f-b09f-11d2-bcde-00805f0e1353 */ \
0x18c2f98f, \
0xb09f, \
0x11d2, \
{0xbc, 0xde, 0x00, 0x80, 0x5f, 0x0e, 0x13, 0x53} \
}
#define NS_XPInstallManager_CID \
{ /* {6a4d4c1e-a74a-4320-8124-16233a0183d6} */ \
0x6a4d4c1e, \

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

@ -1,46 +0,0 @@
#
# ***** BEGIN LICENSE BLOCK *****
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
#
# The contents of this file are subject to the Mozilla Public License Version
# 1.1 (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/MPL/
#
# 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.org code.
#
# The Initial Developer of the Original Code is
# Netscape Communications Corporation.
# Portions created by the Initial Developer are Copyright (C) 1998
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
#
# Alternatively, the contents of this file may be used under the terms of
# either of the GNU General Public License Version 2 or later (the "GPL"),
# or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
# in which case the provisions of the GPL or the LGPL are applicable instead
# of those above. If you wish to allow use of your version of this file only
# under the terms of either the GPL or the LGPL, and not to allow others to
# use your version of this file under the terms of the MPL, indicate your
# decision by deleting the provisions above and replace them with the notice
# and other provisions required by the GPL or the LGPL. If you do not delete
# the provisions above, a recipient may use your version of this file under
# the terms of any one of the MPL, the GPL or the LGPL.
#
# ***** END LICENSE BLOCK *****
DEPTH = ../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
include $(topsrcdir)/config/rules.mk

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

@ -1,64 +0,0 @@
<?xml version="1.0"?> <!-- -*- Mode: SGML -*- -->
<!-- ***** BEGIN LICENSE BLOCK *****
- Version: MPL 1.1/GPL 2.0/LGPL 2.1
-
- The contents of this file are subject to the Mozilla Public License Version
- 1.1 (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/MPL/
-
- 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.
-
- The Initial Developer of the Original Code is
- Netscape Communications Corp.
- Portions created by the Initial Developer are Copyright (C) 1999
- the Initial Developer. All Rights Reserved.
-
- Contributor(s):
- Doug Turner <dougt@netscape.com>
- Chris Waterson <waterson@netscape.com>
-
- Alternatively, the contents of this file may be used under the terms of
- either of the GNU General Public License Version 2 or later (the "GPL"),
- or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- in which case the provisions of the GPL or the LGPL are applicable instead
- of those above. If you wish to allow use of your version of this file only
- under the terms of either the GPL or the LGPL, and not to allow others to
- use your version of this file under the terms of the MPL, indicate your
- decision by deleting the provisions above and replace them with the notice
- and other provisions required by the GPL or the LGPL. If you do not delete
- the provisions above, a recipient may use your version of this file under
- the terms of any one of the MPL, the GPL or the LGPL.
-
- ***** END LICENSE BLOCK ***** -->
<RDF:RDF xmlns:RDF="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:NC="http://home.netscape.com/NC-rdf#">
<RDF:Bag about="http://home.netscape.com/NC-rdf#SoftwareUpdateRoot">
<RDF:li>
<RDF:Bag about="http://home.netscape.com/NC-rdf#SoftwarePackages" NC:title="Test Updates" NC:url="http://www.netscape.com/people/dougt">
<RDF:li>
<RDF:Description ID="Update344">
<NC:version>3.4.1.12</NC:version>
<NC:registryKey>/AOL/</NC:registryKey>
</RDF:Description>
</RDF:li>
<RDF:li>
<RDF:Description ID="PGPPlugin345">
<NC:version>1.1.2.0</NC:version>
<NC:registryKey>/PGP/ROCKS/</NC:registryKey>
</RDF:Description>
</RDF:li>
</RDF:Bag>
</RDF:li>
</RDF:Bag>
</RDF:RDF>

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

@ -1,46 +0,0 @@
<?xml version="1.0"?> <!-- -*- Mode: SGML -*- -->
<!-- ***** BEGIN LICENSE BLOCK *****
- Version: MPL 1.1/GPL 2.0/LGPL 2.1
-
- The contents of this file are subject to the Mozilla Public License Version
- 1.1 (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/MPL/
-
- 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.
-
- The Initial Developer of the Original Code is
- Netscape Communications Corp.
- Portions created by the Initial Developer are Copyright (C) 1999
- the Initial Developer. All Rights Reserved.
-
- Contributor(s):
- Doug Turner <dougt@netscape.com>
- Chris Waterson <waterson@netscape.com>
-
- Alternatively, the contents of this file may be used under the terms of
- either of the GNU General Public License Version 2 or later (the "GPL"),
- or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- in which case the provisions of the GPL or the LGPL are applicable instead
- of those above. If you wish to allow use of your version of this file only
- under the terms of either the GPL or the LGPL, and not to allow others to
- use your version of this file under the terms of the MPL, indicate your
- decision by deleting the provisions above and replace them with the notice
- and other provisions required by the GPL or the LGPL. If you do not delete
- the provisions above, a recipient may use your version of this file under
- the terms of any one of the MPL, the GPL or the LGPL.
-
- ***** END LICENSE BLOCK ***** -->
<RDF:RDF xmlns:RDF="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:NC="http://home.netscape.com/NC-rdf#">
<RDF:Bag about="http://home.netscape.com/NC-rdf#SoftwareUpdateDataSources">
<RDF:li resource="chrome://communicator/content/xpinstall/SoftwareUpdate-Source-1.rdf" />
</RDF:Bag>
</RDF:RDF>

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

@ -1,140 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (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/MPL/
*
* 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, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
// dialog param block
var gParam;
var gBundle;
function addTreeItem(num, aName, aUrl, aCertName)
{
// first column is the package name
var item = document.createElement("description");
item.setAttribute("value", aName);
item.setAttribute("tooltiptext", aName);
item.setAttribute("class", "confirmName");
item.setAttribute("crop", "center");
// second column is for the cert name
var certName = document.createElement("description");
var certNameValue = aCertName ? aCertName : gBundle.getString("Unsigned");
certName.setAttribute("value", certNameValue);
certName.setAttribute("tooltiptext", certNameValue);
certName.setAttribute("crop", "center");
// third column is the host serving the file
var urltext = aUrl.replace(/^([^:]*:\/*[^\/]+).*/, "$1");
var url = document.createElement("description");
url.setAttribute("value", aUrl);
url.setAttribute("tooltiptext", aUrl);
url.setAttribute("class", "confirmURL");
url.setAttribute("crop", "center");
// create row and add it to the grid
var row = document.createElement("row");
row.appendChild(item);
row.appendChild(certName);
row.appendChild(url);
document.getElementById("xpirows").appendChild(row);
}
function onLoad()
{
var row = 0;
var moduleName, URL, IconURL, certName, numberOfDialogTreeElements;
gBundle = document.getElementById("xpinstallBundle");
gParam = window.arguments[0].QueryInterface(Components.interfaces.nsIDialogParamBlock);
gParam.SetInt(0, 1); // Set the default return to Cancel
numberOfDialogTreeElements = gParam.GetInt(1);
for (var i=0; i < numberOfDialogTreeElements; i++)
{
moduleName = gParam.GetString(i);
URL = gParam.GetString(++i);
IconURL = gParam.GetString(++i); // Advance the enumeration, parameter is unused just now.
certName = gParam.GetString(++i);
addTreeItem(row++, moduleName, URL, certName);
}
// Move default+focus from |accept| to |cancel| button.
var aButton = document.documentElement.getButton("accept");
aButton.setAttribute("default", false);
aButton.setAttribute("label", gBundle.getString("OK"));
aButton.setAttribute("disabled", true);
aButton = document.documentElement.getButton("cancel");
aButton.focus();
aButton.setAttribute("default", true);
// start timer to re-enable buttons
var delayInterval = 2000;
try {
var prefs = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefBranch);
delayInterval = prefs.getIntPref("security.dialog_enable_delay");
} catch (e) {}
setTimeout(reenableInstallButtons, delayInterval);
}
function reenableInstallButtons()
{
document.documentElement.getButton("accept").setAttribute("disabled", false);
}
function onAccept()
{
// set the accept button in the param block
if (gParam)
gParam.SetInt(0, 0);
return true;
}
function onCancel()
{
// set the cancel button in the param block
if (gParam)
gParam.SetInt(0, 1);
return true;
}

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

@ -1,87 +0,0 @@
<?xml version="1.0"?>
<!-- ***** BEGIN LICENSE BLOCK *****
Version: MPL 1.1/GPL 2.0/LGPL 2.1
The contents of this file are subject to the Mozilla Public License Version
1.1 (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/MPL/
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 the Initial Developer are Copyright (C) 1998-1999
the Initial Developer. All Rights Reserved.
Contributor(s):
Don Bragg <dbragg@netscape.com>
Dan Veditz <dveditz@netscape.com>
Blake Ross <blakeross@telocity.com>
Håkan Waara <hwaara@chello.se>
Alternatively, the contents of this file may be used under the terms of
either of the GNU General Public License Version 2 or later (the "GPL"),
or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
in which case the provisions of the GPL or the LGPL are applicable instead
of those above. If you wish to allow use of your version of this file only
under the terms of either the GPL or the LGPL, and not to allow others to
use your version of this file under the terms of the MPL, indicate your
decision by deleting the provisions above and replace them with the notice
and other provisions required by the GPL or the LGPL. If you do not delete
the provisions above, a recipient may use your version of this file under
the terms of any one of the MPL, the GPL or the LGPL.
***** END LICENSE BLOCK ***** -->
<?xml-stylesheet href="chrome://communicator/skin/xpinstall/xpinstall.css" type="text/css"?>
<!DOCTYPE dialog SYSTEM "chrome://communicator/locale/xpinstall/institems.dtd">
<dialog xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
onload="onLoad()"
title="&dialog.title;"
id="confirmDlg"
style="width: 60em"
buttons="accept,cancel"
ondialogaccept="return onAccept();"
ondialogcancel="return onCancel();">
<script src="chrome://communicator/content/xpinstall/institems.js"/>
<stringbundle id="xpinstallBundle" src="chrome://global/locale/xpinstall/xpinstall.properties"/>
<hbox flex="1" align="center">
<hbox align="center">
<image id="alert-image" class="alert-icon"/>
</hbox>
<vbox id="confirmBox" flex="1">
<description id="warn1" flex="1">
&warningText.label;
</description>
<separator class="confirmSeparator"/>
<grid id="confirmGrid" flex="1">
<columns>
<column id="xpiColumn" flex="1"/>
<column id="certColumn" flex="1"/>
<column id="urlColumn" flex="1"/>
</columns>
<rows id="xpirows">
</rows>
</grid>
<separator class="confirmSeparator"/>
<description id="warn2" flex="1">
&warningText2.label;
</description>
</vbox>
</hbox>
</dialog>

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

@ -1,33 +0,0 @@
<?xml version="1.0"?>
<!DOCTYPE overlay SYSTEM "chrome://global/locale/updateNotification.dtd" >
<overlay id="updateNotificationMenuID"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/x-javascript">
function ShowUpdateFromResource( node )
{
var url = node.getAttribute('updateURL');
dump (url + '\n' );
//window.open( url );
}
</script>
<menupopup id="taskPopup">
<menu label="&updateNotification.label;" datasources="rdf:xpinstall-update-notifier" ref="http://home.netscape.com/NC-rdf#SoftwareNotificationRoot">
<template>
<rule>
<menupopup>
<menuitem uri="rdf:*" label="rdf:http://home.netscape.com/NC-rdf#name" updateURL="rdf:http://home.netscape.com/NC-rdf#url" oncommand="ShowUpdateFromResource( event.target )"/>
</menupopup>
</rule>
</template>
</menu>
<menuseparator/>
</menupopup>
</overlay>

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

@ -1,190 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (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/MPL/
*
* 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, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
var gManager;
var gBundle;
var gCanClose = false;
var gCancelled = false;
// implements nsIXPIProgressDialog
var progressHooks =
{
onStateChange: function( aIndex, aState, aValue )
{
const state = Components.interfaces.nsIXPIProgressDialog;
var status = document.getElementById("status"+aIndex);
var progress = document.getElementById("progress"+aIndex);
switch( aState ) {
case state.DOWNLOAD_START:
status.setAttribute("value",
gBundle.getString("progress.downloading"));
progress.setAttribute("value","0%");
break;
case state.DOWNLOAD_DONE:
status.setAttribute("value",
gBundle.getString("progress.downloaded"));
progress.setAttribute("value","100%");
break;
case state.INSTALL_START:
status.setAttribute("value",
gBundle.getString("progress.installing"));
progress.setAttribute("mode","undetermined");
break;
case state.INSTALL_DONE:
progress.setAttribute("mode","determined");
progress.hidden = true;
var msg;
try
{
msg = gBundle.getString("error"+aValue);
}
catch (e)
{
msg = gBundle.stringBundle.formatStringFromName(
"unknown.error", [aValue], 1 );
}
status.setAttribute("value",msg);
break;
case state.DIALOG_CLOSE:
// nsXPInstallManager is done with us, but we'll let users
// dismiss the dialog themselves so they can see the status
// (unless we're closing because the user cancelled)
document.documentElement.getButton("accept").disabled = false;
document.documentElement.getButton("cancel").disabled = true;
document.documentElement.getButton("accept").focus();
gCanClose = true;
if (gCancelled)
window.close();
break;
}
},
onProgress: function( aIndex, aValue, aMaxValue )
{
var percent = Math.round( 100 * (aValue/aMaxValue) );
var node = document.getElementById("progress"+aIndex);
node.setAttribute("value", percent);
},
QueryInterface: function( iid )
{
if (iid.equals(Components.interfaces.nsISupports) ||
iid.equals(Components.interfaces.nsIXPIProgressDialog))
return this;
Components.returnCode = Components.results.NS_ERROR_NO_INTERFACE;
return null;
}
}
function onLoad()
{
document.documentElement.getButton("accept").disabled = true;
document.documentElement.getButton("cancel").focus();
gBundle = document.getElementById("xpinstallBundle");
var param = window.arguments[0].QueryInterface(
Components.interfaces.nsIDialogParamBlock );
if ( !param )
dump (" error getting param block interface \n");
var i = 0;
var row = 0;
var numElements = param.GetInt(1);
while ( i < numElements )
{
var moduleName = param.GetString(i++);
var URL = param.GetString(i++);
var IconURL = param.GetString(i++); // Advance the enumeration, parameter is unused just now.
var certName = param.GetString(i++);
addTreeItem(row++, moduleName, URL);
}
gManager = window.arguments[1];
// inform nsXPInstallManager we're open for business
gManager.observe( progressHooks, "xpinstall-progress", "open" );
}
function addTreeItem(aRow, aName, aUrl)
{
// first column is the package name
var item = document.createElement("description");
item.setAttribute("class", "packageName");
item.setAttribute("id", "package"+aRow);
item.setAttribute("value", aName);
item.setAttribute("tooltiptext", aUrl);
// second column is the status
var status = document.createElement('description');
status.setAttribute("class", "packageStatus");
status.setAttribute("id", "status"+aRow);
status.setAttribute("value", gBundle.getString("progress.queued"));
// third row is a progress meter
var progress = document.createElement("progressmeter");
progress.setAttribute("class", "packageProgress");
progress.setAttribute("id", "progress"+aRow);
progress.setAttribute("value", "0%");
// create row and add it to the grid
var row = document.createElement("row");
row.appendChild(item);
row.appendChild(status);
row.appendChild(progress);
document.getElementById("xpirows").appendChild(row);
}
function onCancel()
{
gCancelled = true;
if (gManager)
gManager.observe( progressHooks, "xpinstall-progress", "cancel");
// window is closed by native impl after cleanup
return gCanClose;
}

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

@ -1,74 +0,0 @@
<?xml version="1.0"?>
<!-- ***** BEGIN LICENSE BLOCK *****
Version: MPL 1.1/GPL 2.0/LGPL 2.1
The contents of this file are subject to the Mozilla Public License Version
1.1 (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/MPL/
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 the Initial Developer are Copyright (C) 1998-2002
the Initial Developer. All Rights Reserved.
Contributor(s):
Don Bragg (dbragg@netscape.com) 12/08/1999
Blake Ross (BlakeR1234@aol.com) 7/05/2000
Daniel Veditz <dveditz@netscape.com> 1/2002
Alternatively, the contents of this file may be used under the terms of
either of the GNU General Public License Version 2 or later (the "GPL"),
or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
in which case the provisions of the GPL or the LGPL are applicable instead
of those above. If you wish to allow use of your version of this file only
under the terms of either the GPL or the LGPL, and not to allow others to
use your version of this file under the terms of the MPL, indicate your
decision by deleting the provisions above and replace them with the notice
and other provisions required by the GPL or the LGPL. If you do not delete
the provisions above, a recipient may use your version of this file under
the terms of any one of the MPL, the GPL or the LGPL.
***** END LICENSE BLOCK ***** -->
<?xml-stylesheet href="chrome://communicator/skin/xpinstall/xpinstall.css" type="text/css"?>
<!DOCTYPE dialog SYSTEM "chrome://communicator/locale/xpinstall/xpistatus.dtd">
<dialog xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
title="&progressTitle.label;"
onload="onLoad()"
onclose="return gCanClose"
id="statusDlg"
style="width: 50em"
ondialogcancel="return onCancel();"
>
<script src="chrome://communicator/content/xpinstall/xpistatus.js"/>
<stringbundle id="xpinstallBundle" src="chrome://global/locale/xpinstall/xpinstall.properties"/>
<vbox id="mainProgressBox" flex="1">
<groupbox id="progressGroup" orient="vertical" flex="1">
<caption id="progressCaption" label="&group.caption;"/>
<grid id="progressGrid" flex="1">
<columns>
<column id="xpiColumn" flex="3"/>
<column id="statusColumn" flex="2"/>
<column id="progressColumn"/>
</columns>
<rows id="xpirows">
</rows>
</grid>
</groupbox>
</vbox>
</dialog>

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

@ -1,10 +0,0 @@
comm.jar:
content/communicator/xpinstall/xpistatus.xul (content/xpistatus.xul)
content/communicator/xpinstall/xpistatus.js (content/xpistatus.js)
content/communicator/xpinstall/institems.xul (content/institems.xul)
content/communicator/xpinstall/institems.js (content/institems.js)
en-US.jar:
locale/en-US/global/xpinstall/xpinstall.properties (/toolkit/locales/en-US/chrome/global/xpinstall/xpinstall.properties)
locale/en-US/communicator/xpinstall/xpistatus.dtd (locale/en-US/xpistatus.dtd)
locale/en-US/communicator/xpinstall/institems.dtd (locale/en-US/institems.dtd)

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

@ -1,5 +0,0 @@
<!-- extracted from institems.xul -->
<!ENTITY dialog.title "Software Installation">
<!ENTITY warningText.label "A web site is requesting permission to install">
<!ENTITY warningText2.label "Malicious software can damage your computer or violate your privacy. You should only install software from sources that you trust.">

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

@ -1,2 +0,0 @@
<!ENTITY progressTitle.label "Software Installation">
<!ENTITY group.caption "Download and installation status">

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

@ -23,6 +23,7 @@
# Contributor(s):
# Daniel Veditz <dveditz@netscape.com>
# Douglas Turner <dougt@netscape.com>
# Dave Townsend <dtownsend@oxymoronical.com>
#
# Alternatively, the contents of this file may be used under the terms of
# either of the GNU General Public License Version 2 or later (the "GPL"),
@ -70,9 +71,6 @@ REQUIRES = xpcom \
caps \
content \
necko \
intl \
locale \
libreg \
js \
pref \
widget \
@ -80,14 +78,11 @@ REQUIRES = xpcom \
xpconnect \
dom \
windowwatcher \
plugin \
unicharutil \
appshell \
docshell \
layout \
chrome \
extensions \
embed_base \
pipnss \
pipboot \
$(ZLIB_REQUIRES) \
@ -98,74 +93,23 @@ EXPORTS = nsXPITriggerInfo.h
CPPSRCS = \
CertReader.cpp \
nsInstall.cpp \
nsInstallTrigger.cpp \
nsInstallVersion.cpp \
nsInstallFolder.cpp \
nsJSInstall.cpp \
nsJSFile.cpp \
nsJSInstallTriggerGlobal.cpp \
nsJSInstallVersion.cpp \
nsSoftwareUpdate.cpp \
nsSoftwareUpdateRun.cpp \
nsInstallFile.cpp \
nsInstallExecute.cpp \
nsInstallPatch.cpp \
nsInstallUninstall.cpp \
nsInstallResources.cpp \
nsRegisterItem.cpp \
nsTopProgressNotifier.cpp \
nsLoggingProgressNotifier.cpp \
ScheduledTasks.cpp \
nsXPIProxy.cpp \
nsXPITriggerInfo.cpp \
nsXPInstallManager.cpp \
nsInstallFileOpItem.cpp \
nsJSFileSpecObj.cpp \
nsInstallLogComment.cpp \
nsInstallBitwise.cpp \
nsXPIInstallInfo.cpp \
$(NULL)
ifeq ($(OS_ARCH),WINNT)
CPPSRCS += \
nsWinReg.cpp \
nsJSWinReg.cpp \
nsWinRegItem.cpp \
nsWinProfile.cpp \
nsJSWinProfile.cpp \
nsWinProfileItem.cpp \
nsWinShortcut.cpp \
$(NULL)
OS_LIBS += $(call EXPAND_LIBNAME,ole32 version uuid)
endif
# Support AppleSingle decoding on Mac OS X
ifneq (,$(filter mac cocoa,$(MOZ_WIDGET_TOOLKIT)))
REQUIRES += macmorefiles
CPPSRCS += \
nsAppleSingleDecoder.cpp \
$(NULL)
endif
LOCAL_INCLUDES = -I$(srcdir)/../public
EXTRA_DSO_LDOPTS = \
$(DEPTH)/modules/libreg/src/$(LIB_PREFIX)mozreg_s.$(LIB_SUFFIX) \
$(MOZ_JS_LIBS) \
$(MOZ_UNICHARUTIL_LIBS) \
$(MOZ_COMPONENT_LIBS) \
$(ZLIB_LIBS) \
$(NULL)
ifneq (,$(filter mac cocoa,$(MOZ_WIDGET_TOOLKIT)))
EXTRA_DSO_LDOPTS += \
$(TK_LIBS) \
$(NULL)
endif
include $(topsrcdir)/config/rules.mk
ifeq ($(OS_ARCH)$(MOZ_ENABLE_LIBXUL),WINNT)

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

@ -1,940 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (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/MPL/
*
* 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, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Douglas Turner <dougt@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "PatchableAppleSingle.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
OSErr PAS_EncodeFile(FSSpec *inSpec, FSSpec *outSpec);
OSErr PAS_DecodeFile(FSSpec *inSpec, FSSpec *outSpec);
OSErr PAS_encodeResource(FSSpec *inFile, short outRefNum);
OSErr PAS_decodeResource(PASEntry *entry, FSSpec *outFile, short inRefNum);
OSErr PAS_encodeMisc(FSSpec *inFile, short outRefNum);
OSErr PAS_decodeMisc(PASEntry *entry, FSSpec *outFile, short inRefNum);
OSErr PAS_encodeData(FSSpec *inFile, short outRefNum);
OSErr PAS_decodeData(PASEntry *entry, FSSpec *outFile, short inRefNum);
OSErr PAS_encodeHeader(short refnum);
OSErr PAS_decodeHeader(short refNum, PASHeader *header);
unsigned long PAS_getDataSize(FSSpec *spec);
short PAS_getResourceID(Handle resource);
OSErr PAS_flattenResource(ResType type, short *ids, long count, short source, short dest);
OSErr PAS_unflattenResource(PASResource *pasRes, Ptr buffer);
void PAS_sortTypes(short sourceRefNum, ResType **resTypePtr, long *count);
void PAS_sortIDs(short sourceRefNum, OSType theType, short **IdPtr, long *count);
void PAS_bubbleSortResType(ResType *types, long count);
void PAS_bubbleSortIDS(short *ids, long count);
OSErr PAS_EncodeFile(FSSpec *inSpec, FSSpec *outSpec)
{
OSErr err;
short outRefNum;
PASEntry dataEntry, miscEntry, resourceEntry;
long sizeOfEntry;
if (inSpec == NULL || outSpec == NULL)
return paramErr;
memset(&dataEntry, 0, sizeof(PASEntry));
memset(&miscEntry, 0, sizeof(PASEntry));
memset(&resourceEntry, 0, sizeof(PASEntry));
FSpDelete( outSpec ) ;
err = FSpCreate( outSpec, kCreator, kType ,smSystemScript );
if (err != noErr) return err;
err = FSpOpenDF(outSpec, fsRdWrPerm, &outRefNum);
if (err != noErr) goto error;
// Write Out Header
err = PAS_encodeHeader(outRefNum);
if (err != noErr) goto error;
/* Why am I using three (3)?
E stand for entry.
The data for the entry is after the THREE headers
|---------|----|----|----|---------------------->
header E E E
*/
// Write Out Data Entry
dataEntry.entryID = ePas_Data;
dataEntry.entryLength = PAS_getDataSize(inSpec);
dataEntry.entryOffset = sizeof(PASHeader) + (3 * sizeof(PASEntry));
sizeOfEntry = sizeof(PASEntry);
if(dataEntry.entryLength < 0)
{
err = dataEntry.entryLength;
goto error;
}
err = FSWrite(outRefNum, &sizeOfEntry, &dataEntry);
if (err != noErr) goto error;
// Write Out Misc Entry
miscEntry.entryID = ePas_Misc;
miscEntry.entryLength = sizeof(PASMiscInfo);
miscEntry.entryOffset = sizeof(PASHeader) + (3 * sizeof(PASEntry)) + dataEntry.entryLength;
sizeOfEntry = sizeof(PASEntry);
err = FSWrite(outRefNum, &sizeOfEntry, &miscEntry);
if (err != noErr) goto error;
// Write Out Resource Entry
resourceEntry.entryID = ePas_Resource;
resourceEntry.entryLength = -1;
resourceEntry.entryOffset = sizeof(PASHeader) + (3 * sizeof(PASEntry)) + dataEntry.entryLength + miscEntry.entryLength;
sizeOfEntry = sizeof(PASEntry);
err = FSWrite(outRefNum, &sizeOfEntry, &resourceEntry);
if (err != noErr) goto error;
err = PAS_encodeData(inSpec, outRefNum);
if (err != noErr) goto error;
err = PAS_encodeMisc(inSpec, outRefNum);
if (err != noErr) goto error;
err = PAS_encodeResource(inSpec, outRefNum);
if (err == kResFileNotOpened)
{
// there was no resource fork
err = noErr;
}
else if (err != noErr)
{
goto error;
}
FSClose(outRefNum);
return noErr;
error:
if (outRefNum != kResFileNotOpened)
{
FSClose(outRefNum);
}
FSpDelete( outSpec ) ;
return err;
}
OSErr PAS_DecodeFile(FSSpec *inSpec, FSSpec *outSpec)
{
OSErr err;
short inRefNum;
PASHeader header;
PASEntry dataEntry, miscEntry, resourceEntry;
long sizeOfEntry;
if (inSpec == NULL || outSpec == NULL)
return paramErr;
FSpDelete( outSpec ) ;
err = FSpCreate( outSpec, kCreator, kType ,smSystemScript );
if (err != noErr) return err;
err = FSpOpenDF(inSpec, fsRdPerm, &inRefNum);
if (err != noErr) goto error;
// Read Header
err = PAS_decodeHeader(inRefNum, &header);
if (err != noErr) goto error;
if( header.magicNum != PAS_MAGIC_NUM ||
header.versionNum != PAS_VERSION)
{
err = -1;
goto error;
}
// Read Data Entry
err = SetFPos(inRefNum, fsFromStart, sizeof(PASHeader));
if (err != noErr) goto error;
sizeOfEntry = sizeof(PASEntry);
err = FSRead(inRefNum, &sizeOfEntry, &dataEntry);
if (err != noErr) goto error;
// Read Misc Entry
err = SetFPos(inRefNum, fsFromStart, (sizeof(PASHeader) + sizeof(PASEntry)));
if (err != noErr) goto error;
sizeOfEntry = sizeof(PASEntry);
err = FSRead(inRefNum, &sizeOfEntry, &miscEntry);
if (err != noErr) goto error;
// Read Resource Entry
err = SetFPos(inRefNum, fsFromStart, (sizeof(PASHeader) + (2 * sizeof(PASEntry)))) ;
if (err != noErr) goto error;
sizeOfEntry = sizeof(PASEntry);
err = FSRead(inRefNum, &sizeOfEntry, &resourceEntry);
if (err != noErr) goto error;
err = PAS_decodeData(&dataEntry, outSpec, inRefNum);
if (err != noErr) goto error;
err = PAS_decodeMisc(&miscEntry, outSpec, inRefNum);
if (err != noErr) goto error;
err = PAS_decodeResource(&resourceEntry, outSpec, inRefNum);
if (err == kResFileNotOpened)
{
// there was no resource fork
err = noErr;
}
else if (err != noErr)
{
goto error;
}
FSClose(inRefNum);
return noErr;
error:
if (inRefNum != kResFileNotOpened)
{
FSClose(inRefNum);
}
FSpDelete( outSpec ) ;
return err;
}
#pragma mark -
OSErr PAS_encodeResource(FSSpec *inFile, short outRefNum)
{
OSErr err;
short inRefNum;
PASResFork resInfo;
SInt32 currentWrite;
ResType *resTypes;
long typeCount;
short *ids;
long idCount;
short oldResFile;
oldResFile=CurResFile();
inRefNum = FSpOpenResFile(inFile, fsRdPerm);
if (inRefNum < noErr) return inRefNum;
UseResFile(inRefNum);
memset(&resInfo, 0, sizeof(PASResFork));
PAS_sortTypes(inRefNum, &resTypes, &typeCount);
resInfo.NumberOfTypes = typeCount;
currentWrite = sizeof(PASResFork);
err = FSWrite(outRefNum, &currentWrite, &resInfo);
if (err != noErr) return err;
for (typeCount = 0; ((typeCount < resInfo.NumberOfTypes) && (err == noErr)); typeCount++)
{
PAS_sortIDs(inRefNum, resTypes[typeCount], &ids, &idCount);
err = PAS_flattenResource(resTypes[typeCount], ids, idCount, inRefNum, outRefNum);
DisposePtr((Ptr)ids);
}
DisposePtr((Ptr)resTypes);
UseResFile(oldResFile);
CloseResFile(inRefNum);
return err;
}
OSErr PAS_decodeResource(PASEntry *entry, FSSpec *outFile, short inRefNum)
{
OSErr err = noErr;
short outRefNum;
PASResFork info;
SInt32 infoSize;
short oldResFile;
PASResource pasRes;
SInt32 pasResSize;
long bufSize;
Handle buffer;
long counter=0;
infoSize = sizeof(PASResFork);
err = SetFPos(inRefNum, fsFromStart, (*entry).entryOffset );
if (err != noErr) return err;
err = FSRead( inRefNum, &infoSize, &info);
if (err != noErr) return err;
if(infoSize != sizeof(PASResFork))
{
err = -1;
goto error;
}
oldResFile=CurResFile();
outRefNum = FSpOpenResFile(outFile, fsRdWrPerm);
if (outRefNum < noErr) return outRefNum;
UseResFile(outRefNum);
while (1)
{
pasResSize = sizeof(PASResource);
err = FSRead( inRefNum, &pasResSize, &pasRes);
if (err != noErr)
{
if(err == eofErr)
err = noErr;
break;
}
bufSize = pasRes.length;
buffer = NewHandle(bufSize);
HLock(buffer);
if(buffer == NULL)
{
// if we did not get our memory, try updateresfile
HUnlock(buffer);
UpdateResFile(outRefNum);
counter=0;
buffer = NewHandle(bufSize);
HLock(buffer);
if(buffer == NULL)
{
err = memFullErr;
break;
}
}
err = FSRead( inRefNum, &bufSize, &(**buffer));
if (err != noErr && err != eofErr) break;
AddResource(buffer, pasRes.attrType, pasRes.attrID, pasRes.attrName);
WriteResource(buffer);
SetResAttrs(buffer, pasRes.attr);
ChangedResource(buffer);
WriteResource(buffer);
ReleaseResource(buffer);
if (counter++ > 100)
{
UpdateResFile(outRefNum);
counter=0;
}
}
error:
UseResFile(oldResFile);
CloseResFile(outRefNum);
return err;
}
#pragma mark -
OSErr PAS_encodeMisc(FSSpec *inFile, short outRefNum)
{
OSErr err;
short inRefNum;
PASMiscInfo infoBlock;
FInfo fInfo;
SInt32 currentRead;
err = FSpOpenDF(inFile, fsRdPerm, &inRefNum);
if (err != noErr) return err;
memset(&infoBlock, 0, sizeof(PASMiscInfo));
err = FSpGetFInfo(inFile, &fInfo);
if (err != noErr) return err;
infoBlock.fileType = fInfo.fdType;
infoBlock.fileCreator = fInfo.fdCreator;
infoBlock.fileFlags = fInfo.fdFlags;
FSClose(inRefNum);
inRefNum = FSpOpenResFile(inFile, fsRdPerm);
if (inRefNum > noErr)
{
infoBlock.fileHasResFork = 1;
infoBlock.fileResAttrs = GetResFileAttrs(inRefNum);
FSClose(inRefNum);
}
else
{
infoBlock.fileHasResFork = 0;
infoBlock.fileResAttrs = 0;
}
currentRead = sizeof(PASMiscInfo);
err = FSWrite(outRefNum, &currentRead, &infoBlock);
if (err != noErr) return err;
CloseResFile(inRefNum);
return noErr;
}
OSErr PAS_decodeMisc(PASEntry *entry, FSSpec *outFile, short inRefNum)
{
OSErr err = noErr;
short outRefNum;
PASMiscInfo info;
SInt32 infoSize;
FInfo theFInfo;
infoSize = sizeof(PASMiscInfo);
err = SetFPos(inRefNum, fsFromStart, (*entry).entryOffset );
if (err != noErr) return err;
err = FSRead( inRefNum, &infoSize, &info);
if (err != noErr) return err;
if(infoSize != sizeof(PASMiscInfo))
{
return -1;
}
err = FSpOpenDF(outFile, fsRdWrPerm, &outRefNum);
if (err != noErr) return err;
memset(&theFInfo, 0, sizeof(FInfo));
theFInfo.fdType = info.fileType;
theFInfo.fdCreator = info.fileCreator;
theFInfo.fdFlags = info.fileFlags;
err = FSpSetFInfo(outFile, &theFInfo);
if (err != noErr) return err;
FSClose(outRefNum);
if (info.fileHasResFork)
{
outRefNum = FSpOpenResFile(outFile, fsRdWrPerm);
if (outRefNum < noErr)
{
// maybe it does not have one!
FSpCreateResFile(outFile, info.fileCreator, info.fileType, smSystemScript);
outRefNum = FSpOpenResFile(outFile, fsRdWrPerm);
if (outRefNum < noErr)
{
return outRefNum;
}
}
SetResFileAttrs(outRefNum, info.fileResAttrs);
CloseResFile(outRefNum);
}
if(info.fileType == 'APPL')
{
// we need to add applications to the desktop database.
/* FIX :: need to find DTSetAPPL() function
err = DTSetAPPL( NULL,
outFile->vRefNum,
info.fileCreator,
outFile->parID,
outFile->name);
*/ }
return err;
}
#pragma mark -
OSErr PAS_encodeData(FSSpec *inFile, short outRefNum)
{
OSErr err;
short inRefNum;
Ptr buffer;
SInt32 currentRead = PAS_BUFFER_SIZE;
buffer = NewPtr(currentRead);
err = FSpOpenDF(inFile, fsRdPerm, &inRefNum);
if (err != noErr) return err;
while ( currentRead > 0 )
{
err = FSRead( inRefNum, &currentRead, buffer);
if (err != noErr && err != eofErr) return err;
err = FSWrite(outRefNum, &currentRead, buffer);
if (err != noErr) return err;
}
FSClose(inRefNum);
DisposePtr(buffer);
return noErr;
}
OSErr PAS_decodeData(PASEntry *entry, FSSpec *outFile, short inRefNum)
{
OSErr err;
short outRefNum;
Ptr buffer;
SInt32 currentWrite = PAS_BUFFER_SIZE;
SInt32 totalSize;
buffer = NewPtr(currentWrite);
err = FSpOpenDF(outFile, fsRdWrPerm, &outRefNum);
if (err != noErr) return err;
err = SetFPos(inRefNum, fsFromStart, (*entry).entryOffset );
if (err != noErr) return err;
err = SetFPos(outRefNum, fsFromStart, 0 );
if (err != noErr) return err;
totalSize = (*entry).entryLength;
while(totalSize > 0)
{
currentWrite = PAS_BUFFER_SIZE;
if (totalSize < currentWrite)
{
currentWrite = totalSize;
}
err = FSRead( inRefNum, &currentWrite, buffer);
if (err != noErr && err != eofErr) return err;
err = FSWrite(outRefNum, &currentWrite, buffer);
if (err != noErr) return err;
totalSize = totalSize - currentWrite;
}
FSClose(outRefNum);
DisposePtr(buffer);
return noErr;
}
#pragma mark -
OSErr PAS_encodeHeader(short refnum)
{
PASHeader header;
long sizeOfHeader;
OSErr err;
sizeOfHeader = sizeof(PASHeader);
memset(&header, 0, sizeOfHeader);
header.magicNum = PAS_MAGIC_NUM;
header.versionNum = PAS_VERSION;
header.numEntries = 3;
// Write Out Header
err = FSWrite(refnum, &sizeOfHeader, &header);
return err;
}
OSErr PAS_decodeHeader(short refNum, PASHeader *header)
{
OSErr err;
long sizeOfHeader = sizeof(PASHeader);
memset(header, 0, sizeOfHeader);
err = FSRead(refNum, &sizeOfHeader, header);
return err;
}
#pragma mark -
unsigned long PAS_getDataSize(FSSpec *spec)
{
short refNum;
OSErr err;
Str255 temp;
CInfoPBRec cbrec;
err = FSpOpenDF(spec, fsRdPerm, &refNum);
memcpy( temp, spec->name, spec->name[0] + 1);
cbrec.hFileInfo.ioNamePtr = temp;
cbrec.hFileInfo.ioDirID = spec->parID;
cbrec.hFileInfo.ioVRefNum = spec->vRefNum;
cbrec.hFileInfo.ioFDirIndex = 0;
err = PBGetCatInfoSync(&cbrec);
FSClose(refNum);
if(err != noErr)
{
cbrec.hFileInfo.ioFlLgLen = err;
}
return (cbrec.hFileInfo.ioFlLgLen);
}
short PAS_getResourceID(Handle resource)
{
ResType theType;
Str255 name;
short theID;
memset(&name, 0, sizeof(Str255));
GetResInfo(resource, &theID, &theType, name);
return theID;
}
#pragma mark -
OSErr PAS_flattenResource(ResType type, short *ids, long count, short source, short dest)
{
long idIndex;
Handle resToCopy;
long handleLength;
PASResource pasResource;
long pasResLen;
OSErr err;
for (idIndex=0; idIndex < count; idIndex++)
{
if( (type == 'SIZE') && ( ids[idIndex] == 1 || ids[idIndex] == 0 ) )
{
/*
We do not want to encode/flatten SIZE 0 or 1 because this
is the resource that the user can modify. Most applications
will not be affected if we remove these resources
*/
}
else
{
resToCopy=Get1Resource(type,ids[idIndex]);
if(!resToCopy)
{
return resNotFound;
}
memset(&pasResource, 0, sizeof(PASResource));
GetResInfo( resToCopy,
&pasResource.attrID,
&pasResource.attrType,
pasResource.attrName);
pasResource.attr = GetResAttrs(resToCopy);
DetachResource(resToCopy);
HLock(resToCopy);
pasResource.length = GetHandleSize(resToCopy);
handleLength = pasResource.length;
pasResLen = sizeof(PASResource);
err = FSWrite(dest, &pasResLen, &pasResource);
if(err != noErr)
{
return err;
}
err = FSWrite(dest, &handleLength, &(**resToCopy));
if(err != noErr)
{
return err;
}
HUnlock(resToCopy);
DisposeHandle(resToCopy);
}
}
return noErr;
}
#pragma mark -
void PAS_sortTypes(short sourceRefNum, ResType **resTypePtr, long *count)
{
short oldRef;
short typeIndex;
short numberOfTypes;
*count = -1;
oldRef = CurResFile();
UseResFile(sourceRefNum);
numberOfTypes = Count1Types();
*resTypePtr = (ResType*) NewPtrClear( numberOfTypes * sizeof(OSType) );
for (typeIndex=1; typeIndex <= numberOfTypes; typeIndex++)
{
Get1IndType(&(*resTypePtr)[typeIndex-1], typeIndex);
}
UseResFile(oldRef);
PAS_bubbleSortResType(*resTypePtr, numberOfTypes);
*count = numberOfTypes;
}
void PAS_sortIDs(short sourceRefNum, OSType theType, short **IdPtr, long *count)
{
short oldRef;
Handle theHandle;
short resCount;
short resIndex;
*count = -1;
oldRef = CurResFile();
UseResFile(sourceRefNum);
resCount = Count1Resources(theType);
*IdPtr = (short*) NewPtrClear( resCount * sizeof(short) );
for (resIndex=1; resIndex <= resCount; resIndex++)
{
theHandle = Get1IndResource(theType, resIndex);
if(theHandle == NULL) return;
(*IdPtr)[resIndex-1] = PAS_getResourceID(theHandle);
ReleaseResource(theHandle);
}
UseResFile(oldRef);
PAS_bubbleSortIDS(*IdPtr, resCount);
*count = resCount;
}
#pragma mark -
void
PAS_bubbleSortResType(ResType *types, long count)
{
long x, y;
OSType temp;
for (x=0; x < count-1; x++)
{
for (y=0; y < count-x-1; y++)
{
if (types[y] > types[y+1])
{
temp=types[y];
types[y]=types[y+1];
types[y+1]=temp;
}
}
}
}
void
PAS_bubbleSortIDS(short *ids, long count)
{
long x, y;
short temp;
for (x=0; x < count-1; x++)
{
for (y=0; y < count-x-1; y++)
{
if (ids[y] > ids[y+1])
{
temp=ids[y];
ids[y]=ids[y+1];
ids[y+1]=temp;
}
}
}
}

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

@ -1,132 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (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/MPL/
*
* 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, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Douglas Turner <dougt@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef SU_PAS_H
#define SU_PAS_H
#include <Errors.h>
#include <Types.h>
#include <Files.h>
#include <Script.h>
#include <Resources.h>
typedef struct PASHeader /* header portion of Patchable AppleSingle */
{
UInt32 magicNum; /* internal file type tag = 0x00244200*/
UInt32 versionNum; /* format version: 1 = 0x00010000 */
UInt8 filler[16]; /* filler */
UInt16 numEntries; /* number of entries which follow */
} PASHeader ;
typedef struct PASEntry /* one Patchable AppleSingle entry descriptor */
{
UInt32 entryID; /* entry type: see list, 0 invalid */
UInt32 entryOffset; /* offset, in bytes, from beginning */
/* of file to this entry's data */
UInt32 entryLength; /* length of data in octets */
} PASEntry;
typedef struct PASMiscInfo
{
short fileHasResFork;
short fileResAttrs;
OSType fileType;
OSType fileCreator;
UInt32 fileFlags;
} PASMiscInfo;
typedef struct PASResFork
{
short NumberOfTypes;
} PASResFork;
typedef struct PASResource
{
short attr;
short attrID;
OSType attrType;
Str255 attrName;
unsigned long length;
} PASResource;
#if PRAGMA_STRUCT_ALIGN
#pragma options align=reset
#endif
#define kCreator 'MOSS'
#define kType 'PASf'
#define PAS_BUFFER_SIZE (1024*512)
#define PAS_MAGIC_NUM (0x00244200)
#define PAS_VERSION (0x00010000)
enum
{
ePas_Data = 1,
ePas_Misc,
ePas_Resource
};
#ifdef __cplusplus
extern "C" {
#endif
/* Prototypes */
OSErr PAS_EncodeFile(FSSpec *inSpec, FSSpec *outSpec);
OSErr PAS_DecodeFile(FSSpec *inSpec, FSSpec *outSpec);
#ifdef __cplusplus
}
#endif
#endif /* SU_PAS_H */

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

@ -1,609 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (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/MPL/
*
* 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, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Daniel Veditz <dveditz@netscape.com>
* Douglas Turner <dougt@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nscore.h"
#include "nsXPIDLString.h"
#include "nsInstall.h" // for error codes
#include "prmem.h"
#include "ScheduledTasks.h"
#include "InstallCleanupDefines.h"
#include "nsDirectoryService.h"
#include "nsDirectoryServiceDefs.h"
#include "nsAppDirectoryServiceDefs.h"
static nsresult
GetPersistentStringFromSpec(nsIFile* inSpec, nsACString &string)
{
nsresult rv;
nsCOMPtr<nsILocalFile> LocalFile = do_QueryInterface(inSpec, &rv);
if (NS_SUCCEEDED(rv)) {
rv = LocalFile->GetNativePath(string);
}
else {
string.Truncate();
}
return rv;
}
#ifdef _WINDOWS
#include <sys/stat.h>
#include <windows.h>
PRInt32 ReplaceWindowsSystemFile(nsIFile* currentSpec, nsIFile* finalSpec)
{
PRInt32 err = -1;
// Get OS version info
DWORD dwVersion = GetVersion();
nsCAutoString final;
nsCAutoString current;
finalSpec->GetNativePath(final);
currentSpec->GetNativePath(current);
// Get build numbers for Windows NT or Win32s
if (dwVersion > 0x80000000)
{
// Windows 95 or Win16
// Place an entry in the WININIT.INI file in the Windows directory
// to delete finalName and rename currentName to be finalName at reboot
int strlen;
char Src[_MAX_PATH]; // 8.3 name
char Dest[_MAX_PATH]; // 8.3 name
strlen = GetShortPathName( (LPCTSTR)current.get(), (LPTSTR)Src, (DWORD)sizeof(Src) );
if ( strlen > 0 )
{
current = Src;
}
strlen = GetShortPathName( (LPCTSTR) final.get(), (LPTSTR) Dest, (DWORD) sizeof(Dest));
if ( strlen > 0 )
{
final = Dest;
}
// NOTE: use OEM filenames! Even though it looks like a Windows
// .INI file, WININIT.INI is processed under DOS
AnsiToOem( final.BeginWriting(), final.BeginWriting() );
AnsiToOem( current.BeginWriting(), current.BeginWriting() );
if ( WritePrivateProfileString( "Rename", final.get(), current.get(), "WININIT.INI" ) )
err = 0;
}
else
{
// Windows NT
if ( MoveFileEx(final.get(), current.get(), MOVEFILE_DELAY_UNTIL_REBOOT) )
err = 0;
}
return err;
}
#endif
nsresult GetRegFilePath(nsACString &regFilePath)
{
nsresult rv;
nsCOMPtr<nsILocalFile> iFileUtilityPath;
//Get the program directory
nsCOMPtr<nsIProperties> directoryService =
do_GetService(NS_DIRECTORY_SERVICE_CONTRACTID, &rv);
if (NS_FAILED(rv))
return nsnull;
if (nsSoftwareUpdate::GetProgramDirectory()) // In the stub installer
{
nsCOMPtr<nsIFile> tmp;
rv = nsSoftwareUpdate::GetProgramDirectory()->Clone(getter_AddRefs(tmp));
if (NS_FAILED(rv) || !tmp)
return nsnull;
iFileUtilityPath = do_QueryInterface(tmp);
}
else
{
rv = directoryService->Get(NS_APP_INSTALL_CLEANUP_DIR,
NS_GET_IID(nsIFile),
getter_AddRefs(iFileUtilityPath));
}
if (NS_FAILED(rv) || !iFileUtilityPath)
return nsnull;
iFileUtilityPath->AppendNative(CLEANUP_REGISTRY);
//Yes, we know using GetPath is buggy on the Mac.
//When libreg is fixed to accept nsIFiles we'll change this to match.
return iFileUtilityPath->GetNativePath(regFilePath);
}
PRInt32 DeleteFileNowOrSchedule(nsIFile* filename)
{
PRBool flagExists;
PRInt32 result = nsInstall::SUCCESS;
filename->Remove(PR_FALSE);
filename->Exists(&flagExists);
if (flagExists)
result = ScheduleFileForDeletion(filename);
return result;
}
PRInt32 ScheduleFileForDeletion(nsIFile *filename)
{
// could not delete, schedule it for later
RKEY newkey;
HREG reg;
REGERR err;
PRInt32 result = nsInstall::UNEXPECTED_ERROR;
nsCAutoString path;
GetRegFilePath(path);
err = NR_RegOpen(const_cast<char*>(path.get()), &reg);
if ( err == REGERR_OK )
{
err = NR_RegAddKey(reg,ROOTKEY_PRIVATE,REG_DELETE_LIST_KEY,&newkey);
if ( err == REGERR_OK )
{
char valname[20];
err = NR_RegGetUniqueName( reg, valname, sizeof(valname) );
if ( err == REGERR_OK )
{
nsCAutoString nameowner;
nsresult rv = GetPersistentStringFromSpec(filename, nameowner);
if ( NS_SUCCEEDED(rv) && !nameowner.IsEmpty() )
{
const char *fnamestr = nameowner.get();
err = NR_RegSetEntry( reg, newkey, valname,
REGTYPE_ENTRY_BYTES,
(void*)fnamestr,
strlen(fnamestr)+sizeof('\0'));
if ( err == REGERR_OK )
{
result = nsInstall::REBOOT_NEEDED;
nsSoftwareUpdate::NeedCleanup();
}
}
}
}
NR_RegClose(reg);
}
return result;
}
PRInt32 ReplaceFileNow(nsIFile* aReplacementFile, nsIFile* aDoomedFile )
{
PRBool flagExists, flagRenamedDoomedFileExists, flagIsEqual;
nsCOMPtr<nsIFile> replacementFile;
nsresult rv;
// make a clone of aReplacement file so we touch affect callers
aReplacementFile->Clone(getter_AddRefs(replacementFile));
// replacement file must exist, doomed file doesn't have to
replacementFile->Exists(&flagExists);
if ( !flagExists )
return nsInstall::DOES_NOT_EXIST;
// don't have to do anything if the files are the same
replacementFile->Equals(aDoomedFile, &flagIsEqual);
if ( flagIsEqual )
return nsInstall::SUCCESS;
PRInt32 result = nsInstall::ACCESS_DENIED;
// first try to rename the doomed file out of the way (if it exists)
nsCOMPtr<nsIFile> renamedDoomedFile;
nsCOMPtr<nsILocalFile> tmpLocalFile;
aDoomedFile->Clone(getter_AddRefs(renamedDoomedFile));
renamedDoomedFile->Exists(&flagRenamedDoomedFileExists);
if ( flagRenamedDoomedFileExists )
{
#ifdef XP_MACOSX
// If we clone an nsIFile, and move the clone, the FSRef of the *original*
// file is not what you would expect - it points to the moved file. This
// is despite the fact that the two FSRefs are independent objects. Until
// the OS X file impl is changed to not use FSRefs, need to do this (see
// bug 200024).
nsCOMPtr<nsILocalFile> doomedFileLocal = do_QueryInterface(aDoomedFile);
nsCAutoString doomedFilePath;
rv = doomedFileLocal->GetNativePath(doomedFilePath);
if (NS_FAILED(rv))
return nsInstall::UNEXPECTED_ERROR;
#endif
tmpLocalFile = do_QueryInterface(renamedDoomedFile, &rv); // Convert to an nsILocalFile
//get the doomedLeafname so we can convert its extension to .old
nsAutoString doomedLeafname;
nsCAutoString uniqueLeafName;
tmpLocalFile->GetLeafName(doomedLeafname);
// do not RFind on the native charset! UTF8 or Unicode are OK
PRInt32 extpos = doomedLeafname.RFindChar('.');
if (extpos != -1)
{
// We found the extension;
doomedLeafname.Truncate(extpos + 1); //strip off the old extension
}
doomedLeafname.AppendLiteral("old");
//Now reset the doomedLeafname
tmpLocalFile->SetLeafName(doomedLeafname);
tmpLocalFile->CreateUnique(nsIFile::NORMAL_FILE_TYPE, 0644);
tmpLocalFile->GetNativeLeafName(uniqueLeafName);//this is the new "unique" doomedLeafname
rv = aDoomedFile->Clone(getter_AddRefs(renamedDoomedFile));// Reset renamedDoomed file so aDoomedfile
// isn't changed during the MoveTo call
if (NS_FAILED(rv))
result = nsInstall::UNEXPECTED_ERROR;
else
{
rv = renamedDoomedFile->MoveToNative(nsnull, uniqueLeafName);
if (NS_FAILED(rv))
{
// MoveToNative() failing is OK. It simply means that the file
// was locked in memory and needs to be replaced on browser
// shutdown or system reboot.
//
// Since renamedDoomedFile->MoveToNative() failed, it created a
// 0 byte '-old' file that needs to be cleaned up.
tmpLocalFile->Remove(PR_FALSE);
}
else
{
// The implementation of MoveToNative() on some platforms (osx and win32) resets
// the object to the 'moved to' filename. This is incorrect behavior. This
// implementation will be fixed in the future. We need to take into account that
// fix by setting renamedDoomedFile to the filename that it was moved to above.
// See bug 200024.
//
// renamedDoomedFile needs to be reset because it's used later on in this
// function.
rv = renamedDoomedFile->SetNativeLeafName(uniqueLeafName);
if (NS_FAILED(rv))
result = nsInstall::UNEXPECTED_ERROR;
}
}
#ifdef XP_MACOSX
rv = doomedFileLocal->InitWithNativePath(doomedFilePath);
if (NS_FAILED(rv))
result = nsInstall::UNEXPECTED_ERROR;
#endif
if (result == nsInstall::UNEXPECTED_ERROR)
return result;
}
// if aDoomedFile is still in the way, give up and return result.
aDoomedFile->Exists(&flagExists);
if ( flagExists )
return result;
nsCOMPtr<nsIFile> parentofDoomedFile;
nsCAutoString doomedLeafname;
rv = aDoomedFile->GetParent(getter_AddRefs(parentofDoomedFile));
if ( NS_SUCCEEDED(rv) )
rv = aDoomedFile->GetNativeLeafName(doomedLeafname);
if ( NS_SUCCEEDED(rv) )
{
rv = replacementFile->MoveToNative(parentofDoomedFile, doomedLeafname);
// The implementation of MoveToNative() on some platforms (osx and win32) resets
// the object to the 'moved to' filename. This is incorrect behavior. This
// implementation will be fixed in the future. We need to take into account that
// fix by setting replacementFile to the filename that it was moved to above.
// See bug 200024.
//
// However, since replacementFile is a clone of aReplacementFile and is also
// not used beyond here, there's no need to set the path+leafname to what
// it was MoveToNative()'ed to.
}
if (NS_SUCCEEDED(rv))
{
if (flagRenamedDoomedFileExists)
{
// we replaced the old file OK, now we have to
// get rid of it if it was renamed out of the way
result = DeleteFileNowOrSchedule( renamedDoomedFile );
}
}
else
{
// couldn't rename file, try to put old file back
renamedDoomedFile->MoveToNative(nsnull, doomedLeafname);
// No need to reset remanedDoomedFile after a MoveToNative() call
// because renamedDoomedFile is not used beyond here.
}
return result;
}
PRInt32 ReplaceFileNowOrSchedule(nsIFile* aReplacementFile, nsIFile* aDoomedFile, PRInt32 aMode)
{
PRInt32 result = ReplaceFileNow( aReplacementFile, aDoomedFile );
if ( result == nsInstall::ACCESS_DENIED )
{
// if we couldn't replace the file schedule it for later
#ifdef _WINDOWS
if ( (aMode & WIN_SYSTEM_FILE) &&
(ReplaceWindowsSystemFile(aReplacementFile, aDoomedFile) == 0) )
return nsInstall::REBOOT_NEEDED;
#endif
RKEY listkey;
RKEY filekey;
HREG reg;
REGERR err;
nsCAutoString regFilePath;
GetRegFilePath(regFilePath);
if ( REGERR_OK == NR_RegOpen(const_cast<char*>(regFilePath.get()), &reg) )
{
err = NR_RegAddKey( reg, ROOTKEY_PRIVATE, REG_REPLACE_LIST_KEY, &listkey );
if ( err == REGERR_OK )
{
char valname[20];
REGERR err2;
err = NR_RegGetUniqueName( reg, valname, sizeof(valname) );
if ( err == REGERR_OK )
{
err = NR_RegAddKey( reg, listkey, valname, &filekey );
if ( REGERR_OK == err )
{
nsCAutoString srcowner;
nsCAutoString destowner;
nsresult rv = GetPersistentStringFromSpec(aReplacementFile, srcowner);
nsresult rv2 = GetPersistentStringFromSpec(aDoomedFile, destowner);
if ( NS_SUCCEEDED(rv) && NS_SUCCEEDED(rv2) )
{
const char *fsrc = srcowner.get();
const char *fdest = destowner.get();
err = NR_RegSetEntry( reg, filekey,
REG_REPLACE_SRCFILE,
REGTYPE_ENTRY_BYTES,
(void*)fsrc,
strlen(fsrc)+sizeof('\0'));
err2 = NR_RegSetEntry(reg, filekey,
REG_REPLACE_DESTFILE,
REGTYPE_ENTRY_BYTES,
(void*)fdest,
strlen(fdest)+sizeof('\0'));
if ( err == REGERR_OK && err2 == REGERR_OK )
{
result = nsInstall::REBOOT_NEEDED;
nsSoftwareUpdate::NeedCleanup();
}
else
NR_RegDeleteKey( reg, listkey, valname );
}
}
}
}
NR_RegClose(reg);
}
}
return result;
}
//-----------------------------------------------------------------------------
//
// STARTUP: DO SCHEDULED ACTIONS
//
//-----------------------------------------------------------------------------
void DeleteScheduledFiles(HREG);
void ReplaceScheduledFiles(HREG);
void PerformScheduledTasks(HREG reg)
{
DeleteScheduledFiles( reg );
ReplaceScheduledFiles( reg );
}
void DeleteScheduledFiles( HREG reg )
{
REGERR err;
RKEY key;
REGENUM state = 0;
nsresult rv = NS_OK;
// perform scheduled file deletions
if (REGERR_OK == NR_RegGetKey(reg,ROOTKEY_PRIVATE,REG_DELETE_LIST_KEY,&key))
{
// the delete key exists, so we loop through its children
// and try to delete all the listed files
char namebuf[MAXREGNAMELEN];
char valbuf[MAXREGPATHLEN];
nsCOMPtr<nsIFile> doomedFile;
nsCOMPtr<nsILocalFile> spec;
if (NS_SUCCEEDED(rv))
{
while (REGERR_OK == NR_RegEnumEntries( reg, key, &state, namebuf,
sizeof(namebuf), 0 ) )
{
uint32 bufsize = sizeof(valbuf); // gets changed, must reset
err = NR_RegGetEntry( reg, key, namebuf, valbuf, &bufsize );
if ( err == REGERR_OK )
{
// no need to check return value of
// SetPersistentDescriptorString, it's always NS_OK
//spec->SetPersistentDescriptorString(valbuf);
//nsIFileXXX: Do we still need this instead of InitWithPath?
NS_NewNativeLocalFile(nsDependentCString(valbuf), PR_TRUE, getter_AddRefs(spec));
spec->Clone(getter_AddRefs(doomedFile));
if (NS_SUCCEEDED(rv))
{
PRBool flagExists;
doomedFile->Remove(PR_FALSE);
doomedFile->Exists(&flagExists);
if ( !flagExists )
{
// deletion successful, don't have to retry
NR_RegDeleteEntry( reg, key, namebuf );
}
}
}
}
// delete list node if empty
state = 0;
err = NR_RegEnumEntries(reg, key, &state, namebuf, sizeof(namebuf), 0);
if ( err == REGERR_NOMORE )
{
NR_RegDeleteKey(reg, ROOTKEY_PRIVATE, REG_DELETE_LIST_KEY);
}
}
}
}
void ReplaceScheduledFiles( HREG reg )
{
RKEY key;
// replace files if any listed
if (REGERR_OK == NR_RegGetKey(reg,ROOTKEY_PRIVATE,REG_REPLACE_LIST_KEY,&key))
{
char keyname[MAXREGNAMELEN];
char doomedFile[MAXREGPATHLEN];
char srcFile[MAXREGPATHLEN];
nsCOMPtr<nsIFile> doomedSpec;
nsCOMPtr<nsIFile> srcSpec;
nsCOMPtr<nsILocalFile> src;
nsCOMPtr<nsILocalFile> dest;
nsresult rv1, rv2;
uint32 bufsize;
REGENUM state = 0;
while (REGERR_OK == NR_RegEnumSubkeys( reg, key, &state,
keyname, sizeof(keyname), REGENUM_CHILDREN))
{
bufsize = sizeof(srcFile);
REGERR err1 = NR_RegGetEntry( reg, (RKEY)state,
REG_REPLACE_SRCFILE, srcFile, &bufsize);
bufsize = sizeof(doomedFile);
REGERR err2 = NR_RegGetEntry( reg, (RKEY)state,
REG_REPLACE_DESTFILE, doomedFile, &bufsize);
if ( err1 == REGERR_OK && err2 == REGERR_OK )
{
rv1 = NS_NewNativeLocalFile(nsDependentCString(srcFile), PR_TRUE, getter_AddRefs(src));
rv1 = src->Clone(getter_AddRefs(srcSpec));
rv2 = NS_NewNativeLocalFile(nsDependentCString(doomedFile), PR_TRUE, getter_AddRefs(dest));
rv2 = dest->Clone(getter_AddRefs(doomedSpec));
if (NS_SUCCEEDED(rv1) && NS_SUCCEEDED(rv2))
{
// finally now try to do the replace
PRInt32 result = ReplaceFileNow( srcSpec, doomedSpec );
if ( result == nsInstall::DOES_NOT_EXIST ||
result == nsInstall::SUCCESS )
{
// This one is done
NR_RegDeleteKey( reg, key, keyname );
}
}
}
}
// delete list node if empty
state = 0;
if (REGERR_NOMORE == NR_RegEnumSubkeys( reg, key, &state, keyname,
sizeof(keyname), REGENUM_CHILDREN ))
{
NR_RegDeleteKey(reg, ROOTKEY_PRIVATE, REG_REPLACE_LIST_KEY);
}
}
}

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

@ -1,61 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (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/MPL/
*
* 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, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Daniel Veditz <dveditz@netscape.com>
* Douglas Turner <dougt@netscape.com>
* Samir Gehani <sgehani@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef __SCHEDULEDTASKS_H__
#define __SCHEDULEDTASKS_H__
#include "NSReg.h"
#include "nsIFile.h"
PR_BEGIN_EXTERN_C
PRInt32 DeleteFileNowOrSchedule(nsIFile* filename);
PRInt32 ReplaceFileNowOrSchedule(nsIFile* tmpfile, nsIFile* target, PRInt32 aMode);
PRInt32 ScheduleFileForDeletion(nsIFile* filename);
char* GetRegFilePath();
void PerformScheduledTasks(HREG reg);
PR_END_EXTERN_C
#endif

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

@ -1,153 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (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/MPL/
*
* 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.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/*--------------------------------------------------------------
* GDIFF.H
*
* Constants used in processing the GDIFF format
*--------------------------------------------------------------*/
#include "prio.h"
#define GDIFF_MAGIC "\xD1\xFF\xD1\xFF"
#define GDIFF_MAGIC_LEN 4
#define GDIFF_VER 5
#define GDIFF_EOF "\0"
#define GDIFF_VER_POS 4
#define GDIFF_CS_POS 5
#define GDIFF_CSLEN_POS 6
#define GDIFF_HEADERSIZE 7
#define GDIFF_APPDATALEN 4
#define GDIFF_CS_NONE 0
#define GDIFF_CS_MD5 1
#define GDIFF_CS_SHA 2
#define GDIFF_CS_CRC32 32
#define CRC32_LEN 4
/*--------------------------------------
* GDIFF opcodes
*------------------------------------*/
#define ENDDIFF 0
#define ADD8MAX 246
#define ADD16 247
#define ADD32 248
#define COPY16BYTE 249
#define COPY16SHORT 250
#define COPY16LONG 251
#define COPY32BYTE 252
#define COPY32SHORT 253
#define COPY32LONG 254
#define COPY64 255
/* instruction sizes */
#define ADD16SIZE 2
#define ADD32SIZE 4
#define COPY16BYTESIZE 3
#define COPY16SHORTSIZE 4
#define COPY16LONGSIZE 6
#define COPY32BYTESIZE 5
#define COPY32SHORTSIZE 6
#define COPY32LONGSIZE 8
#define COPY64SIZE 12
/*--------------------------------------
* error codes
*------------------------------------*/
#define GDIFF_OK 0
#define GDIFF_ERR_UNKNOWN -1
#define GDIFF_ERR_ARGS -2
#define GDIFF_ERR_ACCESS -3
#define GDIFF_ERR_MEM -4
#define GDIFF_ERR_HEADER -5
#define GDIFF_ERR_BADDIFF -6
#define GDIFF_ERR_OPCODE -7
#define GDIFF_ERR_OLDFILE -8
#define GDIFF_ERR_CHKSUMTYPE -9
#define GDIFF_ERR_CHECKSUM -10
#define GDIFF_ERR_CHECKSUM_TARGET -11
#define GDIFF_ERR_CHECKSUM_RESULT -12
/*--------------------------------------
* types
*------------------------------------*/
#ifndef AIX
#ifdef OSF1
#include <sys/types.h>
#else
typedef unsigned char uchar;
#endif
#endif
typedef struct _diffdata {
PRFileDesc* fSrc;
PRFileDesc* fOut;
PRFileDesc* fDiff;
uint8 checksumType;
uint8 checksumLength;
uchar* oldChecksum;
uchar* newChecksum;
PRBool bMacAppleSingle;
PRBool bWin32BoundImage;
uchar* databuf;
uint32 bufsize;
} DIFFDATA;
typedef DIFFDATA* pDIFFDATA;
/*--------------------------------------
* miscellaneous
*------------------------------------*/
#define APPFLAG_W32BOUND "autoinstall:Win32PE"
#define APPFLAG_APPLESINGLE "autoinstall:AppleSingle"
#ifndef TRUE
#define TRUE 1
#endif
#ifndef FALSE
#define FALSE 0
#endif

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

@ -1,713 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (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/MPL/
*
* 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, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1999
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Samir Gehani <sgehani@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef _NS_APPLESINGLEDECODER_H_
#include "nsAppleSingleDecoder.h"
#endif
#include "MoreFilesX.h"
#ifdef STANDALONE_ASD
#include <iostream>
using namespace std;
#undef MOZILLA_CLIENT
#endif
#ifdef MOZILLA_CLIENT
#include "nsISupportsUtils.h"
#endif
/*----------------------------------------------------------------------*
* Constructors/Destructor
*----------------------------------------------------------------------*/
nsAppleSingleDecoder::nsAppleSingleDecoder(const FSRef *inRef, FSRef *outRef)
: mInRef(NULL),
mOutRef(NULL),
mInRefNum(0),
mRenameReqd(false)
{
#ifdef MOZILLA_CLIENT
MOZ_COUNT_CTOR(nsAppleSingleDecoder);
#endif
if (inRef && outRef)
{
/* merely point to FSRefs, not own 'em */
mInRef = inRef;
mOutRef = outRef;
}
}
nsAppleSingleDecoder::nsAppleSingleDecoder()
: mInRef(NULL),
mOutRef(NULL),
mInRefNum(0),
mRenameReqd(false)
{
#ifdef MOZILLA_CLIENT
MOZ_COUNT_CTOR(nsAppleSingleDecoder);
#endif
}
nsAppleSingleDecoder::~nsAppleSingleDecoder()
{
/* not freeing FSRefs since we don't own 'em */
#ifdef MOZILLA_CLIENT
MOZ_COUNT_DTOR(nsAppleSingleDecoder);
#endif
}
#pragma mark -
/*----------------------------------------------------------------------*
* Public methods
*----------------------------------------------------------------------*/
OSErr
nsAppleSingleDecoder::Decode()
{
OSErr err = noErr;
ASHeader header;
UInt32 bytesRead = sizeof(header);
HFSUniStr255 nameInRef;
// param check
if (!mInRef || !mOutRef)
return paramErr;
// check for existence (and get leaf name for later renaming of decoded file)
err = FSGetCatalogInfo(mInRef, kFSCatInfoNone, NULL, &nameInRef, NULL, NULL);
if (err == fnfErr)
return err;
HFSUniStr255 dataForkName;
MAC_ERR_CHECK(FSGetDataForkName( &dataForkName ));
MAC_ERR_CHECK(FSOpenFork( mInRef, dataForkName.length, dataForkName.unicode,
fsRdPerm, &mInRefNum ));
MAC_ERR_CHECK(FSRead( mInRefNum, (long *)&bytesRead, &header ));
if ( (bytesRead != sizeof(header)) ||
(header.magicNum != APPLESINGLE_MAGIC) ||
(header.versionNum != APPLESINGLE_VERSION) ||
(header.numEntries == 0) ) // empty file?
return -1;
// create the outSpec which we'll rename correctly later
FSRef parentRef;
MAC_ERR_CHECK(FSGetParentRef( mInRef, &parentRef ));
MAC_ERR_CHECK(FSMakeUnique( &parentRef, mOutRef ));
MAC_ERR_CHECK(FSCreateFork( mOutRef, dataForkName.length,
dataForkName.unicode ));
/* Loop through the entries, processing each.
** Set the time/date stamps last, because otherwise they'll
** be destroyed when we write.
*/
{
Boolean hasDateEntry = false;
ASEntry dateEntry;
long offset;
ASEntry entry;
for ( int i=0; i < header.numEntries; i++ )
{
offset = sizeof( ASHeader ) + sizeof( ASEntry ) * i;
MAC_ERR_CHECK(SetFPos( mInRefNum, fsFromStart, offset ));
bytesRead = sizeof(entry);
MAC_ERR_CHECK(FSRead( mInRefNum, (long *) &bytesRead, &entry ));
if (bytesRead != sizeof(entry))
return -1;
if ( entry.entryID == AS_FILEDATES )
{
hasDateEntry = true;
dateEntry = entry;
}
else
MAC_ERR_CHECK(ProcessASEntry( entry ));
}
if ( hasDateEntry )
MAC_ERR_CHECK(ProcessASEntry( dateEntry ));
}
// close the inSpec
FSClose( mInRefNum );
// rename if need be
if (mRenameReqd)
{
// delete encoded version of target file
MAC_ERR_CHECK(FSDeleteObject( mInRef ));
MAC_ERR_CHECK(FSRenameUnicode( mOutRef, nameInRef.length,
nameInRef.unicode, kTextEncodingUnknown, mOutRef ));
mRenameReqd = false;
}
return err;
}
OSErr
nsAppleSingleDecoder::Decode(const FSRef *inRef, FSRef *outRef)
{
OSErr err = noErr;
// param check
if (inRef && outRef)
{
mInRef = inRef; // reinit
mOutRef = outRef;
mRenameReqd = false;
}
else
return paramErr;
err = Decode();
return err;
}
Boolean
DecodeDirIterateFilter(Boolean containerChanged, ItemCount currentLevel,
const FSCatalogInfo *catalogInfo, const FSRef *ref,
const FSSpec *spec, const HFSUniStr255 *name, void *yourDataPtr)
{
FSRef outRef;
nsAppleSingleDecoder *thisObj;
Boolean isDir;
// param check
if (!yourDataPtr || !ref)
return false;
// extract 'this' -- an nsAppleSingleDecoder instance
thisObj = (nsAppleSingleDecoder*) yourDataPtr;
isDir = nsAppleSingleDecoder::IsDirectory(ref);
// if current FSRef is file
if (!isDir)
{
// if file is in AppleSingle format
if (nsAppleSingleDecoder::IsAppleSingleFile(ref))
{
// decode file
thisObj->Decode(ref, &outRef);
}
}
// else current FSRef is folder
else
{
thisObj->DecodeFolder(ref);
}
return false; // always continue iteration
}
OSErr
nsAppleSingleDecoder::DecodeFolder(const FSRef *aFolder)
{
OSErr err;
Boolean isDir = false;
// check that FSSpec is folder
if (aFolder)
{
isDir = IsDirectory((const FSRef *) aFolder);
if (!isDir)
return dirNFErr;
}
// recursively enumerate contents of folder
// (maxLevels=0 means recurse all)
err = FSIterateContainer(aFolder, 0, kFSCatInfoNone, false,
false, DecodeDirIterateFilter, (void*)this);
// XXX do we really want to return err?
return err;
}
Boolean
nsAppleSingleDecoder::IsAppleSingleFile(const FSRef *inRef)
{
OSErr err;
SInt16 inRefNum;
UInt32 magic;
long bytesRead = sizeof(magic);
// param checks
if (!inRef)
return false;
// check for existence
err = FSGetCatalogInfo(inRef, kFSCatInfoNone, NULL, NULL, NULL, NULL);
if (err!=noErr)
return false;
// open and read the magic number len bytes
HFSUniStr255 dataForkName;
err = FSGetDataForkName( &dataForkName );
if (err!=noErr)
return false;
err = FSOpenFork( inRef, dataForkName.length, dataForkName.unicode,
fsRdPerm, &inRefNum );
if (err!=noErr)
return false;
err = FSRead( inRefNum, &bytesRead, &magic );
if (err!=noErr)
return false;
FSClose(inRefNum);
if (bytesRead != sizeof(magic))
return false;
// check if bytes read match magic number
return (magic == APPLESINGLE_MAGIC);
}
#pragma mark -
/*----------------------------------------------------------------------*
* Private methods
*----------------------------------------------------------------------*/
OSErr
nsAppleSingleDecoder::ProcessASEntry(ASEntry inEntry)
{
switch (inEntry.entryID)
{
case AS_DATA:
return ProcessDataFork( inEntry );
break;
case AS_RESOURCE:
return ProcessResourceFork( inEntry );
break;
case AS_REALNAME:
ProcessRealName( inEntry );
break;
case AS_FILEDATES:
return ProcessFileDates( inEntry );
break;
case AS_FINDERINFO:
return ProcessFinderInfo( inEntry );
break;
case AS_MACINFO:
case AS_COMMENT:
case AS_ICONBW:
case AS_ICONCOLOR:
case AS_PRODOSINFO:
case AS_MSDOSINFO:
case AS_AFPNAME:
case AS_AFPINFO:
case AS_AFPDIRID:
default:
return 0;
}
return 0;
}
OSErr
nsAppleSingleDecoder::ProcessDataFork(ASEntry inEntry)
{
OSErr err = noErr;
SInt16 refNum;
/* Setup the files */
HFSUniStr255 dataForkName;
err = FSGetDataForkName( &dataForkName );
if (err != noErr)
return err;
err = FSOpenFork( mOutRef, dataForkName.length, dataForkName.unicode,
fsWrPerm, &refNum );
if ( err == noErr )
err = EntryToMacFile( inEntry, refNum );
FSClose( refNum );
return err;
}
OSErr
nsAppleSingleDecoder::ProcessResourceFork(ASEntry inEntry)
{
OSErr err = noErr;
SInt16 refNum;
HFSUniStr255 rsrcForkName;
err = FSGetResourceForkName( &rsrcForkName );
if (err != noErr)
return err;
err = FSOpenFork( mOutRef, rsrcForkName.length, rsrcForkName.unicode,
fsWrPerm, &refNum );
if ( err == noErr )
err = EntryToMacFile( inEntry, refNum );
FSClose( refNum );
return err;
}
OSErr
nsAppleSingleDecoder::ProcessRealName(ASEntry inEntry)
{
OSErr err = noErr;
Str255 newName;
HFSUniStr255 newNameUni;
UInt32 bytesRead;
FSRef parentOfOutRef;
MAC_ERR_CHECK(SetFPos(mInRefNum, fsFromStart, inEntry.entryOffset));
bytesRead = inEntry.entryLength;
MAC_ERR_CHECK(FSRead(mInRefNum, (long *) &bytesRead, &newName[1]));
if (bytesRead != inEntry.entryLength)
return -1;
newName[0] = inEntry.entryLength;
MAC_ERR_CHECK(FSGetParentRef(mOutRef, &parentOfOutRef));
MAC_ERR_CHECK(HFSNameGetUnicodeName(newName, kTextEncodingUnknown,
&newNameUni));
err = FSRenameUnicode(mOutRef, newNameUni.length, newNameUni.unicode,
kTextEncodingUnknown, mOutRef);
if (err == dupFNErr)
{
HFSUniStr255 inRefName;
MAC_ERR_CHECK(FSGetCatalogInfo(mInRef, kFSCatInfoNone, NULL, &inRefName,
NULL, NULL));
// if we are trying to rename temp decode file to src name, rename later
if (nsAppleSingleDecoder::UCstrcmp(&newNameUni, &inRefName))
{
mRenameReqd = true;
return noErr;
}
// otherwise replace file in the way
FSRef inTheWayRef;
// delete file in the way
MAC_ERR_CHECK(FSMakeFSRefUnicode( &parentOfOutRef, newNameUni.length,
newNameUni.unicode, kTextEncodingUnknown, &inTheWayRef ));
MAC_ERR_CHECK(FSDeleteObject( &inTheWayRef ));
// rename decoded file to ``newName''
MAC_ERR_CHECK(FSRenameUnicode( mOutRef, newNameUni.length,
newNameUni.unicode, kTextEncodingUnknown, mOutRef ));
}
return err;
}
OSErr
nsAppleSingleDecoder::ProcessFileDates(ASEntry inEntry)
{
OSErr err = noErr;
ASFileDates dates;
UInt32 bytesRead;
FSCatalogInfo catInfo;
if ( inEntry.entryLength != sizeof(dates) )
return -1;
MAC_ERR_CHECK(SetFPos(mInRefNum, fsFromStart, inEntry.entryOffset));
bytesRead = inEntry.entryLength;
MAC_ERR_CHECK(FSRead(mInRefNum, (long *) &bytesRead, &dates));
if (bytesRead != inEntry.entryLength)
return -1;
#define YR_2000_SECONDS 3029529600
LocalDateTime local = (LocalDateTime) {0, 0, 0};
// set creation date
local.lowSeconds = dates.create + YR_2000_SECONDS;
ConvertLocalToUTCDateTime(&local, &catInfo.createDate);
// set content modification date
local.lowSeconds = dates.modify + YR_2000_SECONDS;
ConvertLocalToUTCDateTime(&local, &catInfo.contentModDate);
// set last access date
local.lowSeconds = dates.access + YR_2000_SECONDS;
ConvertLocalToUTCDateTime(&local, &catInfo.accessDate);
// set backup date
local.lowSeconds = dates.backup + YR_2000_SECONDS;
ConvertLocalToUTCDateTime(&local, &catInfo.backupDate);
// set attribute modification date
GetUTCDateTime(&catInfo.attributeModDate, kUTCDefaultOptions);
MAC_ERR_CHECK(FSSetCatalogInfo(mOutRef,
kFSCatInfoCreateDate |
kFSCatInfoContentMod |
kFSCatInfoAttrMod |
kFSCatInfoAccessDate |
kFSCatInfoBackupDate,
&catInfo));
return err;
}
OSErr
nsAppleSingleDecoder::ProcessFinderInfo(ASEntry inEntry)
{
OSErr err = noErr;
ASFinderInfo info;
UInt32 bytesRead;
FSCatalogInfo catInfo;
if (inEntry.entryLength != sizeof( ASFinderInfo ))
return -1;
MAC_ERR_CHECK(SetFPos(mInRefNum, fsFromStart, inEntry.entryOffset));
bytesRead = sizeof(info);
MAC_ERR_CHECK(FSRead(mInRefNum, (long *) &bytesRead, &info));
if (bytesRead != inEntry.entryLength)
return -1;
MAC_ERR_CHECK(FSGetCatalogInfo(mOutRef, kFSCatInfoGettableInfo, &catInfo,
NULL, NULL, NULL));
BlockMoveData((const void *) &info.ioFlFndrInfo,
(void *) &catInfo.finderInfo, sizeof(FInfo));
BlockMoveData((const void *) &info.ioFlXFndrInfo,
(void *) &catInfo.extFinderInfo, sizeof(FXInfo));
MAC_ERR_CHECK(FSSetCatalogInfo(mOutRef,
kFSCatInfoFinderInfo |
kFSCatInfoFinderXInfo,
&catInfo));
return err;
}
OSErr
nsAppleSingleDecoder::EntryToMacFile(ASEntry inEntry, UInt16 inTargetSpecRefNum)
{
#define BUFFER_SIZE 8192
OSErr err = noErr;
char buffer[BUFFER_SIZE];
UInt32 totalRead = 0, bytesRead, bytesToWrite;
MAC_ERR_CHECK(SetFPos( mInRefNum, fsFromStart, inEntry.entryOffset ));
while ( totalRead < inEntry.entryLength )
{
// Should we yield in here?
bytesRead = BUFFER_SIZE;
err = FSRead( mInRefNum, (long *) &bytesRead, buffer );
if (err!=noErr && err!=eofErr)
return err;
if ( bytesRead <= 0 )
return -1;
bytesToWrite = totalRead + bytesRead > inEntry.entryLength ?
inEntry.entryLength - totalRead :
bytesRead;
totalRead += bytesRead;
MAC_ERR_CHECK(FSWrite(inTargetSpecRefNum, (long *) &bytesToWrite,
buffer));
}
return err;
}
#pragma mark -
Boolean
nsAppleSingleDecoder::IsDirectory(const FSRef *inRef)
{
OSErr err;
Boolean isDir;
if (!inRef)
return false;
err = FSGetFinderInfo(inRef, NULL, NULL, &isDir);
if (err != noErr)
return false;
return isDir;
}
OSErr
nsAppleSingleDecoder::FSMakeUnique(const FSRef *inParentRef, FSRef *outRef)
{
/*
** This function has descended from Apple Sample Code, but we have
** made changes. Specifically, this function descends from the
** GenerateUniqueHFSUniStr() function in MoreFilesX.c, version 1.0.1.
*/
OSErr result = noErr;
long i, startSeed = 0x4a696d4c; /* a fine unlikely filename */
FSRefParam pb;
unsigned char hexStr[17] = "0123456789ABCDEF";
HFSUniStr255 uniqueName;
/* set up the parameter block */
pb.name = uniqueName.unicode;
pb.nameLength = 8; /* always 8 characters */
pb.textEncodingHint = kTextEncodingUnknown;
pb.newRef = outRef;
pb.ref = inParentRef;
/* loop until we get fnfErr with a filename in both directories */
result = noErr;
while ( fnfErr != result )
{
/* convert startSeed to 8 character Unicode string */
uniqueName.length = 8;
for ( i = 0; i < 8; ++i )
{
uniqueName.unicode[i] = hexStr[((startSeed >> ((7-i)*4)) & 0xf)];
}
result = PBMakeFSRefUnicodeSync(&pb);
if ( fnfErr == result )
{
OSErr err;
MAC_ERR_CHECK(FSCreateFileUnicode(inParentRef, uniqueName.length,
uniqueName.unicode, kFSCatInfoNone, NULL, outRef, NULL));
return noErr;
}
else if ( noErr != result)
{
/* exit if anything other than noErr or fnfErr */
return result;
}
/* increment seed for next pass through loop */
++(startSeed);
}
return result;
}
/*----------------------------------------------------------------------*
* Utilities
*----------------------------------------------------------------------*/
Boolean
nsAppleSingleDecoder::UCstrcmp(const HFSUniStr255 *str1,
const HFSUniStr255 *str2)
{
OSStatus status;
Boolean bEqual;
status = UCCompareTextDefault(kUCCollateStandardOptions, str1->unicode,
str1->length, str2->unicode, str2->length,
&bEqual, NULL);
if (status != noErr)
return false;
return bEqual;
}
#ifdef STANDALONE_ASD
int
main(int argc, char **argv)
{
OSErr err;
FSRef encoded, decoded;
nsAppleSingleDecoder *decoder = new nsAppleSingleDecoder;
Boolean isDir;
if (argc < 2)
{
cout << "usage: " << argv[0] << " <file/folder>" << endl
<< "\t\tAppleSingle encoded file path" << endl
<< "\t\tor" << endl
<< "\t\tfolder path containing AppleSingle encoded files." << endl;
exit(-1);
}
err = FSPathMakeRef((const UInt8 *)argv[1], &encoded, &isDir);
if (err != noErr)
return 1;
// handle AppleSingle encoded files
if (!isDir)
{
Boolean isEncoded = nsAppleSingleDecoder::IsAppleSingleFile(&encoded);
cout << "IsAppleSingleFile returned: " << (isEncoded ? "true" : "false")
<< endl;
if (isEncoded)
{
err = decoder->Decode(&encoded, &decoded);
cout << "Decode returned: " << err << endl;
}
}
// handle folders containing AppleSingle encoded files
else
{
err = decoder->DecodeFolder(&encoded);
cout << "DecodeFolder returned: " << err << endl;
}
// verify out file (n/a for folders)
if (!isDir)
{
err = FSGetCatalogInfo(&decoded, kFSCatInfoNone, NULL, NULL, NULL, NULL);
if (err == noErr)
{
cout << "Decoded file appears to exist" << endl;
char path[1024];
FSRefMakePath(&decoded, (UInt8 *)path, 1024);
cout << "Decoded file path: " << path << endl;
}
else
cout << "Decoded file doesn't appear to exist: " << err << endl;
}
return 0;
}
#endif /* STANDALONE_ASD */

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

@ -1,237 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (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/MPL/
*
* 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, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1999
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Samir Gehani <sgehani@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/*----------------------------------------------------------------------*
* Implements a simple AppleSingle decoder, as described in RFC1740
* http://andrew2.andrew.cmu.edu/rfc/rfc1740.html
*----------------------------------------------------------------------*/
#pragma options align=mac68k
#ifndef _NS_APPLESINGLEDECODER_H_
#define _NS_APPLESINGLEDECODER_H_
#include <stdlib.h>
#include <string.h>
#include <Carbon/Carbon.h>
/*----------------------------------------------------------------------*
* Struct definitions from RFC1740
*----------------------------------------------------------------------*/
#define APPLESINGLE_MAGIC 0x00051600L
#define APPLESINGLE_VERSION 0x00020000L
typedef struct ASHeader /* header portion of AppleSingle */
{
/* AppleSingle = 0x00051600; AppleDouble = 0x00051607 */
UInt32 magicNum; /* internal file type tag */
UInt32 versionNum; /* format version: 2 = 0x00020000 */
UInt8 filler[16]; /* filler, currently all bits 0 */
UInt16 numEntries; /* number of entries which follow */
} ASHeader ; /* ASHeader */
typedef struct ASEntry /* one AppleSingle entry descriptor */
{
UInt32 entryID; /* entry type: see list, 0 invalid */
UInt32 entryOffset; /* offset, in octets, from beginning */
/* of file to this entry's data */
UInt32 entryLength; /* length of data in octets */
} ASEntry; /* ASEntry */
typedef struct ASFinderInfo
{
FInfo ioFlFndrInfo; /* PBGetFileInfo() or PBGetCatInfo() */
FXInfo ioFlXFndrInfo; /* PBGetCatInfo() (HFS only) */
} ASFinderInfo; /* ASFinderInfo */
typedef struct ASMacInfo /* entry ID 10, Macintosh file information */
{
UInt8 filler[3]; /* filler, currently all bits 0 */
UInt8 ioFlAttrib; /* PBGetFileInfo() or PBGetCatInfo() */
} ASMacInfo;
typedef struct ASFileDates /* entry ID 8, file dates info */
{
SInt32 create; /* file creation date/time */
SInt32 modify; /* last modification date/time */
SInt32 backup; /* last backup date/time */
SInt32 access; /* last access date/time */
} ASFileDates; /* ASFileDates */
/* entryID list */
#define AS_DATA 1 /* data fork */
#define AS_RESOURCE 2 /* resource fork */
#define AS_REALNAME 3 /* File's name on home file system */
#define AS_COMMENT 4 /* standard Mac comment */
#define AS_ICONBW 5 /* Mac black & white icon */
#define AS_ICONCOLOR 6 /* Mac color icon */
/* 7 not used */
#define AS_FILEDATES 8 /* file dates; create, modify, etc */
#define AS_FINDERINFO 9 /* Mac Finder info & extended info */
#define AS_MACINFO 10 /* Mac file info, attributes, etc */
#define AS_PRODOSINFO 11 /* Pro-DOS file info, attrib., etc */
#define AS_MSDOSINFO 12 /* MS-DOS file info, attributes, etc */
#define AS_AFPNAME 13 /* Short name on AFP server */
#define AS_AFPINFO 14 /* AFP file info, attrib., etc */
#define AS_AFPDIRID 15 /* AFP directory ID */
/*----------------------------------------------------------------------*
* Macros
*----------------------------------------------------------------------*/
#define MAC_ERR_CHECK(_funcCall) \
err = _funcCall; \
if (err!=noErr) \
return err;
class nsAppleSingleDecoder
{
public:
nsAppleSingleDecoder(const FSRef *inRef, FSRef *outRef);
nsAppleSingleDecoder();
~nsAppleSingleDecoder();
/**
* Decode
*
* Takes an "in" FSSpec for the source file in AppleSingle
* format to decode and write out to an "out" FSSpec.
* This form is used when the Decode(void) method has already
* been invoked once and this object is reused to decode
* another AppleSingled file: useful in iteration to avoid
* nsAppleSingleDecoder object instantiation per file.
*
* @param inRef the AppleSingled file to decode
* @param outRef the destination file in which the decoded
* data was written out (empty when passed in
* and filled on return)
* @return err a standard MacOS OSErr where noErr means OK
*/
OSErr Decode(const FSRef *inRef, FSRef *outRef);
/**
* Decode
*
* Decodes the AppleSingled file passed in to the constructor
* and writes out the decoded data to the outSpec passed to the
* constructor.
*
* @return err a standard MacOS OSErr where noErr = OK
*/
OSErr Decode();
/**
* DecodeFolder
*
* Traverses arbitrarily nested subdirs decoding any files
* in AppleSingle format and leaving other files alone.
*
* @param aFolder the folder whose contents to decode
* @return err a standard MacOS err
* (dirNFErr if invalid dir, noErr = OK)
*/
OSErr DecodeFolder(const FSRef *aFolder);
/**
* IsAppleSingleFile
*
* Checks the file header to see whether this is an AppleSingle
* version 2 file by matching the magicNum field in the header.
*
* @param inRef the file to check
* @return bAppleSingle a Boolean where true indicates this is
* in fact an AppleSingle file
*/
static Boolean IsAppleSingleFile(const FSRef *inRef);
/**
* IsDirectory
*
* Check whether the supplied FSSpec points to a directory.
*
* @param inRef the file/directory spec
* @return bDir true iff this spec is a valid directory
*/
static Boolean IsDirectory(const FSRef *inRef);
/**
* String utility wrapper to compare to Unicode filenames.
*/
static Boolean UCstrcmp(const HFSUniStr255 *str1, const HFSUniStr255 *str2);
private:
const FSRef *mInRef;
FSRef *mOutRef;
// cache since it's used through the life of one Decode cycle:
SInt16 mInRefNum;
Boolean mRenameReqd;
OSErr ProcessASEntry(ASEntry inEntry);
OSErr ProcessDataFork(ASEntry inEntry);
OSErr ProcessResourceFork(ASEntry inEntry);
OSErr ProcessRealName(ASEntry inEntry);
OSErr ProcessFileDates(ASEntry inEntry);
OSErr ProcessFinderInfo(ASEntry inEntry);
OSErr EntryToMacFile(ASEntry inEntry, UInt16 inTargetSpecRefNum);
OSErr FSMakeUnique(const FSRef *inParentRef, FSRef *outRef);
};
#ifdef __cplusplus
extern "C" {
#endif
Boolean
DecodeDirIterateFilter(Boolean containerChanged, ItemCount currentLevel,
const FSCatalogInfo *catalogInfo, const FSRef *ref,
const FSSpec *spec, const HFSUniStr255 *name, void *yourDataPtr);
#ifdef __cplusplus
}
#endif
#pragma options align=reset
#endif /* _NS_APPLESINGLEDECODER_H_ */

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

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

@ -23,6 +23,7 @@
* Daniel Veditz <dveditz@netscape.com>
* Douglas Turner <dougt@netscape.com>
* Jens Bannmann <jens.b@web.de>
* Dave Townsend <dtownsend@oxymoronical.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
@ -41,125 +42,8 @@
#ifndef __NS_INSTALL_H__
#define __NS_INSTALL_H__
#include "nscore.h"
#include "nsISupports.h"
#include "jsapi.h"
#include "nsString.h"
#include "nsVoidArray.h"
#include "nsHashtable.h"
#include "nsCOMPtr.h"
#include "nsILocalFile.h"
#include "nsIURI.h"
#include "nsSoftwareUpdate.h"
#include "nsInstallObject.h"
#include "nsInstallVersion.h"
#include "nsInstallFolder.h"
#include "nsIXPINotifier.h"
#include "nsPIXPIProxy.h"
#include "nsIStringBundle.h"
#include "nsILocale.h"
#include "nsIServiceManager.h"
#include "nsIComponentManager.h"
#include "nsIEnumerator.h"
#include "nsIZipReader.h"
#include "nsIExtensionManager.h"
#include "nsIPrincipal.h"
#ifdef MOZ_XUL_APP
#include "nsIToolkitChromeRegistry.h"
#define CHROMEREG_IFACE nsIToolkitChromeRegistry
#else
#include "nsIChromeRegistrySea.h"
#define CHROMEREG_IFACE nsIChromeRegistrySea
#endif
#define XPINSTALL_BUNDLE_URL "chrome://global/locale/xpinstall/xpinstall.properties"
//file and directory name length maximums
#ifdef XP_MAC
#define MAX_FILENAME 31
#elif defined (XP_WIN) || defined(XP_OS2)
#define MAX_FILENAME 128
#else
#define MAX_FILENAME 1024
#endif
class nsInstallInfo
{
public:
nsInstallInfo( PRUint32 aInstallType,
nsIFile* aFile,
const PRUnichar* aURL,
const PRUnichar* aArgs,
nsIPrincipal* mPrincipal,
PRUint32 aFlags,
nsIXPIListener* aListener);
virtual ~nsInstallInfo();
nsIFile* GetFile() { return mFile.get(); }
const PRUnichar* GetURL() { return mURL.get(); }
const PRUnichar* GetArguments() { return mArgs.get(); }
PRUint32 GetFlags() { return mFlags; }
PRUint32 GetType() { return mType; }
nsIXPIListener* GetListener() { return mListener.get(); }
CHROMEREG_IFACE* GetChromeRegistry() { return mChromeRegistry; }
#ifdef MOZ_XUL_APP
nsIExtensionManager* GetExtensionManager() { return mExtensionManager; }
#else
const nsCString& GetFileJARSpec() { return mFileJARSpec; }
#endif
nsCOMPtr<nsIPrincipal> mPrincipal;
private:
nsresult mError;
PRUint32 mType;
PRUint32 mFlags;
nsString mURL;
nsString mArgs;
nsCOMPtr<nsIFile> mFile;
nsCOMPtr<nsIXPIListener> mListener;
nsCOMPtr<CHROMEREG_IFACE> mChromeRegistry;
#ifdef MOZ_XUL_APP
nsCOMPtr<nsIExtensionManager> mExtensionManager;
#else
nsCString mFileJARSpec;
#endif
};
#if defined(XP_WIN) || defined(XP_OS2)
#define FILESEP '\\'
#elif defined XP_MAC
#define FILESEP ':'
#elif defined XP_BEOS
#define FILESEP '/'
#else
#define FILESEP '/'
#endif
// not using 0x1 in this bitfield because it causes problems with legacy code
#define DO_NOT_UNINSTALL 0x2
#define WIN_SHARED_FILE 0x4
#define WIN_SYSTEM_FILE 0x8
class nsInstall
{
friend class nsWinReg;
friend class nsWinProfile;
public:
enum
@ -228,171 +112,6 @@ class nsInstall
SUCCESS = 0,
REBOOT_NEEDED = 999
};
nsInstall(nsIZipReader * theJARFile);
virtual ~nsInstall();
PRInt32 SetScriptObject(void* aScriptObject);
PRInt32 SaveWinRegPrototype(void* aScriptObject);
PRInt32 SaveWinProfilePrototype(void* aScriptObject);
JSObject* RetrieveWinRegPrototype(void);
JSObject* RetrieveWinProfilePrototype(void);
PRInt32 AbortInstall(PRInt32 aErrorNumber);
PRInt32 AddDirectory(const nsString& aRegName, const nsString& aVersion, const nsString& aJarSource, nsInstallFolder* aFolder, const nsString& aSubdir, PRInt32 aMode, PRInt32* aReturn);
PRInt32 AddDirectory(const nsString& aRegName, const nsString& aVersion, const nsString& aJarSource, nsInstallFolder* aFolder, const nsString& aSubdir, PRInt32* aReturn);
PRInt32 AddDirectory(const nsString& aRegName, const nsString& aJarSource, nsInstallFolder* aFolder, const nsString& aSubdir, PRInt32* aReturn);
PRInt32 AddDirectory(const nsString& aJarSource, PRInt32* aReturn);
PRInt32 AddSubcomponent(const nsString& aRegName, const nsString& aVersion, const nsString& aJarSource, nsInstallFolder *aFolder, const nsString& aTargetName, PRInt32 aMode, PRInt32* aReturn);
PRInt32 AddSubcomponent(const nsString& aRegName, const nsString& aVersion, const nsString& aJarSource, nsInstallFolder *aFolder, const nsString& aTargetName, PRInt32* aReturn);
PRInt32 AddSubcomponent(const nsString& aRegName, const nsString& aJarSource, nsInstallFolder *aFolder, const nsString& aTargetName, PRInt32* aReturn);
PRInt32 AddSubcomponent(const nsString& aJarSource, PRInt32* aReturn);
PRInt32 DiskSpaceAvailable(const nsString& aFolder, PRInt64* aReturn);
PRInt32 Execute(const nsString& aJarSource, const nsString& aArgs, PRBool aBlocking, PRInt32* aReturn);
PRInt32 FinalizeInstall(PRInt32* aReturn);
PRInt32 Gestalt(const nsString& aSelector, PRInt32* aReturn);
PRInt32 GetComponentFolder(const nsString& aComponentName, const nsString& aSubdirectory, nsInstallFolder** aFolder);
PRInt32 GetComponentFolder(const nsString& aComponentName, nsInstallFolder** aFolder);
PRInt32 GetFolder(nsInstallFolder& aTargetFolder, const nsString& aSubdirectory, nsInstallFolder** aFolder);
PRInt32 GetFolder(const nsString& aTargetFolder, const nsString& aSubdirectory, nsInstallFolder** aFolder);
PRInt32 GetFolder(const nsString& aTargetFolder, nsInstallFolder** aFolder);
PRInt32 GetLastError(PRInt32* aReturn);
PRInt32 GetWinProfile(const nsString& aFolder, const nsString& aFile, JSContext* jscontext, JSClass* WinProfileClass, jsval* aReturn);
PRInt32 GetWinRegistry(JSContext* jscontext, JSClass* WinRegClass, jsval* aReturn);
PRInt32 LoadResources(JSContext* cx, const nsString& aBaseName, jsval* aReturn);
PRInt32 Patch(const nsString& aRegName, const nsString& aVersion, const nsString& aJarSource, nsInstallFolder* aFolder, const nsString& aTargetName, PRInt32* aReturn);
PRInt32 Patch(const nsString& aRegName, const nsString& aJarSource, nsInstallFolder* aFolder, const nsString& aTargetName, PRInt32* aReturn);
PRInt32 RegisterChrome(nsIFile* chrome, PRUint32 chromeType, const char* path);
PRInt32 RefreshPlugins(PRBool aReloadPages);
PRInt32 ResetError(PRInt32 aError);
PRInt32 SetPackageFolder(nsInstallFolder& aFolder);
PRInt32 StartInstall(const nsString& aUserPackageName, const nsString& aPackageName, const nsString& aVersion, PRInt32* aReturn);
PRInt32 Uninstall(const nsString& aPackageName, PRInt32* aReturn);
PRInt32 FileOpDirCreate(nsInstallFolder& aTarget, PRInt32* aReturn);
PRInt32 FileOpDirGetParent(nsInstallFolder& aTarget, nsInstallFolder** theParentFolder);
PRInt32 FileOpDirRemove(nsInstallFolder& aTarget, PRInt32 aFlags, PRInt32* aReturn);
PRInt32 FileOpDirRename(nsInstallFolder& aSrc, nsString& aTarget, PRInt32* aReturn);
PRInt32 FileOpFileCopy(nsInstallFolder& aSrc, nsInstallFolder& aTarget, PRInt32* aReturn);
PRInt32 FileOpFileDelete(nsInstallFolder& aTarget, PRInt32 aFlags, PRInt32* aReturn);
PRInt32 FileOpFileExists(nsInstallFolder& aTarget, PRBool* aReturn);
PRInt32 FileOpFileExecute(nsInstallFolder& aTarget, nsString& aParams, PRBool aBlocking, PRInt32* aReturn);
PRInt32 FileOpFileGetNativeVersion(nsInstallFolder& aTarget, nsString* aReturn);
PRInt32 FileOpFileGetDiskSpaceAvailable(nsInstallFolder& aTarget, PRInt64* aReturn);
PRInt32 FileOpFileGetModDate(nsInstallFolder& aTarget, double* aReturn);
PRInt32 FileOpFileGetSize(nsInstallFolder& aTarget, PRInt64* aReturn);
PRInt32 FileOpFileIsDirectory(nsInstallFolder& aTarget, PRBool* aReturn);
PRInt32 FileOpFileIsWritable(nsInstallFolder& aTarget, PRBool* aReturn);
PRInt32 FileOpFileIsFile(nsInstallFolder& aTarget, PRBool* aReturn);
PRInt32 FileOpFileModDateChanged(nsInstallFolder& aTarget, double aOldStamp, PRBool* aReturn);
PRInt32 FileOpFileMove(nsInstallFolder& aSrc, nsInstallFolder& aTarget, PRInt32* aReturn);
PRInt32 FileOpFileRename(nsInstallFolder& aSrc, nsString& aTarget, PRInt32* aReturn);
PRInt32 FileOpFileWindowsGetShortName(nsInstallFolder& aTarget, nsString& aShortPathName);
PRInt32 FileOpFileWindowsShortcut(nsIFile* aTarget, nsIFile* aShortcutPath, nsString& aDescription, nsIFile* aWorkingPath, nsString& aParams, nsIFile* aIcon, PRInt32 aIconId, PRInt32* aReturn);
PRInt32 FileOpFileMacAlias(nsIFile *aSourceFile, nsIFile *aAliasFile, PRInt32* aReturn);
PRInt32 FileOpFileUnixLink(nsInstallFolder& aTarget, PRInt32 aFlags, PRInt32* aReturn);
PRInt32 FileOpWinRegisterServer(nsInstallFolder& aTarget, PRInt32* aReturn);
void LogComment(const nsAString& aComment);
PRInt32 ExtractFileFromJar(const nsString& aJarfile, nsIFile* aSuggestedName, nsIFile** aRealName);
char* GetResourcedString(const nsAString& aResName);
void AddPatch(nsHashKey *aKey, nsIFile* fileName);
void GetPatch(nsHashKey *aKey, nsIFile** fileName);
nsIFile* GetJarFileLocation() { return mJarFileLocation; }
void SetJarFileLocation(nsIFile* aFile);
void GetInstallArguments(nsString& args);
void SetInstallArguments(const nsString& args);
void GetInstallURL(nsString& url);
void SetInstallURL(const nsString& url);
PRUint32 GetInstallFlags() { return mInstallFlags; }
void SetInstallFlags(PRUint32 aFlags) { mInstallFlags = aFlags; }
PRInt32 GetInstallPlatform(nsCString& aPlatform);
CHROMEREG_IFACE* GetChromeRegistry() { return mChromeRegistry; }
void SetChromeRegistry(CHROMEREG_IFACE* reg)
{ mChromeRegistry = reg; }
PRInt32 GetFinalStatus() { return mFinalStatus; }
PRBool InInstallTransaction(void) { return mInstalledFiles != nsnull; }
PRInt32 Alert(nsString& string);
PRInt32 ConfirmEx(nsString& aDialogTitle, nsString& aText, PRUint32 aButtonFlags, nsString& aButton0Title, nsString& aButton1Title, nsString& aButton2Title, nsString& aCheckMsg, PRBool* aCheckState, PRInt32* aReturn);
void InternalAbort(PRInt32 errcode);
PRInt32 ScheduleForInstall(nsInstallObject* ob);
PRInt32 SaveError(PRInt32 errcode);
private:
JSObject* mScriptObject;
JSObject* mWinRegObject;
JSObject* mWinProfileObject;
nsCOMPtr<nsIFile> mJarFileLocation;
nsIZipReader* mJarFileData;
nsString mInstallArguments;
nsString mInstallURL;
PRUint32 mInstallFlags;
nsCString mInstallPlatform;
CHROMEREG_IFACE* mChromeRegistry; // we don't own it, it outlives us
nsInstallFolder* mPackageFolder;
PRBool mUserCancelled;
PRInt32 mFinalStatus;
PRBool mUninstallPackage;
PRBool mRegisterPackage;
PRBool mStartInstallCompleted;
nsString mRegistryPackageName; /* Name of the package we are installing */
nsString mUIName; /* User-readable package name */
nsInstallVersion* mVersionInfo; /* Component version info */
nsVoidArray* mInstalledFiles;
//nsCOMPtr<nsISupportsArray> mInstalledFiles;
nsHashtable* mPatchList;
nsCOMPtr<nsIXPIListener> mListener;
nsCOMPtr<nsPIXPIProxy> mUIThreadProxy;
nsCOMPtr<nsIStringBundle> mStringBundle;
PRInt32 mLastError;
void ParseFlags(int flags);
PRInt32 SanityCheck(void);
void GetTime(nsString &aString);
nsPIXPIProxy* GetUIThreadProxy();
PRInt32 GetQualifiedRegName(const nsString& name, nsString& qualifiedRegName );
PRInt32 GetQualifiedPackageName( const nsString& name, nsString& qualifiedName );
void CurrentUserNode(nsString& userRegNode);
PRBool BadRegName(const nsString& regName);
void CleanUp();
};
nsresult MakeUnique(nsILocalFile* file);
#endif

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

@ -1,91 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (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/MPL/
*
* 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, released March 31,
* 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Sean Su <ssu@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nscore.h"
#include "nsInstall.h" // for error codes
#include "prmem.h"
#include "nsInstallBitwise.h"
#ifdef _WINDOWS
#include <windows.h>
#include <winreg.h>
#endif
#define KEY_SHARED_DLLS "Software\\Microsoft\\Windows\\CurrentVersion\\SharedDlls"
PRInt32 RegisterSharedFile(const char *file, PRBool bAlreadyExists)
{
PRInt32 rv = nsInstall::SUCCESS;
#ifdef WIN32
HKEY root;
HKEY keyHandle = 0;
LONG result;
DWORD type = REG_DWORD;
DWORD dwDisposition;
PRUint32 valbuf = 0;
PRUint32 valbufsize;
valbufsize = sizeof(PRUint32);
root = HKEY_LOCAL_MACHINE;
result = RegCreateKeyEx(root, KEY_SHARED_DLLS, 0, nsnull, REG_OPTION_NON_VOLATILE, KEY_READ | KEY_WRITE, nsnull, &keyHandle, &dwDisposition);
if(ERROR_SUCCESS == result)
{
result = RegQueryValueEx(keyHandle, file, nsnull, &type, (LPBYTE)&valbuf, (LPDWORD)&valbufsize);
if((ERROR_SUCCESS == result) && (type == REG_DWORD))
++valbuf;
else
{
valbuf = 1;
if(bAlreadyExists == PR_TRUE)
++valbuf;
}
RegSetValueEx(keyHandle, file, 0, REG_DWORD, (LPBYTE)&valbuf, valbufsize);
RegCloseKey(keyHandle);
}
else
rv = nsInstall::UNEXPECTED_ERROR;
#endif
return(rv);
}

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

@ -1,52 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (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/MPL/
*
* 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, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Sean Su <ssu@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef __NSINSTALLBITWISE_H__
#define __NSINSTALLBITWISE_H__
#include "NSReg.h"
#include "nsIFile.h"
PR_BEGIN_EXTERN_C
PRInt32 RegisterSharedFile(const char *file, PRBool bAlreadyExists);
PR_END_EXTERN_C
#endif

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

@ -1,311 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (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/MPL/
*
* 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, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Daniel Veditz <dveditz@netscape.com>
* Douglas Turner <dougt@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsCRT.h"
#include "prmem.h"
#include "prprf.h"
#include "VerReg.h"
#include "nsInstallExecute.h"
#include "nsInstallResources.h"
#include "ScheduledTasks.h"
#include "nsInstall.h"
#include "nsIDOMInstallVersion.h"
#include "nsProcess.h"
#include "nsReadableUtils.h"
// Chop the command-line up in place into an array of arguments
// by replacing spaces in the command-line string with null
// terminators and pointing the array elements to the
// characters following the null terminators.
//
// aArgsString is a string containing the complete command-line.
// aArgs points to an array which will be filled with the
// individual arguments from the command-line.
// aArgsAvailable is the size of aArgs, i.e. the maximum number of
// individual command-line arguments which can be stored in the array.
//
// Returns the count of the number of command-line arguments actually
// stored into the array aArgs or -1 if it fails.
PRInt32 xpi_PrepareProcessArguments(const char *aArgsString, char **aArgs, PRInt32 aArgsAvailable)
{
int argc;
char *c;
char *p; // look ahead
PRBool quoted = PR_FALSE;
aArgs[0] = (char *)aArgsString;
if (!aArgs[0])
return -1;
// Strip leading spaces from command-line string.
argc = 0;
c = aArgs[argc];
while (*c == ' ') ++c;
aArgs[argc++] = c;
for (; *c && argc < aArgsAvailable; ++c)
{
switch(*c) {
// Only handle escaped double quote and escaped backslash.
case '\\':
// See if next character is backslash or dquote
if ( *(c+1) == '\\' || *(c+1) == '\"' )
{
// Eat escape character (i.e., backslash) by
// shifting all characters to the left one.
for (p=c; *p != 0; ++p)
*p = *(p+1);
}
break;
case '\"':
*c = 0; // terminate current arg
if (quoted)
{
p = c+1; // look ahead
while (*p == ' ')
++p; // eat spaces
if (*p)
aArgs[argc++] = p; //not at end, set next arg
c = p-1;
quoted = PR_FALSE;
}
else
{
quoted = PR_TRUE;
if (aArgs[argc-1] == c)
// Quote is at beginning so
// start current argument after the quote.
aArgs[argc-1] = c+1;
else
// Quote is embedded so
// start a new argument after the quote.
aArgs[argc++] = c+1;
}
break;
case ' ':
if (!quoted)
{
*c = 0; // terminate current arg
p = c+1; // look ahead
while (*p == ' ')
++p; // eat spaces
if (*p)
aArgs[argc++] = p; //not at end, set next arg
c = p-1;
}
break;
default:
break; // nothing to do
}
}
return argc;
}
nsInstallExecute:: nsInstallExecute( nsInstall* inInstall,
const nsString& inJarLocation,
const nsString& inArgs,
const PRBool inBlocking,
PRInt32 *error)
: nsInstallObject(inInstall)
{
MOZ_COUNT_CTOR(nsInstallExecute);
if ((inInstall == nsnull) || (inJarLocation.IsEmpty()) )
{
*error = nsInstall::INVALID_ARGUMENTS;
return;
}
mJarLocation = inJarLocation;
mArgs = inArgs;
mExecutableFile = nsnull;
mBlocking = inBlocking;
mPid = nsnull;
}
nsInstallExecute::~nsInstallExecute()
{
MOZ_COUNT_DTOR(nsInstallExecute);
}
PRInt32 nsInstallExecute::Prepare()
{
if (mInstall == NULL || mJarLocation.IsEmpty())
return nsInstall::INVALID_ARGUMENTS;
return mInstall->ExtractFileFromJar(mJarLocation, nsnull, getter_AddRefs(mExecutableFile));
}
PRInt32 nsInstallExecute::Complete()
{
#define ARG_SLOTS 256
PRInt32 result = NS_OK;
PRInt32 rv = nsInstall::SUCCESS;
char *cArgs[ARG_SLOTS];
int argcount = 0;
if (mExecutableFile == nsnull)
return nsInstall::INVALID_ARGUMENTS;
nsCOMPtr<nsIProcess> process = do_CreateInstance(NS_PROCESS_CONTRACTID);
char *arguments = nsnull;
if (!mArgs.IsEmpty())
{
arguments = ToNewCString(mArgs);
argcount = xpi_PrepareProcessArguments(arguments, cArgs, ARG_SLOTS);
}
if (argcount >= 0)
{
result = process->Init(mExecutableFile);
if (NS_SUCCEEDED(result))
{
result = process->Run(mBlocking, (const char**)&cArgs, argcount, mPid);
if (NS_SUCCEEDED(result))
{
if (mBlocking)
{
process->GetExitValue(&result);
if (result != 0)
rv = nsInstall::EXECUTION_ERROR;
// should be OK to delete now since execution done
DeleteFileNowOrSchedule( mExecutableFile );
}
else
{
// don't try to delete now since execution is async
ScheduleFileForDeletion( mExecutableFile );
}
}
else
rv = nsInstall::EXECUTION_ERROR;
}
else
rv = nsInstall::EXECUTION_ERROR;
}
else
rv = nsInstall::UNEXPECTED_ERROR;
if(arguments)
NS_Free(arguments);
return rv;
}
void nsInstallExecute::Abort()
{
/* Get the names */
if (mExecutableFile == nsnull)
return;
DeleteFileNowOrSchedule(mExecutableFile);
}
char* nsInstallExecute::toString()
{
if (!mInstall)
return nsnull;
char* buffer = new char[1024];
char* rsrcVal = nsnull;
if (!buffer)
return nsnull;
// if the FileSpec is NULL, just us the in jar file name.
if (mExecutableFile == nsnull)
{
char *tempString = ToNewCString(mJarLocation);
rsrcVal = mInstall->GetResourcedString(NS_LITERAL_STRING("Execute"));
if (rsrcVal)
{
PR_snprintf(buffer, sizeof(buffer), rsrcVal, tempString);
nsCRT::free(rsrcVal);
}
if (tempString)
NS_Free(tempString);
}
else
{
rsrcVal = mInstall->GetResourcedString(NS_LITERAL_STRING("Execute"));
if (rsrcVal)
{
nsCAutoString temp;
mExecutableFile->GetNativePath(temp);
PR_snprintf(buffer, sizeof(buffer), rsrcVal, temp.get());
nsCRT::free(rsrcVal);
}
}
return buffer;
}
PRBool
nsInstallExecute::CanUninstall()
{
return PR_FALSE;
}
PRBool
nsInstallExecute::RegisterPackageNode()
{
return PR_FALSE;
}

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

@ -1,92 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (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/MPL/
*
* 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, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Daniel Veditz <dveditz@netscape.com>
* Douglas Turner <dougt@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsInstallExecute_h__
#define nsInstallExecute_h__
#include "prtypes.h"
#include "nsString.h"
#include "nsInstallObject.h"
#include "nsInstall.h"
#include "nsIDOMInstallVersion.h"
PRInt32 xpi_PrepareProcessArguments(const char *aArgsString, char **aArgs, PRInt32 aArgsAvailable);
class nsInstallExecute : public nsInstallObject
{
public:
nsInstallExecute( nsInstall* inInstall,
const nsString& inJarLocation,
const nsString& inArgs,
const PRBool inBlocking,
PRInt32 *error);
virtual ~nsInstallExecute();
PRInt32 Prepare();
PRInt32 Complete();
void Abort();
char* toString();
PRBool CanUninstall();
PRBool RegisterPackageNode();
private:
nsString mJarLocation; // Location in the JAR
nsString mArgs; // command line arguments
nsCOMPtr<nsIFile> mExecutableFile; // temporary file location
PRBool mBlocking;
PRUint32* mPid;
PRInt32 NativeComplete(void);
void NativeAbort(void);
};
#endif /* nsInstallExecute_h__ */

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

@ -1,449 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (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/MPL/
*
* 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, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Daniel Veditz <dveditz@netscape.com>
* Douglas Turner <dougt@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "prprf.h"
#include "nsInstallFile.h"
#include "VerReg.h"
#include "ScheduledTasks.h"
#include "nsInstall.h"
#include "nsIDOMInstallVersion.h"
#include "nsInstallResources.h"
#include "nsInstallLogComment.h"
#include "nsInstallBitwise.h"
#include "nsXPIDLString.h"
#include "nsReadableUtils.h"
/* 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(nsInstall* inInstall,
const nsString& inComponentName,
const nsString& inVInfo,
const nsString& inJarLocation,
nsInstallFolder *folderSpec,
const nsString& inPartialPath,
PRInt32 mode,
PRBool aRegister,
PRInt32 *error)
: nsInstallObject(inInstall),
mVersionInfo(nsnull),
mJarLocation(nsnull),
mExtractedFile(nsnull),
mFinalFile(nsnull),
mVersionRegistryName(nsnull),
mReplaceFile(PR_FALSE),
mRegister(aRegister),
mMode(mode)
{
MOZ_COUNT_CTOR(nsInstallFile);
PRBool flagExists, flagIsFile;
mFolderCreateCount = 0;
if ((folderSpec == nsnull) || (inInstall == NULL))
{
*error = nsInstall::INVALID_ARGUMENTS;
return;
}
*error = nsInstall::SUCCESS;
nsCOMPtr<nsIFile> tmp = folderSpec->GetFileSpec();
if (!tmp)
{
*error = nsInstall::INVALID_ARGUMENTS;
return;
}
tmp->Clone(getter_AddRefs(mFinalFile));
if (mFinalFile == nsnull)
{
*error = nsInstall::OUT_OF_MEMORY;
return;
}
mFinalFile->Exists(&flagExists);
if (flagExists)
{
// is there a file with the same name as the proposed folder?
mFinalFile->IsFile(&flagIsFile);
if ( flagIsFile)
{
*error = nsInstall::ACCESS_DENIED;
return;
}
// else this directory already exists, so do nothing
}
//Need to parse the inPartialPath to remove any separators
PRBool finished = PR_FALSE;
PRUint32 offset = 0;
PRInt32 location = 0, nodeLength = 0;
nsString subString;
location = inPartialPath.FindChar('/', offset);
if (location == ((PRInt32)inPartialPath.Length() - 1)) //trailing slash
{
*error = nsInstall::INVALID_ARGUMENTS;
return;
}
while (!finished)
{
if (location == kNotFound) //no separators were found
{
nodeLength = inPartialPath.Length() - offset;
finished = PR_TRUE;
}
else
{
nodeLength = location - offset;
}
if (nodeLength > MAX_FILENAME)
{
*error = nsInstall::FILENAME_TOO_LONG;
return;
}
else
{
inPartialPath.Mid(subString, offset, nodeLength);
mFinalFile->Append(subString);
offset += nodeLength + 1;
if (!finished)
location = inPartialPath.FindChar('/', offset);
}
}
mFinalFile->Exists(&mReplaceFile);
mVersionRegistryName = new nsString(inComponentName);
mJarLocation = new nsString(inJarLocation);
mVersionInfo = new nsString(inVInfo);
if (mVersionRegistryName == nsnull ||
mJarLocation == nsnull ||
mVersionInfo == nsnull )
{
*error = nsInstall::OUT_OF_MEMORY;
return;
}
}
nsInstallFile::~nsInstallFile()
{
if (mVersionRegistryName)
delete mVersionRegistryName;
if (mJarLocation)
delete mJarLocation;
if (mVersionInfo)
delete mVersionInfo;
//if(mFinalFile)
// mFinalFile = nsnull;
//if(mExtractedFile)
// mExtractedFile = nsnull;
MOZ_COUNT_DTOR(nsInstallFile);
}
void nsInstallFile::CreateAllFolders(nsInstall *aInstall, nsIFile *aFolder, PRInt32 *aError)
{
PRBool flagExists;
nsInstallLogComment *ilc = nsnull;
nsresult rv = aFolder->Exists(&flagExists);
if (NS_FAILED(rv))
*aError = nsInstall::UNEXPECTED_ERROR;
else if (flagExists)
*aError = nsInstall::SUCCESS;
else
{
// Doesn't exist, work our way up trying to create each node above
nsCOMPtr<nsIFile> parent;
rv = aFolder->GetParent(getter_AddRefs(parent));
if (NS_FAILED(rv))
{
// we're already at the top -- give up
*aError = nsInstall::ACCESS_DENIED;
return;
}
CreateAllFolders(aInstall, parent, aError);
if (*aError != nsInstall::SUCCESS)
return;
aFolder->Create(nsIFile::DIRECTORY_TYPE, 0755); //nsIFileXXX: What kind of permissions are required here?
++mFolderCreateCount;
nsAutoString folderPath;
aFolder->GetPath(folderPath);
ilc = new nsInstallLogComment(aInstall,
NS_LITERAL_STRING("CreateFolder"),
folderPath,
aError);
if(ilc == nsnull)
*aError = nsInstall::OUT_OF_MEMORY;
if(*aError == nsInstall::SUCCESS)
*aError = mInstall->ScheduleForInstall(ilc);
}
}
#ifdef XXX_SSU
void nsInstallFile::RemoveAllFolders()
{
/* the nsFileSpecMac.cpp operator += requires "this" (the nsFileSpec)
* to be an existing dir
*/
PRUint32 i;
nsFileSpec nsfsFolder;
nsFileSpec nsfsParentFolder;
nsString nsStrFolder;
if(mFinalFile != nsnull)
{
mFinalFile->GetParent(nsfsFolder);
for(i = 0; i < mFolderCreateCount; i++)
{
nsfsFolder.Remove(PR_FALSE);
nsfsFolder.GetParent(nsfsParentFolder);
nsfsFolder = nsfsParentFolder;
}
}
}
#endif
/* Prepare
* Extracts file out of the JAR archive
*/
PRInt32 nsInstallFile::Prepare()
{
PRInt32 error = nsInstall::SUCCESS;
if (mInstall == nsnull || mFinalFile == nsnull || mJarLocation == nsnull )
return nsInstall::INVALID_ARGUMENTS;
if (mReplaceFile == PR_FALSE)
{
/* although it appears that we are creating the dir _again_ it is necessary
* when inPartialPath has arbitrary levels of nested dirs before the leaf
*/
nsCOMPtr<nsIFile> parent;
mFinalFile->GetParent(getter_AddRefs(parent));
CreateAllFolders(mInstall, parent, &error);
if(nsInstall::SUCCESS != error)
return error;
}
return mInstall->ExtractFileFromJar(*mJarLocation, mFinalFile, getter_AddRefs(mExtractedFile));
}
/* Complete
* Completes the install:
* - move the downloaded file to the final location
* - updates the registry
*/
PRInt32 nsInstallFile::Complete()
{
PRInt32 err;
if (mInstall == nsnull || mVersionRegistryName == nsnull || mFinalFile == nsnull )
{
return nsInstall::INVALID_ARGUMENTS;
}
err = CompleteFileMove();
if ( mRegister && (0 == err || nsInstall::REBOOT_NEEDED == err) )
{
nsCAutoString path;
mFinalFile->GetNativePath(path);
VR_Install( const_cast<char*>(NS_ConvertUTF16toUTF8(*mVersionRegistryName).get()),
const_cast<char*>(path.get()),
const_cast<char*>(NS_ConvertUTF16toUTF8(*mVersionInfo).get()),
PR_FALSE );
}
return err;
}
void nsInstallFile::Abort()
{
if (mExtractedFile != nsnull)
mExtractedFile->Remove(PR_FALSE);
}
#define RESBUFSIZE 4096
char* nsInstallFile::toString()
{
if (!mInstall)
return nsnull;
char* buffer = new char[RESBUFSIZE];
char* rsrcVal = nsnull;
if (!buffer)
return nsnull;
else
buffer[0] = '\0';
if (mReplaceFile)
{
if(mMode & WIN_SHARED_FILE)
{
rsrcVal = mInstall->GetResourcedString(NS_LITERAL_STRING("ReplaceSharedFile"));
}
else
{
rsrcVal = mInstall->GetResourcedString(NS_LITERAL_STRING("ReplaceFile"));
}
}
else
{
if(mMode & WIN_SHARED_FILE)
{
rsrcVal = mInstall->GetResourcedString(NS_LITERAL_STRING("InstallSharedFile"));
}
else
{
rsrcVal = mInstall->GetResourcedString(NS_LITERAL_STRING("InstallFile"));
}
}
if (rsrcVal)
{
char* interimCStr = nsnull;
nsString interimStr;
if(mMode & DO_NOT_UNINSTALL)
interimStr.Assign(NS_LITERAL_STRING("(*dnu*) "));
interimStr.AppendWithConversion(rsrcVal);
interimCStr = ToNewCString(interimStr);
if(interimCStr)
{
nsCAutoString fname;
if (mFinalFile)
mFinalFile->GetNativePath(fname);
PR_snprintf( buffer, RESBUFSIZE, interimCStr, fname.get() );
NS_Free(interimCStr);
}
NS_Free(rsrcVal);
}
return buffer;
}
PRInt32 nsInstallFile::CompleteFileMove()
{
int result = 0;
PRBool bIsEqual = PR_FALSE;
if (mExtractedFile == nsnull)
{
return nsInstall::UNEXPECTED_ERROR;
}
mExtractedFile->Equals(mFinalFile, &bIsEqual);
if ( bIsEqual )
{
/* No need to rename, they are the same */
result = nsInstall::SUCCESS;
}
else
{
result = ReplaceFileNowOrSchedule(mExtractedFile, mFinalFile, mMode );
}
if(mMode & WIN_SHARED_FILE)
{
nsCAutoString path;
mFinalFile->GetNativePath(path);
RegisterSharedFile(path.get(), mReplaceFile);
}
return result;
}
/* CanUninstall
* InstallFile() installs files which can be uninstalled,
* hence this function returns true.
*/
PRBool
nsInstallFile::CanUninstall()
{
return PR_TRUE;
}
/* RegisterPackageNode
* InstallFile() installs files which need to be registered,
* hence this function returns true.
*/
PRBool
nsInstallFile::RegisterPackageNode()
{
return PR_TRUE;
}

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

@ -1,119 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (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/MPL/
*
* 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, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Daniel Veditz <dveditz@netscape.com>
* Douglas Turner <dougt@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsInstallFile_h__
#define nsInstallFile_h__
#include "prtypes.h"
#include "nsString.h"
#include "nsInstallObject.h"
#include "nsInstall.h"
#include "nsInstallVersion.h"
/* Global defines for file handling mode bitfield values */
#define INSTALL_NO_COMPARE 0x1
#define INSTALL_IF_NEWER 0x2
#define INSTALL_IF_EQUAL_OR_NEWER 0x4
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( nsInstall* inInstall,
const nsString& inVRName,
const nsString& inVInfo,
const nsString& inJarLocation,
nsInstallFolder *folderSpec,
const nsString& inPartialPath,
PRInt32 mode,
PRBool bRegister,
PRInt32 *error);
virtual ~nsInstallFile();
PRInt32 Prepare();
PRInt32 Complete();
void Abort();
char* toString();
PRBool CanUninstall();
PRBool RegisterPackageNode();
private:
/* Private Fields */
nsString* mVersionInfo; /* Version info for this file*/
nsString* mJarLocation; /* Location in the JAR */
nsCOMPtr<nsIFile> mExtractedFile; /* temporary file location */
nsCOMPtr<nsIFile> mFinalFile; /* final file destination */
nsString* mVersionRegistryName; /* full version path */
PRBool mReplaceFile; /* whether file exists */
PRBool mRegister; /* if true register this file */
PRUint32 mFolderCreateCount; /* int to keep count of the number of folders created for a given path */
PRInt32 mMode; /* an integer used like a bitfield to control *
* how a file is installed or registered */
PRInt32 CompleteFileMove();
void CreateAllFolders(nsInstall *inInstall, nsIFile *inFolderPath, PRInt32 *error);
};
#endif /* nsInstallFile_h__ */

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

@ -1,58 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (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/MPL/
*
* 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.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsInstallFileOpEnums_h__
#define nsInstallFileOpEnums_h__
typedef enum nsInstallFileOpEnums {
NS_FOP_DIR_CREATE = 0,
NS_FOP_DIR_REMOVE = 1,
NS_FOP_DIR_RENAME = 2,
NS_FOP_FILE_COPY = 3,
NS_FOP_FILE_DELETE = 4,
NS_FOP_FILE_EXECUTE = 5,
NS_FOP_FILE_MOVE = 6,
NS_FOP_FILE_RENAME = 7,
NS_FOP_WIN_SHORTCUT = 8,
NS_FOP_MAC_ALIAS = 9,
NS_FOP_UNIX_LINK = 10,
NS_FOP_FILE_SET_STAT = 11,
NS_FOP_WIN_REGISTER_SERVER = 12
} nsInstallFileOpEnums;
#endif /* nsInstallFileOpEnums_h__ */

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

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

@ -1,178 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (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/MPL/
*
* 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.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsInstallFileOpItem_h__
#define nsInstallFileOpItem_h__
#include "prtypes.h"
#include "nsIFile.h"
#include "nsSoftwareUpdate.h"
#include "nsInstallObject.h"
#include "nsInstall.h"
class nsInstallFileOpItem : public nsInstallObject
{
public:
/* Public Fields */
enum
{
ACTION_NONE = -401,
ACTION_SUCCESS = -402,
ACTION_FAILED = -403
};
/* Public Methods */
// used by:
// FileOpFileDelete()
nsInstallFileOpItem(nsInstall* installObj,
PRInt32 aCommand,
nsIFile* aTarget,
PRInt32 aFlags,
PRInt32* aReturn);
// used by:
// FileOpDirRemove()
// FileOpFileCopy()
// FileOpFileMove()
// FileMacAlias()
nsInstallFileOpItem(nsInstall* installObj,
PRInt32 aCommand,
nsIFile* aSrc,
nsIFile* aTarget,
PRInt32* aReturn);
// used by:
// FileOpDirCreate()
nsInstallFileOpItem(nsInstall* aInstallObj,
PRInt32 aCommand,
nsIFile* aTarget,
PRInt32* aReturn);
// used by:
// FileOpDirRename()
// FileOpFileExecute()
// FileOpFileRename()
nsInstallFileOpItem(nsInstall* aInstallObj,
PRInt32 aCommand,
nsIFile* a1,
nsString& a2,
PRBool aBlocking,
PRInt32* aReturn);
// used by:
// WindowsShortcut()
nsInstallFileOpItem(nsInstall* aInstallObj,
PRInt32 aCommand,
nsIFile* aTarget,
nsIFile* aShortcutPath,
nsString& aDescription,
nsIFile* aWorkingPath,
nsString& aParams,
nsIFile* aIcon,
PRInt32 aIconId,
PRInt32* aReturn);
virtual ~nsInstallFileOpItem();
PRInt32 Prepare(void);
PRInt32 Complete();
char* toString();
void Abort();
/* should these be protected? */
PRBool CanUninstall();
PRBool RegisterPackageNode();
private:
/* Private Fields */
nsInstall* mIObj; // initiating Install object
nsCOMPtr<nsIFile> mSrc;
nsCOMPtr<nsIFile> mTarget;
nsCOMPtr<nsIFile> mShortcutPath;
nsCOMPtr<nsIFile> mWorkingPath;
nsCOMPtr<nsIFile> mIcon;
nsString mDescription;
nsString* mStrTarget;
nsString mParams;
long mFStat;
PRInt32 mFlags;
PRInt32 mIconId;
PRInt32 mCommand;
PRInt32 mAction;
PRBool mBlocking;
/* Private Methods */
PRInt32 NativeFileOpDirCreatePrepare();
PRInt32 NativeFileOpDirCreateAbort();
PRInt32 NativeFileOpDirRemovePrepare();
PRInt32 NativeFileOpDirRemoveComplete();
PRInt32 NativeFileOpDirRenamePrepare();
PRInt32 NativeFileOpDirRenameComplete();
PRInt32 NativeFileOpDirRenameAbort();
PRInt32 NativeFileOpFileCopyPrepare();
PRInt32 NativeFileOpFileCopyComplete();
PRInt32 NativeFileOpFileCopyAbort();
PRInt32 NativeFileOpFileDeletePrepare();
PRInt32 NativeFileOpFileDeleteComplete(nsIFile *aTarget);
PRInt32 NativeFileOpFileExecutePrepare();
PRInt32 NativeFileOpFileExecuteComplete();
PRInt32 NativeFileOpFileMovePrepare();
PRInt32 NativeFileOpFileMoveComplete();
PRInt32 NativeFileOpFileMoveAbort();
PRInt32 NativeFileOpFileRenamePrepare();
PRInt32 NativeFileOpFileRenameComplete();
PRInt32 NativeFileOpFileRenameAbort();
PRInt32 NativeFileOpWindowsShortcutPrepare();
PRInt32 NativeFileOpWindowsShortcutComplete();
PRInt32 NativeFileOpWindowsShortcutAbort();
PRInt32 NativeFileOpMacAliasPrepare();
PRInt32 NativeFileOpMacAliasComplete();
PRInt32 NativeFileOpMacAliasAbort();
PRInt32 NativeFileOpUnixLink();
PRInt32 NativeFileOpWindowsRegisterServerPrepare();
PRInt32 NativeFileOpWindowsRegisterServerComplete();
PRInt32 NativeFileOpWindowsRegisterServerAbort();
};
#endif /* nsInstallFileOpItem_h__ */

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

@ -1,737 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (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/MPL/
*
* 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, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Daniel Veditz <dveditz@netscape.com>
* Douglas Turner <dougt@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsInstall.h"
#include "nsInstallFolder.h"
#include "nscore.h"
#include "prtypes.h"
#include "nsIComponentManager.h"
#include "nsString.h"
#include "nsUnicharUtils.h"
#include "nsNativeCharsetUtils.h"
#include "nsXPIDLString.h"
#include "nsIFile.h"
#include "nsILocalFile.h"
#include "nsDirectoryService.h"
#include "nsDirectoryServiceDefs.h"
#include "nsAppDirectoryServiceDefs.h"
#ifdef XP_WIN
#include <stdarg.h>
#include <stdlib.h>
#include <windows.h>
#endif
struct DirectoryTable
{
const char * directoryName; /* The formal directory name */
PRInt32 folderEnum; /* Directory ID */
};
struct DirectoryTable DirectoryTable[] =
{
{"Plugins", PLUGIN_DIR },
{"Program", PROGRAM_DIR },
{"Communicator", PROGRAM_DIR }, // "Communicator" is deprecated
{"Temporary", TEMP_DIR },
{"OS Home", OS_HOME_DIR },
{"Profile", PROFILE_DIR },
{"Current User", PROFILE_DIR }, // "Current User" is deprecated
{"Preferences", PREFERENCES_DIR },
{"OS Drive", OS_DRIVE },
{"file:///", FILE_TARGET },
{"Components", COMPONENTS_DIR },
{"Chrome", CHROME_DIR },
{"Win System", WIN_SYS_DIR },
{"Windows", WINDOWS_DIR },
{"Win Desktop", WIN_DESKTOP_DIR },
{"Win Desktop Common", WIN_DESKTOP_COMMON },
{"Win StartMenu", WIN_STARTMENU },
{"Win StartMenu Common", WIN_STARTMENU_COMMON },
{"Win Programs", WIN_PROGRAMS_DIR },
{"Win Programs Common", WIN_PROGRAMS_COMMON },
{"Win Startup", WIN_STARTUP_DIR },
{"Win Startup Common", WIN_STARTUP_COMMON },
{"Win AppData", WIN_APPDATA_DIR },
{"Win Program Files", WIN_PROGRAM_FILES },
{"Win Common Files", WIN_COMMON_FILES },
{"Mac System", MAC_SYSTEM },
{"Mac Desktop", MAC_DESKTOP },
{"Mac Trash", MAC_TRASH },
{"Mac Startup", MAC_STARTUP },
{"Mac Shutdown", MAC_SHUTDOWN },
{"Mac Apple Menu", MAC_APPLE_MENU },
{"Mac Control Panel", MAC_CONTROL_PANEL },
{"Mac Extension", MAC_EXTENSION },
{"Mac Fonts", MAC_FONTS },
{"Mac Preferences", MAC_PREFERENCES },
{"Mac Documents", MAC_DOCUMENTS },
{"MacOSX Home", MACOSX_HOME },
{"MacOSX Default Download", MACOSX_DEFAULT_DOWNLOAD },
{"MacOSX User Desktop", MACOSX_USER_DESKTOP },
{"MacOSX Local Desktop", MACOSX_LOCAL_DESKTOP },
{"MacOSX User Applications", MACOSX_USER_APPLICATIONS },
{"MacOSX Local Applications", MACOSX_LOCAL_APPLICATIONS },
{"MacOSX User Documents", MACOSX_USER_DOCUMENTS },
{"MacOSX Local Documents", MACOSX_LOCAL_DOCUMENTS },
{"MacOSX User Internet PlugIn", MACOSX_USER_INTERNET_PLUGIN },
{"MacOSX Local Internet PlugIn", MACOSX_LOCAL_INTERNET_PLUGIN },
{"MacOSX User Frameworks", MACOSX_USER_FRAMEWORKS },
{"MacOSX Local Frameworks", MACOSX_LOCAL_FRAMEWORKS },
{"MacOSX User Preferences", MACOSX_USER_PREFERENCES },
{"MacOSX Local Preferences", MACOSX_LOCAL_PREFERENCES },
{"MacOSX Picture Documents", MACOSX_PICTURE_DOCUMENTS },
{"MacOSX Movie Documents", MACOSX_MOVIE_DOCUMENTS },
{"MacOSX Music Documents", MACOSX_MUSIC_DOCUMENTS },
{"MacOSX Internet Sites", MACOSX_INTERNET_SITES },
{"Unix Local", UNIX_LOCAL },
{"Unix Lib", UNIX_LIB },
{"", -1 }
};
nsInstallFolder::nsInstallFolder()
{
MOZ_COUNT_CTOR(nsInstallFolder);
}
nsresult
nsInstallFolder::Init(nsIFile* rawIFile, const nsString& aRelativePath)
{
mFileSpec = rawIFile;
if (!aRelativePath.IsEmpty())
AppendXPPath(aRelativePath);
return NS_OK;
}
nsresult
nsInstallFolder::Init(const nsAString& aFolderID, const nsString& aRelativePath)
{
SetDirectoryPath( aFolderID, aRelativePath );
if (mFileSpec)
return NS_OK;
return NS_ERROR_FAILURE;
}
nsresult
nsInstallFolder::Init(nsInstallFolder& inFolder, const nsString& subString)
{
if (!inFolder.mFileSpec)
return NS_ERROR_NULL_POINTER;
inFolder.mFileSpec->Clone(getter_AddRefs(mFileSpec));
if (!mFileSpec)
return NS_ERROR_FAILURE;
if(!subString.IsEmpty())
AppendXPPath(subString);
return NS_OK;
}
nsInstallFolder::~nsInstallFolder()
{
MOZ_COUNT_DTOR(nsInstallFolder);
}
void
nsInstallFolder::GetDirectoryPath(nsCString& aDirectoryPath)
{
PRBool flagIsDir;
nsCAutoString thePath;
aDirectoryPath.SetLength(0);
if (mFileSpec != nsnull)
{
// We want the NATIVE path.
mFileSpec->GetNativePath(thePath);
aDirectoryPath.Assign(thePath);
mFileSpec->IsDirectory(&flagIsDir);
if (flagIsDir)
{
if (aDirectoryPath.Last() != FILESEP)
aDirectoryPath.Append(FILESEP);
}
}
}
void
nsInstallFolder::SetDirectoryPath(const nsAString& aFolderID, const nsString& aRelativePath)
{
nsresult rv = NS_OK;
// reset mFileSpec in case of error
mFileSpec = nsnull;
nsCOMPtr<nsIProperties> directoryService(do_GetService(NS_DIRECTORY_SERVICE_CONTRACTID));
if (!directoryService)
return;
PRInt32 dirID = MapNameToEnum(aFolderID);
switch ( dirID )
{
case PLUGIN_DIR:
if (!nsSoftwareUpdate::GetProgramDirectory())
directoryService->Get(NS_APP_PLUGINS_DIR, NS_GET_IID(nsIFile), getter_AddRefs(mFileSpec));
else
{
rv = nsSoftwareUpdate::GetProgramDirectory()->Clone(getter_AddRefs(mFileSpec));
if (NS_SUCCEEDED(rv))
mFileSpec->AppendNative(INSTALL_PLUGINS_DIR);
else
mFileSpec = nsnull;
}
break;
case PROGRAM_DIR:
if (!nsSoftwareUpdate::GetProgramDirectory()) //Not in stub installer
directoryService->Get(NS_OS_CURRENT_PROCESS_DIR, NS_GET_IID(nsIFile), getter_AddRefs(mFileSpec));
else //In stub installer. mProgram has been set so
rv = nsSoftwareUpdate::GetProgramDirectory()->Clone(getter_AddRefs(mFileSpec));
break;
case TEMP_DIR:
directoryService->Get(NS_OS_TEMP_DIR, NS_GET_IID(nsIFile), getter_AddRefs(mFileSpec));
break;
case PROFILE_DIR:
directoryService->Get(NS_APP_USER_PROFILE_50_DIR, NS_GET_IID(nsIFile), getter_AddRefs(mFileSpec));
break;
case OS_HOME_DIR:
directoryService->Get(NS_OS_HOME_DIR, NS_GET_IID(nsIFile), getter_AddRefs(mFileSpec));
break;
case PREFERENCES_DIR:
directoryService->Get(NS_APP_PREFS_50_DIR, NS_GET_IID(nsIFile), getter_AddRefs(mFileSpec));
break;
case OS_DRIVE:
directoryService->Get(NS_OS_DRIVE_DIR, NS_GET_IID(nsIFile), getter_AddRefs(mFileSpec));
break;
case FILE_TARGET:
{
if (!aRelativePath.IsEmpty())
{
nsCAutoString nativePath;
nsCOMPtr<nsILocalFile> localFile;
NS_CopyUnicodeToNative(aRelativePath, nativePath);
rv = NS_NewNativeLocalFile(nativePath, PR_TRUE, getter_AddRefs(localFile));
if (rv == NS_ERROR_FILE_UNRECOGNIZED_PATH) {
// we need to convert this relative path to absolute
directoryService->Get(NS_OS_CURRENT_PROCESS_DIR, NS_GET_IID(nsILocalFile), getter_AddRefs(localFile));
if (localFile)
rv = localFile->AppendRelativeNativePath(nativePath);
}
if (NS_SUCCEEDED(rv)) {
mFileSpec = do_QueryInterface(localFile);
}
}
// file:// is a special case where it returns and does not
// go to the standard relative path code below.
return;
}
break;
case COMPONENTS_DIR:
if (!nsSoftwareUpdate::GetProgramDirectory())
{
directoryService->Get(NS_XPCOM_COMPONENT_DIR,
NS_GET_IID(nsIFile),
getter_AddRefs(mFileSpec));
}
else
{
rv = nsSoftwareUpdate::GetProgramDirectory()->Clone(getter_AddRefs(mFileSpec));
if (NS_SUCCEEDED(rv))
mFileSpec->AppendNative(INSTALL_COMPONENTS_DIR);
else
mFileSpec = nsnull;
}
break;
case CHROME_DIR:
if (!nsSoftwareUpdate::GetProgramDirectory())
{
directoryService->Get(NS_APP_CHROME_DIR,
NS_GET_IID(nsIFile),
getter_AddRefs(mFileSpec));
}
else
{
rv = nsSoftwareUpdate::GetProgramDirectory()->Clone(getter_AddRefs(mFileSpec));
if (NS_SUCCEEDED(rv))
mFileSpec->AppendNative(INSTALL_CHROME_DIR);
}
break;
#if defined(XP_WIN)
case WIN_SYS_DIR:
directoryService->Get(NS_OS_SYSTEM_DIR,
NS_GET_IID(nsIFile),
getter_AddRefs(mFileSpec));
break;
case WINDOWS_DIR:
directoryService->Get(NS_WIN_WINDOWS_DIR,
NS_GET_IID(nsIFile),
getter_AddRefs(mFileSpec));
break;
case WIN_DESKTOP_DIR:
directoryService->Get( NS_WIN_DESKTOP_DIRECTORY,
NS_GET_IID(nsIFile),
getter_AddRefs(mFileSpec) );
break;
case WIN_DESKTOP_COMMON:
directoryService->Get( NS_WIN_COMMON_DESKTOP_DIRECTORY,
NS_GET_IID(nsIFile),
getter_AddRefs(mFileSpec) );
break;
case WIN_STARTMENU:
directoryService->Get( NS_WIN_STARTMENU_DIR,
NS_GET_IID(nsIFile),
getter_AddRefs(mFileSpec) );
break;
case WIN_STARTMENU_COMMON:
directoryService->Get( NS_WIN_COMMON_STARTMENU_DIR,
NS_GET_IID(nsIFile),
getter_AddRefs(mFileSpec) );
break;
case WIN_PROGRAMS_DIR:
directoryService->Get( NS_WIN_PROGRAMS_DIR,
NS_GET_IID(nsIFile),
getter_AddRefs(mFileSpec) );
break;
case WIN_PROGRAMS_COMMON:
directoryService->Get( NS_WIN_COMMON_PROGRAMS_DIR,
NS_GET_IID(nsIFile),
getter_AddRefs(mFileSpec) );
break;
case WIN_STARTUP_DIR:
directoryService->Get( NS_WIN_STARTUP_DIR,
NS_GET_IID(nsIFile),
getter_AddRefs(mFileSpec) );
break;
case WIN_STARTUP_COMMON:
directoryService->Get( NS_WIN_COMMON_STARTUP_DIR,
NS_GET_IID(nsIFile),
getter_AddRefs(mFileSpec) );
break;
case WIN_APPDATA_DIR:
directoryService->Get( NS_WIN_APPDATA_DIR,
NS_GET_IID(nsIFile),
getter_AddRefs(mFileSpec) );
break;
case WIN_PROGRAM_FILES:
case WIN_COMMON_FILES:
{
HKEY key;
LONG result = RegOpenKeyEx( HKEY_LOCAL_MACHINE,
"SOFTWARE\\Microsoft\\Windows\\CurrentVersion",
0, KEY_QUERY_VALUE, &key );
if ( result != ERROR_SUCCESS )
break;
BYTE path[_MAX_PATH + 1] = { 0 };
DWORD type;
DWORD pathlen = sizeof(path);
const char *value = (dirID==WIN_PROGRAM_FILES) ?
"ProgramFilesDir" :
"CommonFilesDir";
result = RegQueryValueEx( key, value, 0, &type, path, &pathlen );
if ( result == ERROR_SUCCESS && type == REG_SZ )
{
nsCOMPtr<nsILocalFile> tmp;
NS_NewNativeLocalFile( nsDependentCString((char*)path),
PR_FALSE, getter_AddRefs(tmp) );
mFileSpec = do_QueryInterface(tmp);
}
}
break;
#endif
#if defined (XP_MACOSX)
case MAC_SYSTEM:
directoryService->Get(NS_OS_SYSTEM_DIR,
NS_GET_IID(nsIFile),
getter_AddRefs(mFileSpec));
break;
case MAC_DESKTOP:
directoryService->Get(NS_MAC_DESKTOP_DIR,
NS_GET_IID(nsIFile),
getter_AddRefs(mFileSpec));
break;
case MAC_TRASH:
directoryService->Get(NS_MAC_TRASH_DIR,
NS_GET_IID(nsIFile),
getter_AddRefs(mFileSpec));
break;
case MAC_STARTUP:
directoryService->Get(NS_MAC_STARTUP_DIR,
NS_GET_IID(nsIFile),
getter_AddRefs(mFileSpec));
break;
case MAC_SHUTDOWN:
directoryService->Get(NS_MAC_SHUTDOWN_DIR,
NS_GET_IID(nsIFile),
getter_AddRefs(mFileSpec));
break;
case MAC_APPLE_MENU:
directoryService->Get(NS_MAC_APPLE_MENU_DIR,
NS_GET_IID(nsIFile),
getter_AddRefs(mFileSpec));
break;
case MAC_CONTROL_PANEL:
directoryService->Get(NS_MAC_CONTROL_PANELS_DIR,
NS_GET_IID(nsIFile),
getter_AddRefs(mFileSpec));
break;
case MAC_EXTENSION:
directoryService->Get(NS_MAC_EXTENSIONS_DIR,
NS_GET_IID(nsIFile),
getter_AddRefs(mFileSpec));
break;
case MAC_FONTS:
directoryService->Get(NS_MAC_FONTS_DIR,
NS_GET_IID(nsIFile),
getter_AddRefs(mFileSpec));
break;
case MAC_PREFERENCES:
directoryService->Get(NS_MAC_PREFS_DIR,
NS_GET_IID(nsIFile),
getter_AddRefs(mFileSpec));
break;
case MAC_DOCUMENTS:
directoryService->Get(NS_MAC_DOCUMENTS_DIR,
NS_GET_IID(nsIFile),
getter_AddRefs(mFileSpec));
break;
case MACOSX_HOME:
directoryService->Get(NS_OSX_HOME_DIR,
NS_GET_IID(nsIFile),
getter_AddRefs(mFileSpec));
break;
case MACOSX_DEFAULT_DOWNLOAD:
directoryService->Get(NS_OSX_DEFAULT_DOWNLOAD_DIR,
NS_GET_IID(nsIFile),
getter_AddRefs(mFileSpec));
break;
case MACOSX_USER_DESKTOP:
directoryService->Get(NS_OSX_USER_DESKTOP_DIR,
NS_GET_IID(nsIFile),
getter_AddRefs(mFileSpec));
break;
case MACOSX_LOCAL_DESKTOP:
directoryService->Get(NS_OSX_LOCAL_DESKTOP_DIR,
NS_GET_IID(nsIFile),
getter_AddRefs(mFileSpec));
break;
case MACOSX_USER_APPLICATIONS:
directoryService->Get(NS_OSX_USER_APPLICATIONS_DIR,
NS_GET_IID(nsIFile),
getter_AddRefs(mFileSpec));
break;
case MACOSX_LOCAL_APPLICATIONS:
directoryService->Get(NS_OSX_LOCAL_APPLICATIONS_DIR,
NS_GET_IID(nsIFile),
getter_AddRefs(mFileSpec));
break;
case MACOSX_USER_DOCUMENTS:
directoryService->Get(NS_OSX_USER_DOCUMENTS_DIR,
NS_GET_IID(nsIFile),
getter_AddRefs(mFileSpec));
break;
case MACOSX_LOCAL_DOCUMENTS:
directoryService->Get(NS_OSX_LOCAL_DOCUMENTS_DIR,
NS_GET_IID(nsIFile),
getter_AddRefs(mFileSpec));
break;
case MACOSX_USER_INTERNET_PLUGIN:
directoryService->Get(NS_OSX_USER_INTERNET_PLUGIN_DIR,
NS_GET_IID(nsIFile),
getter_AddRefs(mFileSpec));
break;
case MACOSX_LOCAL_INTERNET_PLUGIN:
directoryService->Get(NS_OSX_LOCAL_INTERNET_PLUGIN_DIR,
NS_GET_IID(nsIFile),
getter_AddRefs(mFileSpec));
break;
case MACOSX_USER_FRAMEWORKS:
directoryService->Get(NS_OSX_USER_FRAMEWORKS_DIR,
NS_GET_IID(nsIFile),
getter_AddRefs(mFileSpec));
break;
case MACOSX_LOCAL_FRAMEWORKS:
directoryService->Get(NS_OSX_LOCAL_FRAMEWORKS_DIR,
NS_GET_IID(nsIFile),
getter_AddRefs(mFileSpec));
break;
case MACOSX_USER_PREFERENCES:
directoryService->Get(NS_OSX_USER_PREFERENCES_DIR,
NS_GET_IID(nsIFile),
getter_AddRefs(mFileSpec));
break;
case MACOSX_LOCAL_PREFERENCES:
directoryService->Get(NS_OSX_LOCAL_PREFERENCES_DIR,
NS_GET_IID(nsIFile),
getter_AddRefs(mFileSpec));
break;
case MACOSX_PICTURE_DOCUMENTS:
directoryService->Get(NS_OSX_PICTURE_DOCUMENTS_DIR,
NS_GET_IID(nsIFile),
getter_AddRefs(mFileSpec));
break;
case MACOSX_MOVIE_DOCUMENTS:
directoryService->Get(NS_OSX_MOVIE_DOCUMENTS_DIR,
NS_GET_IID(nsIFile),
getter_AddRefs(mFileSpec));
break;
case MACOSX_MUSIC_DOCUMENTS:
directoryService->Get(NS_OSX_MUSIC_DOCUMENTS_DIR,
NS_GET_IID(nsIFile),
getter_AddRefs(mFileSpec));
break;
case MACOSX_INTERNET_SITES:
directoryService->Get(NS_OSX_INTERNET_SITES_DIR,
NS_GET_IID(nsIFile),
getter_AddRefs(mFileSpec));
break;
#endif
#if defined(XP_UNIX) && !defined(XP_MACOSX)
case UNIX_LOCAL:
directoryService->Get(NS_UNIX_LOCAL_DIR,
NS_GET_IID(nsIFile),
getter_AddRefs(mFileSpec));
break;
case UNIX_LIB:
directoryService->Get(NS_UNIX_LIB_DIR,
NS_GET_IID(nsIFile),
getter_AddRefs(mFileSpec));
break;
#endif
case -1:
default:
mFileSpec = nsnull;
break;
}
if (mFileSpec && !aRelativePath.IsEmpty())
{
AppendXPPath(aRelativePath);
}
}
void
nsInstallFolder::AppendXPPath(const nsString& aRelativePath)
{
nsAutoString segment;
PRUint32 start = 0;
PRUint32 curr;
NS_ASSERTION(!aRelativePath.IsEmpty(),"InstallFolder appending null path");
do {
curr = aRelativePath.FindChar('/',start);
if ( curr == start )
{
// illegal, two slashes in a row (or not a relative path)
mFileSpec = nsnull;
break;
}
else if ( curr == PRUint32(kNotFound) )
{
// last segment
aRelativePath.Right(segment,aRelativePath.Length() - start);
start = aRelativePath.Length();
}
else
{
// found a segment
aRelativePath.Mid(segment,start,curr-start);
start = curr+1;
}
nsresult rv = mFileSpec->Append(segment);
if (NS_FAILED(rv))
{
// Unicode converters not present (likely wizard case)
// so do our best with the vanilla conversion.
mFileSpec->AppendNative(NS_LossyConvertUTF16toASCII(segment));
}
} while ( start < aRelativePath.Length() );
}
/* MapNameToEnum
* maps name from the directory table to its enum */
PRInt32
nsInstallFolder::MapNameToEnum(const nsAString& name)
{
int i = 0;
if ( name.IsEmpty())
return -1;
while ( DirectoryTable[i].directoryName[0] != 0 )
{
// safe compare because all strings in DirectoryTable are ASCII
if ( name.Equals(NS_ConvertASCIItoUTF16(DirectoryTable[i].directoryName), nsCaseInsensitiveStringComparator()) )
return DirectoryTable[i].folderEnum;
i++;
}
return -1;
}
nsIFile*
nsInstallFolder::GetFileSpec()
{
return mFileSpec;
}
PRInt32
nsInstallFolder::ToString(nsAutoString* outString)
{
//XXX: May need to fix. Native charset paths will be converted into Unicode when the get to JS
// This will appear to work on Latin-1 charsets but won't work on Mac or other charsets.
// On the other hand doing it right requires intl charset converters
// which we don't yet have in the initial install case.
//
// However, nsLocalFile now uses the native charset conversion implementation, so this
// code should always work.
if (!mFileSpec || !outString)
return NS_ERROR_NULL_POINTER;
nsresult rv = mFileSpec->GetPath(*outString);
if (NS_FAILED(rv))
{
// converters not present, most likely in wizard case;
// do best we can with stock ASCII conversion
// Since bug 100676 was fixed we should never get here
// XXX NOTE we can make sure our filenames are ASCII, but we have no
// control over the directory name which might be localized!!!
NS_ASSERTION(PR_FALSE, "Couldn't get Unicode path, using broken conversion!");
nsCAutoString temp;
rv = mFileSpec->GetNativePath(temp);
CopyASCIItoUTF16(temp, *outString);
}
PRBool flagIsFile = PR_FALSE;
mFileSpec->IsFile(&flagIsFile);
if (!flagIsFile)
{
// assume directory, thus end with slash.
outString->Append(PRUnichar(FILESEP));
}
return rv;
}

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

@ -1,146 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (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/MPL/
*
* 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, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Daniel Veditz <dveditz@netscape.com>
* Douglas Turner <dougt@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef __NS_INSTALLFOLDER_H__
#define __NS_INSTALLFOLDER_H__
#include "nscore.h"
#include "prtypes.h"
#include "nsString.h"
#define PLUGIN_DIR 100
#define PROGRAM_DIR 101
#define TEMP_DIR 104
#define OS_HOME_DIR 105
#define PROFILE_DIR 106
#define PREFERENCES_DIR 107
#define OS_DRIVE 108
#define FILE_TARGET 109
#define COMPONENTS_DIR 110
#define CHROME_DIR 111
#define WIN_SYS_DIR 200
#define WINDOWS_DIR 201
#define WIN_DESKTOP_DIR 202
#define WIN_DESKTOP_COMMON 203
#define WIN_STARTMENU 204
#define WIN_STARTMENU_COMMON 205
#define WIN_PROGRAMS_DIR 206
#define WIN_PROGRAMS_COMMON 207
#define WIN_STARTUP_DIR 208
#define WIN_STARTUP_COMMON 209
#define WIN_APPDATA_DIR 210
#define WIN_PROGRAM_FILES 211
#define WIN_COMMON_FILES 212
#define MAC_SYSTEM 300
#define MAC_DESKTOP 301
#define MAC_TRASH 302
#define MAC_STARTUP 303
#define MAC_SHUTDOWN 304
#define MAC_APPLE_MENU 305
#define MAC_CONTROL_PANEL 306
#define MAC_EXTENSION 307
#define MAC_FONTS 308
#define MAC_PREFERENCES 309
#define MAC_DOCUMENTS 310
#define MACOSX_HOME 500
#define MACOSX_DEFAULT_DOWNLOAD 501
#define MACOSX_USER_DESKTOP 502
#define MACOSX_LOCAL_DESKTOP 503
#define MACOSX_USER_APPLICATIONS 504
#define MACOSX_LOCAL_APPLICATIONS 505
#define MACOSX_USER_DOCUMENTS 506
#define MACOSX_LOCAL_DOCUMENTS 507
#define MACOSX_USER_INTERNET_PLUGIN 508
#define MACOSX_LOCAL_INTERNET_PLUGIN 509
#define MACOSX_USER_FRAMEWORKS 510
#define MACOSX_LOCAL_FRAMEWORKS 511
#define MACOSX_USER_PREFERENCES 512
#define MACOSX_LOCAL_PREFERENCES 513
#define MACOSX_PICTURE_DOCUMENTS 514
#define MACOSX_MOVIE_DOCUMENTS 515
#define MACOSX_MUSIC_DOCUMENTS 516
#define MACOSX_INTERNET_SITES 517
#define UNIX_LOCAL 400
#define UNIX_LIB 401
#ifdef XP_MAC
#define INSTALL_PLUGINS_DIR NS_LITERAL_CSTRING("Plug-ins")
#define INSTALL_COMPONENTS_DIR NS_LITERAL_CSTRING("Components")
#define INSTALL_CHROME_DIR NS_LITERAL_CSTRING("Chrome")
#else
#define INSTALL_PLUGINS_DIR NS_LITERAL_CSTRING("plugins")
#define INSTALL_COMPONENTS_DIR NS_LITERAL_CSTRING("components")
#define INSTALL_CHROME_DIR NS_LITERAL_CSTRING("chrome")
#endif
class nsInstallFolder
{
public:
nsInstallFolder();
virtual ~nsInstallFolder();
nsresult Init(nsInstallFolder& inFolder, const nsString& subString);
nsresult Init(const nsAString& aFolderID, const nsString& aRelativePath);
nsresult Init(nsIFile* rawIFile, const nsString& aRelativePath);
void GetDirectoryPath(nsCString& aDirectoryPath);
nsIFile* GetFileSpec();
PRInt32 ToString(nsAutoString* outString);
private:
nsCOMPtr<nsIFile> mFileSpec;
void SetDirectoryPath(const nsAString& aFolderID, const nsString& aRelativePath);
void AppendXPPath(const nsString& aRelativePath);
PRInt32 MapNameToEnum(const nsAString& name);
};
#endif

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

@ -1,132 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (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/MPL/
*
* 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, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Daniel Veditz <dveditz@netscape.com>
* Douglas Turner <dougt@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsCRT.h"
#include "prmem.h"
#include "prprf.h"
#include "VerReg.h"
#include "ScheduledTasks.h"
#include "nsInstallLogComment.h"
#include "nsInstallResources.h"
#include "nsInstall.h"
#include "nsIDOMInstallVersion.h"
#include "nsNativeCharsetUtils.h"
nsInstallLogComment::nsInstallLogComment( nsInstall* inInstall,
const nsAString& inFileOpCommand,
const nsAString& inComment,
PRInt32 *error)
: nsInstallObject(inInstall)
{
MOZ_COUNT_CTOR(nsInstallLogComment);
*error = nsInstall::SUCCESS;
if (inInstall == NULL)
{
*error = nsInstall::INVALID_ARGUMENTS;
return;
}
mFileOpCommand = inFileOpCommand;
mComment = inComment;
}
nsInstallLogComment::~nsInstallLogComment()
{
MOZ_COUNT_DTOR(nsInstallLogComment);
}
PRInt32 nsInstallLogComment::Prepare()
{
// no set-up necessary
return nsInstall::SUCCESS;
}
PRInt32 nsInstallLogComment::Complete()
{
// nothing to complete
return nsInstall::SUCCESS;
}
void nsInstallLogComment::Abort()
{
}
char* nsInstallLogComment::toString()
{
if (!mInstall)
return nsnull;
char* buffer = new char[1024];
char* rsrcVal = nsnull;
if (!buffer)
return nsnull;
rsrcVal = mInstall->GetResourcedString(mFileOpCommand);
if (rsrcVal)
{
nsCAutoString comment;
if ( NS_SUCCEEDED( NS_CopyUnicodeToNative(mComment, comment) ) )
PR_snprintf(buffer, 1024, rsrcVal, comment.get());
nsCRT::free(rsrcVal);
}
return buffer;
}
PRBool
nsInstallLogComment::CanUninstall()
{
return PR_FALSE;
}
PRBool
nsInstallLogComment::RegisterPackageNode()
{
return PR_FALSE;
}

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

@ -1,77 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (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/MPL/
*
* 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, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Daniel Veditz <dveditz@netscape.com>
* Douglas Turner <dougt@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsInstallLogComment_h__
#define nsInstallLogComment_h__
#include "prtypes.h"
#include "nsString.h"
#include "nsInstallObject.h"
#include "nsInstall.h"
class nsInstallLogComment : public nsInstallObject
{
public:
nsInstallLogComment(nsInstall* inInstall,
const nsAString&,
const nsAString&,
PRInt32 *error);
virtual ~nsInstallLogComment();
PRInt32 Prepare();
PRInt32 Complete();
void Abort();
char* toString();
PRBool CanUninstall();
PRBool RegisterPackageNode();
private:
/* Private Fields */
nsString mFileOpCommand;
nsString mComment;
};
#endif /* nsInstallLogComment_h__ */

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

@ -1,72 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (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/MPL/
*
* 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.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsInstallObject_h__
#define nsInstallObject_h__
#include "prtypes.h"
class nsInstall;
class nsInstallObject
{
public:
/* Public Methods */
nsInstallObject(nsInstall* inInstall) {mInstall = inInstall; }
virtual ~nsInstallObject() {}
/* Override with your set-up action */
virtual PRInt32 Prepare() = 0;
/* Override with your Completion action */
virtual PRInt32 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:
nsInstall* mInstall;
};
#endif /* nsInstallObject_h__ */

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

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

@ -1,98 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (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/MPL/
*
* 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.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsInstallPatch_h__
#define nsInstallPatch_h__
#include "prtypes.h"
#include "nsString.h"
#include "nsInstallObject.h"
#include "nsInstall.h"
#include "nsInstallFolder.h"
#include "nsInstallVersion.h"
class nsInstallPatch : public nsInstallObject
{
public:
nsInstallPatch( nsInstall* inInstall,
const nsString& inVRName,
const nsString& inVInfo,
const nsString& inJarLocation,
nsInstallFolder* folderSpec,
const nsString& inPartialPath,
PRInt32 *error);
nsInstallPatch( nsInstall* inInstall,
const nsString& inVRName,
const nsString& inVInfo,
const nsString& inJarLocation,
PRInt32 *error);
virtual ~nsInstallPatch();
PRInt32 Prepare();
PRInt32 Complete();
void Abort();
char* toString();
PRBool CanUninstall();
PRBool RegisterPackageNode();
private:
nsInstallVersion *mVersionInfo;
nsCOMPtr<nsIFile> mTargetFile;
nsCOMPtr<nsIFile> mPatchFile;
nsCOMPtr<nsIFile> mPatchedFile;
nsString *mJarLocation;
nsString *mRegistryName;
PRInt32 NativePatch(nsIFile *sourceFile, nsIFile *patchfile, nsIFile **newFile);
void* HashFilePath(nsIFile* aPath);
};
#endif /* nsInstallPatch_h__ */

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

@ -1,114 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (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/MPL/
*
* 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, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Daniel Veditz <dveditz@netscape.com>
* Douglas Turner <dougt@netscape.com>
* Samir Gehani <sgehani@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include <string.h>
#include "nscore.h"
#include "nsInstallResources.h"
static nsXPIResourceTableItem XPIResTable[] =
{
/*---------------------------------------------------------------------*
* Install Actions
*---------------------------------------------------------------------*/
{ "InstallFile", "Installing: %s" },
{ "InstallSharedFile", "Installing Shared File: %s" },
{ "ReplaceFile", "Replacing: %s" },
{ "ReplaceSharedFile", "Replacing Shared File: %s" },
{ "SkipFile", "Skipping: %s" },
{ "SkipSharedFile", "Skipping Shared File: %s" },
{ "DeleteFile", "Deleting file: %s" },
{ "DeleteComponent", "Deleting component: %s" },
{ "Execute", "Executing: %s" },
{ "ExecuteWithArgs", "Executing: %s with argument: %s" },
{ "Patch", "Patching: %s" },
{ "Uninstall", "Uninstalling: %s" },
{ "RegSkin", "Register Skin: %s" },
{ "RegLocale", "Register Locale: %s" },
{ "RegContent", "Register Content: %s" },
{ "RegPackage", "Register Package: %s" },
{ "CopyFile", "Copy File: %s to %s" },
{ "ExecuteFile", "Execute File: %s" },
{ "ExecuteFileWithArgs", "Execute File: %s with argument: %s" },
{ "MoveFile", "Move File: %s to %s" },
{ "RenameFile", "Rename File: %s to %s" },
{ "CreateFolder", "Create Folder: %s" },
{ "RemoveFolder", "Remove Folder: %s" },
{ "RenameFolder", "Rename Folder: %s to %s" },
{ "WindowsShortcut", "Windows Shortcut: %s" },
{ "MacAlias", "Mac Alias: %s" },
{ "WindowsRegisterServer", "Windows Register Server: %s" },
{ "UnknownFileOpCommand", "Unknown file operation command!" },
// XXX FileOp*() action strings
// XXX WinReg and WinProfile action strings
/*---------------------------------------------------------------------*
* Miscellaneous
*---------------------------------------------------------------------*/
{ "ERROR", "ERROR" },
{ NS_XPI_EOT, "" }
};
char*
nsInstallResources::GetDefaultVal(const char* aResName)
{
char *currResName = XPIResTable[0].resName;
char *currResVal = nsnull;
PRInt32 idx, len = 0;
for (idx = 0; 0 != strcmp(currResName, NS_XPI_EOT); idx++)
{
currResName = XPIResTable[idx].resName;
len = strlen(currResName);
if (0 == strncmp(currResName, aResName, len))
{
currResVal = XPIResTable[idx].defaultString;
break;
}
}
return currResVal;
}

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

@ -1,63 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (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/MPL/
*
* 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, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Daniel Veditz <dveditz@netscape.com>
* Douglas Turner <dougt@netscape.com>
* Samir Gehani <sgehani@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef __NS_INSTALLRESOURCES_H__
#define __NS_INSTALLRESOURCES_H__
#define NS_XPI_EOT "___END_OF_TABLE___"
typedef struct _nsXPIResourceTableItem
{
char *resName;
char *defaultString;
} nsXPIResourceTableItem;
class nsInstallResources
{
public:
static char* GetDefaultVal(const char* aResName);
};
#endif

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

@ -20,6 +20,7 @@
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Dave Townsend <dtownsend@oxymoronical.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
@ -36,10 +37,8 @@
* ***** END LICENSE BLOCK ***** */
#include "nsSoftwareUpdate.h"
#include "nsXPInstallManager.h"
#include "nsInstallTrigger.h"
#include "nsInstallVersion.h"
#include "nsIDOMInstallTriggerGlobal.h"
#include "nscore.h"
@ -65,8 +64,6 @@
#include "nsIComponentManager.h"
#include "nsIServiceManager.h"
#include "VerReg.h"
#include "nsIContentHandler.h"
#include "nsIChannel.h"
#include "nsIURI.h"
@ -76,9 +73,6 @@
nsInstallTrigger::nsInstallTrigger()
{
mScriptObject = nsnull;
// make sure all the SoftwareUpdate initialization has happened
nsCOMPtr<nsISoftwareUpdate> svc (do_GetService(NS_IXPINSTALLCOMPONENT_CONTRACTID));
}
nsInstallTrigger::~nsInstallTrigger()
@ -183,7 +177,7 @@ nsInstallTrigger::HandleContent(const char * aContentType,
// Get the global object of the target window for StartSoftwareUpdate
nsCOMPtr<nsIScriptGlobalObjectOwner> globalObjectOwner =
nsCOMPtr<nsIScriptGlobalObjectOwner> globalObjectOwner =
do_QueryInterface(aWindowContext);
nsIScriptGlobalObject* globalObject =
globalObjectOwner ? globalObjectOwner->GetScriptGlobalObject() : nsnull;
@ -202,7 +196,7 @@ nsInstallTrigger::HandleContent(const char * aContentType,
// they trust the actual source when they get the install confirmation
// dialog. The decision we're making here is whether the triggering
// site is one which is allowed to annoy the user with modal dialogs.
checkuri = referringURI;
}
else
@ -391,7 +385,7 @@ nsInstallTrigger::GetOriginatingURI(nsIScriptGlobalObject* aGlobalObject, nsIURI
NS_ENSURE_ARG_POINTER(aGlobalObject);
*aUri = nsnull;
// find the current site
nsCOMPtr<nsIDOMDocument> domdoc;
nsCOMPtr<nsIDOMWindow> window(do_QueryInterface(aGlobalObject));
@ -441,7 +435,7 @@ nsInstallTrigger::StartInstall(nsIXPIInstallInfo* aInstallInfo, PRBool* aReturn)
{
if (aReturn)
*aReturn = PR_FALSE;
nsXPInstallManager *mgr = new nsXPInstallManager();
if (mgr)
{
@ -455,187 +449,3 @@ nsInstallTrigger::StartInstall(nsIXPIInstallInfo* aInstallInfo, PRBool* aReturn)
return NS_ERROR_OUT_OF_MEMORY;
}
}
NS_IMETHODIMP
nsInstallTrigger::Install(nsIScriptGlobalObject* aGlobalObject, nsXPITriggerInfo* aTrigger, PRBool* aReturn)
{
NS_ASSERTION(aReturn, "Invalid pointer arg");
*aReturn = PR_FALSE;
nsresult rv;
nsXPInstallManager *mgr = new nsXPInstallManager();
if (mgr)
{
nsCOMPtr<nsIDOMWindowInternal> win(do_QueryInterface(aGlobalObject));
// The Install manager will delete itself when done
rv = mgr->InitManager( win, aTrigger, 0 );
if (NS_SUCCEEDED(rv))
*aReturn = PR_TRUE;
}
else
{
delete aTrigger;
rv = NS_ERROR_OUT_OF_MEMORY;
}
return rv;
}
NS_IMETHODIMP
nsInstallTrigger::InstallChrome(nsIScriptGlobalObject* aGlobalObject, PRUint32 aType, nsXPITriggerItem *aItem, PRBool* aReturn)
{
NS_ENSURE_ARG_POINTER(aReturn);
NS_ENSURE_ARG_POINTER(aItem);
*aReturn = PR_FALSE;
// The Install manager will delete itself when done, once we've called
// InitManager. Before then **WE** must delete it
nsresult rv = NS_ERROR_OUT_OF_MEMORY;
nsXPInstallManager *mgr = new nsXPInstallManager();
if (mgr)
{
nsXPITriggerInfo* trigger = new nsXPITriggerInfo();
if ( trigger )
{
trigger->Add( aItem );
nsCOMPtr<nsIDOMWindowInternal> win(do_QueryInterface(aGlobalObject));
// The Install manager will delete itself when done
rv = mgr->InitManager( win, trigger, aType );
*aReturn = PR_TRUE;
}
else
{
rv = NS_ERROR_OUT_OF_MEMORY;
delete mgr;
delete aItem;
}
}
else
{
delete aItem;
}
return NS_OK;
}
NS_IMETHODIMP
nsInstallTrigger::StartSoftwareUpdate(nsIScriptGlobalObject* aGlobalObject, const nsString& aURL, PRInt32 aFlags, PRBool* aReturn)
{
nsresult rv = NS_ERROR_OUT_OF_MEMORY;
*aReturn = PR_FALSE;
// The Install manager will delete itself when done, once we've called
// InitManager. Before then **WE** must delete it
nsXPInstallManager *mgr = new nsXPInstallManager();
if (mgr)
{
nsXPITriggerInfo* trigger = new nsXPITriggerInfo();
if ( trigger )
{
nsXPITriggerItem* item = new nsXPITriggerItem(0,aURL.get(),nsnull);
if (item)
{
trigger->Add( item );
nsCOMPtr<nsIDOMWindowInternal> win(do_QueryInterface(aGlobalObject));
// The Install manager will delete itself when done
rv = mgr->InitManager(win, trigger, 0 );
*aReturn = PR_TRUE;
}
else
{
rv = NS_ERROR_OUT_OF_MEMORY;
delete trigger;
delete mgr;
}
}
else
{
rv = NS_ERROR_OUT_OF_MEMORY;
delete mgr;
}
}
return rv;
}
NS_IMETHODIMP
nsInstallTrigger::CompareVersion(const nsString& aRegName, PRInt32 aMajor, PRInt32 aMinor, PRInt32 aRelease, PRInt32 aBuild, PRInt32* aReturn)
{
nsInstallVersion inVersion;
inVersion.Init(aMajor, aMinor, aRelease, aBuild);
return CompareVersion(aRegName, &inVersion, aReturn);
}
NS_IMETHODIMP
nsInstallTrigger::CompareVersion(const nsString& aRegName, const nsString& aVersion, PRInt32* aReturn)
{
nsInstallVersion inVersion;
inVersion.Init(aVersion);
return CompareVersion(aRegName, &inVersion, aReturn);
}
NS_IMETHODIMP
nsInstallTrigger::CompareVersion(const nsString& aRegName, nsIDOMInstallVersion* aVersion, PRInt32* aReturn)
{
*aReturn = NOT_FOUND; // assume failure.
VERSION cVersion;
NS_ConvertUTF16toUTF8 regName(aRegName);
REGERR status;
nsInstallVersion regNameVersion;
status = VR_GetVersion( const_cast<char *>(regName.get()), &cVersion );
if ( status == REGERR_OK )
{
// we found the version
if ( VR_ValidateComponent( const_cast<char *>(regName.get()) ) != REGERR_NOFILE )
{
// and the installed file was not missing: do the compare
regNameVersion.Init(cVersion.major,
cVersion.minor,
cVersion.release,
cVersion.build);
regNameVersion.CompareTo( aVersion, aReturn );
}
}
return NS_OK;
}
NS_IMETHODIMP
nsInstallTrigger::GetVersion(const nsString& component, nsString& version)
{
VERSION cVersion;
NS_ConvertUTF16toUTF8 regName(component);
REGERR status;
status = VR_GetVersion( const_cast<char *>(regName.get()), &cVersion );
version.Truncate();
/* if we got the version */
// XXX fix the right way after PR3 or RTM
// if ( status == REGERR_OK && VR_ValidateComponent( tempCString ) == REGERR_OK)
if ( status == REGERR_OK )
{
nsInstallVersion regNameVersion;
regNameVersion.Init(cVersion.major,
cVersion.minor,
cVersion.release,
cVersion.build);
regNameVersion.ToString(version);
}
return NS_OK;
}

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

@ -11,7 +11,6 @@
#include "nsHashtable.h"
#include "nsIDOMInstallTriggerGlobal.h"
#include "nsSoftwareUpdate.h"
#include "nsXPITriggerInfo.h"
#include "nsIContentHandler.h"
@ -31,13 +30,17 @@
#define XPI_WHITELIST PR_TRUE
#define XPI_GLOBAL PR_FALSE
#define XPINSTALL_ENABLE_PREF "xpinstall.enabled"
#define XPINSTALL_WHITELIST_ADD "xpinstall.whitelist.add"
#define XPINSTALL_WHITELIST_ADD_103 "xpinstall.whitelist.add.103"
#define XPINSTALL_WHITELIST_REQUIRED "xpinstall.whitelist.required"
#define XPINSTALL_BLACKLIST_ADD "xpinstall.blacklist.add"
class nsInstallTrigger: public nsIScriptObjectOwner,
public nsIDOMInstallTriggerGlobal,
public nsIContentHandler
{
public:
static const nsIID& IID() { static nsIID iid = NS_SoftwareUpdateInstallTrigger_CID; return iid; }
nsInstallTrigger();
virtual ~nsInstallTrigger();
@ -51,13 +54,6 @@ class nsInstallTrigger: public nsIScriptObjectOwner,
NS_IMETHOD UpdateEnabled(nsIScriptGlobalObject* aGlobalObject, PRBool aUseWhitelist, PRBool* aReturn);
NS_IMETHOD UpdateEnabled(nsIURI* aURI, PRBool aUseWhitelist, PRBool* aReturn);
NS_IMETHOD StartInstall(nsIXPIInstallInfo* aInstallInfo, PRBool* aReturn);
NS_IMETHOD Install(nsIScriptGlobalObject* aGlobalObject, nsXPITriggerInfo *aInfo, PRBool* aReturn);
NS_IMETHOD InstallChrome(nsIScriptGlobalObject* aGlobalObject, PRUint32 aType, nsXPITriggerItem* aItem, PRBool* aReturn);
NS_IMETHOD StartSoftwareUpdate(nsIScriptGlobalObject* aGlobalObject, const nsString& aURL, PRInt32 aFlags, PRInt32* aReturn);
NS_IMETHOD CompareVersion(const nsString& aRegName, PRInt32 aMajor, PRInt32 aMinor, PRInt32 aRelease, PRInt32 aBuild, PRInt32* aReturn);
NS_IMETHOD CompareVersion(const nsString& aRegName, const nsString& aVersion, PRInt32* aReturn);
NS_IMETHOD CompareVersion(const nsString& aRegName, nsIDOMInstallVersion* aVersion, PRInt32* aReturn);
NS_IMETHOD GetVersion(const nsString& component, nsString& version);
private:

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

@ -1,240 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (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/MPL/
*
* 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, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Daniel Veditz <dveditz@netscape.com>
* Douglas Turner <dougt@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsInstall.h"
#include "nsInstallUninstall.h"
#include "nsInstallResources.h"
#include "VerReg.h"
#include "nsCRT.h"
#include "prmem.h"
#include "prprf.h"
#include "ScheduledTasks.h"
#include "nsReadableUtils.h"
#include "nsILocalFile.h"
extern "C" NS_EXPORT PRInt32 SU_Uninstall(char *regPackageName);
REGERR su_UninstallProcessItem(char *component_path);
nsInstallUninstall::nsInstallUninstall( nsInstall* inInstall,
const nsString& regName,
PRInt32 *error)
: nsInstallObject(inInstall)
{
MOZ_COUNT_CTOR(nsInstallUninstall);
if (regName.IsEmpty())
{
*error = nsInstall::INVALID_ARGUMENTS;
return;
}
mRegName.Assign(regName);
char* userName = (char*)PR_Malloc(MAXREGPATHLEN);
PRInt32 err = VR_GetUninstallUserName( const_cast<char*>(NS_ConvertUTF16toUTF8(regName).get()),
userName,
MAXREGPATHLEN );
mUIName.AssignWithConversion(userName);
if (err != REGERR_OK)
{
*error = nsInstall::NO_SUCH_COMPONENT;
}
PR_FREEIF(userName);
}
nsInstallUninstall::~nsInstallUninstall()
{
MOZ_COUNT_DTOR(nsInstallUninstall);
}
PRInt32 nsInstallUninstall::Prepare()
{
// no set-up necessary
return nsInstall::SUCCESS;
}
PRInt32 nsInstallUninstall::Complete()
{
PRInt32 err = nsInstall::SUCCESS;
if (mInstall == NULL)
return nsInstall::INVALID_ARGUMENTS;
err = SU_Uninstall( const_cast<char*>(NS_ConvertUTF16toUTF8(mRegName).get()) );
return err;
}
void nsInstallUninstall::Abort()
{
}
char* nsInstallUninstall::toString()
{
if (!mInstall)
return nsnull;
char* buffer = new char[1024];
char* rsrcVal = nsnull;
if (!buffer)
return nsnull;
char* temp = ToNewCString(mUIName);
if (temp)
{
rsrcVal = mInstall->GetResourcedString(NS_LITERAL_STRING("Uninstall"));
if (rsrcVal)
{
PR_snprintf( buffer, 1024, rsrcVal, temp);
nsCRT::free(rsrcVal);
}
}
if (temp)
NS_Free(temp);
return buffer;
}
PRBool
nsInstallUninstall::CanUninstall()
{
return PR_FALSE;
}
PRBool
nsInstallUninstall::RegisterPackageNode()
{
return PR_FALSE;
}
extern "C" NS_EXPORT PRInt32 SU_Uninstall(char *regPackageName)
{
REGERR status = REGERR_FAIL;
char pathbuf[MAXREGPATHLEN+1] = {0};
char sharedfilebuf[MAXREGPATHLEN+1] = {0};
REGENUM state = 0;
int32 length;
int32 err;
if (regPackageName == NULL)
return REGERR_PARAM;
if (pathbuf == NULL)
return REGERR_PARAM;
/* Get next path from Registry */
status = VR_Enum( regPackageName, &state, pathbuf, MAXREGPATHLEN );
/* if we got a good path */
while (status == REGERR_OK)
{
char component_path[2*MAXREGPATHLEN+1] = {0};
strcat(component_path, regPackageName);
length = strlen(regPackageName);
if (component_path[length - 1] != '/')
strcat(component_path, "/");
strcat(component_path, pathbuf);
err = su_UninstallProcessItem(component_path);
status = VR_Enum( regPackageName, &state, pathbuf, MAXREGPATHLEN );
}
err = VR_Remove(regPackageName);
// there is a problem here. It looks like if the file is refcounted, we still blow away the reg key
// FIX!
state = 0;
status = VR_UninstallEnumSharedFiles( regPackageName, &state, sharedfilebuf, MAXREGPATHLEN );
while (status == REGERR_OK)
{
err = su_UninstallProcessItem(sharedfilebuf);
err = VR_UninstallDeleteFileFromList(regPackageName, sharedfilebuf);
status = VR_UninstallEnumSharedFiles( regPackageName, &state, sharedfilebuf, MAXREGPATHLEN );
}
err = VR_UninstallDeleteSharedFilesKey(regPackageName);
err = VR_UninstallDestroy(regPackageName);
return err;
}
REGERR su_UninstallProcessItem(char *component_path)
{
int refcount;
int err;
char filepath[MAXREGPATHLEN];
nsCOMPtr<nsILocalFile> nsLFPath;
nsCOMPtr<nsIFile> nsFPath;
err = VR_GetPath(component_path, sizeof(filepath), filepath);
if ( err == REGERR_OK )
{
NS_NewNativeLocalFile(nsDependentCString(filepath), PR_TRUE, getter_AddRefs(nsLFPath));
nsFPath = nsLFPath;
err = VR_GetRefCount(component_path, &refcount);
if ( err == REGERR_OK )
{
--refcount;
if (refcount > 0)
err = VR_SetRefCount(component_path, refcount);
else
{
err = VR_Remove(component_path);
DeleteFileNowOrSchedule(nsFPath);
}
}
else
{
/* delete node and file */
err = VR_Remove(component_path);
DeleteFileNowOrSchedule(nsFPath);
}
}
return err;
}

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

@ -1,78 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (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/MPL/
*
* 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, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Daniel Veditz <dveditz@netscape.com>
* Douglas Turner <dougt@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsInstallUninstall_h__
#define nsInstallUninstall_h__
#include "prtypes.h"
#include "nsString.h"
#include "nsInstallObject.h"
#include "nsInstall.h"
class nsInstallUninstall : public nsInstallObject
{
public:
nsInstallUninstall( nsInstall* inInstall,
const nsString& regName,
PRInt32 *error);
virtual ~nsInstallUninstall();
PRInt32 Prepare();
PRInt32 Complete();
void Abort();
char* toString();
PRBool CanUninstall();
PRBool RegisterPackageNode();
private:
nsString mRegName; // Registry name of package
nsString mUIName; // User name of package
};
#endif /* nsInstallUninstall_h__ */

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

@ -1,287 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (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/MPL/
*
* 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 the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsSoftwareUpdate.h"
#include "nsInstall.h"
#include "nsInstallVersion.h"
#include "nsIDOMInstallVersion.h"
#include "nscore.h"
#include "nsString.h"
#include "nsIFactory.h"
#include "nsISupports.h"
#include "nsIScriptGlobalObject.h"
#include "prprf.h"
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID);
static NS_DEFINE_IID(kIInstallVersion_IID, NS_IDOMINSTALLVERSION_IID);
nsInstallVersion::nsInstallVersion()
{
mScriptObject = nsnull;
}
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 (!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)
{
mMajor = aMajor;
mMinor = aMinor;
mRelease = aRelease;
mBuild = aBuild;
return NS_OK;
}
NS_IMETHODIMP
nsInstallVersion::Init(const nsString& version)
{
mMajor = mMinor = mRelease = mBuild = 0;
// nsString is a flat string
if (PR_sscanf(NS_ConvertUTF16toUTF8(version).get(),"%d.%d.%d.%d",&mMajor,&mMinor,&mRelease,&mBuild) < 1)
return NS_ERROR_UNEXPECTED;
return NS_OK;
}
NS_IMETHODIMP
nsInstallVersion::GetMajor(PRInt32* aMajor)
{
*aMajor = mMajor;
return NS_OK;
}
NS_IMETHODIMP
nsInstallVersion::SetMajor(PRInt32 aMajor)
{
mMajor = aMajor;
return NS_OK;
}
NS_IMETHODIMP
nsInstallVersion::GetMinor(PRInt32* aMinor)
{
*aMinor = mMinor;
return NS_OK;
}
NS_IMETHODIMP
nsInstallVersion::SetMinor(PRInt32 aMinor)
{
mMinor = aMinor;
return NS_OK;
}
NS_IMETHODIMP
nsInstallVersion::GetRelease(PRInt32* aRelease)
{
*aRelease = mRelease;
return NS_OK;
}
NS_IMETHODIMP
nsInstallVersion::SetRelease(PRInt32 aRelease)
{
mRelease = aRelease;
return NS_OK;
}
NS_IMETHODIMP
nsInstallVersion::GetBuild(PRInt32* aBuild)
{
*aBuild = mBuild;
return NS_OK;
}
NS_IMETHODIMP
nsInstallVersion::SetBuild(PRInt32 aBuild)
{
mBuild = 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& aString, PRInt32* aReturn)
{
nsInstallVersion inVersion;
inVersion.Init(aString);
return CompareTo(&inVersion, aReturn);
}
NS_IMETHODIMP
nsInstallVersion::CompareTo(PRInt32 aMajor, PRInt32 aMinor, PRInt32 aRelease, PRInt32 aBuild, PRInt32* aReturn)
{
int diff;
if ( mMajor == aMajor )
{
if ( mMinor == aMinor )
{
if ( mRelease == aRelease )
{
if ( mBuild == aBuild )
diff = EQUAL;
else if ( mBuild > aBuild )
diff = BLD_DIFF;
else
diff = BLD_DIFF_MINUS;
}
else if ( mRelease > aRelease )
diff = REL_DIFF;
else
diff = REL_DIFF_MINUS;
}
else if ( mMinor > aMinor )
diff = MINOR_DIFF;
else
diff = MINOR_DIFF_MINUS;
}
else if ( mMajor > aMajor )
diff = MAJOR_DIFF;
else
diff = MAJOR_DIFF_MINUS;
*aReturn = diff;
return NS_OK;
}
NS_IMETHODIMP
nsInstallVersion::ToString(nsString& aReturn)
{
char buf[128];
PRUint32 len;
len=PR_snprintf(buf, sizeof(buf), "%d.%d.%d.%d", mMajor, mMinor, mRelease, mBuild);
aReturn.AssignASCII(buf,len);
return NS_OK;
}

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

@ -1,58 +0,0 @@
#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();
virtual ~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(const nsString& aString, PRInt32* aReturn);
NS_IMETHOD CompareTo(PRInt32 aMajor, PRInt32 aMinor, PRInt32 aRelease, PRInt32 aBuild, PRInt32* aReturn);
private:
void *mScriptObject;
PRInt32 mMajor;
PRInt32 mMinor;
PRInt32 mRelease;
PRInt32 mBuild;
};
#define NS_INSTALLVERSIONCOMPONENT_CONTRACTID "@mozilla.org/xpinstall/installversion;1"
#endif

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

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

@ -1,110 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (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/MPL/
*
* 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.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef __NS_JSFILE_H__
#define __NS_JSFILE_H__
#include "jsapi.h"
#include "nscore.h"
JSBool JS_DLL_CALLBACK
InstallFileOpDirCreate(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
JSBool JS_DLL_CALLBACK
InstallFileOpDirGetParent(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
JSBool JS_DLL_CALLBACK
InstallFileOpDirRemove(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
JSBool JS_DLL_CALLBACK
InstallFileOpDirRename(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
JSBool JS_DLL_CALLBACK
InstallFileOpFileCopy(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
JSBool JS_DLL_CALLBACK
InstallFileOpFileRemove(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
JSBool JS_DLL_CALLBACK
InstallFileOpFileExists(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
JSBool JS_DLL_CALLBACK
InstallFileOpFileExecute(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
JSBool JS_DLL_CALLBACK
InstallFileOpFileGetNativeVersion(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
JSBool JS_DLL_CALLBACK
InstallFileOpFileGetDiskSpaceAvailable(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
JSBool JS_DLL_CALLBACK
InstallFileOpFileGetModDate(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
JSBool JS_DLL_CALLBACK
InstallFileOpFileGetSize(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
JSBool JS_DLL_CALLBACK
InstallFileOpFileIsDirectory(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
JSBool JS_DLL_CALLBACK
InstallFileOpFileIsWritable(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
JSBool JS_DLL_CALLBACK
InstallFileOpFileIsFile(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
JSBool JS_DLL_CALLBACK
InstallFileOpFileModDateChanged(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
JSBool JS_DLL_CALLBACK
InstallFileOpFileMove(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
JSBool JS_DLL_CALLBACK
InstallFileOpFileRename(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
JSBool JS_DLL_CALLBACK
InstallFileOpFileWindowsShortcut(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
JSBool JS_DLL_CALLBACK
InstallFileOpFileMacAlias(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
JSBool JS_DLL_CALLBACK
InstallFileOpFileUnixLink(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
PRInt32 InitXPFileOpObjectPrototype(JSContext *jscontext, JSObject *global, JSObject **fileOpObjectPrototype);
#endif

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

@ -1,172 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (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/MPL/
*
* 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.org Code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "jsapi.h"
#include "nscore.h"
#include "nsIScriptContext.h"
#include "nsString.h"
#include "nsInstall.h"
#include "nsJSFileSpecObj.h"
extern void ConvertJSValToStr(nsString& aString,
JSContext* aContext,
jsval aValue);
extern void ConvertStrToJSVal(const nsString& aProp,
JSContext* aContext,
jsval* aReturn);
extern PRBool ConvertJSValToBool(PRBool* aProp,
JSContext* aContext,
jsval aValue);
static void PR_CALLBACK
FileSpecObjectCleanup(JSContext *cx, JSObject *obj);
/***********************************************************************/
//
// class for FileObj
//
JSClass FileSpecObjectClass = {
"FileSpecObject",
JSCLASS_HAS_PRIVATE,
JS_PropertyStub,
JS_PropertyStub,
JS_PropertyStub,
JS_PropertyStub,
JS_EnumerateStub,
JS_ResolveStub,
JS_ConvertStub,
FileSpecObjectCleanup
};
/***********************************************************************************/
// Native methods for FileSpecObj functions
/*
* Native method fso_ToString
*/
JS_STATIC_DLL_CALLBACK(JSBool)
fso_ToString(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsInstallFolder *nativeThis =
(nsInstallFolder*)JS_GetInstancePrivate(cx, obj, &FileSpecObjectClass,
argv);
if (!nativeThis)
return JS_FALSE;
nsAutoString stringReturned;
*rval = JSVAL_NULL;
if(NS_FAILED( nativeThis->ToString(&stringReturned)))
return JS_TRUE;
JSString *jsstring =
JS_NewUCStringCopyN(cx, reinterpret_cast<const jschar*>
(stringReturned.get()),
stringReturned.Length());
// set the return value
*rval = STRING_TO_JSVAL(jsstring);
return JS_TRUE;
}
/*
* Native method fso_AppendString
*/
JS_STATIC_DLL_CALLBACK(JSBool)
fso_AppendPath(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
return JS_TRUE;
}
/*
* FileSpecObj destructor
*/
JS_STATIC_DLL_CALLBACK(void) FileSpecObjectCleanup(JSContext *cx, JSObject *obj)
{
nsInstallFolder *nativeThis = (nsInstallFolder*)JS_GetPrivate(cx, obj);
if (nativeThis != nsnull)
delete nativeThis;
}
//
// FileObj class methods
//
static JSFunctionSpec fileSpecObjMethods[] =
{
{"appendPath", fso_AppendPath, 1,0,0},
{"toString", fso_ToString, 0,0,0},
{nsnull,nsnull,0,0,0}
};
PRInt32 InitFileSpecObjectPrototype(JSContext *jscontext,
JSObject *global,
JSObject **fileSpecObjectPrototype)
{
*fileSpecObjectPrototype = JS_InitClass( jscontext, // context
global, // global object
nsnull, // parent proto
&FileSpecObjectClass, // JSClass
nsnull, // JSNative ctor
0, // ctor args
nsnull, // proto props
fileSpecObjMethods,// proto funcs
nsnull, // ctor props (static)
nsnull); // ctor funcs (static)
if (nsnull == *fileSpecObjectPrototype)
{
return NS_ERROR_FAILURE;
}
return NS_OK;
}

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

@ -1,45 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (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/MPL/
*
* 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.org Code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef __NS_JSFILEOBJ_H__
#define __NS_JSFILEOBJ_H__
PRInt32
InitFileSpecObjectPrototype(JSContext *jscontext, JSObject *global, JSObject **fileSpecObjectPrototype);
#endif

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

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

@ -20,6 +20,7 @@
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Dave Townsend <dtownsend@oxymoronical.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
@ -43,7 +44,6 @@
#include "nsIScriptGlobalObject.h"
#include "nsCRT.h"
#include "nsString.h"
#include "nsIDOMInstallVersion.h"
#include "nsIDOMInstallTriggerGlobal.h"
#include "nsPIDOMWindow.h"
#include "nsIDOMDocument.h"
@ -61,17 +61,22 @@
#include "nsSoftwareUpdateIIDs.h"
extern void ConvertJSValToStr(nsString& aString,
JSContext* aContext,
jsval aValue);
void ConvertJSValToStr(nsString& aString,
JSContext* aContext,
jsval aValue)
{
JSString *jsstring;
extern void ConvertStrToJSVal(const nsString& aProp,
JSContext* aContext,
jsval* aReturn);
extern PRBool ConvertJSValToBool(PRBool* aProp,
JSContext* aContext,
jsval aValue);
if ( !JSVAL_IS_NULL(aValue) &&
(jsstring = JS_ValueToString(aContext, aValue)) != nsnull)
{
aString.Assign(reinterpret_cast<const PRUnichar*>(JS_GetStringChars(jsstring)));
}
else
{
aString.Truncate();
}
}
PR_STATIC_CALLBACK(void)
FinalizeInstallTriggerGlobal(JSContext *cx, JSObject *obj);
@ -227,7 +232,7 @@ InstallTriggerGlobalUpdateEnabled(JSContext *cx, JSObject *obj, uintN argc, jsva
//
JS_STATIC_DLL_CALLBACK(JSBool)
InstallTriggerGlobalInstall(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
{
nsIDOMInstallTriggerGlobal *nativeThis = getTriggerNative(cx, obj);
if (!nativeThis)
return JS_FALSE;
@ -242,7 +247,7 @@ InstallTriggerGlobalInstall(JSContext *cx, JSObject *obj, uintN argc, jsval *arg
if (!globalObject)
return JS_TRUE;
nsCOMPtr<nsIScriptSecurityManager> secman(do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID));
if (!secman)
{
@ -306,7 +311,7 @@ InstallTriggerGlobalInstall(JSContext *cx, JSObject *obj, uintN argc, jsval *arg
URL = iconURL = nsnull;
hash = nsnull;
JS_GetUCProperty( cx, JSVAL_TO_OBJECT(argv[0]), reinterpret_cast<const jschar*>(name), nsCRT::strlen(name), &v );
if ( JSVAL_IS_OBJECT(v) && JSVAL_TO_OBJECT(v) )
if ( JSVAL_IS_OBJECT(v) && JSVAL_TO_OBJECT(v) )
{
jsval v2;
if (JS_GetProperty( cx, JSVAL_TO_OBJECT(v), "URL", &v2 ) && !JSVAL_IS_VOID(v2))
@ -395,7 +400,7 @@ InstallTriggerGlobalInstall(JSContext *cx, JSObject *obj, uintN argc, jsval *arg
nsCOMPtr<nsIObserverService> os(do_GetService("@mozilla.org/observer-service;1"));
if (os)
os->NotifyObservers(installInfo,
"xpinstall-install-blocked",
"xpinstall-install-blocked",
nsnull);
}
else
@ -451,7 +456,7 @@ InstallTriggerGlobalInstallChrome(JSContext *cx, JSObject *obj, uintN argc, jsva
if (!globalObject)
return JS_TRUE;
// get window.location to construct relative URLs
nsCOMPtr<nsIURI> baseURL;
JSObject* global = JS_GetGlobalObject(cx);
@ -515,7 +520,7 @@ InstallTriggerGlobalInstallChrome(JSContext *cx, JSObject *obj, uintN argc, jsva
nsCOMPtr<nsIObserverService> os(do_GetService("@mozilla.org/observer-service;1"));
if (os)
os->NotifyObservers(installInfo,
"xpinstall-install-blocked",
"xpinstall-install-blocked",
nsnull);
}
else
@ -555,7 +560,7 @@ InstallTriggerGlobalStartSoftwareUpdate(JSContext *cx, JSObject *obj, uintN argc
if (!globalObject)
return JS_TRUE;
// get window.location to construct relative URLs
nsCOMPtr<nsIURI> baseURL;
JSObject* global = JS_GetGlobalObject(cx);
@ -570,7 +575,7 @@ InstallTriggerGlobalStartSoftwareUpdate(JSContext *cx, JSObject *obj, uintN argc
}
}
if ( argc >= 1 )
{
nsAutoString xpiURL;
@ -633,7 +638,7 @@ InstallTriggerGlobalStartSoftwareUpdate(JSContext *cx, JSObject *obj, uintN argc
}
else
{
JS_ReportError(cx, "Function StartSoftwareUpdate requires 2 parameters");
JS_ReportError(cx, "Function StartSoftwareUpdate requires 1 parameters");
return JS_FALSE;
}
@ -641,161 +646,18 @@ InstallTriggerGlobalStartSoftwareUpdate(JSContext *cx, JSObject *obj, uintN argc
}
//
// Native method CompareVersion
//
JS_STATIC_DLL_CALLBACK(JSBool)
InstallTriggerGlobalCompareVersion(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMInstallTriggerGlobal *nativeThis = getTriggerNative(cx, obj);
if (!nativeThis)
return JS_FALSE;
nsAutoString regname;
nsAutoString version;
int32 major,minor,release,build;
// In case of error or disabled return NOT_FOUND
PRInt32 nativeRet = nsIDOMInstallTriggerGlobal::NOT_FOUND;
*rval = INT_TO_JSVAL(nativeRet);
// make sure XPInstall is enabled, return if not
nsIScriptGlobalObject *globalObject = nsnull;
nsIScriptContext *scriptContext = GetScriptContextFromJSContext(cx);
if (scriptContext)
globalObject = scriptContext->GetGlobalObject();
PRBool enabled = PR_FALSE;
nativeThis->UpdateEnabled(globalObject, XPI_WHITELIST, &enabled);
if (!enabled)
return JS_TRUE;
if (argc < 2 )
{
JS_ReportError(cx, "CompareVersion requires at least 2 parameters");
return JS_FALSE;
}
else if ( !JSVAL_IS_STRING(argv[0]) )
{
JS_ReportError(cx, "Invalid parameter passed to CompareVersion");
return JS_FALSE;
}
// get the registry name argument
ConvertJSValToStr(regname, cx, argv[0]);
if (argc == 2 )
{
// public int CompareVersion(String registryName, String version)
// --OR-- CompareVersion(String registryNamve, InstallVersion version)
ConvertJSValToStr(version, cx, argv[1]);
if(NS_OK != nativeThis->CompareVersion(regname, version, &nativeRet))
{
return JS_FALSE;
}
}
else
{
// public int CompareVersion(String registryName,
// int major,
// int minor,
// int release,
// int build);
//
// minor, release, and build values are optional
major = minor = release = build = 0;
if(!JS_ValueToInt32(cx, argv[1], &major))
{
JS_ReportError(cx, "2th parameter must be a number");
return JS_FALSE;
}
if( argc > 2 && !JS_ValueToInt32(cx, argv[2], &minor) )
{
JS_ReportError(cx, "3th parameter must be a number");
return JS_FALSE;
}
if( argc > 3 && !JS_ValueToInt32(cx, argv[3], &release) )
{
JS_ReportError(cx, "4th parameter must be a number");
return JS_FALSE;
}
if( argc > 4 && !JS_ValueToInt32(cx, argv[4], &build) )
{
JS_ReportError(cx, "5th parameter must be a number");
return JS_FALSE;
}
if(NS_OK != nativeThis->CompareVersion(regname, major, minor, release, build, &nativeRet))
{
return JS_FALSE;
}
}
*rval = INT_TO_JSVAL(nativeRet);
return JS_TRUE;
}
//
// Native method GetVersion
//
JS_STATIC_DLL_CALLBACK(JSBool)
InstallTriggerGlobalGetVersion(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMInstallTriggerGlobal *nativeThis = getTriggerNative(cx, obj);
if (!nativeThis)
return JS_FALSE;
nsAutoString regname;
nsAutoString version;
// In case of error return a null value
*rval = JSVAL_NULL;
// make sure XPInstall is enabled, return if not
nsIScriptGlobalObject *globalObject = nsnull;
nsIScriptContext *scriptContext = GetScriptContextFromJSContext(cx);
if (scriptContext)
globalObject = scriptContext->GetGlobalObject();
PRBool enabled = PR_FALSE;
nativeThis->UpdateEnabled(globalObject, XPI_WHITELIST, &enabled);
if (!enabled)
return JS_TRUE;
// get the registry name argument
ConvertJSValToStr(regname, cx, argv[0]);
if(nativeThis->GetVersion(regname, version) == NS_OK && !version.IsEmpty() )
{
ConvertStrToJSVal(version, cx, rval);
}
return JS_TRUE;
}
//
// InstallTriggerGlobal class methods
//
static JSFunctionSpec InstallTriggerGlobalMethods[] =
{
// -- obsolete forms, do not document. Kept for 4.x compatibility
{"UpdateEnabled", InstallTriggerGlobalUpdateEnabled, 0,0,0},
{"StartSoftwareUpdate", InstallTriggerGlobalStartSoftwareUpdate, 2,0,0},
{"CompareVersion", InstallTriggerGlobalCompareVersion, 5,0,0},
{"GetVersion", InstallTriggerGlobalGetVersion, 2,0,0},
{"updateEnabled", InstallTriggerGlobalUpdateEnabled, 0,0,0},
// -- new forms to match JS style --
{"enabled", InstallTriggerGlobalUpdateEnabled, 0,0,0},
{"install", InstallTriggerGlobalInstall, 2,0,0},
{"installChrome", InstallTriggerGlobalInstallChrome, 2,0,0},
{"startSoftwareUpdate", InstallTriggerGlobalStartSoftwareUpdate, 2,0,0},
{"compareVersion", InstallTriggerGlobalCompareVersion, 5,0,0},
{"getVersion", InstallTriggerGlobalGetVersion, 2,0,0},
{nsnull,nsnull,0,0,0}
};

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

@ -1,705 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (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/MPL/
*
* 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.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/* AUTO-GENERATED. DO NOT EDIT!!! */
#include "jsapi.h"
#include "nscore.h"
#include "nsIScriptContext.h"
#include "nsIScriptObjectOwner.h"
#include "nsIScriptGlobalObject.h"
#include "nsString.h"
#include "nsIDOMInstallVersion.h"
#include "nsIScriptNameSpaceManager.h"
#include "nsIComponentManager.h"
#include "nsDOMCID.h"
#include "nsSoftwareUpdateIIDs.h"
PR_STATIC_CALLBACK(JSBool)
GetInstallVersionProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp);
PR_STATIC_CALLBACK(JSBool)
SetInstallVersionProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp);
PR_STATIC_CALLBACK(JSBool)
EnumerateInstallVersion(JSContext *cx, JSObject *obj);
PR_STATIC_CALLBACK(JSBool)
ResolveInstallVersion(JSContext *cx, JSObject *obj, jsval id);
PR_STATIC_CALLBACK(void)
FinalizeInstallVersion(JSContext *cx, JSObject *obj);
/***********************************************************************/
//
// class for InstallVersion
//
JSClass InstallVersionClass = {
"InstallVersion",
JSCLASS_HAS_PRIVATE | JSCLASS_PRIVATE_IS_NSISUPPORTS,
JS_PropertyStub,
JS_PropertyStub,
GetInstallVersionProperty,
SetInstallVersionProperty,
EnumerateInstallVersion,
ResolveInstallVersion,
JS_ConvertStub,
FinalizeInstallVersion
};
extern void ConvertJSValToStr(nsString& aString,
JSContext* aContext,
jsval aValue);
extern void ConvertStrToJSVal(const nsString& aProp,
JSContext* aContext,
jsval* aReturn);
extern PRBool ConvertJSValToBool(PRBool* aProp,
JSContext* aContext,
jsval aValue);
extern PRBool ConvertJSValToObj(nsISupports** aSupports,
REFNSIID aIID,
JSClass* aClass,
JSContext* aContext,
jsval aValue);
void ConvertJSvalToVersionString(nsString& versionString, JSContext* cx, jsval* argument);
//
// InstallVersion property ids
//
enum InstallVersion_slots {
INSTALLVERSION_MAJOR = -1,
INSTALLVERSION_MINOR = -2,
INSTALLVERSION_RELEASE = -3,
INSTALLVERSION_BUILD = -4
};
/***********************************************************************/
//
// InstallVersion Properties Getter
//
JS_STATIC_DLL_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;
}
}
}
return JS_TRUE;
}
/***********************************************************************/
//
// InstallVersion Properties Setter
//
JS_STATIC_DLL_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;
}
}
}
return JS_TRUE;
}
//
// InstallVersion finalizer
//
JS_STATIC_DLL_CALLBACK(void)
FinalizeInstallVersion(JSContext *cx, JSObject *obj)
{
nsISupports *nativeThis = (nsISupports*)JS_GetPrivate(cx, obj);
if (nsnull != nativeThis) {
// get the js object
nsIScriptObjectOwner *owner = nsnull;
if (NS_OK == nativeThis->QueryInterface(NS_GET_IID(nsIScriptObjectOwner),
(void**)&owner)) {
owner->SetScriptObject(nsnull);
NS_RELEASE(owner);
}
// The addref was part of JSObject construction
NS_RELEASE(nativeThis);
}
}
//
// InstallVersion enumerate
//
JS_STATIC_DLL_CALLBACK(JSBool)
EnumerateInstallVersion(JSContext *cx, JSObject *obj)
{
return JS_TRUE;
}
//
// InstallVersion resolve
//
JS_STATIC_DLL_CALLBACK(JSBool)
ResolveInstallVersion(JSContext *cx, JSObject *obj, jsval id)
{
return JS_TRUE;
}
//
// Native method Init
//
JS_STATIC_DLL_CALLBACK(JSBool)
InstallVersionInit(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMInstallVersion *nativeThis =
(nsIDOMInstallVersion*)JS_GetInstancePrivate(cx, obj, &InstallVersionClass,
argv);
if (!nativeThis)
return 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)
{
JSString *jsstring;
if ((jsstring = JS_ValueToString(cx, argv[0])) != nsnull) {
b0.Assign(reinterpret_cast<const PRUnichar*>
(JS_GetStringChars(jsstring)));
}
}
else
{
b0.AssignLiteral("0.0.0.0");
}
if (NS_OK != nativeThis->Init(b0))
return JS_FALSE;
*rval = JSVAL_VOID;
return JS_TRUE;
}
//
// Native method ToString
//
JS_STATIC_DLL_CALLBACK(JSBool)
InstallVersionToString(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMInstallVersion *nativeThis =
(nsIDOMInstallVersion*)JS_GetInstancePrivate(cx, obj, &InstallVersionClass,
argv);
if (!nativeThis)
return 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 (NS_OK != nativeThis->ToString(nativeRet)) {
return JS_TRUE;
}
JSString *jsstring =
JS_NewUCStringCopyN(cx, reinterpret_cast<const jschar*>
(nativeRet.get()),
nativeRet.Length());
// set the return value
*rval = STRING_TO_JSVAL(jsstring);
return JS_TRUE;
}
//
// Native method CompareTo
//
JS_STATIC_DLL_CALLBACK(JSBool)
InstallVersionCompareTo(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMInstallVersion *nativeThis =
(nsIDOMInstallVersion*)JS_GetInstancePrivate(cx, obj, &InstallVersionClass,
argv);
if (!nativeThis)
return JS_FALSE;
PRInt32 nativeRet;
nsString b0str;
PRInt32 b0int;
PRInt32 b1int;
PRInt32 b2int;
PRInt32 b3int;
*rval = JSVAL_NULL;
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
if(argc >= 4)
{
// public int CompareTo(int major,
// int minor,
// int release,
// int build);
if(!JSVAL_IS_INT(argv[0]))
{
JS_ReportError(cx, "1st parameter must be a number");
return JS_FALSE;
}
else if(!JSVAL_IS_INT(argv[1]))
{
JS_ReportError(cx, "2nd parameter must be a number");
return JS_FALSE;
}
else if(!JSVAL_IS_INT(argv[2]))
{
JS_ReportError(cx, "3rd parameter must be a number");
return JS_FALSE;
}
else if(!JSVAL_IS_INT(argv[3]))
{
JS_ReportError(cx, "4th parameter must be a number");
return JS_FALSE;
}
b0int = JSVAL_TO_INT(argv[0]);
b1int = JSVAL_TO_INT(argv[1]);
b2int = JSVAL_TO_INT(argv[2]);
b3int = JSVAL_TO_INT(argv[3]);
if(NS_OK != nativeThis->CompareTo(b0int, b1int, b2int, b3int, &nativeRet))
{
return JS_FALSE;
}
*rval = INT_TO_JSVAL(nativeRet);
}
else if(argc >= 1)
{
// public int AddDirectory(String version); --OR-- VersionInfo version
if(JSVAL_IS_OBJECT(argv[0]))
{
nsCOMPtr<nsIDOMInstallVersion> versionObj;
if(JS_FALSE == ConvertJSValToObj(getter_AddRefs(versionObj),
NS_GET_IID(nsIDOMInstallVersion),
&InstallVersionClass,
cx,
argv[0]))
{
return JS_FALSE;
}
if (!versionObj)
{
JS_ReportError(cx, "Function compareTo expects a non null object.");
return JS_FALSE;
}
if(NS_OK != nativeThis->CompareTo(versionObj, &nativeRet))
{
return JS_FALSE;
}
}
else
{
ConvertJSValToStr(b0str, cx, argv[0]);
if(NS_OK != nativeThis->CompareTo(b0str, &nativeRet))
{
return JS_FALSE;
}
}
*rval = INT_TO_JSVAL(nativeRet);
}
else
{
JS_ReportError(cx, "Function compareTo requires 4 parameters");
return JS_FALSE;
}
return JS_TRUE;
}
//
// 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,0,0},
{"toString", InstallVersionToString, 0,0,0},
{"compareTo", InstallVersionCompareTo, 1,0,0},
{nsnull,nsnull,0,0,0}
};
static JSConstDoubleSpec version_constants[] =
{
{ nsIDOMInstallVersion::EQUAL, "EQUAL" },
{ nsIDOMInstallVersion::BLD_DIFF, "BLD_DIFF" },
{ nsIDOMInstallVersion::BLD_DIFF_MINUS, "BLD_DIFF_MINUS" },
{ nsIDOMInstallVersion::REL_DIFF, "REL_DIFF" },
{ nsIDOMInstallVersion::REL_DIFF_MINUS, "REL_DIFF_MINUS" },
{ nsIDOMInstallVersion::MINOR_DIFF, "MINOR_DIFF" },
{ nsIDOMInstallVersion::MINOR_DIFF_MINUS, "MINOR_DIFF_MINUS" },
{ nsIDOMInstallVersion::MAJOR_DIFF, "MAJOR_DIFF" },
{ nsIDOMInstallVersion::MAJOR_DIFF_MINUS, "MAJOR_DIFF_MINUS" },
{0,nsnull}
};
//
// InstallVersion constructor
//
JS_STATIC_DLL_CALLBACK(JSBool)
InstallVersion(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsresult result;
nsIDOMInstallVersion *nativeThis;
nsIScriptObjectOwner *owner = nsnull;
static NS_DEFINE_IID(kInstallVersion_CID, NS_SoftwareUpdateInstallVersion_CID);
result = CallCreateInstance(kInstallVersion_CID, &nativeThis);
if (NS_FAILED(result)) return JS_FALSE;
result = nativeThis->QueryInterface(NS_GET_IID(nsIScriptObjectOwner),
(void **)&owner);
if (NS_FAILED(result)) {
NS_RELEASE(nativeThis);
return JS_FALSE;
}
owner->SetScriptObject((void *)obj);
JS_SetPrivate(cx, obj, nativeThis);
NS_RELEASE(owner);
jsval ignore;
InstallVersionInit(cx, obj, argc, argv, &ignore);
return JS_TRUE;
}
nsresult InitInstallVersionClass(JSContext *jscontext, JSObject *global, void** prototype)
{
JSObject *proto = nsnull;
if (prototype != nsnull)
*prototype = nsnull;
proto = JS_InitClass(jscontext, // context
global, // global object
nsnull, // 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_FALSE == JS_DefineConstDoubles(jscontext, proto, version_constants) )
return NS_ERROR_FAILURE;
if (prototype != nsnull)
*prototype = proto;
return NS_OK;
}
//
// InstallVersion class initialization
//
nsresult NS_InitInstallVersionClass(nsIScriptContext *aContext, void **aPrototype)
{
JSContext *jscontext = (JSContext *)aContext->GetNativeContext();
JSObject *proto = nsnull;
JSObject *constructor = 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))
{
nsresult rv = InitInstallVersionClass(jscontext, global, (void**)&proto);
if (NS_FAILED(rv)) return rv;
}
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
//
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 *installVersion;
if (nsnull == aParent) {
parent = nsnull;
}
else if (NS_OK == aParent->QueryInterface(NS_GET_IID(nsIScriptObjectOwner),
(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(NS_GET_IID(nsIDOMInstallVersion), (void **)&installVersion);
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, installVersion);
}
else {
NS_RELEASE(installVersion);
return NS_ERROR_FAILURE;
}
return NS_OK;
}

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

@ -1,217 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (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/MPL/
*
* 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.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "jsapi.h"
#include "nscore.h"
#include "nsIScriptContext.h"
#include "nsString.h"
#include "nsInstall.h"
#include "nsWinProfile.h"
#include "nsJSWinProfile.h"
extern void ConvertJSValToStr(nsString& aString,
JSContext* aContext,
jsval aValue);
extern void ConvertStrToJSVal(const nsString& aProp,
JSContext* aContext,
jsval* aReturn);
extern PRBool ConvertJSValToBool(PRBool* aProp,
JSContext* aContext,
jsval aValue);
static void PR_CALLBACK
WinProfileCleanup(JSContext *cx, JSObject *obj);
/***********************************************************************/
//
// class for WinProfile
//
JSClass WinProfileClass = {
"WinProfile",
JSCLASS_HAS_PRIVATE,
JS_PropertyStub,
JS_PropertyStub,
JS_PropertyStub,
JS_PropertyStub,
JS_EnumerateStub,
JS_ResolveStub,
JS_ConvertStub,
WinProfileCleanup
};
static void PR_CALLBACK WinProfileCleanup(JSContext *cx, JSObject *obj)
{
nsWinProfile *nativeThis = (nsWinProfile*)JS_GetPrivate(cx, obj);
delete nativeThis;
}
/***********************************************************************************/
// Native mothods for WinProfile functions
//
// Native method GetString
//
PR_STATIC_CALLBACK(JSBool)
WinProfileGetString(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsWinProfile *nativeThis =
(nsWinProfile*)JS_GetInstancePrivate(cx, obj, &WinProfileClass, argv);
if (!nativeThis)
return JS_FALSE;
nsString nativeRet;
nsAutoString b0;
nsAutoString b1;
*rval = JSVAL_NULL;
if(argc >= 2)
{
// public string getString ( String section,
// String key);
ConvertJSValToStr(b0, cx, argv[0]);
ConvertJSValToStr(b1, cx, argv[1]);
nativeThis->GetString(b0, b1, &nativeRet);
ConvertStrToJSVal(nativeRet, cx, rval);
}
else
{
JS_ReportWarning(cx, "WinProfile.getString() parameters error");
}
return JS_TRUE;
}
//
// Native method WriteString
//
PR_STATIC_CALLBACK(JSBool)
WinProfileWriteString(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsWinProfile *nativeThis =
(nsWinProfile*)JS_GetInstancePrivate(cx, obj, &WinProfileClass, argv);
if (!nativeThis)
return JS_FALSE;
PRInt32 nativeRet;
nsAutoString b0;
nsAutoString b1;
nsAutoString b2;
*rval = JSVAL_ZERO;
if(argc >= 3)
{
// public int writeString ( String section,
// String key,
// String value);
ConvertJSValToStr(b0, cx, argv[0]);
ConvertJSValToStr(b1, cx, argv[1]);
ConvertJSValToStr(b2, cx, argv[2]);
if(NS_OK == nativeThis->WriteString(b0, b1, b2, &nativeRet))
{
*rval = INT_TO_JSVAL(nativeRet);
}
}
else
{
JS_ReportWarning(cx, "WinProfile.writeString() parameters error");
}
return JS_TRUE;
}
//
// WinProfile constructor
//
PR_STATIC_CALLBACK(JSBool)
WinProfile(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
return JS_FALSE;
}
static JSConstDoubleSpec winprofile_constants[] =
{
{0}
};
//
// WinProfile class methods
//
static JSFunctionSpec WinProfileMethods[] =
{
{"getString", WinProfileGetString, 2,0,0},
{"writeString", WinProfileWriteString, 3,0,0},
{nsnull,nsnull,0,0,0}
};
PRInt32
InitWinProfilePrototype(JSContext *jscontext, JSObject *global, JSObject **winProfilePrototype)
{
*winProfilePrototype = JS_InitClass( jscontext, // context
global, // global object
nsnull, // parent proto
&WinProfileClass, // JSClass
nsnull, // JSNative ctor
0, // ctor args
nsnull, // proto props
nsnull, // proto funcs
nsnull, // ctor props (static)
WinProfileMethods); // ctor funcs (static)
if(nsnull == *winProfilePrototype)
{
return NS_ERROR_FAILURE;
}
if(PR_FALSE == JS_DefineConstDoubles(jscontext, *winProfilePrototype, winprofile_constants))
return NS_ERROR_FAILURE;
return NS_OK;
}

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

@ -1,44 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (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/MPL/
*
* 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.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef __NS_JSWINPROTOTYPE_H__
#define __NS_JSWINPROTOTYPE_H__
PRInt32
InitWinProfilePrototype(JSContext *jscontext, JSObject *global, JSObject **winRegPrototype);
#endif

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

@ -1,748 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (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/MPL/
*
* 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.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "jsapi.h"
#include "nscore.h"
#include "nsIScriptContext.h"
#include "nsString.h"
#include "nsInstall.h"
#include "nsWinReg.h"
#include "nsJSWinReg.h"
static void PR_CALLBACK WinRegCleanup(JSContext *cx, JSObject *obj);
extern void ConvertJSValToStr(nsString& aString,
JSContext* aContext,
jsval aValue);
extern void ConvertStrToJSVal(const nsString& aProp,
JSContext* aContext,
jsval* aReturn);
extern PRBool ConvertJSValToBool(PRBool* aProp,
JSContext* aContext,
jsval aValue);
static void PR_CALLBACK WinRegCleanup(JSContext *cx, JSObject *obj)
{
nsWinReg *nativeThis = (nsWinReg*)JS_GetPrivate(cx, obj);
delete nativeThis;
}
/***********************************************************************/
//
// class for WinReg
//
JSClass WinRegClass = {
"WinReg",
JSCLASS_HAS_PRIVATE,
JS_PropertyStub,
JS_PropertyStub,
JS_PropertyStub,
JS_PropertyStub,
JS_EnumerateStub,
JS_ResolveStub,
JS_ConvertStub,
WinRegCleanup
};
/***********************************************************************************/
// Native mothods for WinReg functions
//
// Native method SetRootKey
//
PR_STATIC_CALLBACK(JSBool)
WinRegSetRootKey(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsWinReg *nativeThis =
(nsWinReg*)JS_GetInstancePrivate(cx, obj, &WinRegClass, argv);
if (!nativeThis)
return JS_FALSE;
PRInt32 b0;
*rval = JSVAL_NULL;
if(argc >= 1)
{
// public void setRootKey(PRInt32 key);
if(JS_ValueToInt32(cx, argv[0], (int32 *)&b0))
{
nativeThis->SetRootKey(b0);
}
else
{
JS_ReportWarning(cx, "Parameter must be a number");
}
}
else
{
JS_ReportWarning(cx, "Function SetRootKey requires 1 parameters");
}
return JS_TRUE;
}
//
// Native method KeyExists
//
PR_STATIC_CALLBACK(JSBool)
WinRegKeyExists(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsWinReg *nativeThis =
(nsWinReg*)JS_GetInstancePrivate(cx, obj, &WinRegClass, argv);
if (!nativeThis)
return JS_FALSE;
PRBool nativeRet;
nsAutoString b0;
*rval = JSVAL_FALSE;
if(argc >= 1)
{
// public boolean keyExists ( String subKey );
ConvertJSValToStr(b0, cx, argv[0]);
if(NS_OK == nativeThis->KeyExists(b0, &nativeRet))
{
*rval = BOOLEAN_TO_JSVAL(nativeRet);
}
else
{
NS_WARNING("WinReg.KeyExists() internal error");
}
}
else
{
JS_ReportWarning(cx, "WinReg.KeyExists() parameters error");
}
return JS_TRUE;
}
//
// Native method ValueExists
//
PR_STATIC_CALLBACK(JSBool)
WinRegValueExists(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsWinReg *nativeThis =
(nsWinReg*)JS_GetInstancePrivate(cx, obj, &WinRegClass, argv);
if (!nativeThis)
return JS_FALSE;
PRBool nativeRet;
nsAutoString b0;
nsAutoString b1;
*rval = JSVAL_FALSE;
if(argc >= 2)
{
// public boolean valueExists ( String subKey,
// String value );
ConvertJSValToStr(b0, cx, argv[0]);
ConvertJSValToStr(b1, cx, argv[1]);
if(NS_OK == nativeThis->ValueExists(b0, b1, &nativeRet))
{
*rval = BOOLEAN_TO_JSVAL(nativeRet);
}
}
else
{
JS_ReportWarning(cx, "WinReg.ValueExists() parameters error");
}
return JS_TRUE;
}
//
// Native method IsKeyWritable
//
PR_STATIC_CALLBACK(JSBool)
WinRegIsKeyWritable(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsWinReg *nativeThis =
(nsWinReg*)JS_GetInstancePrivate(cx, obj, &WinRegClass, argv);
if (!nativeThis)
return JS_FALSE;
PRInt32 nativeRet;
nsAutoString b0;
*rval = JSVAL_FALSE;
if(argc >= 1)
{
// public boolean isKeyWritable ( String subKey );
ConvertJSValToStr(b0, cx, argv[0]);
if(NS_OK == nativeThis->IsKeyWritable(b0, &nativeRet))
{
*rval = BOOLEAN_TO_JSVAL(nativeRet);
}
}
else
{
JS_ReportWarning(cx, "WinReg.IsKeyWritable() parameters error");
}
return JS_TRUE;
}
//
// Native method CreateKey
//
PR_STATIC_CALLBACK(JSBool)
WinRegCreateKey(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsWinReg *nativeThis =
(nsWinReg*)JS_GetInstancePrivate(cx, obj, &WinRegClass, argv);
if (!nativeThis)
return JS_FALSE;
PRInt32 nativeRet;
nsAutoString b0;
nsAutoString b1;
*rval = INT_TO_JSVAL(nsInstall::UNEXPECTED_ERROR);
if(argc >= 2)
{
// public int createKey ( String subKey,
// String className);
ConvertJSValToStr(b0, cx, argv[0]);
ConvertJSValToStr(b1, cx, argv[1]);
if(NS_OK == nativeThis->CreateKey(b0, b1, &nativeRet))
{
*rval = INT_TO_JSVAL(nativeRet);
}
}
else
{
JS_ReportWarning(cx, "WinReg.CreateKey() parameters error");
}
return JS_TRUE;
}
//
// Native method DeleteKey
//
PR_STATIC_CALLBACK(JSBool)
WinRegDeleteKey(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsWinReg *nativeThis =
(nsWinReg*)JS_GetInstancePrivate(cx, obj, &WinRegClass, argv);
if (!nativeThis)
return JS_FALSE;
PRInt32 nativeRet;
nsAutoString b0;
*rval = INT_TO_JSVAL(nsInstall::UNEXPECTED_ERROR);
if(argc >= 1)
{
// public int deleteKey ( String subKey);
ConvertJSValToStr(b0, cx, argv[0]);
if(NS_OK == nativeThis->DeleteKey(b0, &nativeRet))
{
*rval = INT_TO_JSVAL(nativeRet);
}
}
else
{
JS_ReportWarning(cx, "WinReg.DeleteKey() parameters error");
}
return JS_TRUE;
}
//
// Native method DeleteValue
//
PR_STATIC_CALLBACK(JSBool)
WinRegDeleteValue(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsWinReg *nativeThis =
(nsWinReg*)JS_GetInstancePrivate(cx, obj, &WinRegClass, argv);
if (!nativeThis)
return JS_FALSE;
PRInt32 nativeRet;
nsString b0;
nsString b1;
*rval = INT_TO_JSVAL(nsInstall::UNEXPECTED_ERROR);
if(argc >= 2)
{
// public int deleteValue ( String subKey,
// String valueName);
ConvertJSValToStr(b0, cx, argv[0]);
ConvertJSValToStr(b1, cx, argv[1]);
if(NS_OK == nativeThis->DeleteValue(b0, b1, &nativeRet))
{
*rval = INT_TO_JSVAL(nativeRet);
}
}
else
{
JS_ReportWarning(cx, "WinReg.DeleteValue() parameters error");
}
return JS_TRUE;
}
//
// Native method SetValueString
//
PR_STATIC_CALLBACK(JSBool)
WinRegSetValueString(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsWinReg *nativeThis =
(nsWinReg*)JS_GetInstancePrivate(cx, obj, &WinRegClass, argv);
if (!nativeThis)
return JS_FALSE;
PRInt32 nativeRet;
nsAutoString b0;
nsAutoString b1;
nsAutoString b2;
*rval = INT_TO_JSVAL(nsInstall::UNEXPECTED_ERROR);
if(argc >= 3)
{
// public int setValueString ( String subKey,
// String valueName,
// String value);
ConvertJSValToStr(b0, cx, argv[0]);
ConvertJSValToStr(b1, cx, argv[1]);
ConvertJSValToStr(b2, cx, argv[2]);
if(NS_OK == nativeThis->SetValueString(b0, b1, b2, &nativeRet))
{
*rval = INT_TO_JSVAL(nativeRet);
}
}
else
{
JS_ReportWarning(cx, "WinReg.SetValueString() parameters error");
}
return JS_TRUE;
}
//
// Native method GetValueString
//
PR_STATIC_CALLBACK(JSBool)
WinRegGetValueString(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsWinReg *nativeThis =
(nsWinReg*)JS_GetInstancePrivate(cx, obj, &WinRegClass, argv);
if (!nativeThis)
return JS_FALSE;
nsString nativeRet;
nsAutoString b0;
nsAutoString b1;
*rval = JSVAL_NULL;
if(argc >= 2)
{
// public string getValueString ( String subKey,
// String valueName);
ConvertJSValToStr(b0, cx, argv[0]);
ConvertJSValToStr(b1, cx, argv[1]);
if(NS_OK == nativeThis->GetValueString(b0, b1, &nativeRet))
{
ConvertStrToJSVal(nativeRet, cx, rval);
}
}
else
{
JS_ReportWarning(cx, "WinReg.GetValueString() parameters error");
}
return JS_TRUE;
}
//
// Native method enumValueNames
//
PR_STATIC_CALLBACK(JSBool)
WinRegEnumValueNames(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsWinReg *nativeThis =
(nsWinReg*)JS_GetInstancePrivate(cx, obj, &WinRegClass, argv);
if (!nativeThis)
return JS_FALSE;
nsAutoString nativeRet;
nsAutoString b0;
int32 b1;
*rval = JSVAL_NULL;
if(argc >= 2)
{
// public String enumValueNames ( String subkey,
// Int index);
ConvertJSValToStr(b0, cx, argv[0]);
if(JS_ValueToInt32(cx, argv[1], &b1))
{
if ( NS_OK == nativeThis->EnumValueNames(b0, b1, nativeRet) )
{
ConvertStrToJSVal(nativeRet, cx, rval);
}
}
else
{
JS_ReportWarning(cx, "WinReg.enumValueNames - Parameter 2 must be a number");
}
}
else
{
JS_ReportWarning(cx, "WinReg.enumValueNames() - Too few parameters");
}
return JS_TRUE;
}
//
// Native method enumKeys
//
PR_STATIC_CALLBACK(JSBool)
WinRegEnumKeys(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsWinReg *nativeThis =
(nsWinReg*)JS_GetInstancePrivate(cx, obj, &WinRegClass, argv);
if (!nativeThis)
return JS_FALSE;
nsAutoString nativeRet;
nsAutoString b0;
int32 b1;
*rval = JSVAL_NULL;
if(argc >= 2)
{
// public String enumKeys ( String subkey,
// Int index);
ConvertJSValToStr(b0, cx, argv[0]);
if(JS_ValueToInt32(cx, argv[1], &b1))
{
if ( NS_OK == nativeThis->EnumKeys(b0, b1, nativeRet) )
{
ConvertStrToJSVal(nativeRet, cx, rval);
}
}
else
{
JS_ReportWarning(cx, "WinReg.enumKeys() - Parameter 2 must be a number");
}
}
else
{
JS_ReportWarning(cx, "WinReg.enumKeys() - Too few parameters");
}
return JS_TRUE;
}
//
// Native method SetValueNumber
//
PR_STATIC_CALLBACK(JSBool)
WinRegSetValueNumber(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsWinReg *nativeThis =
(nsWinReg*)JS_GetInstancePrivate(cx, obj, &WinRegClass, argv);
if (!nativeThis)
return JS_FALSE;
PRInt32 nativeRet;
nsAutoString b0;
nsAutoString b1;
int32 ib2;
*rval = INT_TO_JSVAL(nsInstall::UNEXPECTED_ERROR);
if(argc >= 3)
{
// public int setValueNumber ( String subKey,
// String valueName,
// Number value);
ConvertJSValToStr(b0, cx, argv[0]);
ConvertJSValToStr(b1, cx, argv[1]);
if(!JS_ValueToInt32(cx, argv[2], &ib2))
{
JS_ReportWarning(cx, "Parameter 3 must be a number");
}
else if(NS_OK == nativeThis->SetValueNumber(b0, b1, ib2, &nativeRet))
{
*rval = INT_TO_JSVAL(nativeRet);
}
}
else
{
JS_ReportWarning(cx, "WinReg.SetValueNumber() parameters error");
}
return JS_TRUE;
}
//
// Native method GetValueNumber
//
PR_STATIC_CALLBACK(JSBool)
WinRegGetValueNumber(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsWinReg *nativeThis =
(nsWinReg*)JS_GetInstancePrivate(cx, obj, &WinRegClass, argv);
if (!nativeThis)
return JS_FALSE;
PRInt32 nativeRet;
nsAutoString b0;
nsAutoString b1;
*rval = JSVAL_NULL;
if(argc >= 2)
{
// public int getValueNumber ( String subKey,
// Number valueName);
ConvertJSValToStr(b0, cx, argv[0]);
ConvertJSValToStr(b1, cx, argv[1]);
if(NS_OK == nativeThis->GetValueNumber(b0, b1, &nativeRet))
{
*rval = INT_TO_JSVAL(nativeRet);
}
}
else
{
JS_ReportWarning(cx, "WinReg.GetValueNumber() parameters error");
}
return JS_TRUE;
}
//
// Native method SetValue
//
PR_STATIC_CALLBACK(JSBool)
WinRegSetValue(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsWinReg *nativeThis =
(nsWinReg*)JS_GetInstancePrivate(cx, obj, &WinRegClass, argv);
if (!nativeThis)
return JS_FALSE;
nsAutoString b0;
nsAutoString b1;
*rval = INT_TO_JSVAL(nsInstall::UNEXPECTED_ERROR);
if(argc >= 3)
{
// public int setValue ( String subKey,
// String valueName,
// nsWinRegItem *value);
ConvertJSValToStr(b0, cx, argv[0]);
ConvertJSValToStr(b1, cx, argv[1]);
// fix: this parameter is an object, not a string.
// A way needs to be figured out to convert the JSVAL to this object type
// ConvertJSValToStr(b2, cx, argv[2]);
// if(NS_OK != nativeThis->SetValue(b0, b1, b2, &nativeRet))
// {
// return JS_FALSE;
// }
// *rval = INT_TO_JSVAL(nativeRet);
}
else
{
JS_ReportWarning(cx, "WinReg.SetValue() parameters error");
}
return JS_TRUE;
}
//
// Native method GetValue
//
PR_STATIC_CALLBACK(JSBool)
WinRegGetValue(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsWinReg *nativeThis =
(nsWinReg*)JS_GetInstancePrivate(cx, obj, &WinRegClass, argv);
if (!nativeThis)
return JS_FALSE;
nsWinRegValue *nativeRet;
nsAutoString b0;
nsAutoString b1;
*rval = JSVAL_NULL;
if(argc >= 2)
{
// public int getValue ( String subKey,
// String valueName);
ConvertJSValToStr(b0, cx, argv[0]);
ConvertJSValToStr(b1, cx, argv[1]);
if(NS_OK == nativeThis->GetValue(b0, b1, &nativeRet))
{
*rval = INT_TO_JSVAL(nativeRet);
}
}
else
{
JS_ReportWarning(cx, "WinReg.GetValue() parameters error");
}
return JS_TRUE;
}
//
// WinReg constructor
//
PR_STATIC_CALLBACK(JSBool)
WinReg(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
return JS_FALSE;
}
static JSConstDoubleSpec winreg_constants[] =
{
{ nsWinReg::NS_HKEY_CLASSES_ROOT, "HKEY_CLASSES_ROOT" },
{ nsWinReg::NS_HKEY_CURRENT_USER, "HKEY_CURRENT_USER" },
{ nsWinReg::NS_HKEY_LOCAL_MACHINE, "HKEY_LOCAL_MACHINE" },
{ nsWinReg::NS_HKEY_USERS, "HKEY_USERS" },
{0}
};
//
// WinReg class methods
//
static JSFunctionSpec WinRegMethods[] =
{
{"setRootKey", WinRegSetRootKey, 1,0,0},
{"keyExists", WinRegKeyExists, 1,0,0},
{"valueExists", WinRegValueExists, 2,0,0},
{"isKeyWritable", WinRegIsKeyWritable, 1,0,0},
{"createKey", WinRegCreateKey, 2,0,0},
{"deleteKey", WinRegDeleteKey, 1,0,0},
{"deleteValue", WinRegDeleteValue, 2,0,0},
{"setValueString", WinRegSetValueString, 3,0,0},
{"getValueString", WinRegGetValueString, 2,0,0},
{"setValueNumber", WinRegSetValueNumber, 3,0,0},
{"getValueNumber", WinRegGetValueNumber, 2,0,0},
{"setValue", WinRegSetValue, 3,0,0},
{"getValue", WinRegGetValue, 2,0,0},
{"enumKeys", WinRegEnumKeys, 2,0,0},
{"enumValueNames", WinRegEnumValueNames, 2,0,0},
{nsnull,nsnull,0,0,0}
};
PRInt32
InitWinRegPrototype(JSContext *jscontext, JSObject *global, JSObject **winRegPrototype)
{
*winRegPrototype = JS_InitClass( jscontext, // context
global, // global object
nsnull, // parent proto
&WinRegClass, // JSClass
nsnull, // JSNative ctor
0, // ctor args
nsnull, // proto props
nsnull, // proto funcs
nsnull, // ctor props (static)
WinRegMethods); // ctor funcs (static)
if(nsnull == *winRegPrototype)
{
return NS_ERROR_FAILURE;
}
if(PR_FALSE == JS_DefineConstDoubles(jscontext, *winRegPrototype, winreg_constants))
return NS_ERROR_FAILURE;
return NS_OK;
}

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

@ -1,44 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (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/MPL/
*
* 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.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef __NS_JSWINREG_H__
#define __NS_JSWINREG_H__
PRInt32
InitWinRegPrototype(JSContext *jscontext, JSObject *global, JSObject **winRegPrototype);
#endif

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

@ -1,335 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (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/MPL/
*
* 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, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Douglas Turner <dougt@netscape.com>
* Pierre Phaneuf <pp@ludusdesign.com>
* Samir Gehani <sgehani@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsLoggingProgressNotifier.h"
#include "nsInstall.h"
#include "nsDirectoryService.h"
#include "nsDirectoryServiceDefs.h"
#include "nsAppDirectoryServiceDefs.h"
#include "nsILocalFile.h"
#include "nsNativeCharsetUtils.h"
#include "nspr.h"
#include "plstr.h"
#include "nsNetUtil.h"
#ifdef XP_WIN
#define snprintf _snprintf
#endif
#ifdef XP_MAC
#define INSTALL_LOG NS_LITERAL_CSTRING("Install Log")
#else
#define INSTALL_LOG NS_LITERAL_CSTRING("install.log")
#endif
#define _SMALL_TEXT_BUFFER_SIZE 64
#define _MEDIUM_TEXT_BUFFER_SIZE 1024
#define _LARGE_TEXT_BUFFER_SIZE 2048
nsLoggingProgressListener::nsLoggingProgressListener()
: mLogStream(0)
{
}
nsLoggingProgressListener::~nsLoggingProgressListener()
{
if (mLogStream)
{
NS_ERROR("We're being destroyed before script finishes!");
mLogStream->Close();
mLogStream = nsnull;
}
}
NS_IMPL_ISUPPORTS1(nsLoggingProgressListener, nsIXPIListener)
NS_IMETHODIMP
nsLoggingProgressListener::OnInstallStart(const PRUnichar *URL)
{
nsCOMPtr<nsIFile> iFile;
nsresult rv = NS_OK;
// Not in stub installer
if (!nsSoftwareUpdate::GetProgramDirectory())
{
nsCOMPtr<nsIProperties> dirSvc =
do_GetService(NS_DIRECTORY_SERVICE_CONTRACTID, &rv);
if (!dirSvc) return NS_ERROR_FAILURE;
dirSvc->Get(NS_OS_CURRENT_PROCESS_DIR, NS_GET_IID(nsIFile),
getter_AddRefs(iFile));
}
// In stub installer
else
{
rv = nsSoftwareUpdate::GetProgramDirectory()->Clone(
getter_AddRefs(iFile));
}
if (NS_FAILED(rv)) return rv;
if (!nsSoftwareUpdate::GetLogName())
rv = iFile->AppendNative(INSTALL_LOG);
else
rv = iFile->AppendNative(nsDependentCString(nsSoftwareUpdate::GetLogName()));
if (NS_FAILED(rv)) return rv;
// create log file if it doesn't exist (to work around a mac filespec bug)
PRBool bExists = PR_FALSE, bTryProfileDir = PR_FALSE, bWritable = PR_FALSE;
rv = iFile->Exists(&bExists);
if (NS_FAILED(rv)) return rv;
if (!bExists)
{
rv = iFile->Create(nsIFile::NORMAL_FILE_TYPE, 0644);
if (NS_FAILED(rv))
bTryProfileDir = PR_TRUE;
#ifdef XP_MAC
else
{
nsCOMPtr<nsILocalFileMac> iMacFile = do_QueryInterface(iFile);
iMacFile->SetFileType('TEXT');
iMacFile->SetFileCreator('R*ch');
}
#endif
}
if (!bTryProfileDir)
{
rv = iFile->IsWritable(&bWritable);
if (NS_FAILED(rv) || !bWritable)
bTryProfileDir = PR_TRUE;
}
if (bTryProfileDir && !nsSoftwareUpdate::GetProgramDirectory())
{
// failed to create the log file in the application directory
// so try to create the log file in the user's profile directory
// while we are not in the stub installer
nsCOMPtr<nsIProperties> dirSvc =
do_GetService(NS_DIRECTORY_SERVICE_CONTRACTID, &rv);
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
dirSvc->Get(NS_APP_USER_PROFILE_50_DIR, NS_GET_IID(nsIFile),
getter_AddRefs(iFile));
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
if (!nsSoftwareUpdate::GetLogName())
rv = iFile->AppendNative(INSTALL_LOG);
else
rv = iFile->AppendNative(nsDependentCString(nsSoftwareUpdate::GetLogName()));
if (NS_FAILED(rv)) return rv;
bExists = PR_FALSE;
bWritable = PR_FALSE;
rv = iFile->Exists(&bExists);
if (NS_FAILED(rv)) return rv;
if (!bExists)
{
rv = iFile->Create(nsIFile::NORMAL_FILE_TYPE, 0644);
if (NS_FAILED(rv)) return rv;
#ifdef XP_MAC
nsCOMPtr<nsILocalFileMac> iMacFile = do_QueryInterface(iFile);
iMacFile->SetFileType('TEXT');
iMacFile->SetFileCreator('R*ch');
#endif
}
rv = iFile->IsWritable(&bWritable);
if (NS_FAILED(rv) || !bWritable) return NS_ERROR_FAILURE;
}
rv = NS_NewLocalFileOutputStream(getter_AddRefs(mLogStream), iFile,
PR_WRONLY | PR_CREATE_FILE | PR_APPEND,
0744);
if (NS_FAILED(rv)) return rv;
char* time;
GetTime(&time);
char buffer[_LARGE_TEXT_BUFFER_SIZE];
PRUint32 dummy;
snprintf(buffer, sizeof(buffer), "-------------------------------------------------------------------------------\n%s -- %s\n-------------------------------------------------------------------------------\n\n", NS_ConvertUTF16toUTF8(URL).get(), time);
PL_strfree(time);
rv = mLogStream->Write(buffer, strlen(buffer), &dummy);
if (NS_FAILED(rv)) return rv;
return NS_OK;
}
NS_IMETHODIMP
nsLoggingProgressListener::OnInstallDone(const PRUnichar *aURL, PRInt32 aStatus)
{
nsresult rv;
PRUint32 dummy;
char buffer[_SMALL_TEXT_BUFFER_SIZE];
if (mLogStream == nsnull) return NS_ERROR_NULL_POINTER;
rv = mLogStream->Write("\n", 1, &dummy);
if (NS_FAILED(rv)) return rv;
switch (aStatus)
{
case nsInstall::SUCCESS:
snprintf(buffer, sizeof(buffer), " Install completed successfully");
break;
case nsInstall::REBOOT_NEEDED:
snprintf(buffer, sizeof(buffer), " Install completed successfully, restart required");
break;
case nsInstall::INSTALL_CANCELLED:
snprintf(buffer, sizeof(buffer), " Install cancelled by script");
break;
case nsInstall::USER_CANCELLED:
snprintf(buffer, sizeof(buffer), " Install cancelled by user");
break;
default:
snprintf(buffer, sizeof(buffer), " Install **FAILED** with error %d", aStatus);
break;
}
rv = mLogStream->Write(buffer, strlen(buffer), &dummy);
if (NS_FAILED(rv)) return rv;
char* time;
GetTime(&time);
snprintf(buffer, sizeof(buffer), " -- %s\n\n", time);
rv = mLogStream->Write(buffer, strlen(buffer), &dummy);
PL_strfree(time);
if (NS_FAILED(rv)) return rv;
mLogStream->Close();
mLogStream = nsnull;
return NS_OK;
}
NS_IMETHODIMP
nsLoggingProgressListener::OnPackageNameSet(const PRUnichar *URL, const PRUnichar* UIPackageName, const PRUnichar* aVersion)
{
if (mLogStream == nsnull) return NS_ERROR_NULL_POINTER;
char buffer[_MEDIUM_TEXT_BUFFER_SIZE];
PRUint32 dummy;
nsresult rv;
nsCString name;
nsCString version;
nsCString uline;
nsAutoString autostrName(UIPackageName);
nsAutoString autostrVersion(aVersion);
NS_CopyUnicodeToNative(autostrName, name);
NS_CopyUnicodeToNative(autostrVersion, version);
uline.SetCapacity(name.Length());
for ( unsigned int i=0; i < name.Length(); ++i)
uline.Append('-');
snprintf(buffer, sizeof(buffer), " %s (version %s)\n %s\n\n",
name.get(), version.get(), uline.get());
rv = mLogStream->Write(buffer, strlen(buffer), &dummy);
return rv;
}
NS_IMETHODIMP
nsLoggingProgressListener::OnItemScheduled(const PRUnichar* message )
{
return NS_OK;
}
NS_IMETHODIMP
nsLoggingProgressListener::OnFinalizeProgress(const PRUnichar* aMessage, PRInt32 aItemNum, PRInt32 aTotNum )
{
nsCString messageConverted;
nsresult rv;
char buffer[_MEDIUM_TEXT_BUFFER_SIZE];
PRUint32 dummy;
// this Lossy conversion is safe because the input source came from a
// similar fake-ascii-to-not-really-unicode conversion.
// If you use NS_CopyUnicodeToNative(), it'll crash under a true JA WinXP
// system as opposed to a EN winXP system changed to JA.
messageConverted.AssignWithConversion(aMessage);
if (mLogStream == nsnull) return NS_ERROR_NULL_POINTER;
snprintf(buffer, sizeof(buffer), " [%d/%d]\t%s\n", aItemNum, aTotNum,
messageConverted.get());
rv = mLogStream->Write(buffer, strlen(buffer), &dummy);
return rv;
}
void
nsLoggingProgressListener::GetTime(char** aString)
{
PRExplodedTime et;
char line[256];
PR_ExplodeTime(PR_Now(), PR_LocalTimeParameters, &et);
PR_FormatTimeUSEnglish(line, sizeof(line), "%Y-%m-%d %H:%M:%S", &et);
*aString = PL_strdup(line);
}
NS_IMETHODIMP
nsLoggingProgressListener::OnLogComment(const PRUnichar* aComment)
{
nsCString commentConverted;
nsresult rv;
char buffer[_MEDIUM_TEXT_BUFFER_SIZE];
PRUint32 dummy;
NS_CopyUnicodeToNative(nsDependentString(aComment), commentConverted);
if (mLogStream == nsnull) return NS_ERROR_NULL_POINTER;
snprintf(buffer, sizeof(buffer), " ** %s\n", commentConverted.get());
rv = mLogStream->Write(buffer, strlen(buffer), &dummy);
return rv;
}

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

@ -1,68 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (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/MPL/
*
* 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, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Daniel Veditz <dveditz@netscape.com>
* Douglas Turner <dougt@netscape.com>
* Samir Gehani <sgehani@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsLoggingProgressNotifier_H__
#define nsLoggingProgressNotifier_H__
#include "nsCOMPtr.h"
#include "nsIFile.h"
#include "nsIOutputStream.h"
#include "nsIXPINotifier.h"
class nsLoggingProgressListener : public nsIXPIListener
{
public:
nsLoggingProgressListener();
~nsLoggingProgressListener();
NS_DECL_ISUPPORTS
// nsIXPIListener interfaces
NS_DECL_NSIXPILISTENER
private:
void GetTime(char** aString);
nsCOMPtr<nsIOutputStream> mLogStream;
};
#endif

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

@ -1,556 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (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/MPL/
*
* 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, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2000
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Daniel Veditz <dveditz@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "prprf.h"
#include "nsCRT.h"
#include "nsRegisterItem.h"
#include "nsInstallResources.h"
#include "nsNetUtil.h"
#include "nsXPIDLString.h"
#include "nsReadableUtils.h"
#include "nsInstallTrigger.h"
#include "nsIChromeRegistry.h"
#include "nsIDirectoryService.h"
#include "nsDirectoryServiceDefs.h"
#include "nsAppDirectoryServiceDefs.h"
#include "nsNativeCharsetUtils.h"
nsRegisterItem:: nsRegisterItem( nsInstall* inInstall,
nsIFile* chrome,
PRUint32 chromeType,
const char* path )
: nsInstallObject(inInstall), mChrome(chrome), mChromeType(chromeType), mPath(path)
{
MOZ_COUNT_CTOR(nsRegisterItem);
}
nsRegisterItem::~nsRegisterItem()
{
MOZ_COUNT_DTOR(nsRegisterItem);
}
#if defined(XP_WIN)
#include <windows.h>
#endif
static nsresult
hack_nsIFile2URL(nsIFile* file, char * *aURL)
{
nsresult rv;
nsCAutoString ePath;
rv = file->GetNativePath(ePath);
if (NS_FAILED(rv)) return rv;
#if defined(XP_WIN) || defined(XP_OS2)
// Replace \ with / to convert to an url
char* s;
ePath.BeginWriting(s);
while (*s) {
#ifndef XP_OS2
// We need to call IsDBCSLeadByte because
// Japanese windows can have 0x5C in the sencond byte
// of a Japanese character, for example 0x8F 0x5C is
// one Japanese character
if(::IsDBCSLeadByte(*s) && *(s+1) != nsnull) {
s++;
} else
#endif
if (*s == '\\')
*s = '/';
s++;
}
#endif
// Escape the path with the directory mask
nsCAutoString tmp(ePath);
tmp.ReplaceChar(":", '|');
nsCAutoString escPath("file://");
escPath += tmp;
// rv = nsURLEscape(ePath,nsIIOService::url_Directory + nsIIOService::url_Forced, escPath);
// if (NS_SUCCEEDED(rv)) {
PRBool dir;
rv = file->IsDirectory(&dir);
if (NS_SUCCEEDED(rv) && dir && escPath[escPath.Length() - 1] != '/') {
// make sure we have a trailing slash
escPath += "/";
}
*aURL = ToNewCString(escPath);
if (*aURL == nsnull) {
return NS_ERROR_OUT_OF_MEMORY;
}
// }
return rv;
}
void nsRegisterItem::LogErrorWithFilename(const nsAString& aMessage, nsresult code, nsILocalFile* localFile)
{
nsCAutoString path;
nsAutoString unipath;
LogError(aMessage, code);
localFile->GetNativePath(path);
if(NS_SUCCEEDED(NS_CopyNativeToUnicode(path, unipath)))
mInstall->LogComment(unipath);
}
void nsRegisterItem::LogError(const nsAString& aMessage, nsresult code)
{
char resultString[12];
PR_snprintf(resultString, 12, "0x%lx", code);
mInstall->LogComment(aMessage + NS_LITERAL_STRING(" - nsresult code: ") +
NS_ConvertASCIItoUTF16(resultString));
}
PRInt32 nsRegisterItem::Prepare()
{
// The chrome must exist
PRBool exists;
nsresult rv = mChrome->Exists(&exists);
if (NS_FAILED(rv))
return nsInstall::UNEXPECTED_ERROR;
if (!exists)
return nsInstall::DOES_NOT_EXIST;
// Are we dealing with a directory (flat chrome) or an archive?
PRBool isDir;
rv = mChrome->IsDirectory(&isDir);
if (NS_FAILED(rv))
return nsInstall::UNEXPECTED_ERROR;
// Can we construct a resource: URL or do we need a file: URL instead?
// find the xpcom directory and see if mChrome is a child
PRBool isChild = PR_FALSE;
mProgDir = nsSoftwareUpdate::GetProgramDirectory();
if (!mProgDir)
{
// not in the wizard, so ask the directory service where it is
nsCOMPtr<nsIProperties> dirService(
do_GetService(NS_DIRECTORY_SERVICE_CONTRACTID, &rv));
if(NS_SUCCEEDED(rv))
{
NS_ASSERTION(dirService,"directory service lied to us");
rv = dirService->Get(NS_XPCOM_CURRENT_PROCESS_DIR,
NS_GET_IID(nsIFile), getter_AddRefs(mProgDir));
}
}
if (NS_SUCCEEDED(rv))
{
NS_ASSERTION(mProgDir,"NS_SUCCESS but no mProgDir");
rv = mProgDir->Contains(mChrome, PR_TRUE, &isChild);
if (NS_FAILED(rv))
return nsInstall::UNEXPECTED_ERROR;
}
else
return nsInstall::UNEXPECTED_ERROR;
// Either way we need the file: URL to the chrome
nsXPIDLCString localURL;
rv = GetURLFromIFile( mChrome, getter_Copies(localURL) );
if (NS_FAILED(rv))
return nsInstall::UNEXPECTED_ERROR;
// see what kind of URL we have to construct
if (!isChild)
{
// Not relative so use the file:// URL we got above
PRInt32 urlLen = strlen(localURL) + mPath.Length();
if (isDir)
{
// "flat" chrome, urlLen is suffient
mURL.SetCapacity( urlLen );
}
else
{
// archive, add room for jar: syntax (over by one, but harmless)
mURL.SetCapacity( urlLen + sizeof("jar:") + sizeof('!') );
mURL = "jar:";
}
mURL.Append(localURL);
}
else
{
// we can construct a resource: URL to chrome in a subdir
nsXPIDLCString binURL;
rv = GetURLFromIFile( mProgDir, getter_Copies(binURL) );
if (NS_FAILED(rv))
return nsInstall::UNEXPECTED_ERROR;
PRInt32 binLen = strlen(binURL);
const char *subURL = localURL + binLen;
PRInt32 padding = sizeof("resource:/") + sizeof("jar:!/");
mURL.SetCapacity( strlen(subURL) + mPath.Length() + padding );
if (!isDir)
mURL = "jar:";
mURL.Append("resource:/");
mURL.Append(subURL);
}
if (!isDir)
{
// need jar: URL closing bang-slash
mURL.Append("!/");
}
else
{
// Necko should already slash-terminate directory file:// URLs
NS_ASSERTION(mURL[mURL.Length()-1] == '/', "Necko changed the rules");
}
// add on "extra" subpath to new content.rdf
mURL.Append(mPath);
return nsInstall::SUCCESS;
}
PRInt32 nsRegisterItem::Complete()
{
nsresult rv = NS_OK;
PRInt32 result = nsInstall::SUCCESS;
CHROMEREG_IFACE* reg = mInstall->GetChromeRegistry();
#ifndef MOZ_XUL_APP
PRBool isProfile = mChromeType & CHROME_PROFILE;
#endif
if ( reg && !(mChromeType & CHROME_DELAYED) )
{
#ifdef MOZ_XUL_APP
nsCOMPtr<nsIURI> baseuri;
rv = NS_NewURI(getter_AddRefs(baseuri), mURL);
if (NS_FAILED(rv)) {
LogError(NS_LITERAL_STRING("NS_NewURI failed."), rv);
}
else {
nsCOMPtr<nsIURI> manifesturi;
rv = NS_NewURI(getter_AddRefs(manifesturi),
NS_LITERAL_CSTRING("resource:///chrome/xpinstall.manifest"));
if (NS_FAILED(rv)) {
LogError(NS_LITERAL_STRING("NS_NewURI failed."), rv);
}
else {
PRBool skinOnly = (mChromeType & CHROME_ALL) == CHROME_SKIN;
rv = reg->ProcessContentsManifest(baseuri, manifesturi,
baseuri, PR_TRUE,
skinOnly);
if (NS_FAILED(rv)) {
LogError(NS_LITERAL_STRING("ProcessContentsManifest failed."), rv);
}
reg->CheckForNewChrome();
}
}
#else
// We can register right away
if (mChromeType & CHROME_SKIN)
rv = reg->InstallSkin(mURL.get(), isProfile, PR_TRUE);
if (NS_FAILED(rv)) {
LogError(NS_LITERAL_STRING("InstallSkin() failed."), rv);
}
if (NS_SUCCEEDED(rv) && (mChromeType & CHROME_LOCALE))
rv = reg->InstallLocale(mURL.get(), isProfile);
if (NS_FAILED(rv)) {
LogError(NS_LITERAL_STRING("InstallLocale() failed."), rv);
}
if (NS_SUCCEEDED(rv) && (mChromeType & CHROME_CONTENT))
rv = reg->InstallPackage(mURL.get(), isProfile);
if (NS_FAILED(rv)) {
LogError(NS_LITERAL_STRING("InstallPackage() failed."), rv);
}
#endif
}
else
{
// Either script asked for delayed chrome or we can't find
// the chrome registry to do it now.
// construct a reference to the magic file
PRFileDesc* fd = nsnull;
nsCOMPtr<nsIFile> tmp;
PRBool bExists = PR_FALSE;
if (!nsSoftwareUpdate::GetProgramDirectory()) // not in the stub installer
{
nsCOMPtr<nsIProperties> directoryService =
do_GetService(NS_DIRECTORY_SERVICE_CONTRACTID, &rv);
if (NS_FAILED(rv)) {
LogError(NS_LITERAL_STRING("failed to get directory service."), rv);
}
if (NS_SUCCEEDED(rv) && directoryService)
{
rv = directoryService->Get(NS_APP_CHROME_DIR,
NS_GET_IID(nsIFile),
getter_AddRefs(tmp));
if(NS_FAILED(rv))
{
LogError(NS_LITERAL_STRING("failed get application chrome directory."), rv);
result = nsInstall::CHROME_REGISTRY_ERROR;
return result;
}
}
}
else
{
rv = nsSoftwareUpdate::GetProgramDirectory()->Clone(getter_AddRefs(tmp));
if (NS_SUCCEEDED(rv))
{
tmp->AppendNative(INSTALL_CHROME_DIR);
} else {
LogError(NS_LITERAL_STRING("failed to clone program directory. (not critical)"), rv);
}
}
nsCOMPtr<nsILocalFile> startupFile( do_QueryInterface(tmp, &rv) );
if (NS_SUCCEEDED(rv))
{
rv = startupFile->Exists(&bExists);
if(NS_FAILED(rv))
{
LogErrorWithFilename(NS_LITERAL_STRING("directory existance check failed."), rv, startupFile);
}
if (NS_SUCCEEDED(rv) && !bExists)
rv = startupFile->Create(nsIFile::DIRECTORY_TYPE, 0755);
if (NS_SUCCEEDED(rv))
{
rv = startupFile->AppendNative(NS_LITERAL_CSTRING("installed-chrome.txt"));
if (NS_SUCCEEDED(rv))
{
rv = startupFile->OpenNSPRFileDesc(
PR_CREATE_FILE | PR_WRONLY,
0744,
&fd);
if(NS_FAILED(rv))
{
LogErrorWithFilename(NS_LITERAL_STRING("opening of installed-chrome.txt failed."), rv, startupFile);
}
} else {
LogError(NS_LITERAL_STRING("String append failed."), rv);
}
} else {
LogErrorWithFilename(NS_LITERAL_STRING("startup directory creation failed."), rv, startupFile);
}
}
if ( NS_SUCCEEDED(rv) && fd )
{
PR_Seek(fd, 0, PR_SEEK_END);
const char* location = (mChromeType & CHROME_PROFILE) ? "profile" : "install";
if (NS_SUCCEEDED(rv)/* && path*/)
{
PRInt32 written, actual;
char* installStr = nsnull;
// this looks redundant, but a single registerChrome()
// call can register all three types.
if (mChromeType & CHROME_SKIN)
{
installStr = PR_smprintf("skin,%s,url,%s\n",
location, mURL.get());
if (installStr)
{
actual = strlen(installStr);
written = PR_Write(fd, installStr, actual);
if ( written != actual )
{
LogErrorWithFilename(NS_LITERAL_STRING("writing to installed-chrome.txt failed."), rv, startupFile);
result = nsInstall::CHROME_REGISTRY_ERROR;
}
PR_smprintf_free(installStr);
}
else
result = nsInstall::OUT_OF_MEMORY;
}
if (mChromeType & CHROME_LOCALE)
{
installStr = PR_smprintf("locale,%s,url,%s\n",
location, mURL.get());
if (installStr)
{
actual = strlen(installStr);
written = PR_Write(fd, installStr, actual);
if ( written != actual )
{
LogErrorWithFilename(NS_LITERAL_STRING("writing to installed-chrome.txt failed."), rv, startupFile);
result = nsInstall::CHROME_REGISTRY_ERROR;
}
PR_smprintf_free(installStr);
}
else
result = nsInstall::OUT_OF_MEMORY;
}
if (mChromeType & CHROME_CONTENT)
{
installStr = PR_smprintf("content,%s,url,%s\n",
location, mURL.get());
if (installStr)
{
actual = strlen(installStr);
written = PR_Write(fd, installStr, actual);
if ( written != actual )
{
LogErrorWithFilename(NS_LITERAL_STRING("writing to installed-chrome.txt failed."), rv, startupFile);
result = nsInstall::CHROME_REGISTRY_ERROR;
}
PR_smprintf_free(installStr);
}
else
result = nsInstall::OUT_OF_MEMORY;
}
}
PR_Close(fd);
#ifdef MOZ_XUL_APP
// app-chrome.manifest is not regenerated if it exists
rv = startupFile->SetNativeLeafName(NS_LITERAL_CSTRING("app-chrome.manifest"));
if (NS_SUCCEEDED(rv))
startupFile->Remove(PR_FALSE);
#endif
}
else
{
LogError(NS_LITERAL_STRING("opening of installed-chrome.txt failed."), rv);
result = nsInstall::CHROME_REGISTRY_ERROR;
}
}
if (NS_FAILED(rv))
{
LogError(NS_LITERAL_STRING("Failed to register chrome."), rv);
result = nsInstall::CHROME_REGISTRY_ERROR;
}
return result;
}
void nsRegisterItem::Abort()
{
// nothing to undo
}
char* nsRegisterItem::toString()
{
char* rsrcVal = nsnull;
if (!mInstall)
return nsnull;
char* buffer = new char[1024];
if (!buffer)
return nsnull;
buffer[0] = '\0';
switch (mChromeType & CHROME_ALL)
{
case CHROME_SKIN:
rsrcVal = mInstall->GetResourcedString(
NS_LITERAL_STRING("RegSkin"));
break;
case CHROME_LOCALE:
rsrcVal = mInstall->GetResourcedString(
NS_LITERAL_STRING("RegLocale"));
break;
case CHROME_CONTENT:
rsrcVal = mInstall->GetResourcedString(
NS_LITERAL_STRING("RegContent"));
break;
default:
rsrcVal = mInstall->GetResourcedString(
NS_LITERAL_STRING("RegPackage"));
break;
}
if (rsrcVal)
{
PR_snprintf(buffer, 1024, rsrcVal, mURL.get());
nsCRT::free(rsrcVal);
}
return buffer;
}
PRBool
nsRegisterItem::CanUninstall()
{
return PR_FALSE;
}
PRBool
nsRegisterItem::RegisterPackageNode()
{
return PR_FALSE;
}
nsresult
nsRegisterItem::GetURLFromIFile(nsIFile* aFile, char** aOutURL)
{
if (!aFile || !aOutURL)
{
NS_WARNING("bogus arg passed to nsRegisterItem::GetURLFromIFile()");
return NS_ERROR_NULL_POINTER;
}
*aOutURL = nsnull;
// try to use Necko to create the URL; if that fails (as
// it will for the install wizards which don't have Necko)
// then use warren's local hack.
nsCAutoString spec;
nsresult rv = NS_GetURLSpecFromFile(aFile, spec);
if (NS_FAILED(rv))
rv = hack_nsIFile2URL(aFile, aOutURL);
else {
*aOutURL = ToNewCString(spec);
if (!*aOutURL)
rv = NS_ERROR_OUT_OF_MEMORY;
}
return rv;
}

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

@ -1,84 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (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/MPL/
*
* 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, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Daniel Veditz <dveditz@netscape.com>
* Douglas Turner <dougt@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsRegisterItem_h__
#define nsRegisterItem_h__
#include "prtypes.h"
#include "nsString.h"
#include "nsInstall.h"
#include "nsInstallObject.h"
class nsRegisterItem : public nsInstallObject
{
public:
nsRegisterItem( nsInstall* install,
nsIFile* chrome,
PRUint32 chromeType,
const char* path );
virtual ~nsRegisterItem();
PRInt32 Prepare();
PRInt32 Complete();
void Abort();
char* toString();
PRBool CanUninstall();
PRBool RegisterPackageNode();
private:
nsresult GetURLFromIFile(nsIFile *aFile, char **aOutURL);
/* write a message to install.log and include the nsresult code in hexadecimal form */
void LogError(const nsAString& aMessage, nsresult code);
/* same as above, but also write the filename */
void LogErrorWithFilename(const nsAString& aMessage, nsresult code, nsILocalFile *localFile);
nsCString mURL;
nsCOMPtr<nsIFile> mChrome;
PRUint32 mChromeType;
nsCOMPtr<nsIFile> mProgDir;
nsCString mPath;
};
#endif /* nsRegisterItem_h__ */

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

@ -20,6 +20,7 @@
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Dave Townsend <dtownsend@oxymoronical.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
@ -43,465 +44,26 @@
#include "nsIComponentRegistrar.h"
#include "nsIServiceManager.h"
#include "nsICategoryManager.h"
#include "nsCOMPtr.h"
#include "nsCRT.h"
#include "nsIObserverService.h"
#include "nspr.h"
#include "prlock.h"
#include "nsXPIDLString.h"
#include "NSReg.h"
#include "VerReg.h"
#include "nsIDirectoryService.h"
#include "nsDirectoryServiceDefs.h"
#include "nsAppDirectoryServiceDefs.h"
#include "nsInstall.h"
#include "nsSoftwareUpdateIIDs.h"
#include "nsSoftwareUpdate.h"
#include "nsSoftwareUpdateRun.h"
#include "nsInstallTrigger.h"
#include "nsInstallVersion.h"
#include "ScheduledTasks.h"
#include "InstallCleanupDefines.h"
#include "nsXPInstallManager.h"
#include "nsTopProgressNotifier.h"
#include "nsLoggingProgressNotifier.h"
#include "nsProcess.h"
/* For Javascript Namespace Access */
#include "nsDOMCID.h"
#include "nsIServiceManager.h"
#include "nsIScriptNameSpaceManager.h"
#include "nsIScriptExternalNameSet.h"
#include "nsIChromeRegistry.h"
#include "nsCURILoader.h"
extern "C" void PR_CALLBACK RunChromeInstallOnThread(void *data);
////////////////////////////////////////////////////////////////////////////////
// Globals
////////////////////////////////////////////////////////////////////////////////
nsSoftwareUpdate* nsSoftwareUpdate::mInstance = nsnull;
nsCOMPtr<nsIFile> nsSoftwareUpdate::mProgramDir = nsnull;
char* nsSoftwareUpdate::mLogName = nsnull;
PRBool nsSoftwareUpdate::mNeedCleanup = PR_FALSE;
nsSoftwareUpdate *
nsSoftwareUpdate::GetInstance()
{
if (mInstance == nsnull)
mInstance = new nsSoftwareUpdate();
NS_IF_ADDREF(mInstance);
return mInstance;
}
nsSoftwareUpdate::nsSoftwareUpdate()
: mInstalling(PR_FALSE),
mMasterListener(0),
mReg(0)
{
mLock = PR_NewLock();
/***************************************/
/* Startup the Version Registry */
/***************************************/
NR_StartupRegistry(); /* startup the registry; if already started, this will essentially be a noop */
nsresult rv;
nsCOMPtr<nsIProperties> directoryService =
do_GetService(NS_DIRECTORY_SERVICE_CONTRACTID, &rv);
if(!directoryService) return;
nsCOMPtr<nsILocalFile> dir;
directoryService->Get(NS_XPCOM_CURRENT_PROCESS_DIR, NS_GET_IID(nsILocalFile), getter_AddRefs(dir));
if (dir)
{
nsCAutoString nativePath;
dir->GetNativePath(nativePath);
// EVIL version registry does not take a nsIFile.;
VR_SetRegDirectory( nativePath.get() );
}
/***************************************/
/* Add this as a shutdown observer */
/***************************************/
nsCOMPtr<nsIObserverService> observerService =
do_GetService("@mozilla.org/observer-service;1", &rv);
if (NS_SUCCEEDED(rv))
observerService->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, PR_FALSE);
}
nsSoftwareUpdate::~nsSoftwareUpdate()
{
PR_Lock(mLock);
nsInstallInfo* element;
for (PRInt32 i=0; i < mJarInstallQueue.Count(); i++)
{
element = (nsInstallInfo*)mJarInstallQueue.ElementAt(i);
//FIX: need to add to registry....
delete element;
}
mJarInstallQueue.Clear();
PR_Unlock(mLock);
PR_DestroyLock(mLock);
NR_ShutdownRegistry();
NS_IF_RELEASE (mMasterListener);
mInstance = nsnull;
PR_FREEIF(mLogName);
}
//------------------------------------------------------------------------
// nsISupports implementation
//------------------------------------------------------------------------
NS_IMPL_THREADSAFE_ISUPPORTS3(nsSoftwareUpdate,
nsISoftwareUpdate,
nsPIXPIStubHook,
nsIObserver)
void
nsSoftwareUpdate::Shutdown()
{
if (mNeedCleanup)
{
// Create a non-blocking process to run the native platform cleanup utility
nsresult rv;
nsCOMPtr<nsILocalFile> pathToCleanupUtility;
//Get the program directory
nsCOMPtr<nsIProperties> directoryService =
do_GetService(NS_DIRECTORY_SERVICE_CONTRACTID, &rv);
if (nsSoftwareUpdate::GetProgramDirectory()) // In the stub installer
{
nsCOMPtr<nsIFile> tmp;
rv = nsSoftwareUpdate::GetProgramDirectory()->Clone(getter_AddRefs(tmp));
pathToCleanupUtility = do_QueryInterface(tmp);
}
else
{
rv = directoryService->Get(NS_APP_INSTALL_CLEANUP_DIR,
NS_GET_IID(nsIFile),
getter_AddRefs(pathToCleanupUtility));
}
NS_ASSERTION(pathToCleanupUtility,"No path to cleanup utility in nsSoftwareUpdate::Shutdown()");
//Create the Process framework
pathToCleanupUtility->AppendNative(CLEANUP_UTIL);
nsCOMPtr<nsIProcess> cleanupProcess = do_CreateInstance(NS_PROCESS_CONTRACTID);
rv = cleanupProcess->Init(pathToCleanupUtility);
if (NS_SUCCEEDED(rv))
{
//Run the cleanup utility as a NON-blocking process
rv = cleanupProcess->Run(PR_FALSE, nsnull, 0, nsnull);
}
}
}
NS_IMETHODIMP nsSoftwareUpdate::Observe(nsISupports *aSubject,
const char *aTopic,
const PRUnichar *aData)
{
if (!nsCRT::strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID))
Shutdown();
return NS_OK;
}
NS_IMETHODIMP
nsSoftwareUpdate::RegisterListener(nsIXPIListener *aListener)
{
// once you register a Listener, you can not remove it.
// This should get changed at some point.
if (!mMasterListener)
CreateMasterListener();
if (!mMasterListener)
return NS_ERROR_FAILURE;
mMasterListener->RegisterListener(aListener);
return NS_OK;
}
NS_IMETHODIMP
nsSoftwareUpdate::GetMasterListener(nsIXPIListener **aListener)
{
NS_ASSERTION(aListener, "getter has invalid return pointer");
if (!aListener)
return NS_ERROR_NULL_POINTER;
if (!mMasterListener)
CreateMasterListener();
if (!mMasterListener)
return NS_ERROR_FAILURE;
NS_ADDREF (mMasterListener);
*aListener = mMasterListener;
return NS_OK;
}
NS_IMETHODIMP
nsSoftwareUpdate::SetActiveListener(nsIXPIListener *aListener)
{
if (!mMasterListener)
CreateMasterListener();
if (!mMasterListener)
return NS_ERROR_FAILURE;
mMasterListener->SetActiveListener (aListener);
return NS_OK;
}
void nsSoftwareUpdate::CreateMasterListener()
{
mMasterListener = new nsTopProgressListener;
if (mMasterListener)
{
NS_ADDREF(mMasterListener);
nsLoggingProgressListener *logger = new nsLoggingProgressListener();
mMasterListener->RegisterListener(logger);
}
}
NS_IMETHODIMP
nsSoftwareUpdate::InstallJar( nsIFile* aLocalFile,
const PRUnichar* aURL,
const PRUnichar* aArguments,
nsIPrincipal* aPrincipal,
PRUint32 flags,
nsIXPIListener* aListener)
{
if ( !aLocalFile )
return NS_ERROR_NULL_POINTER;
// we want to call this with or without a chrome registry
nsInstallInfo *info = new nsInstallInfo( 0, aLocalFile, aURL, aArguments, aPrincipal,
flags, aListener);
if (!info)
return NS_ERROR_OUT_OF_MEMORY;
PR_Lock(mLock);
mJarInstallQueue.AppendElement( info );
PR_Unlock(mLock);
RunNextInstall();
return NS_OK;
}
NS_IMETHODIMP
nsSoftwareUpdate::InstallChrome( PRUint32 aType,
nsIFile* aFile,
const PRUnichar* URL,
const PRUnichar* aName,
PRBool aSelect,
nsIXPIListener* aListener)
{
nsInstallInfo *info = new nsInstallInfo( aType,
aFile,
URL,
aName,
nsnull,
(PRUint32)aSelect,
aListener);
if (!info)
return NS_ERROR_OUT_OF_MEMORY;
if (!info->GetChromeRegistry() ||
#ifdef MOZ_XUL_APP
!info->GetExtensionManager()
#else
info->GetFileJARSpec().IsEmpty()
#endif
) {
delete info;
return NS_ERROR_FAILURE;
}
PR_CreateThread(PR_USER_THREAD,
RunChromeInstallOnThread,
(void*)info,
PR_PRIORITY_NORMAL,
PR_GLOBAL_THREAD,
PR_UNJOINABLE_THREAD,
0);
return NS_OK;
}
void
nsSoftwareUpdate::InstallJarCallBack()
{
PR_Lock(mLock);
if (mJarInstallQueue.Count() != 0) // paranoia
{
nsInstallInfo *nextInstall = (nsInstallInfo*)mJarInstallQueue.ElementAt(0);
if (nextInstall != nsnull)
delete nextInstall;
mJarInstallQueue.RemoveElementAt(0);
}
mInstalling = PR_FALSE;
PR_Unlock(mLock);
RunNextInstall();
}
nsresult
nsSoftwareUpdate::RunNextInstall()
{
nsresult rv = NS_OK;
nsInstallInfo* info = nsnull;
PR_Lock(mLock);
// make sure master master listener exists
if (!mMasterListener)
CreateMasterListener();
if (!mInstalling)
{
if ( mJarInstallQueue.Count() > 0 )
{
info = (nsInstallInfo*)mJarInstallQueue.ElementAt(0);
if ( info )
mInstalling = PR_TRUE;
else
{
// bogus elements got into the queue
NS_ERROR("leaks remaining nsInstallInfos, please file bug!");
rv = NS_ERROR_NULL_POINTER;
VR_Close();
}
}
else
{
// nothing more to do
VR_Close();
}
}
PR_Unlock(mLock);
// make sure to RunInstall() outside of locked section due to callbacks
if (info)
RunInstall( info );
return rv;
}
NS_IMETHODIMP
nsSoftwareUpdate::StubInitialize(nsIFile *aDir, const char* logName)
{
if ( !aDir )
return NS_ERROR_NULL_POINTER;
// fix GetFolder return path
nsresult rv = aDir->Clone(getter_AddRefs(mProgramDir));
// make sure registry updates go to the right place
nsCAutoString tempPath;
rv = aDir->GetNativePath(tempPath);
if (NS_SUCCEEDED(rv))
VR_SetRegDirectory( tempPath.get() );
// Optionally set logfile leafname
if (logName)
{
mLogName = PL_strdup(logName);
if (!mLogName)
return NS_ERROR_OUT_OF_MEMORY;
}
return rv;
}
////////////////////////////////////////////////////////////////////////////////
// nsSoftwareUpdateNameSet
////////////////////////////////////////////////////////////////////////////////
nsSoftwareUpdateNameSet::nsSoftwareUpdateNameSet()
{
}
nsSoftwareUpdateNameSet::~nsSoftwareUpdateNameSet()
{
}
NS_IMPL_ISUPPORTS1(nsSoftwareUpdateNameSet, nsIScriptExternalNameSet)
NS_IMETHODIMP
nsSoftwareUpdateNameSet::InitializeNameSet(nsIScriptContext* aScriptContext)
{
nsresult result = NS_OK;
result = NS_InitInstallVersionClass(aScriptContext, nsnull);
if (NS_FAILED(result)) return result;
result = NS_InitInstallTriggerGlobalClass(aScriptContext, nsnull);
return result;
}
#include "nsSoftwareUpdateIIDs.h"
#include "nsInstallTrigger.h"
#include "nsXPInstallManager.h"
//----------------------------------------------------------------------
// Functions used to create new instances of a given object by the
// generic factory.
NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsSoftwareUpdate,
nsSoftwareUpdate::GetInstance)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsInstallTrigger)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsInstallVersion)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsXPInstallManager)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsSoftwareUpdateNameSet)
//----------------------------------------------------------------------
#define NS_SOFTWAREUPDATENAMESET_CID \
{ 0xcde48010, 0x9494, 0x4a73, \
{ 0x96, 0x9a, 0x26, 0x33, 0x50, 0x0, 0x70, 0xde }}
#define NS_SOFTWAREUPDATENAMESET_CONTRACTID \
"@mozilla.org/xpinstall/softwareupdatenameset;1"
static NS_METHOD
RegisterSoftwareUpdate( nsIComponentManager *aCompMgr,
RegisterInstallTrigger( nsIComponentManager *aCompMgr,
nsIFile *aPath,
const char *registryLocation,
const char *componentType,
@ -514,12 +76,6 @@ RegisterSoftwareUpdate( nsIComponentManager *aCompMgr,
NS_ENSURE_SUCCESS(rv, rv);
nsXPIDLCString previous;
rv = catman->AddCategoryEntry(JAVASCRIPT_GLOBAL_CONSTRUCTOR_CATEGORY,
"InstallVersion",
NS_INSTALLVERSIONCOMPONENT_CONTRACTID,
PR_TRUE, PR_TRUE, getter_Copies(previous));
NS_ENSURE_SUCCESS(rv, rv);
rv = catman->AddCategoryEntry(JAVASCRIPT_GLOBAL_PROPERTY_CATEGORY,
"InstallTrigger",
NS_INSTALLTRIGGERCOMPONENT_CONTRACTID,
@ -533,23 +89,11 @@ RegisterSoftwareUpdate( nsIComponentManager *aCompMgr,
// The list of components we register
static const nsModuleComponentInfo components[] =
{
{ "SoftwareUpdate Component",
NS_SoftwareUpdate_CID,
NS_IXPINSTALLCOMPONENT_CONTRACTID,
nsSoftwareUpdateConstructor,
RegisterSoftwareUpdate
},
{ "InstallTrigger Component",
NS_SoftwareUpdateInstallTrigger_CID,
NS_INSTALLTRIGGERCOMPONENT_CONTRACTID,
nsInstallTriggerConstructor
},
{ "InstallVersion Component",
NS_SoftwareUpdateInstallVersion_CID,
NS_INSTALLVERSIONCOMPONENT_CONTRACTID,
nsInstallVersionConstructor
nsInstallTriggerConstructor,
RegisterInstallTrigger
},
{ "XPInstall Content Handler",
@ -558,12 +102,6 @@ static const nsModuleComponentInfo components[] =
nsInstallTriggerConstructor
},
{ "Software update nameset",
NS_SOFTWAREUPDATENAMESET_CID,
NS_SOFTWAREUPDATENAMESET_CONTRACTID,
nsSoftwareUpdateNameSetConstructor
},
{ "XPInstallManager Component",
NS_XPInstallManager_CID,
NS_XPINSTALLMANAGERCOMPONENT_CONTRACTID,
@ -571,7 +109,4 @@ static const nsModuleComponentInfo components[] =
}
};
NS_IMPL_NSGETMODULE(nsSoftwareUpdate, components)

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

@ -1,109 +0,0 @@
#ifndef nsSoftwareUpdate_h___
#define nsSoftwareUpdate_h___
#include "nsSoftwareUpdateIIDs.h"
#include "nsISoftwareUpdate.h"
#include "nscore.h"
#include "nsIFactory.h"
#include "nsISupports.h"
#include "nsString.h"
#include "nsVoidArray.h"
#include "prlock.h"
//#include "mozreg.h"
#include "NSReg.h"
#include "nsCOMPtr.h"
class nsInstallInfo;
class nsIPrincipal;
#include "nsIScriptExternalNameSet.h"
#include "nsIObserver.h"
#include "nsPIXPIStubHook.h"
#include "nsTopProgressNotifier.h"
class nsSoftwareUpdate: public nsISoftwareUpdate,
public nsPIXPIStubHook,
public nsIObserver
{
public:
NS_DEFINE_STATIC_CID_ACCESSOR( NS_SoftwareUpdate_CID )
static nsSoftwareUpdate *GetInstance();
/** GetProgramDirectory
* Information used within the XPI module -- not
* available through any interface
*/
static nsIFile* GetProgramDirectory() { return mProgramDir; }
/** GetLogName
* Optional log name used privately in the XPI module.
*/
static char* GetLogName() { return mLogName; }
static void NeedCleanup() { mNeedCleanup = PR_TRUE; }
NS_DECL_ISUPPORTS
NS_DECL_NSPIXPISTUBHOOK
NS_DECL_NSIOBSERVER
NS_IMETHOD InstallJar( nsIFile* localFile,
const PRUnichar* URL,
const PRUnichar* arguments,
nsIPrincipal* principal = nsnull,
PRUint32 flags = 0,
nsIXPIListener* aListener = 0);
NS_IMETHOD InstallChrome( PRUint32 aType,
nsIFile* aFile,
const PRUnichar* URL,
const PRUnichar* aName,
PRBool aSelect,
nsIXPIListener* aListener = 0);
NS_IMETHOD RegisterListener(nsIXPIListener *aListener);
virtual void InstallJarCallBack();
NS_IMETHOD GetMasterListener(nsIXPIListener **aListener);
NS_IMETHOD SetActiveListener(nsIXPIListener *aListener);
nsSoftwareUpdate();
virtual ~nsSoftwareUpdate();
static PRBool mNeedCleanup;
private:
static nsSoftwareUpdate* mInstance;
static nsCOMPtr<nsIFile> mProgramDir;
static char* mLogName;
nsresult RunNextInstall();
nsresult RegisterNameset();
void CreateMasterListener();
void Shutdown();
PRLock* mLock;
PRBool mInstalling;
nsVoidArray mJarInstallQueue;
nsTopProgressListener *mMasterListener;
HREG mReg;
};
class nsSoftwareUpdateNameSet : public nsIScriptExternalNameSet
{
public:
nsSoftwareUpdateNameSet();
virtual ~nsSoftwareUpdateNameSet();
// nsISupports
NS_DECL_ISUPPORTS
// nsIScriptExternalNameSet
NS_IMETHOD InitializeNameSet(nsIScriptContext* aScriptContext);
};
#endif

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

@ -1,696 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* vim: set ts=4 sw=4 et tw=80: */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (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/MPL/
*
* 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, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Daniel Veditz <dveditz@netscape.com>
* Douglas Turner <dougt@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsSoftwareUpdate.h"
#include "nsSoftwareUpdateRun.h"
#include "nsInstall.h"
#include "nsNetUtil.h"
#include "nspr.h"
#include "plstr.h"
#include "jsapi.h"
#include "nsIZipReader.h"
#include "nsInstallTrigger.h"
#include "nsIConsoleService.h"
#include "nsIScriptError.h"
#include "nsStringEnumerator.h"
#include "nsIJAR.h"
#include "nsIPrincipal.h"
#include "nsIExtensionManager.h"
static NS_DEFINE_CID(kSoftwareUpdateCID, NS_SoftwareUpdate_CID);
extern JSObject *InitXPInstallObjects(JSContext *jscontext,
nsIFile* jarfile, const PRUnichar* url,
const PRUnichar* args, PRUint32 flags,
CHROMEREG_IFACE* registry,
nsIZipReader* hZip);
extern nsresult InitInstallVersionClass(JSContext *jscontext, JSObject *global, void** prototype);
extern nsresult InitInstallTriggerGlobalClass(JSContext *jscontext, JSObject *global, void** prototype);
// Defined in this file:
JS_STATIC_DLL_CALLBACK(void) XPInstallErrorReporter(JSContext *cx, const char *message, JSErrorReport *report);
static PRInt32 GetInstallScriptFromJarfile(nsIZipReader* hZip, char** scriptBuffer, PRUint32 *scriptLength);
static PRInt32 OpenAndValidateArchive(nsIZipReader* hZip, nsIFile* jarFile, nsIPrincipal* aPrincipal);
static nsresult SetupInstallContext(nsIZipReader* hZip, nsIFile* jarFile, const PRUnichar* url, const PRUnichar* args,
PRUint32 flags, CHROMEREG_IFACE* reg, JSRuntime *jsRT, JSContext **jsCX, JSObject **jsGlob);
extern "C" void PR_CALLBACK RunInstallOnThread(void *data);
nsresult VerifySigning(nsIZipReader* hZip, nsIPrincipal* aPrincipal)
{
if (!aPrincipal)
return NS_OK; // not signed, but not an error
PRBool hasCert;
aPrincipal->GetHasCertificate(&hasCert);
if (!hasCert)
return NS_ERROR_FAILURE;
nsCOMPtr<nsIJAR> jar(do_QueryInterface(hZip));
if (!jar)
return NS_ERROR_FAILURE;
// See if the archive is signed at all first
nsCOMPtr<nsIPrincipal> principal;
nsresult rv = jar->GetCertificatePrincipal(nsnull, getter_AddRefs(principal));
if (NS_FAILED(rv) || !principal)
return NS_ERROR_FAILURE;
PRUint32 entryCount = 0;
// first verify all files in the jar are also in the manifest.
nsCOMPtr<nsIUTF8StringEnumerator> entries;
rv = hZip->FindEntries(nsnull, getter_AddRefs(entries));
if (NS_FAILED(rv))
return rv;
PRBool more;
nsCAutoString name;
while (NS_SUCCEEDED(entries->HasMore(&more)) && more)
{
rv = entries->GetNext(name);
if (NS_FAILED(rv)) return rv;
// Do not verify the directory entries or
// entries which are in the meta-inf directory
if ((name.Last() == '/') ||
(PL_strncasecmp("META-INF/", name.get(), 9) == 0))
continue;
// Count the entries to be verified
entryCount++;
// Each entry must be signed
rv = jar->GetCertificatePrincipal(name.get(), getter_AddRefs(principal));
if (NS_FAILED(rv) || !principal) return NS_ERROR_FAILURE;
PRBool equal;
rv = principal->Equals(aPrincipal, &equal);
if (NS_FAILED(rv) || !equal) return NS_ERROR_FAILURE;
}
// next verify all files in the manifest are in the archive.
PRUint32 manifestEntryCount;
rv = jar->GetManifestEntriesCount(&manifestEntryCount);
if (NS_FAILED(rv))
return rv;
if (entryCount != manifestEntryCount)
return NS_ERROR_FAILURE; // some files were deleted from archive
return NS_OK;
}
///////////////////////////////////////////////////////////////////////////////////////////////
// Function name : XPInstallErrorReporter
// Description : Prints error message to stdout
// Return type : void
// Argument : JSContext *cx
// Argument : const char *message
// Argument : JSErrorReport *report
///////////////////////////////////////////////////////////////////////////////////////////////
static void
XPInstallErrorReporter(JSContext *cx, const char *message, JSErrorReport *report)
{
nsresult rv;
/* Use the console service to register the error. */
nsCOMPtr<nsIConsoleService> consoleService
(do_GetService("@mozilla.org/consoleservice;1"));
/*
* Make an nsIScriptError, populate it with information from this
* error, then log it with the console service.
*/
nsCOMPtr<nsIScriptError>
errorObject(do_CreateInstance("@mozilla.org/scripterror;1"));
if (consoleService != nsnull && errorObject != nsnull && report != nsnull) {
/*
* Got an error object; prepare appropriate-width versions of
* various arguments to it.
*/
PRUint32 column = report->uctokenptr - report->uclinebuf;
rv = errorObject->Init(reinterpret_cast<const PRUnichar*>(report->ucmessage),
NS_ConvertASCIItoUTF16(report->filename).get(),
reinterpret_cast<const PRUnichar*>(report->uclinebuf),
report->lineno, column, report->flags,
"XPInstall JavaScript");
if (NS_SUCCEEDED(rv)) {
rv = consoleService->LogMessage(errorObject);
if (NS_SUCCEEDED(rv)) {
// We're done!
// For now, always also print out the error to stderr.
// return;
}
}
}
// lets set up an eventQ so that our xpcom/proxies will not have to:
nsCOMPtr<nsISoftwareUpdate> softwareUpdate =
do_GetService(kSoftwareUpdateCID, &rv);
if (NS_FAILED(rv))
{
NS_WARNING("shouldn't have RunInstall() if we can't get SoftwareUpdate");
return;
}
nsCOMPtr<nsIXPIListener> listener;
softwareUpdate->GetMasterListener(getter_AddRefs(listener));
if(listener)
{
nsAutoString logMessage;
if (report)
{
logMessage.AssignLiteral("Line: ");
logMessage.AppendInt(report->lineno, 10);
logMessage.AppendLiteral("\t");
if (report->ucmessage)
logMessage.Append( reinterpret_cast<const PRUnichar*>(report->ucmessage) );
else
logMessage.AppendWithConversion( message );
}
else
logMessage.AssignWithConversion( message );
listener->OnLogComment( logMessage.get() );
}
}
///////////////////////////////////////////////////////////////////////////////////////////////
// Function name : OpenAndValidateArchive
// Description : Opens install archive and validates contents
// Return type : PRInt32
// Argument : nsIZipReader* hZip - the zip reader
// Argument : nsIFile* jarFile - the .xpi file
// Argument : nsIPrincipal* aPrincipal - a principal, if any, displayed to the user
// regarding the cert used to sign this install
///////////////////////////////////////////////////////////////////////////////////////////////
static PRInt32
OpenAndValidateArchive(nsIZipReader* hZip, nsIFile* jarFile, nsIPrincipal* aPrincipal)
{
if (!jarFile)
return nsInstall::DOWNLOAD_ERROR;
nsCOMPtr<nsIFile> jFile;
nsresult rv =jarFile->Clone(getter_AddRefs(jFile));
if (NS_SUCCEEDED(rv))
rv = hZip->Open(jFile);
if (NS_FAILED(rv))
return nsInstall::CANT_READ_ARCHIVE;
// CRC check the integrity of all items in this archive
rv = hZip->Test(nsnull);
if (NS_FAILED(rv))
{
NS_WARNING("CRC check of archive failed!");
return nsInstall::CANT_READ_ARCHIVE;
}
rv = VerifySigning(hZip, aPrincipal);
if (NS_FAILED(rv))
{
NS_WARNING("Signing check of archive failed!");
return nsInstall::INVALID_SIGNATURE;
}
return nsInstall::SUCCESS;
}
///////////////////////////////////////////////////////////////////////////////////////////////
// Function name : GetInstallScriptFromJarfile
// Description : Extracts and reads in a install.js file from a passed jar file.
// Return type : static PRInt32
// Argument : char** scriptBuffer - must be deleted via delete []
// Argument : PRUint32 *scriptLength
///////////////////////////////////////////////////////////////////////////////////////////////
static PRInt32
GetInstallScriptFromJarfile(nsIZipReader* hZip, char** scriptBuffer, PRUint32 *scriptLength)
{
PRInt32 result = NS_OK;
*scriptBuffer = nsnull;
*scriptLength = 0;
// Extract the install.js file.
nsCOMPtr<nsIInputStream> instream;
nsresult rv = hZip->GetInputStream("install.js", getter_AddRefs(instream));
if ( NS_SUCCEEDED(rv) )
{
// Read it into a buffer
char* buffer;
PRUint32 bufferLength;
PRUint32 readLength;
result = nsInstall::CANT_READ_ARCHIVE;
rv = instream->Available(&bufferLength);
if (NS_SUCCEEDED(rv))
{
buffer = new char[bufferLength + 1];
if (buffer != nsnull)
{
rv = instream->Read(buffer, bufferLength, &readLength);
if (NS_SUCCEEDED(rv) && readLength > 0)
{
*scriptBuffer = buffer;
*scriptLength = readLength;
result = NS_OK;
}
else
{
delete [] buffer;
}
}
}
instream->Close();
}
else
{
result = nsInstall::NO_INSTALL_SCRIPT;
}
return result;
}
///////////////////////////////////////////////////////////////////////////////////////////////
// Function name : SetupInstallContext
// Description : Creates a Javascript context and adds our xpinstall objects to it.
// Return type : static nsresult
// Argument : nsIZipReader hZip - the handle to the open archive file
// Argument : const char* jarFile - native filepath to where jar exists on disk
// Argument : const PRUnichar* url - URL of where this package came from
// Argument : const PRUnichar* args - any arguments passed into the javascript context
// Argument : PRUint32 flags - bitmask of flags passed in
// Argument : nsIChromeRegistry* - the chrome registry to run with.
// Argument : JSRuntime *jsRT - A valid JS Runtime
// Argument : JSContext **jsCX - Created context, destroy via JS_DestroyContext
// Argument : JSObject **jsGlob - created global object
///////////////////////////////////////////////////////////////////////////////////////////////
static nsresult SetupInstallContext(nsIZipReader* hZip,
nsIFile* jarFile,
const PRUnichar* url,
const PRUnichar* args,
PRUint32 flags,
CHROMEREG_IFACE* reg,
JSRuntime *rt,
JSContext **jsCX,
JSObject **jsGlob)
{
JSContext *cx;
JSObject *glob;
*jsCX = nsnull;
*jsGlob = nsnull;
if (!rt)
return NS_ERROR_OUT_OF_MEMORY;
cx = JS_NewContext(rt, 8192);
if (!cx)
{
return NS_ERROR_OUT_OF_MEMORY;
}
JS_SetErrorReporter(cx, XPInstallErrorReporter);
JS_BeginRequest(cx);
glob = InitXPInstallObjects(cx, jarFile, url, args, flags, reg, hZip);
if (!glob)
{
JS_DestroyContext(cx);
return NS_ERROR_OUT_OF_MEMORY;
}
// Init standard classes
JS_InitStandardClasses(cx, glob);
// Add our Install class to this context
InitInstallVersionClass(cx, glob, nsnull);
InitInstallTriggerGlobalClass(cx, glob, nsnull);
JS_EndRequest(cx);
*jsCX = cx;
*jsGlob = glob;
return NS_OK;
}
///////////////////////////////////////////////////////////////////////////////////////////////
// Function name : RunInstall
// Description : Creates our Install Thread.
// Return type : PRInt32
// Argument : nsInstallInfo *installInfo
///////////////////////////////////////////////////////////////////////////////////////////////
PRInt32 RunInstall(nsInstallInfo *installInfo)
{
if (installInfo->GetFlags() & XPI_NO_NEW_THREAD)
{
RunInstallOnThread((void *)installInfo);
}
else
{
PR_CreateThread(PR_USER_THREAD,
RunInstallOnThread,
(void*)installInfo,
PR_PRIORITY_NORMAL,
PR_GLOBAL_THREAD,
PR_UNJOINABLE_THREAD,
0);
}
return 0;
}
///////////////////////////////////////////////////////////////////////////////////////////////
// Function name : RunInstallOnThread
// Description : called by starting thread. It directly calls the C api for xpinstall,
// : and once that returns, it calls the completion routine to notify installation
// : completion.
// Return type : extern "C"
// Argument : void *data
///////////////////////////////////////////////////////////////////////////////////////////////
extern "C" void PR_CALLBACK RunInstallOnThread(void *data)
{
nsInstallInfo *installInfo = (nsInstallInfo*)data;
char *scriptBuffer = nsnull;
PRUint32 scriptLength;
JSRuntime *rt;
JSContext *cx;
JSObject *glob;
static NS_DEFINE_IID(kZipReaderCID, NS_ZIPREADER_CID);
nsresult rv;
nsCOMPtr<nsIZipReader> hZip = do_CreateInstance(kZipReaderCID, &rv);
if (NS_FAILED(rv))
return;
// we will plan on sending a failure status back from here unless we
// find positive acknowledgement that the script sent the status
PRInt32 finalStatus;
nsCOMPtr<nsIXPIListener> listener;
nsCOMPtr<nsISoftwareUpdate> softwareUpdate =
do_GetService(kSoftwareUpdateCID, &rv);
if (NS_FAILED(rv))
{
NS_WARNING("shouldn't have RunInstall() if we can't get SoftwareUpdate");
return;
}
softwareUpdate->SetActiveListener( installInfo->GetListener() );
softwareUpdate->GetMasterListener(getter_AddRefs(listener));
if(listener)
listener->OnInstallStart( installInfo->GetURL() );
nsCOMPtr<nsIFile> jarpath = installInfo->GetFile();
finalStatus = OpenAndValidateArchive( hZip,
jarpath,
installInfo->mPrincipal);
if (finalStatus == nsInstall::SUCCESS)
{
#ifdef MOZ_XUL_APP
if (NS_SUCCEEDED(hZip->Test("install.rdf")) && !(nsSoftwareUpdate::GetProgramDirectory()))
{
hZip->Close();
// appears to be an Extension Manager install
nsIExtensionManager* em = installInfo->GetExtensionManager();
if (em)
{
rv = em->InstallItemFromFile(jarpath,
NS_INSTALL_LOCATION_APPPROFILE);
if (NS_FAILED(rv))
finalStatus = nsInstall::EXECUTION_ERROR;
} else {
finalStatus = nsInstall::UNEXPECTED_ERROR;
}
} else {
hZip->Close();
finalStatus = nsInstall::UNSUPPORTED_TYPE;
}
#else
// If we're not a new toolkit app try XPInstall
finalStatus = GetInstallScriptFromJarfile( hZip,
&scriptBuffer,
&scriptLength);
if ( finalStatus == NS_OK && scriptBuffer )
{
// create our runtime
rt = JS_NewRuntime(4L * 1024L * 1024L);
rv = SetupInstallContext( hZip, jarpath,
installInfo->GetURL(),
installInfo->GetArguments(),
installInfo->GetFlags(),
installInfo->GetChromeRegistry(),
rt, &cx, &glob);
if (NS_SUCCEEDED(rv))
{
// Go ahead and run!!
jsval rval;
jsval installedFiles;
JS_BeginRequest(cx); //Increment JS thread counter associated
//with this context
PRBool ok = JS_EvaluateScript( cx,
glob,
scriptBuffer,
scriptLength,
nsnull,
0,
&rval);
if(!ok)
{
// problem compiling or running script -- a true SCRIPT_ERROR
if(JS_GetProperty(cx, glob, "_installedFiles", &installedFiles) &&
JSVAL_TO_BOOLEAN(installedFiles))
{
nsInstall *a = (nsInstall*)JS_GetPrivate(cx, glob);
a->InternalAbort(nsInstall::SCRIPT_ERROR);
}
finalStatus = nsInstall::SCRIPT_ERROR;
}
else
{
// check to make sure the script sent back a status -- if
// not the install may have been syntactically correct but
// left the init/(perform|cancel) transaction open
if(JS_GetProperty(cx, glob, "_installedFiles", &installedFiles) &&
JSVAL_TO_BOOLEAN(installedFiles))
{
// install items remain in queue, must clean up!
nsInstall *a = (nsInstall*)JS_GetPrivate(cx, glob);
a->InternalAbort(nsInstall::MALFORMED_INSTALL);
}
jsval sent;
if ( JS_GetProperty( cx, glob, "_finalStatus", &sent ) )
finalStatus = JSVAL_TO_INT(sent);
else
finalStatus = nsInstall::UNEXPECTED_ERROR;
}
JS_EndRequest(cx); //Decrement JS thread counter
JS_DestroyContextMaybeGC(cx);
}
else
{
// couldn't initialize install context
finalStatus = nsInstall::UNEXPECTED_ERROR;
}
// Clean up after ourselves.
JS_DestroyRuntime(rt);
}
#endif
// force zip archive closed before other cleanup
hZip = 0;
}
if(listener)
listener->OnInstallDone( installInfo->GetURL(), finalStatus );
if (scriptBuffer) delete [] scriptBuffer;
softwareUpdate->SetActiveListener(0);
if (installInfo->GetFlags() & XPI_NO_NEW_THREAD)
{
softwareUpdate->InstallJarCallBack();
}
else
{
// Proxy the callback to the main thread
nsCOMPtr<nsIRunnable> callback = NS_NEW_RUNNABLE_METHOD(nsISoftwareUpdate,
softwareUpdate,
InstallJarCallBack);
NS_DispatchToMainThread(callback);
}
}
//-----------------------------------------------------------------------------
// RunChromeInstallOnThread
//
// Performs the guts of a chrome install on its own thread
//
// XXX: need to return errors/status somehow. What feedback will a user want?
// How do we get it there? Maybe just alerts on errors, could also dump to
// the new console service.
//-----------------------------------------------------------------------------
extern "C" void PR_CALLBACK RunChromeInstallOnThread(void *data)
{
nsresult rv;
NS_ASSERTION(data, "No nsInstallInfo passed to Chrome Install");
nsInstallInfo *info = (nsInstallInfo*)data;
nsIXPIListener* listener = info->GetListener();
if (listener)
listener->OnInstallStart(info->GetURL());
// make sure we've got a chrome registry -- can't proceed if not
CHROMEREG_IFACE* reg = info->GetChromeRegistry();
NS_ASSERTION(reg, "We shouldn't get here without a chrome registry.");
if (reg)
{
#ifdef MOZ_XUL_APP
if (info->GetType() == CHROME_SKIN) {
static NS_DEFINE_CID(kZipReaderCID, NS_ZIPREADER_CID);
nsCOMPtr<nsIZipReader> hZip = do_CreateInstance(kZipReaderCID, &rv);
if (NS_SUCCEEDED(rv) && hZip) {
rv = hZip->Open(info->GetFile());
if (NS_SUCCEEDED(rv))
{
rv = hZip->Test("install.rdf");
nsIExtensionManager* em = info->GetExtensionManager();
if (NS_SUCCEEDED(rv) && em) {
rv = em->InstallItemFromFile(info->GetFile(),
NS_INSTALL_LOCATION_APPPROFILE);
}
}
hZip->Close();
}
// Extension Manager copies the theme .jar file to
// a different location, so remove the temporary file.
info->GetFile()->Remove(PR_FALSE);
}
#else
PRBool isSkin = (info->GetType() & CHROME_SKIN);
PRBool isLocale = (info->GetType() & CHROME_LOCALE);
PRBool isContent = (info->GetType() & CHROME_CONTENT);
PRBool selected = (info->GetFlags() != 0);
const nsCString& spec = info->GetFileJARSpec();
if ( isContent )
rv = reg->InstallPackage(spec.get(), PR_TRUE);
if ( isSkin )
{
rv = reg->InstallSkin(spec.get(), PR_TRUE, PR_FALSE);
if (NS_SUCCEEDED(rv) && selected)
{
NS_ConvertUTF16toUTF8 utf8Args(info->GetArguments());
rv = reg->SelectSkin(utf8Args, PR_TRUE);
}
}
if ( isLocale )
{
rv = reg->InstallLocale(spec.get(), PR_TRUE);
if (NS_SUCCEEDED(rv) && selected)
{
NS_ConvertUTF16toUTF8 utf8Args(info->GetArguments());
rv = reg->SelectLocale(utf8Args, PR_TRUE);
}
}
// now that all types are registered try to activate
if ( isSkin && selected )
reg->RefreshSkins();
#ifdef RELOAD_CHROME_WORKS
// XXX ReloadChrome() crashes right now
if ( isContent || (isLocale && selected) )
reg->ReloadChrome();
#endif
#endif
}
if (listener)
listener->OnInstallDone(info->GetURL(), nsInstall::SUCCESS);
delete info;
}

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

@ -1,6 +0,0 @@
#ifndef __NS_SoftwareUpdateRun_H__
#define __NS_SoftwareUpdateRun_H__
PRInt32 RunInstall(nsInstallInfo *installInfo);
#endif

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

@ -1,222 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (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/MPL/
*
* 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, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Douglas Turner <dougt@netscape.com>
* Daniel Veditz <dveditz@netscape.com>
* Pierre Phaneuf <pp@ludusdesign.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsTopProgressNotifier.h"
nsTopProgressListener::nsTopProgressListener()
{
mListeners = new nsVoidArray();
mActive = 0;
mLock = PR_NewLock();
}
nsTopProgressListener::~nsTopProgressListener()
{
if (mLock) PR_Lock(mLock);
if (mListeners)
{
PRInt32 i=0;
for (; i < mListeners->Count(); i++)
{
nsIXPIListener* element = (nsIXPIListener*)mListeners->ElementAt(i);
NS_IF_RELEASE(element);
}
mListeners->Clear();
delete (mListeners);
}
if (mLock)
{
PR_Unlock(mLock);
PR_DestroyLock(mLock);
}
}
NS_IMPL_THREADSAFE_ISUPPORTS1(nsTopProgressListener, nsIXPIListener)
long
nsTopProgressListener::RegisterListener(nsIXPIListener * newListener)
{
if (mLock) PR_Lock(mLock);
NS_IF_ADDREF( newListener );
long retval = mListeners->AppendElement( newListener );
if (mLock) PR_Unlock(mLock);
return retval;
}
void
nsTopProgressListener::UnregisterListener(long id)
{
if (mLock) PR_Lock(mLock);
if (id < mListeners->Count())
{
nsIXPIListener *item = (nsIXPIListener*)mListeners->ElementAt(id);
mListeners->ReplaceElementAt(nsnull, id);
NS_IF_RELEASE(item);
}
if (mLock) PR_Unlock(mLock);
}
NS_IMETHODIMP
nsTopProgressListener::OnInstallStart(const PRUnichar *URL)
{
if (mActive)
mActive->OnInstallStart(URL);
if (mListeners)
{
PRInt32 i=0;
for (; i < mListeners->Count(); i++)
{
nsIXPIListener* element = (nsIXPIListener*)mListeners->ElementAt(i);
if (element != NULL)
element->OnInstallStart(URL);
}
}
return NS_OK;
}
NS_IMETHODIMP
nsTopProgressListener::OnPackageNameSet(const PRUnichar *URL, const PRUnichar* UIPackageName, const PRUnichar* aVersion)
{
if (mActive)
mActive->OnPackageNameSet(URL, UIPackageName, aVersion);
if (mListeners)
{
PRInt32 i=0;
for (; i < mListeners->Count(); i++)
{
nsIXPIListener* element = (nsIXPIListener*)mListeners->ElementAt(i);
if (element != NULL)
element->OnPackageNameSet(URL, UIPackageName, aVersion);
}
}
return NS_OK;
}
NS_IMETHODIMP
nsTopProgressListener::OnItemScheduled( const PRUnichar* message )
{
long rv = 0;
if (mActive)
mActive->OnItemScheduled( message );
if (mListeners)
{
PRInt32 i=0;
for (; i < mListeners->Count(); i++)
{
nsIXPIListener* element = (nsIXPIListener*)mListeners->ElementAt(i);
if (element != NULL)
element->OnItemScheduled( message );
}
}
return rv;
}
NS_IMETHODIMP
nsTopProgressListener::OnFinalizeProgress( const PRUnichar* message, PRInt32 itemNum, PRInt32 totNum )
{
if (mActive)
mActive->OnFinalizeProgress( message, itemNum, totNum );
if (mListeners)
{
PRInt32 i=0;
for (; i < mListeners->Count(); i++)
{
nsIXPIListener* element = (nsIXPIListener*)mListeners->ElementAt(i);
if (element != NULL)
element->OnFinalizeProgress( message, itemNum, totNum );
}
}
return NS_OK;
}
NS_IMETHODIMP
nsTopProgressListener::OnInstallDone(const PRUnichar *URL, PRInt32 status)
{
if (mActive)
mActive->OnInstallDone(URL, status);
if (mListeners)
{
PRInt32 i=0;
for (; i < mListeners->Count(); i++)
{
nsIXPIListener* element = (nsIXPIListener*)mListeners->ElementAt(i);
if (element != NULL)
element->OnInstallDone(URL,status);
}
}
return NS_OK;
}
NS_IMETHODIMP
nsTopProgressListener::OnLogComment(const PRUnichar* comment)
{
if (mActive)
mActive->OnLogComment(comment);
if (mListeners)
{
PRInt32 i=0;
for (; i < mListeners->Count(); i++)
{
nsIXPIListener* element = (nsIXPIListener*)mListeners->ElementAt(i);
if (element != NULL)
element->OnLogComment(comment);
}
}
return NS_OK;
}

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

@ -1,72 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (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/MPL/
*
* 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, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Douglas Turner <dougt@netscape.com>
* Daniel Veditz <dveditz@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsTopProgressNotifier_h__
#define nsTopProgressNotifier_h__
#include "nsCOMPtr.h"
#include "nsIXPINotifier.h"
#include "nsVoidArray.h"
#include "prlock.h"
class nsTopProgressListener : public nsIXPIListener
{
public:
nsTopProgressListener();
virtual ~nsTopProgressListener();
long RegisterListener(nsIXPIListener * newListener);
void UnregisterListener(long id);
void SetActiveListener(nsIXPIListener *aListener)
{ mActive = aListener; }
NS_DECL_ISUPPORTS
// implements nsIXPIListener
NS_DECL_NSIXPILISTENER
private:
nsVoidArray *mListeners;
PRLock *mLock;
nsCOMPtr<nsIXPIListener> mActive;
};
#endif

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

@ -1,630 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (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/MPL/
*
* 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, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998-1999
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Doug Turner <dougt@netscape.com>
* Pierre Phaneuf <pp@ludusdesign.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsUpdateNotification.h"
#include "nsISupports.h"
#include "nsIServiceManager.h"
#include "nsCOMPtr.h"
#include "nsIComponentManager.h"
#include "nsIGenericFactory.h"
#include "nsIRDFContainer.h"
#include "nsIRDFDataSource.h"
#include "nsIRDFService.h"
#include "nsIRDFRemoteDataSource.h"
#include "nsRDFCID.h"
#include "nsIRDFXMLSink.h"
#include "nsIPrefBranch.h"
#include "nsIPrefService.h"
#include "nsISoftwareUpdate.h"
#define NC_RDF_NAME "http://home.netscape.com/NC-rdf#name"
#define NC_RDF_SOURCE "http://home.netscape.com/NC-rdf#source"
#define NC_RDF_URL "http://home.netscape.com/NC-rdf#url"
#define NC_RDF_CHILD "http://home.netscape.com/NC-rdf#child"
#define NC_RDF_NOTIFICATION_ROOT "http://home.netscape.com/NC-rdf#SoftwareNotificationRoot"
#define NC_XPI_SOURCES "http://home.netscape.com/NC-rdf#SoftwareUpdateDataSources"
#define NC_XPI_PACKAGES "http://home.netscape.com/NC-rdf#SoftwarePackages"
#define NC_XPI_TITLE "http://home.netscape.com/NC-rdf#title"
#define NC_XPI_REGKEY "http://home.netscape.com/NC-rdf#registryKey"
#define NC_XPI_VERSION "http://home.netscape.com/NC-rdf#version"
#define NC_XPI_DESCRIPTION "http://home.netscape.com/NC-rdf#description"
static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
static NS_DEFINE_CID(kRDFContainerCID, NS_RDFCONTAINER_CID);
nsIRDFResource* nsXPINotifierImpl::kXPI_NotifierSources = nsnull;
nsIRDFResource* nsXPINotifierImpl::kXPI_NotifierPackages = nsnull;
nsIRDFResource* nsXPINotifierImpl::kXPI_NotifierPackage_Title = nsnull;
nsIRDFResource* nsXPINotifierImpl::kXPI_NotifierPackage_Version = nsnull;
nsIRDFResource* nsXPINotifierImpl::kXPI_NotifierPackage_Description = nsnull;
nsIRDFResource* nsXPINotifierImpl::kXPI_NotifierPackage_RegKey = nsnull;
nsIRDFResource* nsXPINotifierImpl::kNC_NotificationRoot = nsnull;
nsIRDFResource* nsXPINotifierImpl::kNC_Source = nsnull;
nsIRDFResource* nsXPINotifierImpl::kNC_Name = nsnull;
nsIRDFResource* nsXPINotifierImpl::kNC_URL = nsnull;
nsIRDFResource* nsXPINotifierImpl::kNC_Child = nsnull;
nsXPINotifierImpl::nsXPINotifierImpl()
: mRDF(nsnull)
{
mPendingRefreshes = 0;
static NS_DEFINE_CID(kRDFInMemoryDataSourceCID, NS_RDFINMEMORYDATASOURCE_CID);
mNotifications = do_CreateInstance(kRDFInMemoryDataSourceCID);
}
nsXPINotifierImpl::~nsXPINotifierImpl()
{
NS_IF_RELEASE(mRDF);
NS_IF_RELEASE(kXPI_NotifierSources);
NS_IF_RELEASE(kXPI_NotifierPackages);
NS_IF_RELEASE(kXPI_NotifierPackage_Title);
NS_IF_RELEASE(kXPI_NotifierPackage_Version);
NS_IF_RELEASE(kXPI_NotifierPackage_Description);
NS_IF_RELEASE(kXPI_NotifierPackage_RegKey);
NS_IF_RELEASE(kNC_NotificationRoot);
NS_IF_RELEASE(kNC_Source);
NS_IF_RELEASE(kNC_Name);
NS_IF_RELEASE(kNC_URL);
NS_IF_RELEASE(kNC_Child);
}
NS_IMPL_ISUPPORTS2(nsXPINotifierImpl, nsIRDFXMLSinkObserver, nsIUpdateNotification)
nsresult
nsXPINotifierImpl::NotificationEnabled(PRBool* aReturn)
{
*aReturn = PR_FALSE;
nsCOMPtr<nsIPrefBranch> prefBranch = do_GetService(NS_PREFSERVICE_CONTRACTID);
if ( prefBranch )
{
PRBool value;
// check to see if we are on.
nsresult rv = prefBranch->GetBoolPref( (const char*) XPINSTALL_NOTIFICATIONS_ENABLE, &value);
if (NS_SUCCEEDED(rv) && value)
{
// check to see the last time we did anything. Since flash does not have a persistent
// way to do poll invervals longer than a session, we will implemented that here by using the
// preferences.
PRInt32 intervalHours = 0;
PRTime now = 0;
PRInt32 nowSec = 0;
PRInt32 lastTime = 0;
rv = prefBranch->GetIntPref(XPINSTALL_NOTIFICATIONS_INTERVAL, &intervalHours);
if (NS_FAILED(rv))
{
intervalHours = 7*24; // default at once a week
rv = prefBranch->SetIntPref(XPINSTALL_NOTIFICATIONS_INTERVAL, intervalHours);
}
rv = prefBranch->GetIntPref(XPINSTALL_NOTIFICATIONS_LASTDATE, &lastTime);
now = PR_Now();
// nowSec = now / 1000000
LL_DIV(nowSec, now, 1000000);
if (NS_FAILED(rv) || lastTime == 0)
{
rv = prefBranch->SetIntPref(XPINSTALL_NOTIFICATIONS_LASTDATE, nowSec);
return NS_OK;
}
if ((lastTime + (intervalHours*60*24)) <= nowSec)
{
*aReturn = PR_TRUE;
}
}
}
return NS_OK;
}
nsresult
nsXPINotifierImpl::Init()
{
PRBool enabled;
NotificationEnabled(&enabled);
if (!enabled)
return NS_ERROR_FAILURE;
if (mNotifications == nsnull)
return NS_ERROR_FAILURE;
nsresult rv;
nsCOMPtr<nsIRDFDataSource> distributors;
nsCOMPtr<nsIRDFContainer> distributorsContainer;
nsCOMPtr <nsISimpleEnumerator> distributorEnumerator;
PRBool moreElements;
// Read the distributor registry
rv = CallGetService(kRDFServiceCID, &mRDF);
if (NS_FAILED(rv)) return rv;
if (! kXPI_NotifierSources)
{
mRDF->GetResource(NC_XPI_SOURCES, &kXPI_NotifierSources);
mRDF->GetResource(NC_XPI_PACKAGES, &kXPI_NotifierPackages);
mRDF->GetResource(NC_XPI_TITLE, &kXPI_NotifierPackage_Title);
mRDF->GetResource(NC_XPI_VERSION, &kXPI_NotifierPackage_Version);
mRDF->GetResource(NC_XPI_DESCRIPTION, &kXPI_NotifierPackage_Description);
mRDF->GetResource(NC_XPI_REGKEY, &kXPI_NotifierPackage_RegKey);
mRDF->GetResource(NC_RDF_NOTIFICATION_ROOT, &kNC_NotificationRoot);
mRDF->GetResource(NC_RDF_SOURCE, &kNC_Source);
mRDF->GetResource(NC_RDF_NAME, &kNC_Name);
mRDF->GetResource(NC_RDF_URL, &kNC_URL);
mRDF->GetResource(NC_RDF_CHILD, &kNC_Child);
}
rv = OpenRemoteDataSource(BASE_DATASOURCE_URL, PR_TRUE, getter_AddRefs(distributors));
if (NS_FAILED(rv)) return rv;
distributorsContainer = do_CreateInstance(kRDFContainerCID, &rv);
if (NS_SUCCEEDED(rv))
{
rv = distributorsContainer->Init(distributors, kXPI_NotifierSources);
if (NS_SUCCEEDED(rv))
{
rv = distributorsContainer->GetElements(getter_AddRefs(distributorEnumerator));
if (NS_SUCCEEDED(rv))
{
distributorEnumerator->HasMoreElements(&moreElements);
while (moreElements)
{
nsCOMPtr<nsISupports> i;
rv = distributorEnumerator->GetNext(getter_AddRefs(i));
if (NS_FAILED(rv)) break;
nsCOMPtr<nsIRDFResource> aDistributor(do_QueryInterface(i, &rv));
if (NS_FAILED(rv)) break;
char* uri;
nsCOMPtr<nsIRDFDataSource> remoteDatasource;
aDistributor->GetValue(&uri);
rv = OpenRemoteDataSource(uri, PR_FALSE, getter_AddRefs(remoteDatasource));
nsMemory::Free(uri);
if (NS_FAILED(rv)) break;
distributorEnumerator->HasMoreElements(&moreElements);
}
}
}
}
return NS_OK;
}
PRBool
nsXPINotifierImpl::IsNewerOrUninstalled(const char* regKey, const char* versionString)
{
PRBool needJar = PR_FALSE;
REGERR status = VR_ValidateComponent( (char*) regKey );
if ( status == REGERR_NOFIND || status == REGERR_NOFILE )
{
// either component is not in the registry or it's a file
// node and the physical file is missing
needJar = PR_TRUE;
}
else
{
VERSION oldVersion;
status = VR_GetVersion( (char*)regKey, &oldVersion );
if ( status != REGERR_OK )
{
needJar = PR_TRUE;
}
else
{
VERSION newVersion;
StringToVersionNumbers(versionString, &(newVersion).major, &(newVersion).minor, &(newVersion).release, &(newVersion).build);
if ( CompareVersions(&oldVersion, &newVersion) < 0 )
needJar = PR_TRUE;
}
}
return needJar;
}
PRInt32
nsXPINotifierImpl::CompareVersions(VERSION *oldversion, VERSION *newVersion)
{
PRInt32 diff;
if ( oldversion->major == newVersion->major )
{
if ( oldversion->minor == newVersion->minor )
{
if ( oldversion->release == newVersion->release )
{
if ( oldversion->build == newVersion->build )
diff = 0;
else if ( oldversion->build > newVersion->build )
diff = 1;
else
diff = -1;
}
else if ( oldversion->release > newVersion->release )
diff = 1;
else
diff = -1;
}
else if ( oldversion->minor > newVersion->minor )
diff = 1;
else
diff = -1;
}
else if ( oldversion->major > newVersion->major )
diff = 1;
else
diff = -1;
return diff;
}
void
nsXPINotifierImpl::StringToVersionNumbers(const nsString& version, int32 *aMajor, int32 *aMinor, int32 *aRelease, int32 *aBuild)
{
PRInt32 errorCode;
int dot = version.FindChar('.', 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.FindChar('.',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.FindChar('.',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);
}
}
}
}
}
nsresult
nsXPINotifierImpl::OpenRemoteDataSource(const char* aURL, PRBool blocking, nsIRDFDataSource** aResult)
{
static NS_DEFINE_CID(kRDFXMLDataSourceCID, NS_RDFXMLDATASOURCE_CID);
nsresult rv;
nsCOMPtr<nsIRDFRemoteDataSource> remote = do_CreateInstance(kRDFXMLDataSourceCID, &rv);
if (NS_FAILED(rv)) return rv;
rv = remote->Init(aURL);
if (NS_SUCCEEDED(rv))
{
if (! blocking)
{
nsCOMPtr<nsIRDFXMLSink> sink = do_QueryInterface(remote, &rv);
if (NS_FAILED(rv)) return rv;
rv = sink->AddXMLSinkObserver(this);
if (NS_FAILED(rv)) return rv;
}
rv = remote->Refresh(blocking);
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIRDFDataSource> result = do_QueryInterface(remote, &rv);
*aResult = result;
NS_IF_ADDREF(*aResult);
return rv;
}
else
{
// we've already loaded this datasource. use cached copy
return mRDF->GetDataSource(aURL, aResult);
}
}
NS_IMETHODIMP
nsXPINotifierImpl::New(nsISupports* aOuter, REFNSIID aIID, void** aResult)
{
NS_PRECONDITION(aOuter == nsnull, "no aggregation");
if (aOuter)
return NS_ERROR_NO_AGGREGATION;
nsXPINotifierImpl* result = new nsXPINotifierImpl();
if (! result)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(result); // stabilize
nsresult rv;
rv = result->Init();
if (NS_SUCCEEDED(rv)) {
rv = result->QueryInterface(aIID, aResult);
}
NS_RELEASE(result);
return rv;
}
NS_IMETHODIMP
nsXPINotifierImpl::OnBeginLoad(nsIRDFXMLSink *aSink)
{
return NS_OK;
}
NS_IMETHODIMP
nsXPINotifierImpl::OnInterrupt(nsIRDFXMLSink *aSink)
{
return NS_OK;
}
NS_IMETHODIMP
nsXPINotifierImpl::OnResume(nsIRDFXMLSink *aSink)
{
return NS_OK;
}
NS_IMETHODIMP
nsXPINotifierImpl::OnEndLoad(nsIRDFXMLSink *aSink)
{
nsresult rv;
(void) aSink->RemoveXMLSinkObserver(this);
nsCOMPtr<nsIRDFDataSource> distributorDataSource = do_QueryInterface(aSink, &rv);
if (NS_FAILED(rv)) return rv;
nsCOMPtr <nsISimpleEnumerator> packageEnumerator;
PRBool moreElements;
nsCOMPtr<nsIRDFContainer> distributorContainer =
do_CreateInstance(kRDFContainerCID, &rv);
if (NS_SUCCEEDED(rv))
{
rv = distributorContainer->Init(distributorDataSource, kXPI_NotifierPackages);
if (NS_SUCCEEDED(rv))
{
rv = distributorContainer->GetElements(getter_AddRefs(packageEnumerator));
if (NS_SUCCEEDED(rv))
{
packageEnumerator->HasMoreElements(&moreElements);
while (moreElements)
{
nsCOMPtr<nsISupports> i;
rv = packageEnumerator->GetNext(getter_AddRefs(i));
if (NS_FAILED(rv)) break;
nsCOMPtr<nsIRDFResource> aPackage(do_QueryInterface(i, &rv));
if (NS_FAILED(rv)) break;
// Get the version information
nsCOMPtr<nsIRDFNode> versionNode;
distributorDataSource->GetTarget(aPackage,
kXPI_NotifierPackage_Version,
PR_TRUE,
getter_AddRefs(versionNode));
nsCOMPtr<nsIRDFLiteral> version(do_QueryInterface(versionNode, &rv));
if (NS_FAILED(rv)) break;
// Get the regkey information
nsCOMPtr<nsIRDFNode> regkeyNode;
distributorDataSource->GetTarget(aPackage,
kXPI_NotifierPackage_RegKey,
PR_TRUE,
getter_AddRefs(regkeyNode));
nsCOMPtr<nsIRDFLiteral> regkey(do_QueryInterface(regkeyNode, &rv));
if (NS_FAILED(rv)) break;
// convert them into workable nsAutoStrings
PRUnichar* regkeyCString;
regkey->GetValue(&regkeyCString);
nsString regKeyString(regkeyCString);
PRUnichar* versionCString;
version->GetValue(&versionCString);
nsString versionString(versionCString);
nsMemory::Free(versionCString);
nsMemory::Free(regkeyCString);
// check to see if this software title should be "flashed"
if (IsNewerOrUninstalled(NS_ConvertUTF16toUTF8(regKeyString).get(), NS_ConvertUTF16toUTF8(versionString).get()))
{
//assert into flash
nsCOMPtr<nsIRDFNode> urlNode;
distributorDataSource->GetTarget(kXPI_NotifierPackages,
kNC_URL,
PR_TRUE,
getter_AddRefs(urlNode));
nsCOMPtr<nsIRDFLiteral> url(do_QueryInterface(urlNode, &rv));
if (NS_FAILED(rv)) break;
nsCOMPtr<nsIRDFNode> titleNode;
distributorDataSource->GetTarget(kXPI_NotifierPackages,
kXPI_NotifierPackage_Title,
PR_TRUE,
getter_AddRefs(titleNode));
nsCOMPtr<nsIRDFLiteral> title(do_QueryInterface(titleNode, &rv));
if (NS_FAILED(rv)) break;
nsCOMPtr<nsIRDFDataSource> ds = do_QueryInterface(mNotifications);
ds->Assert(aPackage, kNC_Name, title, PR_TRUE);
ds->Assert(aPackage, kNC_URL, url, PR_TRUE);
ds->Assert(kNC_NotificationRoot, kNC_Child, aPackage, PR_TRUE);
break;
}
}
}
}
}
VR_Close();
return NS_OK;
}
NS_IMETHODIMP
nsXPINotifierImpl::OnError(nsIRDFXMLSink *aSink, nsresult aResult, const PRUnichar* aErrorMsg)
{
(void) aSink->RemoveXMLSinkObserver(this);
return NS_OK;
}
NS_IMETHODIMP
nsXPINotifierImpl::DisplayUpdateDialog(void)
{
nsresult rv;
nsCOMPtr <nsISimpleEnumerator> packages;
PRBool moreElements;
nsCOMPtr<nsIRDFDataSource> ds = do_QueryInterface(mNotifications, &rv);
if (NS_SUCCEEDED(rv))
{
rv = ds->GetAllResources(getter_AddRefs(packages));
if (NS_SUCCEEDED(rv))
{
packages->HasMoreElements(&moreElements);
while (moreElements)
{
nsCOMPtr<nsISupports> i;
rv = packages->GetNext(getter_AddRefs(i));
if (NS_FAILED(rv)) break;
nsCOMPtr<nsIRDFResource> aPackage(do_QueryInterface(i, &rv));
if (NS_FAILED(rv)) break;
// Get the version information
nsCOMPtr<nsIRDFNode> name;
ds->GetTarget(aPackage,
nsXPINotifierImpl::kNC_Name,
PR_TRUE,
getter_AddRefs(name));
nsCOMPtr<nsIRDFLiteral> nameLiteral = do_QueryInterface(name, &rv);
if (NS_FAILED(rv)) break;
}
}
}
return rv;
}

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

@ -1,107 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (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/MPL/
*
* 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, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998-1999
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Doug Turner <dougt@netscape.com>
* Pierre Phaneuf <pp@ludusdesign.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsCOMPtr.h"
#include "nsIRDFDataSource.h"
#include "nsRDFCID.h"
#include "nsIRDFXMLSink.h"
#include "nsIRDFResource.h"
#include "nsIRDFService.h"
#include "VerReg.h"
#include "nsIUpdateNotification.h"
#define NS_XPI_UPDATE_NOTIFIER_DATASOURCE_CID \
{ 0x69fdc800, 0x4050, 0x11d3, { 0xbe, 0x2f, 0x0, 0x10, 0x4b, 0xde, 0x60, 0x48 } }
#define NS_XPI_UPDATE_NOTIFIER_CID \
{ 0x68a24e36, 0x042d, 0x11d4, { 0xac, 0x85, 0x0, 0xc0, 0x4f, 0xa0, 0xd2, 0x6b } }
#define NS_XPI_UPDATE_NOTIFIER_CONTRACTID "@mozilla.org/xpinstall/notifier;1"
#define BASE_DATASOURCE_URL "chrome://communicator/content/xpinstall/SoftwareUpdates.rdf"
class nsXPINotifierImpl : public nsIUpdateNotification, public nsIRDFXMLSinkObserver
{
public:
static NS_IMETHODIMP New(nsISupports* aOuter, REFNSIID aIID, void** aResult);
NS_DECL_ISUPPORTS
NS_DECL_NSIRDFXMLSINKOBSERVER
NS_DECL_NSIUPDATENOTIFICATION
protected:
nsXPINotifierImpl();
virtual ~nsXPINotifierImpl();
nsresult NotificationEnabled(PRBool* aReturn);
nsresult Init();
nsresult OpenRemoteDataSource(const char* aURL, PRBool blocking, nsIRDFDataSource** aResult);
PRBool IsNewerOrUninstalled(const char* regKey, const char* versionString);
PRInt32 CompareVersions(VERSION *oldversion, VERSION *newVersion);
void StringToVersionNumbers(const nsString& version, int32 *aMajor, int32 *aMinor, int32 *aRelease, int32 *aBuild);
nsCOMPtr<nsISupports> mNotifications;
nsIRDFService* mRDF;
PRUint32 mPendingRefreshes;
static nsIRDFResource* kXPI_NotifierSources;
static nsIRDFResource* kXPI_NotifierPackages;
static nsIRDFResource* kXPI_NotifierPackage_Title;
static nsIRDFResource* kXPI_NotifierPackage_Version;
static nsIRDFResource* kXPI_NotifierPackage_Description;
static nsIRDFResource* kXPI_NotifierPackage_RegKey;
static nsIRDFResource* kNC_NotificationRoot;
static nsIRDFResource* kNC_Source;
static nsIRDFResource* kNC_Name;
static nsIRDFResource* kNC_URL;
static nsIRDFResource* kNC_Child;
};

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

@ -1,176 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (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/MPL/
*
* 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.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsWinReg.h"
#include "nsWinProfile.h"
#include "nsWinProfileItem.h"
#include "nspr.h"
#include <windows.h>
#include "nsNativeCharsetUtils.h"
/* Public Methods */
nsWinProfile::nsWinProfile( nsInstall* suObj, const nsString& folder, const nsString& file )
: mFilename(folder)
{
MOZ_COUNT_CTOR(nsWinProfile);
if(mFilename.Last() != '\\')
{
mFilename.AppendLiteral("\\");
}
mFilename.Append(file);
mInstallObject = suObj;
}
nsWinProfile::~nsWinProfile()
{
MOZ_COUNT_DTOR(nsWinProfile);
}
PRInt32
nsWinProfile::GetString(nsString section, nsString key, nsString* aReturn)
{
return NativeGetString(section, key, aReturn);
}
PRInt32
nsWinProfile::WriteString(nsString section, nsString key, nsString value, PRInt32* aReturn)
{
*aReturn = NS_OK;
nsWinProfileItem* wi = new nsWinProfileItem(this, section, key, value, aReturn);
if(wi == nsnull)
{
*aReturn = nsInstall::OUT_OF_MEMORY;
return NS_OK;
}
if(*aReturn != nsInstall::SUCCESS)
{
if(wi)
{
delete wi;
return NS_OK;
}
}
if (mInstallObject)
mInstallObject->ScheduleForInstall(wi);
return NS_OK;
}
nsString& nsWinProfile::GetFilename()
{
return mFilename;
}
nsInstall* nsWinProfile::InstallObject()
{
return mInstallObject;
}
PRInt32
nsWinProfile::FinalWriteString( nsString section, nsString key, nsString value )
{
/* do we need another security check here? */
return NativeWriteString(section, key, value);
}
/* Private Methods */
#define STRBUFLEN 255
PRInt32
nsWinProfile::NativeGetString(nsString aSection, nsString aKey, nsString* aReturn )
{
int numChars = 0;
char valbuf[STRBUFLEN];
/* make sure conversions worked */
if(aSection.First() != '\0' && aKey.First() != '\0' && mFilename.First() != '\0')
{
nsCAutoString section;
nsCAutoString key;
nsCAutoString filename;
if(NS_FAILED(NS_CopyUnicodeToNative(aSection, section)) ||
NS_FAILED(NS_CopyUnicodeToNative(aKey, key)) ||
NS_FAILED(NS_CopyUnicodeToNative(mFilename, filename)))
return 0;
valbuf[0] = 0;
numChars = GetPrivateProfileString( section.get(), key.get(), "", valbuf,
STRBUFLEN, filename.get());
nsCAutoString cStrValue(valbuf);
nsAutoString value;
if(NS_SUCCEEDED(NS_CopyNativeToUnicode(cStrValue, value)))
aReturn->Assign(value);
}
return numChars;
}
PRInt32
nsWinProfile::NativeWriteString( nsString aSection, nsString aKey, nsString aValue )
{
int success = 0;
/* make sure conversions worked */
if(aSection.First() != '\0' && aKey.First() != '\0' && mFilename.First() != '\0')
{
nsCAutoString section;
nsCAutoString key;
nsCAutoString value;
nsCAutoString filename;
if(NS_FAILED(NS_CopyUnicodeToNative(aSection, section)) ||
NS_FAILED(NS_CopyUnicodeToNative(aKey, key)) ||
NS_FAILED(NS_CopyUnicodeToNative(aValue, value)) ||
NS_FAILED(NS_CopyUnicodeToNative(mFilename, filename)))
return 0;
success = WritePrivateProfileString( section.get(), key.get(), value.get(), filename.get() );
}
return success;
}

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

@ -1,91 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (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/MPL/
*
* 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.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsWinProfile_h__
#define nsWinProfile_h__
#include "prtypes.h"
#include "nsInstall.h"
class nsWinProfile
{
public:
/* Public Fields */
/* Public Methods */
nsWinProfile( nsInstall* suObj, const nsString& folder, const nsString& file );
~nsWinProfile();
/**
* Schedules a write into a windows "ini" file. "Value" can be
* null to delete the value, but we don't support deleting an entire
* section via a null "key". The actual write takes place during
* SoftwareUpdate.FinalizeInstall();
*
* @return false for failure, true for success
*/
PRInt32 WriteString( nsString section, nsString key, nsString value, PRInt32* aReturn );
/**
* Reads a value from a windows "ini" file. We don't support using
* a null "key" to return a list of keys--you have to know what you want
*
* @return String value from INI, "" if not found, null if error
*/
PRInt32 GetString( nsString section, nsString key, nsString* aReturn );
nsString& GetFilename();
nsInstall* InstallObject();
PRInt32 FinalWriteString( nsString section, nsString key, nsString value );
private:
/* Private Fields */
nsString mFilename;
nsInstall* mInstallObject;
/* Private Methods */
PRInt32 NativeWriteString( nsString section, nsString key, nsString value );
PRInt32 NativeGetString( nsString section, nsString key, nsString* aReturn );
};
#endif /* nsWinProfile_h__ */

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

@ -1,144 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (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/MPL/
*
* 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.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsWinProfileItem.h"
#include "nspr.h"
#include <windows.h>
/* Public Methods */
nsWinProfileItem::nsWinProfileItem(nsWinProfile* profileObj,
nsString sectionName,
nsString keyName,
nsString val,
PRInt32 *aReturn) : nsInstallObject(profileObj->InstallObject())
{
MOZ_COUNT_CTOR(nsWinProfileItem);
mProfile = profileObj;
mSection = new nsString(sectionName);
mKey = new nsString(keyName);
mValue = new nsString(val);
*aReturn = nsInstall::SUCCESS;
if((mSection == nsnull) ||
(mKey == nsnull) ||
(mValue == nsnull))
{
*aReturn = nsInstall::OUT_OF_MEMORY;
}
}
nsWinProfileItem::~nsWinProfileItem()
{
if (mSection) delete mSection;
if (mKey) delete mKey;
if (mValue) delete mValue;
MOZ_COUNT_DTOR(nsWinProfileItem);
}
PRInt32 nsWinProfileItem::Complete()
{
if (mProfile)
mProfile->FinalWriteString(*mSection, *mKey, *mValue);
return NS_OK;
}
char* nsWinProfileItem::toString()
{
char* resultCString;
nsString* filename = new nsString(mProfile->GetFilename());
nsString* result = new nsString;
result->AssignLiteral("Write ");
if (filename == nsnull || result == nsnull) {
delete filename;
delete result;
return nsnull;
}
result->Append(*filename);
result->AppendLiteral(": [");
result->Append(*mSection);
result->AppendLiteral("] ");
result->Append(*mKey);
result->AppendLiteral("=");
result->Append(*mValue);
resultCString = ToNewCString(*result);
if (result) delete result;
if (filename) delete filename;
return resultCString;
}
void nsWinProfileItem::Abort()
{
}
PRInt32 nsWinProfileItem::Prepare()
{
return nsnull;
}
/* CanUninstall
* WinProfileItem() does not install any files which can be uninstalled,
* hence this function returns false.
*/
PRBool
nsWinProfileItem::CanUninstall()
{
return PR_FALSE;
}
/* RegisterPackageNode
* WinProfileItem() installs files which need to be registered,
* hence this function returns true.
*/
PRBool
nsWinProfileItem::RegisterPackageNode()
{
return PR_TRUE;
}

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

@ -1,96 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (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/MPL/
*
* 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.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsWinProfileItem_h__
#define nsWinProfileItem_h__
#include "prtypes.h"
#include "nsSoftwareUpdate.h"
#include "nsInstallObject.h"
#include "nsWinProfile.h"
PR_BEGIN_EXTERN_C
class nsWinProfileItem : public nsInstallObject {
public:
/* Public Fields */
/* Public Methods */
nsWinProfileItem(nsWinProfile* profileObj,
nsString sectionName,
nsString keyName,
nsString val,
PRInt32 *aReturn);
virtual ~nsWinProfileItem();
/**
* Completes the install:
* - writes the data into the .INI file
*/
PRInt32 Complete();
char* toString();
// no need for special clean-up
void Abort();
// no need for set-up
PRInt32 Prepare();
/* should these be protected? */
PRBool CanUninstall();
PRBool RegisterPackageNode();
private:
/* Private Fields */
nsWinProfile* mProfile; // initiating profile object
nsString* mSection; // Name of section
nsString* mKey; // Name of key
nsString* mValue; // data to write
/* Private Methods */
};
PR_END_EXTERN_C
#endif /* nsWinProfileItem_h__ */

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

@ -1,916 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (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/MPL/
*
* 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.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsWinReg.h"
#include "nsWinRegItem.h"
#include "nsNativeCharsetUtils.h"
#include <windows.h>
/* Public Methods */
nsWinReg::nsWinReg(nsInstall* suObj)
{
MOZ_COUNT_CTOR(nsWinReg);
mInstallObject = suObj;
mRootKey = (PRInt32)HKEY_CLASSES_ROOT;
}
nsWinReg::~nsWinReg()
{
MOZ_COUNT_DTOR(nsWinReg);
}
PRInt32
nsWinReg::SetRootKey(PRInt32 key)
{
mRootKey = key;
return NS_OK;
}
PRInt32
nsWinReg::CreateKey(const nsAString& subkey, const nsAString& classname, PRInt32* aReturn)
{
nsWinRegItem* wi = new nsWinRegItem(this, mRootKey, NS_WIN_REG_CREATE, subkey, classname, NS_LITERAL_STRING("null"), aReturn);
if(wi == nsnull)
{
*aReturn = nsInstall::OUT_OF_MEMORY;
return NS_OK;
}
if(*aReturn != nsInstall::SUCCESS)
{
if(wi)
{
delete wi;
return NS_OK;
}
}
if(mInstallObject)
*aReturn = mInstallObject->ScheduleForInstall(wi);
return 0;
}
PRInt32
nsWinReg::DeleteKey(const nsAString& subkey, PRInt32* aReturn)
{
nsWinRegItem* wi = new nsWinRegItem(this, mRootKey, NS_WIN_REG_DELETE, subkey, NS_LITERAL_STRING("null"), NS_LITERAL_STRING("null"), aReturn);
if(wi == nsnull)
{
*aReturn = nsInstall::OUT_OF_MEMORY;
return NS_OK;
}
if(*aReturn != nsInstall::SUCCESS)
{
if(wi)
{
delete wi;
return NS_OK;
}
}
if(mInstallObject)
*aReturn = mInstallObject->ScheduleForInstall(wi);
return 0;
}
PRInt32
nsWinReg::DeleteValue(const nsAString& subkey, const nsAString& valname, PRInt32* aReturn)
{
nsWinRegItem* wi = new nsWinRegItem(this, mRootKey, NS_WIN_REG_DELETE_VAL, subkey, valname, NS_LITERAL_STRING("null"), aReturn);
if(wi == nsnull)
{
*aReturn = nsInstall::OUT_OF_MEMORY;
return NS_OK;
}
if(*aReturn != nsInstall::SUCCESS)
{
if(wi)
{
delete wi;
return NS_OK;
}
}
if(mInstallObject)
*aReturn = mInstallObject->ScheduleForInstall(wi);
return 0;
}
PRInt32
nsWinReg::SetValueString(const nsAString& subkey, const nsAString& valname, const nsAString& value, PRInt32* aReturn)
{
nsWinRegItem* wi = new nsWinRegItem(this, mRootKey, NS_WIN_REG_SET_VAL_STRING, subkey, valname, value, aReturn);
if(wi == nsnull)
{
*aReturn = nsInstall::OUT_OF_MEMORY;
return NS_OK;
}
if(*aReturn != nsInstall::SUCCESS)
{
if(wi)
{
delete wi;
return NS_OK;
}
}
if(mInstallObject)
*aReturn = mInstallObject->ScheduleForInstall(wi);
return 0;
}
PRInt32
nsWinReg::GetValueString(const nsString& subkey, const nsString& valname, nsString* aReturn)
{
return NativeGetValueString(subkey, valname, aReturn);
}
PRInt32
nsWinReg::EnumValueNames(const nsString& aSubkey, PRInt32 aIndex, nsString &aReturn)
{
char namebuf[MAX_BUF];
HKEY root;
HKEY newkey;
LONG result;
DWORD namesize = sizeof(namebuf);
PRInt32 rv = nsInstall::UNEXPECTED_ERROR;
nsCAutoString subkey;
if ( NS_FAILED ( NS_CopyUnicodeToNative(aSubkey, subkey) ) )
return nsInstall::UNEXPECTED_ERROR;
root = (HKEY) mRootKey;
result = RegOpenKeyEx( root, subkey.get(), 0, KEY_READ, &newkey );
if ( ERROR_SUCCESS == result ) {
result = RegEnumValue( newkey, aIndex, namebuf, &namesize, nsnull, 0, 0, 0 );
RegCloseKey( newkey );
if ( ERROR_SUCCESS == result ) {
nsCAutoString cstrName(namebuf);
nsAutoString name;
if(NS_SUCCEEDED(NS_CopyNativeToUnicode(cstrName, name)))
{
aReturn.Assign(name);
rv = nsInstall::SUCCESS;
}
}
}
return rv;
}
PRInt32
nsWinReg::EnumKeys(const nsString& aSubkey, PRInt32 aIndex, nsString &aReturn)
{
char keybuf[MAX_BUF];
HKEY root;
HKEY newkey;
LONG result;
DWORD type = REG_SZ;
PRInt32 rv = nsInstall::UNEXPECTED_ERROR;
nsCAutoString subkey;
if ( NS_FAILED(NS_CopyUnicodeToNative(aSubkey, subkey) ) )
return nsInstall::UNEXPECTED_ERROR;
root = (HKEY) mRootKey;
result = RegOpenKeyEx( root, subkey.get(), 0, KEY_READ, &newkey );
if ( ERROR_SUCCESS == result ) {
result = RegEnumKey( newkey, aIndex, keybuf, sizeof keybuf );
RegCloseKey( newkey );
if ( ERROR_SUCCESS == result ) {
nsCAutoString cstrKey(keybuf);
nsAutoString key;
if (NS_SUCCEEDED(NS_CopyNativeToUnicode(cstrKey, key) ) )
{
aReturn.Assign(key);
rv = nsInstall::SUCCESS;
}
}
}
return rv;
}
PRInt32
nsWinReg::SetValueNumber(const nsString& subkey, const nsString& valname, PRInt32 value, PRInt32* aReturn)
{
nsWinRegItem* wi = new nsWinRegItem(this, mRootKey, NS_WIN_REG_SET_VAL_NUMBER, subkey, valname, value, aReturn);
if(wi == nsnull)
{
*aReturn = nsInstall::OUT_OF_MEMORY;
return NS_OK;
}
if(*aReturn != nsInstall::SUCCESS)
{
if(wi)
{
delete wi;
return NS_OK;
}
}
if(mInstallObject)
*aReturn = mInstallObject->ScheduleForInstall(wi);
return 0;
}
PRInt32
nsWinReg::GetValueNumber(const nsString& subkey, const nsString& valname, PRInt32* aReturn)
{
return NativeGetValueNumber(subkey, valname, aReturn);
}
PRInt32
nsWinReg::SetValue(const nsString& subkey, const nsString& valname, nsWinRegValue* value, PRInt32* aReturn)
{
// fix: need to figure out what to do with nsWinRegValue class.
//
// nsWinRegItem* wi = new nsWinRegItem(this, mRootKey, NS_WIN_REG_SET_VAL, subkey, valname, (nsWinRegValue*)value, aReturn);
//
// if(wi == nsnull)
// {
// return NS_OK;
// }
// mInstallObject->ScheduleForInstall(wi);
return 0;
}
PRInt32
nsWinReg::GetValue(const nsString& subkey, const nsString& valname, nsWinRegValue** aReturn)
{
// fix:
return NS_OK;
}
nsInstall* nsWinReg::InstallObject()
{
return mInstallObject;
}
PRInt32
nsWinReg::KeyExists(const nsString& subkey,
PRBool* aReturn)
{
*aReturn = NativeKeyExists(subkey);
return NS_OK;
}
PRInt32
nsWinReg::ValueExists(const nsString& subkey,
const nsString& valname,
PRBool* aReturn)
{
*aReturn = NativeValueExists(subkey, valname);
return NS_OK;
}
PRInt32
nsWinReg::IsKeyWritable(const nsString& subkey,
PRBool* aReturn)
{
*aReturn = NativeIsKeyWritable(subkey);
return NS_OK;
}
PRInt32
nsWinReg::PrepareCreateKey(PRInt32 root,
const nsString& subkey,
PRInt32* aReturn)
{
SetRootKey(root);
if(NativeIsKeyWritable(subkey))
*aReturn = nsInstall::SUCCESS;
else
*aReturn = nsInstall::KEY_ACCESS_DENIED;
return NS_OK;
}
PRInt32
nsWinReg::PrepareDeleteKey(PRInt32 root,
const nsString& subkey,
PRInt32* aReturn)
{
SetRootKey(root);
if(NativeKeyExists(subkey))
{
if(NativeIsKeyWritable(subkey))
*aReturn = nsInstall::SUCCESS;
else
*aReturn = nsInstall::KEY_ACCESS_DENIED;
}
else
*aReturn = nsInstall::KEY_DOES_NOT_EXIST;
return NS_OK;
}
PRInt32
nsWinReg::PrepareDeleteValue(PRInt32 root,
const nsString& subkey,
const nsString& valname,
PRInt32* aReturn)
{
SetRootKey(root);
if(NativeValueExists(subkey, valname))
{
if(NativeIsKeyWritable(subkey))
*aReturn = nsInstall::SUCCESS;
else
*aReturn = nsInstall::KEY_ACCESS_DENIED;
}
else
*aReturn = nsInstall::VALUE_DOES_NOT_EXIST;
return NS_OK;
}
PRInt32
nsWinReg::PrepareSetValueString(PRInt32 root,
const nsString& subkey,
PRInt32* aReturn)
{
SetRootKey(root);
if(NativeIsKeyWritable(subkey))
*aReturn = nsInstall::SUCCESS;
else
*aReturn = nsInstall::KEY_ACCESS_DENIED;
return NS_OK;
}
PRInt32
nsWinReg::PrepareSetValueNumber(PRInt32 root,
const nsString& subkey,
PRInt32* aReturn)
{
SetRootKey(root);
if(NativeIsKeyWritable(subkey))
*aReturn = nsInstall::SUCCESS;
else
*aReturn = nsInstall::KEY_ACCESS_DENIED;
return NS_OK;
}
PRInt32
nsWinReg::PrepareSetValue(PRInt32 root,
const nsString& subkey,
PRInt32* aReturn)
{
SetRootKey(root);
if(NativeIsKeyWritable(subkey))
*aReturn = nsInstall::SUCCESS;
else
*aReturn = nsInstall::KEY_ACCESS_DENIED;
return NS_OK;
}
PRInt32
nsWinReg::FinalCreateKey(PRInt32 root, const nsString& subkey, const nsString& classname, PRInt32* aReturn)
{
SetRootKey(root);
*aReturn = NativeCreateKey(subkey, classname);
return NS_OK;
}
PRInt32
nsWinReg::FinalDeleteKey(PRInt32 root, const nsString& subkey, PRInt32* aReturn)
{
SetRootKey(root);
if ( PR_TRUE == NativeKeyExists(subkey) )
*aReturn = NativeDeleteKey(subkey);
else {
NS_WARNING("Trying to delete a key that doesn't exist anymore. Possible causes include calling deleteKey for the same key multiple times, or key+subkey are not unique");
*aReturn = ERROR_SUCCESS;
}
return NS_OK;
}
PRInt32
nsWinReg::FinalDeleteValue(PRInt32 root, const nsString& subkey, const nsString& valname, PRInt32* aReturn)
{
SetRootKey(root);
*aReturn = NativeDeleteValue(subkey, valname);
return NS_OK;
}
PRInt32
nsWinReg::FinalSetValueString(PRInt32 root, const nsString& subkey, const nsString& valname, const nsString& value, PRInt32* aReturn)
{
SetRootKey(root);
*aReturn = NativeSetValueString(subkey, valname, value);
return NS_OK;
}
PRInt32
nsWinReg::FinalSetValueNumber(PRInt32 root, const nsString& subkey, const nsString& valname, PRInt32 value, PRInt32* aReturn)
{
SetRootKey(root);
*aReturn = NativeSetValueNumber(subkey, valname, value);
return NS_OK;
}
PRInt32
nsWinReg::FinalSetValue(PRInt32 root, const nsString& subkey, const nsString& valname, nsWinRegValue* value, PRInt32* aReturn)
{
SetRootKey(root);
*aReturn = NativeSetValue(subkey, valname, value);
return NS_OK;
}
/* Private Methods */
PRBool
nsWinReg::NativeKeyExists(const nsString& aSubkey)
{
HKEY root, newkey;
LONG result;
PRBool keyExists = PR_FALSE;
#ifdef WIN32
nsCAutoString subkey;
if ( NS_FAILED( NS_CopyUnicodeToNative(aSubkey, subkey) ) )
return PR_FALSE;
root = (HKEY)mRootKey;
result = RegOpenKeyEx(root, subkey.get(), 0, KEY_READ, &newkey);
switch(result)
{
case ERROR_SUCCESS:
RegCloseKey(newkey);
keyExists = PR_TRUE;
break;
case ERROR_FILE_NOT_FOUND:
case ERROR_ACCESS_DENIED:
default:
break;
}
#endif
return keyExists;
}
PRBool
nsWinReg::NativeValueExists(const nsString& aSubkey, const nsString& aValname)
{
HKEY root;
HKEY newkey;
LONG result;
PRBool valueExists = PR_FALSE;
DWORD length = _MAXKEYVALUE_;
unsigned char valbuf[_MAXKEYVALUE_];
#ifdef WIN32
nsCAutoString subkey;
nsCAutoString valname;
if ( NS_FAILED( NS_CopyUnicodeToNative(aSubkey, subkey) ) ||
NS_FAILED( NS_CopyUnicodeToNative(aValname, valname) ) )
return PR_FALSE;
root = (HKEY) mRootKey;
result = RegOpenKeyEx(root, subkey.get(), 0, KEY_READ, &newkey);
switch(result)
{
case ERROR_SUCCESS:
result = RegQueryValueEx(newkey,
valname.get(),
0,
NULL,
valbuf,
&length);
switch(result)
{
case ERROR_SUCCESS:
valueExists = PR_TRUE;
break;
case ERROR_FILE_NOT_FOUND:
case ERROR_ACCESS_DENIED:
default:
break;
}
RegCloseKey(newkey);
break;
case ERROR_FILE_NOT_FOUND:
case ERROR_ACCESS_DENIED:
default:
break;
}
#endif
return valueExists;
}
PRBool
nsWinReg::NativeIsKeyWritable(const nsString& aSubkey)
{
HKEY root;
HKEY newkey;
LONG result;
nsString subkeyParent = aSubkey;
PRInt32 index;
PRInt32 rv = PR_FALSE;
#ifdef WIN32
/* In order to check to see if a key is writable (user has write access
* to the key), we need to open the key with KEY_WRITE access. In order
* to open a key, the key must first exist. If the key passed does not
* exist, we need to search for one of its parent key that _does_ exist.
* This do{} loop will search for an existing parent key. */
do
{
rv = NativeKeyExists(subkeyParent);
if(!rv)
{
index = subkeyParent.RFindChar('\\', -1, -1);
if(index > 0)
/* delete everything from the '\\' found to the end of the string */
subkeyParent.SetLength(index);
else
/* key does not exist and no parent key found */
break;
}
}while(!rv);
if(rv)
{
nsCAutoString subkey;
if ( NS_FAILED( NS_CopyUnicodeToNative(subkeyParent, subkey) ) )
result = nsInstall::UNEXPECTED_ERROR;
else
{
rv = PR_FALSE;
root = (HKEY)mRootKey;
result = RegOpenKeyEx(root, subkey.get(), 0, KEY_WRITE, &newkey);
switch(result)
{
case ERROR_SUCCESS:
RegCloseKey(newkey);
rv = PR_TRUE;
break;
case ERROR_FILE_NOT_FOUND:
case ERROR_ACCESS_DENIED:
default:
break;
}
}
}
#endif
return rv;
}
PRInt32
nsWinReg::NativeCreateKey(const nsString& aSubkey, const nsString& aClassname)
{
HKEY root, newkey;
LONG result;
ULONG disposition;
#ifdef WIN32
nsCAutoString subkey;
nsCAutoString classname;
if (NS_FAILED(NS_CopyUnicodeToNative(aSubkey, subkey) ) ||
NS_FAILED(NS_CopyUnicodeToNative(aClassname, classname) ) )
return nsInstall::UNEXPECTED_ERROR;
root = (HKEY)mRootKey;
result = RegCreateKeyEx(root, subkey.get(), 0, const_cast<char*>(classname.get()),
REG_OPTION_NON_VOLATILE, KEY_WRITE, nsnull, &newkey, &disposition);
if(ERROR_SUCCESS == result)
{
RegCloseKey( newkey );
}
#endif
return result;
}
PRInt32
nsWinReg::NativeDeleteKey(const nsString& aSubkey)
{
HKEY root;
LONG result;
#ifdef WIN32
nsCAutoString subkey;
if (NS_FAILED(NS_CopyUnicodeToNative(aSubkey, subkey) ) )
return nsInstall::UNEXPECTED_ERROR;
root = (HKEY) mRootKey;
result = RegDeleteKey( root, subkey.get() );
#endif
return result;
}
PRInt32
nsWinReg::NativeDeleteValue(const nsString& aSubkey, const nsString& aValname)
{
#if defined (WIN32) || defined (XP_OS2)
HKEY root, newkey;
LONG result;
nsCAutoString subkey;
nsCAutoString valname;
if ( NS_FAILED( NS_CopyUnicodeToNative(aSubkey, subkey) ) ||
NS_FAILED( NS_CopyUnicodeToNative(aValname, valname) ) )
return nsInstall::UNEXPECTED_ERROR;
root = (HKEY) mRootKey;
result = RegOpenKeyEx( root, subkey.get(), 0, KEY_WRITE, &newkey);
if ( ERROR_SUCCESS == result )
{
result = RegDeleteValue( newkey, valname.get() );
RegCloseKey( newkey );
}
return result;
#else
return ERROR_INVALID_PARAMETER;
#endif
}
PRInt32
nsWinReg::NativeSetValueString(const nsString& aSubkey, const nsString& aValname, const nsString& aValue)
{
HKEY root;
HKEY newkey;
LONG result;
DWORD length;
nsCAutoString subkey;
nsCAutoString valname;
nsCAutoString value;
if ( NS_FAILED( NS_CopyUnicodeToNative(aSubkey, subkey) ) ||
NS_FAILED( NS_CopyUnicodeToNative(aValname, valname) ) ||
NS_FAILED( NS_CopyUnicodeToNative(aValue, value) ) )
return nsInstall::UNEXPECTED_ERROR;
length = value.Length();
root = (HKEY) mRootKey;
result = RegOpenKeyEx( root, subkey.get(), 0, KEY_WRITE, &newkey);
if(ERROR_SUCCESS == result)
{
result = RegSetValueEx( newkey, valname.get(), 0, REG_SZ, (unsigned char*)value.get(), length );
RegCloseKey( newkey );
}
return result;
}
#define STRBUFLEN 255
PRInt32
nsWinReg::NativeGetValueString(const nsString& aSubkey, const nsString& aValname, nsString* aReturn)
{
unsigned char valbuf[_MAXKEYVALUE_];
HKEY root;
HKEY newkey;
LONG result;
DWORD type = REG_SZ;
DWORD length = sizeof(valbuf);
nsCAutoString subkey;
nsCAutoString valname;
if ( NS_FAILED( NS_CopyUnicodeToNative(aSubkey, subkey) ) ||
NS_FAILED( NS_CopyUnicodeToNative(aValname, valname) ) )
return nsInstall::UNEXPECTED_ERROR;
root = (HKEY) mRootKey;
result = RegOpenKeyEx( root, subkey.get(), 0, KEY_READ, &newkey );
if ( ERROR_SUCCESS == result ) {
result = RegQueryValueEx( newkey, valname.get(), nsnull, &type, valbuf, &length );
RegCloseKey( newkey );
if( result == ERROR_SUCCESS && type == REG_SZ)
{
// this cast is ok until mozilla is compiled in UNICODE, then this
// will break.
nsAutoString value;
if (NS_SUCCEEDED( NS_CopyNativeToUnicode(nsDependentCString(reinterpret_cast<const char *>(valbuf)), value) ) )
aReturn->Assign(value);
else
result = nsInstall::UNEXPECTED_ERROR;
}
}
if(ERROR_ACCESS_DENIED == result)
result = nsInstall::ACCESS_DENIED;
return result;
}
PRInt32
nsWinReg::NativeSetValueNumber(const nsString& aSubkey, const nsString& aValname, PRInt32 aValue)
{
HKEY root;
HKEY newkey;
LONG result;
nsCAutoString subkey;
nsCAutoString valname;
if ( NS_FAILED( NS_CopyUnicodeToNative(aSubkey, subkey) ) ||
NS_FAILED( NS_CopyUnicodeToNative(aValname, valname) ) )
return nsInstall::UNEXPECTED_ERROR;
root = (HKEY) mRootKey;
result = RegOpenKeyEx( root, subkey.get(), 0, KEY_WRITE, &newkey);
if(ERROR_SUCCESS == result)
{
result = RegSetValueEx( newkey, valname.get(), 0, REG_DWORD, (LPBYTE)&aValue, sizeof(PRInt32));
RegCloseKey( newkey );
}
return result;
}
PRInt32
nsWinReg::NativeGetValueNumber(const nsString& aSubkey, const nsString& aValname, PRInt32* aReturn)
{
PRInt32 valbuf;
PRInt32 valbuflen;
HKEY root;
HKEY newkey;
LONG result;
DWORD type = REG_DWORD;
DWORD length = _MAXKEYVALUE_;
nsCAutoString subkey;
nsCAutoString valname;
if ( NS_FAILED( NS_CopyUnicodeToNative(aSubkey, subkey) ) ||
NS_FAILED( NS_CopyUnicodeToNative(aValname, valname) ) )
return nsInstall::UNEXPECTED_ERROR;
valbuflen = sizeof(PRInt32);
root = (HKEY) mRootKey;
result = RegOpenKeyEx( root, subkey.get(), 0, KEY_READ, &newkey );
if ( ERROR_SUCCESS == result ) {
result = RegQueryValueEx( newkey, valname.get(), nsnull, &type, (LPBYTE)&valbuf, (LPDWORD)&valbuflen);
RegCloseKey( newkey );
if(type == REG_DWORD)
*aReturn = valbuf;
}
if(ERROR_ACCESS_DENIED == result)
return nsInstall::ACCESS_DENIED;
else if (result != ERROR_SUCCESS)
return nsInstall::UNEXPECTED_ERROR;
return nsInstall::SUCCESS;
}
PRInt32
nsWinReg::NativeSetValue(const nsString& aSubkey, const nsString& aValname, nsWinRegValue* aValue)
{
#if defined (WIN32) || defined (XP_OS2)
HKEY root;
HKEY newkey;
LONG result;
DWORD length;
DWORD type;
unsigned char* data;
nsCAutoString subkey;
nsCAutoString valname;
if ( NS_FAILED( NS_CopyUnicodeToNative(aSubkey, subkey) ) ||
NS_FAILED( NS_CopyUnicodeToNative(aValname, valname) ) )
return nsnull;
root = (HKEY) mRootKey;
result = RegOpenKeyEx( root, subkey.get(), 0, KEY_WRITE, &newkey );
if(ERROR_SUCCESS == result)
{
type = (DWORD)aValue->type;
data = (unsigned char*)aValue->data;
length = (DWORD)aValue->data_length;
result = RegSetValueEx( newkey, valname.get(), 0, type, data, length);
RegCloseKey( newkey );
}
return result;
#else
return ERROR_INVALID_PARAMETER;
#endif
}
nsWinRegValue*
nsWinReg::NativeGetValue(const nsString& aSubkey, const nsString& aValname)
{
#if defined (WIN32) || defined (XP_OS2)
unsigned char valbuf[STRBUFLEN];
HKEY root;
HKEY newkey;
LONG result;
DWORD length=STRBUFLEN;
DWORD type;
nsString* data;
nsWinRegValue* value = nsnull;
nsCAutoString subkey;
nsCAutoString valname;
if ( NS_FAILED( NS_CopyUnicodeToNative(aSubkey, subkey) ) ||
NS_FAILED( NS_CopyUnicodeToNative(aValname, valname) ) )
return nsnull;
root = (HKEY) mRootKey;
result = RegOpenKeyEx( root, subkey.get(), 0, KEY_READ, &newkey );
if(ERROR_SUCCESS == result)
{
result = RegQueryValueEx( newkey, valname.get(), nsnull, &type, valbuf, &length );
if ( ERROR_SUCCESS == result ) {
data = new nsString;
data->AssignWithConversion((char *)valbuf);
length = data->Length();
value = new nsWinRegValue(type, (void*)data, length);
}
RegCloseKey( newkey );
}
return value;
#else
return nsnull;
#endif
}

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

@ -1,140 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (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/MPL/
*
* 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.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef __NS_WINREG_H__
#define __NS_WINREG_H__
#include "nsWinRegEnums.h"
#include "nsWinRegValue.h"
#include "nscore.h"
#include "nsISupports.h"
#include "jsapi.h"
#include "nsString.h"
#include "nsHashtable.h"
#include "nsSoftwareUpdate.h"
#include "nsInstallObject.h"
#include "nsInstallVersion.h"
#include "nsInstall.h"
#define _MAXKEYVALUE_ 8196
#ifndef MAX_BUF
#define MAX_BUF 4096
#endif
class nsWinReg
{
public:
enum
{
NS_HKEY_CLASSES_ROOT = 0x80000000,
NS_HKEY_CURRENT_USER = 0x80000001,
NS_HKEY_LOCAL_MACHINE = 0x80000002,
NS_HKEY_USERS = 0x80000003
};
/* Public Fields */
/* Public Methods */
nsWinReg(nsInstall* suObj);
~nsWinReg();
PRInt32 SetRootKey(PRInt32 key);
PRInt32 CreateKey(const nsAString& subkey, const nsAString& classname, PRInt32* aReturn);
PRInt32 DeleteKey(const nsAString& subkey, PRInt32* aReturn);
PRInt32 DeleteValue(const nsAString& subkey, const nsAString& valname, PRInt32* aReturn);
PRInt32 SetValueString(const nsAString& subkey, const nsAString& valname, const nsAString& value, PRInt32* aReturn);
PRInt32 GetValueString(const nsString& subkey, const nsString& valname, nsString* aReturn);
PRInt32 SetValueNumber(const nsString& subkey, const nsString& valname, PRInt32 value, PRInt32* aReturn);
PRInt32 GetValueNumber(const nsString& subkey, const nsString& valname, PRInt32* aReturn);
PRInt32 SetValue(const nsString& subkey, const nsString& valname, nsWinRegValue* value, PRInt32* aReturn);
PRInt32 GetValue(const nsString& subkey, const nsString& valname, nsWinRegValue** aReturn);
PRInt32 EnumValueNames(const nsString& keyname, PRInt32 index, nsString &aReturn);
PRInt32 EnumKeys(const nsString& keyname, PRInt32 index, nsString &aReturn);
nsInstall* InstallObject(void);
PRInt32 KeyExists(const nsString& subkey, PRInt32* aReturn);
PRInt32 ValueExists(const nsString& subkey, const nsString& valname, PRInt32* aReturn);
PRInt32 IsKeyWritable(const nsString& subkey, PRInt32* aReturn);
PRInt32 PrepareCreateKey(PRInt32 root, const nsString& subkey, PRInt32* aReturn);
PRInt32 PrepareDeleteKey(PRInt32 root, const nsString& subkey, PRInt32* aReturn);
PRInt32 PrepareDeleteValue(PRInt32 root, const nsString& subkey, const nsString& valname, PRInt32* aReturn);
PRInt32 PrepareSetValueString(PRInt32 root, const nsString& subkey, PRInt32* aReturn);
PRInt32 PrepareSetValueNumber(PRInt32 root, const nsString& subkey, PRInt32* aReturn);
PRInt32 PrepareSetValue(PRInt32 root, const nsString& subkey, PRInt32* aReturn);
PRInt32 FinalCreateKey(PRInt32 root, const nsString& subkey, const nsString& classname, PRInt32* aReturn);
PRInt32 FinalDeleteKey(PRInt32 root, const nsString& subkey, PRInt32* aReturn);
PRInt32 FinalDeleteValue(PRInt32 root, const nsString& subkey, const nsString& valname, PRInt32* aReturn);
PRInt32 FinalSetValueString(PRInt32 root, const nsString& subkey, const nsString& valname, const nsString& value, PRInt32* aReturn);
PRInt32 FinalSetValueNumber(PRInt32 root, const nsString& subkey, const nsString& valname, PRInt32 value, PRInt32* aReturn);
PRInt32 FinalSetValue(PRInt32 root, const nsString& subkey, const nsString& valname, nsWinRegValue* value, PRInt32* aReturn);
private:
/* Private Fields */
PRInt32 mRootKey;
nsInstall* mInstallObject;
/* Private Methods */
PRBool NativeKeyExists(const nsString& subkey);
PRBool NativeValueExists(const nsString& subkey, const nsString& valname);
PRBool NativeIsKeyWritable(const nsString& subkey);
PRInt32 NativeCreateKey(const nsString& subkey, const nsString& classname);
PRInt32 NativeDeleteKey(const nsString& subkey);
PRInt32 NativeDeleteValue(const nsString& subkey, const nsString& valname);
PRInt32 NativeSetValueString(const nsString& subkey, const nsString& valname, const nsString& value);
PRInt32 NativeGetValueString(const nsString& subkey, const nsString& valname, nsString* aReturn);
PRInt32 NativeSetValueNumber(const nsString& subkey, const nsString& valname, PRInt32 value);
PRInt32 NativeGetValueNumber(const nsString& subkey, const nsString& valname, PRInt32* aReturn);
PRInt32 NativeSetValue(const nsString& subkey, const nsString& valname, nsWinRegValue* value);
nsWinRegValue* NativeGetValue(const nsString& subkey, const nsString& valname);
};
#endif /* __NS_WINREG_H__ */

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

@ -1,66 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (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/MPL/
*
* 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.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsWinRegEnums_h__
#define nsWinRegEnums_h__
typedef enum nsWinRegEnum {
NS_WIN_REG_CREATE = 1,
NS_WIN_REG_DELETE = 2,
NS_WIN_REG_DELETE_VAL = 3,
NS_WIN_REG_SET_VAL_STRING = 4,
NS_WIN_REG_SET_VAL_NUMBER = 5,
NS_WIN_REG_SET_VAL = 6
} nsWinRegEnum;
typedef enum nsWinRegValueEnum {
NS_WIN_REG_SZ = 1,
NS_WIN_REG_EXPAND_SZ = 2,
NS_WIN_REG_BINARY = 3,
NS_WIN_REG_DWORD = 4,
NS_WIN_REG_DWORD_LITTLE_ENDIAN = 4,
NS_WIN_REG_DWORD_BIG_ENDIAN = 5,
NS_WIN_REG_LINK = 6,
NS_WIN_REG_MULTI_SZ = 7,
NS_WIN_REG_RESOURCE_LIST = 8,
NS_WIN_REG_FULL_RESOURCE_DESCRIPTOR = 9,
NS_WIN_REG_RESOURCE_REQUIREMENTS_LIST = 10
} nsWinRegValueEnum;
#endif /* nsWinRegEnums_h__ */

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

@ -1,356 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (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/MPL/
*
* 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.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsWinRegItem.h"
#include "nspr.h"
#include "nsWinReg.h"
#ifdef WIN32
#include <windows.h> /* is this needed? */
#endif
/* Public Methods */
nsWinRegItem::nsWinRegItem(nsWinReg* regObj, PRInt32 root, PRInt32 action, const nsAString& sub, const nsAString& valname, const nsAString& val, PRInt32 *aReturn)
: nsInstallObject(regObj->InstallObject())
{
MOZ_COUNT_CTOR(nsWinRegItem);
mReg = regObj;
mCommand = action;
mRootkey = root;
*aReturn = nsInstall::SUCCESS;
/* I'm assuming we need to copy these */
mSubkey = new nsString(sub);
mName = new nsString(valname);
mValue = new nsString(val);
if((mSubkey == nsnull) ||
(mName == nsnull) ||
(mValue == nsnull))
{
*aReturn = nsInstall::OUT_OF_MEMORY;
}
}
nsWinRegItem::nsWinRegItem(nsWinReg* regObj, PRInt32 root, PRInt32 action, const nsAString& sub, const nsAString& valname, PRInt32 val, PRInt32 *aReturn)
: nsInstallObject(regObj->InstallObject())
{
MOZ_COUNT_CTOR(nsWinRegItem);
mReg = regObj;
mCommand = action;
mRootkey = root;
*aReturn = nsInstall::SUCCESS;
/* I'm assuming we need to copy these */
mSubkey = new nsString(sub);
mName = new nsString(valname);
mValue = new PRInt32(val);
if((mSubkey == nsnull) ||
(mName == nsnull) ||
(mValue == nsnull))
{
*aReturn = nsInstall::OUT_OF_MEMORY;
}
}
nsWinRegItem::~nsWinRegItem()
{
if (mSubkey) delete mSubkey;
if (mName) delete mName;
if (mValue) delete mValue;
MOZ_COUNT_DTOR(nsWinRegItem);
}
PRInt32 nsWinRegItem::Complete()
{
PRInt32 aReturn = NS_OK;
if (mReg == nsnull)
return nsInstall::OUT_OF_MEMORY;
switch (mCommand)
{
case NS_WIN_REG_CREATE:
mReg->FinalCreateKey(mRootkey, *mSubkey, *mName, &aReturn);
break;
case NS_WIN_REG_DELETE:
mReg->FinalDeleteKey(mRootkey, *mSubkey, &aReturn);
break;
case NS_WIN_REG_DELETE_VAL:
mReg->FinalDeleteValue(mRootkey, *mSubkey, *mName, &aReturn);
break;
case NS_WIN_REG_SET_VAL_STRING:
mReg->FinalSetValueString(mRootkey, *mSubkey, *mName, *(nsString*)mValue, &aReturn);
break;
case NS_WIN_REG_SET_VAL_NUMBER:
mReg->FinalSetValueNumber(mRootkey, *mSubkey, *mName, *(PRInt32*)mValue, &aReturn);
break;
case NS_WIN_REG_SET_VAL:
mReg->FinalSetValue(mRootkey, *mSubkey, *mName, (nsWinRegValue*)mValue, &aReturn);
break;
}
return aReturn;
}
#define kCRK "Create Registry Key: "
#define kDRK "Delete Registry Key: "
#define kDRV "Delete Registry Value: "
#define kSRVS "Store Registry Value String: "
#define kSRVN "Store Registry Value Number: "
#define kSRV "Store Registry Value: "
#define kUNK "Unknown "
char* nsWinRegItem::toString()
{
nsString* keyString = nsnull;
nsAutoString result;
char* resultCString = nsnull;
switch(mCommand)
{
case NS_WIN_REG_CREATE:
keyString = keystr(mRootkey, mSubkey, nsnull);
result.AssignWithConversion(kCRK);
break;
case NS_WIN_REG_DELETE:
keyString = keystr(mRootkey, mSubkey, nsnull);
result.AssignWithConversion(kDRK);
break;
case NS_WIN_REG_DELETE_VAL:
keyString = keystr(mRootkey, mSubkey, mName);
result.AssignWithConversion(kDRV);
break;
case NS_WIN_REG_SET_VAL_STRING:
keyString = keystr(mRootkey, mSubkey, mName);
result.AssignWithConversion(kSRVS);
break;
case NS_WIN_REG_SET_VAL_NUMBER:
keyString = keystr(mRootkey, mSubkey, mName);
result.AssignWithConversion(kSRVN);
break;
case NS_WIN_REG_SET_VAL:
keyString = keystr(mRootkey, mSubkey, mName);
result.AssignWithConversion(kSRV);
break;
default:
keyString = keystr(mRootkey, mSubkey, mName);
result.AssignWithConversion(kUNK);
break;
}
result.Append(*keyString);
resultCString = ToNewCString(result);
if (keyString) delete keyString;
return resultCString;
}
PRInt32 nsWinRegItem::Prepare()
{
PRInt32 aReturn = NS_OK;
if (mReg == nsnull)
return nsInstall::OUT_OF_MEMORY;
switch (mCommand)
{
case NS_WIN_REG_CREATE:
mReg->PrepareCreateKey(mRootkey, *mSubkey, &aReturn);
break;
case NS_WIN_REG_DELETE:
mReg->PrepareDeleteKey(mRootkey, *mSubkey, &aReturn);
break;
case NS_WIN_REG_DELETE_VAL:
mReg->PrepareDeleteValue(mRootkey, *mSubkey, *mName, &aReturn);
break;
case NS_WIN_REG_SET_VAL_STRING:
mReg->PrepareSetValueString(mRootkey, *mSubkey, &aReturn);
break;
case NS_WIN_REG_SET_VAL_NUMBER:
mReg->PrepareSetValueNumber(mRootkey, *mSubkey, &aReturn);
break;
case NS_WIN_REG_SET_VAL:
mReg->PrepareSetValue(mRootkey, *mSubkey, &aReturn);
break;
default:
break;
}
return aReturn;
}
void nsWinRegItem::Abort()
{
}
/* Private Methods */
nsString* nsWinRegItem::keystr(PRInt32 root, nsString* mSubkey, nsString* mName)
{
nsString rootstr;
nsString* finalstr = nsnull;
char* istr = nsnull;
switch(root)
{
case nsWinReg::NS_HKEY_CLASSES_ROOT:
rootstr.AssignLiteral("HKEY_CLASSES_ROOT\\");
break;
case nsWinReg::NS_HKEY_CURRENT_USER:
rootstr.AssignLiteral("HKEY_CURRENT_USER\\");
break;
case nsWinReg::NS_HKEY_LOCAL_MACHINE:
rootstr.AssignLiteral("HKEY_LOCAL_MACHINE\\");
break;
case nsWinReg::NS_HKEY_USERS:
rootstr.AssignLiteral("HKEY_USERS\\");
break;
default:
istr = itoa(root);
if (istr)
{
rootstr.AssignLiteral("#");
rootstr.AppendWithConversion(istr);
rootstr.AppendLiteral("\\");
PR_DELETE(istr);
}
break;
}
finalstr = new nsString(rootstr);
if(finalstr != nsnull)
{
finalstr->Append(*mSubkey);
finalstr->AppendLiteral(" [");
if(mName != nsnull)
finalstr->Append(*mName);
finalstr->AppendLiteral("]");
}
return finalstr;
}
char* nsWinRegItem::itoa(PRInt32 n)
{
char* s;
int i, sign;
if((sign = n) < 0)
n = -n;
i = 0;
s = (char*)PR_CALLOC(sizeof(char));
do
{
s = (char*)PR_REALLOC(s, (i+1)*sizeof(char));
s[i++] = n%10 + '0';
s[i] = '\0';
} while ((n/=10) > 0);
if(sign < 0)
{
s = (char*)PR_REALLOC(s, (i+1)*sizeof(char));
s[i++] = '-';
}
s[i] = '\0';
reverseString(s);
return s;
}
void nsWinRegItem::reverseString(char* s)
{
int c, i, j;
for(i=0, j=strlen(s)-1; i<j; i++, j--)
{
c = s[i];
s[i] = s[j];
s[j] = c;
}
}
/* CanUninstall
* WinRegItem() does not install any files which can be uninstalled,
* hence this function returns false.
*/
PRBool
nsWinRegItem:: CanUninstall()
{
return PR_FALSE;
}
/* RegisterPackageNode
* WinRegItem() installs files which need to be registered,
* hence this function returns true.
*/
PRBool
nsWinRegItem:: RegisterPackageNode()
{
return PR_TRUE;
}

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

@ -1,107 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (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/MPL/
*
* 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.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsWinRegItem_h__
#define nsWinRegItem_h__
#include "prtypes.h"
#include "nsSoftwareUpdate.h"
#include "nsInstallObject.h"
#include "nsWinReg.h"
PR_BEGIN_EXTERN_C
class nsWinRegItem : public nsInstallObject {
public:
/* Public Fields */
/* Public Methods */
nsWinRegItem(nsWinReg* regObj,
PRInt32 root,
PRInt32 action,
const nsAString& sub,
const nsAString& valname,
const nsAString& val,
PRInt32* aReturn);
nsWinRegItem(nsWinReg* regObj,
PRInt32 root,
PRInt32 action,
const nsAString& sub,
const nsAString& valname,
PRInt32 val,
PRInt32* aReturn);
virtual ~nsWinRegItem();
PRInt32 Prepare(void);
PRInt32 Complete();
char* toString();
void Abort();
/* should these be protected? */
PRBool CanUninstall();
PRBool RegisterPackageNode();
private:
/* Private Fields */
nsWinReg* mReg; // initiating WinReg object
PRInt32 mRootkey;
PRInt32 mCommand;
nsString* mSubkey; // Name of section
nsString* mName; // Name of key
void* mValue; // data to write
/* Private Methods */
nsString* keystr(PRInt32 root, nsString* subkey, nsString* name);
char* itoa(PRInt32 n);
void reverseString(char* s);
};
PR_END_EXTERN_C
#endif /* nsWinRegItem_h__ */

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

@ -1,75 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (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/MPL/
*
* 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.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsWinRegValue_h__
#define nsWinRegValue_h__
#include "prtypes.h"
PR_BEGIN_EXTERN_C
struct nsWinRegValue {
public:
/* Public Fields */
PRInt32 type;
void* data;
PRInt32 data_length;
/* Public Methods */
nsWinRegValue(PRInt32 datatype, void* regdata, PRInt32 len)
{
type = datatype;
data = regdata;
data_length = len;
}
/* should we copy the regdata? */
private:
/* Private Fields */
/* Private Methods */
};
PR_END_EXTERN_C
#endif /* nsWinRegValue_h__ */

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

@ -1,109 +0,0 @@
/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (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/MPL/
*
* 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, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Sean Su <ssu@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/* This is a hack for vc5.0. It needs to be set *before* any shell
* include files. The INITGUID definition turns off the inclusion
* of shlguid.h in shlobj.h so it has to be done explicitly.
*/
#if (_MSC_VER == 1100)
#define INITGUID
#include "objbase.h"
DEFINE_OLEGUID(IID_IPersistFile, 0x0000010BL, 0, 0);
#endif
#include <shlobj.h>
#include <shlguid.h>
#include "nsWinShortcut.h"
HRESULT CreateALink(LPCSTR lpszPathObj, LPCSTR lpszPathLink, LPCSTR lpszDesc, LPCSTR lpszWorkingPath, LPCSTR lpszArgs, LPCSTR lpszIconFullPath, int iIcon)
{
HRESULT hres;
IShellLink *psl;
char lpszFullPath[MAX_BUF];
lstrcpy(lpszFullPath, lpszPathLink);
lstrcat(lpszFullPath, "\\");
lstrcat(lpszFullPath, lpszDesc);
lstrcat(lpszFullPath, ".lnk");
CreateDirectory(lpszPathLink, NULL);
CoInitialize(NULL);
// Get a pointer to the IShellLink interface.
hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (LPVOID *)&psl);
if(SUCCEEDED(hres))
{
IPersistFile* ppf;
// Set the path to the shortcut target, and add the
// description.
psl->SetPath(lpszPathObj);
// Do not set the description at this time. We need to fix this
// parameter so it can be passed in independent of the shortcut name
// itself. Comment this code out for now until a real fix can be done.
// psl->SetDescription(lpszDesc);
if(lpszWorkingPath)
psl->SetWorkingDirectory(lpszWorkingPath);
if(lpszArgs)
psl->SetArguments(lpszArgs);
psl->SetIconLocation(lpszIconFullPath, iIcon);
// Query IShellLink for the IPersistFile interface for saving the
// shortcut in persistent storage.
hres = psl->QueryInterface(IID_IPersistFile, (LPVOID FAR *)&ppf);
if(SUCCEEDED(hres))
{
WORD wsz[MAX_BUF];
// Ensure that the string is ANSI.
MultiByteToWideChar(CP_ACP, 0, lpszFullPath, -1, (wchar_t *)wsz, MAX_BUF);
// Save the link by calling IPersistFile::Save.
hres = ppf->Save((wchar_t *)wsz, TRUE);
ppf->Release();
}
psl->Release();
}
CoUninitialize();
return hres;
}

Некоторые файлы не были показаны из-за слишком большого количества измененных файлов Показать больше