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.

246 lines
6.8 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. wsprintf( szServerPath, L"\\\\%s", g_ServerName );
  33. lResult = RegOpenKeyEx( HKEY_LOCAL_MACHINE,
  34. L"Software\\Microsoft\\Windows\\CurrentVersion\\Setup",
  35. 0, // reserved
  36. KEY_READ,
  37. &hkeySetup );
  38. if ( lResult != ERROR_SUCCESS )
  39. goto Error;
  40. cbPath = sizeof(szPath );
  41. lResult = RegQueryValueEx( hkeySetup,
  42. L"SourcePath",
  43. 0, // reserved
  44. NULL,
  45. (LPBYTE) &szPath,
  46. &cbPath );
  47. if ( lResult != ERROR_SUCCESS )
  48. goto Error;
  49. if ( StrCmpNI( szPath, szServerPath, wcslen( szServerPath ) ) == 0 )
  50. {
  51. wsprintf( g_ImageName, L"%s\\%s", szPath, g_Architecture );
  52. DebugMsg( "Found Match! Using %s for SetupPath\n", g_ImageName );
  53. fMatch = TRUE;
  54. }
  55. Error:
  56. if ( hkeySetup != INVALID_HANDLE_VALUE )
  57. RegCloseKey( hkeySetup );
  58. RETURN(fMatch);
  59. }
  60. void
  61. PopulateImagesListbox2(
  62. HWND hwndList,
  63. LPWSTR pszDirName,
  64. LPWSTR pszOSPath )
  65. {
  66. HANDLE hFind;
  67. WIN32_FIND_DATA fd;
  68. WCHAR szPath[ MAX_PATH ];
  69. TraceFunc( "PopulateImagesListbox2( )\n" );
  70. wsprintf( szPath, L"%s\\%s\\%s\\templates\\*.sif", pszOSPath, pszDirName, g_Architecture );
  71. hFind = FindFirstFile( szPath, &fd );
  72. if ( hFind != INVALID_HANDLE_VALUE )
  73. {
  74. do
  75. {
  76. if (( fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) == 0 )
  77. {
  78. WCHAR szType[ 64 ];
  79. DWORD dwCount;
  80. wsprintf( szPath, L"%s\\%s\\%s\\templates\\%s", pszOSPath, pszDirName, g_Architecture, fd.cFileName );
  81. dwCount = GetPrivateProfileString( L"OSChooser",
  82. L"ImageType",
  83. L"",
  84. szType,
  85. ARRAYSIZE(szType),
  86. szPath );
  87. if ( dwCount
  88. && StrCmpIW( szType, L"flat" ) == 0 )
  89. {
  90. ListBox_AddString( hwndList, pszDirName );
  91. break; // list only once!
  92. }
  93. }
  94. } while ( FindNextFile( hFind, &fd ) );
  95. FindClose( hFind );
  96. }
  97. TraceFuncExit( );
  98. }
  99. void
  100. PopulateImagesListbox(
  101. HWND hwndList )
  102. {
  103. HANDLE hFind;
  104. WIN32_FIND_DATA fd;
  105. WCHAR szPath[ MAX_PATH ];
  106. TraceFunc( "PopulateImagesListbox( )\n" );
  107. ListBox_ResetContent( hwndList );
  108. wsprintf( szPath, L"\\\\%s\\REMINST\\Setup\\%s\\%s\\*", g_ServerName, g_Language, REMOTE_INSTALL_IMAGE_DIR_W );
  109. hFind = FindFirstFile( szPath, &fd );
  110. if ( hFind != INVALID_HANDLE_VALUE )
  111. {
  112. szPath[wcslen(szPath) - 2] = L'\0';
  113. do
  114. {
  115. if ( ( fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY )
  116. && StrCmp( fd.cFileName, L"." ) !=0
  117. && StrCmp( fd.cFileName, L".." ) !=0 )
  118. {
  119. PopulateImagesListbox2( hwndList, fd.cFileName, szPath );
  120. }
  121. } while ( FindNextFile( hFind, &fd ) );
  122. FindClose( hFind );
  123. }
  124. TraceFuncExit( );
  125. }
  126. //
  127. // SetupPathCheckNextButtonActivation( )
  128. //
  129. VOID
  130. SetupPathCheckNextButtonActivation(
  131. HWND hDlg )
  132. {
  133. TraceFunc( "SetupPathCheckNextButtonActivation( )\n" );
  134. LRESULT lResult = ListBox_GetCurSel( GetDlgItem( hDlg, IDC_L_IMAGES ) );
  135. PropSheet_SetWizButtons( GetParent( hDlg ), PSWIZB_BACK | ( lResult == LB_ERR ? 0 : PSWIZB_NEXT ));
  136. TraceFuncExit( );
  137. }
  138. //
  139. // SetupPathDlgProc()
  140. //
  141. INT_PTR CALLBACK
  142. SetupPathDlgProc(
  143. HWND hDlg,
  144. UINT uMsg,
  145. WPARAM wParam,
  146. LPARAM lParam )
  147. {
  148. switch (uMsg)
  149. {
  150. default:
  151. return FALSE;
  152. case WM_INITDIALOG:
  153. CenterDialog( GetParent( hDlg ) );
  154. return FALSE;
  155. case WM_COMMAND:
  156. switch ( LOWORD( wParam ) )
  157. {
  158. case IDC_L_IMAGES:
  159. if ( HIWORD( wParam ) == LBN_SELCHANGE )
  160. {
  161. SetupPathCheckNextButtonActivation( hDlg );
  162. }
  163. }
  164. break;
  165. case WM_NOTIFY:
  166. SetWindowLongPtr( hDlg, DWLP_MSGRESULT, FALSE );
  167. LPNMHDR lpnmhdr = (LPNMHDR) lParam;
  168. switch ( lpnmhdr->code )
  169. {
  170. case PSN_WIZNEXT:
  171. {
  172. HWND hwndList = GetDlgItem( hDlg, IDC_L_IMAGES );
  173. UINT sel = ListBox_GetCurSel( hwndList );
  174. if ( sel == -1 )
  175. {
  176. SetWindowLongPtr( hDlg, DWLP_MSGRESULT, -1 );
  177. }
  178. else
  179. {
  180. WCHAR szPath[ MAX_PATH ];
  181. ListBox_GetText( hwndList, sel, szPath );
  182. wsprintf( g_ImageName,
  183. L"\\\\%s\\REMINST\\Setup\\%s\\%s\\%s\\%s",
  184. g_ServerName,
  185. g_Language,
  186. REMOTE_INSTALL_IMAGE_DIR_W,
  187. szPath,
  188. g_Architecture );
  189. }
  190. }
  191. break;
  192. case PSN_QUERYCANCEL:
  193. return VerifyCancel( hDlg );
  194. case PSN_SETACTIVE:
  195. if ( DetermineSetupPath( ) )
  196. {
  197. DebugMsg( "Skipping SetupPath...\n" );
  198. SetWindowLongPtr( hDlg, DWLP_MSGRESULT, -1 ); // don't show
  199. }
  200. else
  201. {
  202. PopulateImagesListbox( GetDlgItem( hDlg, IDC_L_IMAGES ) );
  203. SetupPathCheckNextButtonActivation( hDlg );
  204. ClearMessageQueue( );
  205. }
  206. break;
  207. }
  208. break;
  209. }
  210. return TRUE;
  211. }