1 // WinAfsLoadDlg.cpp : implementation file
3 /* Copyright 2000, International Business Machines Corporation and others.
6 This software has been released under the terms of the IBM Public
7 License. For details, see the LICENSE file in the top-level source
8 directory or online at http://www.openafs.org/dl/license10.html
12 #include "WinAfsLoad.h"
13 #include "WinAfsLoadDlg.h"
24 #include "ProgBarDlg.h"
26 #include "commandsettings.h"
27 //#include <process.h>
29 #define PASSWORDSIZE 32
30 #define USERNAMESIZE 32
31 #define SHARENAMESIZE 12
35 #define ITEMCHECKED 0x2000 //CONTROL List defined for checked and not checked condition
36 #define ITEMNOTCHECKED 0x1000
37 #define TIMEINTERVAL 200
38 #define CHECKDIR 2500 //NUMBER CYCLE before checking directory for changes (2.5 seconds)
39 #define MAXWORLDINDEX 25 //Number of frames (-1) in the whirling world
44 static char THIS_FILE[] = __FILE__;
48 /////////////////////////////////////////////////////////////////////////////
49 // CAboutDlg dialog used for App About
51 class CAboutDlg : public CDialog
57 //{{AFX_DATA(CAboutDlg)
58 enum { IDD = IDD_ABOUTBOX };
62 // ClassWizard generated virtual function overrides
63 //{{AFX_VIRTUAL(CAboutDlg)
65 virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
70 //{{AFX_MSG(CAboutDlg)
75 CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
77 //{{AFX_DATA_INIT(CAboutDlg)
82 void CAboutDlg::DoDataExchange(CDataExchange* pDX)
84 CDialog::DoDataExchange(pDX);
85 //{{AFX_DATA_MAP(CAboutDlg)
86 DDX_Text(pDX, IDC_STATICABOUT, m_sVersion);
90 BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
91 //{{AFX_MSG_MAP(CAboutDlg)
92 // No message handlers
102 CCancel(BOOL &sav,BOOL val){m_pPtr=&sav;m_bVal=val;}
108 /////////////////////////////////////////////////////////////////////////////
109 // CWinAfsLoadDlg dialog
111 CWinAfsLoadDlg::CWinAfsLoadDlg(const char *user,const char *pass,CWnd* pParent /*=NULL*/)
112 : CDialog(CWinAfsLoadDlg::IDD, pParent), m_trayIcon(WM_MY_TRAY_NOTIFICATION,IDR_MAINFRAME,IDR_TRAYICON)
114 //{{AFX_DATA_INIT(CWinAfsLoadDlg)
115 m_sPassword = _T("");
116 m_sUsername = _T("");
117 m_sMountDisplay = _T("");
119 // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
124 m_bConnect=CWINAFSLOADAPP->m_bConnect;
125 m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
127 m_iActiveItem=-1; //used in MountList to indicate which item is clicked on
128 m_nAutTimer=m_nDirTimer=0;
130 m_PowerResumeDelay=-1;
134 void CWinAfsLoadDlg::DoDataExchange(CDataExchange* pDX)
136 CDialog::DoDataExchange(pDX);
137 //{{AFX_DATA_MAP(CWinAfsLoadDlg)
138 DDX_Control(pDX, IDC_WORLD, m_cWorld);
139 DDX_Control(pDX, IDC_AUTHWARN, m_cAuthWarn);
140 DDX_Control(pDX, IDC_AUTH, m_cAuthenicate);
141 DDX_Control(pDX, IDC_SAVEUSERNAME, m_cSaveUsername);
142 DDX_Control(pDX, IDC_DRIVEMOUNTLIST, m_cMountlist);
143 DDX_Control(pDX, IDC_CHANGE, m_cChange);
144 DDX_Control(pDX, IDC_REMOVE, m_cRemove);
145 DDX_Control(pDX, IDC_OPTIONLINE, m_cOptionLine);
146 DDX_Control(pDX, IDC_CHECKADVANCED, m_cCheckAdvanceDisplay);
147 DDX_Control(pDX, IDC_CONNECT, m_cConnect);
148 DDX_Control(pDX, IDC_CANCEL, m_cCancel);
149 DDX_Control(pDX, IDC_PASSWORD, m_cPassword);
150 DDX_Control(pDX, IDC_USERNAME, m_cUsername);
151 DDX_Text(pDX, IDC_PASSWORD, m_sPassword);
152 DDV_MaxChars(pDX, m_sPassword, 32);
153 DDX_Text(pDX, IDC_USERNAME, m_sUsername);
154 DDV_MaxChars(pDX, m_sUsername, 32);
155 DDX_Text(pDX, IDC_MOUNTDISPLAY, m_sMountDisplay);
159 BEGIN_MESSAGE_MAP(CWinAfsLoadDlg, CDialog)
160 //{{AFX_MSG_MAP(CWinAfsLoadDlg)
163 ON_BN_CLICKED(IDC_CONNECT, OnConnect)
164 ON_BN_CLICKED(IDC_CHECKADVANCED, OnCheckadvanced)
165 ON_COMMAND(IDM_APP_OPEN, OnAppOpen)
166 ON_BN_CLICKED(IDC_CHANGE, OnChange)
167 ON_BN_CLICKED(IDC_ADD, OnAdd)
168 ON_BN_CLICKED(IDC_REMOVE, OnRemove)
169 ON_NOTIFY(NM_CLICK, IDC_DRIVEMOUNTLIST, OnClickDrivemountlist)
170 ON_NOTIFY(LVN_ITEMCHANGED, IDC_DRIVEMOUNTLIST, OnItemchangedDrivemountlist)
171 ON_WM_QUERYENDSESSION()
173 ON_BN_CLICKED(IDC_AUTH, OnAuthenicate)
176 ON_COMMAND(IDC_SHOWBACK, OnShow)
178 ON_BN_CLICKED(IDC_HELPMAIN, OnHelpmain)
179 ON_BN_CLICKED(IDC_SETTINGS, OnSettings)
180 ON_BN_CLICKED(IDC_CANCEL, OnCancel)
183 ON_BN_CLICKED(IDM_EXPLORERAFS, OnTrayButton0)
184 ON_BN_CLICKED(IDM_EXPLORERAFS+16, OnTrayButton1)
185 ON_BN_CLICKED(IDM_EXPLORERAFS+32, OnTrayButton2)
186 ON_BN_CLICKED(IDM_EXPLORERAFS+48, OnTrayButton3)
187 ON_BN_CLICKED(IDM_EXPLORERAFS+64, OnTrayButton4)
188 ON_NOTIFY_EX( TTN_NEEDTEXT, 0, OnToolTipNotify )
189 ON_MESSAGE(WM_POWERBROADCAST,OnPowerBroadcast)
190 ON_MESSAGE(WM_ERRORMSG,OnErrorMessage)
193 /////////////////////////////////////////////////////////////////////////////
194 // CWinAfsLoadDlg message handlers
197 BOOL CWinAfsLoadDlg::OnToolTipNotify( UINT id, NMHDR * pNMHDR, LRESULT * pResult )
199 TOOLTIPTEXT *pTTT = (TOOLTIPTEXT *)pNMHDR;
200 UINT nID =pNMHDR->idFrom;
201 if (pTTT->uFlags & TTF_IDISHWND)
203 // idFrom is actually the HWND of the tool
204 nID = ::GetDlgCtrlID((HWND)nID);
207 case IDC_CHECKADVANCED:
208 if (m_cCheckAdvanceDisplay.GetCheck())
209 pTTT->lpszText = MAKEINTRESOURCE(IDS_HIDEADVANCE);
211 pTTT->lpszText = MAKEINTRESOURCE(nID);
212 pTTT->hinst = AfxGetResourceHandle();
215 case IDC_SAVEUSERNAME:
216 if (m_cSaveUsername.GetCheck())
217 pTTT->lpszText = MAKEINTRESOURCE(IDS_FORGETUSERNAME);
219 pTTT->lpszText = MAKEINTRESOURCE(nID);
220 pTTT->hinst = AfxGetResourceHandle();
223 if (m_bServiceIsActive)
224 pTTT->lpszText = MAKEINTRESOURCE(IDS_HIDE);
226 pTTT->lpszText = MAKEINTRESOURCE(nID);
227 pTTT->hinst = AfxGetResourceHandle();
230 if (m_bServiceIsActive)
231 pTTT->lpszText = MAKEINTRESOURCE(IDS_DISCONNECT);
233 pTTT->lpszText = MAKEINTRESOURCE(nID);
234 pTTT->hinst = AfxGetResourceHandle();
237 pTTT->lpszText = MAKEINTRESOURCE(nID);
238 pTTT->hinst = AfxGetResourceHandle();
247 BOOL CWinAfsLoadDlg::PreTranslateMessage(MSG* pMsg)
249 // TODO: Add your specialized code here and/or call the base class
250 // get the accelerator table to work, i.e. press <enter> is same as IDC_CONNECT
253 if (::TranslateAccelerator(m_hWnd, m_hAccelTable, pMsg))
256 return CDialog::PreTranslateMessage(pMsg);
259 BOOL CWinAfsLoadDlg::OnInitDialog()
264 CDialog::OnInitDialog();
265 // Add "About..." menu item to system menu.
267 // IDM_ABOUTBOX must be in the system command range.
268 ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
269 ASSERT(IDM_ABOUTBOX < 0xF000);
271 CMenu* pSysMenu = GetSystemMenu(FALSE);
272 if (pSysMenu != NULL)
275 strMenu.LoadString(IDS_ABOUTBOX);
276 ASSERT(!strMenu.IsEmpty());
277 pSysMenu->AppendMenu(MF_SEPARATOR);
278 pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strMenu);
280 if (CWINAFSLOADAPP->m_bShowAfs)
282 // Set the icon for this dialog. The framework does this automatically
283 // when the application's main window is not a dialog
284 SetIcon(m_hIcon, TRUE); // Set big icon
285 SetIcon(m_hIcon, FALSE); // Set small icon
286 // TODO: Add extra initialization here
288 m_hAccelTable = LoadAccelerators(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDR_ACCELERATOR1));
290 // bind to socket's DLL
294 if ((uStatus = WSAStartup(MAKEWORD(1,1), &WSAData)) == 0) {
295 LOG("AFS:Startup%s",WSAData.szDescription);
297 msg.Format("AFS Error - Cannot find socket.dll status=0x%0x", uStatus);
298 AfxMessageBox(msg,MB_OK);
299 SendMessage(WM_CLOSE,0,0);
304 // We need to make sure the DLL's support the features provided by the CListCtrl common control
305 // That is they must be later than 4.71
307 // ver.GetFileVersionInfo("comctl32.dll",vernum); //use this form if Win95???
312 if (!ver.DllGetVersion("comctl32.dll", dvi,vernum))
313 ver.GetFileVersionInfo("comctl32.dll",vernum);
314 LOG("comctl32 %d.%d",(vernum>>16) & 0xff,vernum & 0xff);
315 if(vernum< PACKVERSION(4,70))
317 msg.Format("Current Version %d.%d, Recommend at least version 4.70 for COMCTL32.dll, (Install, 401COMUPD.EXE or Internet Explorer 4.01 SP2 or better)",HIWORD(vernum),LOWORD(vernum));
318 MessageBox(msg, "AFS DLL Version Warning", MB_OK);
319 m_cCheckAdvanceDisplay.ModifyStyle(0,WS_DISABLED);
321 if (!ver.DllGetVersion("Shell32.dll", dvi,vernum))
322 ver.GetFileVersionInfo("Shell32.dll",vernum);
323 LOG("Shell32 %d.%d",(vernum>>16) & 0xff,vernum & 0xff);
324 if(vernum< PACKVERSION(4,00))
326 msg.Format("Current Version %d.%d, Recommend at least version 4.00 for SHELL32.dll, (Install Internet Explorer 4.01 SP2 or better)",HIWORD(vernum),LOWORD(vernum));
327 MessageBox(msg, "AFS DLL Version Warning", MB_OK);
328 m_cCheckAdvanceDisplay.ModifyStyle(0,WS_DISABLED);
331 if (!ver.DllGetVersion("ADVAPI32.dll", dvi,vernum))
332 ver.GetFileVersionInfo("ADVAPI32.dll",vernum);
333 LOG("ADVAPI32 %d.%d",(vernum>>16) & 0xff,vernum & 0xff);
334 m_pEncript = (CEncript *)new CEncript(this);
337 // initiallze AFS and setup Progress display
338 if (!m_cAfs.Init(this,msg))
341 m_trayIcon.AddIcon(this);
342 EnableToolTips(TRUE);
344 m_bServiceIsActive=FALSE;
345 // Obtain Version String
346 CRegkey key(HKEY_LOCAL_MACHINE,"Software\\Open AFS\\AFS Control Center","CurrentVersion");
347 key.GetString("VersionString",m_VersionString,128);
348 msg.Format("%s %s",AFSTITLE,m_VersionString);
353 rc = 128; GetComputerName(compName, &rc);
354 m_sComputername=compName;
355 m_sMountDisplay.Format("Connected Drives on Computer:%s",compName);
358 GetWindowRect(&m_OriginalRect);
359 m_cOptionLine.GetWindowRect(&rect);
360 m_DialogShrink=rect.top-m_OriginalRect.top+5; //make it above the edit box
361 SetWindowPos(&wndTop,0,0,m_OriginalRect.right-m_OriginalRect.left,m_DialogShrink,SWP_NOMOVE|SWP_NOZORDER);
362 // Pull registration information out
363 CRegkey regkey("AFS\\Window");
365 DWORD size=sizeof(m_PowerResumeDelay);
366 regkey.GetBinary("PowerResumeDelay",(LPBYTE)&m_PowerResumeDelay,size);
367 if (m_PowerResumeDelay<=0) {
368 m_PowerResumeDelay=20; //seconds
369 regkey.PutBinary("PowerResumeDelay",(LPBYTE)&m_PowerResumeDelay,size);
371 CHAR pLoginName[UNLEN + 1];
373 if (CWINAFSLOADAPP->m_bNoID)
375 CWnd *w=GetDlgItem(IDC_USERNAME);
376 w->EnableWindow(FALSE);
377 w=GetDlgItem(IDC_PASSWORD);
378 w->EnableWindow(FALSE);
379 w=GetDlgItem(IDC_SAVEUSERNAME);
380 w->EnableWindow(FALSE);
382 if (GetUserName(pLoginName,&size))
384 m_sLoginName=pLoginName;
388 RegPassword(sUser,sPass,TRUE);
393 if ((m_sUsername=="") && (m_sLoginName!="Bozo"))
395 m_sUsername=m_sLoginName;
397 if ((m_sPassword=="") || (m_sPassword.IsEmpty()))
401 if (m_sPassword.IsEmpty())
403 m_cSaveUsername.SetCheck(FALSE);
404 RegLastUser(m_sUsername,TRUE);
406 m_cSaveUsername.SetCheck(TRUE);
408 // Initialize mount control list
410 m_pImagelist = new CImageList();
411 ASSERT(m_pImagelist != NULL); // serious allocation failure checking
412 m_pImagelist->Create(16, 16, 0, 2, 2);
413 m_cMountlist.SetImageList(m_pImagelist, LVSIL_SMALL);
415 m_cMountlist.GetWindowRect(&rect);
416 {// don't particullary want to keep the DC around
418 CSize cSize=dc.GetTextExtent("*",1);
419 CSize dSize=dc.GetTextExtent("XXXXXXXXXXX",12);
421 int r=rect.Width()-cSize.cx-dSize.cx;
423 m_cMountlist.InsertColumn(COLDRIVE, "Drive", LVCFMT_LEFT,
426 m_cMountlist.InsertColumn(COLPATH, "Afs Path", LVCFMT_LEFT,
429 m_cMountlist.InsertColumn(COLAUTO, "*", LVCFMT_CENTER,
433 m_cMountlist.InsertColumn(COLSHARE, "Share Name", LVCFMT_LEFT,
435 m_cMountlist.SetExtendedStyle(m_cMountlist.GetExtendedStyle() | LVS_EX_FULLROWSELECT|LVS_EX_CHECKBOXES );
440 BuildDriveList(TRUE);
442 m_seqCount=0; //set up sequence timer for moving world
444 m_cAuthWarn.ShowWindow(SW_HIDE);
445 m_bkBrush.CreateSolidBrush(RGB(255,255,0));
447 // WHIRLING world display
448 m_cWorld.SetWindowPos(NULL,0,0,42,42,SWP_NOMOVE|SWP_NOZORDER);
449 m_cWorld.GetWindowRect(&m_WorldRect);
450 ScreenToClient(&m_WorldRect);
451 VERIFY( m_bmpWorld.LoadBitmap( IDB_WORLD ) );
456 m_nDirTimer=SetTimer(WM_DIRTIMER,TIMEINTERVAL,0);
458 m_nAutTimer=SetTimer(WM_AUTTIMER,10000,0);
460 m_nAutTimer=SetTimer(WM_AUTTIMER,60000,0);
462 m_bRestartAFSD=FALSE;
463 m_OSVersion.dwOSVersionInfoSize=sizeof(m_OSVersion);
464 GetVersionEx(&m_OSVersion); //get OS type & version
466 PostMessage(WM_COMMAND,IDC_CONNECT,0);
468 GotoDlgCtrl(&m_cConnect);
470 // return TRUE unless you set the focus to a control
471 } // end OnInitDialog
473 BOOL CWinAfsLoadDlg::RegPassword(CString &user,CString &pass,BOOL fetch)
478 sKey.Format("AFS\\Security\\%s",m_sLoginName);
479 CRegkey regkey(sKey);
480 if (regkey.Getkey()==0) return FALSE;
483 regkey.GetString("UserName",user,USERNAMESIZE);
484 if (user.IsEmpty()||(user==""))
489 pBuffer=new char[(int)len+1];
490 regkey.GetBinary("Password",(LPBYTE)pBuffer,len);
494 m_pEncript->Encript(m_sComputername,m_sLoginName,user
495 ,(UCHAR *)pBuffer,len,FALSE);
500 if (user.IsEmpty()||pass.IsEmpty()) {
501 regkey.PutString("UserName",user);
502 regkey.PutBinary("Password",NULL,0);
505 if (regkey.PutString("UserName",user))
507 len=pass.GetLength();
508 pBuffer=new char[(int)len+1];
509 strcpy(pBuffer,pass);
511 m_pEncript->Encript(m_sComputername,m_sLoginName,user
512 ,(UCHAR *)pBuffer,len,TRUE);
515 regkey.PutBinary("Password",(LPBYTE)pBuffer,len);
522 BOOL CWinAfsLoadDlg::RegLastUser(CString &user,BOOL fetch)
525 sKey.Format("AFS\\Security\\%s",m_sLoginName);
526 CRegkey regkey(sKey);
527 if (regkey.Getkey()==0) return FALSE;
530 regkey.GetString("LastUser",user,USERNAMESIZE);
533 return (regkey.PutString("LastUser",user));
536 // MOdify the system menu
537 /// need to add items to Icon Menu also
538 /// check out sc_close for close postion rather than depend on fixed position
539 /// Need to add Menu Item aphbetical to drive letter
541 #define NUMOFMENUDRIVES 5
542 #define INSERTPOSITION 6
544 void CWinAfsLoadDlg::AddMenu(const char *sDrive,const char *share)
546 CMenu* pSysMenu = GetSystemMenu(FALSE);
547 if (pSysMenu == NULL) return;
549 msg.Format("%s %s",sDrive,share);
550 UINT id=pSysMenu->GetMenuItemID(INSERTPOSITION); //insert before About Menu Item
551 if (id==IDM_EXPLORERAFS)
554 // limit number of drives added to is NUMOFDRIVES
555 int i=INSERTPOSITION;
557 int len=pSysMenu->GetMenuString(i,lpString,2,MF_BYPOSITION);
558 if (*sDrive==*lpString) return;
559 UINT nID=pSysMenu->GetMenuItemID(++i);
560 if ((nID<IDM_EXPLORERAFS) || (nID>IDM_EXPLORERAFS+16*(NUMOFMENUDRIVES-1)))//NOT a Drive ITEM
562 pSysMenu->InsertMenu(i,MF_BYPOSITION,IDM_EXPLORERAFS+16*(i-INSERTPOSITION),msg);
563 MENUBLOCK blk(IDM_EXPLORERAFS+16*(i-INSERTPOSITION),msg);
564 m_trayIcon.AddDrive(blk);
567 } while (i<INSERTPOSITION+NUMOFMENUDRIVES-1);
570 MENUBLOCK blk(IDM_EXPLORERAFS,msg);
571 m_trayIcon.AddDrive(blk);
572 if (!pSysMenu->InsertMenu(INSERTPOSITION,MF_BYPOSITION,MF_SEPARATOR)) return;
573 if (!pSysMenu->InsertMenu(INSERTPOSITION,MF_BYPOSITION,IDM_EXPLORERAFS,msg)) return;
578 void CWinAfsLoadDlg::RemoveMenu(const char *sDrive)
580 CMenu* pSysMenu = GetSystemMenu(FALSE);
581 if (pSysMenu == NULL) return;
582 UINT nID=pSysMenu->GetMenuItemID(INSERTPOSITION);
583 if ((nID<IDM_EXPLORERAFS)||(nID>IDM_EXPLORERAFS+16*NUMOFMENUDRIVES)) return;
585 for (int i=INSERTPOSITION;i<=INSERTPOSITION+NUMOFMENUDRIVES-1;i++)
587 int len=pSysMenu->GetMenuString(i,lpString,2,MF_BYPOSITION);
588 if (*sDrive==*lpString)
592 blk.mID=pSysMenu->GetMenuItemID(i);
593 m_trayIcon.RemoveDrive(blk);
594 if (!pSysMenu->RemoveMenu(i,MF_BYPOSITION )) return;
595 if ((i==INSERTPOSITION)&& (pSysMenu->GetMenuItemID(i)==MF_SEPARATOR))
596 pSysMenu->RemoveMenu(i,MF_BYPOSITION);
600 /// scan rest of list to see if you need to add a drive
603 void CWinAfsLoadDlg::OnSysCommand(UINT nID, LPARAM lParam)
605 switch (nID & 0xFFF0)
609 HWND hwnd=m_cAfs.GetLoadWindowHandle();
610 if (hwnd==NULL) break;
611 UINT show=(::IsWindowVisible(hwnd))?SW_HIDE:SW_SHOWNORMAL;
612 ::ShowWindow(m_cAfs.GetLoadWindowHandle(),show);
615 case IDM_CAPTUREWINDOW:
616 CWINAFSLOADAPP->m_bLogWindow=TRUE;
617 CWINAFSLOADAPP->ShowLog(TRUE);
619 case IDM_CAPTUREFILE:
620 CWINAFSLOADAPP->m_bLog=TRUE;
621 CWINAFSLOADAPP->ShowPrint(TRUE);
626 // Lets update About box to include version information
629 wsprintf(wdir,"%s.exe",((CWinAfsLoadApp *)AfxGetApp())->m_pszExeName);
631 wsprintf(wdir,"%s.exe",CWINAFSLOADAPP->m_pszExeName);
635 rc =GetFileVersionInfoSize(wdir,&wHandle);
638 BYTE *lpData=(BYTE *)new BYTE[rc];
639 if (GetFileVersionInfo(wdir,wHandle,rc,lpData))
643 WORD langID; // language ID
644 WORD charset; // character set (code page)
647 TRANSLATION mTrans,* pTrans;
648 if (VerQueryValue(lpData,
649 "\\VarFileInfo\\Translation", (PVOID *)&pTrans, &len) && len >= 4) {
651 TRACE("code page = %d\n", mTrans.charset);
656 query.Format(_T("\\StringFileInfo\\%04x%04x\\%s"),
659 _T("ProductVersion"));
660 if (VerQueryValue(lpData, (LPTSTR)(LPCTSTR)query,
661 (LPVOID*)&pVal, &iLenVal)) {
662 // dlgAbout.m_sVersion.Format("WinAFSload Version %s",pVal);
671 m_trayIcon.MinimiseToTray(this); //only if click on miminization botton i
673 CDialog::OnSysCommand(nID, lParam); //do this to mimic the normal windows behavor
677 if ((nID>=IDM_EXPLORERAFS)&&(nID<=IDM_EXPLORERAFS+16*NUMOFMENUDRIVES))
679 CMenu* pSysMenu = GetSystemMenu(FALSE);
680 if (pSysMenu == NULL) return;
683 pSysMenu->GetMenuString(nID,sDrive,3,MF_BYCOMMAND);
684 if (!m_cAfs.StartExployer(msg,sDrive))
688 CDialog::OnSysCommand(nID, lParam);
693 // If you add a minimize button to your dialog, you will need the code below
694 // to draw the icon. For MFC applications using the document/view model,
695 // this is automatically done for you by the framework.
697 void CWinAfsLoadDlg::OnPaint()
699 CPaintDC dc(this); // device context for painting
702 SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
704 // Center icon in client rectangle
705 int cxIcon = GetSystemMetrics(SM_CXICON);
706 int cyIcon = GetSystemMetrics(SM_CYICON);
708 GetClientRect(&rect);
709 int x = (rect.Width() - cxIcon + 1) / 2;
710 int y = (rect.Height() - cyIcon + 1) / 2;
713 dc.DrawIcon(x, y, m_hIcon);
717 m_bmpWorld.DrawTrans(dc,m_WorldRect,(m_WorldRect.Width()-1)*m_seqIndex);
722 void CWinAfsLoadDlg::HandleError(const char *s,BOOL display)
728 m_cAfs.FinishProgress();
729 CWait wait(IDC_ARROW);
730 MessageBox(s,"AFS Client Warning",MB_ICONWARNING | MB_OK);
735 void CWinAfsLoadDlg::OnConnect()
737 // This is required to keep a process from getting inbehind the error display dialog box and hitting the Connect Button again.
738 // the best way to avoid this would have been to separate GUI task from processes; that way
739 // the Connect button would have bee disabled while the process is busy or if waiting for an error response! It is possible
740 // to send a ClickMessage to the Connect button even with the a modal dialog box overlaying the main dialog!
742 if (CWait::IsBusy()) return;
745 m_iActiveItem=-1; //necessary to indicate to MountList that items being changed are done by program not by mouse input
747 if (m_bServiceIsActive) // DOS is active so lets terminate
749 // disconnect any connected AFS mounts, unless there are files open!
750 if (!DismountAll(msg,0))
752 TerminateBackground();
754 m_cAuthWarn.ShowWindow(SW_HIDE);
757 CCancel cancel(m_bConnect,FALSE); //clear m_bConnect when connection done
758 if ( // if username is present then must have password
763 HandleError("You must enter a password!");
764 m_cPassword.SetFocus();
767 CProgress progress(this,7);
769 if (!m_cAfs.Create(msg,m_sComputername,m_procInfo))
773 m_procInfo.hThread=0;
776 // CWINAFSLOADAPP->m_sMsg contains the host name used for login
777 LOG("AFS Client Console started successfully [%s].",(const char *)m_sComputername);
782 for (int iItem=0;iItem<m_cMountlist.GetItemCount();iItem++)
784 sKey = m_cMountlist.GetItemText(iItem,COLSHARE);
785 if (stricmp(sKey,"all")!=0) continue; // lets find the All first
786 CString sAuto(m_cMountlist.GetItemText(iItem,COLAUTO));
789 sDrive=m_cMountlist.GetItemText(iItem,COLDRIVE);
790 LOG("Connect %s %s",sDrive,sKey);
791 if (m_cAfs.Mount(msg,sDrive,sKey))
793 m_cMountlist.SetCheck(iItem,TRUE);
794 AddMenu(sDrive,sKey);
798 m_cAfs.Shutdown(msg2);
799 m_procInfo.hThread=0;
800 msg2.Format("Connect can't continue: %s",msg);
808 // Scan for any other connection
809 for (int iItem=0;iItem<m_cMountlist.GetItemCount();iItem++)
811 CString sAuto(m_cMountlist.GetItemText(iItem,COLAUTO));
814 sDrive=m_cMountlist.GetItemText(iItem,COLDRIVE);
815 LOG("Connect %s %s",sDrive,sKey);
816 if (m_cAfs.Mount(msg,sDrive,sKey))
818 m_cMountlist.SetCheck(iItem,TRUE);
819 AddMenu(sDrive,sKey);
823 m_cAfs.Shutdown(msg2);
824 m_procInfo.hThread=0;
825 msg2.Format("Connect can't continue: %s",msg);
837 if (iMounted<0) //have we mounted at least one drive
839 m_cAfs.Shutdown(msg);
840 m_procInfo.hThread=0;
841 msg="Connect can't continue, mountable drive not defined";
847 if (!m_cAfs.Authencate(msg,m_sUsername,m_sPassword))
850 m_cAfs.Dismount(msg2,sDrive,TRUE);
851 m_cMountlist.SetCheck(iItem,FALSE);
853 m_cAfs.Shutdown(msg2);
854 m_procInfo.hThread=0;
861 // scan through the list for any additional items to connect
863 for (iItem=0;iItem<m_cMountlist.GetItemCount();iItem++)
865 CString sKey(m_cMountlist.GetItemText(iItem,COLSHARE));
866 if (iItem==iMounted) continue;
867 CString sAuto(m_cMountlist.GetItemText(iItem,COLAUTO));
870 sDrive=m_cMountlist.GetItemText(iItem,COLDRIVE);
871 LOG("Connect %s %s",sDrive,sKey);
872 if (m_cAfs.Mount(msg,sDrive,sKey))
874 m_cMountlist.SetCheck(iItem,TRUE);
875 AddMenu(sDrive,sKey);
879 if (!m_cAfs.StartExployer(msg,sDrive))
881 if (!m_cSaveUsername.GetCheck())
887 m_bServiceIsActive=TRUE; //DON'T allow shutdown until DOS is terminated
890 PostMessage(WM_COMMAND,IDC_CANCEL,0);
893 void CWinAfsLoadDlg::PostNcDestroy()
895 // TODO: Add your specialized code here and/or call the base class
897 if( m_pImagelist != NULL)
901 m_bmpWorld.DeleteObject();
902 CDialog::PostNcDestroy();
906 void CWinAfsLoadDlg::OnCancel()
908 // TODO: Add your control notification handler code here
910 if (m_bServiceIsActive)
918 RegPassword(user,pass,TRUE);
919 if (m_cSaveUsername.GetCheck())
921 if (!m_pEncript->IsValid())
922 warn="\n\nAt this time if you choose to save your password on your harddrive, it will not be in encripted form.\n\n\
923 To encript your password you must have version 4.71 of ADVAPI32.dll (or better).\n Note: To upgrade this system file, install Internet Explorer 4.01 SP2 (or better).\n\n\
924 HINT:To intstall Internet Explorer 4.01 Service Pack 2\n\
925 1. Insert the CD that contains Service Pack 2\n\
926 2. Use the Explorer to navigate to the CDROM sub-Directory \\IE4SP2\\I386\n\
927 3. Double Click on Setup \n\
928 4. Follow the instructions for standard Installation\n\
929 5. If asked, select option to install Windows Desktop Update\n\
930 6. You will have to restart your computer when installation is completed\n\
931 7. You may remove all other components except SP2 (approximatly 90MB)";
932 if ((user==m_sUsername) && (m_sPassword!=pass))
934 msg.Format("Your password is different from what was previous saved on disk.\n Do you wish to update? %s",warn);
936 ,"AFS - Security Warning"
937 , MB_ICONWARNING | MB_YESNO)==IDYES)
938 RegPassword(m_sUsername,m_sPassword,FALSE);
939 } else if (user==""){
941 msg.Format("Your user name and password (encrypted) will be saved on your disk.\n Do you wish to save?");
943 msg.Format("Your user name and password will be saved on your disk.\n Do you wish to save?%s",warn);
944 if (MessageBox(msg,"AFS - Security Warning"
945 , MB_ICONWARNING | MB_YESNO)==IDYES)
946 RegPassword(m_sUsername,m_sPassword,FALSE);
947 } else if (user!=m_sUsername){
948 msg.Format("Previous saved on the disk a user name (%s) and password will be overwritten by new user name (%s) and password(encrypted). Do you wish to update?%s",user,m_sUsername,warn);
949 if (MessageBox(msg,"AFS - Security Warning"
950 , MB_ICONWARNING | MB_YESNO)==IDYES)
951 RegPassword(m_sUsername,m_sPassword,FALSE);
956 if ((pass!="")&&(user==m_sUsername))
958 msg.Format("Previous user name (%s) and password will be removed from the disk\nDo you wish to clear?",user);
959 if (MessageBox(msg,"AFS - Security Warning",
960 MB_ICONWARNING | MB_YESNO)==IDYES)
963 RegPassword(user,user,FALSE);
967 RegLastUser(m_sUsername,FALSE);
972 void CWinAfsLoadDlg::OnCheckadvanced()
974 // TODO: Add your control notification handler code here
975 if (m_cCheckAdvanceDisplay.GetCheck())
978 if (m_bServiceIsActive)
979 UpdateMountDisplay();
980 SetWindowPos(&wndTop,0,0,m_OriginalRect.right-m_OriginalRect.left,m_OriginalRect.bottom-m_OriginalRect.top,SWP_NOMOVE|SWP_NOZORDER);
982 SetWindowPos(&wndTop,0,0,m_OriginalRect.right-m_OriginalRect.left,m_DialogShrink,SWP_NOMOVE|SWP_NOZORDER);
986 BOOL CWinAfsLoadDlg::DismountAll(CString &msg,INT mode)
987 {// mode =0 , give user option to retry or cancel
988 //mode =1, give user option to force
989 //mode =3 , force it anyway
990 TCHAR szDrive[] = TEXT("*:");
991 TCHAR szMapping[ MAX_PATH ] = TEXT("");
992 LPTSTR pszSubmount = szMapping;
993 DWORD dwSize = MAX_PATH;
994 TCHAR pBuffer[MAX_PATH];
995 if (strlen(m_cAfs.MountName())==0)
997 for (TCHAR chDrive = 'D'; chDrive <= 'Z'; ++chDrive)
1000 if (WNetGetConnection (szDrive, szMapping, &dwSize) == NO_ERROR)
1002 CHAR *p=strstr(szMapping,m_cAfs.MountName());
1005 LOG("Disconnect %s %s",szDrive,szMapping);
1006 if (!m_cAfs.Dismount(msg,szDrive,(mode==3)))
1011 case 1: //Option to force
1015 switch (dlg.DoModal())
1018 LOG("Force Disconnect %s %s",szDrive,szMapping);
1019 if (!m_cAfs.Dismount(msg,szDrive,TRUE))
1031 switch (dlg.DoModal())
1034 LOG("Force Disconnect %s %s",szDrive,szMapping);
1035 if (!m_cAfs.Dismount(msg,szDrive,TRUE))
1048 p=strrchr(szMapping,'\\');
1050 for (int iItem=m_cMountlist.GetItemCount()-1;iItem>=0;iItem--)
1052 m_cMountlist.GetItemText(iItem,COLSHARE,pBuffer,MAX_PATH);
1053 if (stricmp(p+1,pBuffer)!=0) continue;
1054 m_cMountlist.GetItemText(iItem,COLDRIVE,pBuffer,MAX_PATH);
1055 if (stricmp(szDrive,pBuffer)!=0) continue;
1056 m_cMountlist.SetCheck(iItem,FALSE);
1057 RemoveMenu(szDrive);
1066 BOOL CWinAfsLoadDlg::TerminateBackground(BOOL bDisplay,CString *emsg)
1067 {// if bDisplay==FALSE then skip error message and don't update connect buttons (power down needs this option)
1068 // IF error and emsg!=NULL then return error messaage
1071 if (!m_cAfs.Shutdown(msg))
1073 HandleError(msg,bDisplay);
1074 m_cConnect.ModifyStyle(0,WS_DISABLED,0);
1075 m_cConnect.Invalidate();
1076 m_cCancel.SetWindowText("Exit");
1077 m_cCancel.Invalidate();
1078 m_trayIcon.SetConnectState(2);
1079 m_bServiceIsActive=FALSE;
1084 m_bServiceIsActive=FALSE;
1087 LOG("AFS Client Console stopped");
1091 void CWinAfsLoadDlg::UpdateConnect()
1095 m_cConnect.ModifyStyle(WS_DISABLED,0);
1096 m_cAuthenicate.ModifyStyle(WS_DISABLED,0);
1099 if (m_bServiceIsActive)
1101 m_cConnect.SetWindowText("DisConnect");
1102 m_cConnect.Invalidate();
1103 m_cCancel.SetWindowText("Cancel");
1104 m_cCancel.Invalidate();
1105 if (!CWINAFSLOADAPP->m_bNoID)
1107 m_cAuthenicate.ModifyStyle(WS_DISABLED,0);
1109 m_cAuthenicate.SetWindowText("ReAuthenicate");
1110 else //tokens are not gotten; allow authenication
1111 m_cAuthenicate.SetWindowText("Authenicate");
1112 m_cAuthenicate.Invalidate();
1114 m_trayIcon.SetConnectState(0);
1117 m_cConnect.SetWindowText("Connect");
1118 m_cConnect.Invalidate();
1119 m_cCancel.SetWindowText("Exit");
1120 m_cCancel.Invalidate();
1121 m_cAuthenicate.ModifyStyle(0,WS_DISABLED);
1122 m_cAuthenicate.Invalidate();
1123 m_trayIcon.SetConnectState(1);
1127 void CWinAfsLoadDlg::OnAppOpen()
1129 // TODO: Add your command handler code here
1130 //required so when icon menu is "Open" it will show the hidden application
1131 m_trayIcon.MaximiseFromTray(this);
1132 // ShowWindow(SW_SHOW);
1135 // Up to 4 drives can be listed on the menu for the user to click on and start up explorer
1136 void CWinAfsLoadDlg::OnTrayButton0()
1138 OnSysCommand(IDM_EXPLORERAFS, 0);
1140 void CWinAfsLoadDlg::OnTrayButton1()
1142 OnSysCommand(IDM_EXPLORERAFS+16, 0);
1144 void CWinAfsLoadDlg::OnTrayButton2()
1146 OnSysCommand(IDM_EXPLORERAFS+32, 0);
1148 void CWinAfsLoadDlg::OnTrayButton3()
1150 OnSysCommand(IDM_EXPLORERAFS+48, 0);
1152 void CWinAfsLoadDlg::OnTrayButton4()
1154 OnSysCommand(IDM_EXPLORERAFS+64, 0);
1157 #define MAXDRIVESIZE (SHARENAMESIZE+5)*MAXSHARES
1159 BOOL CWinAfsLoadDlg::ProfileData(BOOL put)
1163 dINI.Format("%safsdsbmd.ini",CWINAFSLOADAPP->m_sTargetDir);
1164 tINI.Format("%safsdsbmt.ini",CWINAFSLOADAPP->m_sTargetDir);
1168 #define BLOCKSIZE MAX_PATH+SHARENAMESIZE+3
1170 char *sblock=(char *)malloc(scur);
1174 char *dblock=(char *)malloc(dcur);
1177 for (int iItem=m_cMountlist.GetItemCount()-1;iItem>=0;iItem--)
1179 CString sKey(m_cMountlist.GetItemText(iItem,COLSHARE));
1180 CString sPath(m_cMountlist.GetItemText(iItem,COLPATH));
1181 CString sDrive(m_cMountlist.GetItemText(iItem,COLDRIVE));
1182 CString sAuto(m_cMountlist.GetItemText(iItem,COLAUTO));
1183 if (!sKey.IsEmpty() && !sPath.IsEmpty())
1184 {// going a lot of trouble to handle any size buffer with out puting a limit on it
1185 int len=sKey.GetLength()+sDrive.GetLength()+sAuto.GetLength()+2;
1186 if (dused+len>=dcur)
1187 dblock=(char *)realloc(dblock,(dcur+=128));
1189 wsprintf(dptr,"%s=%s%s",sKey,sAuto,sDrive);
1191 len=sKey.GetLength()+sPath.GetLength()+2;
1192 if (sused+len>=scur)
1193 sblock=(char *)realloc(sblock,(scur+=BLOCKSIZE));
1195 wsprintf(sptr,"%s=%s",sKey,sPath);
1199 *(sblock+sused)=0; //put extra null at the end
1201 WritePrivateProfileSection("AFS Submounts",sblock,tINI);
1202 WritePrivateProfileSection("AFS Drivemounts",dblock,dINI);
1206 char sShare[SHARENAMESIZE+1];
1207 CHAR sPath[MAX_PATH+1];
1208 CHAR sDriveMount[MAXDRIVESIZE+2];
1209 CHAR sDrive[DRIVESIZE+1];
1210 CHAR sAuto[AUTOSIZE+1];
1213 // lets scan for all and home first, we want to place them first
1214 //mode: 0=look for all, 1=look for home, 2=finish the rest
1215 for(int mode=0;mode<3;mode++)
1217 int drivelen=GetPrivateProfileString("AFS Drivemounts", NULL, "", sDriveMount, MAXDRIVESIZE,dINI);
1218 if (drivelen>=MAXDRIVESIZE)
1221 msg.Format("Profile String Error - Too many entries (%d)",MAXSHARES);
1222 HandleError(msg,TRUE);
1225 PCHAR pDrivekey=sDriveMount;
1228 if ((strlen(pDrivekey)==0) || (strlen(pDrivekey)>SHARENAMESIZE))
1230 HandleError("Profile String Error - AFS Drivemounts - Share Name",FALSE);
1234 strcpy(sShare,pDrivekey);
1235 if (GetPrivateProfileString("AFS Drivemounts", sShare, "", sDrive, DRIVESIZE,dINI)==0)
1237 HandleError("Profile String Error - AFS Drivemounts - Drive Name",FALSE);
1241 if (sDrive[0]=='*') //test for leading *
1245 sDrive[strlen(sDrive)-1]=0;
1248 sDrive[1]=0; //force to be single character
1250 if (strspn(sDrive,"DEFGHIJKLMNOPQRSTUVWXYZ")==0)
1252 HandleError("Profile String Error - AFS Drivemounts - Drive Letter",FALSE);
1260 if (stricmp("all",sShare)!=0) break;
1261 if (GetPrivateProfileString("AFS Submounts", sShare, "", sPath, MAX_PATH,tINI)==0)
1263 strcpy(sPath,"/"); //none defined
1265 AddToList(sDrive,sPath,sShare,sAuto);
1270 if (stricmp("home",sShare)!=0) break;
1271 if (GetPrivateProfileString("AFS Submounts", sShare, "", sPath, MAX_PATH,tINI)==0)
1273 HandleError("Profile String Error - AFS Drivemounts - Share Name",FALSE);
1277 AddToList(sDrive,sPath,sShare,sAuto);
1281 if ((stricmp("all",sShare)==0)|| (stricmp("home",sShare)==0)) break;
1282 if (GetPrivateProfileString("AFS Submounts", sShare, "", sPath, MAX_PATH,tINI)==0)
1284 HandleError("Profile String Error - AFS Drivemounts - Share Name",FALSE);
1288 AddToList(sDrive,sPath,sShare,sAuto);
1291 drivelen-=(strlen(pDrivekey)+1);
1292 pDrivekey+=(strlen(pDrivekey)+1);
1300 void CWinAfsLoadDlg::OnChange()
1302 // TODO: Add your control notification handler code here
1304 POSITION pos = m_cMountlist.GetFirstSelectedItemPosition();
1305 if (pos == NULL) return;
1306 int nItem = m_cMountlist.GetNextSelectedItem(pos);
1307 UINT state=m_cMountlist.GetCheck(nItem);
1310 MessageBox("You cannot change Item from the list while connected!","AFS - Warning",MB_OK|MB_ICONWARNING);
1313 CChange dlg(TRUE,this);
1314 dlg.m_sDrive=m_cMountlist.GetItemText(nItem,COLDRIVE);
1315 dlg.m_sPath=m_cMountlist.GetItemText(nItem,COLPATH);
1316 dlg.m_sDescription=m_cMountlist.GetItemText(nItem,COLSHARE);
1317 dlg.m_bAuto=(strcmp(m_cMountlist.GetItemText(nItem,COLAUTO),"*")==0);
1318 if (dlg.DoModal()==IDCANCEL) return;
1319 m_cMountlist.SetItemText(nItem,COLDRIVE,dlg.m_sDrive);
1320 m_cMountlist.SetItemText(nItem,COLPATH,dlg.m_sPath);
1321 m_cMountlist.SetItemText(nItem,COLSHARE,dlg.m_sDescription);
1322 m_cMountlist.SetItemText(nItem,COLAUTO,(dlg.m_bAuto)?"*":" ");
1327 VOID CWinAfsLoadDlg::AddToList(const char *sDrive,const char *sPath,const char *sShare,const char *sAuto)
1330 memset(&lvitem,0,sizeof(lvitem));
1331 int iSubItem,iActualItem;
1333 if (stricmp(sShare,"home")==0)
1335 else if (stricmp(sShare,"all")==0)
1338 iItem=m_cMountlist.GetItemCount();
1339 if (iItem<1) iItem=2;
1342 for (iSubItem = 0; iSubItem < NUMCOL; iSubItem++)
1344 lvitem.mask = LVIF_TEXT ;//| (iSubItem == 0? LVIF_IMAGE : 0);
1345 lvitem.iItem = (iSubItem == 0)? iItem : iActualItem;
1346 lvitem.iSubItem = iSubItem;
1351 lvitem.pszText=(char *)sDrive;
1354 lvitem.pszText=(char *)sPath;
1357 lvitem.pszText=(char *)sShare;
1360 lvitem.pszText=(char *)sAuto;
1366 iActualItem = m_cMountlist.InsertItem(&lvitem); // insert new item
1368 m_cMountlist.SetItem(&lvitem); // modify existing item (the sub-item text)
1373 void CWinAfsLoadDlg::OnAdd()
1375 // TODO: Add your control notification handler code here
1376 CChange dlg(FALSE,this);
1377 if (dlg.DoModal()==IDCANCEL) return;
1378 //return m_sDescription, m_sPath, m_sDrive
1379 AddToList(dlg.m_sDrive,dlg.m_sPath,dlg.m_sDescription,(dlg.m_bAuto)?"*":" ");
1381 ProfileData(TRUE); //update INI list if changed
1385 void CWinAfsLoadDlg::OnRemove()
1387 // TODO: Add your control notification handler code here
1389 POSITION pos = m_cMountlist.GetFirstSelectedItemPosition();
1390 if (pos == NULL) return;
1393 int nItem = m_cMountlist.GetNextSelectedItem(pos);
1394 UINT state=m_cMountlist.GetCheck(nItem);
1397 HandleError("You cannot remove Item from the list while connected!");
1401 if (stricmp(m_cMountlist.GetItemText(nItem,COLSHARE),"all")==0)
1403 HandleError("You cannot remove 'All' Item from the list!");
1407 m_cMountlist.DeleteItem(nItem);
1412 // FOLLOWING ROUITNE IS required so OnItemchangedDrivemountlist can tell the difference
1413 // between a user changing an item to mount/dismount or the program is just updating the display
1414 // unfortunately any changes go thourgh OnItemchangedDrivemountlist
1415 void CWinAfsLoadDlg::OnClickDrivemountlist(NMHDR* pNMHDR, LRESULT* pResult)
1417 // TODO: Add your control notification handler code here
1420 NM_LISTVIEW* pListview = (NM_LISTVIEW*)pNMHDR;
1423 m_iActiveItem=pListview->iItem; //this is the only place where items changed are done by user click
1426 void CWinAfsLoadDlg::UpdateMountDisplay()
1428 TCHAR szDrive[] = TEXT("*:");
1429 TCHAR szMapping[ MAX_PATH ] = TEXT("");
1430 LPTSTR pszSubmount = szMapping;
1431 DWORD dwSize = MAX_PATH;
1432 TCHAR pDrive[DRIVESIZE+1];
1433 TCHAR pShare[SHARENAMESIZE+1];
1434 ASSERT(strlen(m_cAfs.MountName())!=0);
1436 for (int iItem=m_cMountlist.GetItemCount()-1;iItem>=0;iItem--)
1438 m_cMountlist.GetItemText(iItem,COLDRIVE,pDrive,DRIVESIZE);
1439 m_cMountlist.GetItemText(iItem,COLSHARE,pShare,SHARENAMESIZE);
1440 if ((WNetGetConnection(pDrive, szMapping, &dwSize) == NO_ERROR)
1441 && (strstr(szMapping,m_cAfs.MountName())!=NULL))
1443 if ((stricmp((strrchr(szMapping,'\\')+1),pShare)==0)
1444 && (!m_cMountlist.GetCheck(iItem)))
1446 m_cMountlist.SetCheck(iItem,TRUE);
1447 AddMenu(m_cMountlist.GetItemText(iItem,COLDRIVE),m_cMountlist.GetItemText(iItem,COLSHARE));
1452 if (m_cMountlist.GetCheck(iItem))
1454 m_cMountlist.SetCheck(iItem,FALSE);
1455 RemoveMenu(m_cMountlist.GetItemText(iItem,COLDRIVE));
1461 m_cMountlist.Invalidate();
1464 void CWinAfsLoadDlg::OnItemchangedDrivemountlist(NMHDR* pNMHDR, LRESULT* pResult)
1466 NM_LISTVIEW* pListview = (NM_LISTVIEW*)pNMHDR;
1469 if ((pListview->uNewState & (ITEMCHECKED | ITEMNOTCHECKED))!=(pListview->uOldState & 0x3000))
1471 if (m_iActiveItem<0) return; //no processing needed if not initiated by a mouse click
1473 switch (pListview->uNewState & (ITEMCHECKED | ITEMNOTCHECKED))
1475 case ITEMCHECKED: //mount a drive
1476 if (!m_bServiceIsActive)
1477 {// can't allow mounting if connection not active
1478 HandleError("You must connect first");
1479 m_cMountlist.SetCheck(pListview->iItem,FALSE);
1482 LOG("Connect %s %s",m_cMountlist.GetItemText(pListview->iItem,COLDRIVE),m_cMountlist.GetItemText(pListview->iItem,COLSHARE));
1484 CProgress progress(this,4);
1485 if (!m_cAfs.Mount(msg
1486 ,m_cMountlist.GetItemText(pListview->iItem,COLDRIVE)
1487 ,m_cMountlist.GetItemText(pListview->iItem,COLSHARE)))
1489 m_cMountlist.SetCheck(pListview->iItem,FALSE);
1494 AddMenu(m_cMountlist.GetItemText(pListview->iItem,COLDRIVE),m_cMountlist.GetItemText(pListview->iItem,COLSHARE));
1497 case ITEMNOTCHECKED: //dismount a drive
1500 LOG("Disconnect %s",m_cMountlist.GetItemText(pListview->iItem,COLDRIVE));
1503 if (!m_cAfs.Dismount(msg,m_cMountlist.GetItemText(pListview->iItem,COLDRIVE),force))
1504 {// there was an error, allow the user to force closing the drive anyway
1507 switch (dlg.DoModal())
1515 m_cMountlist.SetCheck(pListview->iItem,TRUE);
1519 RemoveMenu(m_cMountlist.GetItemText(pListview->iItem,COLDRIVE));
1529 POSITION pos = m_cMountlist.GetFirstSelectedItemPosition();
1532 m_cRemove.ModifyStyle(0,WS_DISABLED,0);
1533 m_cChange.ModifyStyle(0,WS_DISABLED,0);
1535 m_cRemove.ModifyStyle(WS_DISABLED,0,0);
1536 m_cMountlist.GetNextSelectedItem(pos);
1538 m_cChange.ModifyStyle(WS_DISABLED,0,0);
1540 m_cChange.ModifyStyle(0,WS_DISABLED,0);
1542 m_cChange.Invalidate(TRUE);
1543 m_cRemove.Invalidate(TRUE);
1547 void CWinAfsLoadDlg::BuildDriveList(BOOL newone)
1548 {//if force then build a newone
1550 DWORD mapDrive=GetLogicalDrives();
1551 TCHAR szDrive[] = TEXT("*: ");
1555 m_Drivelist.RemoveAll();
1556 TCHAR szMapping[ MAX_PATH ] = TEXT("");
1557 LPTSTR pszSubmount = szMapping;
1558 DWORD dwSize = MAX_PATH;
1559 TCHAR stDrive[]=TEXT("*:");
1560 for (iItem = 2;iItem <= 25; ++iItem)
1562 szDrive[0]=stDrive[0]=iItem+'A';
1563 if (((mapDrive & 1<<iItem)==0) // if drive is not in use or it is a network assigned drive
1564 // then place it on the available drive list
1565 || (WNetGetConnection (stDrive, szMapping, &dwSize) == NO_ERROR))
1567 m_Drivelist.AddTail(CString(szDrive));
1572 //update drive list seting * for thoes drives already in use
1573 for (iItem=m_Drivelist.GetCount()-1;iItem>=0;iItem--)
1575 strcpy(szDrive,m_Drivelist.GetAt(m_Drivelist.FindIndex(iItem)));
1576 szDrive[3]= ((1<<(szDrive[0]-'A')) & mapDrive)?'*' :' ';
1577 m_Drivelist.SetAt(m_Drivelist.FindIndex(iItem),CString(szDrive));
1581 void CWinAfsLoadDlg::ExtractDrive(CString &zdrive,const char *request)
1582 {// extract the cloest drive to the requested letter
1583 POSITION pos = m_Drivelist.Find(CString(request));
1586 zdrive=m_Drivelist.GetAt(pos);
1587 m_Drivelist.RemoveAt(pos);
1590 int count=m_Drivelist.GetCount()-4;
1591 if (count<0) count=0;
1592 pos=m_Drivelist.FindIndex(count);
1593 zdrive=m_Drivelist.GetAt(pos);
1594 m_Drivelist.RemoveAt(pos);
1597 HCURSOR CWinAfsLoadDlg::OnQueryDragIcon()
1599 return (HCURSOR) m_hIcon;
1603 // Main menu close statement
1604 BOOL CWinAfsLoadDlg::OnQueryEndSession( )
1606 ShowWindow(SW_SHOW);
1608 if (!DismountAll(msg,1))// disconnect any connected AFS mounts, unless there are files open!
1610 TerminateBackground();
1611 if (m_nDirTimer) //Destroy Window is not being called
1612 KillTimer(m_nDirTimer);
1614 KillTimer(m_nAutTimer);
1615 m_nAutTimer=m_nDirTimer=0;
1616 return !m_bServiceIsActive;
1619 void CWinAfsLoadDlg::OnTimer(UINT nIDEvent)
1621 // TODO: Add your message handler code here and/or call default
1633 if ((m_seqCount+=TIMEINTERVAL)<1000)
1636 if ((m_seqCount+=TIMEINTERVAL)<500)
1642 if ((m_seqCount+=TIMEINTERVAL)<500)
1646 if (++m_seqIndex>MAXWORLDINDEX) m_seqIndex=0;
1647 m_bmpWorld.UpdateMask(this,m_WorldRect);//build new mask and force repaint of world area
1650 if ((!m_bServiceIsActive) || (m_bRestartAFSD)) break;
1651 if ((m_dirCount+=TIMEINTERVAL)<CHECKDIR) break;
1653 len=::GetWindowText(m_cAfs.GetLoadWindowHandle(),pBuffer,64);
1654 if ((len==0) || ((p=strstr(pBuffer,"Finish"))!=NULL))
1655 {// if p!=NULL then application is finished but not totally shutdown
1658 ::SendMessage(m_cAfs.GetLoadWindowHandle(),WM_CLOSE,0,0);
1662 DismountAll(msg,3); //unfortunately all drive references are invalid also!
1663 m_bServiceIsActive=FALSE;
1667 if (!m_cCheckAdvanceDisplay.GetCheck()) break;
1668 if ((WS_VISIBLE & GetStyle()) )
1669 UpdateMountDisplay();
1672 if ((!m_bServiceIsActive) || m_bRestartAFSD) break;
1673 switch (m_cAfs.TestTokenTime(msg))
1676 if (m_nShown==0) break;
1677 m_cAuthWarn.ShowWindow(SW_HIDE);
1678 m_cAuthWarn.Invalidate(TRUE);
1682 if (m_nShown==-1) break;
1684 ShowWindow(SW_SHOWDEFAULT);
1688 if (m_nShown==1) break;
1689 m_bkBrush.DeleteObject();
1690 m_bkBrush.CreateSolidBrush(RGB(255,255,0));
1691 m_cAuthWarn.SetWindowText(msg);
1692 m_cAuthWarn.Invalidate(TRUE);
1693 m_cAuthWarn.ShowWindow(SW_SHOW);
1694 ShowWindow(SW_SHOWDEFAULT);
1699 if (m_nShown==2) break;
1700 m_bkBrush.DeleteObject();
1701 m_bkBrush.CreateSolidBrush(RGB(255,0,0));
1702 m_cAuthWarn.ShowWindow(SW_SHOW);
1703 m_cAuthWarn.SetWindowText(msg);
1704 m_cAuthWarn.Invalidate(TRUE);
1705 ShowWindow(SW_SHOWDEFAULT);
1717 CDialog::OnTimer(nIDEvent);
1720 void CWinAfsLoadDlg::OnAuthenicate()
1722 // TODO: Add your control notification handler code here
1727 m_cAuthWarn.ShowWindow(SW_HIDE);
1728 LOG("Re-Authenication");
1729 if (m_sUsername=="")
1731 HandleError("You must enter a user name!");
1732 m_cUsername.SetFocus();
1735 if (m_sPassword=="")
1737 HandleError("You must enter a password!");
1738 m_cPassword.SetFocus();
1741 if (!m_cAfs.Authencate(msg,m_sUsername,m_sPassword))
1746 m_cAuthenicate.SetWindowText("ReAuthenicate");
1747 m_cAuthenicate.Invalidate();
1748 if (!m_cSaveUsername.GetCheck())
1750 m_sPassword.Empty();
1757 void CWinAfsLoadDlg::OnDestroy()
1760 // ASSERT( m_hBmpOld );
1761 // VERIFY( m_dcMem.SelectObject( CBitmap::FromHandle(m_hBmpOld) ) );
1762 // Need to DeleteObject() the bitmap that was loaded
1763 m_bmpWorld.DeleteObject();
1765 // m_dcMem destructor will handle rest of cleanup
1767 if (m_nDirTimer) //it is better to kill the timer here than PostNcDestroy
1768 KillTimer(m_nDirTimer);
1770 KillTimer(m_nAutTimer);
1771 m_nAutTimer=m_nDirTimer=0;
1772 CDialog::OnDestroy();
1774 // TODO: Add your message handler code here
1778 // Here is how we change the Background color for the yellow warning
1779 HBRUSH CWinAfsLoadDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
1781 HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
1783 // TODO: Change any attributes of the DC here
1784 if (pWnd->GetDlgCtrlID() == IDC_AUTHWARN)
1786 pDC->SetBkMode(TRANSPARENT); // we have to make text background transparent
1787 return (HBRUSH)m_bkBrush; // Return a different brush (YELLOW)
1793 void CWinAfsLoadDlg::OnShow()
1795 // TODO: Add your command handler code here
1796 CMenu* pSysMenu = GetSystemMenu(FALSE);
1798 if (pSysMenu != NULL)
1800 if (0xFFFFFFFF!=pSysMenu->GetMenuState(IDM_CAPTUREWINDOW, MF_BYCOMMAND))
1802 CSettings dlg(this);
1808 void CWinAfsLoadDlg::OnShowAddMenus()
1810 CMenu* pSysMenu = GetSystemMenu(FALSE);
1811 if (pSysMenu == NULL) return;
1813 pSysMenu->AppendMenu(MF_SEPARATOR);
1814 strMenu.LoadString(IDM_CAPTUREWINDOW);
1815 pSysMenu->AppendMenu(MF_STRING, IDM_CAPTUREWINDOW, strMenu);
1816 strMenu.LoadString(IDM_CAPTUREFILE);
1817 pSysMenu->AppendMenu(MF_STRING, IDM_CAPTUREFILE, strMenu);
1818 strMenu.LoadString(IDM_VIEWAFS);
1819 pSysMenu->AppendMenu(MF_STRING, IDM_VIEWAFS, strMenu);
1822 // Signaled when AFSD sends a socket message
1823 LRESULT CWinAfsLoadDlg::OnPowerBroadcast(WPARAM wParam, LPARAM lParam)
1831 case PBT_APMSUSPEND:
1832 LOG("PBT_APMSUSPEND");
1834 case PBT_APMQUERYSUSPEND:
1835 // if lParam & 1 ==1 then you can prompt user for info
1836 LOG("PBT_APMQUERYSUSPEND");
1840 CString *emsg=new CString;
1841 emsg->Format("Warning: Attempt to Suspend was Denied\nPower Suspend on Windows 95 is not compatable with Ufiler. \nYou may be required to reboot before using Ufilier again!");
1842 PostMessage(WM_ERRORMSG,AFS_EXITCODE_GENERAL_FAILURE,(LPARAM)emsg);
1844 return BROADCAST_QUERY_DENY; //deny suspension
1849 if (m_bServiceIsActive)
1853 (!IsWin95()) // WIN95 will suspend anyway
1854 && (!m_cAfs.CheckNet(msg))
1861 CString *emsg=new CString;
1862 emsg->Format("Attempt to Suspend Denied\n%s",msg);
1863 PostMessage(WM_ERRORMSG,AFS_EXITCODE_GENERAL_FAILURE,(LPARAM)emsg);
1865 LOG("AFS Client Console stopped, powerdown denied.");
1866 return BROADCAST_QUERY_DENY; //files open suspend denied
1868 CString *emsg=new CString;
1869 // Allow power suspension even though termination incomplete (no files open anyway)
1870 if (!TerminateBackground(FALSE,emsg))
1874 m_cConnect.ModifyStyle(0,WS_DISABLED,0);
1875 m_cConnect.Invalidate();
1876 m_cCancel.SetWindowText("Exit");
1877 m_cCancel.Invalidate();
1878 m_trayIcon.SetConnectState(2);
1879 m_bServiceIsActive=FALSE;
1880 PostMessage(WM_ERRORMSG,AFS_EXITCODE_GENERAL_FAILURE,(LPARAM)emsg);
1885 m_bServiceIsActive=FALSE;
1887 // terminate socket connection (even if terminatebackground failed
1888 REQUESTUISUSPENDEVENT(ONPARMDISCONNECT);
1892 CWINAFSLOADAPP->WaitForEvent(SOCKETIO+2000,&wp,&msg); //wait 2 second longer than any socket IO
1895 case AFS_EXITCODE_NORMAL:
1898 // have to post message to myself so I can return Querry deny immediately
1900 CString *emsg=new CString(msg);
1901 m_cConnect.ModifyStyle(0,WS_DISABLED,0);
1902 m_cConnect.Invalidate();
1903 m_cCancel.SetWindowText("Exit");
1904 m_cCancel.Invalidate();
1905 PostMessage(WM_ERRORMSG,AFS_EXITCODE_GENERAL_FAILURE,(LPARAM)emsg);
1906 m_trayIcon.SetConnectState(2);
1911 m_bRestartAFSD=result;
1913 case PBT_APMRESUMESUSPEND:
1914 LOG("PBT_APMRESUMESUSPEND");
1915 REQUESTUIPOSTEVENT(WM_UICONNECT,WM_CONNECTRETURN,0);
1917 case PBT_APMRESUMECRITICAL:
1918 LOG("PBT_APMRESUMECRITICAL");
1919 REQUESTUIPOSTEVENT(WM_UICONNECT,WM_CONNECTRETURN,0);
1929 // lParam will contain CString, they must be deleted when done!
1930 LRESULT CWinAfsLoadDlg::OnErrorMessage(WPARAM wParam, LPARAM lParam)
1932 CString *msg=(CString *)lParam;
1933 MessageBox(*msg,"AFS Control Panel Warning");
1938 // actual message comes from AfsLoad (CWinApp)
1939 LRESULT CWinAfsLoadDlg::OnAfsEvent(WPARAM wParam, LPARAM lParam)
1942 CString * msg=(CString *)lParam;
1944 emsg.Format("OnAfsEvent %x [%s]",wParam,(const char *)(*msg));
1945 LOG((const char *)emsg);
1948 case AFS_EXITCODE_NORMAL:
1951 MessageBox((const char*)(*msg),"AFS Client Console Failure");
1960 void CWinAfsLoadDlg::ErrorDisplayState()
1962 m_cConnect.ModifyStyle(0,WS_DISABLED,0);
1963 m_cConnect.Invalidate();
1964 m_cCancel.SetWindowText("Exit");
1965 m_cCancel.Invalidate();
1966 m_cAuthenicate.ModifyStyle(0,WS_DISABLED,0);
1967 m_cAuthenicate.Invalidate();
1971 static CProgress *m_progress=NULL;
1973 // all calls must have set lParam null or contain a message to release
1974 // actual message comes from AfsLoad (CWinApp)
1975 LRESULT CWinAfsLoadDlg::OnNotifyReturn(WPARAM wParam, LPARAM lParam)
1976 {// fields messages from a NotifyFromUI, e.g. ONCONNECT ONPING
1977 // lParam contains the message that must be released
1984 case WM_CONNECTRETURN:
1986 {// we had a failure
1987 HandleError(*(CString *)lParam);
1988 delete (CString *)lParam;
1989 m_bRestartAFSD=FALSE;
1990 ErrorDisplayState();
1993 if (!m_bRestartAFSD)
1995 m_progress = new CProgress(this,7);
1998 m_progress->SetTitle("Power Restart","Enable AFS Client Console","Authenication");
2003 LOG("Wait %d seconds to Bring up AFSD",m_PowerResumeDelay);
2004 return TRUE; // do a return instead of break so Delete won't be called
2006 case WM_RESUMEDELAY:
2007 case WM_PINGRETURN: //we will return here after CONNECT(ONPING) finds the server connected
2008 LOG("Done with delay, load AFSD");
2012 m_bRestartAFSD=FALSE;
2014 {// we had a failure
2015 HandleError(*(CString *)lParam);
2016 delete (CString *)lParam;
2017 ErrorDisplayState();
2022 if (!m_cAfs.Create(msg,m_sComputername,m_procInfo))
2025 m_procInfo.hThread=0;
2026 ErrorDisplayState();
2029 LOG("AFS Client Powerup started successfully.");
2030 for (iItem=0;iItem<m_cMountlist.GetItemCount();iItem++)
2032 sKey = m_cMountlist.GetItemText(iItem,COLSHARE);
2033 if (stricmp(sKey,"all")!=0) continue;
2034 CString sAuto(m_cMountlist.GetItemText(iItem,COLAUTO));
2037 sDrive=m_cMountlist.GetItemText(iItem,COLDRIVE);
2038 LOG("Connect %s %s",sDrive,sKey);
2039 m_cAfs.Dismount(msg,sDrive,TRUE);
2040 if (!m_cAfs.Mount(msg,sDrive,sKey))
2043 m_cAfs.Shutdown(msg2);
2044 m_procInfo.hThread=0;
2045 msg2.Format("Connect can't continue: %s",msg);
2047 ErrorDisplayState();
2050 AddMenu(sDrive,sKey);
2055 if (!m_cAfs.Authencate(msg,m_sUsername,m_sPassword))
2058 DismountAll(msg,3); //unfortunately all drive references are invalid also!
2059 m_cAfs.Shutdown(msg2);
2060 m_procInfo.hThread=0;
2062 ErrorDisplayState();
2067 m_bServiceIsActive=TRUE;
2072 delete (CString *)lParam;
2082 BOOL CWinAfsLoadDlg::OnHelpInfo(HELPINFO* pHelpInfo)
2084 // TODO: Add your message handler code here and/or call default
2085 ::WinHelp(m_hWnd,CWINAFSLOADAPP->m_pszHelpFilePath,HELP_CONTEXT,IDH_MAIN);
2089 void CWinAfsLoadDlg::OnHelpmain()
2091 // TODO: Add your control notification handler code here
2092 ::WinHelp(m_hWnd,CWINAFSLOADAPP->m_pszHelpFilePath,HELP_CONTEXT,IDH_MAIN);
2096 void CWinAfsLoadDlg::OnSettings()
2098 // TODO: Add your control notification handler code here
2099 CRegkey regkey("AFS\\Window");
2100 CCommandSettings dlg;
2101 dlg.m_ConnectOnStart= CWINAFSLOADAPP->m_bConnect;
2102 dlg.m_LogToWindow=CWINAFSLOADAPP->m_bLogWindow;
2103 dlg.m_LogToFile=CWINAFSLOADAPP->m_bLog;
2104 dlg.m_UserName=m_sUsername;
2106 DWORD size=sizeof(tvar);
2107 regkey.GetBinary("LoginTime",(LPBYTE)&tvar,size);
2108 dlg.m_uMaxLoginTime=tvar;
2109 dlg.m_uMaxPowerRestartDelay=m_PowerResumeDelay;
2110 if (dlg.DoModal()==IDOK)
2112 if (dlg.m_LogToWindow ^ CWINAFSLOADAPP->m_bLogWindow)
2113 CWINAFSLOADAPP->ShowLog(dlg.m_LogToWindow);
2114 if (dlg.m_LogToFile ^ CWINAFSLOADAPP->m_bLog)
2115 CWINAFSLOADAPP->ShowPrint(dlg.m_LogToFile);
2116 CWINAFSLOADAPP->m_bLogWindow=dlg.m_LogToWindow;
2117 CWINAFSLOADAPP->m_bLog=dlg.m_LogToFile;
2118 CWINAFSLOADAPP->m_bConnect=dlg.m_ConnectOnStart;
2119 CWINAFSLOADAPP->RegOptions(FALSE);
2120 tvar=dlg.m_uMaxLoginTime;
2121 regkey.PutBinary("LoginTime",(LPBYTE)&tvar,size);
2122 m_PowerResumeDelay=dlg.m_uMaxPowerRestartDelay;
2123 regkey.PutBinary("PowerResumeDelay",(LPBYTE)&m_PowerResumeDelay,size);