home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / winfe / logindg.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  66.3 KB  |  2,308 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. // LoginDlg.cpp : implementation file
  20. //
  21.  
  22. #include "stdafx.h"
  23. #include "LoginDg.h" 
  24. #include "prefapi.h"
  25. #include "hk_funcs.h"
  26. #include "setupwiz.h"
  27. #include "mucwiz.h"
  28. #include "mucproc.h"
  29. #include "profile.h"
  30. #include "dialog.h"
  31. #include "helper.h"
  32. #ifdef MOZ_LOC_INDEP
  33. #include "winli.h"
  34. #endif /* MOZ_LOC_INDEP */
  35.  
  36.  
  37. #ifdef XP_WIN16
  38. #include "winfile.h"
  39. #endif
  40.  
  41. #ifdef _DEBUG
  42. #define new DEBUG_NEW
  43. #undef THIS_FILE
  44. static char THIS_FILE[] = __FILE__;
  45. #endif
  46.  
  47. int login_SetUserKeyData(const char *profileName);
  48.  
  49. /////////////////////////////////////////////////////////////////////
  50. // CLoginList
  51.  
  52. class CLoginList: public CListBox {
  53. private:
  54.     int m_iPosIndex, m_iPosName, m_iPosStatus;
  55.  
  56. protected:
  57.     virtual void DrawItem( LPDRAWITEMSTRUCT lpDrawItemStruct );
  58.  
  59.     afx_msg void OnLButtonDown( UINT nFlags, CPoint point ); 
  60.     afx_msg void OnLButtonDblClk( UINT nFlags, CPoint point );
  61.     virtual void MeasureItem( LPMEASUREITEMSTRUCT lpMeasureItemStruct );
  62.  
  63.     DECLARE_MESSAGE_MAP()
  64.  
  65. public:
  66.     CLoginList();
  67.     ~CLoginList();
  68.  
  69.     void SetColumnPositions(int, int, int);
  70. };
  71. /////////////////////////////////////////////////////////////////////////////
  72. // CLoginDlg dialog
  73.  
  74. class CLoginDlg : public CDialog
  75. {
  76. // Construction
  77. public:
  78.     CLoginDlg(CWnd* pParent = NULL);   // standard constructor
  79.  
  80. // Dialog Data
  81.     //{{AFX_DATA(CLoginDlg)
  82.     enum { IDD = IDD_LOGIN_DIALOG };
  83.     CLoginList    m_LoginList;
  84.     CString    m_ProfileSelected;
  85.     CStringList m_Profiles;
  86.     //}}AFX_DATA
  87.  
  88.  
  89. // Overrides
  90.     // ClassWizard generated virtual function overrides
  91.     //{{AFX_VIRTUAL(CLoginDlg)
  92.     protected:
  93.     virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
  94.     //}}AFX_VIRTUAL
  95.  
  96. // Implementation
  97. protected:
  98.  
  99.     // Generated message map functions
  100.     //{{AFX_MSG(CLoginDlg)
  101.     virtual void OnOK();
  102.     virtual BOOL OnInitDialog();
  103.     afx_msg void OnDblclkLoginList();
  104.     afx_msg void OnSelChangeLoginList();
  105.     afx_msg void OnNewProfile();
  106.     afx_msg void OnDeleteProfile();
  107.     afx_msg void OnOption();
  108.     afx_msg void OnAdvance();
  109.     afx_msg void OnCheck();
  110.     afx_msg void OnEdit();
  111.     afx_msg void OnRemote();
  112.     //}}AFX_MSG
  113.     DECLARE_MESSAGE_MAP()
  114.  
  115.     void CheckPEConfig();
  116.     void DialogDisplay(BOOL);
  117.  
  118. private:
  119.     // PE
  120.     RECT    rect;        
  121.     int        m_range;    
  122.     BOOL    m_bRestoreWindow;
  123.     BOOL    m_bDialOnDemand;
  124.     CString    m_strAcctName;
  125.     CString m_strModemName;
  126.     CString m_strProfileName;
  127. };
  128.  
  129. #define PREF_CHAR 0
  130. #define PREF_INT 1
  131. #define PREF_BOOL 2
  132.  
  133. struct update_PrefTable { char *xp_name; char *section; char *name; int type;};
  134.  
  135. /////////////////////////////////////////////////////////////////////////////
  136. // CUpdateFileDlg dialog
  137. //
  138. class CUpdateFileDlg : public CDialog
  139. {
  140. // Construction
  141. public:
  142.     CUpdateFileDlg(CWnd *pParent, BOOL bCopyDontMove);
  143.  
  144.     // Called at the start of each image saved
  145.     void StartFileUpdate(char *category,char * pFilename);
  146.  
  147.     BOOL m_bCopyDontMove;
  148. // Dialog Data
  149.     //{{AFX_DATA(CSaveFileDlg)
  150.     enum { IDD = IDD_UPDATE_STATUS };
  151.         // NOTE: the ClassWizard will add data members here
  152.     //}}AFX_DATA
  153.     
  154. private:
  155.     CWnd      *m_pParent;
  156.  
  157. // Overrides
  158.     // ClassWizard generated virtual function overrides
  159.     //{{AFX_VIRTUAL(CSaveFileDlg)
  160.     protected:
  161.     virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
  162.     virtual void PostNcDestroy();
  163.     //}}AFX_VIRTUAL
  164.  
  165. // Implementation
  166. protected:
  167.     
  168.     // Generated message map functions
  169.     //{{AFX_MSG(CSaveFileDlg)
  170.     //}}AFX_MSG
  171.     DECLARE_MESSAGE_MAP()
  172. };
  173.  
  174. /////////////////////////////////////////////////////////////////////////////
  175. // CLoginDlg dialog
  176.  
  177.  
  178. CLoginDlg::CLoginDlg(CWnd* pParent /*=NULL*/)
  179.     : CDialog(CLoginDlg::IDD, pParent)
  180. {
  181.     //{{AFX_DATA_INIT(CLoginDlg)
  182.     m_ProfileSelected = _T("");
  183.     //}}AFX_DATA_INIT
  184.  
  185.     if(theApp.m_bPEEnabled)
  186.     {
  187.         m_bRestoreWindow = FALSE;
  188.         m_bDialOnDemand = TRUE;
  189.         m_strAcctName = "";
  190.         m_strModemName = "";
  191.     }
  192. }
  193.  
  194.  
  195. void CLoginDlg::DoDataExchange(CDataExchange* pDX) 
  196. {
  197.     CDialog::DoDataExchange(pDX);
  198.     //{{AFX_DATA_MAP(CLoginDlg)
  199.     //DDX_Control(pDX, IDC_LOGIN_LIST, m_LoginList);
  200.     DDX_LBString(pDX, IDC_LOGIN_LIST, m_ProfileSelected);
  201.     //}}AFX_DATA_MAP
  202. }
  203.  
  204.  
  205. BEGIN_MESSAGE_MAP(CLoginDlg, CDialog)
  206.     //{{AFX_MSG_MAP(CLoginDlg)
  207.     ON_LBN_DBLCLK(IDC_LOGIN_LIST, OnDblclkLoginList)
  208.     ON_LBN_SELCHANGE(IDC_LOGIN_LIST, OnSelChangeLoginList)
  209.     ON_COMMAND(IDC_CREATENEWPROFILE, OnNewProfile)
  210.     ON_COMMAND(IDC_DELETEPROFILE,OnDeleteProfile)
  211.     ON_COMMAND(IDC_OPTION,OnOption)
  212.     ON_COMMAND(IDC_ADVANCED,OnAdvance)
  213.     ON_COMMAND(IDC_PROFILE1,OnRemote)
  214.     ON_COMMAND(IDC_CHECK,OnCheck)
  215.     ON_COMMAND(IDC_EDITPROFILE,OnEdit)
  216.     //}}AFX_MSG_MAP
  217. END_MESSAGE_MAP()
  218.  
  219. /////////////////////////////////////////////////////////////////////////////
  220. // CLoginDlg message handlers
  221.  
  222. void CLoginDlg::OnEdit() 
  223. {
  224.     UpdateData();
  225.     char szMsg[_MAX_PATH+128];
  226.     sprintf(szMsg,szLoadString(IDS_PROFILE_RENAME), m_ProfileSelected);
  227.  
  228.     CDialogPRMT dlgPrompt(this);
  229.     
  230.     char * newName = dlgPrompt.DoModal(szLoadString(IDS_PROFILE_RENAME2), m_ProfileSelected,szMsg);
  231.  
  232.     if (newName) {
  233.         login_RenameUserKey(m_ProfileSelected,newName);
  234.         m_LoginList.DeleteString(m_LoginList.FindStringExact(-1,m_ProfileSelected));
  235.         int idx = m_LoginList.AddString(newName);
  236.         if (idx != LB_ERR) {
  237.             m_LoginList.SetItemDataPtr(idx,XP_STRDUP(newName));
  238.             m_LoginList.UpdateWindow();
  239.             m_LoginList.SetCurSel(m_LoginList.FindStringExact(-1,newName));
  240.         }
  241.     }
  242. }
  243.  
  244. void CLoginDlg::OnOK() 
  245. {
  246.     // PE; disable dial-on-demand for all the profiles
  247.     if(theApp.m_bPEEnabled && !theApp.m_bProfileManager)
  248.     {
  249.         CMucProc    m_mucProc;
  250.         CString        temp;
  251.  
  252.         if(!m_bDialOnDemand)
  253.             temp = "";
  254.         else
  255.             temp = m_strAcctName;
  256.         m_mucProc.SetDialOnDemand(temp,m_bDialOnDemand);
  257.     }
  258.     CDialog::OnOK();
  259. }
  260.  
  261. void CLoginDlg::OnNewProfile() 
  262. {
  263.     char * profile = login_QueryNewProfile(FALSE,this);
  264.     if (profile) {
  265.         int idx = m_LoginList.AddString(profile);
  266.         if (idx != LB_ERR) {
  267.             m_LoginList.SetItemDataPtr(idx,XP_STRDUP(profile));
  268.             m_LoginList.UpdateWindow();
  269.             m_LoginList.SetCurSel(m_LoginList.FindStringExact(-1,profile));
  270.         }
  271.         XP_FREE(profile);
  272.         GetDlgItem(IDOK)->EnableWindow(TRUE);    
  273.         GetDlgItem(IDC_DELETEPROFILE)->EnableWindow(TRUE);    
  274.         GetDlgItem(IDC_EDITPROFILE)->EnableWindow(TRUE);
  275.         GetDlgItem(IDC_OPTION)->EnableWindow(TRUE);
  276.         GetDlgItem(IDC_ADVANCED)->EnableWindow(TRUE);
  277.         OnOK();
  278.     }
  279. }
  280.  
  281. void CLoginDlg::OnDeleteProfile()
  282. {
  283.     UpdateData();
  284.     char szMsg[256];
  285.     sprintf(szMsg, szLoadString(IDS_CONFIRM_DELETE), m_ProfileSelected);
  286.  
  287.     if (AfxMessageBox(szMsg,MB_YESNO) == IDYES) {
  288.         login_DeleteUserKey(m_ProfileSelected);
  289.         m_LoginList.DeleteString(m_LoginList.FindStringExact(-1,m_ProfileSelected));
  290.         m_LoginList.SetCurSel(0);
  291.         AfxMessageBox(szLoadString(IDS_PROFILE_DELETED), MB_OK);
  292.     }
  293.  
  294.     if (m_LoginList.GetCount() <= 0) {
  295.         GetDlgItem(IDOK)->EnableWindow(FALSE);
  296.         GetDlgItem(IDC_DELETEPROFILE)->EnableWindow(FALSE);
  297.         GetDlgItem(IDC_EDITPROFILE)->EnableWindow(FALSE);
  298.         GetDlgItem(IDC_OPTION)->EnableWindow(FALSE);
  299.         GetDlgItem(IDC_ADVANCED)->EnableWindow(FALSE);
  300.     }
  301.  
  302. }
  303.  
  304. BOOL CLoginDlg::OnInitDialog() 
  305. {
  306.     CDialog::OnInitDialog();
  307.  
  308.     // PE: profile selector/manager
  309.     if(theApp.m_bPEEnabled)
  310.     {
  311.         if(!theApp.m_bProfileManager)  // selector    
  312.         {
  313.             GetDlgItem(IDC_OPTION)->ShowWindow(SW_HIDE);
  314.             GetDlgItem(IDC_ADVANCED)->ShowWindow(SW_SHOW);
  315.             ((CButton*)GetDlgItem(IDC_CHECK))->SetCheck(!m_bDialOnDemand);
  316.         }
  317.         else
  318.             GetDlgItem(IDC_ADVANCED)->ShowWindow(SW_HIDE);
  319.     }
  320.     else   // none PE
  321.     {
  322.         GetDlgItem(IDC_ADVANCED)->ShowWindow(SW_HIDE);
  323.         GetDlgItem(IDC_OPTION)->ShowWindow(SW_HIDE);  
  324.         /* we used to hide some of the buttons when the profile manager was used as a
  325.            selector, now with li, we don't do that anymore
  326.         */
  327.     }
  328.  
  329.     // dialog display -- we always show the buttons now, so pass in false.
  330.     DialogDisplay(FALSE);
  331.  
  332.     // profile list
  333.     m_LoginList.SubclassDlgItem(IDC_LOGIN_LIST,this);
  334.     
  335.     int idx=0;
  336.     while (!m_Profiles.IsEmpty()) {
  337.         char * name = strdup(m_Profiles.RemoveHead());
  338.         m_LoginList.AddString(name);    
  339.         //m_LoginList.SetItemData(idx++,(ULONG)(const char *)m_Profiles.RemoveHead());
  340.         m_LoginList.SetItemDataPtr(idx++,(void *)name);
  341.     }
  342.     m_LoginList.SetCurSel(0);
  343.     
  344.     char * name = login_GetCurrentUser();
  345.     if (name) {
  346.         m_LoginList.SelectString(-1,name);      
  347.         free(name);
  348.     }
  349.     if (idx == 0) {
  350.         // we have no profiles -- disable OK/etc
  351.         GetDlgItem(IDOK)->EnableWindow(FALSE);    
  352.         GetDlgItem(IDC_DELETEPROFILE)->EnableWindow(FALSE);    
  353.         GetDlgItem(IDC_EDITPROFILE)->EnableWindow(FALSE);    
  354.         GetDlgItem(IDC_OPTION)->EnableWindow(FALSE);
  355.         GetDlgItem(IDC_ADVANCED)->EnableWindow(FALSE);
  356.     }
  357.     m_LoginList.SetFocus();
  358.  
  359.     if(theApp.m_bPEEnabled)
  360.         CheckPEConfig();
  361.  
  362.     return FALSE;  // return TRUE unless you set the focus to a control
  363.               // EXCEPTION: OCX Property Pages should return FALSE
  364. }
  365.  
  366. void CLoginDlg::DialogDisplay(BOOL m_bSelector)
  367. {
  368.     // display window
  369.     RECT    tagRectTop, tagRectBottom;
  370.     RECT    helpTextRect, frameClientRect, listboxRect;
  371.     RECT    frameScreenRect, helpTextScreenRect;
  372.  
  373.     GetWindowRect(&rect);
  374.     GetDlgItem(IDC_TOP_TAG)->GetWindowRect(&tagRectTop);
  375.     GetDlgItem(IDC_BOTTOM_TAG)->GetWindowRect(&tagRectBottom);
  376.     m_range = tagRectBottom.bottom - tagRectTop.bottom;
  377.  
  378.     SetWindowPos(&wndTop, rect.left, rect.top, 
  379.                 rect.right-rect.left, rect.bottom-rect.top-m_range, SWP_SHOWWINDOW);
  380.  
  381.     // display list box
  382.     if(! m_bSelector)
  383.         return;
  384.  
  385.     GetDlgItem(IDC_FRAME_BOX)->GetClientRect(&frameClientRect);
  386.     GetDlgItem(IDC_LOGIN_LIST)->GetClientRect(&listboxRect);
  387.     GetDlgItem(IDC_HELP_TEXT)->GetClientRect(&helpTextRect);
  388.     GetDlgItem(IDC_FRAME_BOX)->GetWindowRect(&frameScreenRect);
  389.     GetDlgItem(IDC_HELP_TEXT)->GetWindowRect(&helpTextScreenRect);
  390.     
  391.     int m_listBoxWidth = listboxRect.right - listboxRect.left;
  392.     listboxRect.left = frameScreenRect.left + 
  393.                     ((frameClientRect.right - frameClientRect.left) - m_listBoxWidth)/2;
  394.     listboxRect.right = listboxRect.left + m_listBoxWidth;
  395.  
  396.     int m_listBoxHeight = listboxRect.bottom - listboxRect.top;
  397.     listboxRect.top = helpTextScreenRect.bottom + 
  398.                     ((frameScreenRect.bottom - helpTextScreenRect.bottom) - m_listBoxHeight)/2;
  399.     listboxRect.bottom = listboxRect.top + m_listBoxHeight;
  400.  
  401.     ScreenToClient(&listboxRect);
  402.  
  403.     GetDlgItem(IDC_LOGIN_LIST)->SetWindowPos(&wndTop, 
  404.                 listboxRect.left, listboxRect.top,
  405.                 m_listBoxWidth, m_listBoxHeight,
  406.                 SWP_SHOWWINDOW);
  407.  
  408.     // change the dialog title
  409.     CString        m_str;
  410.     m_str.LoadString(IDS_PROFILE_SELECTOR_TITLE);
  411.     SetWindowText(m_str);
  412. }
  413.  
  414. void CLoginDlg::OnDblclkLoginList() 
  415. {
  416.     // TODO: Add your control notification handler code here
  417.     OnOK(); 
  418. }
  419.  
  420. void CLoginDlg::OnSelChangeLoginList() 
  421. {
  422.     if(theApp.m_bPEEnabled && !theApp.m_bProfileManager)
  423.     {
  424.         CheckPEConfig();
  425.         GetDlgItem(IDC_ADVANCED_ACCTNAME)->SetWindowText(m_strAcctName);
  426.         UpdateData(FALSE);
  427.     }
  428. }
  429.  
  430. void CLoginDlg::OnOption() 
  431. {
  432.     CheckPEConfig();
  433.     CMucViewWizard mucViewWizard(this, m_strProfileName, m_strAcctName, m_strModemName);
  434.     int ret = mucViewWizard.DoModal();
  435. }
  436.  
  437. /* handles the remote profile case */
  438. void CLoginDlg::OnRemote() 
  439. {
  440.     /* if they hit ok - go for it
  441.        if they don't, let them choose a regular one.
  442.     */
  443. #ifdef MOZ_LOC_INDEP
  444.     if (winli_QueryNetworkProfile()) {
  445.          /* act like they hit ok to close the profile manager.*/
  446.         OnOK();
  447.         /* set profile selected to null to stop us from getting the profile from 
  448.            the list. Must be done after the ok/dataExchange stuff.
  449.         */
  450.         m_ProfileSelected = "";
  451.     }
  452. #endif // MOZ_LOC_INDEP
  453. }
  454.  
  455. void CLoginDlg::OnAdvance() 
  456. {
  457.     m_bRestoreWindow = (m_bRestoreWindow + 1) %2; 
  458.  
  459.     if(m_bRestoreWindow)
  460.     {
  461.         GetWindowRect(&rect);
  462.         SetWindowPos(&wndTop, rect.left, rect.top, 
  463.                     rect.right-rect.left, rect.bottom-rect.top+m_range, SWP_SHOWWINDOW);
  464.  
  465.         SetDlgItemText(IDC_ADVANCED, "Advanced<<");
  466.     
  467.         GetDlgItem(IDC_ADVANCED_ACCTNAME)->SetWindowText(m_strAcctName);
  468.         UpdateData(FALSE);
  469.     }
  470.     else
  471.     {
  472.         GetWindowRect(&rect);
  473.         SetWindowPos(&wndTop, rect.left, rect.top, 
  474.                     rect.right-rect.left, rect.bottom-rect.top-m_range, SWP_SHOWWINDOW);
  475.                 
  476.         SetDlgItemText(IDC_ADVANCED, "Advanced>>");
  477.     }
  478. }
  479.  
  480. void CLoginDlg::OnCheck() 
  481. {
  482.     m_bDialOnDemand = (m_bDialOnDemand + 1) %2;
  483. }
  484.  
  485. void CLoginDlg::CheckPEConfig() 
  486. {
  487.     XP_StatStruct statinfo; 
  488.     int     ret;
  489.     char    strAcct[MAX_PATH];
  490.     char    strModem[MAX_PATH];
  491.     char    path[MAX_PATH+1];
  492.     HKEY    hKeyRet;
  493.     char    *pString = NULL;
  494.     long    result;
  495.     DWORD   type, size;
  496.     char    name[MAX_PATH];
  497.     int             curSelect;
  498.  
  499.     curSelect = m_LoginList.GetCurSel();  
  500.     if(curSelect < 0)
  501.     {
  502.         m_strAcctName = "";
  503.         m_strModemName = "";
  504.         m_strProfileName = "";   
  505.         return;
  506.     }
  507.     strcpy(name, (char*)m_LoginList.GetItemDataPtr(curSelect));
  508.  
  509.     // get profile path
  510. #ifdef XP_WIN32
  511.     strcpy(path, "SOFTWARE\\Netscape\\Netscape Navigator\\Users");
  512.     strcat(path, "\\");
  513.     strcat(path, name);
  514.  
  515.     if (ERROR_SUCCESS == RegOpenKey(HKEY_LOCAL_MACHINE, path, &hKeyRet)) 
  516.     {
  517.         // see how much space we need
  518.         size = 0;
  519.         result = RegQueryValueEx(hKeyRet, "DirRoot", NULL, &type, NULL, &size);
  520.  
  521.         // if we didn't find it just use the default
  522.         if((result == ERROR_SUCCESS) && (size != 0)) 
  523.         {
  524.             // allocate space to hold the string
  525.             pString = (char *) XP_ALLOC(size * sizeof(char));
  526.  
  527.             // actually load the string now that we have the space
  528.             result = RegQueryValueEx(hKeyRet, "DirRoot", NULL, &type, (LPBYTE) pString, &size);
  529.     
  530.             if (hKeyRet) RegCloseKey(hKeyRet);
  531.         }
  532.     }
  533. #else
  534.     CString csNSCPini;
  535.     login_GetIniFilePath(csNSCPini);
  536.  
  537.     pString = (char *) XP_ALLOC(_MAX_PATH * sizeof(char));
  538.     ::GetPrivateProfileString("Users", name,"",pString,_MAX_PATH,csNSCPini);
  539. #endif
  540.  
  541.     if(pString == NULL)
  542.         return;
  543.     ret = _stat(pString, &statinfo);
  544.     if(ret == 0) 
  545.     {
  546.         // construct the profile full name
  547.         strcpy(path, pString);
  548.         strcat(path, "\\config.ini");
  549.         
  550.         memset(strAcct, 0x00, MAX_PATH);
  551.         ::GetPrivateProfileString("Account", "Account", "", strAcct, MAX_PATH, path);
  552. //        ::GetPrivateProfileString("Modem", "Modem", "", strModem, MAX_PATH, path);
  553.  
  554.         m_strAcctName = strAcct;
  555. //        m_strModemName = strModem;
  556.     }   
  557.     m_strProfileName = path;
  558.     
  559.     XP_FREE (pString);
  560. }                       
  561.  
  562. /////////////////////////////////////////////////////////////////////////////
  563. // CLoginList
  564.  
  565. CLoginList::CLoginList(): CListBox()
  566. {
  567.     m_iPosIndex = 0;
  568.     m_iPosName = 50;
  569.     m_iPosStatus = 100;
  570. }
  571.  
  572. CLoginList::~CLoginList()
  573. {
  574. }
  575.  
  576. void CLoginList::SetColumnPositions(int iPosIndex, int iPosName, int iPosStatus)
  577. {
  578.     m_iPosIndex = iPosIndex;
  579.     m_iPosName = iPosName;
  580.     m_iPosStatus = iPosStatus;
  581. }
  582.  
  583. BEGIN_MESSAGE_MAP( CLoginList, CListBox )
  584.     ON_WM_LBUTTONDOWN()
  585. END_MESSAGE_MAP( )
  586.  
  587. void CLoginList::MeasureItem( LPMEASUREITEMSTRUCT lpMeasureItemStruct )
  588. {
  589.     lpMeasureItemStruct->itemHeight = 32;
  590. }
  591.  
  592. void CLoginList::DrawItem( LPDRAWITEMSTRUCT lpDrawItemStruct )
  593. {
  594.     HDC hDC = lpDrawItemStruct->hDC;
  595.     RECT rcItem = lpDrawItemStruct->rcItem;
  596.     RECT rcTemp = rcItem;
  597.  
  598.     if (!lpDrawItemStruct) return;
  599.     if (!lpDrawItemStruct->itemData) return;
  600.  
  601.     const char * itemData = (const char *)GetItemDataPtr(lpDrawItemStruct->itemID); 
  602.                         
  603.     HBRUSH hBrushFill;
  604.  
  605. #ifndef XP_WIN16
  606.     if ( lpDrawItemStruct->itemState & ODS_SELECTED ) {
  607.         hBrushFill = GetSysColorBrush( COLOR_HIGHLIGHT );
  608.         ::SetBkColor( hDC, GetSysColor( COLOR_HIGHLIGHT ) );
  609.         ::SetTextColor( hDC, GetSysColor( COLOR_HIGHLIGHTTEXT ) );
  610.     } else {
  611.         hBrushFill = GetSysColorBrush( COLOR_WINDOW );
  612.         ::SetBkColor( hDC, GetSysColor( COLOR_WINDOW ) );
  613.         ::SetTextColor( hDC, GetSysColor( COLOR_WINDOWTEXT ) );
  614.     }
  615. #else
  616.     if ( lpDrawItemStruct->itemState & ODS_SELECTED ) {
  617.         hBrushFill = CreateSolidBrush( GetSysColor(COLOR_HIGHLIGHT));
  618.         ::SetBkColor( hDC, GetSysColor( COLOR_HIGHLIGHT ) );
  619.         ::SetTextColor( hDC, GetSysColor( COLOR_HIGHLIGHTTEXT ) );
  620.     } else {
  621.         hBrushFill = CreateSolidBrush( GetSysColor(COLOR_WINDOW) );
  622.         ::SetBkColor( hDC, GetSysColor( COLOR_WINDOW ) );
  623.         ::SetTextColor( hDC, GetSysColor( COLOR_WINDOWTEXT ) );
  624.     }
  625. #endif
  626.  
  627.     if ( itemData ) {
  628.         CClientDC dc(this);
  629.  
  630.         ::FillRect( hDC, &rcItem, hBrushFill );
  631.  
  632.         rcTemp.left = m_iPosIndex;
  633.         rcTemp.right = m_iPosName;
  634.         DrawIcon(hDC,rcTemp.left,rcTemp.top,theApp.LoadIcon(IDR_DOCUMENT));
  635.  
  636.         rcTemp.left = rcTemp.right;
  637.         rcTemp.right = rcItem.right;
  638.         ::DrawText( hDC, itemData, -1,  &rcTemp, DT_VCENTER|DT_LEFT|DT_SINGLELINE );
  639.     }
  640. #ifdef XP_WIN16
  641.     if (hBrushFill) DeleteObject(hBrushFill);
  642. #endif
  643. }
  644.  
  645. char szProfileName[] = "Profile Name:";
  646. char szUserDirectory[] = "UserDirectory";
  647.  
  648. void CLoginList::OnLButtonDown( UINT nFlags, CPoint point )
  649. {
  650.     CListBox::OnLButtonDown( nFlags, point );
  651. }
  652.   
  653. #include "dialog.h"
  654. #include "setupwiz.h"
  655.  
  656. int PR_CALLBACK ProfilePrefChangedFunc(const char *pref, void *data) 
  657. {
  658.     if ((!XP_STRCASECMP(pref,"mail.identity.username")) ||
  659.         (!XP_STRCASECMP(pref,"mail.identity.useremail"))) { 
  660.         char * name = login_GetCurrentUser();
  661.  
  662.         if (name) {
  663.             login_SetUserKeyData(name);
  664.         }
  665.     }
  666.     
  667.     return 0;
  668. }
  669.  
  670. // The magical prefix of $ROOT in a URL will take us to the directory
  671. // that the program was run from.  If that feature should die, this will
  672. // have to contain some real code...
  673. char * GetASWURL()
  674. {
  675.     char *pString = "$ROOT\\ASW\\start.htm";
  676.     return XP_STRDUP(pString);
  677. }
  678.  
  679. // This function will attempt to create a new profile.  This
  680. // includes setting up the registry key as well as creating
  681. // the corresponding user directory
  682. char * login_QueryNewProfile(BOOL bUpgrade,CWnd *parent) {
  683.     CNewProfileWizard setupWizard(parent,bUpgrade);
  684.     int ret = setupWizard.DoModal();
  685.     if (!setupWizard.m_pProfileName.IsEmpty()) {
  686.         char * ret = XP_STRDUP(setupWizard.m_pProfileName);
  687.         return ret;
  688.     }
  689.     else return NULL;
  690. }
  691.  
  692. int login_RenameUserKey(const char *oldName, const char* newName) {
  693.     long    result;
  694.     int             fieldLen = 0;
  695.  
  696.     if (!strcmpi(oldName,newName)) return FALSE;
  697.  
  698. #ifdef XP_WIN32
  699.     HKEY hKeyRet;
  700.     CString csSub = "SOFTWARE\\Netscape\\Netscape Navigator\\Users\\";
  701.     CString newPath,oldPath;
  702.     HKEY hKeyNewName;
  703.     HKEY hKeyOldName;
  704.     DWORD dwDisposition;
  705.  
  706.     newPath = csSub+newName;
  707.     oldPath = csSub+oldName;
  708.  
  709.     // create a new key for our new profile name
  710.     if (ERROR_SUCCESS == RegCreateKeyEx(HKEY_LOCAL_MACHINE, newPath, NULL, NULL, NULL, KEY_WRITE, NULL, &hKeyNewName, &dwDisposition)) {
  711.  
  712.         // now... we enumerate old profile key contents and copy everything into new profile key
  713.         // first, gets the hkey for the old profile path
  714.         if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE, oldPath, NULL, KEY_WRITE | KEY_READ, &hKeyOldName)) {
  715.  
  716.             DWORD subKeys;
  717.             DWORD maxSubKeyLen;
  718.             DWORD maxClassLen;
  719.             DWORD values;
  720.             DWORD maxValueNameLen;
  721.             DWORD maxValueLen;
  722.             DWORD securityDescriptor;
  723.             FILETIME lastWriteTime;
  724.  
  725.             // get some information about this old profile key 
  726.             if (ERROR_SUCCESS == RegQueryInfoKey(hKeyOldName, NULL, NULL, NULL, &subKeys, &maxSubKeyLen, &maxClassLen, &values, &maxValueNameLen, &maxValueLen, &securityDescriptor, &lastWriteTime)) {
  727.  
  728.                 // copy the values
  729.                 BOOL NoErr = CopyRegKeys(hKeyOldName, hKeyNewName, subKeys, maxSubKeyLen, maxClassLen, values, maxValueNameLen, maxValueLen, oldPath, newPath);
  730.  
  731.                 // delete the old Key, if everything went well
  732.                 if (NoErr) {
  733.                     login_DeleteUserKey(oldName);                    
  734.                 }
  735.             }
  736.         }
  737.         RegCloseKey(hKeyNewName);
  738.         RegCloseKey(hKeyOldName);
  739.         return TRUE;
  740.     }
  741.  
  742. #else
  743.     CString csNSCPini;
  744.     login_GetIniFilePath(csNSCPini);
  745.  
  746.     // get old dir
  747.     char *pString = (char *) XP_ALLOC(_MAX_PATH * sizeof(char));
  748.     ::GetPrivateProfileString("Users", oldName,"",pString,_MAX_PATH,csNSCPini);
  749.  
  750.     // blank out old name now
  751.     ::WritePrivateProfileString("Users", oldName, NULL,csNSCPini);
  752.     result = ::WritePrivateProfileString("Users", newName, pString,csNSCPini);
  753.     if (pString) XP_FREE(pString);
  754. #endif
  755.     return TRUE;
  756. }
  757.  
  758. int login_CreateNewUserKey(const char *profileName, const char* directory) {
  759.     long    result;
  760.     char    *nullString = "";
  761.     char    *email, *username;
  762.     int             fieldLen = 0;
  763.  
  764.     if (PREF_GetCharPref("mail.identity.useremail", NULL, &fieldLen) == PREF_NOERROR) {
  765.         email = (char *) XP_ALLOC(fieldLen);
  766.         if (email) {
  767.             PREF_GetCharPref("mail.identity.useremail", email, &fieldLen);
  768.         } else {
  769.             email = nullString;
  770.         }
  771.     }
  772.  
  773.     fieldLen = 0;
  774.     if (PREF_GetCharPref("mail.identity.username", NULL, &fieldLen) == PREF_NOERROR) {
  775.         username = (char *) XP_ALLOC(fieldLen);
  776.         if (username) {
  777.             PREF_GetCharPref("mail.identity.username", username, &fieldLen);
  778.         } else {
  779.             username = nullString;
  780.         }
  781.     }
  782.  
  783. #ifdef XP_WIN32
  784.     HKEY hKeyRet;
  785.     CString csSub = "SOFTWARE\\Netscape\\Netscape Navigator\\Users\\";
  786.  
  787.     csSub += profileName;
  788.     result = RegCreateKey(HKEY_LOCAL_MACHINE,
  789.                         csSub,
  790.                         &hKeyRet);
  791.  
  792.  
  793.     result = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
  794.                         csSub,
  795.                         NULL,
  796.                         KEY_SET_VALUE,
  797.                         &hKeyRet);
  798.  
  799.     if (result == ERROR_SUCCESS) {
  800.         RegSetValueEx(hKeyRet,"DirRoot",NULL,REG_SZ,(const BYTE *)directory,strlen(directory)+1);
  801.         RegSetValueEx(hKeyRet,"UserName",NULL,REG_SZ,(const BYTE *)username,strlen(username)+1);
  802.         RegSetValueEx(hKeyRet,"EmailAddr",NULL,REG_SZ,(const BYTE *)email,strlen(email)+1);
  803.         RegCloseKey(hKeyRet);
  804.     } else {
  805.         AfxMessageBox(szLoadString(IDS_UNABLE_WRITE_REG));
  806.     }
  807. #else
  808.     CString csNSCPini;
  809.     login_GetIniFilePath(csNSCPini);
  810.  
  811.     result = ::WritePrivateProfileString("Users", profileName, directory,csNSCPini);        
  812. #endif
  813.  
  814.     return CASTINT(result);
  815. }
  816.  
  817. #ifdef XP_WIN32
  818. // this wasn't exported anywhere!
  819. extern LONG RegDeleteKeyNT(HKEY hStartKey, LPCSTR lpszKeyName);
  820. #endif
  821.  
  822. int login_DeleteUserKey(const char *profileName) {
  823.     long result;
  824. #ifdef XP_WIN32
  825.     HKEY hKeyRet;
  826.     CString csSub = "SOFTWARE\\Netscape\\Netscape Navigator\\Users\\";
  827.  
  828.     result = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
  829.                         csSub,
  830.                         NULL,
  831.                         KEY_WRITE,
  832.                         &hKeyRet);
  833.  
  834.     if (result == ERROR_SUCCESS) {
  835.         RegDeleteKeyNT(hKeyRet,profileName);
  836.     }
  837.     if (hKeyRet) RegCloseKey(hKeyRet);
  838. #else
  839.     CString csNSCPini;
  840.     login_GetIniFilePath(csNSCPini);
  841.  
  842.     result = ::WritePrivateProfileString("Users", profileName, NULL,csNSCPini);     
  843. #endif
  844.  
  845.     return CASTINT(result);
  846. }
  847.  
  848. int login_SetUserKeyData(const char *profileName) {
  849.     long    result;
  850.     char    *nullString = "";
  851.     char    *email, *username;
  852.     int             fieldLen = 0;
  853.  
  854.     if (PREF_GetCharPref("mail.identity.useremail", NULL, &fieldLen) == PREF_NOERROR) {
  855.         email = (char *) XP_ALLOC(fieldLen);
  856.         if (email) {
  857.             PREF_GetCharPref("mail.identity.useremail", email, &fieldLen);
  858.         } else {
  859.             email = nullString;
  860.         }
  861.     }
  862.  
  863.     fieldLen = 0;
  864.     if (PREF_GetCharPref("mail.identity.username", NULL, &fieldLen) == PREF_NOERROR) {
  865.         username = (char *) XP_ALLOC(fieldLen);
  866.         if (username) {
  867.             PREF_GetCharPref("mail.identity.username", username, &fieldLen);
  868.         } else {
  869.             username = nullString;
  870.         }
  871.     }
  872.     
  873. #ifdef XP_WIN32
  874.     HKEY hKeyRet;
  875.     CString csSub = "SOFTWARE\\Netscape\\Netscape Navigator\\Users\\";
  876.  
  877.     csSub += profileName;
  878.  
  879.     result = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
  880.                         csSub,
  881.                         NULL,
  882.                         KEY_SET_VALUE,
  883.                         &hKeyRet);
  884.  
  885.     if (result == ERROR_SUCCESS) {
  886.         RegSetValueEx(hKeyRet,"UserName",NULL,REG_SZ,(const BYTE *)username,strlen(username)+1);
  887.         RegSetValueEx(hKeyRet,"EmailAddr",NULL,REG_SZ,(const BYTE *)email,strlen(email)+1);
  888.         RegCloseKey(hKeyRet);
  889.     }
  890. #else
  891. #endif
  892.     return CASTINT(result);
  893. }
  894.  
  895.  
  896. int login_SetCurrentUser(const char * user) {
  897.     long result;
  898. #ifdef XP_WIN32
  899.     HKEY hKeyRet = NULL;
  900.     CString csSub = "SOFTWARE\\Netscape\\Netscape Navigator\\Users\\";
  901.  
  902.     result = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
  903.                         csSub,
  904.                         NULL,
  905.                         KEY_SET_VALUE,
  906.                         &hKeyRet);
  907.  
  908.     if (result == ERROR_SUCCESS) {
  909.         RegSetValueEx(hKeyRet,"CurrentUser",NULL,REG_SZ,(const BYTE *)user,strlen(user)+1);
  910.         RegCloseKey(hKeyRet);
  911.     }
  912. #else
  913.     CString csNSCPini;
  914.     login_GetIniFilePath(csNSCPini);
  915.  
  916.     result = ::WritePrivateProfileString("Users Additional Info", "CurrentUser", user,csNSCPini);   
  917. #endif
  918.     return CASTINT(result);
  919. }
  920.  
  921. // checks to see if we think somebody has already used Navigator on this machine
  922. Bool login_UpgradeNeeded(void) {
  923.     // lets just try to load the homepage
  924.     CString csPref= theApp.GetProfileString("Main","Home Page","");
  925.     if (!csPref.IsEmpty()) return TRUE;
  926.  
  927.     csPref= theApp.GetProfileString("User","User_Addr","");
  928.     if (!csPref.IsEmpty()) return TRUE;
  929.  
  930.     csPref= theApp.GetProfileString("User","User_Name","");
  931.     if (!csPref.IsEmpty()) return TRUE;
  932.  
  933.     csPref= theApp.GetProfileString("Bookmark List","File Location","");
  934.     if (!csPref.IsEmpty()) return TRUE;
  935.  
  936.     return FALSE;
  937. }
  938.  
  939. int PR_CALLBACK
  940. ProfileNameChangedFunc(const char *pref, void *data)
  941. {
  942.     if (!pref) return FALSE;
  943.     if (!data) return FALSE;
  944.  
  945.     if (!strcmpi(pref,"profile.name") ) {
  946.         LPSTR    lpszNewName = NULL;
  947.  
  948.         PREF_CopyCharPref("profile.name", &lpszNewName);
  949.         login_RenameUserKey((char *)data,lpszNewName);
  950.         if (lpszNewName)
  951.             XP_FREE(lpszNewName);
  952.         return TRUE;
  953.     }
  954.     return FALSE;
  955. }
  956.  
  957. int login_QueryForCurrentProfile() {
  958.     CLoginDlg dlg;
  959.     Bool bGotoASW = FALSE;
  960.     Bool bFirstTimeUser;
  961.     Bool bUpgradeNeeded;
  962.     Bool bRet;
  963.     int  numProfiles;
  964.     char * pString = NULL;
  965.     CString csProfileSelected;
  966.  
  967.     char aPath[_MAX_PATH];
  968.     ::GetModuleFileName(theApp.m_hInstance, aPath, _MAX_PATH);
  969.     //      Kill the last slash and everything after it
  970.     char *pSlash = ::strrchr(aPath, '\\');
  971.     if(pSlash)
  972.         *pSlash = '\0';
  973.     CString csLockFile = aPath;
  974.     csLockFile += "\\netscape.cfg";
  975.  
  976.     // we need to read this early so that any defaults get set for the setup wizard's use.
  977.     // we will read it again at the end to overwrite any user settings
  978.     PREF_ReadLockFile(csLockFile);
  979.  
  980.     csProfileSelected.Empty();
  981.  
  982.     if (theApp.m_bNetworkProfile) {
  983. #ifdef MOZ_LOC_INDEP
  984.         return winli_QueryNetworkProfile();
  985. #else
  986.     return FALSE;
  987. #endif // MOZ_LOC_INDEP
  988.     }
  989.     //------------------------------------------------------------------------------------------------
  990.     //  KLUDGE!
  991.     //    The Account Setup Wizard is now a Java/Javascript application.  Since they have no control
  992.     //    over the profile that will contain the preference changes, we use a hidden magic profile to
  993.     //    hold their changes until they're done MUCKing about.  When they've finished, they will 
  994.     //    rename the profile based on user inputs.  If all goes well, the magic profile never outlives
  995.     //    any given instance of the navigator/ASW.  However, if anything fails the magic profile could
  996.     //    be left lying about.  This would be bad.
  997.     //
  998.     //    The most unfortunate occurance of this problem would be while creating the first profile.
  999.     //    In this case, we don't know the user hasn't successfully created a profile unless we check
  1000.     //    to see if the magic profile is the only one.  The simplest way to handle this is to just
  1001.     //    expunge the magic profile whenever we get here and find that it exists.
  1002.     //------------------------------------------------------------------------------------------------
  1003.     //
  1004.     //  Delete the magic profile if it exists
  1005.     CUserProfileDB profileDB;
  1006.     profileDB.DeleteUserProfile( ASW_MAGIC_PROFILE_NAME );
  1007.  
  1008.     profileDB.GetUserProfilesList( &dlg.m_Profiles );
  1009.     bFirstTimeUser = dlg.m_Profiles.IsEmpty();
  1010.     numProfiles    = dlg.m_Profiles.GetCount();
  1011.     if (bFirstTimeUser)
  1012.         bUpgradeNeeded = login_UpgradeNeeded();
  1013.     else
  1014.         bUpgradeNeeded = FALSE;
  1015.  
  1016.     /////////////////////////////////////////////////////////////////////////////////////
  1017.     // The account setup flag and the new profile flag are basically mutually exclusive,
  1018.     // but check the account setup flag first just in case.  The account setup flag is
  1019.     // an override that causes the account setup wizard to run instead of the profile
  1020.     // wizard
  1021.     //
  1022.     //-----------------------------------------------------------
  1023.     // Decide what to do between MUP/MUC/ASW
  1024.     //-----------------------------------------------------------
  1025.     if (bFirstTimeUser && theApp.m_bPEEnabled)
  1026.     {
  1027.         // PE!
  1028.  
  1029.         // Disable -profile_manager in this case since we don't
  1030.         // want first-time users to see it for PE
  1031.         theApp.m_bProfileManager = FALSE;
  1032.  
  1033.         if (bUpgradeNeeded)
  1034.         {
  1035.             // Upgrades do upgrade dialog and then to ASW
  1036.             if (!login_QueryNewProfile(bUpgradeNeeded,NULL))
  1037.                 return FALSE;
  1038.  
  1039.             // Tell ASW to go to Upgrade screen
  1040.             PREF_SetBoolPref("account_setup.upgraded", TRUE);
  1041.         }
  1042.         else
  1043.         {
  1044.             // Very first _account_ (this _is_ PE after all)
  1045.  
  1046.             // Get a directory name that'll work on the current system
  1047.             CString theDirectory;
  1048.             if (!profileDB.AssignProfileDirectoryName(ASW_MAGIC_PROFILE_NAME, theDirectory))
  1049.                 return FALSE;
  1050.  
  1051.             // Create the Magic Profile for ASW
  1052.             profileDB.AddNewProfile(ASW_MAGIC_PROFILE_NAME, 
  1053.                          theDirectory,
  1054.                          UPGRADE_IGNORE );
  1055.  
  1056.             bGotoASW = TRUE;
  1057.         }
  1058.  
  1059.         // We now have exactly one profile
  1060.     } 
  1061.     else if (theApp.m_bPEEnabled && theApp.m_bAccountSetup)
  1062.     {
  1063.         // PE, Some normal profile(s) exists and ASW requested
  1064.         bGotoASW = TRUE;
  1065.     }
  1066.     else if ((bFirstTimeUser || theApp.m_bCreateNewProfile) && !theApp.m_bProfileManager)
  1067.     {
  1068.         // No profiles or -new_profile requested
  1069.         char * profile = login_QueryNewProfile(bUpgradeNeeded,NULL);
  1070.         if (!profile)
  1071.             return FALSE;
  1072.         else {
  1073.             login_SetCurrentUser(profile);
  1074.         }
  1075.     }
  1076.  
  1077.     // This information may have changed
  1078.     profileDB.GetUserProfilesList( &dlg.m_Profiles );
  1079.     numProfiles    = dlg.m_Profiles.GetCount();
  1080.     PREF_SetDefaultIntPref( "profile.numprofiles", numProfiles );
  1081.  
  1082.     // See if we need to do wizardry to get to ASW
  1083.     if (bGotoASW)
  1084.     {
  1085.         char *asw = GetASWURL();
  1086.         theApp.m_csPEPage = asw;
  1087.         theApp.m_bAlwaysDockTaskBar = TRUE;
  1088.         XP_FREEIF(asw);
  1089.         theApp.m_bAccountSetup     = TRUE;
  1090.         theApp.m_bAccountSetupStartupJava = TRUE;  // Need this here too...
  1091.     }
  1092.     else
  1093.         theApp.m_bAccountSetup     = FALSE;
  1094.  
  1095.  
  1096.     theApp.m_bCreateNewProfile = FALSE; // already did it
  1097.  
  1098.  
  1099.     if (theApp.m_bProfileManager) {
  1100.         if (dlg.DoModal()==IDCANCEL) {
  1101.             return FALSE;
  1102.         };
  1103.         csProfileSelected =(const char *)dlg.m_ProfileSelected;
  1104.     } else {
  1105.  
  1106.         if (numProfiles == 0) {
  1107.             assert(0);
  1108.             theApp.m_bCreateNewProfile = TRUE; // Do it again!
  1109.             return login_QueryForCurrentProfile();  // run us again
  1110.         }
  1111.  
  1112.         if (numProfiles == 1) {                           
  1113.             // we only have one profile -- just use it!
  1114.             csProfileSelected = dlg.m_Profiles.GetHead();
  1115.  
  1116.         }
  1117.         else if (theApp.m_CmdLineProfile) {
  1118.             csProfileSelected = theApp.m_CmdLineProfile;
  1119.         }
  1120.         else {
  1121.             // ask the user to choose!
  1122.             if (dlg.DoModal()==IDCANCEL) {
  1123.                 return FALSE;
  1124.             } else if (dlg.m_ProfileSelected == "")
  1125.                 return TRUE; // LI NetProfile selected.
  1126.             csProfileSelected =(const char *)dlg.m_ProfileSelected;
  1127.         }
  1128.     }
  1129.     
  1130.     /* we have the profile, publish the name as a pref */
  1131.     PREF_SetDefaultCharPref( "profile.name", csProfileSelected );
  1132.  
  1133.     pString = profileDB.GetUserProfileValue( csProfileSelected, "DirRoot" );
  1134.  
  1135.     // read in the preference file (will assume valid dir here...we need to know if LI)
  1136.     // REMIND:  JEM:  we now read prefs twice...just to find this one pref...we should parse the file
  1137.     CString csTmp = pString;
  1138.     csTmp += "\\prefs.js";
  1139.     PREF_Init((char *)(const char *)csTmp);
  1140.  
  1141.     XP_Bool prefBool=FALSE;
  1142.     PREF_GetBoolPref("li.enabled",&prefBool);
  1143.  
  1144.     theApp.m_UserDirectory = pString;
  1145.     if (pString)
  1146.         PREF_SetDefaultCharPref( "profile.directory", pString );
  1147.  
  1148. // I figure this is safe since "li.enabled" should always be false if not MOZ_LOC_INDEP
  1149. #ifdef MOZ_LOC_INDEP
  1150.     if (prefBool) 
  1151.         bRet = FEU_StartGetCriticalFiles(csProfileSelected,pString);
  1152.     else
  1153. #endif // MOZ_LOC_INDEP
  1154.         bRet = login_ProfileSelectedCompleteTheLogin(csProfileSelected,pString);
  1155.   // Careful, the above line is actually inside an if statement.
  1156.  
  1157.     XP_FREEIF(pString);
  1158.     return bRet;
  1159. }
  1160.  
  1161. Bool login_ProfileSelectedCompleteTheLogin(const char * szProfileName, const char * szProfileDir) {
  1162.  
  1163.  
  1164.     CString csTmp;
  1165.  
  1166.     // verify directory exists
  1167.     XP_StatStruct statinfo; 
  1168.     int ret = _stat((char *)(const char *)theApp.m_UserDirectory, &statinfo);
  1169.     if(ret == -1) {
  1170.         char szMsg[256];
  1171.         sprintf(szMsg, szLoadString(IDS_BAD_DIRECTORY2), theApp.m_UserDirectory);
  1172.  
  1173.         int choice = AfxMessageBox(szMsg,MB_OKCANCEL);
  1174.         if (choice == IDOK) {
  1175.             theApp.m_bCreateNewProfile = TRUE;  // force wizard to run
  1176.             theApp.m_bProfileManager = FALSE;
  1177.             return login_QueryForCurrentProfile();  // run us again
  1178.         } else return FALSE;
  1179.     }
  1180.  
  1181.     // this call needs to be done after the last chance that profile.name would inadvertantly change
  1182.     // in other words, it needs to be below the above recursive call to login_QueryForCurrentProfile()
  1183.     PREF_RegisterCallback("profile.name",ProfileNameChangedFunc,(void *)(const char *)szProfileName);
  1184.  
  1185.     // read in the preference file which we read-write
  1186.     csTmp = theApp.m_UserDirectory;
  1187.     csTmp += "\\prefs.js";
  1188.  
  1189.     PREF_Init((char *)(const char *)csTmp);
  1190.  
  1191.     // read in the user's LI prefs file
  1192.     char * prefName = WH_FileName(NULL, xpLIPrefs);
  1193.     PREF_ReadLIJSFile(prefName);
  1194.     XP_FREEIF (prefName);
  1195.  
  1196.     // read in the users optional JS file
  1197.     csTmp = theApp.m_UserDirectory;
  1198.     csTmp += "\\user.js";
  1199.     PREF_ReadUserJSFile((char *)(const char *)csTmp);
  1200.  
  1201.     // read in the users optional JS HTML Hook file
  1202.     csTmp = theApp.m_UserDirectory;
  1203.     csTmp += "\\hook.js";
  1204.     HK_ReadHookFile((char *)(const char *)csTmp);
  1205.  
  1206.     char aPath[_MAX_PATH];
  1207.     ::GetModuleFileName(theApp.m_hInstance, aPath, _MAX_PATH);
  1208.     //      Kill the last slash and everything after it
  1209.     char *pSlash = ::strrchr(aPath, '\\');
  1210.     if(pSlash)
  1211.         *pSlash = '\0';
  1212.     CString csLockFile = aPath;
  1213.     csLockFile += "\\netscape.cfg";
  1214.  
  1215.     // check for required file: netscape.cfg
  1216.     if (!FEU_SanityCheckFile(csLockFile)) {
  1217.         AfxMessageBox(szLoadString(IDS_MISSING_CFG));
  1218.         return FALSE;
  1219.     }
  1220.  
  1221.     // read the optional profile.cfg file
  1222.     CString csProfileCfg;
  1223.     csProfileCfg = theApp.m_UserDirectory;
  1224.     csProfileCfg += "\\profile.cfg";
  1225.     PREF_ReadLockFile(csProfileCfg);
  1226.  
  1227.     if (PREF_ReadLockFile(csLockFile) == PREF_BAD_LOCKFILE)    {
  1228.         AfxMessageBox(szLoadString(IDS_INVALID_CFG));
  1229.         return FALSE;
  1230.     }
  1231.  
  1232.  
  1233.     PREF_SavePrefFile(); // explicit save to get any prefs set before filename was set
  1234.     login_SetCurrentUser(szProfileName);
  1235.         
  1236.     PREF_RegisterCallback("mail.identity",ProfilePrefChangedFunc, NULL);
  1237.     return TRUE;
  1238. }
  1239.  
  1240.  
  1241. char * login_GetCurrentUser() 
  1242. {
  1243.     long result;
  1244. #ifdef XP_WIN32
  1245.     DWORD type, size;
  1246.     HKEY hKeyRet;
  1247.  
  1248.     CString csSub = "SOFTWARE\\Netscape\\Netscape Navigator\\Users\\";
  1249.  
  1250.     result = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
  1251.                         csSub,
  1252.                         NULL,
  1253.                         KEY_QUERY_VALUE,
  1254.                         &hKeyRet);
  1255.  
  1256.     if (result != ERROR_SUCCESS) {
  1257.         return NULL;
  1258.     }
  1259.  
  1260.     // see how much space we need
  1261.     result = RegQueryValueEx(hKeyRet,
  1262.                               (char *) "CurrentUser",
  1263.                               NULL,
  1264.                               &type,
  1265.                               NULL,
  1266.                               &size);
  1267.  
  1268.     // if we didn't find it error!
  1269.     if((result != ERROR_SUCCESS) || (size == 0))
  1270.         //AfxMessageBox("Unable to determine last user");
  1271.         return NULL;
  1272.  
  1273.     // allocate space to hold the string
  1274.     char * pString = (char *) XP_ALLOC(size * sizeof(char));
  1275.  
  1276.     // actually load the string now that we have the space
  1277.     result = RegQueryValueEx(hKeyRet,
  1278.                               (char *) "CurrentUser",
  1279.                               NULL,
  1280.                               &type,
  1281.                               (LPBYTE) pString,
  1282.                               &size);
  1283.  
  1284.     if((result != ERROR_SUCCESS) || (size == 0))
  1285.         return NULL;
  1286.     if (hKeyRet) RegCloseKey(hKeyRet);
  1287.     return pString;
  1288. #else
  1289.     auto char ca_iniBuff[_MAX_PATH];
  1290.     CString csNSCPini;
  1291.     login_GetIniFilePath(csNSCPini);
  1292.  
  1293.     if (::GetPrivateProfileString("Users Additional Info", "CurrentUser","",ca_iniBuff,_MAX_PATH,csNSCPini))
  1294.         return XP_STRDUP(ca_iniBuff);
  1295.     else return NULL;
  1296. #endif
  1297. }
  1298.  
  1299. char *login_GetUserByName(const char *userName) {
  1300.     long result;
  1301.     char            *matchedProfile = NULL;
  1302.  
  1303. #ifdef XP_WIN32
  1304.     HKEY            hKeyRet;
  1305.     CString         csSub = "SOFTWARE\\Netscape\\Netscape Navigator\\Users\\";
  1306.     DWORD           keyIndex = 0, usernameLen;
  1307.     auto char       subkeyName[MAX_PATH+1];
  1308.     char            *pUserString;
  1309.     
  1310.     result = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
  1311.                         csSub,
  1312.                         NULL,
  1313.                         KEY_READ,
  1314.                         &hKeyRet);
  1315.  
  1316.     while ((result == ERROR_SUCCESS) && (!matchedProfile)) {
  1317.         if ((result = RegEnumKey(hKeyRet,
  1318.                     keyIndex++,
  1319.                     subkeyName,
  1320.                     MAX_PATH+1)) == ERROR_SUCCESS) {
  1321.             CString         csKeyName = csSub + subkeyName;
  1322.             HKEY            hSubkeyRet;
  1323.             
  1324.             if ((result = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
  1325.                                 csKeyName,
  1326.                                 NULL,
  1327.                                 KEY_READ,
  1328.                                 &hSubkeyRet)) == ERROR_SUCCESS) {
  1329.  
  1330.                 // see how much space we need
  1331.                 usernameLen = 0;
  1332.                 result = RegQueryValueEx(hSubkeyRet,
  1333.                                           (char *) "UserName",
  1334.                                           NULL,
  1335.                                           NULL,
  1336.                                           NULL,
  1337.                                           &usernameLen);
  1338.  
  1339.                 if (result == ERROR_SUCCESS) {
  1340.                     // allocate space to hold the string
  1341.                     pUserString = (char *) XP_ALLOC(usernameLen * sizeof(char));
  1342.  
  1343.                     if (pUserString) {
  1344.                         // actually load the string now that we have the space
  1345.                         result = RegQueryValueEx(hSubkeyRet,
  1346.                                                   (char *) "UserName",
  1347.                                                   NULL,
  1348.                                                   NULL,
  1349.                                                   (LPBYTE) pUserString,
  1350.                                                   &usernameLen);
  1351.  
  1352.                         if ((result == ERROR_SUCCESS) && (XP_STRCMP(pUserString, userName) == 0)) {
  1353.                             matchedProfile = XP_STRDUP(subkeyName);
  1354.                         }
  1355.  
  1356.                         XP_FREE(pUserString);
  1357.                     }
  1358.                 }
  1359.  
  1360.             RegCloseKey(hSubkeyRet);
  1361.             }
  1362.             // if we have a problem reading this entry, still go on to the next
  1363.             result = ERROR_SUCCESS;
  1364.         }
  1365.  
  1366.     }
  1367.  
  1368.     RegCloseKey(hKeyRet);
  1369.  
  1370. #else
  1371. /*    CString csNSCPini;
  1372.     login_GetIniFilePath(csNSCPini);
  1373.  
  1374.     result = ::WritePrivateProfileString("Users", profileName, NULL,csNSCPini);     */
  1375. #endif
  1376.     return matchedProfile;
  1377. }
  1378.  
  1379.  
  1380. char *login_GetUserByEmail(const char *email) {
  1381.     long result;
  1382.     char            *matchedProfile = NULL;
  1383.  
  1384. #ifdef XP_WIN32
  1385.     HKEY            hKeyRet;
  1386.     CString         csSub = "SOFTWARE\\Netscape\\Netscape Navigator\\Users\\";
  1387.     DWORD           keyIndex = 0, emailLen;
  1388.     auto char       subkeyName[MAX_PATH+1];
  1389.     char            *pEmailString;
  1390.     
  1391.     result = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
  1392.                         csSub,
  1393.                         NULL,
  1394.                         KEY_READ,
  1395.                         &hKeyRet);
  1396.  
  1397.     while ((result == ERROR_SUCCESS) && (!matchedProfile)) {
  1398.         if ((result = RegEnumKey(hKeyRet,
  1399.                     keyIndex++,
  1400.                     subkeyName,
  1401.                     MAX_PATH+1)) == ERROR_SUCCESS) {
  1402.             CString         csKeyName = csSub + subkeyName;
  1403.             HKEY            hSubkeyRet;
  1404.             
  1405.             if ((result = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
  1406.                                 csKeyName,
  1407.                                 NULL,
  1408.                                 KEY_READ,
  1409.                                 &hSubkeyRet)) == ERROR_SUCCESS) {
  1410.  
  1411.                 // see how much space we need
  1412.                 emailLen = 0;
  1413.                 result = RegQueryValueEx(hSubkeyRet,
  1414.                                           (char *) "EmailAddr",
  1415.                                           NULL,
  1416.                                           NULL,
  1417.                                           NULL,
  1418.                                           &emailLen);
  1419.  
  1420.                 if (result == ERROR_SUCCESS) {
  1421.                     // allocate space to hold the string
  1422.                     pEmailString = (char *) XP_ALLOC(emailLen * sizeof(char));
  1423.  
  1424.                     if (pEmailString) {
  1425.                         // actually load the string now that we have the space
  1426.                         result = RegQueryValueEx(hSubkeyRet,
  1427.                                                   (char *) "EmailAddr",
  1428.                                                   NULL,
  1429.                                                   NULL,
  1430.                                                   (LPBYTE) pEmailString,
  1431.                                                   &emailLen);
  1432.  
  1433.                         if ((result == ERROR_SUCCESS) && (XP_STRCMP(pEmailString, email) == 0)) {
  1434.                             matchedProfile = XP_STRDUP(subkeyName);
  1435.                         }
  1436.  
  1437.                         XP_FREE(pEmailString);
  1438.                     }
  1439.                 }
  1440.  
  1441.             RegCloseKey(hSubkeyRet);
  1442.             }
  1443.             // if we have a problem reading this entry, still go on to the next
  1444.             result = ERROR_SUCCESS;
  1445.         }
  1446.  
  1447.     }
  1448.  
  1449.     RegCloseKey(hKeyRet);
  1450.  
  1451. #else
  1452. /*    CString csNSCPini;
  1453.     login_GetIniFilePath(csNSCPini);
  1454.  
  1455.     result = ::WritePrivateProfileString("Users", profileName, NULL,csNSCPini);     */
  1456. #endif
  1457.     return matchedProfile;
  1458. }
  1459.  
  1460.  
  1461. #ifdef XP_WIN32
  1462. #define MY_FINDFIRST(a,b) FindFirstFile(a,b) 
  1463. #define MY_FINDNEXT(a,b) FindNextFile(a,b) 
  1464. #define ISDIR(a) (a.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) 
  1465. #define MY_FINDCLOSE(a) FindClose(a) 
  1466. #define MY_FILENAME(a) a.cFileName
  1467. #define MY_FILESIZE(a) (a.nFileSizeHigh * MAXDWORD) + a.nFileSizeLow
  1468. #else
  1469. static unsigned u_finding = _A_NORMAL | _A_RDONLY | _A_ARCH | _A_SUBDIR;
  1470.  
  1471. #define MY_FINDFIRST(a,b) (_dos_findfirst(a,u_finding,b)==0)
  1472. #define MY_FINDNEXT(a,b) (_dos_findnext(b)==0) 
  1473. #define ISDIR(a) (a.attrib & _A_SUBDIR)  
  1474. #define MY_FINDCLOSE(a) a=INVALID_HANDLE_VALUE 
  1475. #define MY_FILENAME(a) a.name
  1476. #define MY_FILESIZE(a) a.size
  1477. #endif
  1478.  
  1479. int WFEU_CheckDiskSpaceForMove(CString src,CString dst,uint32 * iSpaceNeeded)
  1480. {
  1481. #ifdef XP_WIN16
  1482.     struct _find_t data_ptr;
  1483.     unsigned find_handle;
  1484. #else
  1485.     WIN32_FIND_DATA data_ptr;
  1486.     HANDLE find_handle;
  1487. #endif
  1488.  
  1489.     // Append slash to the end of the directory names if not there
  1490.     if (dst.Right(1) != "\\")
  1491.         dst += "\\";
  1492.  
  1493.     if (src.Right(1) != "\\")
  1494.         src += "\\";
  1495.  
  1496.     find_handle = MY_FINDFIRST(src+"*.*", &data_ptr);
  1497.  
  1498.     if (find_handle != INVALID_HANDLE_VALUE) {
  1499.         do  {
  1500.  
  1501.             if (ISDIR(data_ptr)
  1502.                 && (strcmpi(MY_FILENAME(data_ptr),"."))
  1503.                 && (strcmpi(MY_FILENAME(data_ptr),".."))) {
  1504.                     WFEU_CheckDiskSpaceForMove(
  1505.                         src + MY_FILENAME(data_ptr),
  1506.                         dst + MY_FILENAME(data_ptr),
  1507.                         iSpaceNeeded);
  1508.             }
  1509.             else if (!ISDIR(data_ptr)) {
  1510.                 *iSpaceNeeded+= MY_FILESIZE(data_ptr);
  1511.             }
  1512.         } while(MY_FINDNEXT(find_handle,&data_ptr));
  1513.         MY_FINDCLOSE(find_handle);
  1514.     }
  1515.     return TRUE;
  1516. }
  1517.  
  1518. #ifndef XP_WIN16
  1519. // doesn't work in win16...copy individual files
  1520. int WFEU_MoveDirectorySameDrive(CString src,CString dst,CUpdateFileDlg * pDlg,char *category) 
  1521. {
  1522.     // Append slash to the end of the directory names if not there
  1523.     if (dst.Right(1) != "\\")
  1524.         dst += "\\";
  1525.  
  1526.     if (src.Right(1) != "\\")
  1527.         src += "\\";
  1528.  
  1529.     // update status dialog
  1530.     if (pDlg) pDlg->StartFileUpdate(category,(char *)(const char *)src);
  1531.  
  1532.     BOOL bRet = WFE_MoveFile(src,dst);
  1533.     return (bRet);
  1534. }
  1535. #endif
  1536.  
  1537. // 
  1538. int WFEU_MoveDirectoryRecursiveDiffDrive(CString src,CString dst,CUpdateFileDlg * pDlg,char *category,XP_Bool bCopyDontMove) 
  1539. {
  1540. #ifdef XP_WIN16
  1541.     struct _find_t data_ptr;
  1542.     unsigned find_handle;
  1543. #else
  1544.     WIN32_FIND_DATA data_ptr;
  1545.     HANDLE find_handle;
  1546. #endif
  1547.  
  1548. #ifdef XP_WIN16
  1549.     // before the extra slash
  1550.     _mkdir(dst);
  1551. #endif
  1552.     // Append slash to the end of the directory names if not there
  1553.     if (dst.Right(1) != "\\")
  1554.         dst += "\\";
  1555.  
  1556.     if (src.Right(1) != "\\")
  1557.         src += "\\";
  1558.  
  1559. #ifdef XP_WIN32
  1560.     // this wants (or at least tolerates the extra slash)
  1561.     CreateDirectory(dst, NULL);
  1562. #endif
  1563.     find_handle = MY_FINDFIRST(src+"*.*", &data_ptr);
  1564.     if (find_handle != INVALID_HANDLE_VALUE) {
  1565.         do  {
  1566.             if (ISDIR(data_ptr) 
  1567.                 && (strcmpi(MY_FILENAME(data_ptr),"."))
  1568.                 && (strcmpi(MY_FILENAME(data_ptr),".."))) {
  1569.                     WFEU_MoveDirectoryRecursiveDiffDrive(
  1570.                         src + MY_FILENAME(data_ptr), 
  1571.                         dst + MY_FILENAME(data_ptr),
  1572.                         pDlg,
  1573.                         category,
  1574.                         bCopyDontMove);
  1575.             }
  1576.             else if (!ISDIR(data_ptr)) {
  1577.                 if (pDlg) pDlg->StartFileUpdate(category,MY_FILENAME(data_ptr));
  1578.                 if (bCopyDontMove)
  1579.                     WFE_CopyFile(src + MY_FILENAME(data_ptr), dst + MY_FILENAME(data_ptr));
  1580.                 else
  1581.                     WFE_MoveFile(src + MY_FILENAME(data_ptr), dst + MY_FILENAME(data_ptr));
  1582.             }
  1583.         } while(MY_FINDNEXT(find_handle,&data_ptr));
  1584.         MY_FINDCLOSE(find_handle);
  1585.         return TRUE;
  1586.     }
  1587.     return FALSE;
  1588. }
  1589.  
  1590. // duplicate of line #1323 in mknewsgr.c -- Bad but don't wanna mess with header files
  1591. #define NEWSRC_MAP_FILE_COOKIE "netscape-newsrc-map-file"
  1592.  
  1593. int     WFEU_UpdateNewsFatFile(CString src,CString dst)
  1594. {
  1595.     XP_File src_fp,dst_fp;
  1596.     XP_StatStruct stats;
  1597.     long fileLength;
  1598.     CString csSrcFat,csDstFat;
  1599.  
  1600.         // Append slash to the end of the directory names if not there
  1601.     if (dst.Right(1) != "\\")
  1602.         dst += "\\";
  1603.  
  1604.     if (src.Right(1) != "\\")
  1605.         src += "\\";
  1606.  
  1607.     csSrcFat = src + "fat";
  1608.     csDstFat = dst + "fat.new";
  1609.  
  1610.     if (_stat(csSrcFat, &stats) == -1)
  1611.         return FALSE;
  1612.  
  1613.     fileLength = stats.st_size;
  1614.     if (fileLength <= 1)
  1615.         return FALSE;
  1616.     
  1617.     src_fp = fopen(csSrcFat, "r");
  1618.     dst_fp = fopen(csDstFat, "wb");
  1619.  
  1620.     if (src_fp && dst_fp) { 
  1621.         char buffer[512];
  1622.         char psuedo_name[512];
  1623.         char filename[512];
  1624.         char is_newsgroup[512];
  1625.  
  1626.         // This code is all stolen from mknewsgr.c -- written by JRE
  1627.  
  1628.         /* get the cookie and ignore */
  1629.         XP_FileReadLine(buffer, sizeof(buffer), src_fp);
  1630.  
  1631.         XP_FileWrite(NEWSRC_MAP_FILE_COOKIE, XP_STRLEN(NEWSRC_MAP_FILE_COOKIE), dst_fp);
  1632.         XP_FileWrite(LINEBREAK, XP_STRLEN(LINEBREAK), dst_fp);
  1633.  
  1634.         while(XP_FileReadLine(buffer, sizeof(buffer), src_fp))
  1635.           {
  1636.             char * p;
  1637.             int i;
  1638.             
  1639.             filename[0] = '\0';
  1640.             is_newsgroup[0]='\0';
  1641.  
  1642.             for (i = 0, p = buffer; *p && *p != '\t' && i < 500; p++, i++)
  1643.                 psuedo_name[i] = *p;
  1644.             psuedo_name[i] = '\0';
  1645.             if (*p) 
  1646.               {
  1647.                 for (i = 0, p++; *p && *p != '\t' && i < 500; p++, i++)
  1648.                     filename[i] = *p;
  1649.                 filename[i]='\0';
  1650.                 if (*p) 
  1651.                   {
  1652.                     for (i = 0, p++; *p && *p != '\r' && *p != '\n' && i < 500; p++, i++)
  1653.                         is_newsgroup[i] = *p;
  1654.                     is_newsgroup[i]='\0';
  1655.                   }
  1656.               }
  1657.  
  1658.             CString csFilename = filename;
  1659.             CString csDestFilename = dst;
  1660.             int iLastSlash = csFilename.ReverseFind('\\');
  1661.  
  1662.             if (iLastSlash != -1) {
  1663.                 csDestFilename += csFilename.Right(csFilename.GetLength()-iLastSlash-1);
  1664.             } else 
  1665.                 csDestFilename += filename;
  1666.  
  1667.             // write routines stolen from mknewsgr.c -- line #1348
  1668.             XP_FileWrite(psuedo_name, XP_STRLEN(psuedo_name),dst_fp);
  1669.             
  1670.             XP_FileWrite("\t", 1, dst_fp);
  1671.  
  1672.             XP_FileWrite((const char *)csDestFilename, csDestFilename.GetLength() , dst_fp);
  1673.             
  1674.             XP_FileWrite("\t", 1, dst_fp);
  1675.  
  1676.             XP_FileWrite(is_newsgroup, XP_STRLEN(is_newsgroup), dst_fp);
  1677.  
  1678.             XP_FileWrite(LINEBREAK, XP_STRLEN(LINEBREAK), dst_fp);
  1679.  
  1680.           }
  1681.         XP_FileClose(src_fp);
  1682.         XP_FileClose(dst_fp);
  1683.     } else
  1684.         return FALSE;
  1685.     
  1686.     return TRUE;
  1687. }
  1688.  
  1689. int WFEU_UpdaterCopyDirectory(CString src,CString dst,CUpdateFileDlg * pDlg,char *category) 
  1690. {
  1691.     uint32 iSpaceNeeded = 0;
  1692.     uint32 iSpaceAvailable = 0;
  1693.     DWORD dwSectorsPerCluster, dwBytesPerSector, dwNumFreeClusters, dwTotalClusters;
  1694.     
  1695.     // assumes properly formated destination string
  1696.     GetDiskFreeSpace(dst.Left(3),&dwSectorsPerCluster,&dwBytesPerSector,
  1697.         &dwNumFreeClusters,&dwTotalClusters);
  1698.  
  1699.     iSpaceAvailable = (dwNumFreeClusters * dwSectorsPerCluster * dwBytesPerSector);
  1700.     WFEU_CheckDiskSpaceForMove(src,dst,&iSpaceNeeded);
  1701.     while (iSpaceNeeded > iSpaceAvailable) {
  1702.         char szLen[64];
  1703.         _ltoa(((iSpaceNeeded-iSpaceAvailable)/1024)/1024,szLen,10);
  1704.  
  1705.         char szMsg[1024];
  1706.         sprintf(szMsg, szLoadString(IDS_INSUFFICIENT_DISKSPACE_COPY), category, src, dst, szLen);
  1707.  
  1708.         if (AfxMessageBox(szMsg,MB_OKCANCEL) == IDCANCEL)
  1709.             return FALSE;
  1710.         GetDiskFreeSpace(dst.Left(3),&dwSectorsPerCluster,&dwBytesPerSector,
  1711.             &dwNumFreeClusters,&dwTotalClusters);
  1712.         iSpaceAvailable = (dwNumFreeClusters * dwSectorsPerCluster * dwBytesPerSector);
  1713.     }
  1714.     return WFEU_MoveDirectoryRecursiveDiffDrive(src,dst,pDlg,category,TRUE);
  1715. }
  1716.  
  1717. int WFEU_UpdaterMoveDirectory(CString src,CString dst,CUpdateFileDlg * pDlg,char *category) 
  1718. {
  1719. #ifndef XP_WIN16
  1720.     // directory rename doesn't work under win16
  1721.     int iDiffDrive = src.Left(2).CompareNoCase(dst.Left(2));
  1722.  
  1723.     if (!iDiffDrive) {
  1724.         int iRet = WFEU_MoveDirectorySameDrive(src,dst,pDlg,category);
  1725.         if (iRet)
  1726.             return iRet;
  1727.     }
  1728. #else
  1729.     int iDiffDrive = TRUE;
  1730. #endif
  1731.     // else if DiffDrive or if move same drive failed...
  1732.  
  1733.     if (iDiffDrive) {
  1734.         uint32 iSpaceNeeded = 0;
  1735.         uint32 iSpaceAvailable = 0;
  1736.         DWORD dwSectorsPerCluster, dwBytesPerSector, dwNumFreeClusters, dwTotalClusters;
  1737.         
  1738.         // assumes properly formated destination string
  1739.         GetDiskFreeSpace(dst.Left(3),&dwSectorsPerCluster,&dwBytesPerSector,
  1740.             &dwNumFreeClusters,&dwTotalClusters);
  1741.  
  1742.         iSpaceAvailable = (dwNumFreeClusters * dwSectorsPerCluster * dwBytesPerSector);
  1743.         WFEU_CheckDiskSpaceForMove(src,dst,&iSpaceNeeded);
  1744.         while (iSpaceNeeded > iSpaceAvailable) {
  1745.             char szLen[64];
  1746.             _ltoa(((iSpaceNeeded-iSpaceAvailable)/1024)/1024,szLen,10);
  1747.  
  1748.             char szMsg[1024];
  1749.             sprintf(szMsg, szLoadString(IDS_INSUFFICIENT_DISKSPACE_MOVE), category, src, dst, szLen);
  1750.  
  1751.             if (AfxMessageBox(szMsg,MB_OKCANCEL) == IDCANCEL)
  1752.                 return FALSE;
  1753.             GetDiskFreeSpace(dst.Left(3),&dwSectorsPerCluster,&dwBytesPerSector,
  1754.                 &dwNumFreeClusters,&dwTotalClusters);
  1755.             iSpaceAvailable = (dwNumFreeClusters * dwSectorsPerCluster * dwBytesPerSector);
  1756.         }
  1757.     }
  1758.     return WFEU_MoveDirectoryRecursiveDiffDrive(src,dst,pDlg,category,FALSE);
  1759. }
  1760.  
  1761.  
  1762. static struct update_PrefTable prefUpdater[] =
  1763. {
  1764.   {"browser.cache.disk_cache_ssl","Cache","Disk Cache SSL",PREF_BOOL},
  1765.   {"browser.cache.disk_cache_size","Cache","Disk Cache Size",PREF_INT},
  1766.   {"browser.cache.memory_cache_size","Cache","Memory Cache Size",PREF_INT},
  1767. //
  1768.   {"security.enable_java","Java","Enable Java",PREF_BOOL},
  1769.   {"security.enable_javascript","Java","Enable JavaScript",PREF_BOOL},
  1770. //  
  1771.   {"mail.check_time","Mail","Check Time",PREF_INT},
  1772.   {"mail.max_size","Mail","Max Size",PREF_INT},
  1773.   {"mail.pop_password","Mail","POP Password",PREF_CHAR},
  1774.   {"mail.pop_name","Mail","POP Name",PREF_CHAR},
  1775.   {"mail.leave_on_server","Mail","Leave on server",PREF_BOOL},
  1776.   {"mail.auto_quote","Mail","Auto quote",PREF_BOOL},
  1777.   {"mail.remember_password","Mail","Remember Password",PREF_BOOL},
  1778. //
  1779.   {"browser.underline_anchors","Main","Anchor Underline",PREF_BOOL},
  1780.   {"browser.cache.check_doc_frequency","Main","Check Server",PREF_INT},
  1781.   {"browser.download_directory","Main","Default Save Dir",PREF_CHAR},
  1782.   {"browser.wfe.ignore_def_check","Main","Ignore DefCheck",PREF_BOOL},
  1783.   {"browser.startup.homepage","Main","Home Page",PREF_CHAR},
  1784. //
  1785.   {"security.submit_email_forms","Network","Warn Submit Email Form",PREF_BOOL},
  1786.   {"security.email_as_ftp_password","Network","Use Email For FTP",PREF_BOOL},
  1787.   {"network.cookie.warnAboutCookies","Network","Warn Accepting Cookie",PREF_BOOL},
  1788.   {"network.max_connections","Network","Max Connections",PREF_INT},
  1789.   {"network.tcpbufsize","Network","TCP Buffer Size",PREF_INT},
  1790. //
  1791.   {"news.max_articles","News","News Chunk Size",PREF_INT},
  1792.   {"news.show_headers","News","Show Headers",PREF_INT},
  1793.   {"news.sort_by","News","Sort News",PREF_INT},
  1794.   {"news.thread_news","News","Thread News",PREF_BOOL},
  1795. //
  1796.   {"network.proxy.autoconfig_url","Proxy Information","Auto Config Url",PREF_CHAR},
  1797.   {"network.proxy.type","Proxy Information","Proxy Type",PREF_INT},
  1798.   {"network.proxy.wais_port","Proxy Information","Wais_ProxyPort",PREF_INT},
  1799.   {"network.proxy.ftp_port","Proxy Information","Ftp_ProxyPort",PREF_INT},
  1800.   {"network.proxy.ssl_port","Proxy Information","HTTPS_ProxyPort",PREF_INT},
  1801.   {"network.proxy.gopher_port","Proxy Information","Gopher_ProxyPort",PREF_INT},
  1802.   {"network.proxy.http_port","Proxy Information","Http_ProxyPort",PREF_INT},
  1803.   {"network.proxy.no_proxies_on","Proxy Information","No_Proxy",PREF_CHAR},
  1804.   {"network.proxy.wais","Proxy Information","Wais_Proxy",PREF_CHAR},
  1805.   {"network.proxy.ssl","Proxy Information","HTTPS_Proxy",PREF_CHAR},
  1806.   {"network.proxy.gopher","Proxy Information","Gopher_Proxy",PREF_CHAR},
  1807.   {"network.proxy.ftp","Proxy Information","FTP_Proxy",PREF_CHAR},
  1808.   {"network.proxy.http","Proxy Information","HTTP_Proxy",PREF_CHAR},
  1809. //
  1810.   {"security.warn_submit_insecure","Security","Warn Insecure Forms",PREF_BOOL},
  1811.   {"security.default_personal_cert","Security","Default User Cert",PREF_CHAR},
  1812.   {"security.enable_ssl3","Security","Enable SSL v3",PREF_BOOL},
  1813.   {"security.enable_ssl2","Security","Enable SSL v2",PREF_BOOL},
  1814.   {"security.ask_for_password","Security","Ask for password",PREF_INT},
  1815.   {"security.password_lifetime","Security","Password Lifetime",PREF_INT},
  1816.   {"security.warn_entering_secure","Security","Warn Entering",PREF_BOOL},
  1817.   {"security.warn_leaving_secure","Security","Warn Leaving",PREF_BOOL},
  1818.   {"security.warn_viewing_mixed","Security","Warn Mixed",PREF_BOOL},
  1819.   {"security.ciphers","Security","Cipher Prefs",PREF_CHAR},
  1820. //
  1821.   {"mail.use_exchange","Services","Mapi",PREF_BOOL},
  1822.   {"network.hosts.socks_serverport","Services","SOCKS_ServerPort",PREF_INT},
  1823.   {"network.hosts.socks_conf","Services","Socks Conf",PREF_CHAR},
  1824.   {"network.hosts.pop_server","Services","POP_Server",PREF_CHAR},
  1825.   {"network.hosts.nntp_server","Services","NNTP_Server",PREF_CHAR},
  1826.   {"network.hosts.smtp_server","Services","SMTP_Server",PREF_CHAR},
  1827.   {"network.hosts.socks_server","Services","SOCKS_Server",PREF_CHAR},
  1828. //
  1829.   {"mail.fixed_width_messages","Settings","Fixed Width Messages",PREF_BOOL},
  1830.   {"mail.quoted_style","Settings","Quoted Style",PREF_INT},
  1831.   {"mail.quoted_size","Settings","Quoted Size",PREF_INT},
  1832.   {"browser.blink_allowed","Settings","Blinking",PREF_BOOL},
  1833.   {"browser.link_expiration","Settings","History Expiration",PREF_INT},
  1834. //
  1835.   {"mail.identity.reply_to","User","Reply_To",PREF_CHAR},
  1836.   {"mail.identity.organization","User","User_Organization",PREF_CHAR},
  1837.   {"mail.signature_file","User","Sig_File",PREF_CHAR},
  1838. //
  1839.   {"editor.publish_location", "Publish", "Default Location", PREF_CHAR},
  1840.   {"editor.publish_browse_location", "Publish", "Default Browse Location", PREF_CHAR},
  1841. //
  1842.   {NULL,NULL,NULL,NULL}
  1843. };
  1844.  
  1845. int     login_UpdatePreferencesToJavaScript(const char * path)
  1846. {
  1847.     int idx=0;
  1848.     while (prefUpdater[idx].xp_name) {
  1849.         if (prefUpdater[idx].type == PREF_CHAR) {// char pref 
  1850.             CString csPref= theApp.GetProfileString(prefUpdater[idx].section,prefUpdater[idx].name,"");
  1851.             if (!csPref.IsEmpty())
  1852.                 PREF_SetCharPref(prefUpdater[idx].xp_name,(char *)(const char *)csPref);
  1853.         } else if (prefUpdater[idx].type == PREF_INT) {// char pref 
  1854.             int iPref= theApp.GetProfileInt(prefUpdater[idx].section,prefUpdater[idx].name,-1);
  1855.             if (iPref != -1)
  1856.                 PREF_SetIntPref(prefUpdater[idx].xp_name,iPref);
  1857.         } else if (prefUpdater[idx].type == PREF_BOOL) {// char pref 
  1858.             CString csPref= theApp.GetProfileString(prefUpdater[idx].section,prefUpdater[idx].name,"");
  1859.             if (!csPref.IsEmpty()) {
  1860.                 int iRet = csPref.CompareNoCase("yes");
  1861.                 if (iRet ==0)
  1862.                     PREF_SetBoolPref(prefUpdater[idx].xp_name,TRUE);
  1863.                 else
  1864.                     PREF_SetBoolPref(prefUpdater[idx].xp_name,FALSE);
  1865.             }
  1866.         }
  1867.         idx++;
  1868.     }
  1869.  
  1870.     // Do some special hacking on "browser.cache.check_doc_frequency" since the values changed
  1871.     // between 3.0 and 4.0
  1872.     int32 iExpr;
  1873.  
  1874.     PREF_GetIntPref("browser.cache.check_doc_frequency",&iExpr);
  1875.     if (iExpr == 1)
  1876.         PREF_SetIntPref("browser.cache.check_doc_frequency",0);
  1877.     else if (iExpr == 0)
  1878.         PREF_SetIntPref("browser.cache.check_doc_frequency",1);
  1879.  
  1880.     // Do some special processing for history link expiration. It used to be that there
  1881.     // was an option that history never expired. We no longer support that, in the UI
  1882.     // anyway
  1883.     int32   iExp;
  1884.  
  1885.     PREF_GetIntPref("browser.link_expiration", &iExp);
  1886.     if (iExp == -1) {
  1887.         // Set the date to something safe like 6 months
  1888.         PREF_SetIntPref("browser.link_expiration", 180);
  1889.     }
  1890.  
  1891.     CString csPref= theApp.GetProfileString("Main","Autoload Home Page","");
  1892.     if (!csPref.IsEmpty()) {
  1893.         if (!csPref.CompareNoCase("yes"))
  1894.             PREF_SetIntPref("browser.startup.page", 1);  // set to load homepage
  1895.         else
  1896.             PREF_SetIntPref("browser.startup.page", 0);  // set to blank
  1897.     }
  1898.     return TRUE;
  1899. }
  1900.  
  1901. void login_CreateEmptyProfileDir(const char * dst, CWnd * pParent, BOOL bExistingDir) 
  1902. {
  1903.         CString csTmp;
  1904.         
  1905.         csTmp = dst;
  1906.         csTmp += "\\News";
  1907.         _mkdir(csTmp);
  1908.  
  1909.         csTmp = dst;
  1910.         csTmp += "\\Mail";
  1911.         _mkdir(csTmp);
  1912.         
  1913.         csTmp = dst;
  1914.         csTmp += "\\Cache";
  1915.         _mkdir(csTmp);
  1916.  
  1917.         csTmp = dst;
  1918.         csTmp += "\\NavCntr";
  1919.         _mkdir(csTmp);
  1920.  
  1921.         if (!bExistingDir) login_CopyStarterFiles(dst,pParent);
  1922. }
  1923.  
  1924. /* The following has to be declared extern "C" because it's called from some Java
  1925.    native code written in C. */
  1926. extern "C"
  1927. char * login_GetUserProfileDir()
  1928. {
  1929.     char    *pString = NULL;
  1930.  
  1931.     /* First, get the user's profile name */
  1932.      char    *name = login_GetCurrentUser();
  1933.  
  1934. #ifdef XP_WIN32
  1935.     char    path[MAX_PATH+1];
  1936.     long    result;
  1937.     DWORD   type, size;
  1938.     HKEY    hKeyRet;
  1939.  
  1940.      /* get profile path */
  1941.     strcpy(path, "SOFTWARE\\Netscape\\Netscape Navigator\\Users");
  1942.     strcat(path, "\\");
  1943.     strcat(path, name);
  1944.  
  1945.     if (ERROR_SUCCESS == RegOpenKey(HKEY_LOCAL_MACHINE, path, &hKeyRet)) 
  1946.     {
  1947.         // see how much space we need
  1948.         size = 0;
  1949.         result = RegQueryValueEx(hKeyRet, "DirRoot", NULL, &type, NULL, &size);
  1950.  
  1951.         // if we didn't find it just use the default
  1952.         if((result == ERROR_SUCCESS) && (size != 0)) 
  1953.         {
  1954.             // allocate space to hold the string
  1955.             pString = (char *) XP_ALLOC(size * sizeof(char));
  1956.  
  1957.             // actually load the string now that we have the space
  1958.             result = RegQueryValueEx(hKeyRet, "DirRoot", NULL, &type, (LPBYTE) pString, &size);
  1959.     
  1960.             if (hKeyRet) RegCloseKey(hKeyRet);
  1961.         }
  1962.     }
  1963.  
  1964. #else
  1965.     CString csNSCPini;
  1966.     login_GetIniFilePath(csNSCPini);
  1967.  
  1968.     pString = (char *) XP_ALLOC(_MAX_PATH * sizeof(char));
  1969.     ::GetPrivateProfileString("Users", name,"",pString,_MAX_PATH,csNSCPini);
  1970. #endif
  1971.  
  1972.     XP_FREE(name);
  1973.  
  1974.     // The string has to be freed by the caller
  1975.     return pString;
  1976. }
  1977.  
  1978. void login_CopyStarterFiles(const char * dst, CWnd *pParent)
  1979. {
  1980.     CString csDst = dst;
  1981.     CString csSrc;
  1982.     char aPath[_MAX_PATH];
  1983.     CUpdateFileDlg * pDlg = new CUpdateFileDlg(pParent,TRUE);
  1984.  
  1985.     ::GetModuleFileName(theApp.m_hInstance, aPath, _MAX_PATH);
  1986.  
  1987.     //    Find the trailing slash.
  1988.     char *pSlash = ::strrchr(aPath, '\\');
  1989.     if(pSlash)    {
  1990.         *pSlash = '\0';
  1991.     }
  1992.     else    {
  1993.         aPath[0] = '\0';
  1994.     }
  1995.     if (!(aPath && aPath[0])) return;
  1996.     if (!dst) return;
  1997.     if (!pDlg) return;
  1998.  
  1999.     csSrc = aPath;
  2000.     csSrc += "\\defaults";
  2001.     csDst = dst;
  2002.     WFEU_UpdaterCopyDirectory(csSrc,csDst,pDlg,"Default Files");
  2003.  
  2004.     // PE doesn't have a parent window to attach pDlg to.
  2005.     if (!pParent)         // For now, this will be PE specific.  JonM will decide if it's always...
  2006.         delete pDlg;
  2007. }
  2008.  
  2009. int     login_UpdateFilesToNewLocation(const char * path,CWnd *pParent,BOOL bCopyDontMove)
  2010. {
  2011.     CString csTmp;
  2012.     
  2013.     if (!path) return FALSE;
  2014.  
  2015.     CUpdateFileDlg * pDlg = new CUpdateFileDlg(pParent,bCopyDontMove);
  2016.  
  2017.     CString csMain = theApp.GetProfileString("Main","Install Directory","");
  2018.  
  2019.     CString csBookmarks = theApp.GetProfileString("Bookmark List","File Location","");
  2020.     if (!csBookmarks.IsEmpty()) {
  2021.         csTmp = path;
  2022.         csTmp += "\\bookmark.htm";
  2023.         pDlg->StartFileUpdate("General Files","bookmark.htm");
  2024.         if (bCopyDontMove) {
  2025.             WFE_CopyFile(csBookmarks,csTmp);
  2026.         } else {
  2027.             if (WFE_MoveFile(csBookmarks,csTmp))
  2028.                 theApp.WriteProfileString("Bookmark List","File Location",csTmp);
  2029.         }
  2030.     }
  2031.  
  2032.     CString csABook = theApp.GetProfileString("Address Book","File Location","");
  2033.     if (!csABook.IsEmpty()) {
  2034.         csTmp = path;
  2035.         csTmp += "\\address.htm";
  2036.         pDlg->StartFileUpdate("General Files","address.htm");
  2037.         if (bCopyDontMove) {
  2038.             WFE_CopyFile(csABook,csTmp);
  2039.         } else {
  2040.             if (WFE_MoveFile(csABook,csTmp))
  2041.                 theApp.WriteProfileString("Address Book","File Location",csTmp);
  2042.         }
  2043.     } else {
  2044.         if (!csMain.IsEmpty()) {
  2045.             csTmp = path;
  2046.             csTmp += "\\address.htm";
  2047.             pDlg->StartFileUpdate("General Files","address.htm");
  2048.             WFE_CopyFile(csMain + "\\address.htm" ,csTmp);
  2049.         }
  2050.     }
  2051.  
  2052.     CString csHist = theApp.GetProfileString("History","History File","");
  2053.     if (!csHist.IsEmpty()) {
  2054.         csTmp = path;
  2055.         csTmp += "\\mozilla.hst";
  2056.         pDlg->StartFileUpdate("General Files","mozilla.hst");
  2057.         if (bCopyDontMove) {
  2058.             WFE_CopyFile(csHist,csTmp);
  2059.         } else {
  2060.             if (WFE_MoveFile(csHist,csTmp))
  2061.                 theApp.WriteProfileString("History","History File",csTmp);
  2062.         }
  2063.     } else {
  2064.         if (!csMain.IsEmpty()) {
  2065.             csTmp = path;
  2066.             csTmp += "\\mozilla.hst";
  2067.             pDlg->StartFileUpdate("General Files","mozilla.hst");
  2068.             WFE_CopyFile(csMain + "\\mozilla.hst" ,csTmp);
  2069.         }
  2070.     }
  2071.  
  2072.     CString csNewsRC = theApp.GetProfileString("Main","News RC","");
  2073.     if (!csNewsRC.IsEmpty()) {
  2074.         csTmp = path;
  2075.         csTmp += "\\Newsrc";
  2076.         pDlg->StartFileUpdate("General Files","Newsrc");
  2077.         if (bCopyDontMove) {
  2078.             WFE_CopyFile(csNewsRC,csTmp);
  2079.         } else {
  2080.             if (WFE_MoveFile(csNewsRC,csTmp))
  2081.                 theApp.WriteProfileString("Main","News RC",csTmp);
  2082.         }
  2083.     } 
  2084.  
  2085.     if (!csMain.IsEmpty()) {
  2086.         // these files are always copied since we don't store pointers
  2087.         csTmp = path;
  2088.         csTmp += "\\socks.cnf";
  2089.         pDlg->StartFileUpdate("General Files","socks.cnf");
  2090.         WFE_CopyFile(csMain + "\\socks.cnf" ,csTmp);
  2091.  
  2092.         csTmp = path;
  2093.         csTmp += "\\cookies.txt";
  2094.         pDlg->StartFileUpdate("General Files","cookies.txt");
  2095.         WFE_CopyFile(csMain + "\\cookies.txt",csTmp);
  2096.  
  2097.         csTmp = path;
  2098.         csTmp += "\\key.db";
  2099.         pDlg->StartFileUpdate("Security Files","key.db");
  2100.         WFE_CopyFile(csMain + "\\key.db",csTmp);
  2101.  
  2102.         csTmp = path;
  2103.         csTmp += "\\cert5.db";
  2104.         pDlg->StartFileUpdate("Security Files","cert5.db");
  2105.         WFE_CopyFile(csMain + "\\cert5.db",csTmp);
  2106.  
  2107.         csTmp = path;
  2108.         csTmp += "\\certni.db";
  2109.         pDlg->StartFileUpdate("Security Files","certni.db");
  2110.         WFE_CopyFile(csMain + "\\certni.db",csTmp);
  2111.  
  2112.         csTmp = path;
  2113.         csTmp += "\\proxy.cfg";
  2114.         pDlg->StartFileUpdate("Network Files","proxy.cfg");
  2115.         WFE_CopyFile(csMain + "\\proxy.cfg",csTmp);
  2116.  
  2117.         csTmp = path;
  2118.         csTmp += "\\abook.nab";
  2119.         if (bCopyDontMove)
  2120.             WFE_CopyFile(csMain + "\\abook.nab",csTmp);
  2121.         else
  2122.             WFE_MoveFile(csMain + "\\abook.nab",csTmp);
  2123.     }
  2124.     csTmp = path;
  2125.     csTmp += "\\Mail";
  2126.     CString csMail = theApp.GetProfileString("Mail","Mail Directory","");
  2127.  
  2128.     if (!strnicmp(csMail,csTmp,strlen(csMail))) {
  2129.         char szMsg[256];
  2130.         _snprintf(szMsg, 256, szLoadString(IDS_UNABLETRANSFER_SUBDIR),"Mail Directory");
  2131.         AfxMessageBox(szMsg);
  2132.     }
  2133.     else {
  2134.         if (bCopyDontMove) {
  2135.             if (!csMail.IsEmpty()) {
  2136.                 WFEU_UpdaterCopyDirectory(csMail,csTmp,pDlg,"Mail Directory");
  2137.             }
  2138.         } else {
  2139.             if ((!csMail.IsEmpty()) && WFEU_UpdaterMoveDirectory(csMail,csTmp,pDlg,"Mail Directory")) {
  2140.                 theApp.WriteProfileString("Mail","Mail Directory",csTmp);
  2141.                 CString csFCC = theApp.GetProfileString("Mail","Default Fcc","");
  2142.                 int iSlash = csFCC.ReverseFind('\\');
  2143.                 if (iSlash != -1) {
  2144.                     CString csFolder = csFCC.Right(csFCC.GetLength()-iSlash);
  2145.                     theApp.WriteProfileString("Mail","Default Fcc",csTmp+csFolder);
  2146.                 }
  2147.             }
  2148.         }
  2149.     }
  2150.  
  2151.     csTmp = path;
  2152.     csTmp += "\\News";
  2153.     CString csNews = theApp.GetProfileString("News","News Directory","");
  2154.  
  2155.     if (!strnicmp(csNews,csTmp,strlen(csNews))) {
  2156.         char szMsg[256];
  2157.         _snprintf(szMsg, 256, szLoadString(IDS_UNABLETRANSFER_SUBDIR),"News Directory");
  2158.         AfxMessageBox(szMsg);
  2159.     }
  2160.     else {
  2161.         if (bCopyDontMove) {
  2162.             if (!csNews.IsEmpty()) {
  2163.                 WFEU_UpdaterCopyDirectory(csNews,csTmp,pDlg,"News Directory");
  2164.             }
  2165.         } else {
  2166.             if ((!csNews.IsEmpty()) && WFEU_UpdaterMoveDirectory(csNews,csTmp,pDlg,"News Directory"))
  2167.                 theApp.WriteProfileString("News","News Directory",csTmp);               
  2168.         }
  2169.         // update news rc file either way to new directory -- creates fat,new
  2170.         int iRet = WFEU_UpdateNewsFatFile(csTmp,csTmp);
  2171.         // now move fat.new over the old fat file
  2172.         if (iRet) {
  2173.             CString csOldFat = csTmp + "\\fat";
  2174.             CString csNewFat = csTmp + "\\fat.new";
  2175.             rename(csOldFat,csTmp + "\\fat.old");
  2176.             rename(csNewFat,csTmp + "\\fat");
  2177.         }
  2178.     }
  2179.  
  2180.     csTmp = path;
  2181.     csTmp += "\\cache";
  2182.     CString csCache = theApp.GetProfileString("Cache","Cache Dir","");
  2183.  
  2184.     if (!strnicmp(csCache,csTmp,strlen(csCache))) {
  2185.         char szMsg[256];
  2186.         _snprintf(szMsg, 256, szLoadString(IDS_UNABLETRANSFER_SUBDIR),"Cache Directory");
  2187.         AfxMessageBox(szMsg);
  2188.     }
  2189.     else {
  2190.         if (bCopyDontMove) {
  2191.             if (!csCache.IsEmpty()) {
  2192.                 WFEU_UpdaterCopyDirectory(csCache,csTmp,pDlg,"Cache Directory");
  2193.             }
  2194.         } else {
  2195.             if ((!csCache.IsEmpty()) && WFEU_UpdaterMoveDirectory(csCache,csTmp,pDlg,"Cache Directory"))
  2196.                 theApp.WriteProfileString("Cache","Cache Dir",csTmp);   
  2197.         }
  2198.     }
  2199.     return TRUE;
  2200. }
  2201.  
  2202. // CUpdateFileDlg dialog
  2203.  
  2204.  
  2205. CUpdateFileDlg::CUpdateFileDlg(CWnd *pParent, BOOL bCopyDontMove)
  2206.     : CDialog(CUpdateFileDlg::IDD, pParent),
  2207.       m_pParent(pParent)
  2208. {
  2209.     //{{AFX_DATA_INIT(CSaveFileDlg)
  2210.         // NOTE: the ClassWizard will add member initialization here
  2211.     //}}AFX_DATA_INIT
  2212.     
  2213.     // Suppress user interaction while we are active!
  2214.     if(pParent){ 
  2215.     pParent->EnableWindow(FALSE);
  2216.     }
  2217.     
  2218.     // For simplicity, create right here
  2219.     if (!CDialog::Create(CUpdateFileDlg::IDD, pParent))
  2220.     {
  2221.     TRACE0("Warning: creation of CUpdateFileDlg dialog failed\n");
  2222.     return;
  2223.     }
  2224.  
  2225.     m_bCopyDontMove = bCopyDontMove;
  2226.  
  2227.     // Clear our place-holder string
  2228.     GetDlgItem(IDC_CATEGORY)->SetWindowText("");
  2229.     GetDlgItem(IDC_TEXT1)->SetWindowText("Note:  If you have large mail or news folders, some of these operations may take a while.  Please be patient.");
  2230.     // Why doesn't this center on parent window automatically!
  2231.     CRect cRectParent;
  2232.     CRect cRectDlg;
  2233.     if( pParent ){
  2234.     pParent->GetWindowRect(&cRectParent);
  2235.     GetWindowRect(&cRectDlg);
  2236.     int iTop = 200;
  2237.     int iLeft = 200;
  2238.     if ( cRectParent.Height() > cRectDlg.Height() ){
  2239.         iTop = cRectParent.top + ( (cRectParent.Height() - cRectDlg.Height()) / 2 );
  2240.     }
  2241.     if ( cRectParent.Width() > cRectDlg.Width() ){
  2242.         iLeft = cRectParent.left + ( (cRectParent.Width() - cRectDlg.Width()) / 2 );
  2243.     }
  2244.     SetWindowPos(&wndTopMost, iLeft, iTop, 0, 0, SWP_NOSIZE);
  2245.     }
  2246.     ShowWindow(SW_SHOW);
  2247. }
  2248.  
  2249. void CUpdateFileDlg::StartFileUpdate(char *category,char * pFilename)
  2250. {
  2251.     GetDlgItem(IDC_CATEGORY)->SetWindowText(category);
  2252.     CString csTmp;
  2253.     
  2254.     if (m_bCopyDontMove)
  2255.         csTmp = "Copying File: ";
  2256.     else
  2257.         csTmp = "Moving File: ";
  2258.     csTmp+=pFilename;
  2259.     GetDlgItem(IDC_FILENAME_AREA)->SetWindowText(csTmp);
  2260.     // Report file number if we have more than 1 total
  2261. }
  2262.  
  2263. void CUpdateFileDlg::DoDataExchange(CDataExchange* pDX)
  2264. {
  2265.     CDialog::DoDataExchange(pDX);
  2266.     //{{AFX_DATA_MAP(CSaveFileDlg)
  2267.         // NOTE: the ClassWizard will add DDX and DDV calls here
  2268.     //}}AFX_DATA_MAP
  2269. }
  2270.  
  2271. BEGIN_MESSAGE_MAP(CUpdateFileDlg, CDialog)
  2272.     //{{AFX_MSG_MAP(CSaveFileDlg)
  2273.     //}}AFX_MSG_MAP
  2274. END_MESSAGE_MAP()
  2275.  
  2276.  
  2277. void CUpdateFileDlg::PostNcDestroy() 
  2278. {
  2279.     CDialog::PostNcDestroy();
  2280.     if( m_pParent && ::IsWindow(m_pParent->m_hWnd) ){
  2281.     m_pParent->EnableWindow(TRUE);
  2282.     // Return focus to parent window
  2283.     m_pParent->SetActiveWindow();
  2284.     m_pParent->SetFocus();
  2285.     }
  2286. }
  2287.  
  2288. #ifdef XP_WIN16
  2289. void login_GetIniFilePath(CString &csNSCPini)
  2290. {
  2291.     // give a chance for win.ini to override the nscp.ini location
  2292.     auto char ca_iniBuff[_MAX_PATH];
  2293.     ::GetProfileString("netscape", "nscpINI", "", ca_iniBuff, _MAX_PATH);
  2294.     if (ca_iniBuff[0]) {
  2295.         csNSCPini = ca_iniBuff;
  2296.         return;
  2297.     }
  2298.  
  2299.     // otherwise fallback on the default
  2300.     GetWindowsDirectory(ca_iniBuff, _MAX_PATH);
  2301.     if (ca_iniBuff[strlen(ca_iniBuff)-1] == '\\')
  2302.         ca_iniBuff[strlen(ca_iniBuff)-1] = 0;
  2303.  
  2304.     csNSCPini = ca_iniBuff;
  2305.     csNSCPini += "\\nscp.ini";
  2306. }
  2307. #endif
  2308.