+ DWORD dwBytes = BUFFER_SIZE*sizeof(TCHAR), dwType;
+ BOOL bRet = TRUE;
+
+ /* If SubKy is specified open it */
+ if (lpSubKey && RegOpenKeyEx(hKey,
+ lpSubKey,
+ 0,
+ KEY_QUERY_VALUE,
+ &hKey) != ERROR_SUCCESS)
+ {
+ //_tprintf("Warning! Cannot open %s. Last error: %lu.\n", lpSubKey, GetLastError());
+ return FALSE;
+ }
+
+ if (RegQueryValueEx(hKey,
+ lpValueName,
+ NULL,
+ &dwType,
+ (LPBYTE)Buf,
+ &dwBytes) != ERROR_SUCCESS || (dwType != REG_SZ && dwType != REG_MULTI_SZ))
+ {
+ //_tprintf("Warning! Cannot query %s. Last error: %lu, type: %lu.\n", lpValueName, GetLastError(), dwType);
+ dwBytes = 0;
+ bRet = FALSE;
+ }
+
+ /* Close key if we opened it */
+ if (lpSubKey)
+ RegCloseKey(hKey);
+
+ /* NULL-terminate string */
+ Buf[min(BUFFER_SIZE-1, dwBytes/sizeof(TCHAR))] = TEXT('\0');
+
+ return bRet;
+}
+
+static
+BOOL
+RegGetDWORD(HKEY hKey, LPCTSTR lpSubKey, LPCTSTR lpValueName, LPDWORD lpData)
+{
+ DWORD dwBytes = sizeof(*lpData), dwType;
+ BOOL bRet = TRUE;
+
+ /* If SubKy is specified open it */
+ if (lpSubKey && RegOpenKeyEx(hKey,
+ lpSubKey,
+ 0,
+ KEY_QUERY_VALUE,
+ &hKey) != ERROR_SUCCESS)
+ {
+ return FALSE;
+ }
+
+ if (RegQueryValueEx(hKey,
+ lpValueName,
+ NULL,
+ &dwType,
+ (LPBYTE)lpData,
+ &dwBytes) != ERROR_SUCCESS || dwType != REG_DWORD)
+ {
+ //_tprintf("Warning! Cannot query %s. Last err: %lu, type: %lu\n", lpValueName, GetLastError(), dwType);
+ *lpData = 0;
+ bRet = FALSE;
+ }
+
+ /* Close key if we opened it */
+ if (lpSubKey)
+ RegCloseKey(hKey);
+
+ return bRet;
+}
+
+static
+void
+FormatBytes(LPTSTR Buf, unsigned cBytes)
+{
+ TCHAR szMB[32], Tmp[BUFFER_SIZE];
+ NUMBERFMT fmt;
+
+ itoa(cBytes / (1024*1024), szMB, 10);
+
+ fmt.NumDigits = 0;
+ fmt.LeadingZero = 0;
+ fmt.Grouping = 3;
+ fmt.lpDecimalSep = TEXT("");
+ fmt.lpThousandSep = TEXT(" ");
+ fmt.NegativeOrder = 0;
+ if(!GetNumberFormat(LOCALE_SYSTEM_DEFAULT, 0, szMB, &fmt, Tmp, BUFFER_SIZE))
+ printf("Error! GetNumberFormat failed.\n");
+
+ CharToOem(Tmp, Buf);
+}
+
+static
+void
+FormatDateTime(time_t Time, LPTSTR lpBuf)
+{
+ unsigned cchBuf = BUFFER_SIZE, i;
+ SYSTEMTIME SysTime;
+ const struct tm *lpTm;
+
+ lpTm = localtime(&Time);
+ SysTime.wYear = (WORD)(1900 + lpTm->tm_year);
+ SysTime.wMonth = (WORD)(1 + lpTm->tm_mon);
+ SysTime.wDayOfWeek = (WORD)lpTm->tm_wday;
+ SysTime.wDay = (WORD)lpTm->tm_mday;
+ SysTime.wHour = (WORD)lpTm->tm_hour;
+ SysTime.wMinute = (WORD)lpTm->tm_min;
+ SysTime.wSecond = (WORD)lpTm->tm_sec;
+ SysTime.wMilliseconds = 0;
+
+ i = GetDateFormat(LOCALE_SYSTEM_DEFAULT, 0, &SysTime, NULL, lpBuf, cchBuf);
+ if (i)
+ --i; /* don't count NULL character */
+ i += _stprintf(lpBuf + i, TEXT(", "));
+ GetTimeFormat(LOCALE_SYSTEM_DEFAULT, 0, &SysTime, NULL, lpBuf + i, cchBuf - i);