Initial checkin of files to test xpinstall via xpistub entry point.

This is not hooked up to the build system yet.
Just checking in so I don't lose the new code.
This commit is contained in:
ssu%netscape.com 2000-02-08 11:49:22 +00:00
Родитель 655c7043b3
Коммит a672e590b3
9 изменённых файлов: 821 добавлений и 0 удалений

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

@ -0,0 +1,68 @@
#
# The contents of this file are subject to the Netscape Public
# License Version 1.1 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
# the License at http://www.mozilla.org/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) 1999 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s):
DEPTH=..\..\..\..
MAKE_OBJ_TYPE = EXE
USE_NON_MT_LIBS = 1
MODULE = TestXPI
PROGRAM = .\$(OBJDIR)\$(MODULE).exe
OBJS = \
.\$(OBJDIR)\testxpi.obj \
.\$(OBJDIR)\xpi.obj \
$(NULL)
LLFLAGS= \
/machine:i386 \
$(NULL)
include <$(DEPTH)\config\rules.mak>
install:: $(PROGRAM)
$(MAKE_INSTALL) $(PROGRAM) $(DIST)\bin
if not exist test1\nul mkdir test1
copy test1.txt test1
copy test1.js test1\install.js
cd test1
zip test1.xpi *.*
cd ..
copy test1\test1.xpi $(DIST)\bin
if not exist test2\nul mkdir test2
copy test2.txt test2
copy test2.js test2\install.js
cd test2
zip test2.xpi *.*
cd ..
copy test2\test2.xpi $(DIST)\bin
clobber_all::
$(RM) $(DIST)\bin\$(MODULE).exe
$(RM) $(DIST)\bin\test1.xpi
$(RM) $(DIST)\bin\test2.xpi
$(RM) -rf $(DIST)\bin\testxpi
$(RM) -rf test1
$(RM) -rf test2

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

@ -0,0 +1,34 @@
////////////////////////////////////////////////////////////////////////////////////////
// test1.js
//
// Acceptance test 1
// Adds a component to the testxpi directory
//
// XPInstall test
// Feb 8, 2000
//
////////////////////////////////////////////////////////////////////////////////////////
var regName = "testxpi test 1";
var vi = "1.0.1.9"
var jarSrc = "test1.txt";
var err;
err = startInstall("Acceptance: test1", "install test file 1", vi, 0);
logComment("startInstall returned: " + err);
f = getFolder("Program", "testxpi");
logComment("getFolder() returned: " + f);
err = addSubcomponent(regName, vi, jarSrc, f, jarSrc, true);
logComment("addSubComponent returned: " + err);
if(0 == getLastError())
{
err = finalizeInstall();
logComment("finalizeInstall returned: " + err);
}
else
{
abortInstall();
}

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

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

@ -0,0 +1,34 @@
////////////////////////////////////////////////////////////////////////////////////////
// test2.js
//
// Acceptance test 2
// Adds a component to the testxpi directory
//
// XPInstall test
// Feb 8, 2000
//
////////////////////////////////////////////////////////////////////////////////////////
var regName = "testxpi test 2";
var vi = "2.0.1.9"
var jarSrc = "test1.txt";
var err;
err = startInstall("Acceptance: test2", "install test file 2", vi, 0);
logComment("startInstall returned: " + err);
f = getFolder("Program", "testxpi");
logComment("getFolder() returned: " + f);
err = addSubcomponent(regName, vi, jarSrc, f, jarSrc, true);
logComment("addSubComponent returned: " + err);
if(0 == getLastError())
{
err = finalizeInstall();
logComment("finalizeInstall returned: " + err);
}
else
{
abortInstall();
}

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

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

