Back to index

lightning-sunbird  0.9+nobinonly
xpi.c
Go to the documentation of this file.
00001 /* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is Mozilla Communicator client code, released
00016  * March 31, 1998.
00017  *
00018  * The Initial Developer of the Original Code is
00019  * Netscape Communications Corporation.
00020  * Portions created by the Initial Developer are Copyright (C) 1998
00021  * the Initial Developer. All Rights Reserved.
00022  *
00023  * Contributor(s):
00024  *   Sean Su <ssu@netscape.com>
00025  *   IBM Corp.
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 #define INCL_DOSMODULEMGR
00042 #define INCL_DOSERRORS
00043 #include "testxpi.h"
00044 
00045 typedef APIRET (_cdecl *XpiInit)(const char *, pfnXPIProgress);
00046 typedef APIRET (_cdecl *XpiInstall)(const char *, const char *, long);
00047 typedef void    (_cdecl *XpiExit)(void);
00048 
00049 static XpiInit          pfnXpiInit;
00050 static XpiInstall      pfnXpiInstall;
00051 static XpiExit         pfnXpiExit;
00052 
00053 extern LHANDLE     hXPIStubInst;
00054 
00055 APIRET InitializeXPIStub()
00056 {
00057   char szBuf[MAX_BUF];
00058   char szXPIStubFile[MAX_BUF];
00059 
00060   hXPIStubInst = NULL;
00061 
00062   /* get full path to xpistub.dll */
00063   if(DosQueryPathInfo("xpistub.dll", sizeof(szXPIStubFile), szXPIStubFile, NULL) == FALSE)
00064     PrintError("File not found: xpistub.dll", ERROR_CODE_SHOW, 2);
00065 
00066   /* load xpistub.dll */
00067   if((DosLoadModule(&szBuf, sizeof(szBuf), szXPIStubFile, &hXPIStubInst)) != NO_ERROR)
00068   {
00069     sprintf(szBuf, "Error loading library: %s\n", szXPIStubFile);
00070     PrintError(szBuf, ERROR_CODE_SHOW, 1);
00071   }
00072   if((pfnXpiInit = DosQueryProcAddr(hXPIStubInst, 1L, NULL,"XPI_Init")) == NULL)
00073   {
00074     sprintf(szBuf, "DosQueryProcAddr() failed: XPI_Init\n");
00075     PrintError(szBuf, ERROR_CODE_SHOW, 1);
00076   }
00077   if((pfnXpiInstall = DosQueryProcAddr(hXPIStubInst, 1L, NULL,"XPI_Install")) == NULL)
00078   {
00079     sprintf(szBuf, "DosQueryProcAddr() failed: XPI_Install\n");
00080     PrintError(szBuf, ERROR_CODE_SHOW, 1);
00081   }
00082   if((pfnXpiExit = DosQueryProcAddr(hXPIStubInst, 1L, NULL,"XPI_Exit")) == NULL)
00083   {
00084     sprintf(szBuf, "DosQueryProcAddr() failed: XPI_Exit\n");
00085     PrintError(szBuf, ERROR_CODE_SHOW, 1);
00086   }
00087 
00088   return(0);
00089 }
00090 
00091 APIRET DeInitializeXPIStub()
00092 {
00093   pfnXpiInit    = NULL;
00094   pfnXpiInstall = NULL;
00095   pfnXpiExit    = NULL;
00096 
00097   if(hXPIStubInst)
00098     DosFreeModule(hXPIStubInst);
00099 
00100   return(0);
00101 }
00102 
00103 int GetTotalArchivesToInstall(PSZ listArchive[])
00104 {
00105   int i = 0;
00106 
00107   while(TRUE)
00108   {
00109     if(*listArchive[i] != '\0')
00110       ++i;
00111     else
00112       return(i);
00113   }
00114 }
00115 
00116 APIRET SmartUpdateJars(PSZ szAppName, PSZ szAppPath, PSZ listArchive[])
00117 {
00118   int       i;
00119   int       iTotalArchives;
00120   char      szBuf[MAX_BUF];
00121   APIRET   hrResult;
00122 
00123   hXPIStubInst = NULL;
00124 
00125   if((hrResult = InitializeXPIStub()) == TEST_OK)
00126   {
00127     RemoveBackSlash(szAppPath);
00128     hrResult = pfnXpiInit(szAppPath, cbXPIProgress);
00129     if(hrResult != 0)
00130     {
00131       sprintf(szBuf, "XpiInit() failed: %d", hrResult);
00132       PrintError(szBuf, ERROR_CODE_HIDE, hrResult);
00133     }
00134 
00135     iTotalArchives = GetTotalArchivesToInstall(listArchive);
00136     for(i = 0; i < iTotalArchives; i++)
00137     {
00138       if(FileExists(listArchive[i]) == FALSE)
00139       {
00140         printf("File not found: %s\n", listArchive[i]);
00141 
00142         /* continue with next file */
00143         continue;
00144       }
00145 
00146       hrResult = pfnXpiInstall(listArchive[i], "", 0xFFFF);
00147       if((hrResult != TEST_OK) && (hrResult != 999))
00148       {
00149         sprintf(szBuf, "XpiInstall() failed: %d", hrResult);
00150         PrintError(szBuf, ERROR_CODE_HIDE, hrResult);
00151 
00152         /* break out of the for loop */
00153         break;
00154       }
00155       printf("\n");
00156     }
00157 
00158     pfnXpiExit();
00159   }
00160   else
00161   {
00162     sprintf(szBuf, "InitializeXPIStub() failed: %d", hrResult);
00163     PrintError(szBuf, ERROR_CODE_HIDE, hrResult);
00164   }
00165 
00166   DeInitializeXPIStub();
00167   return(hrResult);
00168 }
00169 
00170 void cbXPIStart(const char *URL, const char *UIName)
00171 {
00172 }
00173 
00174 void cbXPIProgress(const char* msg, PRInt32 val, PRInt32 max)
00175 {
00176   char szFilename[MAX_BUF];
00177 
00178   ParsePath((char *)msg, szFilename, sizeof(szFilename), PP_FILENAME_ONLY);
00179   if(max == 0)
00180     printf("Processing: %s\n", szFilename);
00181   else
00182     printf("Installing: %d/%d %s\n", val, max, szFilename);
00183 
00184   ProcessWindowsMessages();
00185 }
00186 
00187 void cbXPIFinal(const char *URL, PRInt32 finalStatus)
00188 {
00189 }
00190 
00191    void ProcessWindowsMessages()
00192 {
00193   QMSG qmsg;
00194   HAB hab;
00195 
00196   hab = WinInitialize(0);
00197 
00198   while(WinPeekMsg(hab, &qmsg, (HWND) NULL, 0, 0, PM_REMOVE))
00199   {
00200       WinDispatchMsg(hab, &qmsg);
00201   }
00202   WinTerminate(hab);
00203 }