Back to index

lightning-sunbird  0.9+nobinonly
Defines | Enumerations | Functions | Variables
preloader.cpp File Reference
#include "resrc1.h"
#include <atlbase.h>
#include <windows.h>
#include <commctrl.h>
#include <stdio.h>

Go to the source code of this file.

Defines

#define WM_TRAY   WM_USER+0x100+5
#define _DEPTH_FIRST

Enumerations

enum  eAppVersion {
  eNetscape65, eNetscape60, eMozilla, eNetscapePre60,
  eUserPath, eUnknownVersion, eAutoDetect
}

Functions

void SetTrayIcon (const HICON hIcon)
void SetTrayToolTip (const char *aTip)
void ShowTrayApp (bool aVisible)
int CountModules (char *&aModuleList)
int Get60ModuleList (char *&aModuleList)
int Get65ModuleList (char *&aModuleList)
void GetPathFromRegistry (eAppVersion aVersion, const char *&aKey, const char *&aSubkey, char *&aModuleList, int &aSize)
bool GetMozillaRegistryInfo (eAppVersion &aVersion)
void GetNextModuleName (char *aName)
HINSTANCE LoadModuleFromPath (const char *aPath)
HINSTANCE LoadModule (const char *aName)
BOOL CALLBACK EnumWindowsProc (HWND hwnd, LPARAM lParam)
bool BrowserIsRunning ()
VOID CALLBACK KeepAliveTimerProc (HWND hwnd, UINT uMsg, UINT idEvent, DWORD dwTime)
VOID CALLBACK LoadModuleTimerProc (HWND hwnd, UINT uMsg, UINT idEvent, DWORD dwTime)
void ParseArgs (LPSTR &CmdLineArgs, eAppVersion &anAppVersion)
BOOL CALLBACK DisableDialogProc (HWND hwnd, UINT Msg, WPARAM wParam, LPARAM lParam)
BOOL CALLBACK ConfigureDialogProc (HWND hwnd, UINT Msg, WPARAM wParam, LPARAM lParam)
void RemoveFromStartupFolder ()
LRESULT CALLBACK WindowFunc (HWND hwnd, UINT Msg, WPARAM wParam, LPARAM lParam)
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszArgs, int nWinMode)

Variables

static NOTIFYICONDATA gTrayData = {0,0,0,0,0,0,0}
static HWND gMainWindow = 0
static HICON gCheckIcons [2] = {0,0}
static HICON gBrowserRunningIcon = {0}
static const int kLoadTimerID = 2
static const int kPingModuleTimerID = 3
static char gExePath [1024] = {0}
static const char * thePathSep = "\\"
static const char * gBrowserWindowName = 0
static const char * gRegKey = 0
static const char * gRegSubKey = 0
static HINSTANCE gMainInst = 0
static int gModulePercent = 100
static int gEntryPercent = 50
static int gFrequencyPercent = 50
static bool gUseFullModuleList = false
static eAppVersion gAppVersion = eNetscape65
static char gMozPath [2048] = {0}
static char gUserPath [2048] = {0}
static int gPreloadJava = 1
static char gMozModuleList [4096] = {0}
static char * gModuleCP = gMozModuleList
static int gModuleCount = 0
static int gMozPathLen = 0
static int gUserPathLen = 0
static const char * theMozPath = 0
static int gDLLIndex = 0
static char gKeyBuffer [512] = {0}
static char gSubKeyBuffer [128] = {0}
static char gWinNameBuffer [128] = {0}
const int gMaxDLLCount = 256
const int gMaxProcCount = 512
static HINSTANCE gInstances [gMaxDLLCount]
static longgFuncTable [gMaxDLLCount][gMaxProcCount]
static int gDLLCount = 0
static int gMaxEntryIndex = 0

Define Documentation

#define WM_TRAY   WM_USER+0x100+5

Definition at line 88 of file preloader.cpp.


Enumeration Type Documentation

Enumerator:
eNetscape65 
eNetscape60 
eMozilla 
eNetscapePre60 
eUserPath 
eUnknownVersion 
eAutoDetect 

Definition at line 164 of file preloader.cpp.


Function Documentation

Definition at line 604 of file preloader.cpp.

                        {
  static bool gBrowserIsRunning=false;
  
  if(!gBrowserIsRunning) {
    if(!EnumWindows(EnumWindowsProc,0)) {
      gBrowserIsRunning=true;
    }
  }

  return gBrowserIsRunning;
}

Here is the call graph for this function:

Here is the caller graph for this function:

BOOL CALLBACK ConfigureDialogProc ( HWND  hwnd,
UINT  Msg,
WPARAM  wParam,
LPARAM  lParam 
)

