Skip to content

Commit

Permalink
add system install date
Browse files Browse the repository at this point in the history
  • Loading branch information
a1ive committed Dec 31, 2023
1 parent 8659911 commit 096e2b2
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
3 changes: 3 additions & 0 deletions libnw/sys.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ static void PrintOsVer(PNODE node)
DWORD dwType, dwSize;
CHAR szSP[] = " SP65535.65535";
LPWSTR lpEdition = NULL;
DWORD dwInstallDate = 0;
if (NWLC->NwOsInfo.wServicePackMinor)
snprintf(szSP, sizeof(szSP), " SP%u.%u", NWLC->NwOsInfo.wServicePackMajor, NWLC->NwOsInfo.wServicePackMinor);
else if (NWLC->NwOsInfo.wServicePackMajor)
Expand All @@ -172,6 +173,8 @@ static void PrintOsVer(PNODE node)
NWL_NodeAttrSet(node, "Edition", NWL_Ucs2ToUtf8(lpEdition), 0);
free(lpEdition);
}
NWL_GetRegDwordValue(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", L"InstallDate", &dwInstallDate);
NWL_NodeAttrSet(node, "Install Date", NWL_UnixTimeToStr(dwInstallDate), 0);
}

static void
Expand Down
46 changes: 46 additions & 0 deletions libnw/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,52 @@ NWL_GetMonitorFromName(LPCWSTR lpDevice)
return ctx.hMonitor;
}

#define SECPERMIN 60
#define SECPERHOUR (60*SECPERMIN)
#define SECPERDAY (24*SECPERHOUR)
#define DAYSPERYEAR 365
#define DAYSPER4YEARS (4*DAYSPERYEAR+1)

LPCSTR
NWL_UnixTimeToStr(INT nix)
{
static CHAR buf[28];
UINT8 months[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
INT daysEpoch;
UINT32 days;
UINT32 secsInDay;
UINT16 year;
UINT8 month;
UINT8 hour;

if (nix < 0)
daysEpoch = -(((INT64)(SECPERDAY) - nix - 1) / SECPERDAY);
else
daysEpoch = nix / SECPERDAY;

secsInDay = nix - daysEpoch * SECPERDAY;
days = daysEpoch + 69 * DAYSPERYEAR + 17;
year = 1901 + 4 * (days / DAYSPER4YEARS);
days %= DAYSPER4YEARS;
if (days / DAYSPERYEAR == 4)
{
year += 3;
days -= 3 * DAYSPERYEAR;
}
else
{
year += days / DAYSPERYEAR;
days %= DAYSPERYEAR;
}
for (month = 0; month < 12 && days >= (month == 1 && year % 4 == 0 ? 29U : months[month]); month++)
days -= (month == 1 && year % 4 == 0 ? 29U : months[month]);
hour = (secsInDay / SECPERHOUR);
secsInDay %= SECPERHOUR;
snprintf(buf, sizeof(buf), "%04u-%02u-%02u %02u:%02u:%02u (UTC)",
year, month + 1, days + 1, hour, secsInDay / SECPERMIN, secsInDay % SECPERMIN);
return buf;
}

static CHAR Utf8Buf[NWINFO_BUFSZ + 1];

LPCSTR
Expand Down
1 change: 1 addition & 0 deletions libnw/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ LPCSTR NWL_GetBusTypeString(STORAGE_BUS_TYPE Type);
LPCSTR NWL_GuidToStr(UCHAR Guid[16]);
LPCSTR NWL_WinGuidToStr(BOOL bBracket, GUID* pGuid);
HMONITOR NWL_GetMonitorFromName(LPCWSTR lpDevice);
LPCSTR NWL_UnixTimeToStr(INT nix);
LPCSTR NWL_Ucs2ToUtf8(LPCWSTR src);
LPCWSTR NWL_Utf8ToUcs2(LPCSTR src);

Expand Down

0 comments on commit 096e2b2

Please sign in to comment.