Back to index

lightning-sunbird  0.9+nobinonly
Defines | Typedefs | Functions | Variables
PalmSyncInstall.cpp File Reference
#include <windows.h>
#include <io.h>
#include <stdlib.h>
#include <stdio.h>
#include <tchar.h>
#include <Winreg.h>
#include "CondMgr.h"
#include "HSAPI.h"
#include "resource.h"

Go to the source code of this file.

Defines

#define MOZ_PALMSYNC_PROXY   ".\\PalmSyncProxy.dll"
#define CREATOR   "addr"
#define CONDUIT_FILENAME   "mozABConduit.dll"
#define REMOTE_DB   "AddressDB"
#define CONDUIT_NAME   "address"
#define CONDUIT_PRIORITY   2
#define CONDMGR_FILENAME   "CondMgr.dll"
#define HSAPI_FILENAME   "HsApi.dll"
#define DIRECTORY_SEPARATOR   '\\'
#define DIRECTORY_SEPARATOR_STR   "\\"
#define EXECUTABLE_EXTENSION   ".exe"
#define HOTSYNC_MAX_WAIT   30
#define MAX_LOADSTRING   256

Typedefs

typedef int(WINAPI * CmGetCorePathPtr )(TCHAR *pPath, int *piSize)
typedef int(WINAPI * CmGetHotSyncExecPathPtr )(char *szPath, int *iSize)
typedef int(WINAPI * CmInstallCreatorPtr )(const char *pCreator, int iType)
typedef int(WINAPI * CmRemoveConduitByCreatorIDPtr )(const char *pCreator)
typedef int(WINAPI * CmRestoreHotSyncSettingsPtr )(BOOL bToDefaults)
typedef int(WINAPI * CmSetCreatorRemotePtr )(const char *pCreator, const TCHAR *pRemote)
typedef int(WINAPI * CmSetCreatorNamePtr )(const char *pCreator, const TCHAR *pConduitName)
typedef int(WINAPI * CmSetCreatorTitlePtr )(const char *pCreator, const TCHAR *pConduitTitle)
typedef int(WINAPI * CmSetCreatorFilePtr )(const char *pCreator, const TCHAR *pConduitFile)
typedef int(WINAPI * CmSetCreatorDirectoryPtr )(const char *pCreator, const TCHAR *pConduitDirectory)
typedef int(WINAPI * CmSetCreatorPriorityPtr )(const char *pCreator, DWORD dwPriority)
typedef int(WINAPI * CmSetCreatorIntegratePtr )(const char *pCreator, DWORD dwIntegrate)
typedef int(WINAPI * CmSetCreatorValueDwordPtr )(const char *pCreator, TCHAR *pValue, DWORD dwValue)
typedef int(WINAPI * CmSetCreatorValueStringPtr )(const char *pCreator, TCHAR *pValueName, TCHAR *value)
typedef const TCHARpModule
typedef int(WINAPI * CmGetCreatorNamePtr )(const char *pCreator, TCHAR *pConduitName, int *pSize)
typedef int(WINAPI * CmGetCreatorTitlePtr )(const char *pCreator, TCHAR *pConduitTitle, int *pSize)
typedef int(WINAPI * CmGetCreatorPriorityPtr )(const char *pCreator, DWORD *dwPriority)
typedef int(WINAPI * CmGetCreatorTypePtr )(const char *pCreator)
typedef int(WINAPI * CmGetCreatorIntegratePtr )(const char *pCreator, DWORD *dwIntegrate)
typedef int(WINAPI * CmGetCreatorValueDwordPtr )(const char *pCreator, TCHAR *pValueName, DWORD dwValue, DWORD dwDefault)
typedef int(WINAPI * CmGetCreatorValueStringPtr )(const char *pCreator, TCHAR *pValueName, TCHAR *pValue, int *pSize, TCHAR *pDefault)
typedef TCHARpFile
typedef TCHAR intpiSize
typedef int(WINAPI * CmGetCreatorRemotePtr )(const char *pCreator, const TCHAR *pRemote, int *pSize)
typedef int(WINAPI * HsCheckApiStatusPtr )(void)
typedef int(WINAPI * HsGetSyncStatusPtr )(DWORD *dwStatus)
typedef int(WINAPI * HsSetAppStatusPtr )(HsStatusType statusType, DWORD dwStartFlags)
typedef int(WINAPI * mozDllRegisterServerPtr )(void)
typedef int(WINAPI * mozDllUnregisterServerPtr )(void)

Functions

typedef int (WINAPI *CmSetCorePathPtr)(const char *pPath)
int InstallConduit (HINSTANCE hInstance, TCHAR *installPath)
int UninstallConduit ()
void ConstructMessage (HINSTANCE hInstance, DWORD dwMessageId, TCHAR *formattedMsg)
int APIENTRY WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
int GetPalmDesktopInstallDirectory (TCHAR *pPDInstallDirectory, unsigned long *pSize)
int LoadConduitManagerDll (HINSTANCE *hCondMgrDll, const TCHAR *szPalmDesktopDirectory)
int LoadHsapiDll (HINSTANCE *hHsapiDLL, const TCHAR *szPalmDesktopDirectory)
BOOL IsHotSyncRunning (HINSTANCE hHsapiDLL)
BOOL IsHotSyncInProgress (HINSTANCE hHsapiDLL)
void ShutdownHotSync (HINSTANCE hHsapiDLL)
void StartHotSync (HINSTANCE hHsapiDLL)
int RegisterMozPalmSyncDll ()
int UnregisterMozPalmSyncDll ()
char * mystrsep (char **stringp, char delim)

