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.

2678 lines
89 KiB

  1. //
  2. // Copyright 1997 - Microsoft
  3. //
  4. // IMOS.CPP - Handles the "IntelliMirror OS" IDD_PROP_INTELLIMIRROR_OS tab
  5. //
  6. #include "pch.h"
  7. #include "addwiz.h"
  8. #include "cservice.h"
  9. #include "utils.h"
  10. #include <lm.h>
  11. #include <shlobj.h>
  12. #include <commdlg.h>
  13. DEFINE_MODULE("IMADMUI")
  14. DEFINE_THISCLASS("CAddWiz")
  15. #define THISCLASS CAddWiz
  16. #define LPTHISCLASS LPCADDWIZ
  17. #define BITMAP_WIDTH 16
  18. #define BITMAP_HEIGHT 16
  19. #define LG_BITMAP_WIDTH 32
  20. #define LG_BITMAP_HEIGHT 32
  21. #define NUM_COLUMNS 5
  22. #define SERVER_START_STRING L"\\\\%s\\" REMINST_SHARE
  23. //
  24. // CreateInstance()
  25. //
  26. HRESULT
  27. CAddWiz_CreateInstance(
  28. HWND hwndParent,
  29. LPUNKNOWN punk )
  30. {
  31. TraceFunc( "CAddWiz_CreateInstance()\n" );
  32. LPTHISCLASS lpcc = new THISCLASS( );
  33. HRESULT hr;
  34. if (lpcc == NULL) {
  35. hr = S_FALSE;
  36. } else {
  37. hr = THR( lpcc->Init( hwndParent, punk ) );
  38. delete lpcc;
  39. }
  40. HRETURN(hr);
  41. }
  42. //
  43. // Constructor
  44. //
  45. THISCLASS::THISCLASS( )
  46. {
  47. TraceClsFunc( "CAddWiz()\n" );
  48. Assert( !_pszServerName );
  49. Assert( !_pszSourcePath );
  50. Assert( !_pszDestPath );
  51. Assert( !_pszSourceImage );
  52. Assert( !_pszDestImage );
  53. Assert( !_pszSourceServerName );
  54. InterlockIncrement( g_cObjects );
  55. TraceFuncExit();
  56. }
  57. //
  58. // Init()
  59. //
  60. STDMETHODIMP
  61. THISCLASS::Init(
  62. HWND hwndParent,
  63. LPUNKNOWN punk )
  64. {
  65. TraceClsFunc( "Init()\n" );
  66. if (!LoadString( g_hInstance, IDS_NA, _szNA, ARRAYSIZE(_szNA))) {
  67. HRETURN(HRESULT_FROM_WIN32(GetLastError()));
  68. }
  69. if (!LoadString( g_hInstance, IDS_USER_LOCATION, _szLocation, ARRAYSIZE(_szLocation))) {
  70. HRETURN(HRESULT_FROM_WIN32(GetLastError()));
  71. }
  72. if ( !punk )
  73. HRETURN(E_POINTER);
  74. HRESULT hr = S_OK;
  75. HPROPSHEETPAGE rPages[ 10 ];
  76. PROPSHEETHEADER pshead;
  77. _punk = punk;
  78. _punk->AddRef( );
  79. ZeroMemory( &pshead, sizeof(pshead) );
  80. pshead.dwSize = sizeof(pshead);
  81. pshead.dwFlags = PSH_WIZARD97 | PSH_PROPTITLE | PSH_HEADER;
  82. pshead.hInstance = g_hInstance;
  83. pshead.pszCaption = MAKEINTRESOURCE( IDS_ADD_DOT_DOT_DOT );
  84. pshead.phpage = rPages;
  85. pshead.pszbmHeader = MAKEINTRESOURCE( IDB_HEADER );
  86. pshead.hwndParent = hwndParent;
  87. AddWizardPage( &pshead, IDD_ADD_PAGE1, Page1DlgProc, IDS_PAGE1_TITLE, IDS_PAGE1_SUBTITLE, (LPARAM) this );
  88. AddWizardPage( &pshead, IDD_ADD_PAGE2, Page2DlgProc, IDS_PAGE2_TITLE, IDS_PAGE2_SUBTITLE, (LPARAM) this );
  89. AddWizardPage( &pshead, IDD_ADD_PAGE6, Page6DlgProc, IDS_PAGE6_TITLE, IDS_PAGE6_SUBTITLE, (LPARAM) this );
  90. AddWizardPage( &pshead, IDD_ADD_PAGE3, Page3DlgProc, IDS_PAGE3_TITLE, IDS_PAGE3_SUBTITLE, (LPARAM) this );
  91. AddWizardPage( &pshead, IDD_ADD_PAGE4, Page4DlgProc, IDS_PAGE4_TITLE, IDS_PAGE4_SUBTITLE, (LPARAM) this );
  92. AddWizardPage( &pshead, IDD_ADD_PAGE5, Page5DlgProc, IDS_PAGE5_TITLE, IDS_PAGE5_SUBTITLE, (LPARAM) this );
  93. AddWizardPage( &pshead, IDD_ADD_PAGE7, Page7DlgProc, IDS_PAGE7_TITLE, IDS_PAGE7_SUBTITLE, (LPARAM) this );
  94. AddWizardPage( &pshead, IDD_ADD_PAGE8, Page8DlgProc, IDS_PAGE8_TITLE, IDS_PAGE8_SUBTITLE, (LPARAM) this );
  95. AddWizardPage( &pshead, IDD_ADD_PAGE9, Page9DlgProc, IDS_PAGE9_TITLE, IDS_PAGE9_SUBTITLE, (LPARAM) this );
  96. AddWizardPage( &pshead, IDD_ADD_PAGE10, Page10DlgProc, IDS_PAGE10_TITLE, IDS_PAGE10_SUBTITLE, (LPARAM) this );
  97. PropertySheet( &pshead );
  98. HRETURN(hr);
  99. }
  100. //
  101. // Destructor
  102. //
  103. THISCLASS::~THISCLASS( )
  104. {
  105. TraceClsFunc( "~CAddWiz()\n" );
  106. Assert( !_pszPathBuffer );
  107. if ( !_pszPathBuffer ) {
  108. TraceFree( _pszPathBuffer );
  109. _pszPathBuffer = NULL;
  110. }
  111. if ( _punk )
  112. _punk->Release( );
  113. if ( _pszServerName )
  114. TraceFree( _pszServerName );
  115. if ( _pszSourcePath )
  116. TraceFree( _pszSourcePath );
  117. if ( _pszSourceServerName )
  118. TraceFree( _pszSourceServerName );
  119. if ( _pszDestPath )
  120. TraceFree( _pszDestPath );
  121. if ( _pszSourceImage
  122. && _pszSourceImage != _szNA
  123. && _pszSourceImage != _szLocation )
  124. TraceFree( _pszSourceImage );
  125. if ( _pszDestImage
  126. && _pszDestImage != _szNA
  127. && _pszDestImage != _szLocation )
  128. TraceFree( _pszDestImage );
  129. InterlockDecrement( g_cObjects );
  130. TraceFuncExit();
  131. };
  132. // ************************************************************************
  133. //
  134. // Wizard Functions
  135. //
  136. // ************************************************************************
  137. //
  138. // _PopulateSamplesListView( )
  139. //
  140. STDMETHODIMP
  141. THISCLASS::_PopulateSamplesListView(
  142. LPWSTR pszStartPath
  143. )
  144. {
  145. TraceClsFunc( "_PopulateSamplesListView( " );
  146. TraceMsg( TF_FUNC, "pszStartPath = '%s' )\n", pszStartPath );
  147. if ( !pszStartPath )
  148. HRETURN(E_POINTER);
  149. Assert( _hDlg );
  150. Assert( _hwndList );
  151. CWaitCursor Wait;
  152. HRESULT hr;
  153. HANDLE hFind = INVALID_HANDLE_VALUE;
  154. WIN32_FIND_DATA find;
  155. ListView_DeleteAllItems( _hwndList );
  156. Assert( !_pszPathBuffer );
  157. _dwPathBufferSize = wcslen( pszStartPath ) + MAX_PATH;
  158. _pszPathBuffer = (LPWSTR) TraceAllocString( LMEM_FIXED, _dwPathBufferSize );
  159. if ( !_pszPathBuffer ) {
  160. hr = E_OUTOFMEMORY;
  161. _dwPathBufferSize = 0;
  162. goto Error;
  163. }
  164. wcscpy( _pszPathBuffer, pszStartPath );
  165. hr = _EnumerateSIFs( );
  166. Error:
  167. if ( _pszPathBuffer ) {
  168. TraceFree( _pszPathBuffer );
  169. _pszPathBuffer = NULL;
  170. _dwPathBufferSize = 0;
  171. }
  172. HRETURN(hr);
  173. }
  174. //
  175. // _PopulateTemplatesListView( )
  176. //
  177. STDMETHODIMP
  178. THISCLASS::_PopulateTemplatesListView(
  179. LPWSTR pszStartPath
  180. )
  181. {
  182. TraceClsFunc( "_PopulateTemplatesListView( " );
  183. TraceMsg( TF_FUNC, "pszStartPath = '%s' )\n", pszStartPath );
  184. if ( !pszStartPath )
  185. HRETURN(E_POINTER);
  186. Assert( _hDlg );
  187. Assert( _hwndList );
  188. CWaitCursor Wait;
  189. HRESULT hr;
  190. HANDLE hFind = INVALID_HANDLE_VALUE;
  191. WIN32_FIND_DATA find;
  192. ListView_DeleteAllItems( _hwndList );
  193. Assert( !_pszPathBuffer );
  194. _dwPathBufferSize = wcslen( pszStartPath ) + MAX_PATH ;
  195. _pszPathBuffer = (LPWSTR) TraceAllocString( LMEM_FIXED, _dwPathBufferSize );
  196. if ( !_pszPathBuffer ) {
  197. hr = E_OUTOFMEMORY;
  198. _dwPathBufferSize = 0;
  199. goto Error;
  200. }
  201. if (_snwprintf(_pszPathBuffer,
  202. _dwPathBufferSize,
  203. L"%s%s",
  204. pszStartPath,
  205. SLASH_SETUP) < 0) {
  206. hr = E_OUTOFMEMORY;
  207. goto Error;
  208. }
  209. _pszPathBuffer[_dwPathBufferSize-1] = L'\0';
  210. hr = _FindLanguageDirectory( _EnumerateTemplates );
  211. Error:
  212. if ( _pszPathBuffer ) {
  213. TraceFree( _pszPathBuffer );
  214. _pszPathBuffer = NULL;
  215. _dwPathBufferSize = 0;
  216. }
  217. HRETURN(hr);
  218. }
  219. //
  220. // _PopulateImageListView( )
  221. //
  222. STDMETHODIMP
  223. THISCLASS::_PopulateImageListView(
  224. LPWSTR pszStartPath
  225. )
  226. {
  227. TraceClsFunc( "_PopulateImageListView( " );
  228. TraceMsg( TF_FUNC, "pszStartPath = '%s' )\n", pszStartPath );
  229. if ( !pszStartPath )
  230. HRETURN(E_POINTER);
  231. Assert( _hDlg );
  232. Assert( _hwndList );
  233. CWaitCursor Wait;
  234. HRESULT hr;
  235. HANDLE hFind = INVALID_HANDLE_VALUE;
  236. WIN32_FIND_DATA find;
  237. ListView_DeleteAllItems( _hwndList );
  238. Assert( !_pszPathBuffer );
  239. _dwPathBufferSize = wcslen( pszStartPath ) + MAX_PATH ;
  240. _pszPathBuffer = (LPWSTR) TraceAllocString( LMEM_FIXED, _dwPathBufferSize );
  241. if ( !_pszPathBuffer ) {
  242. hr = E_OUTOFMEMORY;
  243. _dwPathBufferSize = 0;
  244. goto Error;
  245. }
  246. if (_snwprintf(_pszPathBuffer,
  247. _dwPathBufferSize,
  248. L"%s%s",
  249. pszStartPath,
  250. SLASH_SETUP) < 0) {
  251. hr = E_OUTOFMEMORY;
  252. goto Error;
  253. }
  254. hr = _FindLanguageDirectory( _EnumerateImages );
  255. Error:
  256. if ( _pszPathBuffer ) {
  257. TraceFree( _pszPathBuffer );
  258. _pszPathBuffer = NULL;
  259. _dwPathBufferSize = 0;
  260. }
  261. HRETURN(hr);
  262. }
  263. //
  264. // _FindLanguageDirectory( )
  265. //
  266. STDMETHODIMP
  267. THISCLASS::_FindLanguageDirectory(
  268. LPNEXTOP lpNextOperation )
  269. {
  270. TraceClsFunc( "_FindLanguageDirectory( ... )\n" );
  271. HRESULT hr = S_OK;
  272. HANDLE hFind = INVALID_HANDLE_VALUE;
  273. ULONG uLength;
  274. ULONG uLength2;
  275. WIN32_FIND_DATA find;
  276. Assert( _pszPathBuffer );
  277. Assert( lpNextOperation );
  278. uLength = wcslen( _pszPathBuffer );
  279. if (uLength + sizeof(L"\\*") > _dwPathBufferSize) {
  280. hr = E_INVALIDARG;
  281. goto Error;
  282. }
  283. wcscat( _pszPathBuffer, L"\\*" );
  284. uLength2 = wcslen( _pszPathBuffer ) - 1;
  285. hFind = FindFirstFile( _pszPathBuffer, &find );
  286. if ( hFind != INVALID_HANDLE_VALUE ) {
  287. do {
  288. if ( find.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY
  289. && StrCmp( find.cFileName, L"." ) != 0
  290. && StrCmp( find.cFileName, L".." ) != 0 ) {
  291. _pszPathBuffer[uLength2] = L'\0';
  292. if ( (wcslen(_pszPathBuffer) + wcslen( find.cFileName ) + 1) >
  293. _dwPathBufferSize) {
  294. hr = E_INVALIDARG;
  295. goto Error;
  296. }
  297. wcscat( _pszPathBuffer, find.cFileName );
  298. hr = _FindOSDirectory( lpNextOperation );
  299. if (FAILED(hr)) {
  300. goto Error;
  301. }
  302. }
  303. }
  304. while ( FindNextFile( hFind, &find ) );
  305. } else {
  306. hr = HRESULT_FROM_WIN32(GetLastError());
  307. }
  308. Error:
  309. if ( hFind != INVALID_HANDLE_VALUE ) {
  310. FindClose( hFind );
  311. }
  312. // restore the trailing NULL
  313. _pszPathBuffer[uLength] = L'\0';
  314. HRETURN(hr);
  315. }
  316. //
  317. // _FindOSDirectory( )
  318. //
  319. STDMETHODIMP
  320. THISCLASS::_FindOSDirectory(
  321. LPNEXTOP lpNextOperation )
  322. {
  323. TraceClsFunc( "_FindOSDirectory( ... )\n" );
  324. HRESULT hr = S_OK;
  325. HANDLE hFind = INVALID_HANDLE_VALUE;
  326. ULONG uLength;
  327. ULONG uLength2;
  328. WIN32_FIND_DATA find;
  329. Assert( _pszPathBuffer );
  330. Assert( lpNextOperation );
  331. uLength = wcslen( _pszPathBuffer );
  332. if (uLength + sizeof(SLASH_IMAGES L"\\*") > _dwPathBufferSize) {
  333. hr = E_INVALIDARG;
  334. goto Error;
  335. }
  336. wcscat( _pszPathBuffer, SLASH_IMAGES L"\\*");
  337. uLength2 = wcslen( _pszPathBuffer ) -1;
  338. hFind = FindFirstFile( _pszPathBuffer, &find );
  339. if ( hFind != INVALID_HANDLE_VALUE ) {
  340. do {
  341. if ( find.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY
  342. && StrCmp( find.cFileName, L"." ) != 0
  343. && StrCmp( find.cFileName, L".." ) != 0 ) {
  344. _pszPathBuffer[uLength2] = L'\0';
  345. if ( (wcslen(_pszPathBuffer) + wcslen( find.cFileName ) + 1) >
  346. _dwPathBufferSize) {
  347. hr = E_INVALIDARG;
  348. goto Error;
  349. }
  350. wcscat( _pszPathBuffer, find.cFileName );
  351. hr = _EnumeratePlatforms( lpNextOperation );
  352. if (FAILED(hr)) {
  353. goto Error;
  354. }
  355. }
  356. }
  357. while ( FindNextFile( hFind, &find ) );
  358. } else {
  359. hr = HRESULT_FROM_WIN32(GetLastError());
  360. }
  361. Error:
  362. if ( hFind != INVALID_HANDLE_VALUE )
  363. FindClose( hFind );
  364. _pszPathBuffer[uLength] = L'\0';
  365. HRETURN(hr);
  366. }
  367. //
  368. // _EnumeratePlatforms( )
  369. //
  370. STDMETHODIMP
  371. THISCLASS::_EnumeratePlatforms(
  372. LPNEXTOP lpNextOperation )
  373. {
  374. TraceClsFunc( "_EnumeratePlatforms( ... )\n" );
  375. HRESULT hr = S_OK;
  376. HANDLE hFind = INVALID_HANDLE_VALUE;
  377. ULONG uLength;
  378. ULONG uLength2;
  379. WIN32_FIND_DATA find;
  380. Assert( lpNextOperation );
  381. Assert( _pszPathBuffer );
  382. uLength = wcslen( _pszPathBuffer );
  383. if (uLength + sizeof(L"\\*") > _dwPathBufferSize) {
  384. hr = E_INVALIDARG;
  385. goto Error;
  386. }
  387. wcscat( _pszPathBuffer, L"\\*" );
  388. uLength2 = wcslen( _pszPathBuffer ) - 1;
  389. hFind = FindFirstFile( _pszPathBuffer, &find );
  390. if ( hFind != INVALID_HANDLE_VALUE ) {
  391. do {
  392. if ( find.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY
  393. && StrCmp( find.cFileName, L"." ) != 0
  394. && StrCmp( find.cFileName, L".." ) != 0 ) {
  395. _pszPathBuffer[uLength2] = L'\0';
  396. if ( (wcslen(_pszPathBuffer) + wcslen( find.cFileName ) + 1) >
  397. _dwPathBufferSize) {
  398. hr = E_INVALIDARG;
  399. goto Error;
  400. }
  401. wcscat( _pszPathBuffer, find.cFileName );
  402. hr = lpNextOperation( this );
  403. //
  404. // we can get ERROR_PATH_NOT_FOUND in several cases
  405. // like oem preinstall, etc. just eat the error and
  406. // continue
  407. //
  408. if (hr == HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND)) {
  409. hr = S_OK;
  410. }
  411. if (FAILED(hr)) {
  412. goto Error;
  413. }
  414. }
  415. }
  416. while ( FindNextFile( hFind, &find ) );
  417. } else {
  418. hr = HRESULT_FROM_WIN32(GetLastError());
  419. }
  420. Error:
  421. if ( hFind != INVALID_HANDLE_VALUE ) {
  422. FindClose( hFind );
  423. }
  424. // restore the path.
  425. _pszPathBuffer[uLength] = L'\0';
  426. HRETURN(hr);
  427. }
  428. //
  429. // _EnumerateTemplates( )
  430. //
  431. HRESULT
  432. THISCLASS::_EnumerateTemplates(
  433. LPTHISCLASS lpc )
  434. {
  435. TraceClsFunc( "_EnumerateTemplates( )\n" );
  436. HRESULT hr;
  437. ULONG uLength;
  438. Assert( lpc );
  439. Assert( lpc->_pszPathBuffer );
  440. uLength = wcslen( lpc->_pszPathBuffer );
  441. if (uLength + sizeof(SLASH_TEMPLATES) > lpc->_dwPathBufferSize) {
  442. hr = E_INVALIDARG;
  443. goto Error;
  444. }
  445. wcscat( lpc->_pszPathBuffer, SLASH_TEMPLATES );
  446. hr = lpc->_EnumerateSIFs( );
  447. Error:
  448. lpc->_pszPathBuffer[uLength] = L'\0';
  449. HRETURN(hr);
  450. }
  451. //
  452. // _EnumerateImages( )
  453. //
  454. HRESULT
  455. THISCLASS::_EnumerateImages(
  456. LPTHISCLASS lpc )
  457. {
  458. TraceClsFunc( "_EnumerateImages( )\n" );
  459. HRESULT hr;
  460. Assert( lpc );
  461. hr = lpc->_CheckImageType( );
  462. if ( hr == S_OK ) {
  463. hr = lpc->_AddItemToListView( );
  464. }
  465. HRETURN(hr);
  466. }
  467. //
  468. // _CheckImageType( )
  469. //
  470. // This won't add an item to the listview. It only checks to make
  471. // sure the image path points to a "Flat" image.
  472. //
  473. // Returns: S_OK - Flat image found
  474. // S_FALSE - not a flat image
  475. //
  476. HRESULT
  477. THISCLASS::_CheckImageType( )
  478. {
  479. TraceClsFunc( "_CheckImageType( )\n" );
  480. HRESULT hr = S_FALSE;
  481. HANDLE hFind = INVALID_HANDLE_VALUE;
  482. WIN32_FIND_DATA find;
  483. ULONG uLength;
  484. ULONG uLength2;
  485. Assert( _pszPathBuffer );
  486. uLength = wcslen( _pszPathBuffer );
  487. if (uLength + sizeof(L"\\ntoskrnl.exe") > _dwPathBufferSize) {
  488. hr = E_INVALIDARG;
  489. goto Error;
  490. }
  491. //
  492. // Check for <architecture>\ntoskrnl.exe to see
  493. // if this is a "flag" image. If we find this file
  494. // then we're done.
  495. //
  496. wcscat( _pszPathBuffer, L"\\ntoskrnl.exe" );
  497. hFind = FindFirstFile( _pszPathBuffer, &find );
  498. if ( hFind != INVALID_HANDLE_VALUE ) {
  499. do {
  500. if ( !(find.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ) {
  501. Assert( _wcsicmp( find.cFileName, L"ntoskrnl.exe" ) == 0 );
  502. hr = S_OK;
  503. goto Error;
  504. }
  505. }
  506. while ( FindNextFile( hFind, &find ) );
  507. FindClose( hFind );
  508. hFind = INVALID_HANDLE_VALUE;
  509. }
  510. //
  511. // Didn't find the kernel. Now check every sif
  512. // file in the TEMPLATES subdirectory and see if
  513. // he's got an OSCHOOSER_IMAGETYPE_ENTRY. If he
  514. // does, see if it's a "flat" image.
  515. //
  516. _pszPathBuffer[uLength] = L'\0';
  517. if (uLength + sizeof(SLASH_TEMPLATES L"\\*.sif") > _dwPathBufferSize) {
  518. hr = E_INVALIDARG;
  519. goto Error;
  520. }
  521. wcscat( _pszPathBuffer, SLASH_TEMPLATES L"\\*.sif");
  522. uLength2 = wcslen( _pszPathBuffer ) - 5;
  523. hFind = FindFirstFile( _pszPathBuffer, &find );
  524. if ( hFind != INVALID_HANDLE_VALUE ) {
  525. do {
  526. if ( !(find.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ) {
  527. WCHAR szImageType[ 40 ];
  528. _pszPathBuffer[uLength2] = L'\0';
  529. if ( (wcslen(_pszPathBuffer) + wcslen( find.cFileName ) + 1) >
  530. _dwPathBufferSize) {
  531. hr = E_INVALIDARG;
  532. goto Error;
  533. }
  534. wcscat( _pszPathBuffer, find.cFileName );
  535. GetPrivateProfileString( OSCHOOSER_SIF_SECTION,
  536. OSCHOOSER_IMAGETYPE_ENTRY,
  537. L"",
  538. szImageType,
  539. ARRAYSIZE(szImageType),
  540. _pszPathBuffer );
  541. if ( _wcsicmp( szImageType, OSCHOOSER_IMAGETYPE_FLAT ) == 0 ) {
  542. hr = S_OK;
  543. goto Error;
  544. }
  545. }
  546. }
  547. while ( FindNextFile( hFind, &find ) );
  548. FindClose( hFind );
  549. hFind = INVALID_HANDLE_VALUE;
  550. }
  551. Error:
  552. if ( hFind != INVALID_HANDLE_VALUE ) {
  553. FindClose( hFind );
  554. }
  555. _pszPathBuffer[uLength] = L'\0';
  556. HRETURN(hr);
  557. }
  558. //
  559. // _EnumerateSIFs( )
  560. //
  561. STDMETHODIMP
  562. THISCLASS::_EnumerateSIFs( )
  563. {
  564. TraceClsFunc( "_EnumerateSIFs( ... )\n" );
  565. HRESULT hr = S_OK;
  566. HANDLE hFind = INVALID_HANDLE_VALUE;
  567. ULONG uLength;
  568. WIN32_FIND_DATA find;
  569. Assert( _pszPathBuffer );
  570. if (wcslen(_pszPathBuffer) + ARRAYSIZE(L"\\*.sif") >_dwPathBufferSize) {
  571. return(E_INVALIDARG);
  572. }
  573. wcscat( _pszPathBuffer, L"\\*.sif" );
  574. uLength = wcslen( _pszPathBuffer ) - ARRAYSIZE(L"*.sif") + 1;
  575. Assert( uLength <= _dwPathBufferSize );
  576. hFind = FindFirstFile( _pszPathBuffer, &find );
  577. if ( hFind != INVALID_HANDLE_VALUE ) {
  578. do {
  579. if ( !(find.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) ) {
  580. _pszPathBuffer[uLength] = L'\0';
  581. if (wcslen(_pszPathBuffer) + wcslen(find.cFileName) + 1 > _dwPathBufferSize) {
  582. hr = E_INVALIDARG;
  583. goto Error;
  584. }
  585. wcscat( _pszPathBuffer, find.cFileName );
  586. hr = _AddItemToListView( );
  587. if (FAILED(hr))
  588. goto Error;
  589. }
  590. }
  591. while ( FindNextFile( hFind, &find ) );
  592. } else {
  593. hr = HRESULT_FROM_WIN32(GetLastError());
  594. }
  595. Error:
  596. if ( hFind != INVALID_HANDLE_VALUE ) {
  597. FindClose( hFind );
  598. }
  599. _pszPathBuffer[uLength] = L'\0';
  600. HRETURN(hr);
  601. }
  602. //
  603. // _AddItemToListView( )
  604. //
  605. // Returns: S_OK - Item add successfully
  606. // S_FALSE - Item is not valid
  607. // E_OUTOFMEMORY - obvious
  608. //
  609. // Note: this code is nearly identical to PopulateListView() in utils.cpp
  610. //
  611. //
  612. HRESULT
  613. THISCLASS::_AddItemToListView( )
  614. {
  615. TraceClsFunc( "_AddItemToListView( )\n" );
  616. Assert( _pszPathBuffer );
  617. HRESULT hr = S_OK;
  618. LPSIFINFO pSIF = NULL;
  619. LV_ITEM lvI;
  620. INT iCount = 0;
  621. LPWSTR psz;
  622. LPWSTR pszLanguage;
  623. LPWSTR pszImage;
  624. LPWSTR pszArchitecture;
  625. pSIF = (LPSIFINFO) TraceAlloc( LPTR, sizeof(SIFINFO) );
  626. if ( !pSIF ) {
  627. hr = E_OUTOFMEMORY;
  628. goto Error;
  629. }
  630. ZeroMemory( pSIF, sizeof(SIFINFO));
  631. pSIF->pszFilePath = (LPWSTR) TraceStrDup( _pszPathBuffer );
  632. if ( !pSIF->pszFilePath ) {
  633. hr = E_OUTOFMEMORY;
  634. goto Error;
  635. }
  636. psz = &_pszPathBuffer[ wcslen( _pszPathBuffer ) - 4 ];
  637. if ( _wcsicmp( psz, L".SIF" ) == 0 ) {
  638. WCHAR szImageType[ 40 ];
  639. GetPrivateProfileString( OSCHOOSER_SIF_SECTION,
  640. OSCHOOSER_IMAGETYPE_ENTRY,
  641. L"",
  642. szImageType,
  643. ARRAYSIZE(szImageType),
  644. _pszPathBuffer );
  645. // only show "Flat" SIFs
  646. if ( szImageType[0] && _wcsicmp( szImageType, OSCHOOSER_IMAGETYPE_FLAT ) ) {
  647. hr = S_FALSE; // skipping
  648. goto Error;
  649. }
  650. pSIF->pszDescription =
  651. (LPWSTR) TraceAllocString( LMEM_FIXED,
  652. REMOTE_INSTALL_MAX_DESCRIPTION_CHAR_COUNT );
  653. if ( !pSIF->pszDescription ) {
  654. hr = E_OUTOFMEMORY;
  655. goto Error;
  656. }
  657. GetPrivateProfileString( OSCHOOSER_SIF_SECTION,
  658. OSCHOOSER_DESCRIPTION_ENTRY,
  659. L"",
  660. pSIF->pszDescription,
  661. REMOTE_INSTALL_MAX_DESCRIPTION_CHAR_COUNT, // doesn't need -1
  662. _pszPathBuffer );
  663. if ( pSIF->pszDescription[0] == L'\0' ) {
  664. hr = S_FALSE;
  665. goto Error; // not a valid OSChooser SIF
  666. }
  667. pSIF->pszHelpText =
  668. (LPWSTR) TraceAllocString( LMEM_FIXED,
  669. REMOTE_INSTALL_MAX_HELPTEXT_CHAR_COUNT );
  670. if ( !pSIF->pszHelpText ) {
  671. hr = E_OUTOFMEMORY;
  672. goto Error;
  673. }
  674. GetPrivateProfileString( OSCHOOSER_SIF_SECTION,
  675. OSCHOOSER_HELPTEXT_ENTRY,
  676. L"",
  677. pSIF->pszHelpText,
  678. REMOTE_INSTALL_MAX_HELPTEXT_CHAR_COUNT, // doesn't need -1
  679. _pszPathBuffer );
  680. }
  681. // This path will be in one of these forms:
  682. // \\server\reminst\setup\english\images\nt50.wks\i386 ( Samples )
  683. // \\server\reminst\setup\english\images\nt50.wks\i386\templates ( template SIFs )
  684. // \\server\reminst\setup\english\images ( Images )
  685. // Find the language from the path
  686. psz = StrStr( _pszPathBuffer, SLASH_SETUP L"\\" );
  687. if (!psz) {
  688. goto Language_NA;
  689. }
  690. psz++;
  691. if ( !*psz ) {
  692. goto Language_NA;
  693. }
  694. psz = StrChr( psz, L'\\' );
  695. if (!psz) {
  696. goto Language_NA;
  697. }
  698. psz++;
  699. if ( !*psz ) {
  700. goto Language_NA;
  701. }
  702. pszLanguage = psz;
  703. psz = StrChr( psz, L'\\' );
  704. if ( psz ) {
  705. *psz = L'\0'; // terminate
  706. }
  707. pSIF->pszLanguage = (LPWSTR) TraceStrDup( pszLanguage );
  708. if ( psz ) {
  709. *psz = L'\\'; // restore
  710. }
  711. if ( !pSIF->pszLanguage ) {
  712. hr = E_OUTOFMEMORY;
  713. goto Language_NA;
  714. }
  715. // Find the image directory name from the path
  716. psz = StrStr( _pszPathBuffer, SLASH_IMAGES L"\\" );
  717. if ( !psz ) {
  718. goto Image_NA;
  719. }
  720. psz++;
  721. if ( !*psz ) {
  722. goto Image_NA;
  723. }
  724. psz = StrChr( psz, L'\\' );
  725. if (!psz) {
  726. goto Image_NA;
  727. }
  728. psz++;
  729. if ( !*psz ) {
  730. goto Image_NA;
  731. }
  732. pszImage = psz;
  733. psz = StrChr( psz, L'\\' );
  734. if ( psz ) {
  735. *psz = L'\0'; // terminate
  736. }
  737. pSIF->pszImageFile = (LPWSTR) TraceStrDup( pszImage );
  738. if ( psz ) {
  739. *psz = L'\\'; // restore
  740. }
  741. if ( !pSIF->pszImageFile ) {
  742. hr = E_OUTOFMEMORY;
  743. goto Image_NA;
  744. }
  745. // Find the architecture from the path
  746. if ( !*psz ) {
  747. goto Architecture_NA;
  748. }
  749. psz++;
  750. if ( !*psz ) {
  751. goto Architecture_NA;
  752. }
  753. pszArchitecture = psz;
  754. psz = StrChr( psz, L'\\' );
  755. if ( psz ) {
  756. *psz = L'\0'; // terminate
  757. }
  758. pSIF->pszArchitecture = (LPWSTR) TraceStrDup( pszArchitecture );
  759. if ( psz ) {
  760. *psz = L'\\'; // restore
  761. }
  762. if ( !pSIF->pszArchitecture ) {
  763. hr = E_OUTOFMEMORY;
  764. goto Architecture_NA;
  765. }
  766. goto Done;
  767. // Set columns that we couldn't determine to "n/a"
  768. Language_NA:
  769. pSIF->pszLanguage = _szNA;
  770. Image_NA:
  771. pSIF->pszImageFile = _szNA;
  772. Architecture_NA:
  773. pSIF->pszArchitecture = _szNA;
  774. Done:
  775. if ( !pSIF->pszDescription ) {
  776. pSIF->pszDescription = (LPWSTR) TraceStrDup( pSIF->pszImageFile );
  777. if ( !pSIF->pszDescription ) {
  778. hr = E_OUTOFMEMORY;
  779. goto Error;
  780. }
  781. }
  782. lvI.mask = LVIF_TEXT | LVIF_PARAM;
  783. lvI.iSubItem = 0;
  784. lvI.cchTextMax = REMOTE_INSTALL_MAX_DESCRIPTION_CHAR_COUNT;
  785. lvI.lParam = (LPARAM) pSIF;
  786. lvI.iItem = iCount;
  787. lvI.pszText = pSIF->pszDescription;
  788. iCount = ListView_InsertItem( _hwndList, &lvI );
  789. Assert( iCount != -1 );
  790. if ( iCount == -1 ) {
  791. goto Error;
  792. }
  793. ListView_SetItemText( _hwndList, iCount, 1, pSIF->pszArchitecture );
  794. ListView_SetItemText( _hwndList, iCount, 2, pSIF->pszLanguage );
  795. // ListView_SetItemText( hwndList, iCount, 3, pSIF->pszVersion );
  796. ListView_SetItemText( _hwndList, iCount, 3, pSIF->pszImageFile );
  797. pSIF = NULL; // don't free
  798. Error:
  799. if ( pSIF )
  800. THR( _CleanupSIFInfo( pSIF ) );
  801. HRETURN(hr);
  802. }
  803. //
  804. // _CleanUpSifInfo( )
  805. //
  806. HRESULT
  807. THISCLASS::_CleanupSIFInfo(
  808. LPSIFINFO pSIF )
  809. {
  810. TraceClsFunc( "_CleanupSIFInfo( )\n" );
  811. if ( !pSIF )
  812. HRETURN(E_POINTER);
  813. if ( pSIF->pszFilePath )
  814. TraceFree( pSIF->pszFilePath );
  815. if ( pSIF->pszDescription )
  816. TraceFree( pSIF->pszDescription );
  817. if (pSIF->pszHelpText) {
  818. TraceFree( pSIF->pszHelpText );
  819. }
  820. //if ( pSIF->pszImageType && pSIF->pszImageType != _szNA )
  821. // TraceFree( pSIF->pszImageType );
  822. if ( pSIF->pszArchitecture && pSIF->pszArchitecture != _szNA )
  823. TraceFree( pSIF->pszArchitecture );
  824. if ( pSIF->pszLanguage && pSIF->pszLanguage != _szNA )
  825. TraceFree( pSIF->pszLanguage );
  826. if ( pSIF->pszImageFile && pSIF->pszImageFile != _szNA )
  827. TraceFree( pSIF->pszImageFile );
  828. //if ( pSIF->pszVersion && pSIF->pszVersion != _szNA )
  829. // TraceFree( pSIF->pszVersion );
  830. TraceFree( pSIF );
  831. HRETURN(S_OK);
  832. }
  833. //
  834. // _InitListView( )
  835. //
  836. HRESULT
  837. THISCLASS::_InitListView(
  838. HWND hwndList,
  839. BOOL fShowDirectoryColumn )
  840. {
  841. TraceClsFunc( "_InitListView( )\n" );
  842. CWaitCursor Wait;
  843. LV_COLUMN lvC;
  844. INT iSubItem;
  845. INT iCount;
  846. LV_ITEM lvI;
  847. WCHAR szText[ 80 ];
  848. DWORD dw;
  849. UINT uColumnWidth[ NUM_COLUMNS ] = { 215, 75, 75, 75, 75};
  850. lvI.mask = LVIF_TEXT | LVIF_PARAM;
  851. lvI.iSubItem = 0;
  852. lvI.cchTextMax = DNS_MAX_NAME_BUFFER_LENGTH;
  853. // Create the columns
  854. lvC.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
  855. lvC.fmt = LVCFMT_LEFT;
  856. lvC.pszText = szText;
  857. // Add the columns.
  858. for ( iCount = 0; iCount < NUM_COLUMNS; iCount++ ) {
  859. INT i;
  860. if ( iCount == 3 )
  861. continue; // skip "Version"
  862. if ( !fShowDirectoryColumn && iCount == 4 )
  863. continue; // skip "Directory"
  864. lvC.iSubItem = iCount;
  865. lvC.cx = uColumnWidth[iCount];
  866. szText[0] = L'\0';
  867. dw = LoadString( g_hInstance,
  868. IDS_OS_COLUMN1 + iCount,
  869. szText,
  870. ARRAYSIZE(szText));
  871. Assert( dw );
  872. i = ListView_InsertColumn ( hwndList, iCount, &lvC );
  873. Assert( i != -1 );
  874. }
  875. ListView_DeleteAllItems( hwndList );
  876. HRETURN(S_OK);
  877. }
  878. //
  879. // Page1DlgProc( )
  880. //
  881. INT_PTR CALLBACK
  882. THISCLASS::Page1DlgProc(
  883. HWND hDlg,
  884. UINT uMsg,
  885. WPARAM wParam,
  886. LPARAM lParam )
  887. {
  888. LPTHISCLASS lpc = (LPTHISCLASS) GetWindowLongPtr( hDlg, GWLP_USERDATA );
  889. switch ( uMsg ) {
  890. case WM_INITDIALOG:
  891. TraceMsg( TF_WM, "WM_INITDIALOG\n" );
  892. {
  893. HRESULT hr;
  894. DWORD cbSize = DNS_MAX_NAME_BUFFER_LENGTH;
  895. WCHAR szFQDNS[ DNS_MAX_NAME_BUFFER_LENGTH ];
  896. IIntelliMirrorSAP * pimsap = NULL;
  897. LPPROPSHEETPAGE ppsp = (LPPROPSHEETPAGE) lParam;
  898. Assert( ppsp );
  899. Assert( ppsp->lParam );
  900. SetWindowLongPtr( hDlg, GWLP_USERDATA, ppsp->lParam );
  901. lpc = (LPTHISCLASS) ppsp->lParam;
  902. Button_SetCheck( GetDlgItem( hDlg, IDC_B_ADDSIF ), BST_CHECKED );
  903. Assert( lpc->_punk );
  904. hr = THR( lpc->_punk->QueryInterface( IID_IIntelliMirrorSAP,
  905. (void**) &pimsap ) );
  906. if (FAILED(hr)) {
  907. goto InitDialog_Error;
  908. }
  909. Assert( !lpc->_pszServerName );
  910. hr = THR( pimsap->GetServerName( &lpc->_pszServerName ) );
  911. if (FAILED(hr)) {
  912. goto InitDialog_Error;
  913. }
  914. if (GetComputerNameEx( ComputerNameNetBIOS, szFQDNS, &cbSize ) &&
  915. _wcsicmp( szFQDNS, lpc->_pszServerName ) == 0 ) {
  916. EnableWindow( GetDlgItem( hDlg, IDC_B_NEWIMAGE ), TRUE );
  917. }
  918. InitDialog_Error:
  919. return TRUE;
  920. }
  921. break;
  922. case WM_NOTIFY:
  923. {
  924. LPNMHDR lpnmhdr = (LPNMHDR) lParam;
  925. Assert( lpc );
  926. switch ( lpnmhdr->code ) {
  927. case PSN_SETACTIVE:
  928. PropSheet_SetWizButtons( GetParent( hDlg ), PSWIZB_NEXT );
  929. break;
  930. case PSN_WIZNEXT:
  931. TraceMsg( TF_WM, "PSN_WIZNEXT\n" );
  932. if ( Button_GetCheck( GetDlgItem( hDlg, IDC_B_ADDSIF ) )
  933. == BST_CHECKED ) {
  934. lpc->_fAddSif = TRUE;
  935. } else if ( Button_GetCheck( GetDlgItem( hDlg, IDC_B_NEWIMAGE ) )
  936. == BST_CHECKED ) {
  937. STARTUPINFO startupInfo;
  938. PROCESS_INFORMATION pi;
  939. BOOL bRet;
  940. const WCHAR szCommand[] = L"%systemroot%\\system32\\RISETUP.EXE -add";
  941. WCHAR szRealCommandLine[MAX_PATH + 5 + 1]; // 5 for ' -add' and 1 for null
  942. lpc->_fAddSif = FALSE;
  943. ZeroMemory( &startupInfo, sizeof( startupInfo) );
  944. startupInfo.cb = sizeof( startupInfo );
  945. if (ExpandEnvironmentStrings(
  946. szCommand,
  947. szRealCommandLine,
  948. ARRAYSIZE(szRealCommandLine)) &&
  949. CreateProcess(NULL,
  950. szRealCommandLine,
  951. NULL,
  952. NULL,
  953. TRUE,
  954. NORMAL_PRIORITY_CLASS,
  955. NULL,
  956. NULL,
  957. &startupInfo,
  958. &pi )) {
  959. CloseHandle( pi.hProcess );
  960. CloseHandle( pi.hThread );
  961. } else {
  962. DWORD dwErr = GetLastError( );
  963. MessageBoxFromError( hDlg,
  964. IDS_RISETUP_FAILED_TO_START,
  965. dwErr );
  966. }
  967. PropSheet_PressButton( GetParent( hDlg ), PSBTN_FINISH );
  968. }
  969. break;
  970. case PSN_QUERYCANCEL:
  971. TraceMsg( TF_WM, "PSN_QUERYCANCEL\n" );
  972. return lpc->_VerifyCancel( hDlg );
  973. }
  974. }
  975. break;
  976. }
  977. return FALSE;
  978. }
  979. //
  980. // Page2DlgProc( )
  981. //
  982. // SIF Selection dialog proc.
  983. //
  984. INT_PTR CALLBACK
  985. THISCLASS::Page2DlgProc(
  986. HWND hDlg,
  987. UINT uMsg,
  988. WPARAM wParam,
  989. LPARAM lParam )
  990. {
  991. LPTHISCLASS lpc = (LPTHISCLASS) GetWindowLongPtr( hDlg, GWLP_USERDATA );
  992. switch ( uMsg ) {
  993. case WM_INITDIALOG:
  994. TraceMsg( TF_WM, "WM_INITDIALOG\n" );
  995. {
  996. LPPROPSHEETPAGE ppsp = (LPPROPSHEETPAGE) lParam;
  997. Assert( ppsp );
  998. Assert( ppsp->lParam );
  999. SetWindowLongPtr( hDlg, GWLP_USERDATA, ppsp->lParam );
  1000. // lpc = (LPTHISCLASS) ppsp->lParam;
  1001. return TRUE;
  1002. }
  1003. break;
  1004. case WM_NOTIFY:
  1005. {
  1006. LPNMHDR lpnmhdr = (LPNMHDR) lParam;
  1007. Assert( lpc );
  1008. switch ( lpnmhdr->code ) {
  1009. case PSN_SETACTIVE:
  1010. TraceMsg( TF_WM, "PSN_SETACTIVE\n" );
  1011. if ( !lpc->_fAddSif ) {
  1012. SetWindowLongPtr( hDlg, DWLP_MSGRESULT, -1 ); // don't show
  1013. return TRUE;
  1014. } else {
  1015. LRESULT lResult;
  1016. lpc->_fCopyFromSamples = FALSE;
  1017. lpc->_fCopyFromLocation = FALSE;
  1018. lpc->_fCopyFromServer = FALSE;
  1019. lResult = Button_GetCheck( GetDlgItem( hDlg, IDC_B_FROMSAMPLES ) );
  1020. if ( lResult == BST_CHECKED ) {
  1021. lpc->_fCopyFromSamples = TRUE;
  1022. }
  1023. lResult = Button_GetCheck( GetDlgItem( hDlg, IDC_B_SERVER ) );
  1024. if ( lResult == BST_CHECKED ) {
  1025. lpc->_fCopyFromServer = TRUE;
  1026. }
  1027. lResult = Button_GetCheck( GetDlgItem( hDlg, IDC_B_LOCATION ) );
  1028. if ( lResult == BST_CHECKED ) {
  1029. lpc->_fCopyFromLocation = TRUE;
  1030. }
  1031. if ( !lpc->_fCopyFromLocation
  1032. && !lpc->_fCopyFromSamples && !lpc->_fCopyFromServer ) {
  1033. PropSheet_SetWizButtons( GetParent( hDlg ),
  1034. PSWIZB_BACK );
  1035. } else {
  1036. PropSheet_SetWizButtons( GetParent( hDlg ),
  1037. PSWIZB_BACK | PSWIZB_NEXT );
  1038. }
  1039. }
  1040. break;
  1041. case PSN_WIZNEXT:
  1042. TraceMsg( TF_WM, "PSN_WIZNEXT\n" );
  1043. {
  1044. LRESULT lResult;
  1045. lpc->_fCopyFromSamples = FALSE;
  1046. lpc->_fCopyFromLocation = FALSE;
  1047. lpc->_fCopyFromServer = FALSE;
  1048. lResult = Button_GetCheck( GetDlgItem( hDlg, IDC_B_FROMSAMPLES ) );
  1049. if ( lResult == BST_CHECKED ) {
  1050. lpc->_fCopyFromSamples = TRUE;
  1051. }
  1052. lResult = Button_GetCheck( GetDlgItem( hDlg, IDC_B_SERVER ) );
  1053. if ( lResult == BST_CHECKED ) {
  1054. lpc->_fCopyFromServer = TRUE;
  1055. }
  1056. lResult = Button_GetCheck( GetDlgItem( hDlg, IDC_B_LOCATION ) );
  1057. if ( lResult == BST_CHECKED ) {
  1058. lpc->_fCopyFromLocation = TRUE;
  1059. }
  1060. Assert( lpc->_fCopyFromLocation
  1061. || lpc->_fCopyFromSamples
  1062. || lpc->_fCopyFromServer );
  1063. }
  1064. break;
  1065. case PSN_QUERYCANCEL:
  1066. TraceMsg( TF_WM, "PSN_QUERYCANCEL\n" );
  1067. return lpc->_VerifyCancel( hDlg );
  1068. }
  1069. }
  1070. break;
  1071. case WM_COMMAND:
  1072. TraceMsg( TF_WM, "WM_COMMAND\n" );
  1073. HWND hwnd = (HWND) lParam;
  1074. switch ( LOWORD( wParam ) ) {
  1075. case IDC_B_FROMSAMPLES:
  1076. if ( HIWORD( wParam ) == BN_CLICKED ) {
  1077. LRESULT lResult = Button_GetCheck( hwnd );
  1078. if ( lResult == BST_CHECKED ) {
  1079. PropSheet_SetWizButtons( GetParent( hDlg ),
  1080. PSWIZB_BACK | PSWIZB_NEXT );
  1081. }
  1082. return TRUE;
  1083. }
  1084. break;
  1085. case IDC_B_SERVER:
  1086. if ( HIWORD( wParam ) == BN_CLICKED ) {
  1087. LRESULT lResult = Button_GetCheck( hwnd );
  1088. if ( lResult == BST_CHECKED ) {
  1089. PropSheet_SetWizButtons( GetParent( hDlg ),
  1090. PSWIZB_BACK | PSWIZB_NEXT );
  1091. }
  1092. return TRUE;
  1093. }
  1094. break;
  1095. case IDC_B_LOCATION:
  1096. if ( HIWORD( wParam ) == BN_CLICKED ) {
  1097. LRESULT lResult = Button_GetCheck( hwnd );
  1098. if ( lResult == BST_CHECKED ) {
  1099. PropSheet_SetWizButtons( GetParent( hDlg ),
  1100. PSWIZB_BACK | PSWIZB_NEXT );
  1101. }
  1102. return TRUE;
  1103. }
  1104. break;
  1105. }
  1106. break;
  1107. }
  1108. return FALSE;
  1109. }
  1110. //
  1111. // Page3DlgProc( )
  1112. //
  1113. INT_PTR CALLBACK
  1114. THISCLASS::Page3DlgProc(
  1115. HWND hDlg,
  1116. UINT uMsg,
  1117. WPARAM wParam,
  1118. LPARAM lParam )
  1119. {
  1120. LPTHISCLASS lpc = (LPTHISCLASS) GetWindowLongPtr( hDlg, GWLP_USERDATA );
  1121. switch ( uMsg ) {
  1122. case WM_INITDIALOG:
  1123. TraceMsg( TF_WM, "WM_INITDIALOG\n" );
  1124. {
  1125. LPPROPSHEETPAGE ppsp = (LPPROPSHEETPAGE) lParam;
  1126. Assert( ppsp );
  1127. Assert( ppsp->lParam );
  1128. SetWindowLongPtr( hDlg, GWLP_USERDATA, ppsp->lParam );
  1129. // lpc = (LPTHISCLASS) ppsp->lParam;
  1130. return TRUE;
  1131. }
  1132. break;
  1133. case WM_NOTIFY:
  1134. {
  1135. LPNMHDR lpnmhdr = (LPNMHDR) lParam;
  1136. Assert( lpc );
  1137. switch ( lpnmhdr->code ) {
  1138. case PSN_SETACTIVE:
  1139. TraceMsg( TF_WM, "PSN_SETACTIVE\n" );
  1140. if ( !lpc->_fAddSif || !lpc->_fCopyFromServer ) {
  1141. SetWindowLongPtr( hDlg, DWLP_MSGRESULT, -1 ); // don't show
  1142. return TRUE;
  1143. } else {
  1144. ULONG uLength =
  1145. Edit_GetTextLength( GetDlgItem( hDlg, IDC_E_SERVER ) );
  1146. if ( !uLength ) {
  1147. PropSheet_SetWizButtons( GetParent( hDlg ),
  1148. PSWIZB_BACK );
  1149. } else {
  1150. PropSheet_SetWizButtons( GetParent( hDlg ),
  1151. PSWIZB_BACK | PSWIZB_NEXT );
  1152. }
  1153. }
  1154. break;
  1155. case PSN_WIZNEXT:
  1156. TraceMsg( TF_WM, "PSN_WIZNEXT\n" );
  1157. {
  1158. CWaitCursor Wait;
  1159. LPSHARE_INFO_1 psi;
  1160. HWND hwndEdit = GetDlgItem( hDlg, IDC_E_SERVER );
  1161. ULONG uLength = Edit_GetTextLength( hwndEdit );
  1162. Assert( uLength );
  1163. uLength++; // add one for the NULL
  1164. // if we had a previous buffer allocated,
  1165. // see if we can reuse it
  1166. if ( lpc->_pszSourceServerName && uLength
  1167. > wcslen(lpc->_pszSourceServerName) + 1 ) {
  1168. TraceFree( lpc->_pszSourceServerName );
  1169. lpc->_pszSourceServerName = NULL;
  1170. }
  1171. if ( !lpc->_pszSourceServerName ) {
  1172. lpc->_pszSourceServerName =
  1173. (LPWSTR) TraceAllocString( LMEM_FIXED, uLength );
  1174. if ( !lpc->_pszSourceServerName )
  1175. goto PSN_WIZNEXTABORT;
  1176. }
  1177. Edit_GetText( hwndEdit, lpc->_pszSourceServerName, uLength );
  1178. if ( NERR_Success !=
  1179. NetShareGetInfo( lpc->_pszSourceServerName,
  1180. REMINST_SHARE,
  1181. 1,
  1182. (LPBYTE *) &psi ) ) {
  1183. MessageBoxFromStrings( hDlg,
  1184. IDS_NOTARISERVER_CAPTION,
  1185. IDS_NOTARISERVER_TEXT,
  1186. MB_OK );
  1187. SetFocus( hwndEdit );
  1188. goto PSN_WIZNEXTABORT;
  1189. } else {
  1190. NetApiBufferFree( psi );
  1191. }
  1192. break;
  1193. PSN_WIZNEXTABORT:
  1194. SetWindowLongPtr( hDlg, DWLP_MSGRESULT, -1 );
  1195. return TRUE;
  1196. }
  1197. break;
  1198. case LVN_DELETEALLITEMS:
  1199. TraceMsg( TF_WM, "LVN_DELETEALLITEMS - Deleting all items.\n" );
  1200. break;
  1201. case LVN_DELETEITEM:
  1202. TraceMsg( TF_WM, "LVN_DELETEITEM - Deleting an item.\n" );
  1203. {
  1204. LPNMLISTVIEW pnmv = (LPNMLISTVIEW) lParam;
  1205. LPSIFINFO pSIF = (LPSIFINFO) pnmv->lParam;
  1206. THR( lpc->_CleanupSIFInfo( pSIF ) );
  1207. }
  1208. break;
  1209. case PSN_QUERYCANCEL:
  1210. TraceMsg( TF_WM, "PSN_QUERYCANCEL\n" );
  1211. return lpc->_VerifyCancel( hDlg );
  1212. }
  1213. }
  1214. break;
  1215. case WM_COMMAND:
  1216. TraceMsg( TF_WM, "WM_COMMAND\n" );
  1217. HWND hwnd = (HWND) lParam;
  1218. switch ( LOWORD( wParam ) ) {
  1219. case IDC_E_SERVER:
  1220. if ( HIWORD( wParam ) == EN_CHANGE ) {
  1221. LONG uLength = Edit_GetTextLength( hwnd );
  1222. if ( !uLength ) {
  1223. PropSheet_SetWizButtons( GetParent( hDlg ),
  1224. PSWIZB_BACK );
  1225. } else {
  1226. PropSheet_SetWizButtons( GetParent( hDlg ),
  1227. PSWIZB_BACK | PSWIZB_NEXT );
  1228. }
  1229. return TRUE;
  1230. }
  1231. break;
  1232. case IDC_B_BROWSE:
  1233. if ( HIWORD( wParam ) == BN_CLICKED ) {
  1234. _OnSearch( hDlg );
  1235. }
  1236. break;
  1237. }
  1238. break;
  1239. }
  1240. return FALSE;
  1241. }
  1242. HRESULT
  1243. THISCLASS::_OnSearch(
  1244. HWND hDlg )
  1245. {
  1246. TraceClsFunc( "_OnSearch( )\n" );
  1247. HRESULT hr = E_FAIL;
  1248. DSQUERYINITPARAMS dqip;
  1249. OPENQUERYWINDOW oqw;
  1250. LPDSOBJECTNAMES pDsObjects;
  1251. VARIANT var;
  1252. ICommonQuery * pCommonQuery = NULL;
  1253. IDataObject *pdo;
  1254. VariantInit( &var );
  1255. hr = THR( CoCreateInstance( CLSID_CommonQuery, NULL, CLSCTX_INPROC_SERVER, IID_ICommonQuery, (PVOID *)&pCommonQuery) );
  1256. if (FAILED(hr)) {
  1257. goto Error;
  1258. }
  1259. ZeroMemory( &dqip, sizeof(dqip) );
  1260. dqip.cbStruct = sizeof(dqip);
  1261. dqip.dwFlags = DSQPF_NOSAVE | DSQPF_SHOWHIDDENOBJECTS | DSQPF_ENABLEADMINFEATURES;
  1262. dqip.dwFlags |= DSQPF_ENABLEADVANCEDFEATURES;
  1263. ZeroMemory( &oqw, sizeof(oqw) );
  1264. oqw.cbStruct = sizeof(oqw);
  1265. oqw.dwFlags = OQWF_SHOWOPTIONAL | OQWF_ISSUEONOPEN
  1266. | OQWF_REMOVESCOPES | OQWF_REMOVEFORMS
  1267. | OQWF_DEFAULTFORM | OQWF_OKCANCEL | OQWF_SINGLESELECT;
  1268. oqw.clsidHandler = CLSID_DsQuery;
  1269. oqw.pHandlerParameters = &dqip;
  1270. oqw.clsidDefaultForm = CLSID_RISrvQueryForm;
  1271. hr = pCommonQuery->OpenQueryWindow( hDlg, &oqw, &pdo);
  1272. if ( SUCCEEDED(hr) && pdo) {
  1273. FORMATETC fmte = {
  1274. (CLIPFORMAT)g_cfDsObjectNames,
  1275. NULL,
  1276. DVASPECT_CONTENT,
  1277. -1,
  1278. TYMED_HGLOBAL};
  1279. STGMEDIUM medium = { TYMED_HGLOBAL, NULL, NULL};
  1280. //
  1281. // Retrieve the result from the IDataObject,
  1282. // in this case CF_DSOBJECTNAMES (dsclient.h)
  1283. // is needed because it describes
  1284. // the objects which were selected by the user.
  1285. //
  1286. hr = pdo->GetData(&fmte, &medium);
  1287. if ( SUCCEEDED(hr) ) {
  1288. DSOBJECTNAMES *pdon = (DSOBJECTNAMES*)GlobalLock(medium.hGlobal);
  1289. PWSTR p,FQDN;
  1290. //
  1291. // we want the name of the computer object that was selected.
  1292. // crack the DSOBJECTNAMES structure to get this data,
  1293. // convert it into a version that the user can view, and set the
  1294. // dialog text to this data.
  1295. //
  1296. //
  1297. // if we can't get this, it's not a problem because this is
  1298. // only a display value
  1299. //
  1300. if ( pdon ) {
  1301. Assert( pdon->cItems == 1);
  1302. p = (PWSTR)((ULONG_PTR)pdon + (ULONG_PTR)pdon->aObjects[0].offsetName);
  1303. if (p && (p = wcsstr(p, L"LDAP://"))) {
  1304. p += 6;
  1305. if ((p = wcsstr(p, L"/CN="))) {
  1306. p += 1;
  1307. hr = DNtoFQDN( p, &FQDN);
  1308. if (SUCCEEDED(hr)) {
  1309. SetDlgItemText( hDlg, IDC_E_SERVER, FQDN );
  1310. TraceFree( FQDN );
  1311. }
  1312. }
  1313. }
  1314. GlobalUnlock(medium.hGlobal);
  1315. }
  1316. }
  1317. ReleaseStgMedium(&medium);
  1318. pdo->Release();
  1319. }
  1320. Error:
  1321. if ( pCommonQuery )
  1322. pCommonQuery->Release();
  1323. if (FAILED(hr)) {
  1324. MessageBoxFromStrings(
  1325. hDlg,
  1326. IDS_PROBLEM_SEARCHING_TITLE,
  1327. IDS_PROBLEM_SEARCHING_TEXT,
  1328. MB_ICONEXCLAMATION );
  1329. }
  1330. HRETURN(hr);
  1331. }
  1332. //
  1333. // Page4DlgProc( )
  1334. //
  1335. INT_PTR CALLBACK
  1336. THISCLASS::Page4DlgProc(
  1337. HWND hDlg,
  1338. UINT uMsg,
  1339. WPARAM wParam,
  1340. LPARAM lParam )
  1341. {
  1342. LPTHISCLASS lpc = (LPTHISCLASS) GetWindowLongPtr( hDlg, GWLP_USERDATA );
  1343. switch ( uMsg ) {
  1344. case WM_INITDIALOG:
  1345. TraceMsg( TF_WM, "WM_INITDIALOG\n" );
  1346. {
  1347. LPPROPSHEETPAGE ppsp = (LPPROPSHEETPAGE) lParam;
  1348. Assert( ppsp );
  1349. Assert( ppsp->lParam );
  1350. SetWindowLongPtr( hDlg, GWLP_USERDATA, ppsp->lParam );
  1351. lpc = (LPTHISCLASS) ppsp->lParam;
  1352. THR( lpc->_InitListView( GetDlgItem( hDlg, IDC_L_SIFS ), TRUE ) );
  1353. return TRUE;
  1354. }
  1355. break;
  1356. case WM_NOTIFY:
  1357. {
  1358. LPNMHDR lpnmhdr = (LPNMHDR) lParam;
  1359. Assert( lpc );
  1360. switch ( lpnmhdr->code ) {
  1361. case PSN_SETACTIVE:
  1362. TraceMsg( TF_WM, "PSN_SETACTIVE\n" );
  1363. if ( !lpc->_fAddSif || !lpc->_fCopyFromServer ) {
  1364. SetWindowLongPtr( hDlg, DWLP_MSGRESULT, -1 ); // don't show
  1365. return TRUE;
  1366. }
  1367. Assert( lpc->_pszSourceServerName );
  1368. if ( lpc->_pszSourceServerName ) {
  1369. LPWSTR pszStartPath =
  1370. (LPWSTR) TraceAllocString( LMEM_FIXED,
  1371. wcslen( lpc->_pszSourceServerName )
  1372. + ARRAYSIZE(SERVER_START_STRING) );
  1373. if ( pszStartPath ) {
  1374. wsprintf( pszStartPath,
  1375. SERVER_START_STRING,
  1376. lpc->_pszSourceServerName );
  1377. lpc->_hDlg = hDlg;
  1378. lpc->_hwndList = GetDlgItem( hDlg, IDC_L_SIFS );
  1379. lpc->_PopulateTemplatesListView( pszStartPath );
  1380. TraceFree( pszStartPath );
  1381. }
  1382. }
  1383. PropSheet_SetWizButtons( GetParent( hDlg ), PSWIZB_BACK );
  1384. break;
  1385. case PSN_WIZNEXT:
  1386. TraceMsg( TF_WM, "PSN_WIZNEXT\n" );
  1387. {
  1388. LVITEM lvi;
  1389. HWND hwndList = GetDlgItem( hDlg, IDC_L_SIFS );
  1390. lvi.iItem = ListView_GetNextItem( hwndList, -1, LVNI_SELECTED );
  1391. Assert( lvi.iItem != -1 );
  1392. lvi.iSubItem = 0;
  1393. lvi.mask = LVIF_PARAM;
  1394. ListView_GetItem( hwndList, &lvi );
  1395. Assert(lvi.lParam);
  1396. LPSIFINFO pSIF = (LPSIFINFO) lvi.lParam;
  1397. if ( lpc->_pszSourcePath ) {
  1398. TraceFree( lpc->_pszSourcePath );
  1399. lpc->_pszSourcePath = NULL;
  1400. }
  1401. if ( lpc->_pszSourceImage
  1402. && lpc->_pszSourceImage != lpc->_szNA
  1403. && lpc->_pszSourceImage != lpc->_szLocation ) {
  1404. TraceFree( lpc->_pszSourceImage );
  1405. lpc->_pszSourceImage = NULL;
  1406. }
  1407. lpc->_pszSourcePath = pSIF->pszFilePath;
  1408. lpc->_pszSourceImage = pSIF->pszImageFile;
  1409. pSIF->pszFilePath = NULL; // don't free this, we're using it
  1410. pSIF->pszImageFile = NULL; // don't free this, we're using it
  1411. ListView_DeleteAllItems( hwndList );
  1412. }
  1413. break;
  1414. case PSN_QUERYCANCEL:
  1415. TraceMsg( TF_WM, "PSN_QUERYCANCEL\n" );
  1416. return lpc->_VerifyCancel( hDlg );
  1417. case LVN_DELETEALLITEMS:
  1418. TraceMsg( TF_WM, "LVN_DELETEALLITEMS - Deleting all items.\n" );
  1419. break;
  1420. case LVN_DELETEITEM:
  1421. TraceMsg( TF_WM, "LVN_DELETEITEM - Deleting an item.\n" );
  1422. {
  1423. LPNMLISTVIEW pnmv = (LPNMLISTVIEW) lParam;
  1424. LPSIFINFO pSIF = (LPSIFINFO) pnmv->lParam;
  1425. THR( lpc->_CleanupSIFInfo( pSIF ) );
  1426. }
  1427. break;
  1428. case LVN_ITEMCHANGED:
  1429. {
  1430. HWND hwndList = GetDlgItem( hDlg, IDC_L_SIFS );
  1431. UINT iItems = ListView_GetNextItem( hwndList, -1, LVNI_SELECTED );
  1432. if ( iItems != -1 ) {
  1433. PropSheet_SetWizButtons( GetParent( hDlg ),
  1434. PSWIZB_BACK | PSWIZB_NEXT );
  1435. } else {
  1436. PropSheet_SetWizButtons( GetParent( hDlg ),
  1437. PSWIZB_BACK );
  1438. }
  1439. }
  1440. break;
  1441. }
  1442. }
  1443. break;
  1444. }
  1445. return FALSE;
  1446. }
  1447. //
  1448. // Page5DlgProc( )
  1449. //
  1450. INT_PTR CALLBACK
  1451. THISCLASS::Page5DlgProc(
  1452. HWND hDlg,
  1453. UINT uMsg,
  1454. WPARAM wParam,
  1455. LPARAM lParam )
  1456. {
  1457. LPTHISCLASS lpc = (LPTHISCLASS) GetWindowLongPtr( hDlg, GWLP_USERDATA );
  1458. switch ( uMsg ) {
  1459. case WM_INITDIALOG:
  1460. TraceMsg( TF_WM, "WM_INITDIALOG\n" );
  1461. {
  1462. LPPROPSHEETPAGE ppsp = (LPPROPSHEETPAGE) lParam;
  1463. Assert( ppsp );
  1464. Assert( ppsp->lParam );
  1465. SetWindowLongPtr( hDlg, GWLP_USERDATA, ppsp->lParam );
  1466. Edit_LimitText( GetDlgItem( hDlg, IDC_E_FILEPATH ), MAX_PATH );
  1467. SHAutoComplete(GetDlgItem( hDlg, IDC_E_FILEPATH ), SHACF_AUTOSUGGEST_FORCE_ON | SHACF_FILESYSTEM);
  1468. // lpc = (LPTHISCLASS) ppsp->lParam;
  1469. return TRUE;
  1470. }
  1471. break;
  1472. case WM_NOTIFY:
  1473. {
  1474. LPNMHDR lpnmhdr = (LPNMHDR) lParam;
  1475. Assert( lpc );
  1476. switch ( lpnmhdr->code ) {
  1477. case PSN_SETACTIVE:
  1478. TraceMsg( TF_WM, "PSN_SETACTIVE\n" );
  1479. if ( !lpc->_fAddSif || !lpc->_fCopyFromLocation ) {
  1480. SetWindowLongPtr( hDlg, DWLP_MSGRESULT, -1 ); // don't show
  1481. return TRUE;
  1482. } else {
  1483. ULONG uLength =
  1484. Edit_GetTextLength( GetDlgItem( hDlg, IDC_E_FILEPATH ) );
  1485. if ( !uLength ) {
  1486. PropSheet_SetWizButtons( GetParent( hDlg ),
  1487. PSWIZB_BACK );
  1488. } else {
  1489. PropSheet_SetWizButtons( GetParent( hDlg ),
  1490. PSWIZB_BACK | PSWIZB_NEXT );
  1491. }
  1492. }
  1493. break;
  1494. case PSN_WIZNEXT:
  1495. TraceMsg( TF_WM, "PSN_WIZNEXT\n" );
  1496. {
  1497. HWND hwndEdit = GetDlgItem( hDlg, IDC_E_FILEPATH );
  1498. ULONG uLength = Edit_GetTextLength( hwndEdit );
  1499. DWORD dw;
  1500. Assert( uLength );
  1501. uLength++; // add one for the NULL
  1502. // if we had a previous buffer allocated,
  1503. // see if we can reuse it
  1504. if ( lpc->_pszSourcePath && uLength
  1505. > wcslen(lpc->_pszSourcePath) + 1 ) {
  1506. TraceFree( lpc->_pszSourcePath );
  1507. lpc->_pszSourcePath = NULL;
  1508. }
  1509. if ( lpc->_pszSourceImage
  1510. && lpc->_pszSourceImage != lpc->_szNA
  1511. && lpc->_pszSourceImage != lpc->_szLocation ) {
  1512. TraceFree( lpc->_pszSourceImage );
  1513. lpc->_pszSourceImage = NULL;
  1514. }
  1515. lpc->_pszSourceImage = lpc->_szLocation;
  1516. if ( !lpc->_pszSourcePath ) {
  1517. lpc->_pszSourcePath =
  1518. (LPWSTR) TraceAllocString( LMEM_FIXED, uLength );
  1519. if ( !lpc->_pszSourcePath ) {
  1520. SetWindowLongPtr( hDlg, DWLP_MSGRESULT, -1 ); // don't change
  1521. return TRUE;
  1522. }
  1523. }
  1524. Edit_GetText( hwndEdit, lpc->_pszSourcePath, uLength );
  1525. DWORD dwAttrs = GetFileAttributes( lpc->_pszSourcePath );
  1526. if ( dwAttrs == 0xFFFFffff ) { // file doesn't exist
  1527. DWORD dwErr = GetLastError( );
  1528. MessageBoxFromError( hDlg, NULL, dwErr );
  1529. TraceFree( lpc->_pszSourcePath );
  1530. lpc->_pszSourcePath = NULL;
  1531. SetWindowLongPtr( hDlg, DWLP_MSGRESULT, -1 ); // don't continue
  1532. return TRUE;
  1533. } else { // the SIF image must be a "FLAT" image
  1534. WCHAR szImageType[ 40 ];
  1535. GetPrivateProfileString( OSCHOOSER_SIF_SECTION,
  1536. OSCHOOSER_IMAGETYPE_ENTRY,
  1537. L"",
  1538. szImageType,
  1539. ARRAYSIZE(szImageType),
  1540. lpc->_pszSourcePath );
  1541. if ( _wcsicmp( szImageType, OSCHOOSER_IMAGETYPE_FLAT ) ) {
  1542. MessageBoxFromStrings( hDlg,
  1543. IDS_MUST_BE_FLAT_CAPTION,
  1544. IDS_MUST_BE_FLAT_TEXT,
  1545. MB_OK );
  1546. SetWindowLongPtr( hDlg, DWLP_MSGRESULT, -1 ); // don't continue
  1547. return TRUE;
  1548. }
  1549. GetPrivateProfileString( OSCHOOSER_SIF_SECTION,
  1550. OSCHOOSER_DESCRIPTION_ENTRY,
  1551. L"",
  1552. lpc->_szDescription,
  1553. ARRAYSIZE(lpc->_szDescription),
  1554. lpc->_pszSourcePath );
  1555. GetPrivateProfileString( OSCHOOSER_SIF_SECTION,
  1556. OSCHOOSER_HELPTEXT_ENTRY,
  1557. L"",
  1558. lpc->_szHelpText,
  1559. ARRAYSIZE(lpc->_szHelpText),
  1560. lpc->_pszSourcePath );
  1561. }
  1562. }
  1563. break;
  1564. case PSN_QUERYCANCEL:
  1565. TraceMsg( TF_WM, "PSN_QUERYCANCEL\n" );
  1566. return lpc->_VerifyCancel( hDlg );
  1567. }
  1568. }
  1569. break;
  1570. case WM_COMMAND:
  1571. TraceMsg( TF_WM, "WM_COMMAND\n" );
  1572. HWND hwnd = (HWND) lParam;
  1573. switch ( LOWORD( wParam ) ) {
  1574. case IDC_E_FILEPATH:
  1575. if ( HIWORD( wParam ) == EN_CHANGE ) {
  1576. LONG uLength = Edit_GetTextLength( hwnd );
  1577. if ( !uLength ) {
  1578. PropSheet_SetWizButtons( GetParent( hDlg ),
  1579. PSWIZB_BACK );
  1580. } else {
  1581. PropSheet_SetWizButtons( GetParent( hDlg ),
  1582. PSWIZB_BACK | PSWIZB_NEXT );
  1583. }
  1584. return TRUE;
  1585. }
  1586. break;
  1587. case IDC_B_BROWSE:
  1588. if ( HIWORD( wParam ) == BN_CLICKED ) {
  1589. WCHAR szFilter[ 80 ]; // random
  1590. WCHAR szFilepath[ MAX_PATH ] = { L'\0'}; // bigger?
  1591. WCHAR szSIF[ ] = { L"SIF"};
  1592. DWORD dw;
  1593. OPENFILENAME ofn;
  1594. // Build OpenFileName dialogs filter
  1595. ZeroMemory( szFilter, sizeof(szFilter) );
  1596. dw = LoadString( g_hInstance,
  1597. IDS_OFN_SIF_FILTER,
  1598. szFilter,
  1599. ARRAYSIZE(szFilter) );
  1600. Assert( dw );
  1601. dw++; // include NULL character
  1602. wcscat( &szFilter[dw], L"*.SIF" );
  1603. #ifdef DEBUG
  1604. // paranoid... make sure it fits!
  1605. dw += wcslen( &szFilter[dw] ) + 2; // +2 = one for each NULL character
  1606. Assert( dw + 2 <= sizeof(szFilter) );
  1607. #endif // DEBUG
  1608. // Build OpenFileName structure
  1609. ZeroMemory( &ofn, sizeof(ofn) );
  1610. ofn.lStructSize = sizeof(ofn);
  1611. ofn.hwndOwner = hDlg;
  1612. ofn.hInstance = g_hInstance;
  1613. ofn.lpstrFilter = szFilter;
  1614. ofn.lpstrFile = szFilepath;
  1615. ofn.nMaxFile = ARRAYSIZE(szFilepath);
  1616. ofn.Flags = OFN_ENABLESIZING | OFN_FILEMUSTEXIST
  1617. | OFN_HIDEREADONLY;
  1618. ofn.lpstrDefExt = szSIF;
  1619. if ( GetOpenFileName( &ofn ) ) {
  1620. SetDlgItemText( hDlg, IDC_E_FILEPATH, szFilepath );
  1621. return TRUE;
  1622. }
  1623. }
  1624. break;
  1625. }
  1626. break;
  1627. }
  1628. return FALSE;
  1629. }
  1630. //
  1631. // Page6DlgProc( )
  1632. //
  1633. INT_PTR CALLBACK
  1634. THISCLASS::Page6DlgProc(
  1635. HWND hDlg,
  1636. UINT uMsg,
  1637. WPARAM wParam,
  1638. LPARAM lParam )
  1639. {
  1640. LPTHISCLASS lpc = (LPTHISCLASS) GetWindowLongPtr( hDlg, GWLP_USERDATA );
  1641. switch ( uMsg ) {
  1642. case WM_INITDIALOG:
  1643. TraceMsg( TF_WM, "WM_INITDIALOG\n" );
  1644. {
  1645. LPPROPSHEETPAGE ppsp = (LPPROPSHEETPAGE) lParam;
  1646. Assert( ppsp );
  1647. Assert( ppsp->lParam );
  1648. SetWindowLongPtr( hDlg, GWLP_USERDATA, ppsp->lParam );
  1649. lpc = (LPTHISCLASS) ppsp->lParam;
  1650. THR( lpc->_InitListView( GetDlgItem( hDlg, IDC_L_OSES ), FALSE ) );
  1651. return TRUE;
  1652. }
  1653. break;
  1654. case WM_NOTIFY:
  1655. {
  1656. LPNMHDR lpnmhdr = (LPNMHDR) lParam;
  1657. Assert( lpc );
  1658. switch ( lpnmhdr->code ) {
  1659. case PSN_SETACTIVE:
  1660. TraceMsg( TF_WM, "PSN_SETACTIVE\n" );
  1661. if ( !lpc->_fAddSif ) {
  1662. SetWindowLongPtr( hDlg, DWLP_MSGRESULT, -1 ); // don't show
  1663. return TRUE;
  1664. }
  1665. Assert( lpc->_pszServerName );
  1666. if ( lpc->_pszServerName ) {
  1667. LPWSTR pszStartPath =
  1668. (LPWSTR) TraceAllocString( LMEM_FIXED,
  1669. wcslen( lpc->_pszServerName )
  1670. + ARRAYSIZE(SERVER_START_STRING) );
  1671. if ( pszStartPath ) {
  1672. wsprintf( pszStartPath,
  1673. SERVER_START_STRING,
  1674. lpc->_pszServerName );
  1675. lpc->_hDlg = hDlg;
  1676. lpc->_hwndList = GetDlgItem( hDlg, IDC_L_OSES );
  1677. // bugbug what if this fails?
  1678. lpc->_PopulateImageListView( pszStartPath );
  1679. TraceFree( pszStartPath );
  1680. }
  1681. }
  1682. PropSheet_SetWizButtons( GetParent( hDlg ), PSWIZB_BACK );
  1683. break;
  1684. case PSN_WIZNEXT:
  1685. TraceMsg( TF_WM, "PSN_WIZNEXT\n" );
  1686. {
  1687. LVITEM lvi;
  1688. HWND hwndList = GetDlgItem( hDlg, IDC_L_OSES );
  1689. lvi.iItem = ListView_GetNextItem( hwndList, -1, LVNI_SELECTED );
  1690. Assert( lvi.iItem != -1 );
  1691. lvi.iSubItem = 0;
  1692. lvi.mask = LVIF_PARAM;
  1693. ListView_GetItem( hwndList, &lvi );
  1694. Assert(lvi.lParam);
  1695. LPSIFINFO pSIF = (LPSIFINFO) lvi.lParam;
  1696. if ( lpc->_pszDestPath) {
  1697. TraceFree( lpc->_pszDestPath );
  1698. lpc->_pszDestPath = NULL;
  1699. }
  1700. lpc->_pszDestPath =
  1701. (LPWSTR) TraceAllocString( LMEM_FIXED,
  1702. wcslen( pSIF->pszFilePath )
  1703. + ARRAYSIZE(SLASH_TEMPLATES) );
  1704. if ( !lpc->_pszDestPath ) {
  1705. SetWindowLongPtr( hDlg, DWLP_MSGRESULT, -1 ); // don't continue;
  1706. return TRUE;
  1707. }
  1708. wcscpy( lpc->_pszDestPath, pSIF->pszFilePath );
  1709. wcscat( lpc->_pszDestPath, SLASH_TEMPLATES );
  1710. lpc->_fDestPathIncludesSIF = FALSE;
  1711. if ( lpc->_pszDestImage
  1712. && lpc->_pszDestImage != lpc->_szNA )
  1713. TraceFree( lpc->_pszDestImage );
  1714. // no need to NULL - it set again below
  1715. lpc->_pszDestImage = pSIF->pszImageFile;
  1716. pSIF->pszImageFile = NULL; // don't free this
  1717. ListView_DeleteAllItems( hwndList );
  1718. }
  1719. break;
  1720. case PSN_QUERYCANCEL:
  1721. TraceMsg( TF_WM, "PSN_QUERYCANCEL\n" );
  1722. return lpc->_VerifyCancel( hDlg );
  1723. case LVN_DELETEALLITEMS:
  1724. TraceMsg( TF_WM, "LVN_DELETEALLITEMS - Deleting all items.\n" );
  1725. break;
  1726. case LVN_DELETEITEM:
  1727. TraceMsg( TF_WM, "LVN_DELETEITEM - Deleting an item.\n" );
  1728. {
  1729. LPNMLISTVIEW pnmv = (LPNMLISTVIEW) lParam;
  1730. LPSIFINFO pSIF = (LPSIFINFO) pnmv->lParam;
  1731. THR( lpc->_CleanupSIFInfo( pSIF ) );
  1732. }
  1733. break;
  1734. case LVN_ITEMCHANGED:
  1735. {
  1736. HWND hwndList = GetDlgItem( hDlg, IDC_L_OSES );
  1737. UINT iItems =
  1738. ListView_GetNextItem( hwndList, -1, LVNI_SELECTED );
  1739. if ( iItems != -1 ) {
  1740. PropSheet_SetWizButtons( GetParent( hDlg ),
  1741. PSWIZB_BACK | PSWIZB_NEXT );
  1742. } else {
  1743. PropSheet_SetWizButtons( GetParent( hDlg ),
  1744. PSWIZB_BACK );
  1745. }
  1746. }
  1747. break;
  1748. }
  1749. }
  1750. break;
  1751. }
  1752. return FALSE;
  1753. }
  1754. //
  1755. // Page7DlgProc( )
  1756. //
  1757. INT_PTR CALLBACK
  1758. THISCLASS::Page7DlgProc(
  1759. HWND hDlg,
  1760. UINT uMsg,
  1761. WPARAM wParam,
  1762. LPARAM lParam )
  1763. {
  1764. LPTHISCLASS lpc = (LPTHISCLASS) GetWindowLongPtr( hDlg, GWLP_USERDATA );
  1765. switch ( uMsg ) {
  1766. case WM_INITDIALOG:
  1767. TraceMsg( TF_WM, "WM_INITDIALOG\n" );
  1768. {
  1769. LPPROPSHEETPAGE ppsp = (LPPROPSHEETPAGE) lParam;
  1770. Assert( ppsp );
  1771. Assert( ppsp->lParam );
  1772. SetWindowLongPtr( hDlg, GWLP_USERDATA, ppsp->lParam );
  1773. lpc = (LPTHISCLASS) ppsp->lParam;
  1774. THR( lpc->_InitListView( GetDlgItem( hDlg, IDC_L_SIFS ), FALSE ) );
  1775. return TRUE;
  1776. }
  1777. break;
  1778. case WM_NOTIFY:
  1779. {
  1780. LPNMHDR lpnmhdr = (LPNMHDR) lParam;
  1781. Assert( lpc );
  1782. switch ( lpnmhdr->code ) {
  1783. case PSN_SETACTIVE:
  1784. TraceMsg( TF_WM, "PSN_SETACTIVE\n" );
  1785. if ( !lpc->_fAddSif || !lpc->_fCopyFromSamples ) {
  1786. SetWindowLongPtr( hDlg, DWLP_MSGRESULT, -1 ); // don't show
  1787. return TRUE;
  1788. }
  1789. Assert( lpc->_pszDestPath );
  1790. if ( lpc->_pszDestPath ) {
  1791. LPWSTR pszStartPath =
  1792. (LPWSTR) TraceStrDup( lpc->_pszDestPath );
  1793. if ( pszStartPath ) {
  1794. // remove the "\templates" from the path
  1795. LPWSTR psz = StrRChr( pszStartPath,
  1796. &pszStartPath[wcslen(pszStartPath)],
  1797. L'\\' );
  1798. Assert( psz );
  1799. if ( psz ) {
  1800. *psz = L'\0'; // terminate
  1801. lpc->_hDlg = hDlg;
  1802. lpc->_hwndList = GetDlgItem( hDlg, IDC_L_SIFS );
  1803. //bugbug this could fail.
  1804. lpc->_PopulateSamplesListView( pszStartPath );
  1805. *psz = L'\\'; // restore
  1806. }
  1807. TraceFree( pszStartPath );
  1808. }
  1809. }
  1810. PropSheet_SetWizButtons( GetParent( hDlg ), PSWIZB_BACK );
  1811. break;
  1812. case PSN_WIZNEXT:
  1813. TraceMsg( TF_WM, "PSN_WIZNEXT\n" );
  1814. {
  1815. LVITEM lvi;
  1816. DWORD dw;
  1817. HWND hwndList = GetDlgItem( hDlg, IDC_L_SIFS );
  1818. lvi.iItem = ListView_GetNextItem( hwndList, -1, LVNI_SELECTED );
  1819. Assert( lvi.iItem != -1 );
  1820. lvi.iSubItem = 0;
  1821. lvi.mask = LVIF_PARAM;
  1822. ListView_GetItem( hwndList, &lvi );
  1823. Assert(lvi.lParam);
  1824. LPSIFINFO pSIF = (LPSIFINFO) lvi.lParam;
  1825. if ( lpc->_pszSourcePath ) {
  1826. TraceFree( lpc->_pszSourcePath );
  1827. lpc->_pszSourcePath = NULL;
  1828. }
  1829. if ( lpc->_pszSourceImage
  1830. && lpc->_pszSourceImage != lpc->_szNA
  1831. && lpc->_pszSourceImage != lpc->_szLocation ) {
  1832. TraceFree( lpc->_pszSourceImage );
  1833. lpc->_pszSourceImage = NULL;
  1834. }
  1835. lpc->_pszSourcePath = pSIF->pszFilePath;
  1836. lpc->_pszSourceImage = pSIF->pszImageFile;
  1837. if ( pSIF->pszDescription ) {
  1838. wcsncpy( lpc->_szDescription, pSIF->pszDescription, ARRAYSIZE(lpc->_szDescription) );
  1839. lpc->_szDescription[ARRAYSIZE(lpc->_szDescription)-1] = L'\0';
  1840. } else {
  1841. lpc->_szDescription[0] = L'\0';
  1842. }
  1843. if ( pSIF->pszHelpText ) {
  1844. wcsncpy( lpc->_szHelpText, pSIF->pszHelpText, ARRAYSIZE(lpc->_szHelpText) );
  1845. lpc->_szHelpText[ARRAYSIZE(lpc->_szHelpText)-1] = L'\0';
  1846. } else {
  1847. lpc->_szHelpText[0] = L'\0';
  1848. }
  1849. pSIF->pszFilePath = NULL; // don't free this, we're using it
  1850. pSIF->pszImageFile = NULL; // don't free this, we're using it
  1851. ListView_DeleteAllItems( hwndList );
  1852. }
  1853. break;
  1854. case PSN_QUERYCANCEL:
  1855. TraceMsg( TF_WM, "PSN_QUERYCANCEL\n" );
  1856. return lpc->_VerifyCancel( hDlg );
  1857. case LVN_DELETEALLITEMS:
  1858. TraceMsg( TF_WM, "LVN_DELETEALLITEMS - Deleting all items.\n" );
  1859. break;
  1860. case LVN_DELETEITEM:
  1861. TraceMsg( TF_WM, "LVN_DELETEITEM - Deleting an item.\n" );
  1862. {
  1863. LPNMLISTVIEW pnmv = (LPNMLISTVIEW) lParam;
  1864. LPSIFINFO pSIF = (LPSIFINFO) pnmv->lParam;
  1865. THR( lpc->_CleanupSIFInfo( pSIF ) );
  1866. }
  1867. break;
  1868. case LVN_ITEMCHANGED:
  1869. {
  1870. HWND hwndList = GetDlgItem( hDlg, IDC_L_SIFS );
  1871. UINT iItems = ListView_GetNextItem( hwndList, -1, LVNI_SELECTED );
  1872. if ( iItems != -1 ) {
  1873. PropSheet_SetWizButtons( GetParent( hDlg ),
  1874. PSWIZB_BACK | PSWIZB_NEXT );
  1875. } else {
  1876. PropSheet_SetWizButtons( GetParent( hDlg ),
  1877. PSWIZB_BACK );
  1878. }
  1879. }
  1880. break;
  1881. }
  1882. }
  1883. break;
  1884. }
  1885. return FALSE;
  1886. }
  1887. //
  1888. // Page8DlgProc( )
  1889. //
  1890. INT_PTR CALLBACK
  1891. THISCLASS::Page8DlgProc(
  1892. HWND hDlg,
  1893. UINT uMsg,
  1894. WPARAM wParam,
  1895. LPARAM lParam )
  1896. {
  1897. LPTHISCLASS lpc = (LPTHISCLASS) GetWindowLongPtr( hDlg, GWLP_USERDATA );
  1898. switch ( uMsg ) {
  1899. case WM_INITDIALOG:
  1900. TraceMsg( TF_WM, "WM_INITDIALOG\n" );
  1901. {
  1902. LPPROPSHEETPAGE ppsp = (LPPROPSHEETPAGE) lParam;
  1903. Assert( ppsp );
  1904. Assert( ppsp->lParam );
  1905. SetWindowLongPtr( hDlg, GWLP_USERDATA, ppsp->lParam );
  1906. // lpc = (LPTHISCLASS) ppsp->lParam;
  1907. return TRUE;
  1908. }
  1909. break;
  1910. case WM_NOTIFY:
  1911. {
  1912. LPNMHDR lpnmhdr = (LPNMHDR) lParam;
  1913. Assert( lpc );
  1914. switch ( lpnmhdr->code ) {
  1915. case PSN_SETACTIVE:
  1916. TraceMsg( TF_WM, "PSN_SETACTIVE\n" );
  1917. if ( !lpc->_fAddSif ) {
  1918. SetWindowLongPtr( hDlg, DWLP_MSGRESULT, -1 ); // don't show
  1919. return TRUE;
  1920. } else {
  1921. Assert( lpc->_pszSourcePath );
  1922. Assert( lpc->_pszDestPath );
  1923. LPWSTR pszDestFilePath;
  1924. ULONG uDestLength = wcslen( lpc->_pszDestPath );
  1925. LPWSTR pszFilename;
  1926. lpc->_fSIFCanExist = FALSE; // reset
  1927. if ( lpc->_fDestPathIncludesSIF ) { // strip the filename
  1928. LPWSTR psz = StrRChr( lpc->_pszDestPath,
  1929. &lpc->_pszDestPath[ uDestLength ],
  1930. L'\\' );
  1931. Assert(psz);
  1932. *psz = L'\0'; // truncate
  1933. lpc->_fDestPathIncludesSIF = FALSE;
  1934. if ( !lpc->_fShowedPage8 ) {
  1935. SetWindowLongPtr( hDlg, DWLP_MSGRESULT, -1 ); // don't show
  1936. return TRUE;
  1937. }
  1938. psz++;
  1939. pszFilename = psz;
  1940. } else {
  1941. pszFilename =
  1942. StrRChr( lpc->_pszSourcePath,
  1943. &lpc->_pszSourcePath[wcslen(lpc->_pszSourcePath)],
  1944. L'\\' );
  1945. Assert( pszFilename );
  1946. pszFilename++; // move past the '\'
  1947. pszDestFilePath =
  1948. (LPWSTR) TraceAllocString( LMEM_FIXED,
  1949. uDestLength + 1
  1950. + wcslen( pszFilename ) + 1 );
  1951. if ( pszDestFilePath ) {
  1952. wcscpy( pszDestFilePath, lpc->_pszDestPath );
  1953. wcscat( pszDestFilePath, L"\\" );
  1954. wcscat( pszDestFilePath, pszFilename );
  1955. DWORD dwAttrs = GetFileAttributes( pszDestFilePath );
  1956. if ( dwAttrs == 0xFFFFffff ) { // file does not exist on destination server.
  1957. // Use the same SIF as the source.
  1958. TraceFree( lpc->_pszDestPath );
  1959. lpc->_pszDestPath = pszDestFilePath;
  1960. lpc->_fDestPathIncludesSIF = TRUE;
  1961. SetWindowLongPtr( hDlg, DWLP_MSGRESULT, -1 ); // don't show
  1962. return TRUE;
  1963. }
  1964. TraceFree( pszDestFilePath );
  1965. }
  1966. // else be paranoid and prompt for a name
  1967. }
  1968. HWND hwnd = GetDlgItem( hDlg, IDC_E_FILENAME );
  1969. Assert( uDestLength <= MAX_PATH );
  1970. Edit_LimitText( hwnd, MAX_PATH - uDestLength );
  1971. Edit_SetText( hwnd, pszFilename );
  1972. lpc->_fShowedPage8 = TRUE;
  1973. }
  1974. break;
  1975. case PSN_WIZBACK:
  1976. lpc->_fShowedPage8 = FALSE; // reset this
  1977. break;
  1978. case PSN_WIZNEXT:
  1979. TraceMsg( TF_WM, "PSN_WIZNEXT\n" );
  1980. {
  1981. Assert( lpc->_pszDestPath );
  1982. Assert( !lpc->_fDestPathIncludesSIF );
  1983. HWND hwndEdit = GetDlgItem( hDlg, IDC_E_FILENAME );
  1984. ULONG uLength = Edit_GetTextLength( hwndEdit );
  1985. ULONG uLengthDest = wcslen( lpc->_pszDestPath );
  1986. DWORD dwAttrs;
  1987. Assert( uLength );
  1988. AssertMsg( uLengthDest + uLength <= MAX_PATH,
  1989. "The Edit_LimitText() should prevent this from happening." );
  1990. uLength++; // add one for the NULL
  1991. LPWSTR pszNewDestPath =
  1992. (LPWSTR) TraceAllocString( LMEM_FIXED,
  1993. uLengthDest + 1 + uLength );
  1994. if ( !pszNewDestPath )
  1995. goto PSN_WIZNEXT_Abort;
  1996. wcscpy( pszNewDestPath, lpc->_pszDestPath );
  1997. wcscat( pszNewDestPath, L"\\" );
  1998. Edit_GetText( hwndEdit, &pszNewDestPath[uLengthDest + 1], uLength );
  1999. if ( !VerifySIFText( pszNewDestPath )
  2000. || StrChr( pszNewDestPath, 32 ) != NULL ) { // no spaces!
  2001. MessageBoxFromStrings( hDlg,
  2002. IDS_OSCHOOSER_DIRECTORY_RESTRICTION_TITLE,
  2003. IDS_OSCHOOSER_DIRECTORY_RESTRICTION_TEXT,
  2004. MB_OK );
  2005. goto PSN_WIZNEXT_Abort;
  2006. }
  2007. // make sure it doesn't exist.
  2008. dwAttrs = GetFileAttributes( pszNewDestPath );
  2009. if ( dwAttrs != 0xFFFFffff ) { // file exists, verify with user to overwrite
  2010. UINT i = MessageBoxFromStrings( hDlg,
  2011. IDS_OVERWRITE_CAPTION,
  2012. IDS_OVERWRITE_TEXT,
  2013. MB_YESNO );
  2014. if ( i == IDNO ) {
  2015. goto PSN_WIZNEXT_Abort;
  2016. } else {
  2017. lpc->_fSIFCanExist = TRUE;
  2018. }
  2019. }
  2020. uLength = wcslen( pszNewDestPath );
  2021. if ( _wcsicmp( &pszNewDestPath[ uLength - 4 ], L".SIF" ) != 0 ) {
  2022. UINT i = MessageBoxFromStrings( hDlg,
  2023. IDC_IMPROPER_EXTENSION_CAPTION,
  2024. IDC_IMPROPER_EXTENSION_TEXT,
  2025. MB_YESNO );
  2026. if ( i == IDNO )
  2027. goto PSN_WIZNEXT_Abort;
  2028. }
  2029. TraceFree( lpc->_pszDestPath );
  2030. lpc->_pszDestPath = pszNewDestPath;
  2031. lpc->_fDestPathIncludesSIF = TRUE;
  2032. return FALSE; // do it
  2033. PSN_WIZNEXT_Abort:
  2034. if ( pszNewDestPath )
  2035. TraceFree( pszNewDestPath );
  2036. // no need to NULL, going out of scope
  2037. SetFocus( hwndEdit );
  2038. SetWindowLongPtr( hDlg, DWLP_MSGRESULT, -1 ); // don't continue
  2039. return TRUE;
  2040. }
  2041. break;
  2042. case PSN_QUERYCANCEL:
  2043. TraceMsg( TF_WM, "PSN_QUERYCANCEL\n" );
  2044. return lpc->_VerifyCancel( hDlg );
  2045. }
  2046. }
  2047. break;
  2048. case WM_COMMAND:
  2049. TraceMsg( TF_WM, "WM_COMMAND\n" );
  2050. HWND hwnd = (HWND) lParam;
  2051. switch ( LOWORD( wParam ) ) {
  2052. case IDC_E_FILENAME:
  2053. if ( HIWORD( wParam ) == EN_CHANGE ) {
  2054. LONG uLength = Edit_GetTextLength( GetDlgItem( hDlg, IDC_E_FILENAME ) );
  2055. if ( !uLength ) {
  2056. PropSheet_SetWizButtons( GetParent( hDlg ),
  2057. PSWIZB_BACK );
  2058. } else {
  2059. PropSheet_SetWizButtons( GetParent( hDlg ),
  2060. PSWIZB_BACK | PSWIZB_NEXT );
  2061. }
  2062. return TRUE;
  2063. }
  2064. break;
  2065. }
  2066. break;
  2067. }
  2068. return FALSE;
  2069. }
  2070. //
  2071. // Page9DlgProc( )
  2072. //
  2073. INT_PTR CALLBACK
  2074. THISCLASS::Page9DlgProc(
  2075. HWND hDlg,
  2076. UINT uMsg,
  2077. WPARAM wParam,
  2078. LPARAM lParam )
  2079. {
  2080. LPTHISCLASS lpc = (LPTHISCLASS) GetWindowLongPtr( hDlg, GWLP_USERDATA );
  2081. switch ( uMsg ) {
  2082. case WM_INITDIALOG:
  2083. TraceMsg( TF_WM, "WM_INITDIALOG\n" );
  2084. {
  2085. LPPROPSHEETPAGE ppsp = (LPPROPSHEETPAGE) lParam;
  2086. Assert( ppsp );
  2087. Assert( ppsp->lParam );
  2088. SetWindowLongPtr( hDlg, GWLP_USERDATA, ppsp->lParam );
  2089. Edit_LimitText( GetDlgItem( hDlg, IDC_E_DESCRIPTION ),
  2090. ARRAYSIZE(lpc->_szDescription) - 1 );
  2091. Edit_LimitText( GetDlgItem( hDlg, IDC_E_HELPTEXT),
  2092. ARRAYSIZE(lpc->_szHelpText) - 1 );
  2093. // lpc = (LPTHISCLASS) ppsp->lParam;
  2094. return TRUE;
  2095. }
  2096. break;
  2097. case WM_NOTIFY:
  2098. {
  2099. LPNMHDR lpnmhdr = (LPNMHDR) lParam;
  2100. Assert( lpc );
  2101. switch ( lpnmhdr->code ) {
  2102. case PSN_SETACTIVE:
  2103. TraceMsg( TF_WM, "PSN_SETACTIVE\n" );
  2104. if ( !lpc->_fAddSif ) {
  2105. SetWindowLongPtr( hDlg, DWLP_MSGRESULT, -1 ); // don't show
  2106. return TRUE;
  2107. } else {
  2108. Assert( lpc->_pszSourcePath );
  2109. SetDlgItemText( hDlg, IDC_E_DESCRIPTION, lpc->_szDescription);
  2110. SetDlgItemText( hDlg, IDC_E_HELPTEXT, lpc->_szHelpText );
  2111. if ( !Edit_GetTextLength( GetDlgItem( hDlg, IDC_E_DESCRIPTION ) )
  2112. || !Edit_GetTextLength( GetDlgItem( hDlg, IDC_E_HELPTEXT ) ) ) {
  2113. PropSheet_SetWizButtons( GetParent( hDlg ),
  2114. PSWIZB_BACK );
  2115. } else {
  2116. PropSheet_SetWizButtons( GetParent( hDlg ),
  2117. PSWIZB_BACK | PSWIZB_NEXT );
  2118. }
  2119. }
  2120. break;
  2121. case PSN_WIZNEXT:
  2122. TraceMsg( TF_WM, "PSN_WIZNEXT\n" );
  2123. {
  2124. GetDlgItemText( hDlg,
  2125. IDC_E_DESCRIPTION,
  2126. lpc->_szDescription,
  2127. ARRAYSIZE(lpc->_szDescription) );
  2128. GetDlgItemText( hDlg,
  2129. IDC_E_HELPTEXT,
  2130. lpc->_szHelpText,
  2131. ARRAYSIZE(lpc->_szHelpText) );
  2132. if ( !VerifySIFText( lpc->_szDescription ) ) {
  2133. MessageBoxFromStrings( hDlg,
  2134. IDS_OSCHOOSER_RESTRICTION_FIELDS_TITLE,
  2135. IDS_OSCHOOSER_RESTRICTION_FIELDS_TEXT,
  2136. MB_OK );
  2137. SetFocus( GetDlgItem( hDlg, IDC_E_DESCRIPTION ) );
  2138. SetWindowLongPtr( hDlg, DWLP_MSGRESULT, -1 ); // don't change
  2139. return TRUE;
  2140. }
  2141. if ( !VerifySIFText( lpc->_szHelpText ) ) {
  2142. MessageBoxFromStrings( hDlg,
  2143. IDS_OSCHOOSER_RESTRICTION_FIELDS_TITLE,
  2144. IDS_OSCHOOSER_RESTRICTION_FIELDS_TEXT,
  2145. MB_OK );
  2146. SetFocus( GetDlgItem( hDlg, IDC_E_HELPTEXT ) );
  2147. SetWindowLongPtr( hDlg, DWLP_MSGRESULT, -1 ); // don't change
  2148. return TRUE;
  2149. }
  2150. }
  2151. break;
  2152. case PSN_QUERYCANCEL:
  2153. TraceMsg( TF_WM, "PSN_QUERYCANCEL\n" );
  2154. return lpc->_VerifyCancel( hDlg );
  2155. }
  2156. }
  2157. break;
  2158. case WM_COMMAND:
  2159. TraceMsg( TF_WM, "WM_COMMAND\n" );
  2160. switch ( LOWORD( wParam ) ) {
  2161. case IDC_E_DESCRIPTION:
  2162. case IDC_E_HELPTEXT:
  2163. if ( HIWORD( wParam ) == EN_CHANGE ) {
  2164. if ( !Edit_GetTextLength( GetDlgItem( hDlg, IDC_E_DESCRIPTION ) )
  2165. || !Edit_GetTextLength( GetDlgItem( hDlg, IDC_E_HELPTEXT ) ) ) {
  2166. PropSheet_SetWizButtons( GetParent( hDlg ),
  2167. PSWIZB_BACK );
  2168. } else {
  2169. PropSheet_SetWizButtons( GetParent( hDlg ),
  2170. PSWIZB_BACK | PSWIZB_NEXT );
  2171. }
  2172. return TRUE;
  2173. }
  2174. break;
  2175. }
  2176. break;
  2177. }
  2178. return FALSE;
  2179. }
  2180. //
  2181. // Page10DlgProc( )
  2182. //
  2183. INT_PTR CALLBACK
  2184. THISCLASS::Page10DlgProc(
  2185. HWND hDlg,
  2186. UINT uMsg,
  2187. WPARAM wParam,
  2188. LPARAM lParam )
  2189. {
  2190. LPTHISCLASS lpc = (LPTHISCLASS) GetWindowLongPtr( hDlg, GWLP_USERDATA );
  2191. switch ( uMsg ) {
  2192. case WM_INITDIALOG:
  2193. TraceMsg( TF_WM, "WM_INITDIALOG\n" );
  2194. {
  2195. LPPROPSHEETPAGE ppsp = (LPPROPSHEETPAGE) lParam;
  2196. Assert( ppsp );
  2197. Assert( ppsp->lParam );
  2198. SetWindowLongPtr( hDlg, GWLP_USERDATA, ppsp->lParam );
  2199. // lpc = (LPTHISCLASS) ppsp->lParam;
  2200. return TRUE;
  2201. }
  2202. break;
  2203. case WM_NOTIFY:
  2204. {
  2205. LPNMHDR lpnmhdr = (LPNMHDR) lParam;
  2206. Assert( lpc );
  2207. switch ( lpnmhdr->code ) {
  2208. case PSN_SETACTIVE:
  2209. TraceMsg( TF_WM, "PSN_SETACTIVE\n" );
  2210. if ( !lpc->_fAddSif ) {
  2211. SetWindowLongPtr( hDlg, DWLP_MSGRESULT, -1 ); // don't show
  2212. return TRUE;
  2213. } else {
  2214. WCHAR szTemp[ MAX_PATH ];
  2215. RECT rect;
  2216. Assert( lpc->_pszSourcePath );
  2217. Assert( lpc->_pszDestPath );
  2218. Assert( lpc->_pszSourceImage );
  2219. Assert( lpc->_pszDestImage );
  2220. SetDlgItemText( hDlg, IDC_E_SOURCE, lpc->_pszSourcePath );
  2221. wcsncpy( szTemp, lpc->_pszSourceImage,MAX_PATH );
  2222. szTemp[MAX_PATH-1] = L'\0';
  2223. GetWindowRect( GetDlgItem( hDlg, IDC_S_SOURCEIMAGE ), &rect );
  2224. PathCompactPath( NULL, szTemp, rect.right - rect.left );
  2225. SetDlgItemText( hDlg, IDC_S_SOURCEIMAGE, szTemp );
  2226. SetDlgItemText( hDlg, IDC_E_DESTINATION, lpc->_pszDestPath );
  2227. wcsncpy( szTemp, lpc->_pszDestImage, MAX_PATH );
  2228. szTemp[MAX_PATH-1] = L'\0';
  2229. GetWindowRect( GetDlgItem( hDlg, IDC_S_DESTIMAGE ), &rect );
  2230. PathCompactPath( NULL, szTemp, rect.right - rect.left );
  2231. SetDlgItemText( hDlg, IDC_S_DESTIMAGE, szTemp );
  2232. PropSheet_SetWizButtons( GetParent( hDlg ),
  2233. PSWIZB_BACK | PSWIZB_FINISH );
  2234. }
  2235. break;
  2236. case PSN_WIZFINISH:
  2237. TraceMsg( TF_WM, "PSN_WIZFINISH\n" );
  2238. Assert( lpc->_pszSourcePath );
  2239. Assert( lpc->_pszDestPath );
  2240. Assert( wcslen( lpc->_pszSourcePath ) <= MAX_PATH );
  2241. Assert( wcslen( lpc->_pszDestPath ) <= MAX_PATH );
  2242. if ( !CopyFile( lpc->_pszSourcePath, lpc->_pszDestPath, !lpc->_fSIFCanExist ) ) {
  2243. DWORD dwErr = GetLastError( );
  2244. MessageBoxFromError( hDlg, IDS_ERROR_COPYING_FILE, dwErr );
  2245. SetWindowLongPtr( hDlg, DWLP_MSGRESULT, -1 ); // don't continue;
  2246. return TRUE;
  2247. } else {
  2248. WCHAR szTemp[ REMOTE_INSTALL_MAX_HELPTEXT_CHAR_COUNT + 2 + 1 ];
  2249. Assert( REMOTE_INSTALL_MAX_DESCRIPTION_CHAR_COUNT
  2250. < REMOTE_INSTALL_MAX_HELPTEXT_CHAR_COUNT );
  2251. wsprintf( szTemp, L"\"%s\"", lpc->_szDescription );
  2252. WritePrivateProfileString( OSCHOOSER_SIF_SECTION,
  2253. OSCHOOSER_DESCRIPTION_ENTRY,
  2254. szTemp,
  2255. lpc->_pszDestPath );
  2256. wsprintf( szTemp, L"\"%s\"", lpc->_szHelpText );
  2257. WritePrivateProfileString( OSCHOOSER_SIF_SECTION,
  2258. OSCHOOSER_HELPTEXT_ENTRY,
  2259. szTemp,
  2260. lpc->_pszDestPath );
  2261. }
  2262. break;
  2263. case PSN_QUERYCANCEL:
  2264. TraceMsg( TF_WM, "PSN_QUERYCANCEL\n" );
  2265. return lpc->_VerifyCancel( hDlg );
  2266. }
  2267. }
  2268. break;
  2269. }
  2270. return FALSE;
  2271. }
  2272. //
  2273. // Verifies that the user wanted to cancel setup.
  2274. //
  2275. INT
  2276. THISCLASS::_VerifyCancel( HWND hParent )
  2277. {
  2278. TraceClsFunc( "_VerifyCancel( ... )\n" );
  2279. INT iReturn;
  2280. BOOL fAbort = FALSE;
  2281. iReturn = MessageBoxFromStrings( hParent,
  2282. IDS_CANCELCAPTION,
  2283. IDS_CANCELTEXT,
  2284. MB_YESNO | MB_ICONQUESTION );
  2285. if ( iReturn == IDYES ) {
  2286. fAbort = TRUE;
  2287. }
  2288. SetWindowLongPtr( hParent, DWLP_MSGRESULT, ( fAbort ? 0 : -1 ));
  2289. RETURN(!fAbort);
  2290. }