@ -0,0 +1,387 @@
/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/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.
*
* Contributor(s):
* Sean Su <ssu@netscape.com>
*/
#include "testxpi.h"
//#define SSU_DEBUG
/* Function to show the usage for this application */
void ShowUsage(char *name)
{
char szBuf[MAX_BUF];
wsprintf(szBuf, "Usage: %s <output sea name> <files [file1] [file2]...>\n", name);
lstrcat(szBuf, "\n");
lstrcat(szBuf, " output sea name: name to use for the self-extracting executable\n");
lstrcat(szBuf, " files: one or more files to add to the self-extracing executable\n");
// MessageBox(NULL, szBuf, "Usage", MB_OK);
}
/* Function to print error message with/without error code */
void PrintError(LPSTR szMsg, DWORD dwErrorCodeSH, int iExitCode)
{
DWORD dwErr;
char szErrorString[MAX_BUF];
if(dwErrorCodeSH == ERROR_CODE_SHOW)
{
dwErr = GetLastError();
wsprintf(szErrorString, "%d : %s", dwErr, szMsg);
}
else
wsprintf(szErrorString, "%s", szMsg);
printf("%s\n", szErrorString);
printf("exit code: %d\n", iExitCode);
exit(iExitCode);
}
/* Function to remove quotes from a string */
void RemoveQuotes(LPSTR lpszSrc, LPSTR lpszDest, int iDestSize)
{
char *lpszBegin;
if(lstrlen(lpszSrc) > iDestSize)
return;
if(*lpszSrc == '\"')
lpszBegin = &lpszSrc[1];
else
lpszBegin = lpszSrc;
lstrcpy(lpszDest, lpszBegin);
if(lpszDest[lstrlen(lpszDest) - 1] == '\"')
lpszDest[lstrlen(lpszDest) - 1] = '\0';
}
/* Function to remove the last backslash from a path string */
void RemoveBackSlash(LPSTR szInput)
{
int iCounter;
DWORD dwInputLen;
if(szInput != NULL)
{
dwInputLen = lstrlen(szInput);
for(iCounter = dwInputLen -1; iCounter >= 0 ; iCounter--)
{
if(szInput[iCounter] == '\\')
szInput[iCounter] = '\0';
else
break;
}
}
}
/* Function to append a backslash to a path string */
void AppendBackSlash(LPSTR szInput, DWORD dwInputSize)
{
if(szInput != NULL)
{
if(szInput[strlen(szInput) - 1] != '\\')
{
if(((DWORD)lstrlen(szInput) + 1) < dwInputSize)
{
lstrcat(szInput, "\\");
}
}
}
}
/* Function to parse a path string for one of three parts of a path:
* Filename only
* Path only
* drive only */
void ParsePath(LPSTR szInput, LPSTR szOutput, DWORD dwOutputSize, DWORD dwType)
{
int iCounter;
DWORD dwCounter;
DWORD dwInputLen;
BOOL bFound;
if((szInput != NULL) && (szOutput != NULL))
{
bFound = FALSE;
dwInputLen = lstrlen(szInput);
ZeroMemory(szOutput, dwOutputSize);
if(dwInputLen < dwOutputSize)
{
switch(dwType)
{
case PP_FILENAME_ONLY:
for(iCounter = dwInputLen - 1; iCounter >= 0; iCounter--)
{
if(szInput[iCounter] == '\\')
{
lstrcpy(szOutput, &szInput[iCounter + 1]);
bFound = TRUE;
break;
}
}
if(bFound == FALSE)
lstrcpy(szOutput, szInput);
break;
case PP_PATH_ONLY:
for(iCounter = dwInputLen - 1; iCounter >= 0; iCounter--)
{
if(szInput[iCounter] == '\\')
{
lstrcpy(szOutput, szInput);
szOutput[iCounter + 1] = '\0';
bFound = TRUE;
break;
}
}
if(bFound == FALSE)
lstrcpy(szOutput, szInput);
break;
case PP_ROOT_ONLY:
if(szInput[1] == ':')
{
szOutput[0] = szInput[0];
szOutput[1] = szInput[1];
AppendBackSlash(szOutput, dwOutputSize);
}
else if(szInput[1] == '\\')
{
int iFoundBackSlash = 0;
for(dwCounter = 0; dwCounter < dwInputLen; dwCounter++)
{
if(szInput[dwCounter] == '\\')
{
szOutput[dwCounter] = szInput[dwCounter];
++iFoundBackSlash;
}
if(iFoundBackSlash == 3)
break;
}
if(iFoundBackSlash != 0)
AppendBackSlash(szOutput, dwOutputSize);
}
break;
}
}
}
}
/* Function to check to see if a file exists.
* If it does, return it's attributes */
long FileExists(LPSTR szFile)
{
DWORD rv;
if((rv = GetFileAttributes(szFile)) == -1)
{
return(FALSE);
}
else
{
return(rv);
}
}
/* Function to locate the first non space character in a string,
* and return a pointer to it. */
LPSTR GetFirstNonSpace(LPSTR lpszString)
{
int i;
int iStrLength;
iStrLength = lstrlen(lpszString);
for(i = 0; i < iStrLength; i++)
{
if(!isspace(lpszString[i]))
return(&lpszString[i]);
}
return(NULL);
}
/* Function to return the argument count given a command line input
* format string */
int GetArgC(LPSTR lpszCommandLine)
{
int i;
int iArgCount;
int iStrLength;
LPSTR lpszBeginStr;
BOOL bFoundQuote;
BOOL bFoundSpace;
iArgCount = 0;
lpszBeginStr = GetFirstNonSpace(lpszCommandLine);
if(lpszBeginStr == NULL)
return(iArgCount);
iStrLength = lstrlen(lpszBeginStr);
bFoundQuote = FALSE;
bFoundSpace = TRUE;
for(i = 0; i < iStrLength; i++)
{
if(lpszCommandLine[i] == '\"')
{
if(bFoundQuote == FALSE)
{
++iArgCount;
bFoundQuote = TRUE;
}
else
{
bFoundQuote = FALSE;
}
}
else if(bFoundQuote == FALSE)
{
if(!isspace(lpszCommandLine[i]) && (bFoundSpace == TRUE))
{
++iArgCount;
bFoundSpace = FALSE;
}
else if(isspace(lpszCommandLine[i]))
{
bFoundSpace = TRUE;
}
}
}
return(iArgCount);
}
/* Function to return a specific argument parameter from a given command line input
* format string. */
LPSTR GetArgV(LPSTR lpszCommandLine, int iIndex, LPSTR lpszDest, int iDestSize)
{
int i;
int j;
int iArgCount;
int iStrLength;
LPSTR lpszBeginStr;
LPSTR lpszDestTemp;
BOOL bFoundQuote;
BOOL bFoundSpace;
iArgCount = 0;
lpszBeginStr = GetFirstNonSpace(lpszCommandLine);
if(lpszBeginStr == NULL)
return(NULL);
lpszDestTemp = (char *)calloc(iDestSize, sizeof(char));
if(lpszDestTemp == NULL)
PrintError("Out of memory", ERROR_CODE_HIDE, 1);
ZeroMemory(lpszDest, iDestSize);
iStrLength = lstrlen(lpszBeginStr);
bFoundQuote = FALSE;
bFoundSpace = TRUE;
j = 0;
for(i = 0; i < iStrLength; i++)
{
if(lpszCommandLine[i] == '\"')
{
if(bFoundQuote == FALSE)
{
++iArgCount;
bFoundQuote = TRUE;
}
else
{
bFoundQuote = FALSE;
}
}
else if(bFoundQuote == FALSE)
{
if(!isspace(lpszCommandLine[i]) && (bFoundSpace == TRUE))
{
++iArgCount;
bFoundSpace = FALSE;
}
else if(isspace(lpszCommandLine[i]))
{
bFoundSpace = TRUE;
}
}
if((iIndex == (iArgCount - 1)) &&
((bFoundQuote == TRUE) || (bFoundSpace == FALSE) ||
((bFoundQuote == FALSE) && (lpszCommandLine[i] == '\"'))))
{
if(j < iDestSize)
{
lpszDestTemp[j] = lpszCommandLine[i];
++j;
}
else
{
lpszDestTemp[j] = '\0';
}
}
}
RemoveQuotes(lpszDestTemp, lpszDest, iDestSize);
free(lpszDestTemp);
return(lpszDest);
}
//int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow)
int main(void)
{
HRESULT hrResult;
char szBuf[MAX_BUF];
char szAppName[MAX_BUF];
char szAppPath[MAX_BUF];
char *listArchive[] = {"test1.xpi",
"test2.xpi",
"\0"};
if(GetModuleFileName(NULL, szBuf, sizeof(szBuf)) == 0L)
PrintError("GetModuleFileName() failed", ERROR_CODE_SHOW, 1);
ParsePath(szBuf, szAppPath, sizeof(szAppPath), PP_PATH_ONLY);
ParsePath(szBuf, szAppName, sizeof(szAppName), PP_FILENAME_ONLY);
hrResult = SmartUpdateJars(szAppName, szAppPath, listArchive);
if(hrResult == 999)
wsprintf(szBuf, "%s done\nReboot required\n", szAppName);
else
wsprintf(szBuf, "%s done\n", szAppName);
PrintError(szBuf, ERROR_CODE_SHOW, hrResult);
return(0);
}

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