Variables

BOOL gWasHotSyncRunning = FALSE
char oldSettingsStr [500]
static char gSavedCwd [_MAX_PATH]

Define Documentation

#define CONDMGR_FILENAME   "CondMgr.dll"

Definition at line 58 of file PalmSyncInstall.cpp.

#define CONDUIT_FILENAME   "mozABConduit.dll"

Definition at line 53 of file PalmSyncInstall.cpp.

#define CONDUIT_NAME   "address"

Definition at line 55 of file PalmSyncInstall.cpp.

Definition at line 56 of file PalmSyncInstall.cpp.

#define CREATOR   "addr"

Definition at line 52 of file PalmSyncInstall.cpp.

Definition at line 60 of file PalmSyncInstall.cpp.

Definition at line 61 of file PalmSyncInstall.cpp.

Definition at line 62 of file PalmSyncInstall.cpp.

Definition at line 63 of file PalmSyncInstall.cpp.

#define HSAPI_FILENAME   "HsApi.dll"

Definition at line 59 of file PalmSyncInstall.cpp.

Definition at line 65 of file PalmSyncInstall.cpp.

#define MOZ_PALMSYNC_PROXY   ".\\PalmSyncProxy.dll"

Definition at line 51 of file PalmSyncInstall.cpp.

#define REMOTE_DB   "AddressDB"

Definition at line 54 of file PalmSyncInstall.cpp.


Typedef Documentation

typedef int(WINAPI * CmGetCorePathPtr)(TCHAR *pPath, int *piSize)

Definition at line 68 of file PalmSyncInstall.cpp.

typedef int(WINAPI * CmGetCreatorIntegratePtr)(const char *pCreator, DWORD *dwIntegrate)

Definition at line 92 of file PalmSyncInstall.cpp.

typedef int(WINAPI * CmGetCreatorNamePtr)(const char *pCreator, TCHAR *pConduitName, int *pSize)

Definition at line 88 of file PalmSyncInstall.cpp.

typedef int(WINAPI * CmGetCreatorPriorityPtr)(const char *pCreator, DWORD *dwPriority)

Definition at line 90 of file PalmSyncInstall.cpp.

typedef int(WINAPI * CmGetCreatorRemotePtr)(const char *pCreator, const TCHAR *pRemote, int *pSize)

Definition at line 98 of file PalmSyncInstall.cpp.

typedef int(WINAPI * CmGetCreatorTitlePtr)(const char *pCreator, TCHAR *pConduitTitle, int *pSize)

Definition at line 89 of file PalmSyncInstall.cpp.

typedef int(WINAPI * CmGetCreatorTypePtr)(const char *pCreator)

Definition at line 91 of file PalmSyncInstall.cpp.

typedef int(WINAPI * CmGetCreatorValueDwordPtr)(const char *pCreator, TCHAR *pValueName, DWORD dwValue, DWORD dwDefault)

Definition at line 93 of file PalmSyncInstall.cpp.

typedef int(WINAPI * CmGetCreatorValueStringPtr)(const char *pCreator, TCHAR *pValueName, TCHAR *pValue, int *pSize, TCHAR *pDefault)

Definition at line 94 of file PalmSyncInstall.cpp.

typedef int(WINAPI * CmGetHotSyncExecPathPtr)(char *szPath, int *iSize)

Definition at line 69 of file PalmSyncInstall.cpp.

typedef int(WINAPI * CmInstallCreatorPtr)(const char *pCreator, int iType)

Definition at line 71 of file PalmSyncInstall.cpp.

typedef int(WINAPI * CmRemoveConduitByCreatorIDPtr)(const char *pCreator)

Definition at line 72 of file PalmSyncInstall.cpp.

typedef int(WINAPI * CmRestoreHotSyncSettingsPtr)(BOOL bToDefaults)

Definition at line 73 of file PalmSyncInstall.cpp.

typedef int(WINAPI * CmSetCreatorDirectoryPtr)(const char *pCreator, const TCHAR *pConduitDirectory)

Definition at line 78 of file PalmSyncInstall.cpp.

typedef int(WINAPI * CmSetCreatorFilePtr)(const char *pCreator, const TCHAR *pConduitFile)

Definition at line 77 of file PalmSyncInstall.cpp.

typedef int(WINAPI * CmSetCreatorIntegratePtr)(const char *pCreator, DWORD dwIntegrate)

Definition at line 81 of file PalmSyncInstall.cpp.

typedef int(WINAPI * CmSetCreatorNamePtr)(const char *pCreator, const TCHAR *pConduitName)

Definition at line 75 of file PalmSyncInstall.cpp.

typedef int(WINAPI * CmSetCreatorPriorityPtr)(const char *pCreator, DWORD dwPriority)

Definition at line 80 of file PalmSyncInstall.cpp.

typedef int(WINAPI * CmSetCreatorRemotePtr)(const char *pCreator, const TCHAR *pRemote)

Definition at line 74 of file PalmSyncInstall.cpp.

typedef int(WINAPI * CmSetCreatorTitlePtr)(const char *pCreator, const TCHAR *pConduitTitle)

Definition at line 76 of file PalmSyncInstall.cpp.

typedef int(WINAPI * CmSetCreatorValueDwordPtr)(const char *pCreator, TCHAR *pValue, DWORD dwValue)

Definition at line 82 of file PalmSyncInstall.cpp.

typedef int(WINAPI * CmSetCreatorValueStringPtr)(const char *pCreator, TCHAR *pValueName, TCHAR *value)

Definition at line 83 of file PalmSyncInstall.cpp.

typedef int(WINAPI * HsCheckApiStatusPtr)(void)

