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.

133 lines
3.9 KiB

  1. #include "muisetup.h"
  2. #include <shlwapi.h>
  3. #include <shellapi.h>
  4. #define README_FILENAME TEXT("README.TXT")
  5. #define EULA_FILENAME TEXT("EULA.TXT")
  6. BOOL g_bLicenseAccepted;
  7. INT_PTR
  8. CALLBACK
  9. WelcomeDialogProc(HWND hWndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  10. {
  11. HANDLE hFile;
  12. DWORD dwFileSize;
  13. DWORD dwActual;
  14. LPVOID pFileBuffer;
  15. TCHAR szEulaPath[MAX_PATH];
  16. switch ( uMsg ) {
  17. case WM_INITDIALOG:
  18. //
  19. // Load EULA file from the path where MUISETUP was lunched
  20. //
  21. GetModuleFileName( NULL, szEulaPath, ARRAYSIZE( szEulaPath ));
  22. lstrcpy(StrRChrI(szEulaPath, NULL, TEXT('\\'))+1, EULA_FILENAME);
  23. hFile = CreateFile(
  24. szEulaPath,
  25. GENERIC_READ,
  26. FILE_SHARE_READ | FILE_SHARE_WRITE,
  27. NULL,
  28. OPEN_EXISTING,
  29. FILE_ATTRIBUTE_NORMAL,
  30. NULL
  31. );
  32. if ( hFile != INVALID_HANDLE_VALUE ) {
  33. dwFileSize = GetFileSize( hFile, NULL );
  34. if ( dwFileSize != -1 ) {
  35. pFileBuffer = LocalAlloc(LPTR, dwFileSize + 1 );
  36. if ( pFileBuffer ) {
  37. if ( ReadFile( hFile, pFileBuffer, dwFileSize, &dwActual, NULL )) {
  38. //
  39. // Make sure to NULL terminate the string
  40. //
  41. *((PCHAR)((PCHAR)pFileBuffer + dwFileSize)) = 0x00;
  42. //
  43. // Use ANSI text
  44. //
  45. SetDlgItemTextA( hWndDlg, IDC_EDIT_LICENSE, (LPCSTR)pFileBuffer );
  46. }
  47. LocalFree( pFileBuffer );
  48. }
  49. }
  50. }
  51. SetFocus( GetDlgItem( hWndDlg, IDC_CHECK_LICENSE ));
  52. return 0;
  53. case WM_COMMAND:
  54. switch ( LOWORD( wParam ))
  55. {
  56. case IDOK:
  57. g_bLicenseAccepted = ( IsDlgButtonChecked( hWndDlg, IDC_CHECK_LICENSE ) == BST_CHECKED );
  58. EndDialog( hWndDlg, 0 );
  59. return 1;
  60. case IDCANCEL:
  61. EndDialog( hWndDlg, ERROR_CANCELLED );
  62. return 1;
  63. case IDC_README:
  64. {
  65. // invoke notepad.exe open readme.txt
  66. TCHAR szReadMePath[MAX_PATH];
  67. SHELLEXECUTEINFO ExecInfo = {0};
  68. GetModuleFileName(NULL, szReadMePath, sizeof(szReadMePath)/sizeof(TCHAR));
  69. lstrcpy(StrRChrI(szReadMePath, NULL, TEXT('\\'))+1, README_FILENAME);
  70. ExecInfo.lpParameters = szReadMePath;
  71. ExecInfo.lpFile = TEXT("NOTEPAD.EXE");
  72. ExecInfo.nShow = SW_SHOWNORMAL;
  73. ExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
  74. ShellExecuteEx(&ExecInfo);
  75. }
  76. return 1;
  77. case IDC_CHECK_LICENSE:
  78. EnableWindow( GetDlgItem( hWndDlg, IDOK ), IsDlgButtonChecked( hWndDlg, IDC_CHECK_LICENSE ) == BST_CHECKED );
  79. return 1;
  80. }
  81. break;
  82. case WM_CLOSE:
  83. EndDialog( hWndDlg, ERROR_CANCELLED );
  84. return 1;
  85. }
  86. return 0;
  87. }
  88. BOOL
  89. WelcomeDialog(HWND hWndParent)
  90. {
  91. INT_PTR Status;
  92. Status = DialogBox(
  93. NULL,
  94. MAKEINTRESOURCE( IDD_WELCOME ),
  95. hWndParent,
  96. WelcomeDialogProc
  97. );
  98. return (( Status == ERROR_SUCCESS ) && ( g_bLicenseAccepted ));
  99. }