@ -0,0 +1,71 @@
/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/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.
*
* Contributor(s):
* Sean Su <ssu@netscape.com>
*/
#ifndef _TESTXPI_H_
#define _TESTXPI_H_
#ifdef __cplusplus
#define PR_BEGIN_EXTERN_C extern "C" {
#define PR_END_EXTERN_C }
#else
#define PR_BEGIN_EXTERN_C
#define PR_END_EXTERN_C
#endif
typedef unsigned int PRUint32;
typedef int PRInt32;
#define PR_EXTERN(type) type
#include "windows.h"
#include "xpi.h"
#include "..\\setup\\xpistub.h"
#include <stdio.h>
#include <io.h>
#include <stdlib.h>
#include <ctype.h>
#define MAX_BUF 4096
#define ERROR_CODE_HIDE 0
#define ERROR_CODE_SHOW 1
/* PP: Parse Path */
#define PP_FILENAME_ONLY 1
#define PP_PATH_ONLY 2
#define PP_ROOT_ONLY 3
#define TEST_OK 0
void PrintError(LPSTR szMsg, DWORD dwErrorCodeSH, int iExitCode);
void RemoveQuotes(LPSTR lpszSrc, LPSTR lpszDest, int dwDestSize);
void RemoveBackSlash(LPSTR szInput);
void AppendBackSlash(LPSTR szInput, DWORD dwInputSize);
void ParsePath(LPSTR szInput, LPSTR szOutput, DWORD dwOutputSize, DWORD dwType);
long FileExists(LPSTR szFile);
int GetArgC(LPSTR lpszCommandLine);
LPSTR GetArgV(LPSTR lpszCommandLine, int iIndex, LPSTR lpszDest, int iDestSize);
#endif

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