Definition at line 932 of file preloader.cpp.

                                                                                     {

  int x=0;

  switch(Msg) {

    case WM_INITDIALOG:
      {
        RECT cr1,cr2;

          //The rect code below is used to put our dialog right by the taskbar.
          //It makes it's presence more obvious to the user.

        HWND theTopWnd=GetDesktopWindow();
        GetClientRect(theTopWnd,&cr1);
        GetClientRect(hwnd,&cr2);
        int w=cr2.right-cr2.left;
        int h=cr2.bottom-cr2.top;


        /*---------------------------------------------------------------
          Add members to our list control...
         ---------------------------------------------------------------*/

        HWND theListCtrl=GetDlgItem(hwnd,IDC_PRELOAD);

        SendMessage(theListCtrl, CB_RESETCONTENT, 0, 0);
        SendMessage(theListCtrl, CB_ADDSTRING, 0, (LPARAM)"Auto"); 
        SendMessage(theListCtrl, CB_ADDSTRING, 0, (LPARAM)"Mozilla"); 
        SendMessage(theListCtrl, CB_ADDSTRING, 0, (LPARAM)"Netscape-6.0"); 
        SendMessage(theListCtrl, CB_ADDSTRING, 0, (LPARAM)"Netscape-6.5"); 
        SendMessage(theListCtrl, CB_ADDSTRING, 0, (LPARAM)"Pre-Netscape-6.0"); 
        SendMessage(theListCtrl, CB_ADDSTRING, 0, (LPARAM)"User-defined"); 
        
        int theSel=0;
        switch(gAppVersion) {
          case eNetscape65: theSel=3; break;
          case eNetscape60: theSel=2; break;
          case eMozilla:    theSel=1; break;
          case eNetscapePre60:  theSel=4; break;
          case eUserPath:   theSel=5; break;
          default:
            break;
        }
        
        SendMessage(theListCtrl, CB_SETCURSEL, (WPARAM)theSel, 0);

        /*---------------------------------------------------------------
          Set the text of our edit control...
         ---------------------------------------------------------------*/

        HWND theEditCtrl=GetDlgItem(hwnd,IDC_EDIT1);
        SendMessage(theEditCtrl, WM_CLEAR, 0, 0); 
        SendMessage(theEditCtrl, EM_REPLACESEL, 0, (LPARAM)gMozPath); 

        /*---------------------------------------------------------------
          Set the state of our JAVA checkbox...
         ---------------------------------------------------------------*/

        HWND theJavaCheckBox =GetDlgItem(hwnd,IDC_JAVA);
        SendMessage(theJavaCheckBox, BM_SETCHECK, gPreloadJava, 0); 

        /*---------------------------------------------------------------
          add code here to set the range of our sliders...
         ---------------------------------------------------------------*/

        HWND theSlider=GetDlgItem(hwnd,IDC_MODULES);
        gModulePercent = SendMessage(theSlider, TBM_SETPOS, (BOOL)TRUE, (LONG)gModulePercent); 

        theSlider=GetDlgItem(hwnd,IDC_ENTRIES);
        gEntryPercent = SendMessage(theSlider, TBM_SETPOS, (BOOL)TRUE, (LONG)gEntryPercent); 

        theSlider=GetDlgItem(hwnd,IDC_FREQUENCY);
        gFrequencyPercent = SendMessage(theSlider, TBM_SETPOS, (BOOL)TRUE, (LONG)gFrequencyPercent); 
        
        SetWindowPos(hwnd,HWND_TOP,cr1.right-(w+50),cr1.bottom-(h+70),0,0,SWP_NOSIZE);
        return TRUE;
      }

    case WM_COMMAND:
      switch(LOWORD(wParam)) {

        case IDOK:

          {
            HWND theSlider=GetDlgItem(hwnd,IDC_MODULES);
            gModulePercent = SendMessage(theSlider, TBM_GETPOS, 0, 0); 

            theSlider=GetDlgItem(hwnd,IDC_ENTRIES);
            gEntryPercent = SendMessage(theSlider, TBM_GETPOS, 0, 0); 

            theSlider=GetDlgItem(hwnd,IDC_FREQUENCY);
            gFrequencyPercent = SendMessage(theSlider, TBM_GETPOS, 0, 0); 

            theSlider=GetDlgItem(hwnd,IDC_JAVA);
            gPreloadJava = (int)SendMessage(theSlider, BM_GETCHECK, 0, 0); 

            EndDialog(hwnd,1);

            //and now, let's save the configuration settings...

            CRegKey theRegKey;

            LONG theOpenResult=theRegKey.Open(HKEY_LOCAL_MACHINE,gRegKey,KEY_QUERY_VALUE);
            if(ERROR_SUCCESS!=theOpenResult) {
              theRegKey.Create(HKEY_LOCAL_MACHINE,gRegKey);
            }

            char theSettings[128];
            sprintf(theSettings,"%i %i %i %i %s",gModulePercent,gEntryPercent,gFrequencyPercent,gPreloadJava,gUserPath);
            theRegKey.SetValue( HKEY_LOCAL_MACHINE, gRegKey, theSettings, "Settings");
          }
          
          break;

        case IDCANCEL:
          EndDialog(hwnd,0);
          return TRUE;
          break;

        default:
          break;
      }//switch
    default:
      break;
  }
  
  return FALSE;
}

Here is the caller graph for this function:

int CountModules ( char *&  aModuleList)

Definition at line 187 of file preloader.cpp.

                                    {
  char *cp=aModuleList;
  
  int count=0;

  while(*cp) {
    if(*cp) {
      count++;
    }
    char *theSemi=strchr(cp,';');
    if(theSemi) {
      cp=theSemi+1; //skip the semi
    }
  }
  return count;
}

Here is the call graph for this function:

Here is the caller graph for this function:

BOOL CALLBACK DisableDialogProc ( HWND  hwnd,
UINT  Msg,
WPARAM  wParam,
LPARAM  lParam 
)

Definition at line 888 of file preloader.cpp.

                                                                                   {

  switch(Msg) {

    case WM_INITDIALOG:
      {
        RECT cr1,cr2;

          //The rect code below is used to put our dialog right by the taskbar.
          //It makes it's presence more obvious to the user.

        HWND theTopWnd=GetDesktopWindow();
        GetClientRect(theTopWnd,&cr1);
        GetClientRect(hwnd,&cr2);
        int w=cr2.right-cr2.left;
        int h=cr2.bottom-cr2.top;

        SetWindowPos(hwnd,HWND_TOP,cr1.right-(w+50),cr1.bottom-(h+70),0,0,SWP_NOSIZE);
        return TRUE;
      }
  
    case WM_COMMAND:
      switch(LOWORD(wParam)) {
        case IDOK:
          EndDialog(hwnd,1);
          break;
        case IDCANCEL:
          EndDialog(hwnd,0);
          return TRUE;
          break;
        default:
          break;
      }//switch
    default:
      break;
  }
  
  return FALSE;
}

Here is the caller graph for this function:

BOOL CALLBACK EnumWindowsProc ( HWND  hwnd,
LPARAM  lParam 
)

Definition at line 588 of file preloader.cpp.

                                                        {

  char buf[256]={0};
  if(GetWindowText(hwnd,buf,sizeof(buf))){
    if(strstr(buf,gBrowserWindowName)) {
      return FALSE; //stop iterating now...
    }
  }
  return TRUE;
}
int Get60ModuleList ( char *&  aModuleList)

