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.

207 lines
5.0 KiB

  1. // shrwiz.cpp : Defines the class behaviors for the application.
  2. //
  3. #include "stdafx.h"
  4. #include "shrwiz.h"
  5. #include "wizDir.h"
  6. #include "wizPerm.h"
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12. /////////////////////////////////////////////////////////////////////////////
  13. // CShrwizApp
  14. BEGIN_MESSAGE_MAP(CShrwizApp, CWinApp)
  15. //{{AFX_MSG_MAP(CShrwizApp)
  16. // NOTE - the ClassWizard will add and remove mapping macros here.
  17. // DO NOT EDIT what you see in these blocks of generated code!
  18. //}}AFX_MSG
  19. // ON_COMMAND(ID_HELP, CWinApp::OnHelp)
  20. END_MESSAGE_MAP()
  21. /////////////////////////////////////////////////////////////////////////////
  22. // CShrwizApp construction
  23. CShrwizApp::CShrwizApp()
  24. {
  25. m_bNextButtonClicked = TRUE;
  26. // filled in by initialization routine in shrwiz.cpp
  27. m_cstrTargetComputer.Empty();
  28. m_bIsLocal = FALSE;
  29. m_bServerFPNW = FALSE;
  30. m_bServerSFM = FALSE;
  31. m_hLibFPNW = NULL;
  32. m_hLibSFM = NULL;
  33. m_pWizard = NULL;
  34. // filled in by the folder page
  35. m_cstrFolder.Empty();
  36. m_cstrShareName.Empty();
  37. m_cstrShareDescription.Empty();
  38. m_cstrMACShareName.Empty();
  39. m_bSMB = FALSE;
  40. m_bFPNW = FALSE;
  41. m_bSFM = FALSE;
  42. // filled in by the permission page
  43. m_pSD = NULL;
  44. }
  45. CShrwizApp::~CShrwizApp()
  46. {
  47. TRACE(_T("CShrwizApp::~CShrwizApp\n"));
  48. if (m_hLibFPNW)
  49. FreeLibrary(m_hLibFPNW);
  50. if (m_hLibSFM)
  51. FreeLibrary(m_hLibSFM);
  52. if (m_pSD)
  53. LocalFree((HLOCAL)m_pSD);
  54. delete m_pWizard;
  55. }
  56. void
  57. CShrwizApp::Reset()
  58. {
  59. m_bNextButtonClicked = TRUE;
  60. // filled in by the folder page
  61. m_cstrFolder.Empty();
  62. m_cstrShareName.Empty();
  63. m_cstrShareDescription.Empty();
  64. m_cstrMACShareName.Empty();
  65. m_bSMB = FALSE;
  66. m_bFPNW = FALSE;
  67. m_bSFM = FALSE;
  68. // filled in by the permission page
  69. if (m_pSD)
  70. {
  71. LocalFree((HLOCAL)m_pSD);
  72. m_pSD = NULL;
  73. }
  74. m_pWizard->PostMessage(PSM_SETCURSEL, 0);
  75. }
  76. /////////////////////////////////////////////////////////////////////////////
  77. // The one and only CShrwizApp object
  78. CShrwizApp theApp;
  79. /////////////////////////////////////////////////////////////////////////////
  80. // CShrwizApp initialization
  81. BOOL CShrwizApp::InitInstance()
  82. {
  83. InitCommonControls(); // use XP theme-aware common controls
  84. Enable3dControls(); // Call this when using MFC in a shared DLL
  85. if (!GetTargetComputer())
  86. return FALSE;
  87. m_pMainWnd = NULL;
  88. m_pWizard = new CPropertySheet(IDS_WIZARD_TITLE, NULL, 0);
  89. CWizFolder folderPage;
  90. CWizPerm permPage;
  91. m_pWizard->AddPage(&folderPage);
  92. m_pWizard->AddPage(&permPage);
  93. m_pWizard->SetWizardMode();
  94. (m_pWizard->m_psh).dwFlags |= PSH_WIZARD_LITE;
  95. m_pWizard->DoModal();
  96. // Since the dialog has been closed, return FALSE so that we exit the
  97. // application, rather than start the application's message pump.
  98. return FALSE;
  99. }
  100. BOOL
  101. CShrwizApp::GetTargetComputer()
  102. {
  103. BOOL bReturn = FALSE;
  104. m_cstrTargetComputer.Empty();
  105. m_bIsLocal = FALSE;
  106. do { // false loop
  107. CString cstrCmdLine = m_lpCmdLine;
  108. cstrCmdLine.TrimLeft();
  109. cstrCmdLine.TrimRight();
  110. if (cstrCmdLine.IsEmpty() || cstrCmdLine == _T("/s"))
  111. { // local computer
  112. TCHAR szBuffer[MAX_COMPUTERNAME_LENGTH + 1];
  113. DWORD dwSize = MAX_COMPUTERNAME_LENGTH + 1;
  114. if (GetComputerName(szBuffer, &dwSize))
  115. {
  116. m_cstrTargetComputer = szBuffer;
  117. m_bIsLocal = TRUE;
  118. } else
  119. {
  120. DisplayMessageBox(::GetActiveWindow(), MB_OK|MB_ICONERROR, GetLastError(), IDS_CANNOT_GET_LOCAL_COMPUTER);
  121. break;
  122. }
  123. } else if (_T("/s") == cstrCmdLine.Left(2))
  124. {
  125. if (_istspace(cstrCmdLine.GetAt(2)))
  126. {
  127. cstrCmdLine = cstrCmdLine.Mid(3);
  128. cstrCmdLine.TrimLeft();
  129. if ( _T("\\\\") == cstrCmdLine.Left(2) )
  130. m_cstrTargetComputer = cstrCmdLine.Mid(2);
  131. else
  132. m_cstrTargetComputer = cstrCmdLine;
  133. }
  134. }
  135. if (m_cstrTargetComputer.IsEmpty())
  136. {
  137. CString cstrAppName = AfxGetAppName();
  138. CString cstrUsage;
  139. cstrUsage.FormatMessage(IDS_CMDLINE_PARAMS, cstrAppName);
  140. DisplayMessageBox(::GetActiveWindow(), MB_OK|MB_ICONERROR, 0, IDS_APP_USAGE, cstrUsage);
  141. break;
  142. } else
  143. {
  144. SERVER_INFO_102 *pInfo = NULL;
  145. DWORD dwRet = ::NetServerGetInfo(
  146. const_cast<LPTSTR>(static_cast<LPCTSTR>(m_cstrTargetComputer)), 102, (LPBYTE*)&pInfo);
  147. if (NERR_Success == dwRet)
  148. {
  149. m_bServerFPNW = (pInfo->sv102_type & SV_TYPE_SERVER_MFPN) &&
  150. (m_hLibFPNW = LoadLibrary(_T("fpnwclnt.dll")));
  151. m_bServerSFM = (pInfo->sv102_type & SV_TYPE_AFP) &&
  152. (m_hLibSFM = LoadLibrary(_T("sfmapi.dll")));
  153. NetApiBufferFree(pInfo);
  154. if (!m_bIsLocal)
  155. m_bIsLocal = IsLocalComputer(m_cstrTargetComputer);
  156. bReturn = TRUE;
  157. } else
  158. {
  159. DisplayMessageBox(::GetActiveWindow(), MB_OK|MB_ICONERROR, dwRet, IDS_CANNOT_CONTACT_COMPUTER, m_cstrTargetComputer);
  160. break;
  161. }
  162. }
  163. } while (0);
  164. if (!bReturn)
  165. m_cstrTargetComputer.Empty();
  166. return bReturn;
  167. }