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  *
00026  * Alternatively, the contents of this file may be used under the terms of
00027  * either of the GNU General Public License Version 2 or later (the "GPL"),
00028  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00029  * in which case the provisions of the GPL or the LGPL are applicable instead
00030  * of those above. If you wish to allow use of your version of this file only
00031  * under the terms of either the GPL or the LGPL, and not to allow others to
00032  * use your version of this file under the terms of the MPL, indicate your
00033  * decision by deleting the provisions above and replace them with the notice
00034  * and other provisions required by the GPL or the LGPL. If you do not delete
00035  * the provisions above, a recipient may use your version of this file under
00036  * the terms of any one of the MPL, the GPL or the LGPL.
00037  *
00038  * ***** END LICENSE BLOCK ***** */
00039 
00040 #include "testxpi.h"
00041 
00042 typedef HRESULT (_cdecl *XpiInit)(const char *, pfnXPIProgress);
00043 typedef HRESULT (_cdecl *XpiInstall)(const char *, const char *, long);
00044 typedef void    (_cdecl *XpiExit)(void);
00045 
00046 static XpiInit          pfnXpiInit;
00047 static XpiInstall       pfnXpiInstall;
00048 static XpiExit          pfnXpiExit;
00049 
00050 extern HANDLE           hXPIStubInst;
00051 
00052 HRESULT InitializeXPIStub()
00053 {
00054   char szBuf[MAX_BUF];
00055   char szXPIStubFile[MAX_BUF];
00056 
00057   hXPIStubInst = NULL;
00058 
00059   /* get full path to xpistub.dll */
00060   if(GetFullPathName("xpistub.dll", sizeof(szXPIStubFile), szXPIStubFile, NULL) == FALSE)
00061     PrintError("File not found: xpistub.dll", ERROR_CODE_SHOW, 2);
00062 
00063   /* load xpistub.dll */
00064   if((hXPIStubInst = LoadLibraryEx(szXPIStubFile, NULL, LOAD_WITH_ALTERED_SEARCH_PATH)) == NULL)
00065   {
00066     wsprintf(szBuf, "Error loading library: %s\n", szXPIStubFile);
00067     PrintError(szBuf, ERROR_CODE_SHOW, 1);
00068   }
00069   if(((FARPROC)pfnXpiInit = GetProcAddress(hXPIStubInst, "XPI_Init")) == NULL)
00070   {
00071     wsprintf(szBuf, "GetProcAddress() failed: XPI_Init\n");
00072     PrintError(szBuf, ERROR_CODE_SHOW, 1);
00073   }
00074   if(((FARPROC)pfnXpiInstall = GetProcAddress(hXPIStubInst, "XPI_Install")) == NULL)
00075   {
00076     wsprintf(szBuf, "GetProcAddress() failed: XPI_Install\n");
00077     PrintError(szBuf, ERROR_CODE_SHOW, 1);
00078   }
00079   if(((FARPROC)pfnXpiExit = GetProcAddress(hXPIStubInst, "XPI_Exit")) == NULL)
00080   {
00081     wsprintf(szBuf, "GetProcAddress() failed: XPI_Exit\n");
00082     PrintError(szBuf, ERROR_CODE_SHOW, 1);
00083   }
00084 
00085   return(0);
00086 }
00087 
00088 HRESULT DeInitializeXPIStub()
00089 {
00090   pfnXpiInit    = NULL;
00091   pfnXpiInstall = NULL;
00092   pfnXpiExit    = NULL;
00093 
00094   if(hXPIStubInst)
00095     FreeLibrary(hXPIStubInst);
00096 
00097   return(0);
00098 }
00099 
00100 int GetTotalArchivesToInstall(LPSTR listArchive[])
00101 {
00102   int i = 0;
00103 
00104   while(TRUE)
00105   {
00106     if(*listArchive[i] != '\0')
00107       ++i;
00108     else
00109       return(i);
00110   }
00111 }
00112 
00113 HRESULT SmartUpdateJars(LPSTR szAppName, LPSTR szAppPath, LPSTR listArchive[])
00114 {
00115   int       i;
00116   int       iTotalArchives;
00117   char      szBuf[MAX_BUF];
00118   HRESULT   hrResult;
00119 
00120   hXPIStubInst = NULL;
00121 
00122   if((hrResult = InitializeXPIStub()) == TEST_OK)
00123   {
00124     RemoveBackSlash(szAppPath);
00125     hrResult = pfnXpiInit(szAppPath, cbXPIProgress);
00126     if(hrResult != 0)
00127     {
00128       wsprintf(szBuf, "XpiInit() failed: %d", hrResult);
00129       PrintError(szBuf, ERROR_CODE_HIDE, hrResult);
00130     }
00131 
00132     iTotalArchives = GetTotalArchivesToInstall(listArchive);
00133     for(i = 0; i < iTotalArchives; i++)
00134     {
00135       if(FileExists(listArchive[i]) == FALSE)
00136       {
00137         printf("File not found: %s\n", listArchive[i]);
00138 
00139         /* continue with next file */
00140         continue;
00141       }
00142 
00143       hrResult = pfnXpiInstall(listArchive[i], "", 0xFFFF);
00144       if((hrResult != TEST_OK) && (hrResult != 999))
00145       {
00146         wsprintf(szBuf, "XpiInstall() failed: %d", hrResult);
00147         PrintError(szBuf, ERROR_CODE_HIDE, hrResult);
00148 
00149         /* break out of the for loop */
00150         break;
00151       }
00152       printf("\n");
00153     }
00154 
00155     pfnXpiExit();
00156   }
00157   else
00158   {
00159     wsprintf(szBuf, "InitializeXPIStub() failed: %d", hrResult);
00160     PrintError(szBuf, ERROR_CODE_HIDE, hrResult);
00161   }
00162 
00163   DeInitializeXPIStub();
00164   return(hrResult);
00165 }
00166 
00167 void cbXPIStart(const char *URL, const char *UIName)
00168 {
00169 }
00170 
00171 void cbXPIProgress(const char* msg, PRInt32 val, PRInt32 max)
00172 {
00173   char szFilename[MAX_BUF];
00174 
00175   ParsePath((char *)msg, szFilename, sizeof(szFilename), PP_FILENAME_ONLY);
00176   if(max == 0)
00177     printf("Processing: %s\n", szFilename);
00178   else
00179     printf("Installing: %d/%d %s\n", val, max, szFilename);
00180 
00181   ProcessWindowsMessages();
00182 }
00183 
00184 void cbXPIFinal(const char *URL, PRInt32 finalStatus)
00185 {
00186 }
00187 
00188 void ProcessWindowsMessages()
00189 {
00190   MSG msg;
00191 
00192   while(PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
00193   {
00194     TranslateMessage(&msg);
00195     DispatchMessage(&msg);
00196   }
00197 }