Bug #173821 Modify the Palm Installer to search for Palm Dlls on local disk

Changes in the PalmSync installer to search for Palm dir using Registry key settings.
Also changes to include the Palm Sync files in installer manifest.

r=ssu, sr=dveditz, a=asa
This commit is contained in:
rdayal%netscape.com 2007-05-21 14:57:36 +00:00
Родитель 828e1c135a
Коммит 82decc32d4
3 изменённых файлов: 113 добавлений и 103 удалений

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

@ -43,7 +43,7 @@
#include "HSAPI.h"
#include "resource.h"
#define CONDMGR_HSAPI_DIR "."
#define MOZ_PALMSYNC_PROXY ".\\PalmSyncProxy.dll"
#define CREATOR "addr"
#define CONDUIT_FILENAME "mozABConduit.dll"
#define REMOTE_DB "AddressDB"
@ -77,9 +77,14 @@ typedef int (WINAPI *HsCheckApiStatusPtr)(void);
typedef int (WINAPI *HsGetSyncStatusPtr)(DWORD *dwStatus);
typedef int (WINAPI *HsSetAppStatusPtr)(HsStatusType statusType, DWORD dwStartFlags);
// Define general registration fn pointer types
typedef int (WINAPI *mozDllRegisterServerPtr)(void);
typedef int (WINAPI *mozDllUnregisterServerPtr)(void);
// forward declaration
int InstallConduit();
int UninstallConduit();
BOOL gWasHotSyncRunning = FALSE;
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
@ -140,116 +145,63 @@ int APIENTRY WinMain(HINSTANCE hInstance,
}
// this function gets the install dir for installation
int GetPalmDesktopInstallDirectory(HINSTANCE hCondMgrDll, TCHAR *pPDInstallDirectory,
int *pSize )
{
int dwReturnCode;
// Get the Palm Desktop Installation directory
CmGetHotSyncExecPathPtr lpfnCmGetHotSyncExecPath;
lpfnCmGetHotSyncExecPath = (CmGetHotSyncExecPathPtr) GetProcAddress(hCondMgrDll, "CmGetHotSyncExecPath");
if( lpfnCmGetHotSyncExecPath == NULL )
// Invalid Conduit Manager Library - missing functions
return IDS_ERR_LOADING_CONDMGR;
if( (dwReturnCode=(*lpfnCmGetHotSyncExecPath)(pPDInstallDirectory, pSize)) != 0)
// Error determining Palm Desktop install directory,
// return the Conduit Manager error code.
return dwReturnCode;
if( strstr( pPDInstallDirectory, EXECUTABLE_EXTENSION ) != NULL )
{
// Remove the "HotSync.exe" portion
char* cPtr = &(pPDInstallDirectory[*pSize]);
while( cPtr >= pPDInstallDirectory )
{
if( *cPtr == DIRECTORY_SEPARATOR )
int GetPalmDesktopInstallDirectory(TCHAR *pPDInstallDirectory, unsigned long *pSize)
{
*cPtr = '\0';
break;
}
cPtr--;
}
HKEY key;
// open the key
LONG rc = ::RegOpenKey(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows\\CurrentVersion\\App Paths\\palm.exe", &key);
if (rc == ERROR_SUCCESS) {
// get key value
rc = ::RegQueryValueEx(key, "Path", NULL, NULL,
(LPBYTE)pPDInstallDirectory, pSize);
if (rc == ERROR_SUCCESS)
rc=0; // 0 is success for us
// close the key
::RegCloseKey(key);
}
// Set the size of the returned path
*pSize = strlen(pPDInstallDirectory);
return 0;
return rc;
}
// this function loads the Conduit Manager
int LoadConduitManagerDll(HINSTANCE* hCondMgrDll)
int LoadConduitManagerDll(HINSTANCE* hCondMgrDll, const TCHAR * szPalmDesktopDirectory)
{
int dwReturnCode;
HINSTANCE hInstallerCondMgrDll;
// Initialize the return value
*hCondMgrDll=NULL;
// load the temporary Conduit Manager Dll shipped with our Installer
TCHAR szInstallerCondMgrPath[_MAX_PATH];
strncpy(szInstallerCondMgrPath, CONDMGR_HSAPI_DIR, _MAX_PATH);
strncat(szInstallerCondMgrPath, DIRECTORY_SEPARATOR_STR, _MAX_PATH-strlen(szInstallerCondMgrPath));
strncat(szInstallerCondMgrPath, CONDMGR_FILENAME, _MAX_PATH-strlen(szInstallerCondMgrPath));
if( (hInstallerCondMgrDll=LoadLibrary(szInstallerCondMgrPath)) == NULL )
// Error loading temporary Conduit Manager Library
return IDS_ERR_LOADING_CONDMGR;
// Get the Palm Desktop Installation directory
TCHAR szPalmDesktopDir[_MAX_PATH];
int size=_MAX_PATH;
if( (dwReturnCode=GetPalmDesktopInstallDirectory(hInstallerCondMgrDll, szPalmDesktopDir, &size)) != 0 )
return IDS_ERR_FINDING_INSTALL_DIR;
// Construct the path of the Palm Desktop Conduit Manager
TCHAR szPDCondMgrPath[_MAX_PATH];
strncpy(szPDCondMgrPath, szPalmDesktopDir, _MAX_PATH);
strncat(szPDCondMgrPath, DIRECTORY_SEPARATOR_STR, _MAX_PATH-strlen(szPDCondMgrPath));
strncat(szPDCondMgrPath, CONDMGR_FILENAME, _MAX_PATH-strlen(szPDCondMgrPath));
// take care of any possible string overwrites
if((strlen(szPalmDesktopDirectory) + strlen(DIRECTORY_SEPARATOR_STR) + strlen(CONDMGR_FILENAME)) >= _MAX_PATH)
return IDS_ERR_LOADING_CONDMGR;
strcpy(szPDCondMgrPath, szPalmDesktopDirectory);
strcat(szPDCondMgrPath, DIRECTORY_SEPARATOR_STR);
strcat(szPDCondMgrPath, CONDMGR_FILENAME);
// Load the Conduit Manager library from the Palm Desktop directory
if( (*hCondMgrDll=LoadLibrary(szPDCondMgrPath)) == NULL )
{
// Error loading Palm Desktop Conduit Manager library
// use the one we shipped with the installer
*hCondMgrDll = hInstallerCondMgrDll;
}
else
{
// Success loading the Palm Desktop Conduit Manager
// free the Conduit Manager shipped with our installer
FreeLibrary(hInstallerCondMgrDll);
}
if( (*hCondMgrDll=LoadLibrary(szPDCondMgrPath)) != NULL )
// Successfully loaded CondMgr Library from Palm Desktop Directory
return 0;
return IDS_ERR_LOADING_CONDMGR;
}
// this function loads the Hsapi Dll
int LoadHsapiDll(HINSTANCE* hHsapiDLL, const char* szPalmDesktopDirectory)
int LoadHsapiDll(HINSTANCE* hHsapiDLL, const TCHAR * szPalmDesktopDirectory)
{
// Initialize the return value
*hHsapiDLL=NULL;
// First, try loading the HSAPI Dll from the Palm Desktop directory
TCHAR szHsapiPath[_MAX_PATH];
strncpy(szHsapiPath, szPalmDesktopDirectory, _MAX_PATH);
strncat(szHsapiPath, DIRECTORY_SEPARATOR_STR, _MAX_PATH-strlen(szHsapiPath));
strncat(szHsapiPath, HSAPI_FILENAME, _MAX_PATH-strlen(szHsapiPath));
// take care of any possible string overwrites
if((strlen(szPalmDesktopDirectory) + strlen(DIRECTORY_SEPARATOR_STR) + strlen(HSAPI_FILENAME)) >= _MAX_PATH)
return IDS_ERR_LOADING_CONDMGR;
strcpy(szHsapiPath, szPalmDesktopDirectory);
strcat(szHsapiPath, DIRECTORY_SEPARATOR_STR);
strcat(szHsapiPath, HSAPI_FILENAME);
if( (*hHsapiDLL=LoadLibrary(szHsapiPath)) != NULL )
// Successfully loaded HSAPI Library from Palm Desktop Directory
return 0;
// Second, try loading the HSAPI Dll included with the our installer
strncpy(szHsapiPath, CONDMGR_HSAPI_DIR, _MAX_PATH);
strncat(szHsapiPath, DIRECTORY_SEPARATOR_STR, _MAX_PATH-strlen(szHsapiPath));
strncat(szHsapiPath, HSAPI_FILENAME, _MAX_PATH-strlen(szHsapiPath));
if( (*hHsapiDLL=LoadLibrary(szHsapiPath)) != NULL )
// Successfully loaded HSAPI Library from support directory
return 0;
// If we get here, then there was an error loading the library
return IDS_ERR_HSAPI_NOT_FOUND;
}
@ -350,6 +302,36 @@ void StartHotSync(HINSTANCE hHsapiDLL)
}
}
int RegisterMozPalmSyncDll()
{
HINSTANCE hMozPalmSyncProxyDll = NULL;
if( (hMozPalmSyncProxyDll=LoadLibrary(MOZ_PALMSYNC_PROXY)) != NULL ) {
mozDllRegisterServerPtr lpfnmozDllRegisterServer;
lpfnmozDllRegisterServer = (mozDllRegisterServerPtr) GetProcAddress(hMozPalmSyncProxyDll, "DllRegisterServer");
DWORD dwReturnCode = (*lpfnmozDllRegisterServer)();
if(dwReturnCode == S_OK)
// Successfully registered
return 0;
}
return IDS_ERR_REGISTERING_MOZ_DLL;
}
int UnregisterMozPalmSyncDll()
{
HINSTANCE hMozPalmSyncProxyDll = NULL;
if( (hMozPalmSyncProxyDll=LoadLibrary(MOZ_PALMSYNC_PROXY)) != NULL ) {
mozDllUnregisterServerPtr lpfnmozDllUnregisterServer;
lpfnmozDllUnregisterServer = (mozDllUnregisterServerPtr) GetProcAddress(hMozPalmSyncProxyDll, "DllUnregisterServer");
DWORD dwReturnCode = (*lpfnmozDllUnregisterServer)();
if(dwReturnCode == S_OK)
// Successfully registered
return 0;
}
return IDS_ERR_UNREGISTERING_MOZ_DLL;
}
// installs our Conduit
int InstallConduit()
{
@ -362,8 +344,11 @@ int InstallConduit()
TCHAR szConduitPath[_MAX_PATH];
if(!GetCurrentDirectory(_MAX_PATH, szConduitPath))
return IDS_ERR_CONDUIT_NOT_FOUND;
strncat(szConduitPath, DIRECTORY_SEPARATOR_STR, _MAX_PATH-strlen(szConduitPath));
strncat(szConduitPath, CONDUIT_FILENAME, _MAX_PATH-strlen(szConduitPath));
// take care of any possible string overwrites
if((strlen(szConduitPath) + strlen(DIRECTORY_SEPARATOR_STR) + strlen(CONDUIT_FILENAME)) > _MAX_PATH)
return IDS_ERR_LOADING_CONDMGR;
strcat(szConduitPath, DIRECTORY_SEPARATOR_STR);
strcat(szConduitPath, CONDUIT_FILENAME);
// Make sure the conduit dll exists
struct _finddata_t dll_file;
@ -371,9 +356,23 @@ int InstallConduit()
if( (hFile = _findfirst( szConduitPath, &dll_file )) == -1L )
return IDS_ERR_CONDUIT_NOT_FOUND;
// now register the Mozilla Palm Sync Support Dll
if( (dwReturnCode = RegisterMozPalmSyncDll()) != 0)
return dwReturnCode;
// Get the Palm Desktop Installation directory
TCHAR szPalmDesktopDir[_MAX_PATH];
unsigned long size=_MAX_PATH;
// Load the Conduit Manager DLL.
HINSTANCE hConduitManagerDLL;
if( (dwReturnCode = LoadConduitManagerDll(&hConduitManagerDLL)) != 0 )
if( (dwReturnCode=GetPalmDesktopInstallDirectory(szPalmDesktopDir, &size)) == 0 ) {
if( (dwReturnCode = LoadConduitManagerDll(&hConduitManagerDLL, szPalmDesktopDir)) != 0 )
// load it from local dir if present by any chance
if( (dwReturnCode = LoadConduitManagerDll(&hConduitManagerDLL, ".")) != 0 )
return(dwReturnCode);
}
else // if registery key not load it from local dir if present by any chance
if( (dwReturnCode = LoadConduitManagerDll(&hConduitManagerDLL, ".")) != 0 )
return(dwReturnCode);
// Prepare to install the conduit using Conduit Manager functions
@ -401,15 +400,11 @@ int InstallConduit()
return(IDS_ERR_LOADING_CONDMGR);
}
// Get the Palm Desktop Installation directory
TCHAR szPalmDesktopDir[_MAX_PATH];
int size=_MAX_PATH;
if( (dwReturnCode=GetPalmDesktopInstallDirectory(hConduitManagerDLL, szPalmDesktopDir, &size)) != 0 )
return dwReturnCode;
// Load the HSAPI DLL.
HINSTANCE hHsapiDLL;
if( (dwReturnCode = LoadHsapiDll(&hHsapiDLL, szPalmDesktopDir)) != 0 )
// load it from local dir if present by any chance
if( (dwReturnCode = LoadHsapiDll(&hHsapiDLL, ".")) != 0 )
return(dwReturnCode);
// Shutdown the HotSync Process if it is running
@ -420,6 +415,8 @@ int InstallConduit()
return IDS_ERR_HOTSYNC_IN_PROGRESS;
ShutdownHotSync(hHsapiDLL);
// store the flag in temp global so that in the recursive call it is restarted
gWasHotSyncRunning = TRUE;
}
// Actually install the conduit as an Application Conduit
@ -446,7 +443,7 @@ int InstallConduit()
}
// Re-start HotSync if it was running before
if( bHotSyncRunning )
if( gWasHotSyncRunning )
StartHotSync(hHsapiDLL);
return(dwReturnCode);
@ -458,9 +455,19 @@ int UninstallConduit()
int dwReturnCode;
BOOL bHotSyncRunning = FALSE;
// Get the Palm Desktop Installation directory
TCHAR szPalmDesktopDir[_MAX_PATH];
unsigned long size=_MAX_PATH;
// Load the Conduit Manager DLL.
HINSTANCE hConduitManagerDLL;
if( (dwReturnCode = LoadConduitManagerDll(&hConduitManagerDLL)) != 0 )
if( (dwReturnCode=GetPalmDesktopInstallDirectory(szPalmDesktopDir, &size)) == 0 ) {
if( (dwReturnCode = LoadConduitManagerDll(&hConduitManagerDLL, szPalmDesktopDir)) != 0 )
// load it from local dir if present by any chance
if( (dwReturnCode = LoadConduitManagerDll(&hConduitManagerDLL, ".")) != 0 )
return(dwReturnCode);
}
else // if registery key not load it from local dir if present by any chance
if( (dwReturnCode = LoadConduitManagerDll(&hConduitManagerDLL, ".")) != 0 )
return(dwReturnCode);
// Prepare to uninstall the conduit using Conduit Manager functions
@ -473,15 +480,11 @@ int UninstallConduit()
if( (lpfnCmRestoreHotSyncSettings == NULL) )
return(IDS_ERR_LOADING_CONDMGR);
// Get the Palm Desktop Installation directory
TCHAR szPalmDesktopDir[_MAX_PATH];
int size=_MAX_PATH;
if( (dwReturnCode=GetPalmDesktopInstallDirectory(hConduitManagerDLL, szPalmDesktopDir, &size)) != 0 )
return dwReturnCode;
// Load the HSAPI DLL.
HINSTANCE hHsapiDLL;
if( (dwReturnCode = LoadHsapiDll(&hHsapiDLL, szPalmDesktopDir)) != 0 )
// load it from local dir if present by any chance
if( (dwReturnCode = LoadHsapiDll(&hHsapiDLL, ".")) != 0 )
return(dwReturnCode);
// Shutdown the HotSync Process if it is running
@ -496,8 +499,11 @@ int UninstallConduit()
// Actually uninstall the conduit
dwReturnCode = (*lpfnCmRemoveConduitByCreatorID)(CREATOR);
if(dwReturnCode >= 0)
if(dwReturnCode >= 0) {
// uninstall Mozilla Palm Sync Support Proxy Dll
UnregisterMozPalmSyncDll();
dwReturnCode = (*lpfnCmRestoreHotSyncSettings)(TRUE);
}
// Re-start HotSync if it was running before
if( bHotSyncRunning )

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