Definition at line 209 of file preloader.cpp.

                                       {
  
  static char* theModuleList = 

    "nspr4;plds4;plc4;mozreg;xpcom;img3250;zlib;" \

    "gkgfxwin;gkwidget;" \

    "components\\gkparser;" \
    "jpeg3250;" \
    "js3250;" \
    "jsj3250;" \
    "jsdom;" \
    "components\\jsloader;" \

    "components\\activation;" \
    "components\\appcomps;" \
    "components\\addrbook;" \
    "components\\appshell;" \
    "components\\caps;" \
    "components\\chardet;" \
    "components\\chrome;" \
    "components\\cookie;" \
    "components\\docshell;" \
    "components\\editor;" \
    "components\\gkhtml;" \
    "components\\gkplugin;" \
    "components\\gkview;" \
    "gkwidget;" \
    "components\\jar50;" \
    "components\\lwbrk;" \
    "mozreg;" \
    "components\\necko;" \
    "components\\nsgif;" \
    "components\\nslocale;" \
    "components\\nsprefm;" \
    "components\\profile;" \
    "components\\psmglue;" \
    "components\\rdf;" \
    "components\\shistory;" \
    "components\\strres;" \
    "components\\txmgr;" \
    "components\\txtsvc;" \
    "components\\ucharuti;" \
    "components\\uconv;" \
    "components\\ucvlatin;" \
    "components\\ucvcn;" \
    "components\\ucvja;" \
    "components\\urildr;" \
    "components\\wallet;" \
    "components\\xpc3250;" \
    "components\\xpinstal;" \
    "components\\xppref32;" \
    "components\\mozbrwsr;" \
    "components\\nsjpg;" \
    "components\\oji;" \

    "msgbsutl;" \
    "components\\mork;" \
    "components\\msglocal;" \

    "xprt;" \
    "xptl;" \
    "xpcs;";

  strcpy(aModuleList,theModuleList);
  return CountModules(theModuleList);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int Get65ModuleList ( char *&  aModuleList)

Definition at line 282 of file preloader.cpp.

                                        {
  static char* theModuleList = 

  "nspr4;plds4;plc4;mozreg;xpcom;img3250;zlib;" \

  "gkgfxwin;gkwidget;" \

  "components\\gkparser;" \
  "jpeg3250;" \
  "js3250;" \
  "jsj3250;" \
  "jsdom;" \
  "components\\jsloader;" \

  "components\\activation;" \
  "components\\addrbook;" \
  "components\\appcomps;" \
  "components\\appshell;" \
  "components\\embedcomponents;"
  "components\\caps;" \
  "components\\chardet;" \
  "components\\chrome;" \
  "components\\cookie;" \
  "components\\docshell;" \
  "components\\editor;" \
  "components\\gkplugin;" \
  "components\\gkview;" \
  "gkwidget;" \
  "gfx2;" \
  "components\\jar50;" \
  "components\\lwbrk;" \
  "components\\necko;" \
  "components\\nsgif;" \
  "components\\nslocale;" \
  "components\\nsprefm;" \
  "components\\profile;" \
  "components\\psmglue;" \
  "components\\rdf;" \
  "components\\shistory;" \
  "components\\strres;" \
  "components\\txmgr;" \
  "components\\txtsvc;" \
  "components\\ucharuti;" \
  "components\\uconv;" \
  "components\\ucvlatin;" \
  "components\\ucvcn;" \
  "components\\ucvja;" \
  "components\\urildr;" \
  "components\\wallet;" \
  "components\\xpc3250;" \
  "components\\xpinstal;" \
  "components\\xppref32;" \
  "components\\xmlextras;" \

  "components\\gklayout;" \
  "components\\gkcontent;" \
  "components\\mozbrwsr;" \
  "components\\nsjpg;" \
  "components\\oji;" \

  "msgbsutl;" \
  "components\\mork;" \
  "components\\msglocal;" \

  "xprt;" \
  "xptl;" \
  "xpcs;";

  strcpy(aModuleList,theModuleList);
  return CountModules(theModuleList);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 433 of file preloader.cpp.

                                                   {

  //first we try to get the registry info based on the command line settings.
  //if that fails, we try others.

  bool found=false;
  LONG theOpenResult = 1; //any non-zero will do to initialize this...

  if ( aVersion == eUserPath) {
    found=true;
  }  

  while((ERROR_SUCCESS!=theOpenResult) && (aVersion<eUnknownVersion)) {
     
    GetPathFromRegistry(aVersion,gRegKey,gRegSubKey,gModuleCP,gModuleCount);

    CRegKey theRegKey;

    if((eUserPath!=aVersion) && (gRegKey)) {
      theOpenResult=theRegKey.Open(HKEY_LOCAL_MACHINE,gRegKey,KEY_QUERY_VALUE);

      if(ERROR_SUCCESS==theOpenResult) {
        DWORD theSize=1024;

        theRegKey.QueryValue(gMozPath,gRegSubKey,&theSize);

        if((ERROR_SUCCESS==theOpenResult) && (aVersion!=eUserPath)) {

          theSize=1024;
          char theCachedModuleList[1024] = {0};

          theRegKey.QueryValue(theCachedModuleList,"Modules",&theSize);

          if(theCachedModuleList[0]) {
            strcpy(gMozModuleList,theCachedModuleList);
          }
          else {
            theRegKey.Create(HKEY_LOCAL_MACHINE,gRegKey);
            theRegKey.SetValue( HKEY_LOCAL_MACHINE, gRegKey, gMozModuleList, "Modules");
          }
        }

        found=true;
        break;
      }
    }
    aVersion=eAppVersion(int(aVersion)+1);
    
  } //while

  gMozPathLen=strlen(gMozPath);
  gModuleCP = gMozModuleList;

  return found;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void GetNextModuleName ( char *  aName)

Definition at line 494 of file preloader.cpp.

                                    {
  //scan ahead to find the next ';' or the end of the string...
  bool done=false;
  char theChar=0;

  aName[0]=0;

  char *theCP=gModuleCP;

  while(*theCP) {
    theChar=*theCP;
    if(';'==theChar)
      break;
    else theCP++;
  }

  if(theCP!=gModuleCP) {
    size_t theSize=theCP-gModuleCP;
    strncpy(aName,gModuleCP,theSize);
    aName[theSize]=0;
    gModuleCP=theCP;
    while(';'==*gModuleCP)
      gModuleCP++;
  }

}

Here is the call graph for this function:

Here is the caller graph for this function:

void GetPathFromRegistry ( eAppVersion  aVersion,
const char *&  aKey,
const char *&  aSubkey,
char *&  aModuleList,
int aSize 
)

Definition at line 362 of file preloader.cpp.

                                                                                                                        {
  
  switch(aVersion) { 
  
    case eMozilla:

      aKey=(LoadString(gMainInst,IDS_MOZ_KEY,gKeyBuffer,sizeof(gKeyBuffer))) ? gKeyBuffer : "Software\\Mozilla.org\\Mozilla\\0.8 (en)\\Main"; 

      aSubkey = (LoadString(gMainInst,IDS_SUBKEY_INSTALL,gSubKeyBuffer,sizeof(gSubKeyBuffer))) ? gSubKeyBuffer : "Install Directory";

      gBrowserWindowName = (LoadString(gMainInst,IDS_MOZ_WINDOWNAME,gWinNameBuffer,sizeof(gWinNameBuffer))) ? gWinNameBuffer: "- Mozilla";

      aSize=Get65ModuleList(aModuleList);

      break;
    
    case eNetscape65:

      aKey=(LoadString(gMainInst,IDS_NS65_KEY,gKeyBuffer,sizeof(gKeyBuffer))) ? gKeyBuffer : "Software\\Netscape\\Netscape 6\\6.5 (en)\\Main"; 

      aSubkey = (LoadString(gMainInst,IDS_SUBKEY_INSTALL,gSubKeyBuffer,sizeof(gSubKeyBuffer))) ? gSubKeyBuffer : "Install Directory";

      gBrowserWindowName = (LoadString(gMainInst,IDS_NS_WINDOWNAME,gWinNameBuffer,sizeof(gWinNameBuffer))) ? gWinNameBuffer: "- Netstacpe 6";

      aSize=Get65ModuleList(aModuleList);

      break;
    
    case eNetscape60:

      aKey=(LoadString(gMainInst,IDS_NS60_KEY,gKeyBuffer,sizeof(gKeyBuffer))) ? gKeyBuffer : "Software\\Netscape\\Netscape 6\\6.0 (en)\\Main"; 

      aSubkey = (LoadString(gMainInst,IDS_SUBKEY_PATH,gSubKeyBuffer,sizeof(gSubKeyBuffer))) ? gSubKeyBuffer : "Path";

      gBrowserWindowName = (LoadString(gMainInst,IDS_NS_WINDOWNAME,gWinNameBuffer,sizeof(gWinNameBuffer))) ? gWinNameBuffer: "- Netstacpe 6";

      aSize=Get60ModuleList(aModuleList);

      break;

    case eNetscapePre60:

      aKey=(LoadString(gMainInst,IDS_PRE60_KEY,gKeyBuffer,sizeof(gKeyBuffer))) ? gKeyBuffer : "Software\\Microsoft\\Windows\\CurrentVersion\\App Paths\\netscp6.exe"; 

      aSubkey = (LoadString(gMainInst,IDS_SUBKEY_PATH,gSubKeyBuffer,sizeof(gSubKeyBuffer))) ? gSubKeyBuffer : "Path";

      gBrowserWindowName = (LoadString(gMainInst,IDS_NS_WINDOWNAME,gWinNameBuffer,sizeof(gWinNameBuffer))) ? gWinNameBuffer: "- Netstacpe 6";

      aSize=Get60ModuleList(aModuleList);

      break;

    case eUserPath:
      aKey  = 0;
      aSubkey= 0;
      strcpy(gMozPath,gUserPath);

      aSize=Get65ModuleList(aModuleList);

      gBrowserWindowName = (LoadString(gMainInst,IDS_MOZ_WINDOWNAME,gWinNameBuffer,sizeof(gWinNameBuffer))) ? gWinNameBuffer: "- Mozilla";

      break;

    case eUnknownVersion:
      break;
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

VOID CALLBACK KeepAliveTimerProc ( HWND  hwnd,
UINT  uMsg,
UINT  idEvent,
DWORD  dwTime 
)

Definition at line 624 of file preloader.cpp.

                                                                                     {

  //let's go see if mozilla is running.
  //if so, then bail out without pinging modules...
  
  if(BrowserIsRunning()) {
    return;
  }

  static bool theTimerIsRunning=false;
  static int  theCurrentModule=0;
  static int  theCurrentProc=0;

  if(!theTimerIsRunning) { //ignore other timer calls till we're done.
    theTimerIsRunning=true;

      //constrain the step to 1..gDLLCount
    static const double kPercent=gFrequencyPercent/100.0;
    static const int kMaxSteps=1+int(3*gDLLCount*kPercent);

    int count=0;

    //this version iterates the entry points in each module before moving to the next module

    while(count<kMaxSteps) {

      volatile long *p=(long*)gFuncTable[theCurrentModule][theCurrentProc];
      count++;
      if (p) {
        if (*p && p){  
        //don't actually invoke it, just cause it to load into memory...
        //note that modules have different number of entry points.
        //so not all modules have an entry point at theCurrentProc index.
          int x=10;
        }
      }

#define _DEPTH_FIRST
#ifdef _DEPTH_FIRST
      
      if(theCurrentModule >= gDLLCount) {
        theCurrentModule = 0;
        theCurrentProc = (theCurrentProc>=gMaxEntryIndex) ? 0 : theCurrentProc+1;
      }
      else {
        theCurrentModule++;
      }

#else //breadth first...

      if(theCurrentProc >= gMaxEntryIndex) {
        theCurrentProc=0;
        theCurrentModule = (theCurrentModule>=gDLLCount) ? 0 : theCurrentModule+1;
      }
      else {
        theCurrentProc++;
      }

#endif

    }

    theTimerIsRunning=false;
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

HINSTANCE LoadModule ( const char *  aName)

Definition at line 573 of file preloader.cpp.

                                        {

  //we operate on gMozPath directly to avoid an unnecessary string copy.
  //when we're done with this method, we reset gMozpath to it's original value for reuse.

  strcat(gMozPath,aName);
  strcat(gMozPath,".dll");

  HINSTANCE theInstance = LoadModuleFromPath(gMozPath);

  gMozPath[gMozPathLen]=0;
  return theInstance;
}

Here is the call graph for this function:

Here is the caller graph for this function:

HINSTANCE LoadModuleFromPath ( const char *  aPath)

Definition at line 539 of file preloader.cpp.

                                                {
 
  HINSTANCE theInstance=gInstances[gDLLCount++]=LoadLibrary(aPath);

    //we'll constrain the steprate to the range 1..20.
  static double kPercent=(100-gEntryPercent)/100.0;
  static const int kEntryStepRate=1+int(20*kPercent);
  int theEntryCount=0;

  if(theInstance) {
    //let's get addresses throughout the module, skipping by the rate of kEntryStepRate.
    for(int theEntryPoint=0;theEntryPoint<gMaxProcCount;theEntryPoint++){
      long *entry=(long*)::GetProcAddress(theInstance,MAKEINTRESOURCE(1+(kEntryStepRate*theEntryPoint)));
      if(entry) {
        gFuncTable[gDLLCount-1][theEntryCount++]=entry;
      }
      else {
        break;
      }
    }
    if(theEntryCount>gMaxEntryIndex)
      gMaxEntryIndex=theEntryCount; //we track the highest index we find.
  }

  return theInstance;
}

Here is the caller graph for this function:

VOID CALLBACK LoadModuleTimerProc ( HWND  hwnd,
UINT  uMsg,
UINT  idEvent,
DWORD  dwTime 
)

Definition at line 699 of file preloader.cpp.

                                                                                   {

  static bool theTimerIsRunning=false;
  static int  gTrayIconIndex = 0;

  if(!theTimerIsRunning) {
    theTimerIsRunning=true;

      //gDLLCount is the number of modules loaded so far
      //gModuleCount is the total number of modules we know about
      //gModulePercent is the total % of modules we're being asked to load (config setting)

    double theMaxPercentToLoad=gModulePercent/100.0;

      //we'll only load more modules if haven't loaded the max percentage of modules
      //based on the configuration UI (stored in gModulePercent).

    const int theModulePerCallCount = 3; // specifies how many modules to load per timer callback.
    bool  done=false;

    for(int theModuleIndex=0;theModuleIndex<theModulePerCallCount;theModuleIndex++) {

      SetTrayIcon(gCheckIcons[gTrayIconIndex]);

      gTrayIconIndex = (gTrayIconIndex==1) ? 0 : gTrayIconIndex+1; //this toggles the preloader icon to show activity...

      char theDLLName[512];
      GetNextModuleName(theDLLName);

      if(theDLLName[0]) {
        if(gDLLCount/(gModuleCount*1.0)<=theMaxPercentToLoad) {
          HINSTANCE theInstance=LoadModule(theDLLName);
        }
        else done=true;
      }
      else done=true;

      if(done) {

          //if they've asked us to preload java, then do so here...
        if(gPreloadJava) {

          char kJavaRegStr[512] = {0};
          if(LoadString(gMainInst,IDS_JAVAREGSTR,kJavaRegStr,sizeof(kJavaRegStr))){

            CRegKey theRegKey;

            LONG theOpenResult=theRegKey.Open(HKEY_LOCAL_MACHINE,kJavaRegStr,KEY_QUERY_VALUE);
            if(ERROR_SUCCESS==theOpenResult) {

              char kJavaRegPath[128] = {0};
              if(LoadString(gMainInst,IDS_JAVAREGPATH,kJavaRegPath,sizeof(kJavaRegPath))){

                char thePath[1024] = {0};
                DWORD theSize=sizeof(thePath);
                theRegKey.QueryValue(thePath,kJavaRegPath,&theSize);

                if(thePath) {
                  //here we go; let's load java and awt...
                  char theTempPath[1024]={0};

                  sprintf(theTempPath,"%s\\hotspot\\jvm.dll",thePath);
                  LoadModuleFromPath(theTempPath);

                  sprintf(theTempPath,"%s\\verify.dll",thePath);
                  LoadModuleFromPath(theTempPath);

                  sprintf(theTempPath,"%s\\jpins32.dll",thePath);
                  LoadModuleFromPath(theTempPath);

                  sprintf(theTempPath,"%s\\jpishare.dll",thePath);
                  LoadModuleFromPath(theTempPath);

                  sprintf(theTempPath,"%s\\NPOJI600.dll",thePath);
                  LoadModuleFromPath(theTempPath);

                  sprintf(theTempPath,"%s\\java.dll",thePath);
                  LoadModuleFromPath(theTempPath);

                  sprintf(theTempPath,"%s\\awt.dll",thePath);
                  LoadModuleFromPath(theTempPath);

                }
              }
            }
          }

        }

        KillTimer(gMainWindow,kLoadTimerID);     
        SetTrayIcon(gCheckIcons[1]);
    
        //now make a new timer that calls GetProcAddr()...
        //we take gFrequencyPercent into account. We assume a timer range (min..max) of ~1second.

        int theFreq=50+(100-gFrequencyPercent)*10;

        UINT result=SetTimer(gMainWindow,kPingModuleTimerID,theFreq,KeepAliveTimerProc);
        return; //bail out    
      }
    }

    theTimerIsRunning=false;
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void ParseArgs ( LPSTR CmdLineArgs,
eAppVersion anAppVersion 
)

Definition at line 812 of file preloader.cpp.

                                                             {

  const char* cp=CmdLineArgs;
  
  while(*cp) {
    char theChar=*cp;
    if(('-'==theChar) || ('/'==theChar)){
      //we found a valid command, go get it...
      ++cp;
      char theCmd=*cp;

      switch(theCmd) {
        case 'n':
        case 'N':
          anAppVersion=eNetscape65;
          break;

        case 'm':
        case 'M':
          anAppVersion=eMozilla;
          break;

        case 'f':
        case 'F':
          ++cp;          
          if('+'==*cp) {
            gUseFullModuleList=true;
          }
          break;

        case 'p':
        case 'P':
          cp++; //skip over the command, then get the install path the user wants us to use.
          anAppVersion=eUserPath;
          while(*cp) {              //skip whitespace...
            if(' '!=*cp)
              break;
            cp++;
          }
            //now eat the path
          gMozPathLen=gUserPathLen=0;
          if('"'==*cp) { // Allow spaces in the path ie "C:\Program Files"
            cp++; // skip the "
            while(*cp) {
              if('"'!=*cp) {
                gUserPath[gUserPathLen++]=*cp;
              }
              cp++;
            }
          }
          else {
            while(*cp) {
              if(' '!=*cp) {
                gUserPath[gUserPathLen++]=*cp;
              }
              cp++;
            }
          }
          if(gUserPath[gUserPathLen-1]!= '\\') // make sure there's a \ on the end. 
            gUserPath[gUserPathLen++] = '\\';
          gUserPath[gUserPathLen]=0;
          continue;
          break;
        default:
          break;
      }
    }
    cp++; 
  }

}

Here is the caller graph for this function:

Definition at line 1075 of file preloader.cpp.

                               {
  
  //Using the name of our running application, let's derive the
  //name of the link to it in the startup folder.

  char theAppName[128]={0};
  char theFilename[128]={0};
  char theFullPath[1024]={0};

  const char *theLastSep=strrchr(gExePath,thePathSep[0]);

  if(theLastSep) {
    theLastSep++; //skip the slash

    char prefix[512]={0};
    
    if(LoadString(gMainInst,IDS_STARTUP_FOLDER_PREFIX,prefix,sizeof(prefix))){
      
      char suffix[512]={0};
    
      if(LoadString(gMainInst,IDS_STARTUP_FOLDER_SUFFIX,suffix,sizeof(suffix))){
        strcpy(theFilename,prefix);
        strcat(theFilename,theLastSep);
        strcat(theFilename,suffix);
      }
    
    }
  }

  if(theFilename) { //dont try if you can't get a reasonable guess to the path in the startup folder.
  
    //-----------------------------------------------------------------------------
    //first, let's try to remove ourselves from the current users's startup folder...
    //-----------------------------------------------------------------------------

    char theUserKey[256]={0};
    if(LoadString(gMainInst,IDS_STARTUP_FOLDER_KEY,theUserKey,sizeof(theUserKey))) {

      CRegKey theRegKey;

      LONG theOpenResult=theRegKey.Open(HKEY_CURRENT_USER,theUserKey,KEY_QUERY_VALUE);

      if(ERROR_SUCCESS==theOpenResult) {
    
        DWORD theSize=sizeof(theFullPath);

        char theSubKey[128]={0};
        
        if(LoadString(gMainInst,IDS_STARTUP_FOLDER_SUBKEY1,theSubKey,sizeof(theSubKey))) {
         
          theRegKey.QueryValue(theFullPath,theSubKey,&theSize);
          if(theFullPath) {

            //Now let's construct a complete path to our preloader.exe.lnk.

            strcat(theFullPath,thePathSep);
            strcat(theFullPath,theFilename);

            //Ask the OS to remove us from the startup folder...

            DeleteFile(theFullPath);
          }
        }
      }
    }

    //-----------------------------------------------------------------------------
    //Next, let's try to remove ourselves from ALL_USERS startup folder...
    //-----------------------------------------------------------------------------

    CRegKey theRegKey2;

    LONG theOpenResult=theRegKey2.Open(HKEY_LOCAL_MACHINE,theUserKey,KEY_QUERY_VALUE);

    if(ERROR_SUCCESS==theOpenResult) {
  
      DWORD theSize=sizeof(theFullPath);

      char theSubKey[128]={0};
      
      if(LoadString(gMainInst,IDS_STARTUP_FOLDER_SUBKEY2,theSubKey,sizeof(theSubKey))) {
       
        theRegKey2.QueryValue(theFullPath,theSubKey,&theSize);
        if(theFullPath) {

          //Now let's construct a complete path to our preloader.exe.lnk.

          strcat(theFullPath,thePathSep);
          strcat(theFullPath,theFilename);

          //Ask the OS to remove us from the startup folder...

          DeleteFile(theFullPath);
        }
      }
    }

  }
}

Here is the caller graph for this function:

void SetTrayIcon ( const HICON  hIcon)

Definition at line 112 of file preloader.cpp.

                                   {
  gTrayData.hIcon=hIcon;
  Shell_NotifyIcon(NIM_MODIFY, &gTrayData);
}

Here is the caller graph for this function:

void SetTrayToolTip ( const char *  aTip)

Definition at line 120 of file preloader.cpp.

                                     {
  if(aTip) {
    if(!gTrayData.szTip[0])  //if previously no tooltip
      gTrayData.uFlags=gTrayData.uFlags | NIF_TIP;
    strcpy(gTrayData.szTip, aTip);
  }
  else gTrayData.uFlags=NIF_ICON | NIF_MESSAGE;
  Shell_NotifyIcon(NIM_MODIFY, &gTrayData);
}

Here is the caller graph for this function:

void ShowTrayApp ( bool  aVisible)

Definition at line 133 of file preloader.cpp.

                                {

  if(aVisible) {
    gTrayData.cbSize=sizeof(NOTIFYICONDATA);
    gTrayData.hWnd=gMainWindow;
    gTrayData.uID=IDI_CHECK;  //our tray ID
    gTrayData.uFlags= NIF_ICON | NIF_MESSAGE | NIF_TIP;
    gTrayData.uCallbackMessage=WM_TRAY; //send a WM_TRAY message when users clicks in our tray window
    gTrayData.hIcon=gCheckIcons[0]; //init our default icon
  
    Shell_NotifyIcon(NIM_ADD, &gTrayData); //now show our tray icon

    char theTip[256];
    if(LoadString(gMainInst,IDS_TOOLTIP,theTip,sizeof(theTip))){
      SetTrayToolTip(theTip);  
    }
    else SetTrayToolTip("Click to configure moz-preloader");
    SetTrayIcon(gCheckIcons[0]);
  }
  else {
    Shell_NotifyIcon(NIM_DELETE, &gTrayData);
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

LRESULT CALLBACK WindowFunc ( HWND  hwnd,
UINT  Msg,
WPARAM  wParam,
LPARAM  lParam 
)

Definition at line 1179 of file preloader.cpp.

                                                                               {

  static HMENU hPopup=0;           //menu handle
  static int   gState=0;
  static bool  gConfigDialogShowing=false;

  switch(Msg) {

    case WM_CREATE: 
      //initialize icons

      gCheckIcons[0]=LoadIcon(gMainInst, MAKEINTRESOURCE(IDI_CHECK));
      gCheckIcons[1]=LoadIcon(gMainInst, MAKEINTRESOURCE(IDI_CHECK1));
      gBrowserRunningIcon = LoadIcon(gMainInst, MAKEINTRESOURCE(IDI_BROWSERRUNNING));

      //initialize popup menu
      hPopup=LoadMenu(gMainInst, MAKEINTRESOURCE(IDR_MENU1));

      gMainWindow=hwnd;
      ShowTrayApp(true); //now display our app in the system tray

      break;

    //notification from trayicon received
    case WM_TRAY:

      //if right mouse button pressed
      if(lParam == WM_RBUTTONDOWN && (!gConfigDialogShowing)) {
        POINT pt;
        GetCursorPos(&pt);  //get cursor position
        SetForegroundWindow(hwnd);  //set window to foreground
        //display popup menu
        BOOL bRes=TrackPopupMenu(GetSubMenu(hPopup, 0), TPM_BOTTOMALIGN | TPM_RIGHTALIGN | TPM_RIGHTBUTTON,
                                 pt.x, pt.y, 0, hwnd, 0);
        //send dummy message to window
        SendMessage(hwnd, WM_NULL, 0, 0);
      }
      break;

    //notification from menu received
    case WM_COMMAND:

      switch(LOWORD(wParam)) {

        case IDM_CONFIGURE:
          {
            if(!gConfigDialogShowing) {
              gConfigDialogShowing=true;
              if(DialogBox(gMainInst,MAKEINTRESOURCE(IDD_PERFORMANCE),hwnd,ConfigureDialogProc)) {
              }
              gConfigDialogShowing=false;
            }
          }
          break;

        case IDM_REMOVE:
          //show them the disable preloader dialog. If they say yes, remove ourselves from
          //the start menu (if that's where we were launched from) and quit.
          //now fall through on purpose...
          if(DialogBox(gMainInst,MAKEINTRESOURCE(DISABLE),hwnd,DisableDialogProc)) {
            //a non-zero result means we are supposed to kill the preloader 
            //and remove it from the startup folder.

            RemoveFromStartupFolder();
            //now fall thru...

          }
          else break;
                
        case IDM_EXIT:
          DestroyWindow(hwnd);
          break;

        //change icon in system tray; why bother?
        case IDM_CHANGE:
          if(!gState) {
            gState=1;
          } 
          else {
            gState=0;
          }
          break;
      }
      break;

    //exit application
    case WM_DESTROY:
      //release used resources

      ShowTrayApp(false);

      DestroyIcon(gCheckIcons[0]);
      DestroyIcon(gCheckIcons[1]);

      DestroyMenu(hPopup);
      PostQuitMessage(0);
      break;

    default:
      return DefWindowProc(hwnd, Msg, wParam, lParam);
  }
  return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int WINAPI WinMain ( HINSTANCE  hInstance,
HINSTANCE  hPrevInstance,
LPSTR  lpszArgs,
int  nWinMode 
)

Definition at line 1287 of file preloader.cpp.

                                                                                           {

  memset(gFuncTable,0,sizeof(gFuncTable)); //init this to empty ptr's for good housekeeping...
   
  ::CreateMutex(NULL, FALSE, "YourMutexName");
  if (GetLastError()  == ERROR_ALREADY_EXISTS ) {
    //Bail out if we already have one instance running.
    exit(0);
  }

  WNDCLASS WinClass;

  static char theClassName[128];
  if(!LoadString(hInstance,IDS_CLASSNAME,theClassName,sizeof(theClassName)))
    strcpy(theClassName,"MozPreloader"); //as a backup; just being paranoid.

  //register window class
  WinClass.hInstance=hInstance;

  //---------------------------------------------------------------
  //  We hang on to the app name in case they disable us.
  //  We'll remove a .lnk entry of this name from the startup folder.
  //---------------------------------------------------------------

  GetModuleFileName(hInstance,gExePath,sizeof(gExePath)); //remember where we were run from in case we get disabled. 


  //---------------------------------------------------------------
  //  Now let's init and register our window class...
  //---------------------------------------------------------------

  gMainInst=hInstance;
  WinClass.lpszClassName=theClassName;  //specify class name
  WinClass.lpfnWndProc=WindowFunc;    //specify callback function
  WinClass.style=0;
  WinClass.hIcon=LoadIcon(NULL, IDI_APPLICATION); //specify icon
  WinClass.hCursor=LoadCursor(NULL, IDC_ARROW);   //specify cursor
  WinClass.lpszMenuName=0;
  WinClass.cbClsExtra=0;
  WinClass.cbWndExtra=0;
  WinClass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH); //specify window background

  if(!RegisterClass(&WinClass))
    return 0;

  //create window
  HWND hwnd=CreateWindow(theClassName,0,WS_OVERLAPPEDWINDOW,10,10,10,10,HWND_DESKTOP,NULL,hInstance,NULL);
  gMainWindow=hwnd;

  //hide window
  ShowWindow(hwnd, SW_HIDE);

  //---------------------------------------------------------------
  //  Now let's grab the module settings info...
  //---------------------------------------------------------------

  bool useDebugModuleList=false;
  
  ParseArgs(lpszArgs,gAppVersion);

  if(GetMozillaRegistryInfo(gAppVersion)) {

    SetTrayIcon(gBrowserRunningIcon); //by default.

    //---------------------------------------------------------------
    //  Now let's grab the config settings (if they happen to exist)
    //---------------------------------------------------------------

    CRegKey theRegKey;

    LONG theOpenResult=theRegKey.Open(HKEY_LOCAL_MACHINE,gRegKey,KEY_QUERY_VALUE);
    if(ERROR_SUCCESS==theOpenResult) {

      const int theSize=1024;
      DWORD size=theSize;
      char theSettings[theSize] = {0};

      theOpenResult=theRegKey.QueryValue(theSettings,"Settings",&size);
      if(ERROR_SUCCESS==theOpenResult) {
        //now let's decode the settings from the string
        char *cp=theSettings;
        
        gModulePercent = atoi(cp);
        cp=strchr(cp,' '); //skip ahead to the next space...
        cp++; //and step over it

        gEntryPercent = atoi(cp);

        cp=strchr(cp,' '); //skip ahead to the next space...
        if(cp) {
          cp++; //and step over it
          gFrequencyPercent = atoi(cp);
        }

        cp=strchr(cp,' '); //skip ahead to the next space...
        if(cp) {
          cp++; //and step over it
          gPreloadJava = atoi(cp);
        }


        if(!gUserPath[0]) { //dont override something they provide at the 
          if(cp){
            cp=strchr(cp,'['); //seek to the separator for the pathname (optional)
            if(cp && *cp) {
              char *endcp=strchr(cp,']'); //now grab the (optional) user defined path...
              if(endcp) {
                strcpy(gUserPath,cp);
              }
            }
          }
        }
      }
    }

    //---------------------------------------------------------------
    //  And start the timer...
    //---------------------------------------------------------------

    if(!BrowserIsRunning()) {
      SetTimer(hwnd,kLoadTimerID,50,LoadModuleTimerProc); //don't bother with the preloader if the browser is already up...
    }

  }

  //start message pump
  MSG WinMsg;
  while(GetMessage(&WinMsg, NULL, 0, 0)) {
    TranslateMessage(&WinMsg);
    DispatchMessage(&WinMsg);
  }

  return WinMsg.wParam;
}

Here is the call graph for this function:


Variable Documentation

Definition at line 166 of file preloader.cpp.

HICON gBrowserRunningIcon = {0} [static]

Definition at line 93 of file preloader.cpp.

const char* gBrowserWindowName = 0 [static]

Definition at line 100 of file preloader.cpp.

HICON gCheckIcons[2] = {0,0} [static]

Definition at line 92 of file preloader.cpp.

int gDLLCount = 0 [static]

Definition at line 530 of file preloader.cpp.

int gDLLIndex = 0 [static]

Definition at line 180 of file preloader.cpp.

int gEntryPercent = 50 [static]

Definition at line 106 of file preloader.cpp.

char gExePath[1024] = {0} [static]

Definition at line 98 of file preloader.cpp.

int gFrequencyPercent = 50 [static]

Definition at line 107 of file preloader.cpp.

Definition at line 529 of file preloader.cpp.

Definition at line 528 of file preloader.cpp.

char gKeyBuffer[512] = {0} [static]

Definition at line 358 of file preloader.cpp.

HINSTANCE gMainInst = 0 [static]

Definition at line 104 of file preloader.cpp.

HWND gMainWindow = 0 [static]

Definition at line 91 of file preloader.cpp.

Definition at line 526 of file preloader.cpp.

int gMaxEntryIndex = 0 [static]

Definition at line 531 of file preloader.cpp.

Definition at line 527 of file preloader.cpp.

int gModuleCount = 0 [static]

Definition at line 175 of file preloader.cpp.

char* gModuleCP = gMozModuleList [static]

Definition at line 174 of file preloader.cpp.

int gModulePercent = 100 [static]

Definition at line 105 of file preloader.cpp.

char gMozModuleList[4096] = {0} [static]

Definition at line 173 of file preloader.cpp.

char gMozPath[2048] = {0} [static]

Definition at line 169 of file preloader.cpp.

int gMozPathLen = 0 [static]

Definition at line 176 of file preloader.cpp.

int gPreloadJava = 1 [static]

Definition at line 171 of file preloader.cpp.

const char* gRegKey = 0 [static]

Definition at line 101 of file preloader.cpp.

const char* gRegSubKey = 0 [static]

Definition at line 102 of file preloader.cpp.

char gSubKeyBuffer[128] = {0} [static]

Definition at line 359 of file preloader.cpp.

NOTIFYICONDATA gTrayData = {0,0,0,0,0,0,0} [static]

Definition at line 90 of file preloader.cpp.

Definition at line 160 of file preloader.cpp.

char gUserPath[2048] = {0} [static]

Definition at line 170 of file preloader.cpp.

int gUserPathLen = 0 [static]

Definition at line 177 of file preloader.cpp.

char gWinNameBuffer[128] = {0} [static]

Definition at line 360 of file preloader.cpp.

const int kLoadTimerID = 2 [static]

Definition at line 95 of file preloader.cpp.

Definition at line 96 of file preloader.cpp.

const char* theMozPath = 0 [static]

Definition at line 179 of file preloader.cpp.

const char* thePathSep = "\\" [static]

Definition at line 99 of file preloader.cpp.