Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

245 lines
5.8 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. HomeDir.cpp : implementation file
  5. CPropertyPage support for User mgmt wizard
  6. File History:
  7. JonY Apr-96 created
  8. --*/
  9. #include "stdafx.h"
  10. #include "speckle.h"
  11. #include "wizbased.h"
  12. #include "HomeDir.h"
  13. #ifdef _DEBUG
  14. //#define new DEBUG_NEW
  15. #undef THIS_FILE
  16. static char THIS_FILE[] = __FILE__;
  17. #endif
  18. /////////////////////////////////////////////////////////////////////////////
  19. // CHomeDir property page
  20. IMPLEMENT_DYNCREATE(CHomeDir, CWizBaseDlg)
  21. CHomeDir::CHomeDir() : CWizBaseDlg(CHomeDir::IDD)
  22. {
  23. //{{AFX_DATA_INIT(CHomeDir)
  24. m_csHome_dir_drive = _T("");
  25. m_csRemotePath = _T("");
  26. m_rbPathLocale = 0;
  27. m_csCaption = _T("");
  28. //}}AFX_DATA_INIT
  29. }
  30. CHomeDir::~CHomeDir()
  31. {
  32. }
  33. void CHomeDir::DoDataExchange(CDataExchange* pDX)
  34. {
  35. CPropertyPage::DoDataExchange(pDX);
  36. //{{AFX_DATA_MAP(CHomeDir)
  37. DDX_Control(pDX, IDC_DRIVE_LETTER, m_cbDriveLetter);
  38. DDX_CBString(pDX, IDC_DRIVE_LETTER, m_csHome_dir_drive);
  39. DDX_Text(pDX, IDC_REMOTE_PATH, m_csRemotePath);
  40. DDX_Radio(pDX, IDC_LOCAL_PATH_BUTTON, m_rbPathLocale);
  41. DDX_Text(pDX, IDC_STATIC1, m_csCaption);
  42. //}}AFX_DATA_MAP
  43. }
  44. BEGIN_MESSAGE_MAP(CHomeDir, CWizBaseDlg)
  45. //{{AFX_MSG_MAP(CHomeDir)
  46. ON_WM_SHOWWINDOW()
  47. ON_BN_CLICKED(IDC_LOCAL_PATH_BUTTON, OnLocalPathButton)
  48. ON_BN_CLICKED(IDC_REMOTE_PATH_BUTTON, OnRemotePathButton)
  49. //}}AFX_MSG_MAP
  50. END_MESSAGE_MAP()
  51. /////////////////////////////////////////////////////////////////////////////
  52. // CHomeDir message handlers
  53. LRESULT CHomeDir::OnWizardNext()
  54. {
  55. CSpeckleApp* pApp = (CSpeckleApp*)AfxGetApp();
  56. UpdateData(TRUE);
  57. if (m_rbPathLocale == 0) // local
  58. {
  59. pApp->m_csHomeDir = L""; // leave this empty per JonN and spec
  60. pApp->m_csHome_dir_drive = "";
  61. }
  62. else // remote
  63. {
  64. if (m_csRemotePath.Left(2) != L"\\\\")
  65. {
  66. AfxMessageBox(IDS_INVALID_PATH);
  67. GetDlgItem(IDC_REMOTE_PATH)->SetFocus();
  68. return -1;
  69. }
  70. if (m_csHome_dir_drive == L"")
  71. {
  72. AfxMessageBox(IDS_NO_HOMEDIR_DRIVE_LETTER);
  73. GetDlgItem(IDC_DRIVE_LETTER)->SetFocus();
  74. return -1;
  75. }
  76. CWaitCursor wait;
  77. // make sure directory exists
  78. if (CreateFile((const TCHAR*)m_csRemotePath, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE,
  79. NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL) == INVALID_HANDLE_VALUE)
  80. {
  81. DWORD dwErr = GetLastError();
  82. if (dwErr == 5) // access denied
  83. {
  84. AfxMessageBox(IDS_NO_DIR_PERMISSION, MB_ICONSTOP);
  85. return -1;
  86. }
  87. // store the current dir so it can be restored
  88. CString csCurDir;
  89. GetCurrentDirectory(256, csCurDir.GetBufferSetLength(256));
  90. csCurDir.ReleaseBuffer();
  91. CString csMessage;
  92. AfxFormatString1(csMessage, IDS_INVALID_DIRECTORY_NAME, m_csRemotePath);
  93. if (AfxMessageBox(csMessage, MB_YESNO) != IDYES) return -1;
  94. if (!CreateNewDirectory((const TCHAR*)m_csRemotePath))
  95. {
  96. if (AfxMessageBox(IDS_CANT_CREATE_DIRECTORY, MB_YESNO) != IDYES) return -1;
  97. }
  98. SetCurrentDirectory((LPCTSTR)csCurDir);
  99. }
  100. pApp->m_csHomeDir = m_csRemotePath;
  101. GetDlgItem(IDC_DRIVE_LETTER)->GetWindowText(pApp->m_csHome_dir_drive);
  102. pApp->m_csHome_dir_drive = pApp->m_csHome_dir_drive.Left(2); // trim off trailing blank
  103. pApp->m_csHome_dir_drive.MakeUpper();
  104. }
  105. if (pApp->m_bRAS) return IDD_RAS_PERM_DIALOG;
  106. else if (pApp->m_bNW) return IDD_FPNW_DLG;
  107. else if (pApp->m_bExchange) return IDD_EXCHANGE_DIALOG;
  108. else return IDD_RESTRICTIONS_DIALOG;
  109. }
  110. BOOL CHomeDir::CreateNewDirectory(const TCHAR* m_csDirectoryName)
  111. {
  112. // first remove the \\server\share info and CD to it
  113. CString csDir = m_csDirectoryName;
  114. csDir = csDir.Right(csDir.GetLength() - 2);
  115. CString csServer = csDir.Left(csDir.Find(L"\\"));
  116. csDir = csDir.Right((csDir.GetLength() - csServer.GetLength()) - 1);
  117. CString csShare = csDir.Left(csDir.Find(L"\\"));
  118. csDir = csDir.Right((csDir.GetLength() - csShare.GetLength()) - 1);
  119. CString csPath;
  120. csPath.Format(L"\\\\%s\\%s", csServer, csShare);
  121. if (!SetCurrentDirectory(csPath)) return FALSE;
  122. // parse out the individual path names and cd / md them
  123. TCHAR* pDirectory = new TCHAR[_tcslen(csDir) * sizeof(TCHAR)];
  124. _tcscpy(pDirectory, csDir);
  125. TCHAR* ppDir = pDirectory;
  126. TCHAR* pDir;
  127. pDir = _tcstok(pDirectory, L"\\");
  128. while (pDir != NULL)
  129. {
  130. if (!SetCurrentDirectory(pDir))
  131. {
  132. CreateDirectory(pDir, NULL);
  133. if (!SetCurrentDirectory(pDir))
  134. {
  135. delete ppDir;
  136. return FALSE;
  137. }
  138. }
  139. pDir = _tcstok(NULL, L"\\");
  140. }
  141. delete ppDir;
  142. TCHAR pCurDir[256];
  143. GetCurrentDirectory(256, pCurDir);
  144. CString csNewDir, csTemp;
  145. csTemp.LoadString(IDS_NEW_DIR_CREATED);
  146. csNewDir.Format(csTemp, pCurDir);
  147. AfxMessageBox(csNewDir);
  148. return TRUE;
  149. }
  150. LRESULT CHomeDir::OnWizardBack()
  151. {
  152. CSpeckleApp* pApp = (CSpeckleApp*)AfxGetApp();
  153. if (pApp->m_bLoginScript) return IDD_LOGON_SCRIPT_DIALOG;
  154. else if (pApp->m_bProfile) return IDD_PROFILE;
  155. else return IDD_OPTIONS_DIALOG;
  156. }
  157. BOOL CHomeDir::OnInitDialog()
  158. {
  159. CWizBaseDlg::OnInitDialog();
  160. // m_csLocalPath = "c:\\users\\default";
  161. // create list of available drives
  162. int drive;
  163. TCHAR tDrive[3];
  164. for( drive = 3; drive <= 26; drive++ )
  165. {
  166. swprintf(tDrive, L"%c: ", drive + 'A' - 1 );
  167. m_cbDriveLetter.AddString(tDrive);
  168. }
  169. return TRUE; // return TRUE unless you set the focus to a control
  170. // EXCEPTION: OCX Property Pages should return FALSE
  171. }
  172. void CHomeDir::OnShowWindow(BOOL bShow, UINT nStatus)
  173. {
  174. CWizBaseDlg::OnShowWindow(bShow, nStatus);
  175. if (bShow)
  176. {
  177. CSpeckleApp* pApp = (CSpeckleApp*)AfxGetApp();
  178. CString csTemp;
  179. csTemp.LoadString(IDS_HOMEDIR_CAPTION);
  180. CString csTemp2;
  181. csTemp2.Format(csTemp, pApp->m_csUserName);
  182. m_csCaption = csTemp2;
  183. UpdateData(FALSE);
  184. }
  185. }
  186. void CHomeDir::OnLocalPathButton()
  187. {
  188. GetDlgItem(IDC_DRIVE_LETTER)->EnableWindow(FALSE);
  189. GetDlgItem(IDC_REMOTE_PATH)->EnableWindow(FALSE);
  190. }
  191. void CHomeDir::OnRemotePathButton()
  192. {
  193. GetDlgItem(IDC_DRIVE_LETTER)->EnableWindow(TRUE);
  194. GetDlgItem(IDC_REMOTE_PATH)->EnableWindow(TRUE);
  195. }