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.

217 lines
7.2 KiB

  1. //=======================================================================
  2. //
  3. // Copyright (c) 2001 Microsoft Corporation. All Rights Reserved.
  4. //
  5. // File: wuaulib.h
  6. //
  7. // Creator: PeterWi
  8. //
  9. // Purpose: library function declarations.
  10. //
  11. //=======================================================================
  12. #pragma once
  13. #include <tchar.h>
  14. #include <wchar.h>
  15. #include <timeutil.h>
  16. #include "WUTestKeys.h"
  17. #define ARRAYSIZE(x) (sizeof(x)/sizeof(x[0]))
  18. // Defs for boolean AU options
  19. #define AUOPTION_UNSPECIFIED 0
  20. #define AUOPTION_AUTOUPDATE_DISABLE 1
  21. #define AUOPTION_PREDOWNLOAD_NOTIFY 2
  22. #define AUOPTION_INSTALLONLY_NOTIFY 3
  23. #define AUOPTION_SCHEDULED 4
  24. #define AUOPTION_ADMIN_MIN AUOPTION_AUTOUPDATE_DISABLE
  25. #define AUOPTION_DOMAIN_MIN AUOPTION_PREDOWNLOAD_NOTIFY
  26. #define AUOPTION_MAX AUOPTION_SCHEDULED
  27. // download status
  28. #define DWNLDSTATUS_NOT_DOWNLOADING 0
  29. #define DWNLDSTATUS_DOWNLOADING 1
  30. #define DWNLDSTATUS_PAUSED 2
  31. #define DWNLDSTATUS_CHECKING_CONNECTION 3
  32. //////////////////////Client (WUAUCLT) exit codes //////////////////////////
  33. #define CDWWUAUCLT_UNSPECIFY -1
  34. #define CDWWUAUCLT_OK 1000
  35. #define CDWWUAUCLT_RELAUNCHNOW 1001
  36. #define CDWWUAUCLT_RELAUNCHLATER 1002 //ask service to launch client
  37. #define CDWWUAUCLT_ENDSESSION 1003 // user logs off or system shuts down
  38. #define CDWWUAUCLT_FATAL_ERROR 1004
  39. #define CDWWUAUCLT_INSTALLNOW 1005
  40. #define CDWWUAUCLT_REBOOTNOW 1007
  41. #define CDWWUAUCLT_REBOOTLATER 1008
  42. #define CDWWUAUCLT_REBOOTNEEDED 1009 //user hasn't made decision as weather to reboot or not
  43. #define CDWWUAUCLT_REBOOTTIMEOUT 1010 //reboot warning dialog times out
  44. //////////////////////No Active Admin Session found//////////////////////////
  45. #define DWNO_ACTIVE_ADMIN_SESSION_FOUND -1 // No Active Admin Session Found
  46. #define DWNO_ACTIVE_ADMIN_SESSION_SERVICE_FINISHED -2 // No Active Admin Sesion found due to Service Finishing or because caller routine needs to finish service
  47. #define DWSYSTEM_ACCOUNT -3
  48. class AU_ENV_VARS {
  49. public:
  50. static const int s_AUENVVARCOUNT = 4;
  51. static const int s_AUENVVARBUFSIZE = 100;
  52. BOOL m_fRebootWarningMode ; //regular mode otherwise
  53. BOOL m_fEnableYes; //for reboot warning dialog
  54. BOOL m_fEnableNo; //for reboot warning dialog
  55. TCHAR m_szClientExitEvtName[s_AUENVVARBUFSIZE];
  56. public:
  57. BOOL ReadIn(void);
  58. BOOL WriteOut(LPTSTR szEnvBuf, //at least size of 4*AUEVVARBUFSIZE
  59. size_t IN cchEnvBuf,
  60. BOOL IN fRebootWarningMode,
  61. BOOL IN fEnableYes = TRUE,
  62. BOOL IN fEnableNo = TRUE,
  63. LPCTSTR IN szClientExitEvtName = NULL);
  64. private:
  65. static const LPCTSTR s_AUENVVARNAMES[s_AUENVVARCOUNT];
  66. HRESULT GetStringValue(int index, LPTSTR buf, DWORD dwCchSize);
  67. BOOL GetBOOLEnvironmentVar(LPCTSTR szEnvVar, BOOL *pfVal);
  68. BOOL GetStringEnvironmentVar(LPCTSTR szzEnvVar, LPTSTR szBuf, DWORD dwSize);
  69. };
  70. //////////////// The following functions are all called from the outside! ///////////////////////
  71. /////////////////////////////////////////////////////////////////////
  72. // cfreg.cpp - Functions to handle registry keys
  73. /////////////////////////////////////////////////////////////////////
  74. BOOL fRegKeyCreate(LPCTSTR tszKey, DWORD dwOptions);
  75. BOOL fRegKeyExists(LPCTSTR tszSubKey, HKEY hRootKey = HKEY_LOCAL_MACHINE);
  76. inline HRESULT String2FileTime(LPCTSTR pszDateTime, FILETIME *pft)
  77. {
  78. SYSTEMTIME st;
  79. HRESULT hr = String2SystemTime(pszDateTime, &st);
  80. if ( SUCCEEDED(hr) )
  81. {
  82. if ( !SystemTimeToFileTime(&st, pft) )
  83. {
  84. hr = HRESULT_FROM_WIN32(GetLastError());
  85. }
  86. }
  87. return hr;
  88. }
  89. inline HRESULT FileTime2String(FILETIME & ft, LPTSTR pszDateTime, size_t cchSize)
  90. {
  91. SYSTEMTIME st;
  92. HRESULT hr;
  93. if ( !FileTimeToSystemTime(&ft, &st) )
  94. {
  95. hr = HRESULT_FROM_WIN32(GetLastError());
  96. }
  97. else
  98. {
  99. hr = SystemTime2String(st, pszDateTime, cchSize);
  100. }
  101. return hr;
  102. }
  103. BOOL FHiddenItemsExist();
  104. HRESULT setAddedTimeout(DWORD timeout, LPCTSTR strkey);
  105. HRESULT getAddedTimeout(DWORD *pdwTimeDiff, LPCTSTR strkey);
  106. extern const TCHAR AUREGKEY_REBOOT_REQUIRED[]; // = _T("Software\\Microsoft\\Windows\\CurrentVersion\\WindowsUpdate\\Auto Update\\RebootRequired");
  107. inline BOOL fSetRebootFlag(void)
  108. {
  109. return fRegKeyCreate(AUREGKEY_REBOOT_REQUIRED, REG_OPTION_VOLATILE);
  110. }
  111. inline BOOL fRegKeyDelete(LPCTSTR tszKey)
  112. {
  113. return (ERROR_SUCCESS == RegDeleteKey(HKEY_LOCAL_MACHINE, tszKey));
  114. }
  115. inline BOOL fCheckRebootFlag(void)
  116. {
  117. return fRegKeyExists(AUREGKEY_REBOOT_REQUIRED);
  118. }
  119. /////////////////////////////////////////////////////////////////////
  120. // helpers.cpp
  121. /////////////////////////////////////////////////////////////////////
  122. DWORD getTimeOut();
  123. int TimeDiff(SYSTEMTIME tm1, SYSTEMTIME tm2);
  124. HRESULT TimeAddSeconds(SYSTEMTIME tmBase, int iSeconds, SYSTEMTIME* pTimeNew);
  125. inline void setTimeOut(DWORD dwTimeOut)
  126. {
  127. SetRegDWordValue(_T("TimeOut"), dwTimeOut);
  128. }
  129. BOOL IsRTFDownloaded(BSTR bstrRTFPath, LANGID langid);
  130. BOOL FHiddenItemsExist(void);
  131. BOOL RemoveHiddenItems(void);
  132. void DisableUserInput(HWND hwnd);
  133. BOOL Hours2LocalizedString(SYSTEMTIME *pst, LPTSTR ptszBuffer, DWORD cbSize);
  134. BOOL FillHrsCombo(HWND hwnd, DWORD dwSchedInstallTime);
  135. BOOL FillDaysCombo(HINSTANCE hInstance, HWND hwnd, DWORD dwSchedInstallDay, UINT uMinResId, UINT uMaxResId);
  136. BOOL fAccessibleToAU(void);
  137. BOOL IsWin2K(void);
  138. extern const LPTSTR HIDDEN_ITEMS_FILE;
  139. //////////////////////////////////////////////////////////////////////////////////////
  140. // platform.cpp
  141. //////////////////////////////////////////////////////////////////////////////////////
  142. void GetOSName(LPTSTR _szOSName);
  143. UINT DetectPlatformID(void);
  144. HRESULT GetOSVersionStr(LPTSTR tszbuf, UINT uSize);
  145. BOOL fIsPersonalOrProfessional(void);
  146. HRESULT GetFileVersionStr(LPCTSTR tszFile, LPTSTR tszbuf, UINT uSize);
  147. const TCHAR g_szPropDialogPtr[] = TEXT("AutoUpdateProp_DialogPtr");
  148. const TCHAR g_szHelpFile[] = _T("wuauhelp.chm::/auw2ktt.txt"); //TEXT("sysdm.hlp"); //used on both w2k and xp.
  149. const TCHAR gtszAUOverviewUrl[] = _T("wuauhelp.chm"); //default
  150. const TCHAR gtszAUW2kSchedInstallUrl[] = _T("wuauhelp.chm::/w2k_autoupdate_sched.htm");
  151. const TCHAR gtszAUXPSchedInstallUrl[] = _T("wuauhelp.chm::/autoupdate_sched.htm");
  152. //////////////////////////////////////////////////////////////////////////////////////
  153. // DEBUG STUFF //
  154. //////////////////////////////////////////////////////////////////////////////////////
  155. #ifdef DBG
  156. //===== DBG ==========================================================================
  157. void _cdecl WUAUTrace(char* pszFormat, ...);
  158. #define DEBUGMSG WUAUTrace
  159. inline BOOL fAUAssertBreak(void)
  160. {
  161. static DWORD dwVal = -1;
  162. if (-1 != dwVal)
  163. {
  164. return 1 == dwVal;
  165. }
  166. if (FAILED(GetRegDWordValue(_T("AssertBreak"), &dwVal)))
  167. { //if key is not there, don't read again and again
  168. dwVal = 0;
  169. }
  170. return 1 == dwVal;
  171. }
  172. #define AUASSERT(x) { if (!(x) && fAUAssertBreak()) DebugBreak();}
  173. #else // !DBG
  174. //===== !DBG ==========================================================================
  175. inline void _cdecl WUAUTrace(char* , ...) {}
  176. #define DEBUGMSG WUAUTrace
  177. #define AUASSERT(x)
  178. #endif // DBG
  179. //=====================================================================================