Definition at line 101 of file PalmSyncInstall.cpp.

typedef int(WINAPI * HsGetSyncStatusPtr)(DWORD *dwStatus)

Definition at line 102 of file PalmSyncInstall.cpp.

typedef int(WINAPI * HsSetAppStatusPtr)(HsStatusType statusType, DWORD dwStartFlags)

Definition at line 103 of file PalmSyncInstall.cpp.

typedef int(WINAPI * mozDllRegisterServerPtr)(void)

Definition at line 106 of file PalmSyncInstall.cpp.

typedef int(WINAPI * mozDllUnregisterServerPtr)(void)

Definition at line 107 of file PalmSyncInstall.cpp.

typedef TCHAR * pFile

Definition at line 95 of file PalmSyncInstall.cpp.

typedef TCHAR int * piSize

Definition at line 95 of file PalmSyncInstall.cpp.

typedef TCHAR * pModule

Definition at line 86 of file PalmSyncInstall.cpp.


Function Documentation

void ConstructMessage ( HINSTANCE  hInstance,
DWORD  dwMessageId,
TCHAR formattedMsg 
)

Definition at line 117 of file PalmSyncInstall.cpp.

{
  // Load brand name and the format string.
  TCHAR brandName[MAX_LOADSTRING];
  TCHAR formatString[MAX_LOADSTRING];
  LoadString(hInstance, IDS_BRAND_NAME, brandName, MAX_LOADSTRING-1);
  LoadString(hInstance, dwMessageId, formatString, MAX_LOADSTRING-1);

  // A few msgs needs two brand name substitutions.
  if ((dwMessageId == IDS_SUCCESS_INSTALL) ||
      (dwMessageId == IDS_CONFIRM_INSTALL) ||
      (dwMessageId == IDS_ERR_REGISTERING_MOZ_DLL))
    _sntprintf(formattedMsg, MAX_LOADSTRING-1, formatString, brandName, brandName);
  else
    _sntprintf(formattedMsg, MAX_LOADSTRING-1, formatString, brandName);

  formattedMsg[MAX_LOADSTRING-1]='\0';
}

Here is the caller graph for this function:

int GetPalmDesktopInstallDirectory ( TCHAR pPDInstallDirectory,
unsigned long pSize 
)

Definition at line 195 of file PalmSyncInstall.cpp.

