From bee33841692e352164cc3329be7d78f32fceee83 Mon Sep 17 00:00:00 2001 From: "dougt%netscape.com" Date: Tue, 23 Mar 1999 22:55:00 +0000 Subject: [PATCH] Moved javascript execution onto a new nspr thread. added delete and replace later got rid of unneeded IIDs in public header Added the correct license to all files. --- xpinstall/Makefile.in | 22 +- xpinstall/makefile.win | 22 +- xpinstall/public/Makefile.in | 21 +- xpinstall/public/makefile.win | 21 +- xpinstall/public/nsISoftwareUpdate.h | 29 +- xpinstall/public/nsSoftwareUpdateIIDs.h | 27 ++ xpinstall/src/Makefile.in | 22 +- xpinstall/src/makefile.win | 118 +++---- xpinstall/src/nsInstall.cpp | 62 ++-- xpinstall/src/nsInstall.h | 42 ++- xpinstall/src/nsInstallDelete.cpp | 26 +- xpinstall/src/nsInstallDelete.h | 24 +- xpinstall/src/nsInstallExecute.cpp | 36 +- xpinstall/src/nsInstallExecute.h | 24 +- xpinstall/src/nsInstallFile.cpp | 54 +-- xpinstall/src/nsInstallFile.h | 24 +- xpinstall/src/nsInstallFolder.cpp | 26 +- xpinstall/src/nsInstallFolder.h | 26 ++ xpinstall/src/nsInstallPatch.cpp | 28 +- xpinstall/src/nsInstallPatch.h | 2 +- xpinstall/src/nsInstallTrigger.cpp | 2 +- xpinstall/src/nsInstallVersion.cpp | 4 +- xpinstall/src/nsJSInstall.cpp | 107 +++--- xpinstall/src/nsSoftwareUpdate.cpp | 107 +++--- xpinstall/src/nsSoftwareUpdate.h | 7 +- xpinstall/src/nsSoftwareUpdateRun.cpp | 414 +++++++++++++++-------- xpinstall/src/nsSoftwareUpdateRun.h | 4 +- xpinstall/src/nsSoftwareUpdateStream.cpp | 4 +- 28 files changed, 837 insertions(+), 468 deletions(-) diff --git a/xpinstall/Makefile.in b/xpinstall/Makefile.in index 16b83d80736c..2db90e9d39d4 100644 --- a/xpinstall/Makefile.in +++ b/xpinstall/Makefile.in @@ -1,19 +1,27 @@ +#!gmake # # The contents of this file are subject to the Netscape Public License -# Version 1.0 (the "NPL"); you may not use this file except in -# compliance with the NPL. You may obtain a copy of the NPL at +# Version 1.0 (the "License"); you may not use this file except in +# compliance with the License. You may obtain a copy of the License at # http://www.mozilla.org/NPL/ # -# Software distributed under the NPL is distributed on an "AS IS" basis, -# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL +# Software distributed under the License is distributed on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License # for the specific language governing rights and limitations under the -# NPL. +# License. # -# The Initial Developer of this code under the NPL is Netscape -# Communications Corporation. Portions created by Netscape are +# 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 Netscape are # Copyright (C) 1998 Netscape Communications Corporation. All Rights # Reserved. # +# Contributors: +# Daniel Veditz +# Douglas Turner + DEPTH = .. topsrcdir = @top_srcdir@ diff --git a/xpinstall/makefile.win b/xpinstall/makefile.win index 6b60af16bc76..39362d93c1bb 100644 --- a/xpinstall/makefile.win +++ b/xpinstall/makefile.win @@ -1,19 +1,27 @@ #!nmake # # The contents of this file are subject to the Netscape Public License -# Version 1.0 (the "NPL"); you may not use this file except in -# compliance with the NPL. You may obtain a copy of the NPL at +# Version 1.0 (the "License"); you may not use this file except in +# compliance with the License. You may obtain a copy of the License at # http://www.mozilla.org/NPL/ # -# Software distributed under the NPL is distributed on an "AS IS" basis, -# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL +# Software distributed under the License is distributed on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License # for the specific language governing rights and limitations under the -# NPL. +# License. # -# The Initial Developer of this code under the NPL is Netscape -# Communications Corporation. Portions created by Netscape are +# 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 Netscape are # Copyright (C) 1998 Netscape Communications Corporation. All Rights # Reserved. +# +# Contributors: +# Daniel Veditz +# Douglas Turner + DEPTH=.. diff --git a/xpinstall/public/Makefile.in b/xpinstall/public/Makefile.in index 7cbf02aafb18..fba10e6bd172 100644 --- a/xpinstall/public/Makefile.in +++ b/xpinstall/public/Makefile.in @@ -1,19 +1,26 @@ #!gmake # # The contents of this file are subject to the Netscape Public License -# Version 1.0 (the "NPL"); you may not use this file except in -# compliance with the NPL. You may obtain a copy of the NPL at +# Version 1.0 (the "License"); you may not use this file except in +# compliance with the License. You may obtain a copy of the License at # http://www.mozilla.org/NPL/ # -# Software distributed under the NPL is distributed on an "AS IS" basis, -# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL +# Software distributed under the License is distributed on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License # for the specific language governing rights and limitations under the -# NPL. +# License. # -# The Initial Developer of this code under the NPL is Netscape -# Communications Corporation. Portions created by Netscape are +# 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 Netscape are # Copyright (C) 1998 Netscape Communications Corporation. All Rights # Reserved. +# +# Contributors: +# Daniel Veditz +# Douglas Turner DEPTH = ../.. topsrcdir = @top_srcdir@ diff --git a/xpinstall/public/makefile.win b/xpinstall/public/makefile.win index 991ea15869dc..b86192b1048d 100644 --- a/xpinstall/public/makefile.win +++ b/xpinstall/public/makefile.win @@ -1,19 +1,26 @@ #!nmake # # The contents of this file are subject to the Netscape Public License -# Version 1.0 (the "NPL"); you may not use this file except in -# compliance with the NPL. You may obtain a copy of the NPL at +# Version 1.0 (the "License"); you may not use this file except in +# compliance with the License. You may obtain a copy of the License at # http://www.mozilla.org/NPL/ # -# Software distributed under the NPL is distributed on an "AS IS" basis, -# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL +# Software distributed under the License is distributed on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License # for the specific language governing rights and limitations under the -# NPL. +# License. # -# The Initial Developer of this code under the NPL is Netscape -# Communications Corporation. Portions created by Netscape are +# 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 Netscape are # Copyright (C) 1998 Netscape Communications Corporation. All Rights # Reserved. +# +# Contributors: +# Daniel Veditz +# Douglas Turner DEPTH=..\.. diff --git a/xpinstall/public/nsISoftwareUpdate.h b/xpinstall/public/nsISoftwareUpdate.h index f6058f61b03f..288ce0e4c02e 100644 --- a/xpinstall/public/nsISoftwareUpdate.h +++ b/xpinstall/public/nsISoftwareUpdate.h @@ -1,19 +1,26 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* * The contents of this file are subject to the Netscape Public License - * Version 1.0 (the "NPL"); you may not use this file except in - * compliance with the NPL. You may obtain a copy of the NPL at + * Version 1.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at * http://www.mozilla.org/NPL/ * - * Software distributed under the NPL is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License * for the specific language governing rights and limitations under the - * NPL. + * License. * - * The Initial Developer of this code under the NPL is Netscape - * Communications Corporation. Portions created by Netscape are + * 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 Netscape are * Copyright (C) 1998 Netscape Communications Corporation. All Rights * Reserved. + * + * Contributors: + * Daniel Veditz + * Douglas Turner */ #ifndef nsISoftwareUpdate_h__ @@ -41,6 +48,10 @@ class nsISoftwareUpdate : public nsISupports const nsString& flags, const nsString& args) = 0; + // these should be in a private interface: + NS_IMETHOD RunNextInstall() = 0; + NS_IMETHOD InstallJarCallBack() = 0; + }; diff --git a/xpinstall/public/nsSoftwareUpdateIIDs.h b/xpinstall/public/nsSoftwareUpdateIIDs.h index 6b365e0f10c0..97363c3d33fc 100644 --- a/xpinstall/public/nsSoftwareUpdateIIDs.h +++ b/xpinstall/public/nsSoftwareUpdateIIDs.h @@ -1,3 +1,28 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is Mozilla Communicator client code, + * released March 31, 1998. + * + * The Initial Developer of the Original Code is Netscape Communications + * Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + * + * Contributors: + * Daniel Veditz + * Douglas Turner + */ + #ifndef nsSoftwareUpdateIIDs_h___ #define nsSoftwareUpdateIIDs_h___ @@ -65,6 +90,7 @@ {0xbc, 0xde, 0x00, 0x80, 0x5f, 0x0e, 0x13, 0x53} \ } +#if 0 #define NS_SoftwareUpdateInstallFolder_CID \ { /* 18c2f991-b09f-11d2-bcde-00805f0e1353 */ \ 0x18c2f991, \ @@ -80,5 +106,6 @@ 0x11d2, \ {0xbc, 0xde, 0x00, 0x80, 0x5f, 0x0e, 0x13, 0x53} \ } +#endif #endif /* nsSoftwareUpdateIIDs_h___ */ \ No newline at end of file diff --git a/xpinstall/src/Makefile.in b/xpinstall/src/Makefile.in index 5c8e2282e987..cc6f5fbe170b 100644 --- a/xpinstall/src/Makefile.in +++ b/xpinstall/src/Makefile.in @@ -1,19 +1,26 @@ +#!gmake # # The contents of this file are subject to the Netscape Public License -# Version 1.0 (the "NPL"); you may not use this file except in -# compliance with the NPL. You may obtain a copy of the NPL at +# Version 1.0 (the "License"); you may not use this file except in +# compliance with the License. You may obtain a copy of the License at # http://www.mozilla.org/NPL/ # -# Software distributed under the NPL is distributed on an "AS IS" basis, -# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL +# Software distributed under the License is distributed on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License # for the specific language governing rights and limitations under the -# NPL. +# License. # -# The Initial Developer of this code under the NPL is Netscape -# Communications Corporation. Portions created by Netscape are +# 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 Netscape are # Copyright (C) 1998 Netscape Communications Corporation. All Rights # Reserved. # +# Contributors: +# Daniel Veditz +# Douglas Turner DEPTH = ../.. topsrcdir = @top_srcdir@ @@ -40,6 +47,7 @@ CPPSRCS = \ nsJSInstallTriggerGlobal.cpp\ nsSoftwareUpdateRun.cpp \ nsSoftwareUpdateStream.cpp \ + ScheduledTasks.cpp \ $(NULL) diff --git a/xpinstall/src/makefile.win b/xpinstall/src/makefile.win index 3278e567aae3..8523ba4828fa 100644 --- a/xpinstall/src/makefile.win +++ b/xpinstall/src/makefile.win @@ -1,92 +1,94 @@ -#!gmake +#!nmake # # The contents of this file are subject to the Netscape Public License -# Version 1.0 (the "NPL"); you may not use this file except in -# compliance with the NPL. You may obtain a copy of the NPL at +# Version 1.0 (the "License"); you may not use this file except in +# compliance with the License. You may obtain a copy of the License at # http://www.mozilla.org/NPL/ # -# Software distributed under the NPL is distributed on an "AS IS" basis, -# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL +# Software distributed under the License is distributed on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License # for the specific language governing rights and limitations under the -# NPL. +# License. # -# The Initial Developer of this code under the NPL is Netscape -# Communications Corporation. Portions created by Netscape are +# 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 Netscape are # Copyright (C) 1998 Netscape Communications Corporation. All Rights # Reserved. +# +# Contributors: +# Daniel Veditz +# Douglas Turner DEPTH=..\.. IGNORE_MANIFEST=1 - +MAKE_OBJ_TYPE = DLL MODULE=xpinstall DLL=.\$(OBJDIR)\$(MODULE).dll -DEFINES=-D_IMPL_NS_DOM +DEFINES=-D_IMPL_NS_DOM -DWIN32_LEAN_AND_MEAN -LCFLAGS = \ +LCFLAGS = \ $(LCFLAGS) \ $(DEFINES) \ $(NULL) -LINCS= \ - -I..\base \ - -I$(XPDIST)\public\xpinstall \ - -I$(XPDIST)\public\js \ - -I$(XPDIST)\public\jar \ - -I$(XPDIST)\public\netlib \ - -I$(XPDIST)\public\network \ - -I$(XPDIST)\public\dom \ - -I$(XPDIST)\public\xpcom \ - -I$(XPDIST)\public\util \ - -I$(XPDIST)\public\nspr2 \ - -I$(XPDIST)\public\pref \ - -I$(XPDIST)\public\raptor \ - -I$(XPDIST)\public\libreg \ - $(NULL) +LINCS= \ + -I$(XPDIST)\public\xpinstall \ + -I$(XPDIST)\public\jar \ + -I$(XPDIST)\public\libreg \ + -I$(XPDIST)\public\netlib \ + -I$(XPDIST)\public\xpcom \ + -I$(XPDIST)\public\pref \ + -I$(XPDIST)\public\js \ + -I$(XPDIST)\public\dom \ + -I$(XPDIST)\public\raptor \ + -I$(XPDIST)\public\nspr2 \ + $(NULL) -LLIBS = \ - $(DIST)\lib\jar50.lib \ - $(DIST)\lib\libreg32.lib \ - $(DIST)\lib\netlib.lib \ - $(DIST)\lib\xpcom32.lib \ - $(DIST)\lib\xppref32.lib \ - $(DIST)\lib\xplib.lib \ - $(DIST)\lib\js3250.lib \ - $(DIST)\lib\jsdombase_s.lib \ - $(DIST)\lib\raptorbase.lib \ - $(DIST)\lib\raptorgfxwin.lib \ - $(LIBNSPR) \ - $(DIST)\lib\libplc21.lib \ - $(NULL) +LLIBS = \ + $(DIST)\lib\jar50.lib \ + $(DIST)\lib\libreg32.lib \ + $(DIST)\lib\netlib.lib \ + $(DIST)\lib\xpcom32.lib \ + $(DIST)\lib\xppref32.lib \ + $(DIST)\lib\js3250.lib \ + $(DIST)\lib\jsdombase_s.lib \ + $(DIST)\lib\raptorbase.lib \ + $(LIBNSPR) \ + $(NULL) -OBJS = \ - .\$(OBJDIR)\nsInstall.obj \ - .\$(OBJDIR)\nsInstallTrigger.obj \ - .\$(OBJDIR)\nsInstallVersion.obj \ - .\$(OBJDIR)\nsInstallFolder.obj \ - .\$(OBJDIR)\nsJSInstall.obj \ - .\$(OBJDIR)\nsJSInstallTriggerGlobal.obj \ - .\$(OBJDIR)\nsJSInstallVersion.obj \ - .\$(OBJDIR)\nsSoftwareUpdate.obj \ - .\$(OBJDIR)\nsSoftwareUpdateRun.obj \ - .\$(OBJDIR)\nsSoftwareUpdateStream.obj \ - .\$(OBJDIR)\nsInstallFile.obj \ - .\$(OBJDIR)\nsInstallDelete.obj \ - .\$(OBJDIR)\nsInstallExecute.obj \ - .\$(OBJDIR)\nsInstallPatch.obj \ - $(NULL) +OBJS = \ + .\$(OBJDIR)\nsInstall.obj \ + .\$(OBJDIR)\nsInstallTrigger.obj \ + .\$(OBJDIR)\nsInstallVersion.obj \ + .\$(OBJDIR)\nsInstallFolder.obj \ + .\$(OBJDIR)\nsJSInstall.obj \ + .\$(OBJDIR)\nsJSInstallTriggerGlobal.obj \ + .\$(OBJDIR)\nsJSInstallVersion.obj \ + .\$(OBJDIR)\nsSoftwareUpdate.obj \ + .\$(OBJDIR)\nsSoftwareUpdateRun.obj \ + .\$(OBJDIR)\nsSoftwareUpdateStream.obj \ + .\$(OBJDIR)\nsInstallFile.obj \ + .\$(OBJDIR)\nsInstallDelete.obj \ + .\$(OBJDIR)\nsInstallExecute.obj \ + .\$(OBJDIR)\nsInstallPatch.obj \ + .\$(OBJDIR)\ScheduledTasks.obj \ + $(NULL) include <$(DEPTH)\config\rules.mak> install:: $(DLL) - $(MAKE_INSTALL) .\$(OBJDIR)\$(MODULE).dll $(DIST)\bin\components $(MAKE_INSTALL) .\$(OBJDIR)\$(MODULE).lib $(DIST)\lib + $(MAKE_INSTALL) .\$(OBJDIR)\$(MODULE).dll $(DIST)\bin\components clobber:: rm -f $(DIST)\lib\$(MODULE).lib - rm -f $(DIST)\bin\$(MODULE).dll + rm -f $(DIST)\bin\components\$(MODULE).dll diff --git a/xpinstall/src/nsInstall.cpp b/xpinstall/src/nsInstall.cpp index 30528b0f7b9f..40436e04c182 100644 --- a/xpinstall/src/nsInstall.cpp +++ b/xpinstall/src/nsInstall.cpp @@ -1,23 +1,30 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* * The contents of this file are subject to the Netscape Public License * Version 1.0 (the "License"); you may not use this file except in * compliance with the License. You may obtain a copy of the License at * http://www.mozilla.org/NPL/ * - * Software distributed under the License is distributed on an "AS IS" - * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See - * the License for the specific language governing rights and limitations - * under the License. + * 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 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 Netscape are Copyright (C) 1998 - * Netscape Communications Corporation. All Rights Reserved. + * The Initial Developer of the Original Code is Netscape Communications + * Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + * + * Contributors: + * Daniel Veditz + * Douglas Turner */ + #include "nscore.h" #include "nsIFactory.h" #include "nsISupports.h" @@ -71,7 +78,9 @@ nsInstallInfo::nsInstallInfo(const nsString& fromURL, const nsString& arguments, mArguments = new nsString(arguments); mFlags = new nsString(flags); mLocalFile = new nsString(); - + + mInstalled = PR_FALSE; + mMultipleTrigger = PR_FALSE; mFromURLs = nsnull; mLocalFiles = nsnull; @@ -88,6 +97,7 @@ nsInstallInfo::nsInstallInfo(nsVector* fromURL, const nsString& arguments, const mArguments = new nsString(arguments); mFlags = new nsString(flags); + mInstalled = PR_FALSE; mMultipleTrigger = PR_FALSE; // The following are not to be used with the Multiple Trigger @@ -213,7 +223,6 @@ nsInstallInfo::IsMultipleTrigger() return mMultipleTrigger; } - nsInstall::nsInstall() { mScriptObject = nsnull; // this is the jsobject for our context @@ -225,17 +234,14 @@ nsInstall::nsInstall() mUninstallPackage = PR_FALSE; mRegisterPackage = PR_FALSE; - mJarFileLocation = nsnull; - mInstallArguments = nsnull; + mJarFileLocation = ""; + mInstallArguments = ""; } nsInstall::~nsInstall() { if (mVersionInfo != nsnull) delete mVersionInfo; - - PR_FREEIF( mJarFileLocation ); - PR_FREEIF( mInstallArguments ); } @@ -1263,31 +1269,27 @@ nsInstall::CleanUp(void) void -nsInstall::GetJarFileLocation(char** aFile) +nsInstall::GetJarFileLocation(nsString& aFile) { - *aFile = mJarFileLocation; + aFile.SetString( mJarFileLocation ); } void -nsInstall::SetJarFileLocation(const char* aFile) +nsInstall::SetJarFileLocation(const nsString& aFile) { - PR_FREEIF(mJarFileLocation); - mJarFileLocation = (char*) malloc( strlen(aFile) + 1 ); - strncpy(mJarFileLocation, aFile, strlen(aFile) + 1 ); + mJarFileLocation.SetString(aFile); } void -nsInstall::GetInstallArguments(char** args) +nsInstall::GetInstallArguments(nsString& args) { - *args = mInstallArguments; + args.SetString( mInstallArguments ); } void -nsInstall::SetInstallArguments(const char* args) +nsInstall::SetInstallArguments(const nsString& args) { - PR_FREEIF(mInstallArguments); - mInstallArguments = (char*) malloc( strlen(args) + 1 ); - strncpy(mInstallArguments, args, strlen(args) + 1); + mInstallArguments.SetString(args); } @@ -1296,7 +1298,7 @@ PRInt32 nsInstall::OpenJARFile(void) { - PRInt32 result = ZIP_OpenArchive(mJarFileLocation, &mJarFileData); + PRInt32 result = ZIP_OpenArchive(nsAutoCString(mJarFileLocation), &mJarFileData); return result; } diff --git a/xpinstall/src/nsInstall.h b/xpinstall/src/nsInstall.h index d2acd94ab420..844f3237ddba 100644 --- a/xpinstall/src/nsInstall.h +++ b/xpinstall/src/nsInstall.h @@ -1,3 +1,29 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is Mozilla Communicator client code, + * released March 31, 1998. + * + * The Initial Developer of the Original Code is Netscape Communications + * Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + * + * Contributors: + * Daniel Veditz + * Douglas Turner + */ + + #ifndef __NS_INSTALL_H__ #define __NS_INSTALL_H__ @@ -35,7 +61,6 @@ class nsInstallInfo PRBool IsMultipleTrigger(); - private: DeleteVector(nsVector* vector); MakeTempFile(nsString aURL, nsString& tempFileString); @@ -44,7 +69,9 @@ class nsInstallInfo nsString *mFromURL; nsString *mArguments; nsString *mFlags; + + PRBool mInstalled; PRBool mMultipleTrigger; nsVector *mFromURLs; @@ -135,21 +162,20 @@ class nsInstall void AddPatch(nsHashKey *aKey, nsFileSpec* fileName); void GetPatch(nsHashKey *aKey, nsFileSpec* fileName); - void GetJarFileLocation(char** aFile); - void SetJarFileLocation(const char* aFile); + void GetJarFileLocation(nsString& aFile); + void SetJarFileLocation(const nsString& aFile); - void GetInstallArguments(char** args); - void SetInstallArguments(const char* args); + void GetInstallArguments(nsString& args); + void SetInstallArguments(const nsString& args); private: JSObject* mScriptObject; - - char* mJarFileLocation; + nsString mJarFileLocation; void* mJarFileData; - char* mInstallArguments; + nsString mInstallArguments; PRBool mUserCancelled; diff --git a/xpinstall/src/nsInstallDelete.cpp b/xpinstall/src/nsInstallDelete.cpp index baee68c8c2cb..2fb90626575c 100644 --- a/xpinstall/src/nsInstallDelete.cpp +++ b/xpinstall/src/nsInstallDelete.cpp @@ -1,19 +1,26 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* * The contents of this file are subject to the Netscape Public License - * Version 1.0 (the "NPL"); you may not use this file except in - * compliance with the NPL. You may obtain a copy of the NPL at + * Version 1.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at * http://www.mozilla.org/NPL/ * - * Software distributed under the NPL is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License * for the specific language governing rights and limitations under the - * NPL. + * License. * - * The Initial Developer of this code under the NPL is Netscape - * Communications Corporation. Portions created by Netscape are + * 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 Netscape are * Copyright (C) 1998 Netscape Communications Corporation. All Rights * Reserved. + * + * Contributors: + * Daniel Veditz + * Douglas Turner */ @@ -22,6 +29,7 @@ #include "nsFileSpec.h" #include "VerReg.h" +#include "ScheduledTasks.h" #include "nsInstallDelete.h" #include "nsInstall.h" @@ -206,7 +214,7 @@ PRInt32 nsInstallDelete::NativeComplete() if (mFinalFile->Exists()) { // If file still exists, we need to delete it later! - // FIX DeleteOldFileLater( (char*)finalFile ); + DeleteFileLater(mFinalFile->GetCString()); return nsInstall::REBOOT_NEEDED; } } diff --git a/xpinstall/src/nsInstallDelete.h b/xpinstall/src/nsInstallDelete.h index 37679c49f32e..7a444720b372 100644 --- a/xpinstall/src/nsInstallDelete.h +++ b/xpinstall/src/nsInstallDelete.h @@ -1,21 +1,29 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* * The contents of this file are subject to the Netscape Public License - * Version 1.0 (the "NPL"); you may not use this file except in - * compliance with the NPL. You may obtain a copy of the NPL at + * Version 1.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at * http://www.mozilla.org/NPL/ * - * Software distributed under the NPL is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License * for the specific language governing rights and limitations under the - * NPL. + * License. * - * The Initial Developer of this code under the NPL is Netscape - * Communications Corporation. Portions created by Netscape are + * 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 Netscape are * Copyright (C) 1998 Netscape Communications Corporation. All Rights * Reserved. + * + * Contributors: + * Daniel Veditz + * Douglas Turner */ + #ifndef nsInstallDelete_h__ #define nsInstallDelete_h__ diff --git a/xpinstall/src/nsInstallExecute.cpp b/xpinstall/src/nsInstallExecute.cpp index 50b05758cc20..247cc54c6dbe 100644 --- a/xpinstall/src/nsInstallExecute.cpp +++ b/xpinstall/src/nsInstallExecute.cpp @@ -1,22 +1,30 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* * The contents of this file are subject to the Netscape Public License - * Version 1.0 (the "NPL"); you may not use this file except in - * compliance with the NPL. You may obtain a copy of the NPL at + * Version 1.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at * http://www.mozilla.org/NPL/ * - * Software distributed under the NPL is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License * for the specific language governing rights and limitations under the - * NPL. + * License. * - * The Initial Developer of this code under the NPL is Netscape - * Communications Corporation. Portions created by Netscape are + * 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 Netscape are * Copyright (C) 1998 Netscape Communications Corporation. All Rights * Reserved. + * + * Contributors: + * Daniel Veditz + * Douglas Turner */ + #include "prmem.h" #include "nsFileSpec.h" @@ -24,6 +32,8 @@ #include "VerReg.h" #include "nsInstallExecute.h" +#include "ScheduledTasks.h" + #include "nsInstall.h" #include "nsIDOMInstallVersion.h" @@ -68,14 +78,16 @@ PRInt32 nsInstallExecute::Complete() if (mExecutableFile == nsnull) return nsInstall::INVALID_ARGUMENTS; - nsFileSpec appPath( *mExecutableFile); + nsFileSpec app( *mExecutableFile); - if (!appPath.Exists()) + if (!app.Exists()) { return nsInstall::INVALID_ARGUMENTS; } - PRInt32 result = appPath.Execute( mArgs ); + PRInt32 result = app.Execute( mArgs ); + + DeleteFileLater(app.GetCString()); return result; } @@ -90,7 +102,7 @@ void nsInstallExecute::Abort() if ( mExecutableFile->Exists() ) { - /* FIX: need to fe_deletefilelater() or something */ + DeleteFileLater(mExecutableFile->GetCString()); } } diff --git a/xpinstall/src/nsInstallExecute.h b/xpinstall/src/nsInstallExecute.h index 9149c20521b9..89d9d8569d14 100644 --- a/xpinstall/src/nsInstallExecute.h +++ b/xpinstall/src/nsInstallExecute.h @@ -1,21 +1,29 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* * The contents of this file are subject to the Netscape Public License - * Version 1.0 (the "NPL"); you may not use this file except in - * compliance with the NPL. You may obtain a copy of the NPL at + * Version 1.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at * http://www.mozilla.org/NPL/ * - * Software distributed under the NPL is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License * for the specific language governing rights and limitations under the - * NPL. + * License. * - * The Initial Developer of this code under the NPL is Netscape - * Communications Corporation. Portions created by Netscape are + * 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 Netscape are * Copyright (C) 1998 Netscape Communications Corporation. All Rights * Reserved. + * + * Contributors: + * Daniel Veditz + * Douglas Turner */ + #ifndef nsInstallExecute_h__ #define nsInstallExecute_h__ diff --git a/xpinstall/src/nsInstallFile.cpp b/xpinstall/src/nsInstallFile.cpp index 702ac3afa7d9..b61f12b96b43 100644 --- a/xpinstall/src/nsInstallFile.cpp +++ b/xpinstall/src/nsInstallFile.cpp @@ -1,26 +1,32 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* * The contents of this file are subject to the Netscape Public License - * Version 1.0 (the "NPL"); you may not use this file except in - * compliance with the NPL. You may obtain a copy of the NPL at + * Version 1.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at * http://www.mozilla.org/NPL/ * - * Software distributed under the NPL is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License * for the specific language governing rights and limitations under the - * NPL. + * License. * - * The Initial Developer of this code under the NPL is Netscape - * Communications Corporation. Portions created by Netscape are + * 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 Netscape are * Copyright (C) 1998 Netscape Communications Corporation. All Rights * Reserved. + * + * Contributors: + * Daniel Veditz + * Douglas Turner */ -#include "nsFileSpec.h" - -#include "VerReg.h" #include "nsInstallFile.h" - +#include "nsFileSpec.h" +#include "VerReg.h" +#include "ScheduledTasks.h" #include "nsInstall.h" #include "nsInstallVersion.h" @@ -191,19 +197,25 @@ PRInt32 nsInstallFile::CompleteFileMove() } else { - /* Target exists, can't trust XP_FileRename--do platform specific stuff in FE_ReplaceExistingFile() */ - // FIX: FE_ReplaceExistingFile() mFinalFile->Delete(PR_FALSE); - // Now that we have move the existing file, we can move the mExtracedFile into place. - nsFileSpec parentofFinalFile; + if (! mFinalFile->Exists()) + { + // Now that we have move the existing file, we can move the mExtracedFile into place. + nsFileSpec parentofFinalFile; - mFinalFile->GetParent(parentofFinalFile); - result = mExtracedFile->Move(parentofFinalFile); + mFinalFile->GetParent(parentofFinalFile); + result = mExtracedFile->Move(parentofFinalFile); - char* leafName = mFinalFile->GetLeafName(); - mExtracedFile->Rename(leafName); - delete [] leafName; + char* leafName = mFinalFile->GetLeafName(); + mExtracedFile->Rename(leafName); + delete [] leafName; + } + else + { + ReplaceFileLater(mExtracedFile->GetCString(), mFinalFile->GetCString() ); + result = nsInstall::REBOOT_NEEDED; + } } } diff --git a/xpinstall/src/nsInstallFile.h b/xpinstall/src/nsInstallFile.h index e1e86d7d2ddb..f31bb8624a64 100644 --- a/xpinstall/src/nsInstallFile.h +++ b/xpinstall/src/nsInstallFile.h @@ -1,21 +1,29 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* * The contents of this file are subject to the Netscape Public License - * Version 1.0 (the "NPL"); you may not use this file except in - * compliance with the NPL. You may obtain a copy of the NPL at + * Version 1.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at * http://www.mozilla.org/NPL/ * - * Software distributed under the NPL is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License * for the specific language governing rights and limitations under the - * NPL. + * License. * - * The Initial Developer of this code under the NPL is Netscape - * Communications Corporation. Portions created by Netscape are + * 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 Netscape are * Copyright (C) 1998 Netscape Communications Corporation. All Rights * Reserved. + * + * Contributors: + * Daniel Veditz + * Douglas Turner */ + #ifndef nsInstallFile_h__ #define nsInstallFile_h__ diff --git a/xpinstall/src/nsInstallFolder.cpp b/xpinstall/src/nsInstallFolder.cpp index 93a004ec467e..9aee26e59ec0 100644 --- a/xpinstall/src/nsInstallFolder.cpp +++ b/xpinstall/src/nsInstallFolder.cpp @@ -1,20 +1,26 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* * The contents of this file are subject to the Netscape Public License * Version 1.0 (the "License"); you may not use this file except in * compliance with the License. You may obtain a copy of the License at * http://www.mozilla.org/NPL/ * - * Software distributed under the License is distributed on an "AS IS" - * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See - * the License for the specific language governing rights and limitations - * under the License. + * 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 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 Netscape are Copyright (C) 1998 - * Netscape Communications Corporation. All Rights Reserved. + * The Initial Developer of the Original Code is Netscape Communications + * Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + * + * Contributors: + * Daniel Veditz + * Douglas Turner */ #include "nsInstall.h" diff --git a/xpinstall/src/nsInstallFolder.h b/xpinstall/src/nsInstallFolder.h index 2f455e3346e6..cca6f4cc2987 100644 --- a/xpinstall/src/nsInstallFolder.h +++ b/xpinstall/src/nsInstallFolder.h @@ -1,3 +1,29 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is Mozilla Communicator client code, + * released March 31, 1998. + * + * The Initial Developer of the Original Code is Netscape Communications + * Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + * + * Contributors: + * Daniel Veditz + * Douglas Turner + */ + + #ifndef __NS_INSTALLFOLDER_H__ #define __NS_INSTALLFOLDER_H__ diff --git a/xpinstall/src/nsInstallPatch.cpp b/xpinstall/src/nsInstallPatch.cpp index 687433641a17..2679278249b1 100644 --- a/xpinstall/src/nsInstallPatch.cpp +++ b/xpinstall/src/nsInstallPatch.cpp @@ -23,7 +23,7 @@ #include "nsIDOMInstallVersion.h" #include "VerReg.h" - +#include "ScheduledTasks.h" nsInstallPatch::nsInstallPatch( nsInstall* inInstall, @@ -287,7 +287,7 @@ nsInstallPatch::NativeDeleteFile(nsFileSpec* doomedFile) if (doomedFile->Exists()) { // If file still exists, we need to delete it later! - // FIX DeleteOldFileLater( (char*)finalFile ); + DeleteFileLater(doomedFile->GetCString()); return nsInstall::REBOOT_NEEDED; } } @@ -301,24 +301,26 @@ nsInstallPatch::NativeDeleteFile(nsFileSpec* doomedFile) } PRInt32 -nsInstallPatch::NativeReplace(const nsFileSpec& oldfile, const nsFileSpec& newFile) +nsInstallPatch::NativeReplace(const nsFileSpec& oldfile, nsFileSpec& newFile) { oldfile.Delete(PR_FALSE); if (oldfile.Exists()) { - //FIX: FE_ReplaceExistingFile + ReplaceFileLater(newFile.GetCString(), oldfile.GetCString() ); + return nsInstall::REBOOT_NEEDED; } - - nsFileSpec parentDirectory; - oldfile.GetParent(parentDirectory); - - if (parentDirectory.Exists() && parentDirectory.IsDirectory()) + else { - if (newFile.Move(parentDirectory) != 0) - { - return nsInstall::UNEXPECTED_ERROR; - } + // We can simple move the extracted file to the mFinalFile's parent + nsFileSpec parentofFinalFile; + + oldfile.GetParent(parentofFinalFile); + newFile.Move(parentofFinalFile); + + char* leafName = newFile.GetLeafName(); + newFile.Rename(leafName); + delete [] leafName; } return nsInstall::SUCCESS; diff --git a/xpinstall/src/nsInstallPatch.h b/xpinstall/src/nsInstallPatch.h index b2db35ca8da3..d2eade6f1cd8 100644 --- a/xpinstall/src/nsInstallPatch.h +++ b/xpinstall/src/nsInstallPatch.h @@ -73,7 +73,7 @@ class nsInstallPatch : public nsInstallObject PRInt32 NativePatch(const nsFileSpec &sourceFile, const nsFileSpec &patchfile, nsFileSpec **newFile); - PRInt32 NativeReplace (const nsFileSpec& target, const nsFileSpec& tempFile); + PRInt32 NativeReplace (const nsFileSpec& target, nsFileSpec& tempFile); PRInt32 NativeDeleteFile(nsFileSpec* doomedFile); void* HashFilePath(const nsFilePath& aPath); }; diff --git a/xpinstall/src/nsInstallTrigger.cpp b/xpinstall/src/nsInstallTrigger.cpp index 75767804b14d..72ef330a50e1 100644 --- a/xpinstall/src/nsInstallTrigger.cpp +++ b/xpinstall/src/nsInstallTrigger.cpp @@ -234,7 +234,7 @@ nsInstallTriggerFactory::CreateInstance(nsISupports *aOuter, REFNSIID aIID, void nsresult result = inst->QueryInterface(aIID, aResult); - if (result != NS_OK) + if (NS_FAILED(result)) delete inst; return result; diff --git a/xpinstall/src/nsInstallVersion.cpp b/xpinstall/src/nsInstallVersion.cpp index 91923ff87c75..74b7b152f1e0 100644 --- a/xpinstall/src/nsInstallVersion.cpp +++ b/xpinstall/src/nsInstallVersion.cpp @@ -133,7 +133,7 @@ nsInstallVersion::Init(const nsString& version) major = minor = release = build = 0; errorCode = nsInstallVersion::StringToVersionNumbers(version, &aMajor, &aMinor, &aRelease, &aBuild); - if (errorCode == NS_OK) + if (NS_SUCCEEDED(errorCode)) { Init(aMajor, aMinor, aRelease, aBuild); } @@ -416,7 +416,7 @@ nsInstallVersionFactory::CreateInstance(nsISupports *aOuter, REFNSIID aIID, void nsresult result = inst->QueryInterface(aIID, aResult); - if (result != NS_OK) + if (NS_FAILED(result)) delete inst; return result; diff --git a/xpinstall/src/nsJSInstall.cpp b/xpinstall/src/nsJSInstall.cpp index e6d7b8b825ca..e60280d4b87e 100644 --- a/xpinstall/src/nsJSInstall.cpp +++ b/xpinstall/src/nsJSInstall.cpp @@ -57,10 +57,12 @@ GetInstallProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) case INSTALL_USERPACKAGENAME: { nsAutoString prop; - if (NS_OK == a->GetUserPackageName(prop)) { - nsJSUtils::nsConvertStringToJSVal(prop, cx, vp); + if (NS_OK == a->GetUserPackageName(prop)) + { + *vp = STRING_TO_JSVAL( JS_NewUCStringCopyN(cx, prop, prop.Length()) ); } - else { + else + { return JS_TRUE; } break; @@ -68,27 +70,33 @@ GetInstallProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) case INSTALL_REGPACKAGENAME: { nsAutoString prop; - if (NS_OK == a->GetRegPackageName(prop)) { - nsJSUtils::nsConvertStringToJSVal(prop, cx, vp); + if (NS_OK == a->GetRegPackageName(prop)) + { + *vp = STRING_TO_JSVAL( JS_NewUCStringCopyN(cx, prop, prop.Length()) ); } - else { + else + { return JS_TRUE; } break; } case INSTALL_JARFILE: { - char* prop; - a->GetJarFileLocation(&prop); - nsJSUtils::nsConvertStringToJSVal(prop, cx, vp); + nsAutoString prop; + + a->GetJarFileLocation(prop); + *vp = STRING_TO_JSVAL( JS_NewUCStringCopyN(cx, prop, prop.Length()) ); + break; } case INSTALL_ARGUMENTS: { - char* prop; - a->GetInstallArguments(&prop); - nsJSUtils::nsConvertStringToJSVal(prop, cx, vp); + nsAutoString prop; + + a->GetInstallArguments(prop); + *vp = STRING_TO_JSVAL( JS_NewUCStringCopyN(cx, prop, prop.Length()) ); + break; } @@ -132,33 +140,8 @@ SetInstallProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) } -// -// Install finalizer -// -PR_STATIC_CALLBACK(void) -FinalizeInstall(JSContext *cx, JSObject *obj) +static void PR_CALLBACK FinalizeInstall(JSContext *cx, JSObject *obj) { - nsJSUtils::nsGenericFinalize(cx, obj); -} - - -// -// Install enumerate -// -PR_STATIC_CALLBACK(JSBool) -EnumerateInstall(JSContext *cx, JSObject *obj) -{ - return nsJSUtils::nsGenericEnumerate(cx, obj); -} - - -// -// Install resolve -// -PR_STATIC_CALLBACK(JSBool) -ResolveInstall(JSContext *cx, JSObject *obj, jsval id) -{ - return nsJSUtils::nsGenericResolve(cx, obj, id); } @@ -920,6 +903,9 @@ InstallUninstall(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *r } + + + /***********************************************************************/ // // class for Install @@ -931,8 +917,8 @@ JSClass InstallClass = { JS_PropertyStub, GetInstallProperty, SetInstallProperty, - EnumerateInstall, - ResolveInstall, + JS_EnumerateStub, + JS_ResolveStub, JS_ConvertStub, FinalizeInstall }; @@ -1066,4 +1052,43 @@ PRInt32 InitXPInstallObjects(nsIScriptContext *aContext, const char* jarfile, co nativeInstallObject->SetScriptObject(installObject); return NS_OK; -} \ No newline at end of file +} + + + + +PRInt32 InitXPInstallObjects(JSContext *jscontext, JSObject *global, const char* jarfile, const char* args) +{ + JSObject *installObject = nsnull; + nsInstall *nativeInstallObject; + + installObject = JS_InitClass( jscontext, // context + global, // global object + nsnull, // parent proto + &InstallClass, // JSClass + nsnull, // JSNative ctor + 0, // ctor args + nsnull, // proto props + nsnull, // proto funcs + InstallProperties, // ctor props (static) + InstallMethods); // ctor funcs (static) + + if (nsnull == installObject) + { + return NS_ERROR_FAILURE; + } + + if ( PR_FALSE == JS_DefineConstDoubles(jscontext, installObject, install_constants) ) + return NS_ERROR_FAILURE; + + + nativeInstallObject = new nsInstall(); + + nativeInstallObject->SetJarFileLocation(jarfile); + nativeInstallObject->SetInstallArguments(args); + + JS_SetPrivate(jscontext, installObject, nativeInstallObject); + nativeInstallObject->SetScriptObject(installObject); + + return NS_OK; +} diff --git a/xpinstall/src/nsSoftwareUpdate.cpp b/xpinstall/src/nsSoftwareUpdate.cpp index 80e6812a768d..75e7b8fe62d2 100644 --- a/xpinstall/src/nsSoftwareUpdate.cpp +++ b/xpinstall/src/nsSoftwareUpdate.cpp @@ -36,7 +36,7 @@ #include "nsSoftwareUpdateRun.h" #include "nsInstallTrigger.h" #include "nsInstallVersion.h" - +#include "ScheduledTasks.h" /* For Javascript Namespace Access */ #include "nsDOMCID.h" @@ -132,7 +132,7 @@ nsSoftwareUpdate::Startup() /* Stupid Hack to test js env*/ /***************************************/ // FIX: HACK HACK HACK! -#if 0 +#if 1 nsSpecialSystemDirectory jarFile(nsSpecialSystemDirectory::OS_TemporaryDirectory); jarFile += "test.jar"; if (jarFile.Exists()) @@ -143,8 +143,10 @@ nsSoftwareUpdate::Startup() /***************************************/ /* Preform Scheduled Tasks */ /***************************************/ - - DeleteScheduledNodes(); + + DeleteScheduledFiles(); + ReplaceScheduledFiles(); + return NS_OK; } @@ -189,61 +191,60 @@ NS_IMETHODIMP nsSoftwareUpdate::InstallJar(nsInstallInfo *installInfo) { mJarInstallQueue->Add( installInfo ); - UpdateInstallJarQueue(); + + RunNextInstall(); return NS_OK; } -nsresult -nsSoftwareUpdate::UpdateInstallJarQueue() +NS_IMETHODIMP +nsSoftwareUpdate::InstallJarCallBack() { - if (mInstalling == 0) + nsInstallInfo *nextInstall = (nsInstallInfo*)mJarInstallQueue->Get(0); + + if (nextInstall != nsnull) + delete nextInstall; + + mJarInstallQueue->Remove(0); + + mInstalling = PR_FALSE; + + return RunNextInstall(); + +} + + +NS_IMETHODIMP +nsSoftwareUpdate::RunNextInstall() +{ + if (mInstalling == PR_TRUE) + return NS_OK; + + mInstalling = PR_TRUE; + + // check to see if there is anything in our queue + if (mJarInstallQueue->GetSize() <= 0) { - mInstalling++; - - if (mJarInstallQueue->GetSize() <= 0) - { - mInstalling--; - return 0; - } - nsInstallInfo *nextInstall = (nsInstallInfo*)mJarInstallQueue->Get(0); - - if (nextInstall == nsnull) - { - mInstalling--; - return 0; - } - - if (nextInstall->IsMultipleTrigger() == PR_FALSE) - { - Install( nextInstall ); - - delete nextInstall; - mJarInstallQueue->Remove(0); - - mInstalling--; - - // We are done with install the last jar, let see if there are any more. - UpdateInstallJarQueue(); // FIX: Maybe we should do this different to avoid blowing our stack? - - return 0; - } - else - { - // FIX: we have a multiple trigger! - } + mInstalling = PR_FALSE; + return NS_OK; } - - return 0; -} - -nsresult -nsSoftwareUpdate::DeleteScheduledNodes() -{ + + nsInstallInfo *nextInstall = (nsInstallInfo*)mJarInstallQueue->Get(0); + + if (nextInstall->IsMultipleTrigger() == PR_FALSE) + { + RunInstall( nextInstall ); + } + else + { + ; // should we do something different?! + } + return NS_OK; } + ///////////////////////////////////////////////////////////////////////// // ///////////////////////////////////////////////////////////////////////// @@ -312,7 +313,7 @@ nsSoftwareUpdateNameSet::nsSoftwareUpdateNameSet() nsresult result = nsServiceManager::GetService(kCScriptNameSetRegistryCID, kIScriptNameSetRegistryIID, (nsISupports **)&scriptNameSet); - if (NS_OK == result) + if (NS_SUCCEEDED(result)) { scriptNameSet->AddExternalNameSet(this); } @@ -332,7 +333,7 @@ nsSoftwareUpdateNameSet::InitializeClasses(nsIScriptContext* aScriptContext) nsresult result = NS_OK; result = NS_InitInstallVersionClass(aScriptContext, nsnull); - if (result != NS_OK) return result; + if (NS_FAILED(result)) return result; result = NS_InitInstallTriggerGlobalClass(aScriptContext, nsnull); @@ -347,13 +348,13 @@ nsSoftwareUpdateNameSet::AddNameSet(nsIScriptContext* aScriptContext) nsIScriptNameSpaceManager* manager; result = aScriptContext->GetNameSpaceManager(&manager); - if (NS_OK == result) + if (NS_SUCCEEDED(result)) { result = manager->RegisterGlobalName("InstallVersion", kInstallVersion_CID, PR_TRUE); - if (result != NS_OK) return result; + if (NS_FAILED(result)) return result; result = manager->RegisterGlobalName("InstallTrigger", kInstallTrigger_CID, @@ -446,7 +447,7 @@ NSGetFactory(nsISupports* serviceMgr, nsresult res = inst->QueryInterface(kIFactoryIID, (void**) aFactory); - if (res != NS_OK) + if (NS_FAILED(res)) { delete inst; } diff --git a/xpinstall/src/nsSoftwareUpdate.h b/xpinstall/src/nsSoftwareUpdate.h index a3cef50c08cf..437b66ab1c12 100644 --- a/xpinstall/src/nsSoftwareUpdate.h +++ b/xpinstall/src/nsSoftwareUpdate.h @@ -32,16 +32,19 @@ class nsSoftwareUpdate: public nsISoftwareUpdate const nsString& flags, const nsString& args); + + + NS_IMETHOD RunNextInstall(); + NS_IMETHOD InstallJarCallBack(); private: nsresult Startup(); nsresult Shutdown(); - nsresult UpdateInstallJarQueue(); nsresult DeleteScheduledNodes(); - PRInt32 mInstalling; + PRBool mInstalling; nsVector* mJarInstallQueue; static nsSoftwareUpdate* mInstance; diff --git a/xpinstall/src/nsSoftwareUpdateRun.cpp b/xpinstall/src/nsSoftwareUpdateRun.cpp index d4540329ae2e..6c107d283425 100644 --- a/xpinstall/src/nsSoftwareUpdateRun.cpp +++ b/xpinstall/src/nsSoftwareUpdateRun.cpp @@ -1,105 +1,110 @@ #include "nsSoftwareUpdate.h" #include "nsSoftwareUpdateRun.h" -#ifndef XP_MAC -#include -#else -#include -#endif - #include "nsInstall.h" #include "zipfile.h" -#include "nsSpecialSystemDirectory.h" -#include "nspr.h" - #include "nsRepository.h" +#include "nsSpecialSystemDirectory.h" +#include "nsFileStream.h" -#include "nsIBrowserWindow.h" -#include "nsIWebShell.h" +#include "nspr.h" +#include "jsapi.h" -#include "nsIScriptContext.h" -#include "nsIScriptContextOwner.h" +#include "nsISoftwareUpdate.h" +#include "nsSoftwareUpdateIIDs.h" +static NS_DEFINE_IID(kISoftwareUpdateIID, NS_ISOFTWAREUPDATE_IID); +static NS_DEFINE_IID(kSoftwareUpdateCID, NS_SoftwareUpdate_CID); -#include "nsIURL.h" - -extern PRInt32 InitXPInstallObjects(nsIScriptContext *aContext, const char* jarfile, const char* args); - -static NS_DEFINE_IID(kIBrowserWindowIID, NS_IBROWSER_WINDOW_IID); -static NS_DEFINE_IID(kBrowserWindowCID, NS_BROWSER_WINDOW_CID); -static NS_DEFINE_IID(kIScriptContextOwnerIID, NS_ISCRIPTCONTEXTOWNER_IID); - -/* ReadFileIntoBuffer - * given a file name, reads it into buffer - * returns an error code - */ - -static short ReadFileIntoBuffer(const char* fileName, char** buffer, unsigned long *bufferSize) +static JSClass global_class = { - PRFileDesc* file; - struct stat st; - short result = 0; - - *buffer = nsnull; + "global", JSCLASS_HAS_PRIVATE, + JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, + JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub +}; - if ( stat( fileName, &st) != 0 ) +extern PRInt32 InitXPInstallObjects(JSContext *jscontext, JSObject *global, const char* jarfile, const char* args); + +// Defined in this file: +static void XPInstallErrorReporter(JSContext *cx, const char *message, JSErrorReport *report); +static nsresult GetInstallScriptFromJarfile(const char* jarFile, char** scriptBuffer, PRUint32 *scriptLength); +static nsresult SetupInstallContext(const char* jarFile, const char* args, JSRuntime **jsRT, JSContext **jsCX, JSObject **jsGlob); + +extern "C" void RunInstallOnThread(void *data); + +extern "C" NS_EXPORT PRInt32 RunInstall(const char* jarFile, const char* flags, const char* args, const char* fromURL); + + + +/////////////////////////////////////////////////////////////////////////////////////////////// +// 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) +{ + int i, j, k, n; + + fputs("xpinstall: ", stderr); + if (!report) { - result = -1; - goto fail; + fprintf(stderr, "%s\n", message); + return; } - *bufferSize = st.st_size + 1; - - *buffer = (char*) PR_MALLOC( *bufferSize); - if (*buffer == NULL) + if (report->filename) + fprintf(stderr, "%s, ", report->filename); + if (report->lineno) + fprintf(stderr, "line %u: ", report->lineno); + fputs(message, stderr); + if (!report->linebuf) { - result = -1; - goto fail; + putc('\n', stderr); + return; } - memset(*buffer, '\0', *bufferSize); - file = PR_Open(fileName, PR_RDONLY, 0644); - - if ( file == NULL) - { - result = -1; - goto fail; + fprintf(stderr, ":\n%s\n", report->linebuf); + n = report->tokenptr - report->linebuf; + for (i = j = 0; i < n; i++) { + if (report->linebuf[i] == '\t') { + for (k = (j + 8) & ~7; j < k; j++) + putc('.', stderr); + continue; + } + putc('.', stderr); + j++; } - - if ( PR_Read(file, *buffer, *bufferSize ) != st.st_size ) - { - result = -1; - PR_Close( file ); - goto fail; - } - - - PR_Close( file ); - - return result; - -fail: - if (*buffer != NULL) - delete( *buffer); - *buffer = NULL; - return result; + fputs("^\n", stderr); } -PRInt32 Install(nsInstallInfo *installInfo) -{ - return Install( (const char*) nsAutoCString( installInfo->GetLocalFile() ), - (const char*) nsAutoCString( installInfo->GetFlags() ), - (const char*) nsAutoCString( installInfo->GetArguments() ), - (const char*) nsAutoCString( installInfo->GetFromURL() )); -} -extern "C" NS_EXPORT PRInt32 Install(const char* jarFile, const char* flags, const char* args, const char* fromURL) + + + +/////////////////////////////////////////////////////////////////////////////////////////////// +// Function name : GetInstallScriptFromJarfile +// Description : Extracts and reads in a install.js file from a passed jar file. +// Return type : static nsresult +// Argument : const char* jarFile - native filepath +// Argument : char** scriptBuffer - must be deleted via delete [] +// Argument : PRUint32 *scriptLength +/////////////////////////////////////////////////////////////////////////////////////////////// + +static nsresult +GetInstallScriptFromJarfile(const char* jarFile, char** scriptBuffer, PRUint32 *scriptLength) { // Open the jarfile. void* hZip; + + *scriptBuffer = nsnull; + *scriptLength = 0; - PRInt32 rv = ZIP_OpenArchive(jarFile , &hZip); + nsresult rv = ZIP_OpenArchive(jarFile , &hZip); if (rv != ZIP_OK) return rv; @@ -108,7 +113,7 @@ extern "C" NS_EXPORT PRInt32 Install(const char* jarFile, const char* flags, con // Read manifest file for Install Script filename. //FIX: need to do. - + // Extract the install.js file to the temporary directory nsSpecialSystemDirectory installJSFileSpec(nsSpecialSystemDirectory::OS_TemporaryDirectory); installJSFileSpec += "install.js"; installJSFileSpec.MakeUnique(); @@ -116,73 +121,214 @@ extern "C" NS_EXPORT PRInt32 Install(const char* jarFile, const char* flags, con // Extract the install.js file. rv = ZIP_ExtractFile( hZip, "install.js", installJSFileSpec.GetCString() ); if (rv != ZIP_OK) + { + ZIP_CloseArchive(&hZip); + return rv; + } + + // Read it into a buffer + char* buffer; + PRUint32 bufferLength; + PRUint32 readLength; + + nsInputFileStream fileStream(installJSFileSpec); + (fileStream.GetIStream())->GetLength(&bufferLength); + buffer = new char[bufferLength + 1]; + + rv = (fileStream.GetIStream())->Read(buffer, bufferLength, &readLength); + + if (NS_SUCCEEDED(rv)) + { + *scriptBuffer = buffer; + *scriptLength = readLength; + } + else + { + delete [] buffer; + } + + ZIP_CloseArchive(&hZip); + installJSFileSpec.Delete(PR_FALSE); + + return rv; +} + +/////////////////////////////////////////////////////////////////////////////////////////////// +// Function name : SetupInstallContext +// Description : Creates a Javascript runtime and adds our xpinstall objects to it. +// Return type : static nsresult +// Argument : const char* jarFile - native filepath to where jar exists on disk +// Argument : const char* args - any arguments passed into the javascript context +// Argument : JSRuntime **jsRT - Must be deleted via JS_DestroyRuntime +// Argument : JSContext **jsCX - Must be deleted via JS_DestroyContext +// Argument : JSObject **jsGlob +/////////////////////////////////////////////////////////////////////////////////////////////// +static nsresult SetupInstallContext(const char* jarFile, + const char* args, + JSRuntime **jsRT, + JSContext **jsCX, + JSObject **jsGlob) +{ + JSRuntime *rt; + JSContext *cx; + JSObject *glob; + + *jsRT = nsnull; + *jsCX = nsnull; + *jsGlob = nsnull; + + // JS init + rt = JS_Init(8L * 1024L * 1024L); + if (!rt) + { + return -1; + } + + // new context + cx = JS_NewContext(rt, 8192); + if (!rt) + { + return -1; + } + + JS_SetErrorReporter(cx, XPInstallErrorReporter); + + // new global object + glob = JS_NewObject(cx, &global_class, nsnull, nsnull); + + // Init standard classes + JS_InitStandardClasses(cx, glob); + + // Add our Install class to this context + InitXPInstallObjects(cx, glob, jarFile, args); + + // Fix: We have to add Version and Trigger to this context!! + + + *jsRT = rt; + *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) +{ + 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 RunInstallOnThread(void *data) +{ + nsInstallInfo *installInfo = (nsInstallInfo*)data; + + RunInstall( (const char*) nsAutoCString( installInfo->GetLocalFile() ), + (const char*) nsAutoCString( installInfo->GetFlags() ), + (const char*) nsAutoCString( installInfo->GetArguments() ), + (const char*) nsAutoCString( installInfo->GetFromURL() )); + + // After Install, we need to update the queue. + + nsISoftwareUpdate *softwareUpdate; + + nsresult rv = nsComponentManager::CreateInstance( kSoftwareUpdateCID, + nsnull, + kISoftwareUpdateIID, + (void**) &softwareUpdate); + + if (NS_FAILED(rv)) + { + return ; + } + + softwareUpdate->InstallJarCallBack(); + + +} + + + +/////////////////////////////////////////////////////////////////////////////////////////////// +// Function name : RunInstall +// Description : This is the main C entrypoint to run jar installers +// Return type : PRInt32 +// Argument : const char* jarFile - a native filepath to a jarfile to be run +// Argument : const char* flags - UNUSED +// Argument : const char* args - arguments passed into the javascript env +// Argument : const char* fromURL - a url string of where this file came from UNUSED +/////////////////////////////////////////////////////////////////////////////////////////////// + + +extern "C" NS_EXPORT PRInt32 RunInstall(const char* jarFile, const char* flags, const char* args, const char* fromURL) +{ + + char *scriptBuffer; + PRUint32 scriptLength; + + JSRuntime *rt; + JSContext *cx; + JSObject *glob; + + nsresult rv = GetInstallScriptFromJarfile(jarFile, &scriptBuffer, &scriptLength); + + if (NS_FAILED(rv) || scriptBuffer == nsnull) { return rv; } - nsIWebShell* aWebShell = nsnull; - nsIBrowserWindow* aWindow = nsnull; - - rv = nsComponentManager::CreateInstance(kBrowserWindowCID, - nsnull, - kIBrowserWindowIID, - (void**) &aWindow); - - if (NS_FAILED(rv)) + rv = SetupInstallContext(jarFile, args, &rt, &cx, &glob); + if (NS_FAILED(rv)) { - goto bail; + delete [] scriptBuffer; + return rv; } - - aWindow->Init(nsnull, nsnull, nsRect(0, 0, 300, 300), PRUint32(~0), PR_FALSE); - - rv = aWindow->GetWebShell(aWebShell); - - if (rv == NS_OK) - { - nsIScriptContextOwner* scriptContextOwner; - nsIScriptContext* scriptContext; - - rv = aWebShell->QueryInterface( kIScriptContextOwnerIID, (void**)&scriptContextOwner); - if (rv == NS_OK) - { - rv = scriptContextOwner->GetScriptContext(&scriptContext); - if (NS_OK == rv) - { + + + // Go ahead and run!! + jsval rval; + + JS_EvaluateScript(cx, + glob, + scriptBuffer, + scriptLength, + nsnull, + 0, + &rval); - InitXPInstallObjects(scriptContext, jarFile, args ); - - char* buffer; - unsigned long bufferLength; - - ReadFileIntoBuffer(installJSFileSpec, &buffer, &bufferLength); - - nsAutoString retval; - PRBool isUndefined; - // We expected this to block. - scriptContext->EvaluateString(nsString(buffer), nsnull, 0, retval, &isUndefined); - - PR_FREEIF(buffer); - NS_RELEASE(scriptContext); - } - NS_RELEASE(scriptContextOwner); - } - // close and release window. -// NS_RELEASE(aWebShell); - } - -bail: - - if (aWindow != nsnull) - { - aWindow->Close(); - NS_RELEASE(aWindow); - } - - ZIP_CloseArchive(&hZip); - installJSFileSpec.Delete(PR_FALSE); - + + delete [] scriptBuffer; + + JS_DestroyContext(cx); + JS_DestroyRuntime(rt); + return rv; } + + diff --git a/xpinstall/src/nsSoftwareUpdateRun.h b/xpinstall/src/nsSoftwareUpdateRun.h index 1f7edcf7811d..6fcb7ae45c15 100644 --- a/xpinstall/src/nsSoftwareUpdateRun.h +++ b/xpinstall/src/nsSoftwareUpdateRun.h @@ -1,8 +1,6 @@ #ifndef __NS_SoftwareUpdateRun_H__ #define __NS_SoftwareUpdateRun_H__ -PRInt32 Install(nsInstallInfo *installInfo); - -extern "C" NS_EXPORT PRInt32 Install(const char* jarFile, const char* flags, const char* args, const char* fromURL); +PRInt32 RunInstall(nsInstallInfo *installInfo); #endif \ No newline at end of file diff --git a/xpinstall/src/nsSoftwareUpdateStream.cpp b/xpinstall/src/nsSoftwareUpdateStream.cpp index 9d966ec0565f..bb970805299e 100644 --- a/xpinstall/src/nsSoftwareUpdateStream.cpp +++ b/xpinstall/src/nsSoftwareUpdateStream.cpp @@ -62,7 +62,7 @@ nsSoftwareUpdateListener::nsSoftwareUpdateListener(nsInstallInfo *nextInstall) nsIURL *pURL = nsnull; mResult = NS_NewURL(&pURL, nextInstall->GetFromURL()); - if (mResult != NS_OK) + if (NS_FAILED(mResult)) return; mResult = NS_OpenURL(pURL, this); @@ -144,7 +144,7 @@ nsSoftwareUpdateListener::OnDataAvailable(nsIURL* aURL, nsIInputStream *pIStream { err = pIStream->Read(buffer, BUF_SIZE, &len); - if (err == NS_OK) + if (err == 0) { if ( PR_Write(mOutFileDesc, buffer, len) == -1 ) {