Back to index

lightning-sunbird  0.9+nobinonly
nsInstall.h
Go to the documentation of this file.
00001 /* ***** BEGIN LICENSE BLOCK *****
00002  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00003  *
00004  * The contents of this file are subject to the Mozilla Public License Version
00005  * 1.1 (the "License"); you may not use this file except in compliance with
00006  * the License. You may obtain a copy of the License at
00007  * http://www.mozilla.org/MPL/
00008  *
00009  * Software distributed under the License is distributed on an "AS IS" basis,
00010  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00011  * for the specific language governing rights and limitations under the
00012  * License.
00013  *
00014  * The Original Code is Mozilla Communicator client code, released
00015  * March 31, 1998.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *   Daniel Veditz <dveditz@netscape.com>
00024  *   Douglas Turner <dougt@netscape.com>
00025  *   Jens Bannmann <jens.b@web.de>
00026  *
00027  * Alternatively, the contents of this file may be used under the terms of
00028  * either of the GNU General Public License Version 2 or later (the "GPL"),
00029  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00030  * in which case the provisions of the GPL or the LGPL are applicable instead
00031  * of those above. If you wish to allow use of your version of this file only
00032  * under the terms of either the GPL or the LGPL, and not to allow others to
00033  * use your version of this file under the terms of the MPL, indicate your
00034  * decision by deleting the provisions above and replace them with the notice
00035  * and other provisions required by the GPL or the LGPL. If you do not delete
00036  * the provisions above, a recipient may use your version of this file under
00037  * the terms of any one of the MPL, the GPL or the LGPL.
00038  *
00039  * ***** END LICENSE BLOCK ***** */
00040 
00041 #ifndef __NS_INSTALL_H__
00042 #define __NS_INSTALL_H__
00043 
00044 #include "nscore.h"
00045 #include "nsISupports.h"
00046 
00047 #include "jsapi.h"
00048 
00049 #include "plevent.h"
00050 
00051 #include "nsString.h"
00052 #include "nsVoidArray.h"
00053 #include "nsHashtable.h"
00054 #include "nsCOMPtr.h"
00055 #include "nsILocalFile.h"
00056 #include "nsIURI.h"
00057 
00058 #include "nsSoftwareUpdate.h"
00059 
00060 #include "nsInstallObject.h"
00061 #include "nsInstallVersion.h"
00062 #include "nsInstallFolder.h"
00063 
00064 #include "nsIXPINotifier.h"
00065 #include "nsPIXPIProxy.h"
00066 
00067 #include "nsIStringBundle.h"
00068 #include "nsILocale.h"
00069 #include "nsIEventQueueService.h"
00070 #include "nsIServiceManager.h"
00071 #include "nsIComponentManager.h"
00072 #include "nsIEnumerator.h"
00073 #include "nsIZipReader.h"
00074 #include "nsIExtensionManager.h"
00075 #include "nsIPrincipal.h"
00076 
00077 #ifdef MOZ_XUL_APP
00078 #include "nsIToolkitChromeRegistry.h"
00079 #define CHROMEREG_IFACE nsIToolkitChromeRegistry
00080 #else
00081 #include "nsIChromeRegistrySea.h"
00082 #define CHROMEREG_IFACE nsIChromeRegistrySea
00083 #endif
00084 
00085 #define XPINSTALL_BUNDLE_URL "chrome://global/locale/xpinstall/xpinstall.properties"
00086 
00087 //file and directory name length maximums
00088 #ifdef XP_MAC
00089 #define MAX_FILENAME 31
00090 #elif defined (XP_WIN) || defined(XP_OS2)
00091 #define MAX_FILENAME 128
00092 #else
00093 #define MAX_FILENAME 1024
00094 #endif
00095 
00096 class nsInstallInfo
00097 {
00098   public:
00099 
00100     nsInstallInfo( PRUint32         aInstallType,
00101                    nsIFile*         aFile,
00102                    const PRUnichar* aURL,
00103                    const PRUnichar* aArgs,
00104                    nsIPrincipal*    mPrincipal,
00105                    PRUint32         aFlags,
00106                    nsIXPIListener*  aListener);
00107 
00108     virtual ~nsInstallInfo();
00109 
00110     nsIFile*            GetFile()               { return mFile.get(); }
00111     const PRUnichar*    GetURL()                { return mURL.get(); }
00112     const PRUnichar*    GetArguments()          { return mArgs.get(); }
00113     PRUint32            GetFlags()              { return mFlags; }
00114     PRUint32            GetType()               { return mType; }
00115     nsIXPIListener*     GetListener()           { return mListener.get(); }
00116     CHROMEREG_IFACE*    GetChromeRegistry()     { return mChromeRegistry; }
00117 
00118 #ifdef MOZ_XUL_APP
00119     nsIExtensionManager* GetExtensionManager()  { return mExtensionManager; }
00120     nsIURI*              GetFileJARURL()        { return mFileJARURL; }
00121     nsIURI*              GetManifestURL()       { return mManifestURL; }
00122 #else
00123     const nsCString&     GetFileJARSpec()       { return mFileJARSpec; }
00124 #endif
00125 
00126     nsCOMPtr<nsIPrincipal>      mPrincipal;
00127 
00128   private:
00129 
00130     nsresult  mError;
00131 
00132     PRUint32   mType;
00133     PRUint32   mFlags;
00134     nsString   mURL;
00135     nsString   mArgs;
00136 
00137     nsCOMPtr<nsIFile>           mFile;
00138     nsCOMPtr<nsIXPIListener>    mListener;
00139     nsCOMPtr<CHROMEREG_IFACE>   mChromeRegistry;
00140 
00141 #ifdef MOZ_XUL_APP
00142     nsCOMPtr<nsIURI>              mFileJARURL;
00143     nsCOMPtr<nsIURI>              mManifestURL;
00144     nsCOMPtr<nsIExtensionManager> mExtensionManager;
00145 #else
00146     nsCString                     mFileJARSpec;
00147 #endif
00148 };
00149 
00150 #if defined(XP_WIN) || defined(XP_OS2)
00151 #define FILESEP '\\'
00152 #elif defined XP_MAC
00153 #define FILESEP ':'
00154 #elif defined XP_BEOS
00155 #define FILESEP '/'
00156 #else
00157 #define FILESEP '/'
00158 #endif
00159 
00160 // not using 0x1 in this bitfield because it causes problems with legacy code
00161 #define DO_NOT_UNINSTALL  0x2
00162 #define WIN_SHARED_FILE   0x4
00163 #define WIN_SYSTEM_FILE   0x8
00164 
00165 class nsInstall
00166 {
00167     friend class nsWinReg;
00168     friend class nsWinProfile;
00169 
00170     public:
00171 
00172         enum
00173         {
00174             BAD_PACKAGE_NAME            = -200,
00175             UNEXPECTED_ERROR            = -201,
00176             ACCESS_DENIED               = -202,
00177             EXECUTION_ERROR             = -203,
00178             NO_INSTALL_SCRIPT           = -204,
00179             NO_CERTIFICATE              = -205,
00180             NO_MATCHING_CERTIFICATE     = -206,
00181             CANT_READ_ARCHIVE           = -207,
00182             INVALID_ARGUMENTS           = -208,
00183             ILLEGAL_RELATIVE_PATH       = -209,
00184             USER_CANCELLED              = -210,
00185             INSTALL_NOT_STARTED         = -211,
00186             SILENT_MODE_DENIED          = -212,
00187             NO_SUCH_COMPONENT           = -213,
00188             DOES_NOT_EXIST              = -214,
00189             READ_ONLY                   = -215,
00190             IS_DIRECTORY                = -216,
00191             NETWORK_FILE_IS_IN_USE      = -217,
00192             APPLE_SINGLE_ERR            = -218,
00193             INVALID_PATH_ERR            = -219,
00194             PATCH_BAD_DIFF              = -220,
00195             PATCH_BAD_CHECKSUM_TARGET   = -221,
00196             PATCH_BAD_CHECKSUM_RESULT   = -222,
00197             UNINSTALL_FAILED            = -223,
00198             PACKAGE_FOLDER_NOT_SET      = -224,
00199             EXTRACTION_FAILED           = -225,
00200             FILENAME_ALREADY_USED       = -226,
00201             INSTALL_CANCELLED           = -227,
00202             DOWNLOAD_ERROR              = -228,
00203             SCRIPT_ERROR                = -229,
00204 
00205             ALREADY_EXISTS              = -230,
00206             IS_FILE                     = -231,
00207             SOURCE_DOES_NOT_EXIST       = -232,
00208             SOURCE_IS_DIRECTORY         = -233,
00209             SOURCE_IS_FILE              = -234,
00210             INSUFFICIENT_DISK_SPACE     = -235,
00211             FILENAME_TOO_LONG           = -236,
00212 
00213             UNABLE_TO_LOCATE_LIB_FUNCTION = -237,
00214             UNABLE_TO_LOAD_LIBRARY        = -238,
00215 
00216             CHROME_REGISTRY_ERROR       = -239,
00217 
00218             MALFORMED_INSTALL           = -240,
00219 
00220             KEY_ACCESS_DENIED           = -241,
00221             KEY_DOES_NOT_EXIST          = -242,
00222             VALUE_DOES_NOT_EXIST        = -243,
00223 
00224             INVALID_SIGNATURE           = -260,
00225             INVALID_HASH                = -261,
00226             INVALID_HASH_TYPE           = -262,
00227 
00228             OUT_OF_MEMORY               = -299,
00229 
00230             GESTALT_UNKNOWN_ERR         = -5550,
00231             GESTALT_INVALID_ARGUMENT    = -5551,
00232 
00233             SUCCESS                     = 0,
00234             REBOOT_NEEDED               = 999
00235         };
00236 
00237 
00238         nsInstall(nsIZipReader * theJARFile);
00239         virtual ~nsInstall();
00240 
00241         PRInt32    SetScriptObject(void* aScriptObject);
00242 
00243         PRInt32    SaveWinRegPrototype(void* aScriptObject);
00244         PRInt32    SaveWinProfilePrototype(void* aScriptObject);
00245 
00246         JSObject*  RetrieveWinRegPrototype(void);
00247         JSObject*  RetrieveWinProfilePrototype(void);
00248 
00249         PRInt32    AbortInstall(PRInt32 aErrorNumber);
00250 
00251         PRInt32    AddDirectory(const nsString& aRegName, const nsString& aVersion, const nsString& aJarSource, nsInstallFolder* aFolder, const nsString& aSubdir, PRInt32 aMode, PRInt32* aReturn);
00252         PRInt32    AddDirectory(const nsString& aRegName, const nsString& aVersion, const nsString& aJarSource, nsInstallFolder* aFolder, const nsString& aSubdir, PRInt32* aReturn);
00253         PRInt32    AddDirectory(const nsString& aRegName, const nsString& aJarSource, nsInstallFolder* aFolder, const nsString& aSubdir, PRInt32* aReturn);
00254         PRInt32    AddDirectory(const nsString& aJarSource, PRInt32* aReturn);
00255 
00256         PRInt32    AddSubcomponent(const nsString& aRegName, const nsString& aVersion, const nsString& aJarSource, nsInstallFolder *aFolder, const nsString& aTargetName, PRInt32 aMode, PRInt32* aReturn);
00257         PRInt32    AddSubcomponent(const nsString& aRegName, const nsString& aVersion, const nsString& aJarSource, nsInstallFolder *aFolder, const nsString& aTargetName, PRInt32* aReturn);
00258         PRInt32    AddSubcomponent(const nsString& aRegName, const nsString& aJarSource, nsInstallFolder *aFolder, const nsString& aTargetName, PRInt32* aReturn);
00259         PRInt32    AddSubcomponent(const nsString& aJarSource, PRInt32* aReturn);
00260 
00261         PRInt32    DiskSpaceAvailable(const nsString& aFolder, PRInt64* aReturn);
00262         PRInt32    Execute(const nsString& aJarSource, const nsString& aArgs, PRBool aBlocking, PRInt32* aReturn);
00263         PRInt32    FinalizeInstall(PRInt32* aReturn);
00264         PRInt32    Gestalt(const nsString& aSelector, PRInt32* aReturn);
00265 
00266         PRInt32    GetComponentFolder(const nsString& aComponentName, const nsString& aSubdirectory, nsInstallFolder** aFolder);
00267         PRInt32    GetComponentFolder(const nsString& aComponentName, nsInstallFolder** aFolder);
00268 
00269         PRInt32    GetFolder(nsInstallFolder& aTargetFolder, const nsString& aSubdirectory, nsInstallFolder** aFolder);
00270         PRInt32    GetFolder(const nsString& aTargetFolder, const nsString& aSubdirectory, nsInstallFolder** aFolder);
00271         PRInt32    GetFolder(const nsString& aTargetFolder, nsInstallFolder** aFolder);
00272 
00273         PRInt32    GetLastError(PRInt32* aReturn);
00274         PRInt32    GetWinProfile(const nsString& aFolder, const nsString& aFile, JSContext* jscontext, JSClass* WinProfileClass, jsval* aReturn);
00275         PRInt32    GetWinRegistry(JSContext* jscontext, JSClass* WinRegClass, jsval* aReturn);
00276         PRInt32         LoadResources(JSContext* cx, const nsString& aBaseName, jsval* aReturn);
00277         PRInt32    Patch(const nsString& aRegName, const nsString& aVersion, const nsString& aJarSource, nsInstallFolder* aFolder, const nsString& aTargetName, PRInt32* aReturn);
00278         PRInt32    Patch(const nsString& aRegName, const nsString& aJarSource, nsInstallFolder* aFolder, const nsString& aTargetName, PRInt32* aReturn);
00279         PRInt32    RegisterChrome(nsIFile* chrome, PRUint32 chromeType, const char* path);
00280         PRInt32    RefreshPlugins(PRBool aReloadPages);
00281         PRInt32    ResetError(PRInt32 aError);
00282         PRInt32    SetPackageFolder(nsInstallFolder& aFolder);
00283         PRInt32    StartInstall(const nsString& aUserPackageName, const nsString& aPackageName, const nsString& aVersion, PRInt32* aReturn);
00284         PRInt32    Uninstall(const nsString& aPackageName, PRInt32* aReturn);
00285 
00286         PRInt32    FileOpDirCreate(nsInstallFolder& aTarget, PRInt32* aReturn);
00287         PRInt32    FileOpDirGetParent(nsInstallFolder& aTarget, nsInstallFolder** theParentFolder);
00288         PRInt32    FileOpDirRemove(nsInstallFolder& aTarget, PRInt32 aFlags, PRInt32* aReturn);
00289         PRInt32    FileOpDirRename(nsInstallFolder& aSrc, nsString& aTarget, PRInt32* aReturn);
00290         PRInt32    FileOpFileCopy(nsInstallFolder& aSrc, nsInstallFolder& aTarget, PRInt32* aReturn);
00291         PRInt32    FileOpFileDelete(nsInstallFolder& aTarget, PRInt32 aFlags, PRInt32* aReturn);
00292         PRInt32    FileOpFileExists(nsInstallFolder& aTarget, PRBool* aReturn);
00293         PRInt32    FileOpFileExecute(nsInstallFolder& aTarget, nsString& aParams, PRBool aBlocking, PRInt32* aReturn);
00294         PRInt32    FileOpFileGetNativeVersion(nsInstallFolder& aTarget, nsString* aReturn);
00295         PRInt32    FileOpFileGetDiskSpaceAvailable(nsInstallFolder& aTarget, PRInt64* aReturn);
00296         PRInt32    FileOpFileGetModDate(nsInstallFolder& aTarget, double* aReturn);
00297         PRInt32    FileOpFileGetSize(nsInstallFolder& aTarget, PRInt64* aReturn);
00298         PRInt32    FileOpFileIsDirectory(nsInstallFolder& aTarget, PRBool* aReturn);
00299         PRInt32    FileOpFileIsWritable(nsInstallFolder& aTarget, PRBool* aReturn);
00300         PRInt32    FileOpFileIsFile(nsInstallFolder& aTarget, PRBool* aReturn);
00301         PRInt32    FileOpFileModDateChanged(nsInstallFolder& aTarget, double aOldStamp, PRBool* aReturn);
00302         PRInt32    FileOpFileMove(nsInstallFolder& aSrc, nsInstallFolder& aTarget, PRInt32* aReturn);
00303         PRInt32    FileOpFileRename(nsInstallFolder& aSrc, nsString& aTarget, PRInt32* aReturn);
00304         PRInt32    FileOpFileWindowsGetShortName(nsInstallFolder& aTarget, nsString& aShortPathName);
00305         PRInt32    FileOpFileWindowsShortcut(nsIFile* aTarget, nsIFile* aShortcutPath, nsString& aDescription, nsIFile* aWorkingPath, nsString& aParams, nsIFile* aIcon, PRInt32 aIconId, PRInt32* aReturn);
00306         PRInt32    FileOpFileMacAlias(nsIFile *aSourceFile, nsIFile *aAliasFile, PRInt32* aReturn);
00307         PRInt32    FileOpFileUnixLink(nsInstallFolder& aTarget, PRInt32 aFlags, PRInt32* aReturn);
00308         PRInt32    FileOpWinRegisterServer(nsInstallFolder& aTarget, PRInt32* aReturn);
00309 
00310         void       LogComment(const nsAString& aComment);
00311 
00312         PRInt32    ExtractFileFromJar(const nsString& aJarfile, nsIFile* aSuggestedName, nsIFile** aRealName);
00313         char*      GetResourcedString(const nsAString& aResName);
00314         void       AddPatch(nsHashKey *aKey, nsIFile* fileName);
00315         void       GetPatch(nsHashKey *aKey, nsIFile** fileName);
00316 
00317         nsIFile*   GetJarFileLocation() { return mJarFileLocation; }
00318         void       SetJarFileLocation(nsIFile* aFile);
00319 
00320         void       GetInstallArguments(nsString& args);
00321         void       SetInstallArguments(const nsString& args);
00322 
00323         void       GetInstallURL(nsString& url);
00324         void       SetInstallURL(const nsString& url);
00325 
00326         PRUint32   GetInstallFlags()  { return mInstallFlags; }
00327         void       SetInstallFlags(PRUint32 aFlags) { mInstallFlags = aFlags; }
00328 
00329         PRInt32    GetInstallPlatform(nsCString& aPlatform);
00330 
00331         CHROMEREG_IFACE*    GetChromeRegistry() { return mChromeRegistry; }
00332         void                SetChromeRegistry(CHROMEREG_IFACE* reg)
00333                                 { mChromeRegistry = reg; }
00334 
00335         PRUint32   GetFinalStatus() { return mFinalStatus; }
00336         PRBool     InInstallTransaction(void) { return mInstalledFiles != nsnull; }
00337 
00338         PRInt32    Alert(nsString& string);
00339         PRInt32    ConfirmEx(nsString& aDialogTitle, nsString& aText, PRUint32 aButtonFlags, nsString& aButton0Title, nsString& aButton1Title, nsString& aButton2Title, nsString& aCheckMsg, PRBool* aCheckState, PRInt32* aReturn);
00340         void       InternalAbort(PRInt32 errcode);
00341 
00342         PRInt32    ScheduleForInstall(nsInstallObject* ob);
00343 
00344         PRInt32    SaveError(PRInt32 errcode);
00345 
00346     private:
00347         JSObject*           mScriptObject;
00348 
00349         JSObject*           mWinRegObject;
00350         JSObject*           mWinProfileObject;
00351 
00352 
00353         nsCOMPtr<nsIFile>   mJarFileLocation;
00354         nsIZipReader*       mJarFileData;
00355 
00356         nsString            mInstallArguments;
00357         nsString            mInstallURL;
00358         PRUint32            mInstallFlags;
00359         nsCString           mInstallPlatform;
00360         CHROMEREG_IFACE*    mChromeRegistry; // we don't own it, it outlives us
00361         nsInstallFolder*    mPackageFolder;
00362 
00363         PRBool              mUserCancelled;
00364         PRUint32            mFinalStatus;
00365 
00366         PRBool              mUninstallPackage;
00367         PRBool              mRegisterPackage;
00368         PRBool              mStartInstallCompleted;
00369 
00370         nsString            mRegistryPackageName;   /* Name of the package we are installing */
00371         nsString            mUIName;                /* User-readable package name */
00372         nsInstallVersion*   mVersionInfo;           /* Component version info */
00373 
00374         nsVoidArray*        mInstalledFiles;
00375         //nsCOMPtr<nsISupportsArray>   mInstalledFiles;
00376         nsHashtable*        mPatchList;
00377 
00378         nsCOMPtr<nsIXPIListener>    mListener;
00379         nsCOMPtr<nsPIXPIProxy>      mUIThreadProxy;
00380 
00381         nsCOMPtr<nsIStringBundle>   mStringBundle;
00382 
00383         PRInt32             mLastError;
00384 
00385         void        ParseFlags(int flags);
00386         PRInt32     SanityCheck(void);
00387         void        GetTime(nsString &aString);
00388 
00389         nsPIXPIProxy* GetUIThreadProxy();
00390 
00391         PRInt32     GetQualifiedRegName(const nsString& name, nsString& qualifiedRegName );
00392         PRInt32     GetQualifiedPackageName( const nsString& name, nsString& qualifiedName );
00393 
00394         void        CurrentUserNode(nsString& userRegNode);
00395         PRBool      BadRegName(const nsString& regName);
00396 
00397         void        CleanUp();
00398 
00399         PRInt32     ExtractDirEntries(const nsString& directory, nsVoidArray *paths);
00400 
00401         static void DeleteVector(nsVoidArray* vector);
00402 };
00403 
00404 nsresult MakeUnique(nsILocalFile* file);
00405 
00406 #endif