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.

191 lines
5.7 KiB

  1. #include <windows.h>
  2. #include <ntverp.h>
  3. #include <winbase.h> // for GetCommandLine
  4. #include "datasrc.h"
  5. #include "autorun.h"
  6. #include "util.h"
  7. #include "resource.h"
  8. #include "assert.h"
  9. //////////////////////////////////////////////////////////////////////
  10. // Construction/Destruction
  11. //////////////////////////////////////////////////////////////////////
  12. CDataSource::CDataSource()
  13. {
  14. m_iItems = 0;
  15. }
  16. CDataSource::~CDataSource()
  17. {
  18. }
  19. CDataItem & CDataSource::operator[](int i)
  20. {
  21. return m_data[m_piScreen[i]];
  22. }
  23. // Init
  24. //
  25. // For autorun we read all the items out of the resources.
  26. BOOL CDataSource::Init(LPSTR pszCommandLine)
  27. {
  28. BOOL fRet = FALSE;
  29. // read the text for the items from the resources
  30. HINSTANCE hinst = GetModuleHandle(NULL);
  31. if (hinst)
  32. {
  33. for (int i=0; i<MAX_OPTIONS; i++)
  34. {
  35. TCHAR szTitle[256];
  36. TCHAR szConfig[MAX_PATH];
  37. TCHAR szArgs[MAX_PATH];
  38. szTitle[0] = szConfig[0] = szArgs[0] = 0;
  39. if (LoadStringAuto(hinst, IDS_TITLE0+i, szTitle, ARRAYSIZE(szTitle)))
  40. {
  41. LoadStringAuto(hinst, IDS_CONFIG0+i, szConfig, ARRAYSIZE(szConfig)); // may be empty
  42. if (INSTALL_WINNT == i) // for INSTALL_WINNT we pass through the command line args to setup.exe
  43. {
  44. // if we can't fit the whole cmdline, copy none rather than truncate
  45. if (lstrlen(pszCommandLine) < ARRAYSIZE(szArgs))
  46. {
  47. lstrcpyn(szArgs, pszCommandLine, ARRAYSIZE(szArgs));
  48. }
  49. }
  50. else
  51. {
  52. LoadStringAuto(hinst, IDS_ARGS0+i, szArgs, ARRAYSIZE(szArgs));
  53. }
  54. }
  55. m_data[i].SetData(szTitle, szConfig, *szArgs?szArgs:NULL, 0, i);
  56. }
  57. // Should we display the "This CD contains a newer version" dialog?
  58. OSVERSIONINFO ovi;
  59. ovi.dwOSVersionInfoSize = sizeof ( OSVERSIONINFO );
  60. if ( !GetVersionEx(&ovi) || ovi.dwPlatformId==VER_PLATFORM_WIN32s )
  61. {
  62. // We cannot upgrade win32s systems.
  63. m_Version = VER_INCOMPATIBLE;
  64. }
  65. else if ( ovi.dwPlatformId==VER_PLATFORM_WIN32_WINDOWS )
  66. {
  67. if (ovi.dwMajorVersion > 3)
  68. {
  69. // we can always upgrade win98+ systems to NT
  70. m_Version = VER_OLDER;
  71. // Disable ARP. ARP is only enabled if the CD and the OS are the same version
  72. m_data[LAUNCH_ARP].m_dwFlags |= WF_DISABLED|WF_ALTERNATECOLOR;
  73. }
  74. else
  75. {
  76. m_Version = VER_INCOMPATIBLE;
  77. }
  78. }
  79. else if ((VER_PRODUCTMAJORVERSION > ovi.dwMajorVersion) ||
  80. ((VER_PRODUCTMAJORVERSION == ovi.dwMajorVersion) && ((VER_PRODUCTMINORVERSION > ovi.dwMinorVersion) || ((VER_PRODUCTMINORVERSION == ovi.dwMinorVersion) && (VER_PRODUCTBUILD > ovi.dwBuildNumber)))))
  81. {
  82. // For NT to NT upgrades, we only upgrade if the version is lower
  83. m_Version = VER_OLDER;
  84. // Disable ARP. ARP is only enabled if the CD and the OS are the same version
  85. m_data[LAUNCH_ARP].m_dwFlags |= WF_DISABLED|WF_ALTERNATECOLOR;
  86. }
  87. else if ((VER_PRODUCTMAJORVERSION < ovi.dwMajorVersion) || (VER_PRODUCTMINORVERSION < ovi.dwMinorVersion) || (VER_PRODUCTBUILD < ovi.dwBuildNumber))
  88. {
  89. m_Version = VER_NEWER;
  90. // disable upgrade and ARP buttons and associated things
  91. m_data[INSTALL_WINNT].m_dwFlags |= WF_DISABLED|WF_ALTERNATECOLOR;
  92. m_data[COMPAT_LOCAL].m_dwFlags |= WF_DISABLED|WF_ALTERNATECOLOR;
  93. m_data[LAUNCH_ARP].m_dwFlags |= WF_DISABLED|WF_ALTERNATECOLOR;
  94. }
  95. else
  96. {
  97. m_Version = VER_SAME;
  98. }
  99. if (m_Version == VER_SAME)
  100. {
  101. m_piScreen = c_aiWhistler;
  102. m_iItems = c_cWhistler;
  103. }
  104. else
  105. {
  106. m_piScreen = c_aiMain;
  107. m_iItems = c_cMain;
  108. }
  109. fRet = TRUE;
  110. }
  111. return fRet;
  112. }
  113. void CDataSource::SetWindow(HWND hwnd)
  114. {
  115. m_hwndDlg = hwnd;
  116. }
  117. void CDataSource::Invoke( int i, HWND hwnd )
  118. {
  119. i = m_piScreen[i];
  120. // if this item is disalbled then do nothing
  121. if ( m_data[i].m_dwFlags & WF_DISABLED )
  122. {
  123. MessageBeep(0);
  124. return;
  125. }
  126. // otherwise we have already built the correct command and arg strings so just invoke them
  127. switch (i)
  128. {
  129. case INSTALL_WINNT:
  130. case LAUNCH_ARP:
  131. case BROWSE_CD:
  132. case COMPAT_WEB:
  133. case COMPAT_LOCAL:
  134. case HOMENET_WIZ:
  135. case MIGRATION_WIZ:
  136. case TS_CLIENT:
  137. case VIEW_RELNOTES:
  138. m_data[i].Invoke(hwnd);
  139. break;
  140. case SUPPORT_TOOLS:
  141. m_piScreen = c_aiSupport;
  142. m_iItems = c_cSupport;
  143. PostMessage(m_hwndDlg, ARM_CHANGESCREEN, SCREEN_TOOLS, 0);
  144. break;
  145. case COMPAT_TOOLS:
  146. m_piScreen = c_aiCompat;
  147. m_iItems = c_cCompat;
  148. PostMessage(m_hwndDlg, ARM_CHANGESCREEN, SCREEN_COMPAT, 0);
  149. break;
  150. case BACK:
  151. if (m_Version == VER_SAME)
  152. {
  153. m_piScreen = c_aiWhistler;
  154. m_iItems = c_cWhistler;
  155. }
  156. else
  157. {
  158. m_piScreen = c_aiMain;
  159. m_iItems = c_cMain;
  160. }
  161. PostMessage(m_hwndDlg, ARM_CHANGESCREEN, SCREEN_MAIN, 0);
  162. break;
  163. default:
  164. assert(0);
  165. break;
  166. }
  167. }