home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / winfe / mozilla.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  68.4 KB  |  2,138 lines

  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  *
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19. #include "stdafx.h"
  20.  
  21. //    Various startup/shutdown functions.
  22. void STARTUP_np(void);
  23. void SHUTDOWN_np(void);
  24. void STARTUP_cvffc(void);
  25. void SHUTDOWN_cvffc(void);
  26. #ifdef MOZ_LOC_INDEP
  27. void STARTUP_li(void);
  28. void SHUTDOWN_li(void);
  29. #endif/* MOZ_LOC_INDEP */
  30.  
  31. #include "jri.h"
  32.  
  33. #define XP_CPLUSPLUS  // temporary hack - jsw
  34. //#include "secnav.h"
  35.  
  36. // XP Includes
  37. #include "prefapi.h"
  38. #include "NSReg.h"
  39.  
  40. #ifdef XP_WIN32
  41. #include "postal.h"    // mapi DLL interface
  42. #endif
  43. #include "prefinfo.h"
  44.  
  45. #ifdef XP_WIN16
  46. #include "ctl3d.h"
  47. #endif
  48.  
  49. // Be careful adding more headers here since doing so can force the 
  50. // Win16 compiler to "run out of keys", whatever that means
  51.  
  52. #include "libevent.h"
  53.  
  54. // Template/Frame/View/Doc Includes
  55.  
  56. #ifdef MOZ_MAIL_NEWS
  57. #include "wfemsg.h"
  58. #include "addrfrm.h"
  59. #endif /* MOZ_MAIL_NEWS */
  60. #include "hiddenfr.h"
  61. #include "template.h"
  62. #include "logindg.h"
  63. #include "widgetry.h"
  64.  
  65. extern "C"      {
  66.     int NET_ReadCookies(char * filename);
  67.     void NET_RemoveAllCookies();
  68. };
  69.  
  70. // Used to simplify Gold/Non-gold template handling
  71. BOOL bIsGold = FALSE;
  72.  
  73. #include "mainfrm.h"
  74. #include "navfram.h"
  75. // Misc Includes
  76.  
  77. #include "custom.h"
  78. #include "ngdwtrst.h"
  79. #include "oleregis.h"
  80. #include "sysinfo.h"
  81. #include "winproto.h"
  82. #include "cmdparse.h"
  83. #include "ddecmd.h"
  84. #include "slavewnd.h"
  85. #include "feutil.h"
  86. #include "cxicon.h"
  87. // Full Circle stuff - see http://www.fullsoft.com for more info
  88. #include "fullsoft.h"
  89.  
  90. #ifdef JAVA
  91.     // don't include java.h here because the Win16 compiler won't be able to handle this file
  92.     void WFE_LJ_StartupJava(void);
  93.     void WFE_LJ_StartDebugger(void);
  94. #endif
  95.  
  96. #ifdef _DEBUG
  97. #undef THIS_FILE
  98. static char BASED_CODE THIS_FILE[] = __FILE__;
  99. #endif
  100.  
  101. #ifndef VER_PLATFORM_WIN32_WINDOWS
  102. #define VER_PLATFORM_WIN32_WINDOWS      1
  103. #endif
  104.  
  105. #ifdef __BORLANDC__
  106.     #define _mkdir mkdir
  107. #endif
  108.  
  109. extern "C"      {
  110. NET_StreamClass *memory_stream(int iFormatOut, void *pDataObj, URL_Struct *pUrlData, MWContext *pContext);
  111. NET_StreamClass *external_viewer_disk_stream(int iFormatOut, void *pDataObj, URL_Struct *pUrlData, MWContext *pContext);
  112. NET_StreamClass *ContextSaveStream(int iFormatOut, void *pDataObj, URL_Struct *pUrlData, MWContext *pContext);
  113. NET_StreamClass *nfe_OleStream(int iFormatOut, void *pDataObj, URL_Struct *pUrlData, MWContext *pContext);
  114. NET_StreamClass *EmbedStream(int iFormatOut, void *pDataObj, URL_Struct *pUrlData, MWContext *pContext);
  115. NET_StreamClass *IL_ViewStream(int iFormatOut, void *pDataObj, URL_Struct *pUrlData, MWContext *pContext);
  116. };
  117.  
  118. extern "C" int il_debug;
  119. extern CMapStringToOb DNSCacheMap;
  120. extern "C" const char* FE_GetFolderDirectory(MWContext *pContext);
  121. // Temporary hack for MUP -- jonm
  122. extern "C" {
  123.     HINSTANCE hAppInst;
  124. }
  125.  
  126. extern CDocTemplate *WFE_InitializeTemplates();
  127. #ifdef EDITOR
  128. extern void WFE_InitComposer();
  129. extern void WFE_ExitComposer();
  130. #endif // EDITOR
  131. // CLM:
  132. //   Global message to find previous instance of program by ourselves
  133. //    or from other applications.
  134. //   The function OnNetscapeGoldMessage() in CGenericFrame responds TRUE
  135. //     to this message to tell other instances or apps we are here
  136. //
  137. UINT WM_NG_IS_ACTIVE = 0;
  138. UINT WM_OPEN_EDITOR = 0;
  139. UINT WM_OPEN_NAVIGATOR = 0;
  140. // extern XP_List* wfe_pModalDlgList;
  141.  
  142. char szNGMemoryMapFilename[] = "NGMemoryMapFileURL";
  143.  
  144.  
  145. //Multi-Instance codes for detecting app exit and run status.
  146. #define EXITING -10
  147. #define RUNNING  10
  148.  
  149.  
  150. #ifdef XP_WIN32
  151. // System for communication between Navigator/Editor and Site Manager
  152. // BOOL bSiteMgrIsActive = 0;
  153. // The SiteManager client class
  154. #ifdef EDITOR
  155. ITalkSMClient * pITalkSMClient = NULL;
  156. #endif // EDITOR
  157. // This should be set ONLY if pITalkSMClient is not null
  158. BOOL bSiteMgrIsRegistered = 0;
  159. // We call URL Saving/Loading member functions only if
  160. //   site manager is already active
  161. BOOL bSiteMgrIsActive = 0;
  162. UINT WM_SITE_MANAGER = 0;
  163. #endif
  164.  
  165.  
  166. extern "C" int SECNAV_InitConfigObject(void);
  167. extern "C" void SECNAV_EarlyInit(void);
  168. extern "C" void SECNAV_Init(void);
  169. extern "C" int SECNAV_RunInitialSecConfig(void);
  170. extern "C" void SECNAV_Shutdown(void);
  171. #ifndef NSPR20
  172. extern "C" PR_PUBLIC_API(void) PR_Shutdown(void);
  173. #endif
  174.  
  175. /****************************************************************************
  176. *
  177. *       CONSTANTS
  178. *
  179. ****************************************************************************/
  180.  
  181. /////////////////////////////////////////////////////////////////////////////
  182. // CNetscapeApp
  183.  
  184. BEGIN_MESSAGE_MAP(CNetscapeApp, CWinApp)
  185.     ON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup)
  186.     ON_COMMAND(ID_HELP, OnHelp)
  187.     ON_COMMAND(ID_APP_EXIT, OnAppExit)
  188.     ON_COMMAND(ID_APP_SUPER_EXIT, OnAppSuperExit)
  189. END_MESSAGE_MAP()
  190.  
  191. #ifndef _AFXDLL
  192. #define new DEBUG_NEW  // MSVC Debugging new...goes to regular new in release mode
  193. #endif
  194.  
  195. // This identifier was generated to be statistically unique for your app.
  196. // You may change it if you prefer to choose a specific identifier.
  197. static const CLSID BASED_CODE clsid =
  198. { 0x61d8de20, 0xca9a, 0x11ce, { 0x9e, 0xa5, 0x0, 0x80, 0xc8, 0x2b, 0xe3, 0xb6 } };
  199.  
  200.  
  201. /////////////////////////////////////////////////////////////////////////////
  202. // The one and only CNetscapeApp object
  203.  
  204. CNetscapeApp NEAR theApp;
  205.  
  206. //#ifdef MOZ_NETSCAPE_FONT_MODULE
  207. // the only one object of CNetscapeFontModule
  208. CNetscapeFontModule    theGlobalNSFont;
  209. //#endif // MOZ_NETSCAPE_FONT_MODULE
  210.  
  211. NET_StreamClass *null_stream(FO_Present_Types format_out, void *newshack, URL_Struct *urls, MWContext *cx)      {
  212.     //      Stream which does nothing.
  213.     return(NULL);
  214. }
  215.  
  216. /////////////////////////////////////////////////////////////////////////////
  217. // CNetscapeApp initialization
  218. BOOL CNetscapeApp::InitApplication()
  219. {
  220.     // used to mark the beginning of the usefull stack
  221.     // for the java gc. We used to calculate this value based on the
  222.     // first argument to PR_Init(...) but PR_Init() has moved so
  223.     // we are wrong now. In order to avoid keep changing the guess
  224.     // we pass explicitly the value so wherever PR_Init() ends up we are
  225.     // all set. The stackBase must be at this level or higher on the stack
  226.     int stackBase;
  227.  
  228.     CWinApp::InitApplication();
  229.     NSToolBarClass = AfxRegisterWndClass( CS_CLASSDC | CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW,
  230.                     theApp.LoadStandardCursor(IDC_ARROW), 
  231.                     (HBRUSH)(COLOR_BTNFACE + 1));
  232.     fe_InitNSPR((void*)&stackBase);
  233.     m_appFontList = NULL;
  234.  
  235.     // Full Circle initialization
  236.     FCInitialize();
  237.     
  238.     return TRUE;
  239. }
  240.  
  241. typedef    FARPROC   (*WSASetBlockingHook_t) (FARPROC);
  242. /////////////////////////////////////////////////////////////////////////////
  243. // CNetscapeApp initialization
  244.  
  245. BOOL CNetscapeApp::InitInstance()
  246. {
  247.     //  Important to do this one first, as will need to service
  248.     //      any caught messages initialization may cause.
  249. #ifdef XP_WIN32
  250.     BOOL BailOrStay(void);
  251.     if(!BailOrStay())
  252.         return FALSE;//First instance in the middle of initializing.
  253. #endif
  254.     slavewnd.InitInstance(m_hInstance);
  255.     slavewnd.WindowProc(SLAVE_INITINSTANCE, 0, 0);
  256. //PLEASE DO NOT MOVE THE ABOVE LINE.  Multiple instance detection
  257. //relies on this window being created.
  258.  
  259.      //  We allow UNC names, to be turned off by a command line switch.
  260.      if(IsRuntimeSwitch("-nounc")) {
  261.      //  Turn off UNC file names.
  262.      m_bUNC = FALSE;
  263.      }
  264.  
  265.     char *prefStr;  // temporary storage space for preferences
  266.     int32 prefInt;
  267.     XP_Bool prefBool;
  268.  
  269.     // Determine whether this is a PE product ASAP!
  270.     m_hPEInst    = LoadLibrary("muc.dll");
  271.     m_bPEEnabled = ((UINT)m_hPEInst > 32);
  272.  
  273.     // Initialize member data
  274.     m_pTempDir = NULL;
  275. #ifdef XP_WIN16
  276.     m_helpstate = NOT_SENT; //used to prevent loops in sending ID_HELP messages to the topmost windows and having them return back
  277. #endif
  278.  
  279.     //Using resdll.dll by default
  280.     //HINSTANCE m_hResDLLInst;
  281.     m_hResInst = LoadLibrary("resdll.dll");
  282.     if((UINT)m_hResInst > 32)
  283.     {
  284.         AfxSetResourceHandle(m_hResInst);
  285.     }
  286.  
  287.     // Using resource dll if it's been defined and available
  288.    /* We are no longer using the Registry and no longer need this code
  289.    since core uses resdll.dll as well benito
  290.  
  291.      CString szResDll = GetProfileString("INTL", "ResourceDLL", "") ;
  292.     if (szResDll.IsEmpty() == FALSE)
  293.     {
  294.         m_hResInst = LoadLibrary(szResDll);
  295.         if ((UINT)m_hResInst > 32)
  296.         {
  297.             char buf1[256], buf2[256];
  298.             if (::LoadString(m_hResInst, IDS_APP_VERSION, buf1, 254) &&
  299.                 ::LoadString(AfxGetResourceHandle(), IDS_APP_VERSION, buf2, 254))
  300.             {
  301.                 if (strnicmp(buf1, buf2, strlen(buf1)) == 0)  // same version then use it
  302.                 {
  303.                     AfxSetResourceHandle(m_hResInst);
  304.                     FreeLibrary(m_hResDLLInst);
  305.                 }
  306.                 else
  307.                 {
  308.                     FreeLibrary(m_hResInst);
  309.                     m_hResInst = NULL;
  310.                 }
  311.             }
  312.             else
  313.             {
  314.                 FreeLibrary(m_hResInst);
  315.                 m_hResInst = NULL;
  316.             }
  317.         }
  318.     }
  319. */
  320.  
  321.     hAppInst = AfxGetResourceHandle();       // Changed so that this hack grabs resources from
  322.                          // the Resource DLL and not the Application Instance.
  323.                          // temporary hack for MUP -- jonm
  324.  
  325.     //  Save that we're presently in init instance, and save the initial
  326.     //      show command so that MFC doesn't blow it away prematurely.
  327.     m_bInInitInstance = TRUE;   //  Flag for frames created to use m_iFrameCmdShow
  328.     m_iFrameCmdShow = m_nCmdShow;
  329.     m_nCmdShow = SW_SHOWNORMAL;
  330.     TRACE("Show Command is %d\n", m_iFrameCmdShow);
  331.  
  332.     //  We're not exiting yet.
  333.     //  Set to true in OnAppExit.
  334.     m_bExit = FALSE;
  335.  
  336.     // CLM: PREVENT LOADING MULTIPLE INSTANCES OF THE APP!
  337.  
  338.     //  Sent by the Navigator to other navigators. Used to prevent multiple
  339.     //  instances.
  340.     // First parse the command line to get filename and start-editor flag
  341.     m_iCmdLnX = RuntimeIntSwitch(" /X");
  342.     m_iCmdLnY = RuntimeIntSwitch(" /Y");
  343.     m_iCmdLnCX = RuntimeIntSwitch(" /CX");
  344.     m_iCmdLnCY = RuntimeIntSwitch(" /CY");
  345.  
  346. ///////////////////////////////////////////////////////////////////////////
  347. ///BEGIN DDE INSTANCE CRITERIA CHECKING --SEE Abe for this stuff!!     ////
  348. ///////////////////////////////////////////////////////////////////////////
  349.     //Determine instance case and perform component launch if applicable
  350.     //using DDE to detect 2nd instance.
  351.  
  352.  
  353.     const UINT NEAR msg_ExitStatus = RegisterWindowMessage("ExitingNetscape");
  354.  
  355.     CDDECMDWrapper *pWrapper = NULL;
  356.     CStringList lstrArgumentList;
  357.     CCmdParse cmdParse;
  358.  
  359.     LONG lReturn = 0;
  360.     HWND hwnd = NULL;
  361.     CString strServiceName;
  362.     BOOL bAlreadyRunning = FALSE;
  363.     strServiceName.LoadString(IDS_DDE_CMDLINE_SERVICE_NAME);
  364.  
  365.     //initialize our DDE commandline processing conversation
  366.     DDEInitCmdLineConversation();
  367.  
  368.     CString csPrintCommand;
  369.  
  370. #ifdef XP_WIN32
  371.     BOOL CALLBACK WinEnumProc(HWND hwnd, LPARAM lParam);
  372.  
  373.     if (hwnd = FindNavigatorHiddenWindow())
  374.         lReturn = ::SendMessage(hwnd,msg_ExitStatus,0,0);
  375.  
  376.  
  377.     //Start a conversation only if we have a
  378.     //hidden frame up and running.  If the instance was in an exiting state
  379.     //then let the connect to client fail.
  380.     if (lReturn == RUNNING)
  381.     {
  382.         //attempt to connect to the DDE server.
  383.         pWrapper =      CDDECMDWrapper::ClientConnect(strServiceName,
  384.                     CDDECMDWrapper::m_hsz[CDDECMDWrapper::m_ProcessCmdLine]);
  385.     }
  386.  
  387.     if (pWrapper )
  388.     {       //we are the client here.  we must establish a conversation with the server
  389.         CString strDDECMDString = m_lpCmdLine;
  390.         //make sure this always has something in it for second instance.  The first
  391.         //instance needs something to do something for the user.  Default is start browser.
  392.     
  393.     if (strDDECMDString.GetLength() > 249)
  394.     {
  395.         CString strDDECmdFileName = BuildDDEFile();
  396.         CFile fout;
  397.  
  398.         if( !fout.Open( strDDECmdFileName, CFile::modeWrite ) )
  399.         {
  400.         if (!strDDECmdFileName.IsEmpty())
  401.             remove(strDDECmdFileName);
  402.  
  403.         return FALSE;
  404.         }
  405.  
  406.         fout.Write(strDDECMDString, strDDECMDString.GetLength());
  407.  
  408.         strDDECMDString = "-DDEEXCEPTION" + strDDECmdFileName;
  409.     }
  410.         
  411.         
  412.     if (strDDECMDString.IsEmpty()) strDDECMDString = "-BROWSER";
  413.         HCONV  hSavConv = pWrapper->m_hConv;
  414.  
  415.  
  416.         HDDEDATA hData = DdeCreateDataHandle(CDDECMDWrapper::m_dwidInst,
  417.                                             (LPBYTE)(const char*)strDDECMDString,
  418.                                             strDDECMDString.GetLength() +1,
  419.                                             0,
  420.                                             0,
  421.                                             CF_TEXT,
  422.                                             0);
  423.  
  424.         DWORD wdResult;
  425.  
  426.         HDDEDATA ddeTransaction = DdeClientTransaction( (LPBYTE)hData,
  427.                                             0xFFFFFFFF,
  428.                                             hSavConv,
  429.                                             0,
  430.                                             0,
  431.                                             XTYP_EXECUTE,
  432.                                             3000,
  433.                                             &wdResult);
  434.  
  435.         DdeFreeDataHandle(hData);
  436.         DdeDisconnect(hSavConv);
  437.         delete pWrapper;
  438.         bAlreadyRunning = TRUE;
  439.  
  440.         return FALSE;  //EXIT THIS INSTANCE.  WE ARE DONE!!!
  441.     }
  442.     else
  443.     {       //do command line stuff as usual and set flags appropriately
  444.     csPrintCommand = RuntimeStringSwitch("/print", FALSE);
  445.         if (ParseComponentArguments(m_lpCmdLine,TRUE))
  446.         {
  447.             cmdParse.Init(m_lpCmdLine,lstrArgumentList);
  448.             if (!cmdParse.ProcessCmdLine() )
  449.             {
  450.                 AfxMessageBox(IDS_CMDLINE_ERROR3);
  451.                 return FALSE; //make them type it in correctly
  452.             }
  453.         }
  454.         parseCommandLine(m_lpCmdLine);
  455.         //we will be the server in this case, So we must register our name service.
  456.  
  457.         //initialize our DDE commandline processing conversation.
  458.  
  459.         DdeNameService(CDDECMDWrapper::m_dwidInst,
  460.         CDDECMDWrapper::m_hsz[CDDECMDWrapper::m_ServiceName], NULL,
  461.         DNS_REGISTER);
  462.  
  463.     }
  464. #else
  465.         //We are never the client in win16 since we will never have a second instance.
  466.     //Thus we will always start as a server.  The component launch app will decide whether
  467.     //to execute a mozilla.exe or DDE to the mozilla.exe DDE server.
  468.  
  469.     csPrintCommand = RuntimeStringSwitch("/print", FALSE);
  470.     if (ParseComponentArguments(m_lpCmdLine,TRUE))
  471.     {
  472.  
  473.         //build a token list to be looked at later
  474.         cmdParse.Init(m_lpCmdLine,lstrArgumentList);
  475.         if (!cmdParse.ProcessCmdLine() )
  476.         {
  477.             AfxMessageBox(IDS_CMDLINE_ERROR3);
  478.             return FALSE; //make them type it in correctly
  479.         }
  480.  
  481.     }
  482.     parseCommandLine(m_lpCmdLine);
  483.     //we will be the server in this case, So we must register our name service.
  484.     DdeNameService(CDDECMDWrapper::m_dwidInst,
  485.     CDDECMDWrapper::m_hsz[CDDECMDWrapper::m_ServiceName], NULL,
  486.     DNS_REGISTER);
  487. #endif
  488.  
  489. ///////////////////////////////////////////////////////////////////////////
  490. ///END DDE INSTANCE CRITERIA CHECKING  BLOCK                               ////
  491. ///////////////////////////////////////////////////////////////////////////
  492.  
  493.  
  494.  
  495. /////////COMPONENT LAUNCH
  496.  
  497. //#ifdef GOLD
  498.     // Yes we are a gold version!
  499.     bIsGold = TRUE;
  500. //#endif
  501.  
  502. #ifdef EDITOR
  503.     // Register the global messages
  504.  
  505.     //  Sent by the Navigator to other navigators. Used to prevent multiple
  506.     //  instances.
  507.     WM_NG_IS_ACTIVE = RegisterWindowMessage( "__lvp_str_NGIsActive__" );
  508.  
  509.     //  Sent by the Navigator to activate previous instance with URL in
  510.     //  most recent browser window.
  511.     WM_OPEN_EDITOR = RegisterWindowMessage( "__lvp_str_LoadUrlNav__" );
  512.  
  513.     //  Sent by the Navigator to activate previous instance with URL in
  514.     //  a new editor window.
  515.     WM_OPEN_NAVIGATOR = RegisterWindowMessage( "__lvp_str_LoadUrlEdt__" );
  516.  
  517. #ifdef XP_WIN32
  518.     // Sent to identify whether window is a Navigator or Sitemanager
  519.     WM_SITE_MANAGER = RegisterWindowMessage( "__talkSM_SM_IsAlive__" );
  520.  
  521. //#ifdef GOLD
  522.     // Start an OLE Automation client to talk to LiveWire's Site Manager
  523.     pITalkSMClient = new (ITalkSMClient);
  524.     if ( pITalkSMClient && pITalkSMClient->IsRegistered()){
  525.     // SiteManager was registered with OLE database
  526.     bSiteMgrIsRegistered = TRUE;
  527.     // See if we already have an instance
  528.     //bSiteMgrIsActive = FE_FindSiteMgr();
  529.     if( bSiteMgrIsActive ){
  530.         pITalkSMClient->SetKnownSMState(TRUE);
  531.     }
  532.     }
  533. //#endif //GOLD
  534. #endif //XP_WIN32
  535. #endif //EDITOR
  536.  
  537.     TRACE("Windows 16 is %d\n", sysInfo.m_bWin16);
  538.     TRACE("Windows 32 is %d\n", sysInfo.m_bWin32);
  539.     TRACE("Windows 32s is %d\n", sysInfo.m_bWin32s);
  540.     TRACE("Windows NT is %d\n", sysInfo.m_bWinNT);
  541.     TRACE("Windows 95 is %d\n", sysInfo.m_bWin4);
  542.  
  543.     TRACE("Major version is %u\n", (unsigned)sysInfo.m_dwMajor);
  544.     TRACE("Minor version is %u\n", (unsigned)sysInfo.m_dwMinor);
  545.     TRACE("Build version is %u\n", (unsigned)sysInfo.m_dwBuild);
  546.  
  547. #ifdef _MSC_VER
  548.     TRACE("Compiler version is %u\n", _MSC_VER);
  549. #endif
  550. #ifdef _MFC_VER
  551.     TRACE("MFC version is %u\n", _MFC_VER);
  552. #endif
  553.  
  554. #ifdef XP_WIN16
  555.     // Call the magic function that feeds off the environment variable "TZ"
  556.     // to set up the global time variables.
  557. #ifdef __WATCOMC__
  558.     tzset();
  559. #else
  560.     _tzset();
  561. #endif
  562. #endif // XP_WIN16
  563.  
  564.  
  565.  
  566.     //  Initialized OLE, or fail
  567.     TRACE("Starting Ole\n");
  568.     if(!AfxOleInit()) {
  569.     AfxMessageBox(IDP_OLE_INIT_FAILED);
  570.     return FALSE;
  571.     }
  572.  
  573.     // Initialize 3d controls
  574. #ifdef XP_WIN32
  575.     Enable3dControls();
  576. #else
  577.     Ctl3dRegister(m_hInstance);
  578.     Ctl3dAutoSubclass(m_hInstance);
  579. #endif
  580.  
  581.     AssortedWidgetInit();
  582.  
  583.     JSContext * prefContext=NULL;
  584.     JSObject *prefObject=NULL;
  585.  
  586.     PREF_Init(NULL);
  587.     // Read network and cache parameters
  588.  
  589.     PREF_GetConfigContext(&prefContext);
  590.     PREF_GetPrefConfigObject(&prefObject);
  591.     if (!(prefContext && prefObject)) return FALSE;
  592.  
  593.     if (!pref_InitInitialObjects(prefContext,prefObject))
  594.         return FALSE;
  595.  
  596.     SECNAV_InitConfigObject();
  597.  
  598.     /*
  599.     ** Registry startup has to happen before profile stuff because creating a new
  600.     ** profile uses the registry.
  601.     */
  602.     NR_StartupRegistry();
  603.  
  604.     // Initialize the network.
  605.     WORD wVersionRequested;
  606.     int err;
  607.  
  608.     wVersionRequested = MAKEWORD(1,1);
  609.  
  610.     err= WSAStartup(wVersionRequested,&(sysInfo.m_wsaData));
  611.  
  612.     m_csWinsock = sysInfo.m_wsaData.szDescription;    //  Save this, used in ResolveAppName.
  613.  
  614.     if (err !=0) {
  615.     MessageBox(NULL, szLoadString(IDS_NET_INIT_FAILED), szLoadString(AFX_IDS_APP_TITLE), MB_OK);
  616.     return FALSE;
  617.     }
  618.  
  619. #if defined(XP_WIN16) 
  620.     //
  621.     // This is a hack...  It should live in NSPR.  It will be moved for NSPR 2.0
  622.     //
  623.     {
  624.     WSASetBlockingHook_t func;
  625.     HINSTANCE hinstWinsock = LoadLibrary("winsock.dll");
  626.     func = (WSASetBlockingHook_t)GetProcAddress(hinstWinsock, "WSASETBLOCKINGHOOK");
  627.     ASSERT(func);
  628.     if (func) {
  629.         extern BOOL PR_CALLBACK DefaultBlockingHook(void);
  630. #if defined(DEBUG)            
  631.         ASSERT ( (func)( (FARPROC)DefaultBlockingHook ) );
  632. #else
  633.         (func)( (FARPROC)DefaultBlockingHook );
  634. #endif
  635.     }
  636.     FreeLibrary(hinstWinsock);
  637.     }
  638. #endif
  639.  
  640.     TRACE("Winsock description is %s\n", sysInfo.m_wsaData.szDescription);
  641.     TRACE("Winsock status is %s\n", sysInfo.m_wsaData.szSystemStatus);
  642.  
  643.     if (LOBYTE(sysInfo.m_wsaData.wVersion) != 1 || HIBYTE(sysInfo.m_wsaData.wVersion) != 1) {
  644.       MessageBox(NULL, szLoadString(IDS_NET_INIT_FAILED), szLoadString(AFX_IDS_APP_TITLE), MB_OK);
  645.     WSACleanup();
  646.     return FALSE;
  647.     }
  648.  
  649.     //  Determine maximum number of sockets that we will allow in the application.
  650.     //  This is safer than just choosing some arbitrary number (always 50).
  651.     //  Hard coded params:  Min 8 Max 50
  652.     //  Soft coded limits:  Half of available sockets winsock reported.
  653.     sysInfo.m_iMaxSockets = sysInfo.m_wsaData.iMaxSockets / 2;
  654.     if(sysInfo.m_iMaxSockets < 8)   {
  655.     sysInfo.m_iMaxSockets = 8;
  656.     }
  657.     else if(sysInfo.m_iMaxSockets > 50) {
  658.     sysInfo.m_iMaxSockets = 50;
  659.     }
  660.  
  661.     TRACE("Max number of sockets is %d\n", sysInfo.m_iMaxSockets);
  662.  
  663.     // Initialize the network module
  664.     /* NET_InitNetLib handles socks initialization. */
  665.  
  666.     CString msg;
  667.     //
  668.     // Get the temp directory.  See if it exists
  669.     // This must be before the e-kit check below
  670.     //
  671.     msg = GetProfileString("Main", "Temp Directory", DEF_TEMP_DIR);  // directory configured?
  672.     if (msg != BOGUS_TEMP_DIR) {
  673.     m_pTempDir = XP_STRDUP((const char *)msg);
  674.     } else {
  675.     if(getenv("TEMP"))
  676.       m_pTempDir = XP_STRDUP(getenv("TEMP"));  // environmental variable
  677.     if (!m_pTempDir && getenv("TMP"))
  678.       m_pTempDir = XP_STRDUP(getenv("TMP"));  // How about this environmental variable?
  679.     if (!m_pTempDir) {
  680.       // screw 'em put it in the windows directory
  681.       char path[_MAX_PATH];
  682.       GetWindowsDirectory(path, sizeof(path));
  683.       m_pTempDir = XP_STRDUP(path);
  684.     }
  685.     }
  686.  
  687.     //      Ensure no backslash on the end of the temp dir.
  688.     FEU_NoTrailingBackslash(m_pTempDir);
  689.  
  690.     //
  691.     // Check that the temp directory exists
  692.     //
  693.     if(!FEU_SanityCheckDir(m_pTempDir)) {
  694.  
  695.     char msg[1024];
  696.  
  697.     ::sprintf(msg, szLoadString(IDS_ERR_TMP_DIR_NOT_EXIST), m_pTempDir);
  698.     MessageBox(NULL, msg, szLoadString(AFX_IDS_APP_TITLE), MB_ICONEXCLAMATION | MB_OK);
  699.  
  700.     }
  701.     
  702.     NET_InitNetLib(0, sysInfo.m_iMaxSockets);
  703.  
  704.     // init parts of security for li
  705.     SECNAV_EarlyInit();
  706.  
  707.     // Create our hidden frame window.
  708.     // Set this to be the applications main window.
  709.     m_pHiddenFrame = new CHiddenFrame();
  710. #ifdef _WIN32
  711.     {
  712.         WNDCLASS wc;
  713.         wc.style         = 0;
  714.         wc.lpfnWndProc   = ::DefWindowProc;
  715.         wc.cbClsExtra    = 0;
  716.         wc.cbWndExtra    = sizeof(DWORD);               // this is used by java's setAgentPassword
  717.         wc.hInstance     = ::AfxGetInstanceHandle();
  718.         wc.hIcon         = NULL;
  719.         wc.hCursor       = ::LoadCursor(NULL, IDC_ARROW);
  720.         wc.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1);
  721.         wc.lpszMenuName  = (LPCSTR) NULL;
  722.         wc.lpszClassName = "aHiddenFrameClass";
  723.         ATOM result = ::RegisterClass(&wc);
  724.         ASSERT(result != 0);
  725.         m_pHiddenFrame->Create(wc.lpszClassName, "Netscape's Hidden Frame");
  726.     }
  727. #else
  728.         m_pHiddenFrame->Create(NULL, "Netscape's Hidden Frame");
  729. #endif
  730.     m_pMainWnd = m_pHiddenFrame;
  731.     m_pHiddenFrame->ShowWindow(SW_HIDE);
  732.  
  733.     CDocTemplate *pTemplate = WFE_InitializeTemplates();
  734.     if (!pTemplate)
  735.         return FALSE;
  736.  
  737.     // Get the main NSPR event queue
  738.     mozilla_event_queue  = PR_GetMainEventQueue();
  739.  
  740.     LM_InitMocha();
  741.  
  742.     // Initialize the XP file extension mapping
  743.     NET_InitFileFormatTypes(NULL, NULL);
  744.  
  745.     // Register all XP content type converters and stream decoders.
  746.     // We can overwrite these settings if we have other settings ourselves.
  747.     NET_RegisterMIMEDecoders();
  748.  
  749.     /////////////////////////////////////////////////////////////////////////
  750.     // Read in font and setup encoding table stuff
  751. #ifdef XP_WIN32
  752.     theApp.m_bUseUnicodeFont = GetProfileInt("Intl", "UseUnicodeFont",  TRUE ) ;
  753.     theApp.m_bUseVirtualFont = GetProfileInt("Intl", "UseVirtualFont",  FALSE);
  754.     if(! theApp.m_bUseUnicodeFont ) {
  755.     theApp.m_bUseVirtualFont = TRUE;
  756.     }
  757. #else
  758.     theApp.m_bUseUnicodeFont = FALSE ;
  759.     theApp.m_bUseVirtualFont = TRUE;
  760. #endif
  761.  
  762.     m_pIntlFont = new CIntlFont;
  763.  
  764.     int32   csid ;
  765.     if( PREF_GetIntPref("intl.character_set",&csid) != PREF_NOERROR)
  766.         csid = 2;
  767.  
  768.     m_iCSID = (int16)csid;
  769.     INTL_ChangeDefaultCharSetID((int16)csid);
  770.  
  771.     STARTUP_cvffc();
  772.  
  773. //#ifdef MOZ_NETSCAPE_FONT_MODULE
  774.     VERIFY( FONTERR_OK == theGlobalNSFont.InitFontModule() );
  775. //#endif MOZ_NETSCAPE_FONT_MODULE
  776.  
  777.     // Initialize RDF
  778.     m_pRDFCX = new CRDFCX(::RDFSlave, MWContextRDFSlave);
  779.     
  780.     // Set version and application names
  781.     //  We have to get around it's const status.
  782.     XP_AppName     = XP_STRDUP(szLoadString(IDS_APP_NAME));
  783.     XP_AppLanguage = XP_STRDUP(szLoadString(IDS_APP_LANGUAGE));
  784.     XP_AppCodeName = XP_STRDUP(szLoadString(IDS_APP_CODE_NAME));
  785.     XP_AppVersion  = XP_STRDUP(ResolveShortAppVersion());
  786.  
  787.     if (!login_QueryForCurrentProfile())
  788.         return FALSE;
  789.  
  790.     // SECNAV_INIT requires AppCodeName and the first substring in AppVersion 
  791.     SECNAV_Init();
  792.  
  793.     GH_InitGlobalHistory();
  794.  
  795.     NET_RemoveAllCookies();
  796.     NET_ReadCookies("");
  797.  
  798.     PREF_GetIntPref("network.tcpbufsize",&prefInt);
  799.     int nTCPBuff = CASTINT(prefInt);
  800.  
  801.     //  Have preference watchers commence since prefs are up.
  802.     prefInfo.Initialize();
  803.  
  804.     //move to this location due to report that PREF calls were crashing 16bit java.
  805.     //also, only do this if we are the first instance.  See the instance checing section
  806.     //for where bAlreadyRunning is set.  ifdef'd for win16 since never have 2 instances.
  807. #ifdef XP_WIN32
  808.     if(!bAlreadyRunning)
  809.     {
  810. #endif
  811.         extern void AskMeDlg(void);
  812.         AskMeDlg();        
  813. #ifdef XP_WIN32
  814.     }
  815. #endif
  816.     //      If we're running automated or embedded, we instantly need to create
  817.     //              a new lock on the appication.
  818.     //      So OnIdle for a full description of the problem at hand.
  819.     //  Consider ourselves automated if we have a print command.
  820.     m_bEmbedded = RunEmbedded();
  821.     m_bAutomated = RunAutomated();
  822.  
  823.     // register the icon for our document files
  824.     auto char ca_default[_MAX_PATH + 5];
  825.     ::GetModuleFileName(m_hInstance, ca_default, _MAX_PATH);
  826.     strcat(ca_default, ",1"); //Dave: Fixed this
  827.     if(!fe_RegisterOLEIcon("{481ED670-9D30-11ce-8F9B-0800091AC64E}",
  828.             "Netscape Hypertext Document",
  829.             ca_default)) {
  830.     TRACE("Failed to register OLE Icons\n");
  831.     }
  832.  
  833.  
  834.     if (!(sysInfo.m_bWin32 && sysInfo.m_dwMajor >= 4))
  835.     SetDialogBkColor();    // set dialog background color to gray
  836.     LoadStdProfileSettings();  // Load standard INI file options (including MRU)
  837.  
  838.     hAccelTable = LoadAccelerators (m_hInstance, MAKEINTRESOURCE(IDR_MAINFRAME));
  839.  
  840.     // Enable shell printing
  841.     EnableShellStuff();
  842.  
  843.     //  Get the list of trusted user applications.
  844.     m_pSpawn = new CSpawnList();
  845.  
  846.     // The first order of business is to get our install directory so that we can
  847.     //    locate the dumb files and use the install dir as the default for other
  848.     //    files and directories
  849.  
  850.     if (!strcmpi(szLoadString(IDS_LOCKED_PREFERENCES),"yes"))
  851.     m_bUseLockedPrefs = TRUE;
  852.     else
  853.     m_bUseLockedPrefs = FALSE;
  854.  
  855.     // Frame creation may cause the loading of the home page so register
  856.     // all of the parser and network functions first
  857.     static PA_InitData parser_data;
  858.     parser_data.output_func = LO_ProcessTag;
  859.  
  860.     PREF_GetIntPref("network.max_connections",&prefInt);
  861.     int nMaxConnect = CASTINT(prefInt);
  862.  
  863.     // In 2.0 this has no GUI and is only settable via the installer for
  864.     //   Personal Edition so don't put it in the m_PrefList list so that
  865.     //   we don't create the entry when we flush out all of our preferences
  866. //    CPref nTCPTimeOut(NULL, "Network", "TCP Connect Timeout", 0);
  867.  
  868.       /* larubbio begin */
  869.     msg = m_UserDirectory;
  870.     msg += "\\archive";
  871.  
  872.     m_pSARCacheDir = msg;
  873.  
  874.     //
  875.     // make sure we can write to this directory
  876.     //
  877.     if(!FEU_SanityCheckDir(m_pSARCacheDir)){
  878.  
  879.     char msg[1024];
  880.     ::sprintf(msg, szLoadString(IDS_ERR_CACHE_DIR_NOT_EXIST), m_pSARCacheDir);
  881.     MessageBox(NULL, msg, szLoadString(AFX_IDS_APP_TITLE), MB_ICONEXCLAMATION | MB_OK);
  882.  
  883.     }
  884.       /* larubbio end */
  885.  
  886.     // Read the cache dir
  887.     msg = m_UserDirectory;
  888.     msg += "\\cache";
  889.     PREF_SetDefaultCharPref("browser.cache.directory",msg);
  890.  
  891.     prefStr = NULL;
  892.     PREF_CopyCharPref("browser.cache.directory",&prefStr);
  893.     m_pCacheDir = prefStr;
  894.     PREF_RegisterCallback("browser.cache.directory",WinFEPrefChangedFunc,NULL);
  895.     if (prefStr) XP_FREE(prefStr);
  896.  
  897.     //
  898.     // make sure we can write to this directory
  899.     //
  900.     XP_Bool bTurnOffDiskCache = FALSE;
  901.  
  902.     if(!FEU_SanityCheckDir(m_pCacheDir)){
  903.  
  904.     char msg[1024];
  905.     ::sprintf(msg, szLoadString(IDS_ERR_CACHE_DIR_NOT_EXIST), m_pCacheDir);
  906.     MessageBox(NULL, msg, szLoadString(AFX_IDS_APP_TITLE), MB_ICONEXCLAMATION | MB_OK);
  907.  
  908.     // turn off the cache for now
  909.     bTurnOffDiskCache = TRUE;
  910.     }
  911.  
  912. #ifdef JEM
  913.     // Initialize the network module
  914.     /* NET_InitNetLib handles socks initialization. */
  915.     NET_InitNetLib(nTCPBuff, sysInfo.m_iMaxSockets);
  916. #endif
  917.  
  918. #ifdef MOZ_LOC_INDEP
  919.     STARTUP_li();
  920. #endif /* MOZ_LOC_INDEP */
  921.  
  922.     SECNAV_RunInitialSecConfig();
  923.  
  924.     NET_ChangeMaxNumberOfConnectionsPerContext(nMaxConnect);
  925.  
  926.     // throw away old wrong app version, get right one */
  927.     XP_FREE(XP_AppVersion);
  928.     XP_AppVersion = XP_STRDUP(ResolveAppVersion());
  929.  
  930.     if (bTurnOffDiskCache) NET_SetDiskCacheSize(0);
  931.  
  932.     //
  933.     // Only mess with the TCP connect time out if we have gotten a
  934.     //   positive number out of the Registry/INI file.  Don't let the
  935.     //   number go below 30 seconds or above 4 minutes
  936.     //
  937.     int32 nTCPTimeOut;
  938.     PREF_GetIntPref("network.tcptimeout",&nTCPTimeOut);
  939.     if(nTCPTimeOut > 30 && nTCPTimeOut < 240)
  940.     NET_SetTCPConnectTimeout(nTCPTimeOut);
  941.     else if(nTCPTimeOut > 240)
  942.     NET_SetTCPConnectTimeout(240);
  943.  
  944. #if defined(XP_WIN32)
  945.     XP_AppPlatform = "Win32";
  946. #elif defined(XP_WIN16)
  947.     XP_AppPlatform = "Win16";
  948. #else
  949. #error Unexpected platform!
  950. #endif
  951.  
  952.  
  953.     // Get the Id of the message which NSPR uses for event notifications...
  954.     m_msgNSPREventNotify = ::RegisterWindowMessage("NSPR_PostEvent");
  955.  
  956.   // rhp - Added change for not showing splash screen for MAPI startup
  957.     // now that we are done with everything that can fail, show the splash
  958.     if (showSplashScreen(csPrintCommand)) 
  959.     {
  960.         // only show splash if not embedded
  961.     m_splash.Create(NULL);
  962. #if !defined(DEBUG_chouck) && !defined(DEBUG_blythe) && !defined(DEBUG_warren) && !defined(DEBUG_phil) && !defined(DEBUG_hyatt)
  963.     m_splash.ShowWindow(SW_SHOW);
  964. #endif
  965.     m_splash.UpdateWindow();
  966.     }
  967.  
  968.     // figure out if we need to have a little N in the toolbar for
  969.     //  cobranding purposes
  970.     int iTmp;
  971.     m_bShowNetscapeButton = CUST_IsCustomAnimation(&iTmp);
  972.  
  973.  
  974.  
  975. //BEGIN STREAM VODOO
  976.  
  977.  
  978.     // Add user configured MIME types and file extensions to the NETLIB lists.
  979.     // This sets up any user configured viewers also, by placing them in a list that
  980.     //      will be entered in the function external_viewer_disk_stream....  What a kludge.
  981.     // This also constructs a list of possible helper applications that are spawned off
  982.     //      in external_viewer_disk_stream read in from the INI file.
  983.     fe_InitFileFormatTypes();
  984.  
  985. #ifdef XP_WIN32
  986.     // Check to see if we're the "default browser"
  987.     CheckDefaultBrowser();
  988. #endif // XP_WIN32
  989.  
  990.     //Begin CRN_MIME
  991.     //At this point we have all the mime_type prefs(from prefs.js, netscape.cfg) 
  992.     //read into the prefs table. Use this info to update the NETLIB lists.
  993.     fe_UpdateMControlMimeTypes(); 
  994.  
  995.     //Register a callback so that we can update the mime type info., in response to 
  996.     //new AutoAdmin prefs updates.
  997.     PREF_RegisterCallback("mime.types.all_defined",WinFEPrefChangedFunc,NULL);
  998.     //End CRN_MIME
  999.  
  1000.     //  NEVER MODIFY THE BELOW unless NEW FO types appear.
  1001.     //  NEVER CALL RealNET_RegisterContentTypeConverter ANYWHERE ELSE (exceptions in presentm.cpp).
  1002.     //  INSTEAD USE NET_RegisterContentTypeConverter.
  1003.     //  WE MUST INITIALIZE EVERY FO_Format_Out TO OUR PRESENTATION MANAGER.
  1004.     char *cp_wild = "*";
  1005.     //  Mocha src equal converter.
  1006.     NET_RegisterContentTypeConverter("application/x-javascript", FO_PRESENT, NULL, NET_CreateMochaConverter);
  1007.  
  1008.     // XXX dkarlton is adding preencrypted files here, even though it's called
  1009.     // in libnet/cvmime.c. What's going on here?
  1010. #ifdef FORTEZZA
  1011.     NET_RegisterContentTypeConverter(INTERNAL_PRE_ENCRYPTED, FO_PRESENT, NULL, SECNAV_MakePreencryptedStream);
  1012. // mwh - xxx need to check on this.
  1013.     //NET_RegisterContentTypeConverter(INTERNAL_PRE_ENCRYPTED, FO_INTERNAL_IMAGE, NULL, PresentationManagerStream);
  1014.     //NET_RegisterContentTypeConverter(INTERNAL_PRE_ENCRYPTED, FO_VIEW_SOURCE, NULL, PresentationManagerStream);
  1015.     NET_RegisterContentTypeConverter(APPLICATION_PRE_ENCRYPTED, FO_PRESENT, NULL, SECNAV_MakePreencryptedStream);
  1016. // mwh - xxx need to check on this.
  1017.     //NET_RegisterContentTypeConverter(APPLICATION_PRE_ENCRYPTED, FO_INTERNAL_IMAGE, NULL, PresentationManagerStream);
  1018.     //NET_RegisterContentTypeConverter(APPLICATION_PRE_ENCRYPTED, FO_VIEW_SOURCE, NULL, PresentationManagerStream);
  1019. #endif
  1020.  
  1021. #ifdef JAVA
  1022.     //NET_RegisterContentTypeConverter(cp_wild, FO_DO_JAVA, NULL, PresentationManagerStream);
  1023. #endif
  1024.  
  1025. #ifdef FORTEZZA
  1026.     NET_RegisterContentTypeConverter(APPLICATION_PRE_ENCRYPTED, FO_CACHE_AND_PRESENT, NULL, SECNAV_MakePreencryptedStream);
  1027.     NET_RegisterContentTypeConverter(APPLICATION_PRE_ENCRYPTED, FO_CACHE_AND_INTERNAL_IMAGE, NULL, SECNAV_MakePreencryptedStream);
  1028.     NET_RegisterContentTypeConverter(APPLICATION_PRE_ENCRYPTED, FO_CACHE_AND_VIEW_SOURCE, NULL,SECNAV_MakePreencryptedStream);
  1029. #endif
  1030.  
  1031.     NET_RegisterContentTypeConverter(cp_wild, FO_CACHE_ONLY, NULL, NET_CacheConverter);
  1032.     NET_RegisterContentTypeConverter(cp_wild, FO_CACHE_AND_PRESENT, NULL, NET_CacheConverter);
  1033.     NET_RegisterContentTypeConverter(cp_wild, FO_CACHE_AND_INTERNAL_IMAGE, NULL, NET_CacheConverter);
  1034.     NET_RegisterContentTypeConverter(cp_wild, FO_CACHE_AND_OUT_TO_PROXY_CLIENT, NULL, NET_CacheConverter);
  1035.     NET_RegisterContentTypeConverter(cp_wild, FO_CACHE_AND_VIEW_SOURCE, NULL, NET_CacheConverter);
  1036.     NET_RegisterContentTypeConverter(cp_wild, FO_CACHE_AND_SAVE_AS, NULL, NET_CacheConverter);
  1037.     NET_RegisterContentTypeConverter(cp_wild, FO_CACHE_AND_SAVE_AS_TEXT, NULL, NET_CacheConverter);
  1038.     NET_RegisterContentTypeConverter(cp_wild, FO_CACHE_AND_SAVE_AS_POSTSCRIPT, NULL, NET_CacheConverter);
  1039.     NET_RegisterContentTypeConverter(cp_wild, FO_CACHE_AND_QUOTE_MESSAGE, NULL, NET_CacheConverter);
  1040.     NET_RegisterContentTypeConverter(cp_wild, FO_CACHE_AND_MAIL_TO, NULL, NET_CacheConverter);
  1041.     NET_RegisterContentTypeConverter(cp_wild, FO_CACHE_AND_OLE_NETWORK, NULL, NET_CacheConverter);
  1042.     NET_RegisterContentTypeConverter(cp_wild, FO_CACHE_AND_MULTIPART_IMAGE, NULL, NET_CacheConverter);
  1043.     NET_RegisterContentTypeConverter(cp_wild, FO_CACHE_AND_PRINT, NULL, NET_CacheConverter);
  1044.  
  1045.     // Set up converters for our Presentation Manager.
  1046.     // Front end sets these up, only because the front end handles front end converters!
  1047.     // XP code is responsible for registering their proper converters in NET_RegisterMIMEDecoders
  1048.     NET_RegisterContentTypeConverter("text/*", FO_VIEW_SOURCE, NULL, memory_stream);      // */
  1049.     NET_RegisterContentTypeConverter(cp_wild, FO_PRESENT, NULL, external_viewer_disk_stream);
  1050.     NET_RegisterContentTypeConverter(cp_wild, FO_PRINT, NULL, external_viewer_disk_stream);
  1051.     NET_RegisterContentTypeConverter(cp_wild, FO_VIEW_SOURCE, NULL, memory_stream);
  1052.     NET_RegisterContentTypeConverter(cp_wild, FO_OUT_TO_PROXY_CLIENT, NULL, external_viewer_disk_stream);
  1053.     NET_RegisterContentTypeConverter(cp_wild, FO_SAVE_AS, NULL, ContextSaveStream);
  1054.     NET_RegisterContentTypeConverter(cp_wild, FO_OLE_NETWORK, NULL, nfe_OleStream);
  1055.     NET_RegisterContentTypeConverter(cp_wild, FO_EMBED, NULL, EmbedStream);
  1056.     //      added by ftang & jliu, just remap it from memory_stream->net_ColorHTMLStream
  1057.     NET_RegisterContentTypeConverter(INTERNAL_PARSER, FO_VIEW_SOURCE, TEXT_HTML, net_ColorHTMLStream);
  1058.  
  1059.     //  EVERY FO_PRESENT REGISTRATION NEEDS TO BE ALSO DONE FOR FO_PRINT!!!
  1060.     //  Need to handle a format out of FO_PRINT in order to correctly print without spawning
  1061.     //      registered external/automated viewers.
  1062.     //  Had to look in odd places to find all the correct ones.  Try cvmime.c
  1063.     NET_RegisterContentTypeConverter(TEXT_HTML, FO_PRINT, NULL, INTL_ConvCharCode);
  1064.     NET_RegisterContentTypeConverter(TEXT_MDL, FO_PRINT, NULL, INTL_ConvCharCode);
  1065.     NET_RegisterContentTypeConverter(TEXT_PLAIN, FO_PRINT, NULL, NET_PlainTextConverter);
  1066.     NET_RegisterContentTypeConverter(UNKNOWN_CONTENT_TYPE, FO_PRINT, NULL, NET_PlainTextConverter);
  1067.     NET_RegisterContentTypeConverter(INTERNAL_PARSER, FO_PRINT, (void *)&parser_data, PA_BeginParseMDL);
  1068.     NET_RegisterContentTypeConverter(IMAGE_GIF, FO_PRINT, NULL, IL_ViewStream);
  1069.     NET_RegisterContentTypeConverter(IMAGE_XBM, FO_PRINT, NULL, IL_ViewStream);
  1070.     NET_RegisterContentTypeConverter(IMAGE_JPG, FO_PRINT, NULL, IL_ViewStream);
  1071.  
  1072.     // Don't handle printing cases if we can't format it.
  1073. //    NET_RegisterContentTypeConverter(cp_wild, FO_PRINT, NULL, null_stream);
  1074.  
  1075.     //  Initialize our OLE viewers in WPM.
  1076.     COleRegistry::RegisterIniViewers();
  1077.     //  Initialize our OLE protocol handlers.
  1078.     COleRegistry::RegisterIniProtocolHandlers();
  1079. //END STREAM VODOO
  1080.  
  1081.  
  1082.     CString strStatus;
  1083.  
  1084.   // rhp - Added flag for MAPI startup...
  1085.     if (showSplashScreen(csPrintCommand)) {
  1086.         strStatus.LoadString(IDS_LOAD_PREFS);
  1087.         m_splash.DisplayStatus(strStatus);
  1088.     }
  1089.  
  1090.     StoreVersionInReg();
  1091.  
  1092.     // BUG: will need to make sure this directory exists
  1093.     /////////////////////////////////////////////////////////////////////////
  1094.     // Look up application level preferences
  1095.  
  1096.     // Override Home Page for PE ASW Entry here??  SWE
  1097.  
  1098.     if (!theApp.m_csPEPage.IsEmpty())
  1099.     {
  1100.     m_pHomePage = (const char *) theApp.m_csPEPage;
  1101.     // Kludge this one too to make it go there...
  1102.     m_CmdLineLoadURL = XP_STRDUP((const char *) theApp.m_csPEPage);
  1103.     }
  1104.     else
  1105.     {
  1106.     // Read the home page out of the .ini file
  1107.     prefStr = NULL;
  1108.     if (!PREF_CopyCharPref("browser.startup.homepage",&prefStr)) {
  1109.         m_pHomePage = prefStr;
  1110.         if (prefStr) XP_FREE(prefStr);
  1111.     } else m_pHomePage = "";
  1112.     PREF_RegisterCallback("browser.startup.homepage",WinFEPrefChangedFunc,NULL);
  1113.     }
  1114.  
  1115.     // TODO (jonm) register WFE pref callbacks
  1116.  
  1117.     if(!strcmp(szLoadString(IDS_CHANGE_HOMEPAGE), "yes")) {
  1118.         m_nChangeHomePage = TRUE;
  1119.     } else {
  1120.         PREF_SetCharPref("browser.startup.homepage",szLoadString(IDS_DEF_HOMEPAGE));
  1121.         m_nChangeHomePage = FALSE;
  1122.     }
  1123.  
  1124.     fe_InitJava();
  1125.  
  1126.     /////////////////////////////////////////////////////////////////////////
  1127.     // what menu were we last looking at in the preferences window?
  1128.     m_nConfig = GetProfileInt("Main", "Last Config Menu", 0);
  1129.  
  1130.  
  1131.      /////////////////////////////////////////////////////////////////////
  1132.     // Security warnings
  1133.     for(int i = 0; i < MAX_SECURITY_CHECKS; i++)
  1134.     m_nSecurityCheck[i] = TRUE;
  1135.  
  1136.     if(GetProfileString("Security", "Warn Entering", "yes") == "no")
  1137.         m_nSecurityCheck[SD_ENTERING_SECURE_SPACE] = FALSE;
  1138.     if(GetProfileString("Security", "Warn Leaving", "yes") == "no")
  1139.         m_nSecurityCheck[SD_LEAVING_SECURE_SPACE] = FALSE;
  1140.     if(GetProfileString("Security", "Warn Mixed", "yes") == "no")
  1141.         m_nSecurityCheck[SD_INSECURE_DOCS_WITHIN_SECURE_DOCS_NOT_SHOWN] = FALSE;
  1142.     if(GetProfileString("Security", "Warn Insecure Forms", "yes") == "no")
  1143.         m_nSecurityCheck[SD_INSECURE_POST_FROM_INSECURE_DOC] = FALSE;
  1144.  
  1145.  
  1146. #ifdef EDITOR
  1147.     // Initialize any global data etc. needed by composer
  1148.     // (Implemented in EDFRAME.CPP)
  1149.     WFE_InitComposer();
  1150. #endif
  1151.  
  1152.     /////////////////////////////////////////////////////////////////////
  1153.     // Protocol Whining Preferences
  1154.     prefBool=TRUE;
  1155.     PREF_GetBoolPref("security.submit_email_forms",&prefBool);
  1156.     NET_WarnOnMailtoPost((PRBool)prefBool);
  1157.  
  1158.     m_pTelnet = "";
  1159.     m_pTn3270 = "";
  1160.     m_pHTML = "";
  1161.  
  1162.     //
  1163.     // Initialize message stuff...
  1164.     //
  1165. #ifdef MOZ_MAIL_NEWS
  1166.     WFE_MSGInit();
  1167. #endif /* MOZ_MAIL_NEWS */   
  1168.  
  1169.   // rhp - Added flag for MAPI startup...
  1170.     if (showSplashScreen(csPrintCommand)) {
  1171.         strStatus.LoadString(IDS_LOAD_BOOKMARKS);
  1172.         m_splash.DisplayStatus(strStatus);
  1173.     }
  1174.  
  1175. // RDF INITIALIZATION (BEGINS HERE)
  1176.     CString profileDirURL;
  1177.     WFE_ConvertFile2Url(profileDirURL, theApp.m_UserDirectory);
  1178.     profileDirURL = profileDirURL + "/";
  1179.     CString encodedDir;
  1180.     encodedDir = WFE_EscapeURL(profileDirURL);
  1181.  
  1182.     RDF_InitParamsStruct initStruct;
  1183.     initStruct.profileURL = (char *)(const char*)(encodedDir);
  1184.     
  1185.     //m_RDFStdResources = RDF_StdVocab();
  1186.  
  1187.     m_bInInitInstance = FALSE;
  1188.  
  1189.     msg = m_UserDirectory + "\\bookmark.htm";
  1190.     PREF_SetDefaultCharPref("browser.bookmark_location",msg);
  1191.  
  1192.     CString bookmarkFile;
  1193.     prefStr = NULL;
  1194.     PREF_CopyCharPref("browser.bookmark_location",&prefStr);
  1195.     bookmarkFile = prefStr;
  1196.     if (prefStr) XP_FREE(prefStr);
  1197.         
  1198.     CString urlHistory = profileDirURL + "mozilla.hst"; 
  1199.  
  1200.     // Encode the bookmarks
  1201.     CString urlBookmark;
  1202.     WFE_ConvertFile2Url(urlBookmark, bookmarkFile);
  1203.     CString encodedBookmark = WFE_EscapeURL(urlBookmark);
  1204.  
  1205.     initStruct.bookmarksURL = (char*)(const char*)encodedBookmark;
  1206.     initStruct.globalHistoryURL = (char*)(const char*)urlHistory;
  1207.  
  1208.     RDF_Init(&initStruct);    // TODO: Can this fail? Want to bail if so.
  1209.     
  1210.  
  1211. // RDF INITIALIZATION ENDS HERE
  1212.  
  1213.     m_bInInitInstance = FALSE;
  1214.  
  1215.     // read in bookmark location
  1216. //    msg = m_pInstallDir->GetCharValue();
  1217.     
  1218.     prefStr = NULL;
  1219.     PREF_CopyCharPref("browser.bookmark_location",&prefStr);
  1220.     m_pBookmarkFile = prefStr;
  1221.  
  1222.     if (prefStr) XP_FREE(prefStr);
  1223.     PREF_RegisterCallback("browser.bookmark_location",WinFEPrefChangedFunc,NULL);
  1224.  
  1225.     if(_access(m_pBookmarkFile,0)==-1) {
  1226.         PREF_SetCharPref("browser.bookmark_location",msg);
  1227.     }
  1228.  
  1229.  
  1230.     // Get LDAP servers filename
  1231. #ifdef MOZ_LDAP
  1232.     msg = m_UserDirectory;
  1233.     msg += "\\ldapsrvr.txt";
  1234.     PREF_SetDefaultCharPref("browser.ldapfile_location",msg);
  1235.  
  1236.     char * ldapFile = NULL;
  1237.     PREF_CopyCharPref("browser.ldapfile_location",&ldapFile);
  1238.  
  1239.     // Initialize the directories and PAB
  1240. //      msg = m_UserDirectory;
  1241.     msg = "abook.nab";
  1242.     PREF_SetDefaultCharPref("browser.addressbook_location",msg);
  1243.  
  1244.     CFileException e;
  1245.     CStdioFile serversFile;
  1246.     if (serversFile.Open(ldapFile,
  1247.                 CFile::modeRead | CFile::typeText, &e) &&
  1248.         serversFile.GetLength())
  1249.     {
  1250.         char text[1024], temp[256];
  1251.         int pos = 0;
  1252.         int line = 0;
  1253.         m_directories = XP_ListNew();
  1254.         while (serversFile.ReadString(text, 1023) != NULL)
  1255.         {
  1256.             DIR_Server* dir = (DIR_Server *) XP_ALLOC(sizeof(DIR_Server));  // alloc new struct
  1257.             if (dir)
  1258.             {
  1259.                 DIR_InitServer(dir);
  1260.                 if (line)
  1261.                     dir->dirType = LDAPDirectory;   /* required                                                     */
  1262.                 else
  1263.                 {
  1264.                     dir->dirType = PABDirectory;    /* required                                                     */
  1265.                     dir->fileName = XP_STRDUP(msg);
  1266.                 }
  1267.                 line += 1;
  1268.                 int pos = 0;
  1269.                 int tempPos = 0;
  1270.                 int total = 0;
  1271.                 int type = 0;
  1272.                 while (text[pos] != '\0')
  1273.                 {
  1274.                     while (text[pos] != '\t' && text[pos] != '\0')
  1275.                     {
  1276.                         temp[tempPos++] = text[pos++];
  1277.                     }
  1278.                     temp[tempPos] = '\0';
  1279.                     switch (type++)
  1280.                     {
  1281.                     case 0:
  1282.                         dir->description =  XP_STRDUP(temp);
  1283.                         break;
  1284.                     case 1:
  1285.                         dir->serverName =  XP_STRDUP(temp);
  1286.                         break;
  1287.                     case 2:
  1288.                         dir->searchBase =  XP_STRDUP(temp);
  1289.                         break;
  1290.                     case 3:
  1291.                         dir->port = atoi(temp);
  1292.                         break;
  1293.                     case 4:
  1294.                         dir->maxHits =  atoi(temp);
  1295.                         break;
  1296.                     case 5:
  1297.                         dir->isSecure =  atoi(temp);
  1298.                         break;
  1299.                     case 6:
  1300.                         dir->savePassword =  atoi(temp);
  1301.                         break;
  1302.                     default:
  1303.                         break;
  1304.                     }
  1305.                     tempPos = 0;
  1306.                     if (text[pos] == '\t')
  1307.                         pos++;
  1308.  
  1309.                 }
  1310.  
  1311.                 if (dir->dirType == LDAPDirectory)
  1312.                     dir->fileName = WH_FileName (dir->serverName, xpAddrBook);
  1313.  
  1314.                 XP_ListAddObjectToEnd(m_directories, dir);
  1315.             }
  1316.         }
  1317.         serversFile.Close();
  1318.         if (DIR_SaveServerPreferences (m_directories) != -1)
  1319.             CFile::Remove( ldapFile );
  1320.     }
  1321.     else
  1322.     {
  1323.         DIR_GetServerPreferences (&m_directories, msg);
  1324.         char * ldapPref = PR_smprintf("ldap_%d.end_of_directories", kCurrentListVersion);
  1325.         if (ldapPref)
  1326.             PREF_RegisterCallback(ldapPref, DirServerListChanged, NULL);
  1327.         XP_FREEIF (ldapPref);
  1328.     }
  1329.     if (ldapFile) XP_FREE(ldapFile);
  1330.  
  1331.     DIR_Server* pab = NULL;
  1332.  
  1333.     DIR_GetPersonalAddressBook (theApp.m_directories, &pab);
  1334.     XP_ASSERT (pab);
  1335.  
  1336.     msg = m_UserDirectory;
  1337.     msg += "\\address.htm";
  1338.     AB_InitializeAddressBook(pab, &m_pABook, (const char *) msg);
  1339. #endif /* MOZ_LDAP */
  1340.  
  1341.     //  Initialize slave URL loading context.
  1342.     //  Use HTML help IDs, per legacy slave context code
  1343.     //      in olehelp.cpp
  1344.     m_pSlaveCX = new CStubsCX(::HtmlHelp, MWContextHTMLHelp);
  1345.  
  1346. #ifdef MOZ_MAIL_NEWS
  1347.     // Initialize the address book context
  1348.     CStubsCX *pCx = new CAddrCX();
  1349.     m_pAddressContext = pCx->GetContext();
  1350. #endif /* MOZ_MAIL_NEWS */
  1351.  
  1352.   // rhp - Added flags for MAPI startup...
  1353.     if (showSplashScreen(csPrintCommand)) {
  1354.         strStatus.LoadString(IDS_LOAD_PLUGINS);
  1355.         m_splash.DisplayStatus(strStatus);
  1356.     }
  1357.  
  1358.     STARTUP_np();
  1359.  
  1360.     // if PE mode, start up java too!
  1361. #ifdef JAVA
  1362.     if (m_bAccountSetupStartupJava) {
  1363.  
  1364.     // rhp - Added flags for MAPI startup...
  1365.     if (showSplashScreen(csPrintCommand)) {
  1366.             strStatus.LoadString(IDS_LOAD_JAVA);
  1367.             m_splash.DisplayStatus(strStatus);
  1368.         }
  1369.  
  1370.         WFE_LJ_StartupJava();   // stub call because java.h can't be included here
  1371.  
  1372.     }
  1373. #endif
  1374.  
  1375.     //  right before we take down the splash screen, do our OLE startup notifications.
  1376.     COleRegistry::Startup();
  1377.  
  1378.     //CLM: Placed here as done in AKBAR
  1379.     // now that we are done with everything, kill the splash
  1380.     // rhp - Added flag for MAPI startup...
  1381.     if (showSplashScreen(csPrintCommand)) {
  1382.         // only show splash if not embedded
  1383.         m_splash.NavDoneIniting();
  1384.     }
  1385.  
  1386. #ifdef JAVA
  1387.     // if PE mode, check if java environment is valid
  1388.     if (m_bAccountSetupStartupJava) {
  1389.  
  1390.     JRIEnv * ee = JRI_GetCurrentEnv();
  1391.  
  1392.     if (ee == NULL)  {
  1393.  
  1394.             CString szJavaStartupErr = "You are starting up an application that needs java.\nPlease turn on java in your navigator's preference and try again.";
  1395.             AfxMessageBox(szJavaStartupErr, MB_OK);
  1396.  
  1397.             m_bAccountSetupStartupJava = FALSE;
  1398.  
  1399.             return FALSE;
  1400.         }
  1401.  
  1402.         m_bAccountSetupStartupJava = FALSE;
  1403.     }
  1404. #endif
  1405.     // Its now safe to create the frame objects and start this whole thang
  1406.     //      only if we're not automated.
  1407.     //
  1408.     //
  1409.     /// For adding of AddressBook frame to frame list.non private version.
  1410.     void    WFE_AddNewFrameToFrameList(CGenericFrame * pFrame);
  1411.  
  1412.     //Please make sure this code stays before the startupMode stuff so that
  1413.     //we can process the StartMode commands in AltMail mode
  1414.     prefBool = FALSE;
  1415.     PREF_GetBoolPref("mail.use_altmail",&prefBool);
  1416.     if(prefBool)
  1417.     FEU_OpenMapiLibrary();
  1418.  
  1419.     if(m_bAutomated == FALSE && m_bEmbedded == FALSE  && csPrintCommand.IsEmpty())
  1420.     {
  1421.         int iStartupMode=0;
  1422.         BOOL bStartMode = FALSE;
  1423.  
  1424.         PREF_GetBoolPref("general.startup.browser", &bStartMode);
  1425.         if (bStartMode)
  1426.             iStartupMode |= STARTUP_BROWSER;
  1427.  
  1428.         PREF_GetBoolPref("general.startup.mail", &bStartMode);
  1429.         if (bStartMode)
  1430.             iStartupMode |= STARTUP_MAIL;
  1431.  
  1432.         PREF_GetBoolPref("general.startup.news", &bStartMode);
  1433.         if (bStartMode)
  1434.             iStartupMode |= STARTUP_NEWS;
  1435.  
  1436.         PREF_GetBoolPref("general.startup.editor", &bStartMode);
  1437.         if (bStartMode)
  1438.             iStartupMode |= STARTUP_EDITOR;
  1439.  
  1440.         PREF_GetBoolPref("general.startup.netcaster", &bStartMode);
  1441.         if (bStartMode)
  1442.             iStartupMode |= STARTUP_NETCASTER;
  1443.  
  1444.         PREF_GetBoolPref("general.startup.calendar", &bStartMode);
  1445.         if (bStartMode)
  1446.             iStartupMode |= STARTUP_CALENDAR;
  1447.  
  1448.         PREF_GetBoolPref("general.startup.conference", &bStartMode);
  1449.         if (bStartMode)
  1450.             iStartupMode |= STARTUP_CONFERENCE;
  1451.  
  1452.         //over ride prefference settings on iStartupMode if necessary
  1453.         SetStartupMode(&iStartupMode);
  1454.  
  1455.         //Last chance to make sure at least the browser is launched if nothing else
  1456.         //was set either in preferences or on the command line.
  1457.         //--- Added STARTUP_ACCOUNT_SETUP here because we want browser in main window and error in DDE
  1458.         if (iStartupMode == 0 || iStartupMode == STARTUP_ACCOUNT_SETUP)
  1459.             iStartupMode |= STARTUP_BROWSER;
  1460.  
  1461.     void OpenDraftExit (URL_Struct *url_struct, int/*status*/,MWContext *pContext);
  1462.  
  1463.     if (!m_bKioskMode)
  1464.         {
  1465.  
  1466.             // So, instead of adding to the nightmarish way of launching components
  1467.             // below, Netcaster will look for the set bit BEFORE the switch statement,
  1468.             // launch itself, then remove the bit.  In an absurd kind of way, this seems
  1469.             // cleaner than adding a boatload of new #defines to support a fifth module.
  1470.             if (iStartupMode & STARTUP_NETCASTER && FE_IsNetcasterInstalled()) {
  1471.                 FEU_OpenNetcaster() ;
  1472.                 (iStartupMode &= (~STARTUP_NETCASTER)) ;
  1473.             }
  1474.  
  1475.             if (iStartupMode & STARTUP_CALENDAR) {
  1476.                 CString installDirectory, executable;
  1477. #ifdef WIN32
  1478.                 CString calRegistry;
  1479.  
  1480.                 calRegistry.LoadString(IDS_CALENDAR_REGISTRY);
  1481.  
  1482.                 calRegistry = FEU_GetCurrentRegistry(calRegistry);
  1483.                 if(!calRegistry.IsEmpty())
  1484.                 {
  1485.  
  1486.                   installDirectory = FEU_GetInstallationDirectory(calRegistry, szLoadString(IDS_INSTALL_DIRECTORY));
  1487.                   executable = szLoadString(IDS_CALENDAR32EXE);
  1488. #else ifdef XP_WIN16
  1489.                   installDirectory = FEU_GetInstallationDirectory(szLoadString(IDS_CALENDAR),szLoadString(IDS_INSTALL_DIRECTORY));
  1490.                   executable = szLoadString(IDS_CALENDAR16EXE);
  1491. #endif
  1492.                   if(!installDirectory.IsEmpty())
  1493.                   {
  1494.                     executable = installDirectory + executable;
  1495.  
  1496.                     WinExec(executable, SW_SHOW);
  1497.                    
  1498.                   }
  1499. #ifdef WIN32               
  1500.                 }
  1501. #endif
  1502.                 
  1503.                 (iStartupMode &= (~STARTUP_CALENDAR)) ;
  1504.             }
  1505.  
  1506.             if (iStartupMode & STARTUP_CONFERENCE) {
  1507.                 CString installDirectory, executable;
  1508.  
  1509. #ifdef WIN32
  1510.                 installDirectory = FEU_GetInstallationDirectory(szLoadString(IDS_CONFERENCE_REGISTRY), szLoadString(IDS_PATHNAME));
  1511.                 executable = "\\nsconf32.exe -b";
  1512. #else ifdef XP_WIN16
  1513.                 installDirectory = FEU_GetInstallationDirectory(szLoadString(IDS_CONFERENCE),szLoadString(IDS_INSTALL_DIRECTORY));
  1514.                 executable = "\\nsconf16.exe -b";
  1515. #endif
  1516.  
  1517.                 if(!installDirectory.IsEmpty())
  1518.                 {
  1519.                     executable = installDirectory + executable;
  1520.  
  1521.                     WinExec(executable, SW_SHOW);
  1522.                 }
  1523.                 (iStartupMode &= (~STARTUP_CONFERENCE)) ;
  1524.             }
  1525.  
  1526.             //command line component launch
  1527.             switch(iStartupMode)
  1528.             {
  1529.                 case STARTUP_NETHELP: {
  1530.                     //  Have NetHelp handle the request.
  1531.                     ASSERT(m_CmdLineLoadURL);  // Okay, who messed with it?
  1532.                     if(m_pSlaveCX) {
  1533.                         m_pSlaveCX->NormalGetUrl(m_CmdLineLoadURL);
  1534.                     }
  1535.                     
  1536.                     //  Get rid of the URL.
  1537.                     XP_FREE(m_CmdLineLoadURL);
  1538.                     m_CmdLineLoadURL = NULL;
  1539.                     break;
  1540.                 }
  1541. #ifdef MOZ_MAIL_NEWS
  1542.                 case STARTUP_INBOX:
  1543.                     WFE_MSGOpenInbox();     //opens the inbox folder with the split pain view.
  1544.                     break;
  1545.  
  1546.         case STARTUP_CLIENT_MAPI:  // rhp - for MAPI Startup
  1547.           {
  1548.             CGenericDoc *pDoc = (CGenericDoc *)theApp.m_ViewTmplate->OpenDocumentFile(NULL, FALSE);
  1549.             if (pDoc)
  1550.             {
  1551.               CFrameGlue *pFrame = (pDoc->GetContext())->GetFrame();
  1552.                   if(pFrame)
  1553.               {
  1554.                       CFrameWnd *pFrameWnd = pFrame->GetFrameWnd();
  1555.                 if (pFrameWnd)
  1556.                 {
  1557.                   extern void StoreMAPIFrameWnd(CFrameWnd *pFrameWnd);
  1558.  
  1559.                   pFrameWnd->ShowWindow(SW_SHOWMINIMIZED);
  1560.                   StoreMAPIFrameWnd(pFrameWnd);
  1561.                 }
  1562.               } 
  1563.             }
  1564.           }   
  1565.           // rhp - for MAPI startup...
  1566.           break;
  1567.  
  1568.                 case STARTUP_FOLDER:
  1569.                     WFE_MSGOpenInbox();     
  1570.                     break;
  1571.  
  1572.                 case STARTUP_MAIL:
  1573.                     WFE_MSGOpenInbox();     //opens the inbox folder with the split pain view.
  1574.                     //tell the browser to open commandline URL even though MAIL is set in preferences
  1575.                     if(m_CmdLineLoadURL != NULL)
  1576.                         iStartupMode |= STARTUP_BROWSER;
  1577.                     break;
  1578.  
  1579.                 case STARTUP_FOLDERS:
  1580.                     WFE_MSGOpenFolders();           //opens the collections window
  1581.                     break;
  1582.  
  1583.                 case STARTUP_COMPOSE:
  1584.                     if(!lstrArgumentList.GetCount())
  1585.                         MSG_Mail(m_pBmContext); // starts the mail composition window.
  1586.                     else
  1587.                     {       //handle any extra arguments for this flag here.
  1588.                         char *pTemp;
  1589.                         URL_Struct* pURL;
  1590.                         CString strUrl;
  1591.  
  1592.                         int nArgCount = lstrArgumentList.GetCount();
  1593.                         if (nArgCount == 1)
  1594.             {//either a message or an attachment.  If it's an attachment it 
  1595.              //will be prefixed with an "@" symbol
  1596.                             pTemp  = (char*) (const char*)lstrArgumentList.GetHead();
  1597.                 //decide whether it's a message or an attachment
  1598.                 if(*pTemp != '@' && *pTemp != '-') 
  1599.                 {   //it's a message
  1600.                                 CFileStatus rStatus;
  1601.                         if(CFile::GetStatus(pTemp,rStatus))
  1602.                                 {
  1603.                             WFE_ConvertFile2Url(strUrl, pTemp);
  1604.                                     pURL = NET_CreateURLStruct(strUrl, NET_DONT_RELOAD);
  1605.                     StrAllocCopy(pURL->content_type,"message/rfc822");
  1606.                                     NET_GetURL (pURL, FO_OPEN_DRAFT, m_pBmContext,
  1607.                                     OpenDraftExit);
  1608.                                     //Load it into the compose window
  1609.                                 }
  1610.                                 else
  1611.                                 {
  1612.                                     AfxMessageBox(IDS_CMDLINE_ERROR1);
  1613.                                     MSG_Mail(m_pBmContext);
  1614.                     //were just going to act as if we couldn't read what they gave us and continue
  1615.                                 }
  1616.                             }
  1617.                             else
  1618.                 {//it's an attachment
  1619.                                 pTemp += 1;
  1620.                                 CFileStatus rStatus;
  1621.                         if(CFile::GetStatus(pTemp,rStatus))
  1622.                                 {
  1623.                                     if (!LaunchComposeAndAttach(lstrArgumentList))
  1624.                                     {
  1625.                                         AfxMessageBox(IDS_CMDLINE_ERROR3);
  1626.                                         MSG_Mail(m_pBmContext);
  1627.                                     }
  1628.                             //Load it into the compose window
  1629.                                 }
  1630.                                 else
  1631.                                 {
  1632.                                     AfxMessageBox(IDS_CMDLINE_ERROR1);
  1633.                                     MSG_Mail(m_pBmContext);
  1634.                                 }
  1635.                             }
  1636.                         }
  1637.                         else
  1638.                         {
  1639.                             if (nArgCount == 2)
  1640.                             {
  1641.                 //it's a message and has an attachment(s)
  1642.                                 if (!LaunchComposeAndAttach(lstrArgumentList))
  1643.                                 {
  1644.                                     AfxMessageBox(IDS_CMDLINE_ERROR3);
  1645.                                     MSG_Mail(m_pBmContext);
  1646.                                 }
  1647.                                 else
  1648.                                 {   //command line is not in a recognizable format for this flag
  1649.                                     AfxMessageBox(IDS_CMDLINE_ERROR3);
  1650.                                     MSG_Mail(m_pBmContext);
  1651.                                     //ERROR!!!
  1652.                                 }
  1653.                             }
  1654.                         }
  1655.                     }//End -COMPOSE CASE                 
  1656.                     break;
  1657.  
  1658.                 case STARTUP_ADDRESS:
  1659.                     CAddrFrame::Open();
  1660.                     break;
  1661.  
  1662.            case STARTUP_IMPORT:
  1663.            ImportExportLDIF(m_pABook, m_CmdLineLoadURL, iStartupMode);
  1664.            return FALSE;
  1665.  
  1666.            case STARTUP_EXPORT:
  1667.            ImportExportLDIF (m_pABook, m_CmdLineLoadURL, iStartupMode);
  1668.            return FALSE;
  1669.            
  1670.  
  1671.                 case STARTUP_NEWS:
  1672.                     WFE_MSGOpenNews();      //starts the news and opens the default news server and group in split pain.
  1673.                     //tell the browser to open commandline URL even though NEWS is set in preferences
  1674.                     if(m_CmdLineLoadURL != NULL)
  1675.                         iStartupMode |= STARTUP_BROWSER;
  1676.                     break;
  1677.  
  1678.  
  1679.                 case STARTUP_MAIL_NEWS:
  1680.                     //We get here because of preferences and nothing but a file or no file was given on the command
  1681.                     //line.
  1682.                     WFE_MSGOpenInbox();     //opens the inbox folder with the split pain view.
  1683.                     WFE_MSGOpenNews();              //opens the collections window
  1684.                     //tell the browser to open commandline URL even though MAIL & NEWS are  set in preferences
  1685.                     if(m_CmdLineLoadURL != NULL)
  1686.                         iStartupMode |= STARTUP_BROWSER;
  1687.                     break;
  1688.  
  1689.                 case STARTUP_MAIL_NEWS_BROWSER:
  1690.                 //all three check boxes were set in preferences
  1691.                     WFE_MSGOpenInbox();     //opens the inbox folder with the split pain view.
  1692.                     WFE_MSGOpenNews();              //opens the collections window
  1693.                     //browser will get launched in the code below.
  1694.                     break;
  1695.  
  1696.                 case STARTUP_MAIL_BROWSER:
  1697.                     //mail and browser check boxes were checked
  1698.                 WFE_MSGOpenInbox(); //starts the inbox window.
  1699.                     //browser will get launched in the code below
  1700.                     break;
  1701.  
  1702.                 case STARTUP_NEWS_BROWSER:
  1703.                     //browser and news check boxes were checked
  1704.                 WFE_MSGOpenNews();  //opens the collections window
  1705.                     //browser will get launched in the code below.
  1706.                     break;
  1707.  
  1708.                 case STARTUP_BROWSER_EDITOR:
  1709.                     //Code will get called below. for both browser and editor
  1710.                     break;
  1711.  
  1712.                 case STARTUP_MAIL_EDITOR:
  1713.                     //mail and editor check boxes were checked
  1714.                 WFE_MSGOpenInbox(); //starts the inbox window.
  1715.                     //browser will get launched in the code below
  1716.                     //editor is launched in code below
  1717.                     break;
  1718.  
  1719.             case STARTUP_NEWS_EDITOR:
  1720.                 WFE_MSGOpenNews();  //opens the collections window
  1721.                     break;              //editor will get launched in the code below.
  1722.                                 //editor is launched in code below                  
  1723.                         /*
  1724.             case STARTUP_NETCASTER:
  1725.                 FEU_OpenNetcaster() ;
  1726.                         break;
  1727.                         */
  1728.  
  1729.             case STARTUP_MAIL_NEWS_EDITOR:
  1730.                     WFE_MSGOpenInbox();     //opens the inbox folder with the split pain view.
  1731.                     WFE_MSGOpenNews();      //opens the collections window
  1732.                     //tell the browser to open URL even though it wasn't set in preferences
  1733.                     if(m_CmdLineLoadURL != NULL)
  1734.                         iStartupMode |= STARTUP_BROWSER;
  1735.                     break;
  1736.  
  1737.             case STARTUP_MAIL_BROWSER_EDITOR:
  1738.                 WFE_MSGOpenInbox(); //starts the inbox window.
  1739.                      break;             //browser will get launched in the code below
  1740.                     
  1741.             case STARTUP_NEWS_BROWSER_EDITOR:
  1742.                 WFE_MSGOpenNews();  //opens the collections window
  1743.                     break;              //The rest is started below
  1744.                     
  1745.             case STARTUP_MAIL_NEWS_BROWSER_EDITOR:
  1746.                     WFE_MSGOpenInbox();     //opens the inbox folder with the split pain view.
  1747.                     WFE_MSGOpenNews();      //opens the collections window
  1748.                     break;              //tell the browser to open commandline URL even though MAIL & NEWS are      set in preferences
  1749.                 
  1750. #endif /* MOZ_MAIL_NEWS */
  1751.  
  1752. #ifdef JAVA
  1753.         case STARTUP_JAVA_DEBUG_AGENT:
  1754.                     WFE_LJ_StartDebugger();         // stub call because java.h can't be included here
  1755.                     break;
  1756. #endif  
  1757.                 //default:
  1758.             }
  1759.         }
  1760.  
  1761.         //fall through here and launch browser if necessary
  1762.     if ((iStartupMode & STARTUP_BROWSER || iStartupMode & STARTUP_EDITOR || // if startup browser or editor
  1763.         !(iStartupMode & (STARTUP_BROWSER|STARTUP_NEWS|STARTUP_MAIL|STARTUP_ADDRESS
  1764.             |STARTUP_INBOX|STARTUP_COMPOSE|STARTUP_FOLDER|STARTUP_FOLDERS|STARTUP_NETCASTER)) ||    // or invalid data
  1765.         m_bKioskMode ))  {                                                  // or kiosk mode - start browser
  1766. #ifdef EDITOR
  1767.         if ( (bIsGold && (iStartupMode & STARTUP_EDITOR)) && !(iStartupMode & STARTUP_BROWSER))
  1768.             {   //start the editor
  1769.         theApp.m_EditTmplate->OpenDocumentFile(NULL);
  1770.                 CMainFrame *pMainFrame = (CMainFrame *)FEU_GetLastActiveFrame(MWContextBrowser, TRUE);
  1771.                 if(pMainFrame) pMainFrame->OnLoadHomePage();//suppose to load what ever was on the command line
  1772.         }
  1773.             else
  1774. #endif // EDITOR
  1775.             if ((iStartupMode & STARTUP_BROWSER) && !(iStartupMode & STARTUP_EDITOR) )
  1776.             {       //start the browser
  1777.             theApp.m_ViewTmplate->OpenDocumentFile(NULL);
  1778.                     CMainFrame *pMainFrame = (CMainFrame *)FEU_GetLastActiveFrame(MWContextBrowser, FALSE);
  1779.                 if(pMainFrame) pMainFrame->OnLoadHomePage(); //suppose to load what ever was on the command line
  1780.         }
  1781. #ifdef EDITOR
  1782.             else if ((iStartupMode & STARTUP_BROWSER) && (iStartupMode & STARTUP_EDITOR) )
  1783.             {
  1784.                     //start both of these guys since there preferences were set 
  1785.                 //theApp.m_EditTmplate->OpenDocumentFile(NULL);                             
  1786.             theApp.m_ViewTmplate->OpenDocumentFile(NULL);  //open browser window
  1787.                     CGenericFrame *pFrame = (CGenericFrame *)FEU_GetLastActiveFrame(MWContextBrowser, FALSE);
  1788.                     if (pFrame){
  1789.                         CMainFrame *pMainFrame = (CMainFrame*)pFrame;
  1790.                         pMainFrame->OnLoadHomePage();
  1791.                         pFrame->OnOpenComposerWindow();
  1792.                     }
  1793.             }
  1794. #endif // EDITOR
  1795.     }
  1796.  
  1797.         if(m_pFrameList && m_pFrameList->GetMainContext())
  1798.         {
  1799.         NET_CheckForTimeBomb(m_pFrameList->GetMainContext()->GetContext());
  1800.         }
  1801.  
  1802.     }
  1803.  
  1804.     //--------------------------------------------------------------------
  1805.     //                           IMPORTANT
  1806.     //                           =========
  1807.     // The user's homepage could have already been loaded.  Any init code
  1808.     //   below this line better not be needed for page loading
  1809.     //--------------------------------------------------------------------
  1810.  
  1811. #ifdef MOZ_TASKBAR
  1812.     // Start the Task Bar up - this must be done AFTER all frame windows
  1813.     // are created. Get the state flags and last saved position from
  1814.     // the registry.
  1815.     ASSERT(!m_TaskBarMgr.IsInitialized());
  1816.     m_TaskBarMgr.LoadPrefs(m_bAlwaysDockTaskBar);
  1817. #endif /* MOZ_TASKBAR */  
  1818.  
  1819.     //  DDE is hosed on Windows95 October 94 release.  Allow the user to turn it off
  1820.     //      This should be the very last thing done in initinstance, always.
  1821.     if(GetProfileString("Main", "DDE Hosed", "no") == "no")     {
  1822.     extern void DDEStartup(void);
  1823.     DDEStartup();
  1824.     }
  1825.  
  1826.     // read in the page setup information
  1827.     LoadPageSetupOptions();
  1828.  
  1829.     //  Start any timeout events.
  1830.     FEU_GlobalHistoryTimeout((void *)1);
  1831.  
  1832.     //  Leave this as the very last thing to do.
  1833.     //  If we've a print command to exectute, do it now.
  1834.     if(csPrintCommand.IsEmpty() == FALSE)   {
  1835.     OnDDECommand((char *)(const char *)("/print" + csPrintCommand));
  1836.     }
  1837.  
  1838.     //  Only do the below when we think we're really ready to exit InitInstance successfully.
  1839.     //  Previously, these were way up towards the top of initinstance, but have been
  1840.     //      put here as they cause wild effects with Inserting an OLE object while
  1841.     //      not currently running under win32.
  1842.  
  1843.         //  Connect the COleTemplateServer to the view document template.
  1844.         //  The COleTemplateServer creates new documents on the behalf of
  1845.         //          requestion OLE containers by using information specified in the
  1846.         //          document template.
  1847.         m_OleTemplateServer.ConnectTemplate(clsid, pTemplate, FALSE);
  1848.  
  1849.         //  Register all OLE server (factories) as running.
  1850.     //  Also set up for shell open through DDE
  1851.         //  This enables the OLE libraries to create objects from other apps.
  1852.         //  Do not change the calling order here, please, or you may break OLE.
  1853.     COleTemplateServer::RegisterAll();
  1854.     EnableShellOpen();
  1855.     RegisterShellFileTypes();
  1856.  
  1857.     //  Always set that we are an in place server.
  1858.     COleObjectFactory::UpdateRegistryAll();
  1859.     //  This get's in the way of debugging under nt351 with service pack 4 installed, just don't do it....
  1860.     m_OleTemplateServer.UpdateRegistry(OAT_INPLACE_SERVER);
  1861.     return TRUE;
  1862. }
  1863.  
  1864. /////////////////////////////////////////////////////////////////////////////
  1865. // Cleanup our toys and go home
  1866.  
  1867. int CNetscapeApp::ExitInstance()
  1868. {
  1869.     //    When receiving a WM_ENDSESSION, ExitInstance may be entered twice.
  1870.     //    Block the code on the second or more attempts.
  1871.     //    The exact nature happens because the OnIdle code in the app detects
  1872.     //        a lack of all contexts and sends a redundant close message to
  1873.     //      the application's hidden frame, even though this is already
  1874.     //        done by the hidden frame (m_pMainWnd) when it receives the 
  1875.     //      WM_ENDSESSION message.
  1876.  
  1877.     static int iExitCounter = -1;
  1878.     iExitCounter++;
  1879.     if(iExitCounter != 0)   {
  1880.         TRACE("Blocking %d reduntant call(s) to CNetscapeApp::ExitInstance.\n", iExitCounter);
  1881.         return(0);
  1882.     }
  1883.     
  1884.     //unregister our DDE service and free the ServiceName Handle
  1885.     if(CDDECMDWrapper::m_dwidInst)
  1886.     {
  1887.         DdeNameService(CDDECMDWrapper::m_dwidInst,
  1888.             CDDECMDWrapper::m_hsz[CDDECMDWrapper::m_ServiceName], NULL,
  1889.             DNS_UNREGISTER);
  1890.         DdeFreeStringHandle(CDDECMDWrapper::m_dwidInst,
  1891.             CDDECMDWrapper::m_hsz[CDDECMDWrapper::m_ServiceName]);
  1892.     }
  1893.  
  1894.  
  1895.     //m_bExitStatus - Used to detect exit status from second instance.
  1896.     m_bExitStatus = TRUE;
  1897.  
  1898.     //  Tell the slave window that we are exiting.
  1899.     //  Anyone observing the event will deregister themselves.
  1900.     slavewnd.WindowProc(SLAVE_EXITINSTANCE, 0, 0);
  1901.  
  1902.     TRACE("CNetscapeApp::ExitInstance entered\n");
  1903.  
  1904.     if (!m_strStubFile.IsEmpty())
  1905.         remove(m_strStubFile);
  1906.  
  1907. #ifdef MOZ_TASKBAR
  1908.     // Save Task Bar state
  1909.     m_TaskBarMgr.SavePrefs();
  1910. #endif /* MOZ_TASKBAR */
  1911.  
  1912.     WFE_DestroyUIPalette();
  1913.     WFE_DestroyBitmapMap();
  1914.     WFE_DestroyUIFont();
  1915.  
  1916. #ifdef EDITOR
  1917.     WFE_ExitComposer();
  1918. #endif // EDITOR
  1919.  
  1920. #ifdef XP_WIN32
  1921. #ifdef EDITOR
  1922.     // Tell Site Manager we are going away
  1923.     if ( pITalkSMClient != NULL ) {
  1924.     delete ( pITalkSMClient );
  1925. #if 0
  1926.     TALK_UnregisterApp();
  1927. #endif
  1928.     }
  1929. #endif // EDITOR
  1930. #endif // XP_WIN32
  1931.  
  1932.     // Shutdown RDF
  1933.     RDF_Shutdown();
  1934.  
  1935. #ifdef MOZ_LOC_INDEP
  1936.     SHUTDOWN_li();
  1937. #endif /* MOZ_LOC_INDEP */
  1938.     SHUTDOWN_np();
  1939.  
  1940.     //  Unload any remaining images.
  1941.     IL_Shutdown();
  1942.  
  1943.     // shut down exchange if enabled
  1944.     FEU_CloseMapiLibrary();
  1945.  
  1946.     //  Write out our list of trusted applications.
  1947.     if( m_pSpawn ) {
  1948.     delete m_pSpawn;
  1949.     }
  1950.  
  1951.     GH_SaveGlobalHistory();
  1952.     GH_FreeGlobalHistory();
  1953.  
  1954. #ifdef MOZ_MAIL_NEWS
  1955.     // write out newsrc stuff
  1956.     NET_SaveNewsrcFileMappings();
  1957. #endif /* MOZ_MAIL_NEWS */
  1958.  
  1959.     // cleanup intenal file type stuff
  1960.     fe_CleanupFileFormatTypes();
  1961.  
  1962.     PREF_SavePrefFile();
  1963.     char * prefName = WH_FileName(NULL, xpLIPrefs);
  1964.     PREF_SaveLIPrefFile(prefName);
  1965.     XP_FREEIF (prefName);
  1966.     NR_ShutdownRegistry();
  1967.  
  1968.     //  Save certs and keys early, since if they are lost the user is screwed
  1969.     SECNAV_Shutdown();
  1970.  
  1971.     //  Shut down mocha.
  1972.     ET_FinishMocha();
  1973.  
  1974.  
  1975.  
  1976.     BOOL javaShutdownSuccessful = fe_ShutdownJava();
  1977.  
  1978.     if(!m_pCacheDir.IsEmpty())
  1979.     NET_CleanupCacheDirectory((char *)(const char *)m_pCacheDir, CACHE_PREFIX);
  1980.     NET_ShutdownNetLib();
  1981.  
  1982. #ifdef MOZ_MAIL_NEWS
  1983.     if (m_pABook)
  1984.     AB_CloseAddressBook(&m_pABook);
  1985.     WFE_MSGShutdown();
  1986. #endif /* MOZ_MAIL_NEWS */
  1987.  
  1988. #ifdef MOZ_LDAP
  1989.     DIR_DeleteServerList(m_directories);
  1990. #endif /* MOZ_LDAP */
  1991.  
  1992.     PREF_Cleanup();
  1993.  
  1994.  
  1995.     POSITION pos;
  1996.     CString key;
  1997.     CDNSObj * obj;
  1998.  
  1999.     // Iterate through the entire map
  2000.     for( pos = DNSCacheMap.GetStartPosition(); pos != NULL; )
  2001.     {
  2002.     DNSCacheMap.GetNextAssoc( pos, key, (CObject *&)obj );
  2003.     if (obj) delete obj;
  2004.     }
  2005.  
  2006.     // delete cached memory CDCs
  2007.     if(pIconDC)
  2008.     delete pIconDC;
  2009.     if(pImageDC)
  2010.     delete pImageDC;
  2011.  
  2012.     // save the page setup options
  2013.     SavePageSetupOptions();
  2014.  
  2015.     // Resource cleanup
  2016.     if(m_CmdLineLoadURL)
  2017.     XP_FREE(m_CmdLineLoadURL);
  2018.  
  2019.     // Delete any temp files we have created
  2020.     FE_DeleteTempFilesNow();
  2021.  
  2022.  
  2023.     // Unload PE MUC dll
  2024.     if ((UINT)m_hPEInst > 32)
  2025.     FreeLibrary(m_hPEInst);
  2026.  
  2027.     // Unload resource dll
  2028.     if ((UINT)m_hResInst > 32)
  2029.     FreeLibrary(m_hResInst);
  2030.     // Free memory used for WideAPI(Unicode) conversion
  2031. #ifdef XP_WIN32
  2032.     if (theApp.m_bUseUnicodeFont && CIntlWin::m_wConvBuf)
  2033.     free(CIntlWin::m_wConvBuf);
  2034. #else
  2035.     Ctl3dUnregister(m_hInstance);
  2036. #endif
  2037.  
  2038.     SHUTDOWN_cvffc();
  2039.     //  Free off various allocated memory.
  2040.     if(XP_AppName)    {
  2041.     XP_FREE(XP_AppName);
  2042.     XP_AppName = NULL;
  2043.     }
  2044.     if(XP_AppCodeName)    {
  2045.     XP_FREE(XP_AppCodeName);
  2046.     XP_AppCodeName = NULL;
  2047.     }
  2048.     if(XP_AppVersion)    {
  2049.     XP_FREE(XP_AppVersion);
  2050.     XP_AppVersion = NULL;
  2051.     }
  2052.     if(XP_AppLanguage)    {
  2053.     XP_FREE(XP_AppLanguage);
  2054.     XP_AppLanguage = NULL;
  2055.     }
  2056.  
  2057.     //  Finally, do our OLE shutdown notifications.
  2058.     COleRegistry::Shutdown();
  2059.  
  2060.     // DDE is hosed on Windows95 October 94 release.  Allow the user to turn it off.
  2061.     //   If we never turned it on don't turn it off now.
  2062.     if(GetProfileString("Main", "DDE Hosed", "no") == "no")     {
  2063.     extern void DDEShutdown(void);
  2064.     DDEShutdown();
  2065.     }
  2066.  
  2067.     WSACleanup();
  2068.  
  2069.     // clean up the font cache here.
  2070.     XP_List *theList = m_appFontList;
  2071.     NsWinFont* theFont;
  2072.     int count = XP_ListCount(theList);
  2073.     for (int i = 0; i < count; i++) {
  2074.         theFont = (NsWinFont*)XP_ListRemoveTopObject (theList);
  2075.         ::DeleteObject(theFont->hFont);
  2076.         XP_DELETE( theFont);
  2077.     }
  2078.     XP_ListDestroy(theList);
  2079.  
  2080.     // Delete our custom images in NavCenter (Dave H.)
  2081.     CHTFEData::FlushIconInfo();
  2082.  
  2083.     //
  2084.     // Free all resources allocated by NSPR...
  2085.     //
  2086. #if !defined(_WIN32)
  2087. #if defined(JAVA) || defined(MOCHA)
  2088. #if defined(NSPR20)
  2089.     /*
  2090.      * XXX SHould PR_CLeanup be called here?
  2091.      *
  2092.      * In nspr10 PR_Shutdown unloads all the dlls
  2093.      * In nspr20 PR_shutdown is equivalent to the socket shutdown call
  2094.      *      and implict cleanup unloads the dlls for win16
  2095.      */    
  2096. #else
  2097.     PR_Shutdown();
  2098. #endif
  2099. #endif
  2100. #endif  /* JAVA || MOCHA */
  2101.  
  2102.     if (theApp.m_bNetworkProfile) {
  2103.         // if we have a network profile command-line we are assuming delete on exit (for now)
  2104.         CString pTempDir;
  2105.         int ret;
  2106.         XP_StatStruct statinfo; 
  2107.  
  2108.  
  2109.         if(getenv("TEMP"))
  2110.           pTempDir = getenv("TEMP");  // environmental variable
  2111.         if (pTempDir.IsEmpty() && getenv("TMP"))
  2112.           pTempDir = getenv("TMP");  // How about this environmental variable?
  2113.         if (pTempDir.IsEmpty()) {
  2114.               // Last resort: put it in the windows directory
  2115.           char path[_MAX_PATH];
  2116.           GetWindowsDirectory(path, sizeof(path));
  2117.           pTempDir = path;
  2118.         }
  2119.  
  2120.         pTempDir += "\\nstmpusr";        
  2121.         ret = _stat((char *)(const char *)pTempDir, &statinfo);
  2122.         if (ret == 0) {
  2123.             XP_RemoveDirectoryRecursive(pTempDir, xpURL);
  2124.         }
  2125.     }
  2126.  
  2127.     TRACE("CNetscapeApp::ExitInstance leaving\n");
  2128.  
  2129. #if defined( _DEBUG) && defined( XP_WIN32 )
  2130.     if (m_pi.hProcess) {
  2131.         TerminateProcess(m_pi.hProcess, 0);
  2132.         CloseHandle(m_pi.hProcess);
  2133.     }
  2134. #endif
  2135.  
  2136.     return(CWinApp::ExitInstance());
  2137. }
  2138.