@ -84,6 +84,8 @@ BEGIN
IDS_SUCCESS_UNINSTALL "Mozilla Address Book Palm Sync Conduit has been successfully Uninstalled. The Palm Desktop configuration has been restored for you to enable synchronization of your Address Book on the handheld with Palm Desktop."
IDS_CONFIRM_INSTALL "Click Yes to Install the Mozilla Address Book PalmSync Conduit, which will enable address book synchronization between Mozilla Address Book and Palm handheld Address Book. Note this will replace the synchronization with Palm Desktop."
IDS_CONFIRM_UNINSTALL "Click Yes to Un-Install the Mozilla Address Book PalmSync Conduit. Note this will restore the synchronization with Palm Desktop."
IDS_ERR_REGISTERING_MOZ_DLL
"Failed to register the Mozilla's Palm Sync Support Proxy Dll while installing the Mozilla Address Book Palm Sync Conduit."
END
#endif // English (U.S.) resources

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

@ -52,5 +52,7 @@
#define IDS_CONFIRM_INSTALL 117
#define IDS_CONFIRM_UNINSTALL 118
#define IDS_SUCCESS_UNINSTALL 119
#define IDS_ERR_REGISTERING_MOZ_DLL 120
#define IDS_ERR_UNREGISTERING_MOZ_DLL 121
#define IDS_ERR_MAX 140