//======================================================================= // // Copyright (c) 2001-2002 Microsoft Corporation. All Rights Reserved. // // File: AUEventLog.cpp // // Creator: DChow // // Purpose: Event Logging class // //======================================================================= #include "pch.h" extern HINSTANCE g_hInstance; extern AUCatalog *gpAUcatalog; const TCHAR c_tszSourceKey[] = _T("SYSTEM\\CurrentControlSet\\Services\\Eventlog\\System\\Automatic Updates"); CAUEventLog::CAUEventLog(HINSTANCE hInstance) : m_hEventLog(NULL), m_ptszListItemFormat(NULL) { const DWORD c_dwLen = 64; LPTSTR ptszToken = NULL; if (NULL != (m_ptszListItemFormat = (LPTSTR) malloc(sizeof(TCHAR) * c_dwLen)) && 0 != LoadString( hInstance, IDS_EVT_LISTITEMFORMAT, m_ptszListItemFormat, c_dwLen) && NULL != (ptszToken = StrStr(m_ptszListItemFormat, _T("%lS"))) && EnsureValidSource() && NULL != (m_hEventLog = RegisterEventSource(NULL, _T("Automatic Updates")))) { // bug 492897: WUAU: W2K: Event log error for installation failure // does not show the package that failed. CombineItems() calls // StringCchPrintfEx() which in turn calls _sntprintf(). _sntprintf // calls wvsprintf(). Compiled with USE_VCRT=1, the %lS placeholder // in the format string will be replaced under Win2K by only the first // character of the intended string, contrary to MSDN. It doesn't // happen if the placeholder is %ls, %ws or %wS, or if the running // platform is WinXP or .Net Server. To get around the problem // without using an unsafe function, we choose to replace %lS in the // format string from resource with %ls. // We should move the fix to the resource string when we can. ptszToken[2] = _T('s'); // Convert %lS into %ls } else { AUASSERT(FALSE); SafeFreeNULL(m_ptszListItemFormat); } } CAUEventLog::~CAUEventLog() { if (NULL != m_hEventLog) { DeregisterEventSource(m_hEventLog); } SafeFree(m_ptszListItemFormat); } // Assume no NULL in the pbstrItems and pptszMsgParams arrays. BOOL CAUEventLog::LogEvent( WORD wType, WORD wCategory, DWORD dwEventID, UINT nNumOfItems, BSTR *pbstrItems, WORD wNumOfMsgParams, LPTSTR *pptszMsgParams) const { if (NULL == m_hEventLog || NULL == m_ptszListItemFormat) { return FALSE; } BOOL fRet = FALSE; LPTSTR ptszItemList = NULL; LPTSTR *pptszAllMsgParams = pptszMsgParams; WORD wNumOfAllMsgParams = wNumOfMsgParams; if (0 < nNumOfItems) { wNumOfAllMsgParams++; if (NULL == (ptszItemList = CombineItems(nNumOfItems, pbstrItems))) { goto CleanUp; } if (0 < wNumOfMsgParams) { if (NULL == (pptszAllMsgParams = (LPTSTR *) malloc(sizeof(LPTSTR) * wNumOfAllMsgParams))) { goto CleanUp; } for (INT i=0; i 0) { SysFreeString(pbstrItems[--i]); } free(pbstrItems); } DEBUGMSG("CAUEventLog::LogEvent(VARIANT version) ends"); return fRet; } // The caller is responsible for freeing the return value if this function succeeds. LPTSTR CAUEventLog::CombineItems(UINT nNumOfItems, BSTR *pbstrItems) const { DEBUGMSG("CombineItems"); if (NULL != m_ptszListItemFormat && NULL != pbstrItems && 0 < nNumOfItems) { // Estimate buffer size size_t cchBufferLen = 1; // 1 for the terminating NULL size_t cchListItemFormatLen = lstrlen(m_ptszListItemFormat); for (UINT i=0; im_ItemList; UINT nNumOfItems = itemList.GetNumSelected(); if (0 < nNumOfItems) { BSTR *pbstrItems = (BSTR *) malloc(sizeof(BSTR) * nNumOfItems); if (NULL != pbstrItems) { CAUEventLog aueventlog(g_hInstance); UINT j = 0; for (UINT i=0; iGetSchedInstallDate(auftSchedInstallDate); //fixcode: any need to use DATE_LTRREADING or DATE_RTLREADING? if (FileTimeToSystemTime(&auftSchedInstallDate.ft, &stScheduled)) { if (0 != GetDateFormat( LOCALE_SYSTEM_DEFAULT, LOCALE_NOUSEROVERRIDE | DATE_LONGDATE, &stScheduled, NULL, tszScheduledDate, ARRAYSIZE(tszScheduledDate))) { if (Hours2LocalizedString( &stScheduled, tszScheduledTime, ARRAYSIZE(tszScheduledTime))) { LPTSTR pptszMsgParams[2]; pptszMsgParams[0] = tszScheduledDate; pptszMsgParams[1] = tszScheduledTime; LogEvent_ItemList( EVENTLOG_INFORMATION_TYPE, IDS_MSG_Installation, IDS_MSG_InstallReady_Scheduled, 2, pptszMsgParams); } #ifdef DBG else { DEBUGMSG("LogEvent_ScheduledInstall() call to Hours2LocalizedString() failed"); } #endif } #ifdef DBG else { DEBUGMSG("LogEvent_ScheduledInstall() call to GetDateFormatW() failed (%#lx)", GetLastError()); } #endif } #ifdef DBG else { DEBUGMSG("LogEvent_ScheduledInstall() call to FileTimeToSystemTime() failed (%#lx)", GetLastError()); } #endif }