Changeset 96756 in vbox for trunk/src/VBox/Additions
- Timestamp:
- Sep 15, 2022 11:30:47 PM (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/WINNT/Installer/VBoxDrvInst.cpp
r96722 r96756 235 235 236 236 /* 237 * Write to the log file if we have one (wide char format, used to be ansi).237 * Write to the log file if we have one - have to convert the input to UTF-8. 238 238 */ 239 239 HANDLE const hLogFile = (HANDLE)pvCtx; … … 241 241 { 242 242 /* "event: err - desc\r\n" */ 243 wchar_t wszBuf[168]; 244 RTUtf16CopyAscii(wszBuf, RT_ELEMENTS(wszBuf), pszEvent); 245 RTUtf16CatAscii(wszBuf, RT_ELEMENTS(wszBuf), ": "); 246 char szVal[128]; 247 RTStrFormatU32(szVal, sizeof(szVal), dwError, 10, 0, 0, 0); 248 RTUtf16CatAscii(wszBuf, RT_ELEMENTS(wszBuf), szVal); 249 RTUtf16CatAscii(wszBuf, RT_ELEMENTS(wszBuf), " - "); 250 243 char szBuf[256]; 244 RTStrCopy(szBuf, sizeof(szBuf), pszEvent); 245 RTStrCat(szBuf, sizeof(szBuf), ": "); 246 size_t offVal = strlen(szBuf); 247 RTStrFormatU32(&szBuf[offVal], sizeof(szBuf) - offVal, dwError, 10, 0, 0, 0); 248 RTStrCat(szBuf, sizeof(szBuf), " - "); 251 249 DWORD dwIgn; 252 WriteFile(hLogFile, wszBuf, (DWORD)(RTUtf16Len(wszBuf) * sizeof(wchar_t)), &dwIgn, NULL); 253 WriteFile(hLogFile, pwszEventDesc, (DWORD)(RTUtf16Len(pwszEventDesc) * sizeof(wchar_t)), &dwIgn, NULL); 254 WriteFile(hLogFile, L"\r\n", 2 * sizeof(wchar_t), &dwIgn, NULL); 250 WriteFile(hLogFile, szBuf, (DWORD)strlen(szBuf), &dwIgn, NULL); 251 252 char *pszUtf8 = NULL; 253 int vrc = RTUtf16ToUtf8(pwszEventDesc, &pszUtf8); 254 if (RT_SUCCESS(vrc)) 255 { 256 WriteFile(hLogFile, pszUtf8, (DWORD)strlen(pszUtf8), &dwIgn, NULL); 257 RTStrFree(pszUtf8); 258 WriteFile(hLogFile, RT_STR_TUPLE("\r\n"), &dwIgn, NULL); 259 } 260 else 261 WriteFile(hLogFile, RT_STR_TUPLE("<RTUtf16ToUtf8 failed>\r\n"), &dwIgn, NULL); 255 262 } 256 263 } … … 262 269 static void VBoxDIFxWriteLogHeader(HANDLE hLogFile, char const *pszOperation, wchar_t const *pwszInfFile) 263 270 { 264 /* Don't want to use RTUtf16Printf here as it drags in a lot of code, thus this tedium... */ 265 wchar_t wszBuf[168]; 266 RTUtf16CopyAscii(wszBuf, RT_ELEMENTS(wszBuf), "\r\n"); 271 /* Don't want to use RTStrPrintf here as it drags in a lot of code, thus this tedium... */ 272 char szBuf[256]; 273 size_t offBuf = 2; 274 RTStrCopy(szBuf, sizeof(szBuf), "\r\n"); 267 275 268 276 SYSTEMTIME SysTime = {0}; 269 277 GetSystemTime(&SysTime); 270 278 271 char szVal[128]; 272 RTStrFormatU32(szVal, sizeof(szVal), SysTime.wYear, 10, 4, 0, RTSTR_F_ZEROPAD | RTSTR_F_WIDTH); 273 RTUtf16CatAscii(wszBuf, RT_ELEMENTS(wszBuf), szVal); 274 RTUtf16CatAscii(wszBuf, RT_ELEMENTS(wszBuf), "-"); 275 276 RTStrFormatU32(szVal, sizeof(szVal), SysTime.wMonth, 10, 2, 0, RTSTR_F_ZEROPAD | RTSTR_F_WIDTH); 277 RTUtf16CatAscii(wszBuf, RT_ELEMENTS(wszBuf), szVal); 278 RTUtf16CatAscii(wszBuf, RT_ELEMENTS(wszBuf), "-"); 279 280 RTStrFormatU32(szVal, sizeof(szVal), SysTime.wDay, 10, 2, 0, RTSTR_F_ZEROPAD | RTSTR_F_WIDTH); 281 RTUtf16CatAscii(wszBuf, RT_ELEMENTS(wszBuf), szVal); 282 RTUtf16CatAscii(wszBuf, RT_ELEMENTS(wszBuf), "T"); 283 284 RTStrFormatU32(szVal, sizeof(szVal), SysTime.wHour, 10, 2, 0, RTSTR_F_ZEROPAD | RTSTR_F_WIDTH); 285 RTUtf16CatAscii(wszBuf, RT_ELEMENTS(wszBuf), szVal); 286 RTUtf16CatAscii(wszBuf, RT_ELEMENTS(wszBuf), ":"); 287 288 RTStrFormatU32(szVal, sizeof(szVal), SysTime.wMinute, 10, 2, 0, RTSTR_F_ZEROPAD | RTSTR_F_WIDTH); 289 RTUtf16CatAscii(wszBuf, RT_ELEMENTS(wszBuf), szVal); 290 RTUtf16CatAscii(wszBuf, RT_ELEMENTS(wszBuf), ":"); 291 292 RTStrFormatU32(szVal, sizeof(szVal), SysTime.wSecond, 10, 2, 0, RTSTR_F_ZEROPAD | RTSTR_F_WIDTH); 293 RTUtf16CatAscii(wszBuf, RT_ELEMENTS(wszBuf), szVal); 294 RTUtf16CatAscii(wszBuf, RT_ELEMENTS(wszBuf), "."); 295 296 RTStrFormatU32(szVal, sizeof(szVal), SysTime.wMilliseconds, 10, 3, 0, RTSTR_F_ZEROPAD | RTSTR_F_WIDTH); 297 RTUtf16CatAscii(wszBuf, RT_ELEMENTS(wszBuf), szVal); 298 RTUtf16CatAscii(wszBuf, RT_ELEMENTS(wszBuf), "Z: Opened log file for "); 299 300 RTUtf16CatAscii(wszBuf, RT_ELEMENTS(wszBuf), pszOperation); 301 RTUtf16CatAscii(wszBuf, RT_ELEMENTS(wszBuf), " of '"); 279 RTStrFormatU32(&szBuf[offBuf], sizeof(szBuf) - offBuf, SysTime.wYear, 10, 4, 0, RTSTR_F_ZEROPAD | RTSTR_F_WIDTH); 280 offBuf += strlen(&szBuf[offBuf]); 281 szBuf[offBuf++] = '-'; 282 283 RTStrFormatU32(&szBuf[offBuf], sizeof(szBuf) - offBuf, SysTime.wMonth, 10, 2, 0, RTSTR_F_ZEROPAD | RTSTR_F_WIDTH); 284 offBuf += strlen(&szBuf[offBuf]); 285 szBuf[offBuf++] = '-'; 286 287 RTStrFormatU32(&szBuf[offBuf], sizeof(szBuf) - offBuf, SysTime.wDay, 10, 2, 0, RTSTR_F_ZEROPAD | RTSTR_F_WIDTH); 288 offBuf += strlen(&szBuf[offBuf]); 289 szBuf[offBuf++] = 'T'; 290 291 RTStrFormatU32(&szBuf[offBuf], sizeof(szBuf) - offBuf, SysTime.wHour, 10, 2, 0, RTSTR_F_ZEROPAD | RTSTR_F_WIDTH); 292 offBuf += strlen(&szBuf[offBuf]); 293 szBuf[offBuf++] = ':'; 294 295 RTStrFormatU32(&szBuf[offBuf], sizeof(szBuf) - offBuf, SysTime.wMinute, 10, 2, 0, RTSTR_F_ZEROPAD | RTSTR_F_WIDTH); 296 offBuf += strlen(&szBuf[offBuf]); 297 szBuf[offBuf++] = ':'; 298 299 RTStrFormatU32(&szBuf[offBuf], sizeof(szBuf) - offBuf, SysTime.wSecond, 10, 2, 0, RTSTR_F_ZEROPAD | RTSTR_F_WIDTH); 300 offBuf += strlen(&szBuf[offBuf]); 301 szBuf[offBuf++] = '.'; 302 303 RTStrFormatU32(&szBuf[offBuf], sizeof(szBuf) - offBuf, SysTime.wMilliseconds, 10, 3, 0, RTSTR_F_ZEROPAD | RTSTR_F_WIDTH); 304 offBuf += strlen(&szBuf[offBuf]); 305 RTStrCat(&szBuf[offBuf], sizeof(szBuf) - offBuf, "Z: Opened log file for "); 306 RTStrCat(&szBuf[offBuf], sizeof(szBuf) - offBuf, pszOperation); 307 RTStrCat(&szBuf[offBuf], sizeof(szBuf) - offBuf, " of '"); 302 308 303 309 DWORD dwIgn; 304 WriteFile(hLogFile, wszBuf, (DWORD)(RTUtf16Len(wszBuf) * sizeof(wchar_t)), &dwIgn, NULL); 305 WriteFile(hLogFile, pwszInfFile, (DWORD)(RTUtf16Len(pwszInfFile) * sizeof(wchar_t)), &dwIgn, NULL); 306 WriteFile(hLogFile, L"'\r\n", 3 * sizeof(wchar_t), &dwIgn, NULL); 310 WriteFile(hLogFile, szBuf, (DWORD)strlen(szBuf), &dwIgn, NULL); 311 312 char *pszUtf8 = NULL; 313 int vrc = RTUtf16ToUtf8(pwszInfFile, &pszUtf8); 314 if (RT_SUCCESS(vrc)) 315 { 316 WriteFile(hLogFile, pszUtf8, (DWORD)strlen(pszUtf8), &dwIgn, NULL); 317 RTStrFree(pszUtf8); 318 WriteFile(hLogFile, RT_STR_TUPLE("'\r\n"), &dwIgn, NULL); 319 } 320 else 321 WriteFile(hLogFile, RT_STR_TUPLE("<RTUtf16ToUtf8 failed>'\r\n"), &dwIgn, NULL); 307 322 } 308 323
Note:
See TracChangeset
for help on using the changeset viewer.