Skip to content

Commit

Permalink
Updated to V2.3.2.0
Browse files Browse the repository at this point in the history
Rework FormatSystemTime as it wasn't handling strictly invalid dates well. By handling the return values it can at least return empty strings rather than rubbish.
Handle the invalid date in FileTimeToText as SystemTimeToTzSpecificLocalTime would fail (with a bad date) even though FileTimeToSystemTime would succeed.
  • Loading branch information
David Lowndes authored and David Lowndes committed May 13, 2024
1 parent 1167c71 commit 5faa779
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 21 deletions.
8 changes: 4 additions & 4 deletions CppCustomVisualizer/dll/CppCustomVisualizer.rc
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ END
//

VS_VERSION_INFO VERSIONINFO
FILEVERSION 2,3,1,0
PRODUCTVERSION 2,3,1,0
FILEVERSION 2,3,2,0
PRODUCTVERSION 2,3,2,0
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
Expand All @@ -69,12 +69,12 @@ BEGIN
BEGIN
VALUE "CompanyName", "David Lowndes"
VALUE "FileDescription", "Dave's Custom Visualizers"
VALUE "FileVersion", "2.3.1.0"
VALUE "FileVersion", "2.3.2.0"
VALUE "InternalName", "DavesCustomVisualizer.dll"
VALUE "LegalCopyright", "(c) David Lowndes 2024. All rights reserved."
VALUE "OriginalFilename", "DavesCustomVisualizer.dll"
VALUE "ProductName", "Dave's Custom Visualizers"
VALUE "ProductVersion", "2.3.1.0"
VALUE "ProductVersion", "2.3.2.0"
END
END
BLOCK "VarFileInfo"
Expand Down
44 changes: 27 additions & 17 deletions CppCustomVisualizer/dll/FileAndSystemTimeViz.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,41 +12,53 @@ static CString FormatSystemTime( const SYSTEMTIME& st )
TCHAR szDate[50];

// Use long date format to allow the day name to show if that's in that format. Short date formats don't include the day.
size_t NumCharsD = GetDateFormat( GetThreadLocale(), DATE_LONGDATE, &st, NULL, szDate, _countof( szDate ) );
const size_t NumCharsD = GetDateFormat( GetThreadLocale(), DATE_LONGDATE, &st, NULL, szDate, _countof( szDate ) );

TCHAR szTime[50];
if ( NumCharsD == 0 )
{
// Normally GetLastError is ERROR_INVALID_PARAMETER indicating that the SYSTEMTIME invalid.

auto NumCharsT = GetTimeFormat( GetThreadLocale(), TIME_FORCE24HOURFORMAT, &st, NULL, szTime, _countof( szTime ) );
// Date is invalid, so clear the buffer
szDate[0] = _T('\0');
}

CString str;
TCHAR szTime[50];

const auto NumCharsT = GetTimeFormat( GetThreadLocale(), TIME_FORCE24HOURFORMAT, &st, NULL, szTime, _countof( szTime ) );

// If one of these isn't there, something's wrong, return an empty string
if ( (NumCharsD != 0) || (NumCharsT != 0) )
if ( NumCharsT == 0 )
{
str = szDate;
str += _T( ' ' );
str += szTime;
// Failed to get the time, so clear the buffer
szTime[0] = _T('\0');
}

CString str;
str.Format( _T( "%s %s" ), szDate, szTime );

return str;
}

CString FileTimeToText( const FILETIME& ftUtc, UINT nBase )
{
CString text;

bool bValidFileTime{ false };

// convert to SystemTime
SYSTEMTIME SysTime;

if ( FileTimeToSystemTime( &ftUtc, &SysTime ) )
{
CString strUtc = FormatSystemTime( SysTime );
const CString strUtc = FormatSystemTime( SysTime );

SYSTEMTIME lst;

// Even though FileTimeToSystemTime succeeds, and FormatSystemTime can
// return something, SystemTimeToTzSpecificLocalTime can fail if the
// time is invalid. So check the return value.
if ( SystemTimeToTzSpecificLocalTime( NULL, &SysTime, &lst ) )
{
CString strLoc = FormatSystemTime( lst );
const CString strLoc = FormatSystemTime( lst );

// Determine if there's a difference between local & utc so that I can display the most appropriate zone name
LONGLONG diffInMins;
Expand All @@ -65,13 +77,12 @@ CString FileTimeToText( const FILETIME& ftUtc, UINT nBase )
LPCWSTR ZoneName = diffInMins != 0 ? tzi.DaylightName : tzi.StandardName;

text.Format( _T( "[utc] %s [%ls] %s" ), static_cast<LPCTSTR>(strUtc), ZoneName, static_cast<LPCTSTR>(strLoc) );
}
else
{
text.Format( _T( "utc: %s ???" ), static_cast<LPCTSTR>(strUtc) );

bValidFileTime = true;
}
}
else

if ( !bValidFileTime )
{
// Prior to VS2017 RC2, VS only ever passed 10 for nBase, newer versions should support base values of 2, 8, 10, or 16
char szHigh[33]; // 32 chars max for base 2 from a DWORD value
Expand Down Expand Up @@ -100,7 +111,6 @@ CString FileTimeToText( const FILETIME& ftUtc, UINT nBase )
}

text.Format( _T( "Invalid [%hs%hs:%hs%hs]" ), Prefix, szHigh, Prefix, szLow );
// sprintf_s( pResult, BufferMax, );
}
return text;
}
Expand Down

0 comments on commit 5faa779

Please sign in to comment.