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.

194 lines
5.4 KiB

  1. /*++
  2. Copyright (c) 2001 Microsoft Corporation
  3. Module Name:
  4. main.cpp
  5. Abstract:
  6. This is the customization DLL for update.exe. When the AppCompat package
  7. is installed, the first thing that happens is update.exe calls BeginInstallation().
  8. That function checks the registry for the version of the already-installed package.
  9. The user may continue to install THIS package under the following conditions:
  10. - There is no package already installed
  11. - There is any corruption in these registry values
  12. - The package that's already installed is an older version than this one.
  13. The user will not be able to install this package under only the condition that he/she
  14. has a package already installed that's a newer version.
  15. Notes:
  16. * This is written in ANSI because Update.exe is ANSI and a Unicode implementation would add
  17. no value.
  18. * Any messages in the string table of AcVersion.rc will override messages in Update.exe.
  19. For instance, if BeginInstallation() returns STATUS_SP_VERSION_GREATER_1, normally the
  20. message in Update.exe's resources that corresponds to this would be displayed to the user.
  21. If there is, however, a STATUS_SP_VERSION_GREATER_1 string in AcVersion.rc, it will be used
  22. instead. This way we can use either Update.exe's strings OR our own custom strings.
  23. This works for all areas of the installer, by the way, not just BeginInstallation() return value.
  24. For instance, adding a STR_WELCOME_LINE string in AcVersion.rc would replace the corresponding
  25. string in Update.exe.
  26. Author:
  27. carlco created 07/30/2001
  28. --*/
  29. #include <windows.h>
  30. #include <stdlib.h>
  31. #include <stdio.h>
  32. #include "buildno.h"
  33. #include "resource.h"
  34. #define THIS_MAJOR 5
  35. #define THIS_MINOR 1
  36. #define THIS_BUILD 0
  37. #define THIS_REVISION AC_BUILD
  38. // This is from %WIN2k_SE_ROOT%\private\windows\setup\srvpack5\update4\resource.h
  39. //#define STATUS_SP_VERSION_GREATER_1 0xf06a
  40. #define STR_WELCOME_LINE 0xf039
  41. #define STATUS_BUILD_VERSION_MISMATCH 0xf020
  42. /*
  43. This is the code that will be passed back to update.exe to notify the mechanism that
  44. a package has already been installed that is a greater version than this one.
  45. */
  46. #define QFE_FAIL_CODE STATUS_SP_VERSION_GREATER_1
  47. //#define QFE_FAIL_CODE IDS_TEST
  48. /*
  49. Windows Registry Editor Version 5.00
  50. [HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Active Setup\\Installed Components\\{2eac6a2d-57a8-44d4-96f7-e32bab40ca5f}]
  51. @="Windows Update"
  52. "ComponentID"="Windows XP Application Compatibility Update"
  53. "IsInstalled"=dword:00000001
  54. "Locale"="*"
  55. "Version"="1,0,2205,0"
  56. */
  57. BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, PVOID lpvReserved)
  58. {
  59. return TRUE;
  60. }
  61. #define GRABNEXTTOKEN(a) \
  62. sz = strchr(szTok, ','); \
  63. if(sz == NULL) \
  64. { \
  65. return S_OK; \
  66. } \
  67. *sz = 0; \
  68. (a) = atoi(szTok); \
  69. szTok = sz + 1;
  70. DWORD BeginInstallation(PVOID pCustomInfo)
  71. {
  72. HKEY hKey = NULL;
  73. CHAR szVersion[25];
  74. DWORD dwSize = 25;
  75. //CHAR szBuf[500];
  76. DWORD dwMajor = 0;
  77. DWORD dwMinor = 0;
  78. DWORD dwBuild = 0;
  79. DWORD dwRevision = 0;
  80. PSTR sz = NULL;
  81. PSTR szTok = NULL;
  82. //sprintf(szBuf, "BeginInstallation\n");
  83. //OutputDebugString(szBuf);
  84. if(ERROR_SUCCESS != RegOpenKeyEx(
  85. HKEY_LOCAL_MACHINE,
  86. "SOFTWARE\\Microsoft\\Active Setup\\Installed Components\\" AC_GUID,
  87. NULL,
  88. KEY_QUERY_VALUE,
  89. &hKey))
  90. {
  91. // Error opening the key - the package may not be installed, so it's OK to install it.
  92. return S_OK;
  93. }
  94. // Get the version
  95. if(ERROR_SUCCESS != RegQueryValueEx(
  96. hKey, "Version", NULL, NULL, (PBYTE)szVersion, &dwSize
  97. ))
  98. {
  99. // Error getting this value; let's install the package.
  100. RegCloseKey(hKey);
  101. return S_OK;
  102. }
  103. RegCloseKey(hKey);
  104. // Examine the version. Find the major version number.
  105. // Find the first comma and replace it with a NULL
  106. szTok = szVersion;
  107. GRABNEXTTOKEN(dwMajor)
  108. GRABNEXTTOKEN(dwMinor)
  109. GRABNEXTTOKEN(dwBuild)
  110. // Now there shouldn't be any more commas left.
  111. // szTok is the last token.
  112. dwRevision = atoi(szTok);
  113. //sprintf(szBuf, "%d,%d,%d,%d\n", dwMajor, dwMinor, dwBuild, dwRevision);
  114. //OutputDebugString(szBuf);
  115. /*
  116. If we've made it this far, we can now compare the version.
  117. */
  118. if(dwMajor > THIS_MAJOR)
  119. {
  120. return QFE_FAIL_CODE;
  121. }
  122. if(dwMajor == THIS_MAJOR)
  123. {
  124. if(dwMinor > THIS_MINOR)
  125. {
  126. return QFE_FAIL_CODE;
  127. }
  128. if(dwMinor == THIS_MINOR)
  129. {
  130. if(dwBuild > THIS_BUILD)
  131. {
  132. return QFE_FAIL_CODE;
  133. }
  134. if(dwBuild == THIS_BUILD)
  135. {
  136. if(dwRevision > THIS_REVISION) return QFE_FAIL_CODE;
  137. }
  138. }
  139. }
  140. return S_OK;
  141. }
  142. DWORD EndInstallation(PVOID pCustomInfo)
  143. {
  144. return S_OK;
  145. }