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.

175 lines
4.1 KiB

  1. /****************************************************************************
  2. Copyright (c) Microsoft Corporation 1998
  3. All rights reserved
  4. File: SERVERDLG.CPP
  5. ***************************************************************************/
  6. #include "pch.h"
  7. #include <remboot.h>
  8. #include "callback.h"
  9. #include "utils.h"
  10. DEFINE_MODULE( "RIPREP" );
  11. //
  12. // VerifyDirectoryName( )
  13. //
  14. // Make sure that the directory name entered conforms to the
  15. // restrictions that OSChooser has. Directory names also
  16. // can not contain spaces.
  17. //
  18. // Returns: S_OK if it does
  19. // E_FAIL if it does not
  20. //
  21. HRESULT
  22. VerifyDirectoryName(
  23. )
  24. {
  25. HRESULT hr = S_OK;
  26. TraceFunc( "VerifyDirectoryName()\n" );
  27. LPWSTR pszDir = g_MirrorDir;
  28. while ( *pszDir > 32 && *pszDir <= 127 )
  29. {
  30. pszDir++;
  31. }
  32. if ( *pszDir != L'\0' )
  33. {
  34. hr = E_FAIL;
  35. }
  36. HRETURN(hr);
  37. }
  38. //
  39. // CheckDirectory( )
  40. //
  41. // Make sure the directory doesn't exist on the server already.
  42. // If it does, ask the user what to do next.
  43. //
  44. // Returns: S_OK if the directory does NOT exist or if the user
  45. // said it was alright to overwrite.
  46. // E_FAIL if the directory existed and the user said
  47. // it was NOT ok to overwrite
  48. //
  49. HRESULT
  50. CheckDirectory(
  51. HWND hDlg )
  52. {
  53. TraceFunc( "CheckDirectory( ... )\n" );
  54. HRESULT hr = E_FAIL;
  55. WCHAR szPath[ MAX_PATH ];
  56. wsprintf( szPath,
  57. L"\\\\%s\\REMINST\\Setup\\%s\\%s\\%s",
  58. g_ServerName,
  59. g_Language,
  60. REMOTE_INSTALL_IMAGE_DIR_W,
  61. g_MirrorDir );
  62. DWORD dwAttrib = GetFileAttributes( szPath );
  63. if ( dwAttrib != 0xFFFFffff )
  64. {
  65. INT iResult = MessageBoxFromStrings( hDlg,
  66. IDS_DIRECTORY_EXISTS_TITLE,
  67. IDS_DIRECTORY_EXISTS_TEXT,
  68. MB_YESNO );
  69. if ( iResult == IDNO )
  70. goto Cleanup;
  71. }
  72. hr = S_OK;
  73. Cleanup:
  74. HRETURN(hr);
  75. }
  76. //
  77. // DirectoryDlgCheckNextButtonActivation( )
  78. //
  79. VOID
  80. DirectoryDlgCheckNextButtonActivation(
  81. HWND hDlg )
  82. {
  83. TraceFunc( "DirectoryDlgCheckNextButtonActivation( )\n" );
  84. GetDlgItemText( hDlg, IDC_E_OSDIRECTORY, g_MirrorDir, ARRAYSIZE(g_MirrorDir));
  85. PropSheet_SetWizButtons( GetParent( hDlg ), PSWIZB_BACK | (wcslen(g_MirrorDir) ? PSWIZB_NEXT : 0 ) );
  86. TraceFuncExit( );
  87. }
  88. //
  89. // DirectoryDlgProc()
  90. //
  91. INT_PTR CALLBACK
  92. DirectoryDlgProc(
  93. HWND hDlg,
  94. UINT uMsg,
  95. WPARAM wParam,
  96. LPARAM lParam )
  97. {
  98. switch (uMsg)
  99. {
  100. default:
  101. return FALSE;
  102. case WM_INITDIALOG:
  103. // Per bug 208881 - limit directory name to 67 chars
  104. Edit_LimitText( GetDlgItem( hDlg, IDC_E_OSDIRECTORY ), REMOTE_INSTALL_MAX_DIRECTORY_CHAR_COUNT - 1 );
  105. return FALSE;
  106. case WM_COMMAND:
  107. switch ( LOWORD( wParam ) )
  108. {
  109. case IDC_E_OSDIRECTORY:
  110. if ( HIWORD( wParam ) == EN_CHANGE )
  111. {
  112. DirectoryDlgCheckNextButtonActivation( hDlg );
  113. }
  114. break;
  115. }
  116. break;
  117. case WM_NOTIFY:
  118. SetWindowLongPtr( hDlg, DWLP_MSGRESULT, FALSE );
  119. LPNMHDR lpnmhdr = (LPNMHDR) lParam;
  120. switch ( lpnmhdr->code )
  121. {
  122. case PSN_WIZNEXT:
  123. GetDlgItemText( hDlg, IDC_E_OSDIRECTORY, g_MirrorDir, ARRAYSIZE(g_MirrorDir) );
  124. Assert( wcslen( g_MirrorDir ) );
  125. if ( FAILED( VerifyDirectoryName( ) ) )
  126. {
  127. MessageBoxFromStrings( hDlg, IDS_OSCHOOSER_RESTRICTION_TITLE, IDS_OSCHOOSER_RESTRICTION_TEXT, MB_OK );
  128. SetWindowLongPtr( hDlg, DWLP_MSGRESULT, -1 ); // don't go on
  129. break;
  130. }
  131. if ( FAILED( CheckDirectory( hDlg ) ) )
  132. {
  133. SetWindowLongPtr( hDlg, DWLP_MSGRESULT, -1 ); // don't go on
  134. break;
  135. }
  136. break;
  137. case PSN_QUERYCANCEL:
  138. return VerifyCancel( hDlg );
  139. case PSN_SETACTIVE:
  140. DirectoryDlgCheckNextButtonActivation( hDlg );
  141. ClearMessageQueue( );
  142. break;
  143. }
  144. break;
  145. }
  146. return TRUE;
  147. }