{
    HKEY   key;
    // open the key
    LONG rc = ::RegOpenKey(HKEY_CURRENT_USER, "Software\\U.S. Robotics\\Pilot Desktop\\Core", &key);
    if (rc == ERROR_SUCCESS) {
        // get key value
        rc = ::RegQueryValueEx(key, "Path", NULL, NULL, 
                               (LPBYTE)pPDInstallDirectory, pSize);
        if (rc == ERROR_SUCCESS) {
            *pSize = _tcslen(pPDInstallDirectory); // windows only
            rc=0; // 0 is success for us
        }
        // close the key
        ::RegCloseKey(key);
    }

    if(rc) {
        HKEY   key2;
        // open the key
        rc = ::RegOpenKey(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows\\CurrentVersion\\App Paths\\palm.exe", &key2);
        if (rc == ERROR_SUCCESS) {
            // get the default key value
            rc = ::RegQueryValueEx(key2, "", NULL, NULL, 
                                   (LPBYTE)pPDInstallDirectory, pSize);
            // get only the path (ie, strip out the exe name). note that we don't use string match
            // for the exe name here since it's possilbe that the exe name in the default setting
            // is different from the exe name in RegOpenKey() call. For example, the exe name in
            // the default setting for "Software\\...\\App Paths\\pbrush.exe" is mspaint.exe.
            if (rc == ERROR_SUCCESS) {
              TCHAR *end = pPDInstallDirectory + _tcslen(pPDInstallDirectory);
              while ((*end != '\\') && (end != pPDInstallDirectory))
                end--;
              *end = '\0';
              rc=0; // 0 is success for us
            }
            // close the key
            ::RegCloseKey(key2);
        }
    }
    
    return rc;
}

Here is the caller graph for this function:

int InstallConduit ( HINSTANCE  hInstance,
TCHAR installPath 
)

Definition at line 429 of file PalmSyncInstall.cpp.

{ 
    int dwReturnCode;
    BOOL    bHotSyncRunning = FALSE;

    // Prepare the full path of the conduit.
    // Applications should not place conduits in the Palm Desktop directory.
    // The Palm Desktop installer only manages the Palm Desktop conduits.

    TCHAR szConduitPath[_MAX_PATH];
    if (!installDir)
    {
      if(!GetModuleFileName(NULL, szConduitPath, _MAX_PATH))
          return IDS_ERR_CONDUIT_NOT_FOUND;
      // extract the dir path (without the module name)
      int index = strlen(szConduitPath)-1;
      while((szConduitPath[index] != DIRECTORY_SEPARATOR) && index)
          index--;
      szConduitPath[index] = 0;
    }
    else
      strncpy(szConduitPath, installDir, sizeof(szConduitPath) - 1);


    // take care of any possible string overwrites
    if((strlen(szConduitPath) + strlen(DIRECTORY_SEPARATOR_STR) + strlen(CONDUIT_FILENAME)) > _MAX_PATH)
        return IDS_ERR_LOADING_CONDMGR;
    // might already have conduit filename in szConduitPath if we're called recursively
    if (!strstr(szConduitPath, CONDUIT_FILENAME)) 
    {
      if (szConduitPath[strlen(szConduitPath) - 1] != DIRECTORY_SEPARATOR)
        strcat(szConduitPath, DIRECTORY_SEPARATOR_STR);
      strcat(szConduitPath, CONDUIT_FILENAME);
    }
    // Make sure the conduit dll exists
    struct _finddata_t dll_file;
    long hFile;
    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 desktopSize=_MAX_PATH;
    
    // old conduit settings - MAX_PATH is arbitrarily long...
    TCHAR szOldCreatorName[_MAX_PATH];
    TCHAR szOldRemote[_MAX_PATH];
    TCHAR szOldCreatorTitle[_MAX_PATH];
    TCHAR szOldCreatorFile[_MAX_PATH];
    TCHAR szOldCreatorDirectory[_MAX_PATH];
    DWORD oldPriority;
    DWORD oldIntegrate;
    int   oldType;

    // Load the Conduit Manager DLL.
    HINSTANCE hConduitManagerDLL;
    if( (dwReturnCode = GetPalmDesktopInstallDirectory(szPalmDesktopDir, &desktopSize)) == 0 ) 
    {
        // need to switch current working directory to directory with palm dlls
        // because of a bug in Palm Desktop 6.01

        GetCurrentDirectory(sizeof(gSavedCwd), gSavedCwd);
        SetCurrentDirectory(szPalmDesktopDir);

        if( (dwReturnCode = LoadConduitManagerDll(&hConduitManagerDLL, szPalmDesktopDir)) != 0 )
            return dwReturnCode;
    }
    else 
        return IDS_ERR_CONDUIT_NOT_FOUND;
    
    // Prepare to install the conduit using Conduit Manager functions
    CmInstallCreatorPtr lpfnCmInstallCreator;
    lpfnCmInstallCreator = (CmInstallCreatorPtr) GetProcAddress(hConduitManagerDLL, "CmInstallCreator");
    CmSetCreatorRemotePtr   lpfnCmSetCreatorRemote;
    lpfnCmSetCreatorRemote = (CmSetCreatorRemotePtr) GetProcAddress(hConduitManagerDLL, "CmSetCreatorRemote");
    CmSetCreatorNamePtr lpfnCmSetCreatorName;
    lpfnCmSetCreatorName = (CmSetCreatorNamePtr) GetProcAddress(hConduitManagerDLL, "CmSetCreatorName");
    CmSetCreatorTitlePtr lpfnCmSetCreatorTitle;
    lpfnCmSetCreatorTitle = (CmSetCreatorTitlePtr) GetProcAddress(hConduitManagerDLL, "CmSetCreatorTitle");
    CmSetCreatorPriorityPtr lpfnCmSetCreatorPriority;
    lpfnCmSetCreatorPriority = (CmSetCreatorPriorityPtr) GetProcAddress(hConduitManagerDLL, "CmSetCreatorPriority");
    CmSetCreatorIntegratePtr    lpfnCmSetCreatorIntegrate;
    lpfnCmSetCreatorIntegrate = (CmSetCreatorIntegratePtr) GetProcAddress(hConduitManagerDLL, "CmSetCreatorIntegrate");
    CmRemoveConduitByCreatorIDPtr   lpfnCmRemoveConduitByCreatorID;
    lpfnCmRemoveConduitByCreatorID = (CmRemoveConduitByCreatorIDPtr) GetProcAddress(hConduitManagerDLL, "CmRemoveConduitByCreatorID");
    CmSetCreatorValueStringPtr lpfnCmSetCreatorValueString = (CmSetCreatorValueStringPtr) GetProcAddress(hConduitManagerDLL, "CmSetCreatorValueString");

    CmGetCreatorRemotePtr   lpfnCmGetCreatorRemote;
    lpfnCmGetCreatorRemote = (CmGetCreatorRemotePtr) GetProcAddress(hConduitManagerDLL, "CmGetCreatorRemote");
    CmGetCreatorNamePtr lpfnCmGetCreatorName;
    lpfnCmGetCreatorName = (CmGetCreatorNamePtr) GetProcAddress(hConduitManagerDLL, "CmGetCreatorName");
    CmGetCreatorTitlePtr lpfnCmGetCreatorTitle;
    lpfnCmGetCreatorTitle = (CmGetCreatorTitlePtr) GetProcAddress(hConduitManagerDLL, "CmGetCreatorTitle");
    CmGetCreatorPriorityPtr lpfnCmGetCreatorPriority;
    lpfnCmGetCreatorPriority = (CmGetCreatorPriorityPtr) GetProcAddress(hConduitManagerDLL, "CmGetCreatorPriority");
    CmGetCreatorIntegratePtr    lpfnCmGetCreatorIntegrate;
    lpfnCmGetCreatorIntegrate = (CmGetCreatorIntegratePtr) GetProcAddress(hConduitManagerDLL, "CmGetCreatorIntegrate");
    CmGetCreatorTypePtr lpfnCmGetCreatorType = (CmGetCreatorTypePtr) GetProcAddress(hConduitManagerDLL, "CmGetCreatorType");
    CmGetCreatorFilePtr lpfnCmGetCreatorFile = (CmGetCreatorFilePtr) GetProcAddress(hConduitManagerDLL, "CmGetCreatorFile");
    CmGetCreatorDirectoryPtr lpfnCmGetCreatorDirectory = (CmGetCreatorDirectoryPtr) GetProcAddress(hConduitManagerDLL, "CmGetCreatorDirectory");
    if( (lpfnCmInstallCreator == NULL) 
        || (lpfnCmSetCreatorRemote == NULL)
        || (lpfnCmSetCreatorName == NULL)
        || (lpfnCmSetCreatorTitle == NULL)
        || (lpfnCmSetCreatorPriority == NULL)
        || (lpfnCmSetCreatorIntegrate == NULL)
        )
    {
        // Return error code.
        return(IDS_ERR_LOADING_CONDMGR);
    }
 
    szOldCreatorTitle[0] = '\0';
    szOldCreatorName[0] = '\0';
    szOldRemote[0] = '\0';
    szOldCreatorTitle[0] = '\0';
    szOldCreatorFile[0] = '\0';
    szOldCreatorDirectory[0] = '\0';
    // get settings for old conduit
    int remoteBufSize = sizeof(szOldRemote);
    (*lpfnCmGetCreatorRemote) (CREATOR, szOldRemote, &remoteBufSize);
    int creatorBufSize = sizeof(szOldCreatorName);
    (*lpfnCmGetCreatorName)(CREATOR, szOldCreatorName, &creatorBufSize);
    int creatorTitleBufSize = sizeof(szOldCreatorTitle);
    (*lpfnCmGetCreatorTitle)(CREATOR, szOldCreatorTitle, &creatorTitleBufSize);
    int creatorFileBufSize = sizeof(szOldCreatorFile);
    int creatorDirectoryBufSize = sizeof(szOldCreatorDirectory);
    (*lpfnCmGetCreatorFile)(CREATOR, szOldCreatorFile, &creatorFileBufSize);
    (*lpfnCmGetCreatorDirectory)(CREATOR, szOldCreatorDirectory, &creatorDirectoryBufSize);
    (*lpfnCmGetCreatorPriority)(CREATOR, &oldPriority);
    (*lpfnCmGetCreatorIntegrate)(CREATOR, &oldIntegrate);
    oldType = (*lpfnCmGetCreatorType) (CREATOR);

    // if not set by previous pass through here
    if (!oldSettingsStr[0])
      _snprintf(oldSettingsStr, sizeof(oldSettingsStr), "%s,%s,%s,%s,%s,%d,%d,%d", szOldRemote, szOldCreatorName, 
        szOldCreatorTitle, szOldCreatorFile, szOldCreatorDirectory, oldType, oldPriority, oldIntegrate);

    // Load the HSAPI DLL.
    HINSTANCE hHsapiDLL;
    if( (dwReturnCode = LoadHsapiDll(&hHsapiDLL, szPalmDesktopDir)) != 0 )
        return dwReturnCode;
        
    // Shutdown the HotSync Process if it is running
    if( (bHotSyncRunning=IsHotSyncRunning(hHsapiDLL)) )
    {
        // Check for any synchronizations in progress
        if( IsHotSyncInProgress(hHsapiDLL) )
            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
    dwReturnCode = (*lpfnCmInstallCreator)(CREATOR, CONDUIT_APPLICATION);
    if(dwReturnCode == ERR_CREATORID_ALREADY_IN_USE) {
        dwReturnCode = (*lpfnCmRemoveConduitByCreatorID)(CREATOR);
        if(dwReturnCode >= 0 ) {
            //free the library so that the existing AB Conduit is unloaded properly
            FreeLibrary(hConduitManagerDLL);
            FreeLibrary(hHsapiDLL);
            return InstallConduit(hInstance, szConduitPath);
        }
    }
    if( dwReturnCode == 0 )
    {
        (*lpfnCmSetCreatorValueString) (CREATOR, "oldConduitSettings", oldSettingsStr);
        dwReturnCode = (*lpfnCmSetCreatorName)(CREATOR, szConduitPath);
        if( dwReturnCode != 0 ) return dwReturnCode;
        TCHAR title[MAX_LOADSTRING];
        // Construct conduit title (the one displayed in HotSync Mgr's Custom...list)..
        ConstructMessage(hInstance, IDS_CONDUIT_TITLE, title);
        dwReturnCode = (*lpfnCmSetCreatorTitle)(CREATOR, title);
        if( dwReturnCode != 0 ) return dwReturnCode;
        dwReturnCode = (*lpfnCmSetCreatorRemote)(CREATOR, REMOTE_DB);
        if( dwReturnCode != 0 ) return dwReturnCode;
        dwReturnCode = (*lpfnCmSetCreatorPriority)(CREATOR, CONDUIT_PRIORITY);
        if( dwReturnCode != 0 ) return dwReturnCode;
        // Applications should always set Integrate to 0
        dwReturnCode = (*lpfnCmSetCreatorIntegrate)(CREATOR, (DWORD)0);
        (*lpfnCmSetCreatorValueString) (CREATOR, "oldConduitSettings", oldSettingsStr);
    }
    
    // Re-start HotSync if it was running before
    if( gWasHotSyncRunning )
        StartHotSync(hHsapiDLL);

    // restore cwd, if we changed it.        
    if (gSavedCwd[0])
      SetCurrentDirectory(gSavedCwd);

    return(dwReturnCode);
}

Here is the call graph for this function:

Here is the caller graph for this function:

typedef int ( WINAPI *  CmSetCorePathPtr) const

Definition at line 303 of file PalmSyncInstall.cpp.

{
    DWORD dwStatus;
    
    if(!hHsapiDLL)
        return FALSE;
    
    if(IsHotSyncRunning(hHsapiDLL))
    {
        // Prepare to use the HSAPI functions
        HsGetSyncStatusPtr  lpfnHsGetSyncStatus;
        lpfnHsGetSyncStatus = (HsGetSyncStatusPtr) GetProcAddress(hHsapiDLL, "HsGetSyncStatus");
    
        if( lpfnHsGetSyncStatus )
        {
            if( (*lpfnHsGetSyncStatus)(&dwStatus) == 0 )
                if( dwStatus == HOTSYNC_STATUS_IDLE )
                    return FALSE;
        }
    }
    return TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 283 of file PalmSyncInstall.cpp.

{
    BOOL    bRetVal = FALSE;
    
    if(!hHsapiDLL)
        return bRetVal;
    
    // Prepare to use the HSAPI functions
    HsCheckApiStatusPtr lpfnHsCheckApiStatus;
    lpfnHsCheckApiStatus = (HsCheckApiStatusPtr) GetProcAddress(hHsapiDLL, "HsCheckApiStatus");
    
    if( lpfnHsCheckApiStatus )
    {
        if( (*lpfnHsCheckApiStatus)() == 0 )
            bRetVal = TRUE;
    }
    return bRetVal;
}

Here is the caller graph for this function:

int LoadConduitManagerDll ( HINSTANCE hCondMgrDll,
const TCHAR szPalmDesktopDirectory 
)

Definition at line 240 of file PalmSyncInstall.cpp.

{
    // Initialize the return value
    *hCondMgrDll=NULL;
    
    // Construct the path of the Palm Desktop Conduit Manager
    TCHAR   szPDCondMgrPath[_MAX_PATH];
    // 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 )
        // Successfully loaded CondMgr Library from Palm Desktop Directory
        return 0;

    return IDS_ERR_LOADING_CONDMGR;
}

Here is the caller graph for this function:

int LoadHsapiDll ( HINSTANCE hHsapiDLL,
const TCHAR szPalmDesktopDirectory 
)

Definition at line 262 of file PalmSyncInstall.cpp.

{
    // Initialize the return value
    *hHsapiDLL=NULL;
    
    TCHAR   szHsapiPath[_MAX_PATH];
    // 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;

    // If we get here, then there was an error loading the library
    return IDS_ERR_HSAPI_NOT_FOUND;
}

Here is the caller graph for this function:

char* mystrsep ( char **  stringp,
char  delim 
)

Definition at line 409 of file PalmSyncInstall.cpp.

{
  char *endStr = strchr(*stringp, delim);
  char *retStr;
  if (endStr)
  {
    bool foundDelim = (*endStr == delim);
    *endStr = '\0';
    retStr = *stringp;
    *stringp = endStr + !!foundDelim;
  }
  else
    return NULL;
  return retStr;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 378 of file PalmSyncInstall.cpp.

{
    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;
}

Here is the caller graph for this function:

void ShutdownHotSync ( HINSTANCE  hHsapiDLL)

Definition at line 327 of file PalmSyncInstall.cpp.

{
    if(!hHsapiDLL)
        return;

    BOOL    bHotSyncRunning=IsHotSyncRunning(hHsapiDLL);
    
    if(bHotSyncRunning)
    {
        // Prepare to use the HSAPI functions
        HsSetAppStatusPtr   lpfnHsSetAppStatus;
        lpfnHsSetAppStatus = (HsSetAppStatusPtr) GetProcAddress(hHsapiDLL, "HsSetAppStatus");
    
        if( lpfnHsSetAppStatus )
            (*lpfnHsSetAppStatus)(HsCloseApp, HSFLAG_NONE);
        
        // Wait for HotSync to stop
        for( int i=0; (i<HOTSYNC_MAX_WAIT*2) && bHotSyncRunning; i++ )
        {
            if( (bHotSyncRunning=IsHotSyncRunning(hHsapiDLL)) == TRUE )
                Sleep(500);
        }
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void StartHotSync ( HINSTANCE  hHsapiDLL)

Definition at line 353 of file PalmSyncInstall.cpp.

{
    if(!hHsapiDLL)
        return;

    BOOL    bHotSyncRunning=IsHotSyncRunning(hHsapiDLL);
    
    if(!bHotSyncRunning)
    {
        // Prepare to use the HSAPI functions
        HsSetAppStatusPtr   lpfnHsSetAppStatus;
        lpfnHsSetAppStatus = (HsSetAppStatusPtr) GetProcAddress(hHsapiDLL, "HsSetAppStatus");
    
        if( lpfnHsSetAppStatus )
            (*lpfnHsSetAppStatus)(HsStartApp, HSFLAG_NONE);
        
        // Wait for HotSync to start
        for( int i=0; (i<HOTSYNC_MAX_WAIT*2) && !bHotSyncRunning; i++ )
        {
            if( (bHotSyncRunning=IsHotSyncRunning(hHsapiDLL)) == FALSE )
                Sleep(500);
        }
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 630 of file PalmSyncInstall.cpp.

{ 
    int dwReturnCode;
    BOOL    bHotSyncRunning = FALSE;

    // Get the Palm Desktop Installation directory
    TCHAR   szPalmDesktopDir[_MAX_PATH];
    unsigned long desktopSize=_MAX_PATH;
    // Load the Conduit Manager DLL.
    HINSTANCE hConduitManagerDLL;
    if( (dwReturnCode=GetPalmDesktopInstallDirectory(szPalmDesktopDir, &desktopSize)) == 0 )
    {
        if( (dwReturnCode = LoadConduitManagerDll(&hConduitManagerDLL, szPalmDesktopDir)) != 0 )
                return(dwReturnCode);
    }
    // if registery key not load it from local dir if present by any chance
    else 
        return(dwReturnCode);
    
    // need to switch current working directory to directory with palm dlls
    // because of a bug in Palm Desktop 6.01

    GetCurrentDirectory(sizeof(gSavedCwd), gSavedCwd);
    SetCurrentDirectory(szPalmDesktopDir);

    // Prepare to uninstall the conduit using Conduit Manager functions
    CmRemoveConduitByCreatorIDPtr   lpfnCmRemoveConduitByCreatorID;
    lpfnCmRemoveConduitByCreatorID = (CmRemoveConduitByCreatorIDPtr) GetProcAddress(hConduitManagerDLL, "CmRemoveConduitByCreatorID");
    if( (lpfnCmRemoveConduitByCreatorID == NULL) )
        return(IDS_ERR_LOADING_CONDMGR);
    CmSetCorePathPtr lpfnCmSetCorePath = (CmSetCorePathPtr) GetProcAddress(hConduitManagerDLL, "CmSetCorePath");
    CmSetHotSyncExePathPtr lpfnCmSetHotSyncExePath = (CmSetHotSyncExePathPtr) GetProcAddress(hConduitManagerDLL, "CmSetHotSyncExecPath");
    CmRestoreHotSyncSettingsPtr lpfnCmRestoreHotSyncSettings;
    lpfnCmRestoreHotSyncSettings = (CmRestoreHotSyncSettingsPtr) GetProcAddress(hConduitManagerDLL, "CmRestoreHotSyncSettings");
    CmGetCreatorValueStringPtr lpfnCmGetCreatorValueString = (CmGetCreatorValueStringPtr) GetProcAddress(hConduitManagerDLL, "CmGetCreatorValueString");
    CmInstallCreatorPtr lpfnCmInstallCreator;
    lpfnCmInstallCreator = (CmInstallCreatorPtr) GetProcAddress(hConduitManagerDLL, "CmInstallCreator");
    CmSetCreatorRemotePtr   lpfnCmSetCreatorRemote;
    lpfnCmSetCreatorRemote = (CmSetCreatorRemotePtr) GetProcAddress(hConduitManagerDLL, "CmSetCreatorRemote");
    CmSetCreatorNamePtr lpfnCmSetCreatorName;
    lpfnCmSetCreatorName = (CmSetCreatorNamePtr) GetProcAddress(hConduitManagerDLL, "CmSetCreatorName");
    CmSetCreatorTitlePtr lpfnCmSetCreatorTitle;
    lpfnCmSetCreatorTitle = (CmSetCreatorTitlePtr) GetProcAddress(hConduitManagerDLL, "CmSetCreatorTitle");
    CmSetCreatorPriorityPtr lpfnCmSetCreatorPriority;
    lpfnCmSetCreatorPriority = (CmSetCreatorPriorityPtr) GetProcAddress(hConduitManagerDLL, "CmSetCreatorPriority");
    CmSetCreatorIntegratePtr    lpfnCmSetCreatorIntegrate;
    lpfnCmSetCreatorIntegrate = (CmSetCreatorIntegratePtr) GetProcAddress(hConduitManagerDLL, "CmSetCreatorIntegrate");
    CmSetCreatorFilePtr lpfnCmSetCreatorFile = (CmSetCreatorFilePtr) GetProcAddress(hConduitManagerDLL, "CmSetCreatorFile");
    CmSetCreatorDirectoryPtr lpfnCmSetCreatorDirectory = (CmSetCreatorDirectoryPtr) GetProcAddress(hConduitManagerDLL, "CmSetCreatorDirectory");
    if( (lpfnCmRestoreHotSyncSettings == NULL) )
        return(IDS_ERR_LOADING_CONDMGR);
    
    // Load the HSAPI DLL.
    HINSTANCE hHsapiDLL;
    if( (dwReturnCode = LoadHsapiDll(&hHsapiDLL, szPalmDesktopDir)) != 0 )
          return(dwReturnCode);
        
    // Shutdown the HotSync Process if it is running
    if( (bHotSyncRunning=IsHotSyncRunning(hHsapiDLL)) )
    {
        // Check for any synchronizations in progress
        if( IsHotSyncInProgress(hHsapiDLL) )
            return IDS_ERR_HOTSYNC_IN_PROGRESS;
            
        ShutdownHotSync(hHsapiDLL);
    }
    
    TCHAR oldConduitSettings[500];
    int strSize = sizeof(oldConduitSettings);
    dwReturnCode = (*lpfnCmGetCreatorValueString)(CREATOR, "oldConduitSettings", oldConduitSettings, &strSize, "");

    // Actually uninstall the conduit
    dwReturnCode = (*lpfnCmRemoveConduitByCreatorID)(CREATOR);

    if(dwReturnCode >= 0) 
    {
        // uninstall Mozilla Palm Sync Support Proxy Dll
        dwReturnCode = UnregisterMozPalmSyncDll();
//        dwReturnCode = (*lpfnCmRestoreHotSyncSettings)(TRUE);
    }

    if (dwReturnCode >= 0)
    {
      char * szOldCreatorName;
      char *szOldRemote;
      char *szOldCreatorTitle;
      char *szOldCreatorFile;
      char *szOldCreatorDirectory;
      char *oldIntStr;
      DWORD oldPriority;
      DWORD oldIntegrate;
      int   oldType;

      char *strPtr = oldConduitSettings;
      szOldRemote = mystrsep(&strPtr, ',');
      szOldCreatorName = mystrsep(&strPtr, ',');
      szOldCreatorTitle = mystrsep(&strPtr, ',');
      szOldCreatorFile = mystrsep(&strPtr, ',');
      szOldCreatorDirectory = mystrsep(&strPtr, ',');
      oldIntStr = mystrsep(&strPtr, ',');
      oldType = (oldIntStr) ? atoi(oldIntStr) : 0;
      oldIntStr = mystrsep(&strPtr, ',');
      oldPriority = (oldIntStr) ? atoi(oldIntStr) : 0;
      oldIntStr = mystrsep(&strPtr, ',');
      oldIntegrate = (oldIntStr) ? atoi(oldIntStr) : 0;

      dwReturnCode = (*lpfnCmInstallCreator)(CREATOR, oldType);
      if( dwReturnCode == 0 )
      {
          dwReturnCode = (*lpfnCmSetCreatorName)(CREATOR, szOldCreatorName);
          if( dwReturnCode != 0 ) return dwReturnCode;
          // Construct conduit title (the one displayed in HotSync Mgr's Custom...list)..
          dwReturnCode = (*lpfnCmSetCreatorTitle)(CREATOR, szOldCreatorTitle);
          if( dwReturnCode != 0 ) return dwReturnCode;
          dwReturnCode = (*lpfnCmSetCreatorRemote)(CREATOR, szOldRemote);
          if( dwReturnCode != 0 ) return dwReturnCode;
          dwReturnCode = (*lpfnCmSetCreatorFile)(CREATOR, szOldCreatorFile);
          if( dwReturnCode != 0 ) return dwReturnCode;
          dwReturnCode = (*lpfnCmSetCreatorDirectory)(CREATOR, szOldCreatorDirectory);
          if( dwReturnCode != 0 ) return dwReturnCode;
          dwReturnCode = (*lpfnCmSetCreatorPriority)(CREATOR, oldPriority);
          if( dwReturnCode != 0 ) return dwReturnCode;
          // Applications should always set Integrate to 0
          dwReturnCode = (*lpfnCmSetCreatorIntegrate)(CREATOR, oldIntegrate);
      }
    }

//    if (lpfnCmSetCorePath)
//      (*lpfnCmSetCorePath)(szPalmDesktopDir);
//    if (lpfnCmSetHotSyncExePath)
//      (*lpfnCmSetHotSyncExePath)(szPalmHotSyncInstallDir);
    
    // this registry key is set by the RestoreHotSyncSettings to point incorrectly to Mozilla dir
    // this should point to the Palm directory to enable sync with Palm Desktop.
#if 0
    HKEY key;
    LONG rc = RegOpenKeyEx(HKEY_CURRENT_USER, "Software\\U.S. Robotics\\Pilot Desktop\\Core",
                                0, KEY_ALL_ACCESS, &key);
    if(rc == ERROR_SUCCESS)
        ::RegSetValueEx(key, "Path", 0, REG_SZ, (const BYTE *) szPalmDesktopDir, desktopSize);
 
    if(rc == ERROR_SUCCESS)
        ::RegSetValueEx(key, "HotSyncPath", 0, REG_SZ, (const BYTE *) szPalmHotSyncInstallDir, installSize);
#endif
    // Re-start HotSync if it was running before
    if( bHotSyncRunning )
        StartHotSync(hHsapiDLL);
        
    // restore cwd, if we changed it.        
    if (gSavedCwd[0])
      SetCurrentDirectory(gSavedCwd);

    if( dwReturnCode < 0 ) 
        return dwReturnCode;
    else 
        return(0);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 393 of file PalmSyncInstall.cpp.

{
    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;
}

Here is the caller graph for this function:

int APIENTRY WinMain ( HINSTANCE  hInstance,
HINSTANCE  hPrevInstance,
LPSTR  lpCmdLine,
int  nCmdShow 
)

Definition at line 136 of file PalmSyncInstall.cpp.

{
    TCHAR appTitle[MAX_LOADSTRING];
    TCHAR msgStr[MAX_LOADSTRING];

    int strResource=0;
    int res=-1;

    // /p can only be used with a standard install, i.e., non-silent install
    char *installDir = strstr(lpCmdLine, "/p");
    if (installDir)
      installDir += 2; // advance past "/p", e.g., "/pC:/program files/mozilla/dist/bin"

    if(!strcmpi(lpCmdLine,"/u")) // un-install
    {
        ConstructMessage(hInstance, IDS_APP_TITLE_UNINSTALL, appTitle);
        ConstructMessage(hInstance, IDS_CONFIRM_UNINSTALL, msgStr);
        if (MessageBox(NULL, msgStr, appTitle, MB_YESNO | MB_TOPMOST) == IDYES) 
        {
            res = UninstallConduit();
            if(!res)
                res = IDS_SUCCESS_UNINSTALL;
        }
        else
          return 0;
    }
    else if (!strcmpi(lpCmdLine,"/us")) // silent un-install
    {
        return UninstallConduit();
    }
    else if (!strcmpi(lpCmdLine,"/s")) // silent install
    {
        return InstallConduit(hInstance, installDir);
    }
    else // install
    {
        ConstructMessage(hInstance, IDS_APP_TITLE_INSTALL, appTitle);
        ConstructMessage(hInstance, IDS_CONFIRM_INSTALL, msgStr);
        if (MessageBox(NULL, msgStr, appTitle, MB_YESNO) == IDYES) 
        {
            res = InstallConduit(hInstance, installDir);
            if(!res)
                res = IDS_SUCCESS_INSTALL;
        }
    }

    if(res > IDS_ERR_MAX || res < IDS_ERR_GENERAL)
        res = IDS_ERR_GENERAL;

    ConstructMessage(hInstance, res, msgStr);
    MessageBox(NULL, msgStr, appTitle, MB_OK);

    return 0;
}

Here is the call graph for this function:


Variable Documentation

char gSavedCwd[_MAX_PATH] [static]

Definition at line 426 of file PalmSyncInstall.cpp.

Definition at line 115 of file PalmSyncInstall.cpp.

char oldSettingsStr[500]

Definition at line 425 of file PalmSyncInstall.cpp.