@ -0,0 +1,187 @@
/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/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.
*
* Contributor(s):
* Sean Su <ssu@netscape.com>
*/
#include "testxpi.h"
typedef HRESULT (_cdecl *XpiInit)(const char *, pfnXPIProgress);
typedef HRESULT (_cdecl *XpiInstall)(const char *, const char *, long);
typedef void (_cdecl *XpiExit)(void);
static XpiInit pfnXpiInit;
static XpiInstall pfnXpiInstall;
static XpiExit pfnXpiExit;
static HANDLE hXPIStubInst;
struct ExtractFilesDlgInfo
{
HWND hWndDlg;
int nMaxFileBars; // maximum number of bars that can be displayed
int nMaxArchiveBars; // maximum number of bars that can be displayed
int nFileBars; // current number of bars to display
int nArchiveBars; // current number of bars to display
} dlgInfo;
HRESULT InitializeXPIStub()
{
char szBuf[MAX_BUF];
char szXPIStubFile[MAX_BUF];
hXPIStubInst = NULL;
/* get full path to xpistub.dll */
if(GetFullPathName("xpistub.dll", sizeof(szXPIStubFile), szXPIStubFile, NULL) == FALSE)
PrintError("File not found: xpistub.dll", ERROR_CODE_SHOW, 2);
/* load xpistub.dll */
if((hXPIStubInst = LoadLibraryEx(szXPIStubFile, NULL, LOAD_WITH_ALTERED_SEARCH_PATH)) == NULL)
{
wsprintf(szBuf, "Error loading library: %s\n", szXPIStubFile);
PrintError(szBuf, ERROR_CODE_SHOW, 1);
}
if(((FARPROC)pfnXpiInit = GetProcAddress(hXPIStubInst, "XPI_Init")) == NULL)
{
wsprintf(szBuf, "GetProcAddress() failed: XPI_Init\n");
PrintError(szBuf, ERROR_CODE_SHOW, 1);
}
if(((FARPROC)pfnXpiInstall = GetProcAddress(hXPIStubInst, "XPI_Install")) == NULL)
{
wsprintf(szBuf, "GetProcAddress() failed: XPI_Install\n");
PrintError(szBuf, ERROR_CODE_SHOW, 1);
}
if(((FARPROC)pfnXpiExit = GetProcAddress(hXPIStubInst, "XPI_Exit")) == NULL)
{
wsprintf(szBuf, "GetProcAddress() failed: XPI_Exit\n");
PrintError(szBuf, ERROR_CODE_SHOW, 1);
}
return(0);
}
HRESULT DeInitializeXPIStub()
{
pfnXpiInit = NULL;
pfnXpiInstall = NULL;
pfnXpiExit = NULL;
if(hXPIStubInst)
FreeLibrary(hXPIStubInst);
return(0);
}
int GetTotalArchivesToInstall(LPSTR listArchive[])
{
int i = 0;
while(TRUE)
{
if(*listArchive[i] != '\0')
++i;
else
return(i);
}
}
HRESULT SmartUpdateJars(LPSTR szAppName, LPSTR szAppPath, LPSTR listArchive[])
{
int i;
int iTotalArchives;
char szBuf[MAX_BUF];
HRESULT hrResult;
if((hrResult = InitializeXPIStub()) == TEST_OK)
{
RemoveBackSlash(szAppPath);
hrResult = pfnXpiInit(szAppPath, cbXPIProgress);
if(hrResult != 0)
{
wsprintf(szBuf, "XpiInit() failed: %d", hrResult);
PrintError(szBuf, ERROR_CODE_HIDE, hrResult);
}
iTotalArchives = GetTotalArchivesToInstall(listArchive);
for(i = 0; i < iTotalArchives; i++)
{
if(FileExists(listArchive[i]) == FALSE)
{
printf("File not found: %s\n", listArchive[i]);
/* continue with next file */
continue;
}
hrResult = pfnXpiInstall(listArchive[i], "", 0xFFFF);
if((hrResult != TEST_OK) && (hrResult != 999))
{
wsprintf(szBuf, "XpiInstall() failed: %d", hrResult);
PrintError(szBuf, ERROR_CODE_HIDE, hrResult);
/* break out of the for loop */
break;
}
}
pfnXpiExit();
}
else
{
wsprintf(szBuf, "InitializeXPIStub() failed: %d", hrResult);
PrintError(szBuf, ERROR_CODE_HIDE, hrResult);
}
DeInitializeXPIStub();
return(hrResult);
}
void cbXPIStart(const char *URL, const char *UIName)
{
}
void cbXPIProgress(const char* msg, PRInt32 val, PRInt32 max)
{
char szFilename[MAX_BUF];
ParsePath((char *)msg, szFilename, sizeof(szFilename), PP_FILENAME_ONLY);
if(max == 0)
printf("Processing: %s", szFilename);
else
printf("Installing: %d/%d %s", val, max, szFilename);
ProcessWindowsMessages();
}
void cbXPIFinal(const char *URL, PRInt32 finalStatus)
{
}
void ProcessWindowsMessages()
{
MSG msg;
while(PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}

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

@ -0,0 +1,40 @@
/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/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.
*
* Contributor(s):
* Sean Su <ssu@netscape.com>
*/
#ifndef _XPI_H_
#define _XPI_H_
HRESULT InitializeXPIStub(void);
HRESULT DeInitializeXPIStub(void);
HRESULT SmartUpdateJars(LPSTR szAppName, LPSTR szAppPath, LPSTR listArchive[]);
void cbXPIStart(const char *, const char *UIName);
void cbXPIProgress(const char* msg, PRInt32 val, PRInt32 max);
void cbXPIFinal(const char *, PRInt32 finalStatus);
void InitProgressDlg(void);
void DeInitProgressDlg(void);
int GetTotalArchivesToInstall(LPSTR listArchive[]);
void ProcessWindowsMessages();
#endif /* _XPI_H_ */