Leaked source code of windows server 2003
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.

253 lines
7.4 KiB

  1. /****************************************************************************
  2. Copyright (c) Microsoft Corporation 1998
  3. All rights reserved
  4. File: SETUPDLG.CPP
  5. ***************************************************************************/
  6. #include "pch.h"
  7. #include "callback.h"
  8. #include "utils.h"
  9. DEFINE_MODULE( "RIPREP" )
  10. //
  11. // DetermineSetupPath( )
  12. //
  13. // Try to figure out if the server selected is the same server
  14. // that this client computer was installed from. If so, make the
  15. // assumption that he'll choose the same image that installed it.
  16. // We'll bypass the screen and auto-fill the g_ImageName.
  17. //
  18. // Returns: TRUE if we were able to that the system was installed
  19. // from the save server that we are posting to.
  20. // otherwize FALSE
  21. //
  22. BOOLEAN
  23. DetermineSetupPath( )
  24. {
  25. HKEY hkeySetup = (HKEY) INVALID_HANDLE_VALUE;
  26. LONG lResult;
  27. WCHAR szServerPath[ MAX_PATH ];
  28. WCHAR szPath[ MAX_PATH ];
  29. DWORD cbPath;
  30. BOOLEAN fMatch = FALSE;
  31. TraceFunc( "DetermineSetupPath( )\n" );
  32. _snwprintf( szServerPath, ARRAYSIZE(szServerPath), L"\\\\%s", g_ServerName );
  33. TERMINATE_BUFFER(szServerPath);
  34. lResult = RegOpenKeyEx( HKEY_LOCAL_MACHINE,
  35. L"Software\\Microsoft\\Windows\\CurrentVersion\\Setup",
  36. 0, // reserved
  37. KEY_READ,
  38. &hkeySetup );
  39. if ( lResult != ERROR_SUCCESS )
  40. goto Error;
  41. cbPath = sizeof(szPath );
  42. lResult = RegQueryValueEx( hkeySetup,
  43. L"SourcePath",
  44. 0, // reserved
  45. NULL,
  46. (LPBYTE) &szPath,
  47. &cbPath );
  48. if ( lResult != ERROR_SUCCESS )
  49. goto Error;
  50. if ( StrCmpNI( szPath, szServerPath, wcslen( szServerPath ) ) == 0 )
  51. {
  52. _snwprintf( g_ImageName, ARRAYSIZE(g_ImageName), L"%s\\%s", szPath, g_Architecture );
  53. TERMINATE_BUFFER(g_ImageName);
  54. DebugMsg( "Found Match! Using %s for SetupPath\n", g_ImageName );
  55. fMatch = TRUE;
  56. }
  57. Error:
  58. if ( hkeySetup != INVALID_HANDLE_VALUE )
  59. RegCloseKey( hkeySetup );
  60. RETURN(fMatch);
  61. }
  62. void
  63. PopulateImagesListbox2(
  64. HWND hwndList,
  65. LPWSTR pszDirName,
  66. LPWSTR pszOSPath )
  67. {
  68. HANDLE hFind;
  69. WIN32_FIND_DATA fd;
  70. WCHAR szPath[ MAX_PATH ];
  71. TraceFunc( "PopulateImagesListbox2( )\n" );
  72. _snwprintf( szPath, ARRAYSIZE(szPath), L"%s\\%s\\%s\\templates\\*.sif", pszOSPath, pszDirName, g_Architecture );
  73. TERMINATE_BUFFER(szPath);
  74. hFind = FindFirstFile( szPath, &fd );
  75. if ( hFind != INVALID_HANDLE_VALUE )
  76. {
  77. do
  78. {
  79. if (( fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) == 0 )
  80. {
  81. WCHAR szType[ 64 ];
  82. DWORD dwCount;
  83. _snwprintf( szPath, ARRAYSIZE(szPath), L"%s\\%s\\%s\\templates\\%s", pszOSPath, pszDirName, g_Architecture, fd.cFileName );
  84. TERMINATE_BUFFER(szPath);
  85. dwCount = GetPrivateProfileString( L"OSChooser",
  86. L"ImageType",
  87. L"",
  88. szType,
  89. ARRAYSIZE(szType),
  90. szPath );
  91. if ( dwCount
  92. && StrCmpIW( szType, L"flat" ) == 0 )
  93. {
  94. ListBox_AddString( hwndList, pszDirName );
  95. break; // list only once!
  96. }
  97. }
  98. } while ( FindNextFile( hFind, &fd ) );
  99. FindClose( hFind );
  100. }
  101. TraceFuncExit( );
  102. }
  103. void
  104. PopulateImagesListbox(
  105. HWND hwndList )
  106. {
  107. HANDLE hFind;
  108. WIN32_FIND_DATA fd;
  109. WCHAR szPath[ MAX_PATH ];
  110. TraceFunc( "PopulateImagesListbox( )\n" );
  111. ListBox_ResetContent( hwndList );
  112. _snwprintf( szPath, ARRAYSIZE(szPath), L"\\\\%s\\REMINST\\Setup\\%s\\%s\\*", g_ServerName, g_Language, REMOTE_INSTALL_IMAGE_DIR_W );
  113. TERMINATE_BUFFER(szPath);
  114. hFind = FindFirstFile( szPath, &fd );
  115. if ( hFind != INVALID_HANDLE_VALUE )
  116. {
  117. szPath[wcslen(szPath) - 2] = L'\0';
  118. do
  119. {
  120. if ( ( fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY )
  121. && StrCmp( fd.cFileName, L"." ) !=0
  122. && StrCmp( fd.cFileName, L".." ) !=0 )
  123. {
  124. PopulateImagesListbox2( hwndList, fd.cFileName, szPath );
  125. }
  126. } while ( FindNextFile( hFind, &fd ) );
  127. FindClose( hFind );
  128. }
  129. TraceFuncExit( );
  130. }
  131. //
  132. // SetupPathCheckNextButtonActivation( )
  133. //
  134. VOID
  135. SetupPathCheckNextButtonActivation(
  136. HWND hDlg )
  137. {
  138. TraceFunc( "SetupPathCheckNextButtonActivation( )\n" );
  139. LRESULT lResult = ListBox_GetCurSel( GetDlgItem( hDlg, IDC_L_IMAGES ) );
  140. PropSheet_SetWizButtons( GetParent( hDlg ), PSWIZB_BACK | ( lResult == LB_ERR ? 0 : PSWIZB_NEXT ));
  141. TraceFuncExit( );
  142. }
  143. //
  144. // SetupPathDlgProc()
  145. //
  146. INT_PTR CALLBACK
  147. SetupPathDlgProc(
  148. HWND hDlg,
  149. UINT uMsg,
  150. WPARAM wParam,
  151. LPARAM lParam )
  152. {
  153. switch (uMsg)
  154. {
  155. default:
  156. return FALSE;
  157. case WM_INITDIALOG:
  158. CenterDialog( GetParent( hDlg ) );
  159. return FALSE;
  160. case WM_COMMAND:
  161. switch ( LOWORD( wParam ) )
  162. {
  163. case IDC_L_IMAGES:
  164. if ( HIWORD( wParam ) == LBN_SELCHANGE )
  165. {
  166. SetupPathCheckNextButtonActivation( hDlg );
  167. }
  168. }
  169. break;
  170. case WM_NOTIFY:
  171. SetWindowLongPtr( hDlg, DWLP_MSGRESULT, FALSE );
  172. LPNMHDR lpnmhdr = (LPNMHDR) lParam;
  173. switch ( lpnmhdr->code )
  174. {
  175. case PSN_WIZNEXT:
  176. {
  177. HWND hwndList = GetDlgItem( hDlg, IDC_L_IMAGES );
  178. UINT sel = ListBox_GetCurSel( hwndList );
  179. if ( sel == -1 )
  180. {
  181. SetWindowLongPtr( hDlg, DWLP_MSGRESULT, -1 );
  182. }
  183. else
  184. {
  185. WCHAR szPath[ MAX_PATH ];
  186. ListBox_GetText( hwndList, sel, szPath );
  187. _snwprintf( g_ImageName,
  188. ARRAYSIZE(g_ImageName),
  189. L"\\\\%s\\REMINST\\Setup\\%s\\%s\\%s\\%s",
  190. g_ServerName,
  191. g_Language,
  192. REMOTE_INSTALL_IMAGE_DIR_W,
  193. szPath,
  194. g_Architecture );
  195. TERMINATE_BUFFER(g_ImageName);
  196. }
  197. }
  198. break;
  199. case PSN_QUERYCANCEL:
  200. return VerifyCancel( hDlg );
  201. case PSN_SETACTIVE:
  202. if ( DetermineSetupPath( ) )
  203. {
  204. DebugMsg( "Skipping SetupPath...\n" );
  205. SetWindowLongPtr( hDlg, DWLP_MSGRESULT, -1 ); // don't show
  206. }
  207. else
  208. {
  209. PopulateImagesListbox( GetDlgItem( hDlg, IDC_L_IMAGES ) );
  210. SetupPathCheckNextButtonActivation( hDlg );
  211. ClearMessageQueue( );
  212. }
  213. break;
  214. }
  215. break;
  216. }
  217. return TRUE;
  218. }