[SYSTEMINFO] Do some code lift-up; use Conutils lib to be able to display localized unicode strings

In particular:
- unhardcode buffer sizes and API flags;
- add our standard file header in the .c file (I haven't done it for
  the other files);
- merge systeminfo.rc and rsrc.rc together.
This commit is contained in:
Hermès Bélusca-Maïto 2025-06-29 23:01:44 +02:00
parent dc7c7fb9f5
commit 12e01218ad
No known key found for this signature in database
GPG key ID: 3B2539C65E7B93D0
4 changed files with 212 additions and 219 deletions

View file

@ -1,9 +1,10 @@
include_directories(
${REACTOS_SOURCE_DIR}/sdk/lib/conutils
${REACTOS_SOURCE_DIR}/sdk/lib/udmihelp)
add_executable(systeminfo systeminfo.c systeminfo.rc)
set_module_type(systeminfo win32cui)
target_link_libraries(systeminfo udmihelp)
set_module_type(systeminfo win32cui UNICODE)
target_link_libraries(systeminfo conutils udmihelp ${PSEH_LIB})
add_importlibs(systeminfo user32 advapi32 netapi32 shlwapi iphlpapi ws2_32 msvcrt kernel32 ntdll)
add_cd_file(TARGET systeminfo DESTINATION reactos/system32 FOR all)

View file

@ -1,50 +0,0 @@
#include <windows.h>
#include "resource.h"
LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
/* UTF-8 */
#pragma code_page(65001)
#ifdef LANGUAGE_DE_DE
#include "lang/de-DE.rc"
#endif
#ifdef LANGUAGE_EN_US
#include "lang/en-US.rc"
#endif
#ifdef LANGUAGE_ES_ES
#include "lang/es-ES.rc"
#endif
#ifdef LANGUAGE_FR_FR
#include "lang/fr-FR.rc"
#endif
#ifdef LANGUAGE_IT_IT
#include "lang/it-IT.rc"
#endif
#ifdef LANGUAGE_JA_JP
#include "lang/ja-JP.rc"
#endif
#ifdef LANGUAGE_NO_NO
#include "lang/no-NO.rc"
#endif
#ifdef LANGUAGE_PL_PL
#include "lang/pl-PL.rc"
#endif
#ifdef LANGUAGE_RO_RO
#include "lang/ro-RO.rc"
#endif
#ifdef LANGUAGE_SK_SK
#include "lang/sk-SK.rc"
#endif
#ifdef LANGUAGE_TR_TR
#include "lang/tr-TR.rc"
#endif
#ifdef LANGUAGE_UK_UA
#include "lang/uk-UA.rc"
#endif
#ifdef LANGUAGE_ZH_CN
#include "lang/zh-CN.rc"
#endif
#ifdef LANGUAGE_ZH_TW
#include "lang/zh-TW.rc"
#endif

View file

@ -1,20 +1,11 @@
/*
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/* Copyright (C) 2007, Dmitry Chapyshev <lentind@yandex.ru> */
/* Copyright (C) 2011, Rafal Harabien <rafalh1992@o2.pl> */
* PROJECT: ReactOS SystemInfo Command
* LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
* PURPOSE: Displays system information.
* COPYRIGHT: Copyright 2007 Dmitry Chapyshev <lentind@yandex.ru>
* Copyright 2011 Rafal Harabien <rafalh1992@o2.pl>
* Copyright 2018 Stanislav Motylkov <x86corez@gmail.com>
*/
#include <wchar.h>
#include <stdio.h>
@ -28,6 +19,7 @@
#include <iphlpapi.h>
#include <winsock2.h>
#include <udmihelp.h>
#include <conutils.h>
#include "resource.h"
@ -35,11 +27,11 @@
/* Load string from registry */
static
unsigned
UINT
RegGetSZ(HKEY hKey, LPCWSTR lpSubKey, LPCWSTR lpValueName, LPWSTR lpBuf, DWORD cchBuf)
{
DWORD dwBytes = cchBuf*sizeof(WCHAR), dwType = 0;
unsigned cChars;
DWORD dwBytes = cchBuf * sizeof(WCHAR), dwType = 0;
UINT cChars;
/* If SubKey is specified open it */
if (lpSubKey && RegOpenKeyExW(hKey,
@ -48,7 +40,8 @@ RegGetSZ(HKEY hKey, LPCWSTR lpSubKey, LPCWSTR lpValueName, LPWSTR lpBuf, DWORD c
KEY_QUERY_VALUE,
&hKey) != ERROR_SUCCESS)
{
wprintf(L"Warning! Cannot open %s. Last error: %lu.\n", lpSubKey, GetLastError());
ConPrintf(StdErr, L"Warning! Cannot open %s. Last error: %lu.\n",
lpSubKey, GetLastError());
return 0;
}
@ -58,15 +51,17 @@ RegGetSZ(HKEY hKey, LPCWSTR lpSubKey, LPCWSTR lpValueName, LPWSTR lpBuf, DWORD c
NULL,
&dwType,
(LPBYTE)lpBuf,
&dwBytes) != ERROR_SUCCESS || (dwType != REG_SZ && dwType != REG_MULTI_SZ))
&dwBytes) != ERROR_SUCCESS ||
(dwType != REG_SZ && dwType != REG_MULTI_SZ))
{
wprintf(L"Warning! Cannot query %s. Last error: %lu, type: %lu.\n", lpValueName, GetLastError(), dwType);
ConPrintf(StdErr, L"Warning! Cannot query %s. Last error: %lu, type: %lu.\n",
lpValueName, GetLastError(), dwType);
dwBytes = 0;
}
else if (dwBytes == 0)
{
wcscpy(lpBuf, L"N/A");
dwBytes = 6;
dwBytes = sizeof(L"N/A")-sizeof(WCHAR);
}
/* Close key if we opened it */
@ -79,7 +74,7 @@ RegGetSZ(HKEY hKey, LPCWSTR lpSubKey, LPCWSTR lpValueName, LPWSTR lpBuf, DWORD c
lpBuf[min(cchBuf-1, cChars)] = L'\0';
/* Don't count NULL characters */
while(cChars && !lpBuf[cChars-1])
while (cChars && !lpBuf[cChars-1])
--cChars;
return cChars;
@ -100,7 +95,8 @@ RegGetDWORD(HKEY hKey, LPCWSTR lpSubKey, LPCWSTR lpValueName, LPDWORD lpData)
KEY_QUERY_VALUE,
&hKey) != ERROR_SUCCESS)
{
wprintf(L"Warning! Cannot open %s. Last error: %lu.\n", lpSubKey, GetLastError());
ConPrintf(StdErr, L"Warning! Cannot open %s. Last error: %lu.\n",
lpSubKey, GetLastError());
return FALSE;
}
@ -112,7 +108,8 @@ RegGetDWORD(HKEY hKey, LPCWSTR lpSubKey, LPCWSTR lpValueName, LPDWORD lpData)
(LPBYTE)lpData,
&dwBytes) != ERROR_SUCCESS || dwType != REG_DWORD)
{
wprintf(L"Warning! Cannot query %s. Last err: %lu, type: %lu\n", lpValueName, GetLastError(), dwType);
ConPrintf(StdErr, L"Warning! Cannot query %s. Last err: %lu, type: %lu\n",
lpValueName, GetLastError(), dwType);
*lpData = 0;
bRet = FALSE;
}
@ -127,11 +124,11 @@ RegGetDWORD(HKEY hKey, LPCWSTR lpSubKey, LPCWSTR lpValueName, LPDWORD lpData)
/* Format bytes */
static
VOID
FormatBytes(LPWSTR lpBuf, unsigned cBytes)
FormatBytes(LPWSTR lpBuf, UINT cBytes)
{
WCHAR szMB[32];
NUMBERFMTW fmt;
unsigned i;
UINT i;
_itow(cBytes / (1024*1024), szMB, 10);
@ -153,7 +150,7 @@ static
VOID
FormatDateTime(time_t Time, LPWSTR lpBuf)
{
unsigned i;
UINT i;
SYSTEMTIME SysTime;
const struct tm *lpTm;
@ -190,33 +187,23 @@ ULONGLONG GetSecondsQPC(VOID)
ULONGLONG GetSeconds(VOID)
{
ULONGLONG (WINAPI * pGetTickCount64)(VOID);
ULONGLONG (WINAPI *pGetTickCount64)(VOID);
ULONGLONG Ticks64;
HMODULE hModule = GetModuleHandleW(L"kernel32.dll");
pGetTickCount64 = (PVOID)GetProcAddress(hModule, "GetTickCount64");
if (pGetTickCount64)
{
return pGetTickCount64() / 1000;
}
hModule = LoadLibraryW(L"kernel32_vista.dll");
if (!hModule)
{
return GetSecondsQPC();
}
pGetTickCount64 = (PVOID)GetProcAddress(hModule, "GetTickCount64");
if (pGetTickCount64)
{
Ticks64 = pGetTickCount64() / 1000;
}
else
{
Ticks64 = GetSecondsQPC();
}
FreeLibrary(hModule);
return Ticks64;
@ -227,56 +214,57 @@ static
VOID
Usage(VOID)
{
WCHAR Buf[4096];
if (LoadStringW(GetModuleHandle(NULL), IDS_USAGE, Buf, 4096))
wprintf(L"%s", Buf);
ConResPrintf(StdOut, IDS_USAGE);
}
static
VOID
PrintRow(UINT nTitleID, BOOL bIndent, LPWSTR lpFormat, ...)
{
WCHAR Buf[BUFFER_SIZE];
va_list Args;
unsigned c;
UINT c;
WCHAR Buf[BUFFER_SIZE];
if (nTitleID)
{
c = LoadStringW(GetModuleHandle(NULL), nTitleID, Buf, BUFFER_SIZE - 2);
c = LoadStringW(GetModuleHandle(NULL), nTitleID, Buf, _countof(Buf) - 2);
if (!c)
return;
wcscpy(Buf + c, L": ");
} else
}
else
{
Buf[0] = L'\0';
}
if (!bIndent)
wprintf(L"%-32s", Buf);
ConPrintf(StdOut, L"%-32s", Buf);
else if (Buf[0])
wprintf(L"%38s%-16s", L"", Buf);
ConPrintf(StdOut, L"%38s%-16s", L"", Buf);
else
wprintf(L"%38s", L"");
ConPrintf(StdOut, L"%38s", L"");
va_start(Args, lpFormat);
vwprintf(lpFormat, Args);
ConPrintfV(StdOut, lpFormat, Args);
va_end(Args);
wprintf(L"\n");
ConPuts(StdOut, L"\n");
}
/* Print all system information */
VOID
AllSysInfo(VOID)
{
DWORD dwCharCount = BUFFER_SIZE, dwTimestamp, dwResult;
DWORD dwCharCount, dwTimestamp, dwResult;
OSVERSIONINFOW VersionInfo;
SYSTEM_INFO SysInfo;
WCHAR Buf[BUFFER_SIZE], Tmp[BUFFER_SIZE], szSystemDir[MAX_PATH];
const WCHAR *lpcszSysType;
LPCWSTR lpcszSysType;
LPWSTR lpBuffer;
NETSETUP_JOIN_STATUS NetJoinStatus;
MEMORYSTATUS MemoryStatus;
unsigned int cSeconds, i, j;
UINT cSeconds, i, j;
TIME_ZONE_INFORMATION TimeZoneInfo;
HKEY hKey;
PIP_ADAPTER_ADDRESSES pAdapters;
@ -284,42 +272,42 @@ AllSysInfo(VOID)
PVOID SMBiosBuf;
PCHAR DmiStrings[ID_STRINGS_MAX] = { 0 };
if (!GetSystemDirectoryW(szSystemDir, sizeof(szSystemDir)/sizeof(szSystemDir[0])))
if (!GetSystemDirectoryW(szSystemDir, _countof(szSystemDir)))
{
wprintf(L"Error! GetSystemDirectory failed.\n");
ConPrintf(StdErr, L"Error! GetSystemDirectory failed.\n");
return;
}
GetSystemInfo(&SysInfo);
// getting computer name
dwCharCount = BUFFER_SIZE;
/* Getting computer name */
dwCharCount = _countof(Buf);
if (!GetComputerNameW(Buf, &dwCharCount))
wprintf(L"Error! GetComputerName failed.\n");
ConPrintf(StdErr, L"Error! GetComputerName failed.\n");
else
PrintRow(IDS_HOST_NAME, FALSE, L"%s", Buf);
// open CurrentVersion key
if(RegOpenKeyExW(HKEY_LOCAL_MACHINE,
L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion",
0,
KEY_QUERY_VALUE,
&hKey) != ERROR_SUCCESS)
/* Open CurrentVersion key */
if (RegOpenKeyExW(HKEY_LOCAL_MACHINE,
L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion",
0,
KEY_QUERY_VALUE,
&hKey) != ERROR_SUCCESS)
{
wprintf(L"Error! RegOpenKeyEx failed.\n");
ConPrintf(StdErr, L"Error! RegOpenKeyEx failed.\n");
return;
}
//getting OS Name
RegGetSZ(hKey, NULL, L"ProductName", Buf, BUFFER_SIZE);
/* Getting OS Name */
RegGetSZ(hKey, NULL, L"ProductName", Buf, _countof(Buf));
PrintRow(IDS_OS_NAME, FALSE, L"%s", Buf);
//getting OS Version
/* Getting OS Version */
ZeroMemory(&VersionInfo, sizeof(VersionInfo));
VersionInfo.dwOSVersionInfoSize = sizeof(VersionInfo);
GetVersionExW(&VersionInfo);
if (!LoadStringW(GetModuleHandle(NULL), IDS_BUILD, Tmp, BUFFER_SIZE))
if (!LoadStringW(GetModuleHandle(NULL), IDS_BUILD, Tmp, _countof(Tmp)))
Tmp[0] = L'\0';
PrintRow(IDS_OS_VERSION,
FALSE,
@ -331,51 +319,53 @@ AllSysInfo(VOID)
Tmp,
VersionInfo.dwBuildNumber);
//getting OS Manufacturer
/* Getting OS Manufacturer */
//getting OS Configuration
/* Getting OS Configuration */
//getting OS Build Type
RegGetSZ(hKey, NULL, L"CurrentType", Buf, BUFFER_SIZE);
/* Getting OS Build Type */
RegGetSZ(hKey, NULL, L"CurrentType", Buf, _countof(Buf));
PrintRow(IDS_OS_BUILD_TYPE, FALSE, L"%s", Buf);
//getting Registered Owner
RegGetSZ(hKey, NULL, L"RegisteredOwner", Buf, BUFFER_SIZE);
/* Getting Registered Owner */
RegGetSZ(hKey, NULL, L"RegisteredOwner", Buf, _countof(Buf));
PrintRow(IDS_REG_OWNER, FALSE, L"%s", Buf);
//getting Registered Organization
RegGetSZ(hKey, NULL, L"RegisteredOrganization", Buf, BUFFER_SIZE);
/* Getting Registered Organization */
RegGetSZ(hKey, NULL, L"RegisteredOrganization", Buf, _countof(Buf));
PrintRow(IDS_REG_ORG, FALSE, L"%s", Buf);
//getting Product ID
RegGetSZ(hKey, NULL, L"ProductId", Buf, BUFFER_SIZE);
/* Getting Product ID */
RegGetSZ(hKey, NULL, L"ProductId", Buf, _countof(Buf));
PrintRow(IDS_PRODUCT_ID, FALSE, L"%s", Buf);
//getting Install Date
/* Getting Install Date */
RegGetDWORD(hKey, NULL, L"InstallDate", &dwTimestamp);
FormatDateTime((time_t)dwTimestamp, Buf);
PrintRow(IDS_INST_DATE, FALSE, L"%s", Buf);
// close Current Version key now
/* Close Current Version key now */
RegCloseKey(hKey);
//getting System Up Time
/* Getting System Up Time */
cSeconds = GetSeconds();
if (!LoadStringW(GetModuleHandle(NULL), IDS_UP_TIME_FORMAT, Tmp, BUFFER_SIZE))
if (!LoadStringW(GetModuleHandle(NULL), IDS_UP_TIME_FORMAT, Tmp, _countof(Tmp)))
Tmp[0] = L'\0';
swprintf(Buf, Tmp, cSeconds / (60*60*24), (cSeconds / (60*60)) % 24, (cSeconds / 60) % 60, cSeconds % 60);
PrintRow(IDS_UP_TIME, FALSE, L"%s", Buf);
// prepare SMBIOS data
/* Prepare SMBIOS data */
SMBiosBuf = LoadSMBiosData(DmiStrings);
//getting System Manufacturer; HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\OEMInformation\Manufacturer for Win >= 6.0
/* Getting System Manufacturer;
* HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\OEMInformation\Manufacturer
* for Win >= 6.0 */
swprintf(Tmp, L"%s\\oeminfo.ini", szSystemDir);
GetPrivateProfileStringW(L"General",
L"Manufacturer",
L"",
Buf,
sizeof(Buf)/sizeof(Buf[0]),
_countof(Buf),
Tmp);
if (wcslen(Buf) == 0 && SMBiosBuf)
{
@ -383,12 +373,14 @@ AllSysInfo(VOID)
}
PrintRow(IDS_SYS_MANUFACTURER, FALSE, L"%s", Buf);
//getting System Model; HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\OEMInformation\Model for Win >= 6.0
/* Getting System Model;
* HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\OEMInformation\Model
* for Win >= 6.0 */
GetPrivateProfileStringW(L"General",
L"Model",
L"",
Buf,
sizeof(Buf)/sizeof(Buf[0]),
_countof(Buf),
Tmp);
if (wcslen(Buf) == 0 && SMBiosBuf)
{
@ -396,7 +388,7 @@ AllSysInfo(VOID)
}
PrintRow(IDS_SYS_MODEL, FALSE, L"%s", Buf);
//getting System type
/* Getting System type */
switch (SysInfo.wProcessorArchitecture)
{
case PROCESSOR_ARCHITECTURE_INTEL:
@ -414,34 +406,34 @@ AllSysInfo(VOID)
}
PrintRow(IDS_SYS_TYPE, FALSE, L"%s", lpcszSysType);
//getting Processor(s)
if (!LoadStringW(GetModuleHandle(NULL), IDS_PROCESSORS_FORMAT, Tmp, BUFFER_SIZE))
/* Getting Processor(s) */
if (!LoadStringW(GetModuleHandle(NULL), IDS_PROCESSORS_FORMAT, Tmp, _countof(Tmp)))
Tmp[0] = L'\0';
swprintf(Buf, Tmp, (unsigned)SysInfo.dwNumberOfProcessors);
swprintf(Buf, Tmp, (UINT)SysInfo.dwNumberOfProcessors);
PrintRow(IDS_PROCESSORS, FALSE, L"%s", Buf);
for(i = 0; i < (unsigned int)SysInfo.dwNumberOfProcessors; i++)
for (i = 0; i < (UINT)SysInfo.dwNumberOfProcessors; i++)
{
swprintf(Tmp, L"HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\%u", i);
j = swprintf(Buf, L"[%02u]: ", i + 1);
j += RegGetSZ(HKEY_LOCAL_MACHINE, Tmp, L"Identifier", Buf + j, BUFFER_SIZE - j);
if(j + 1 < BUFFER_SIZE)
j += RegGetSZ(HKEY_LOCAL_MACHINE, Tmp, L"Identifier", Buf + j, _countof(Buf) - j);
if (j + 1 < _countof(Buf))
Buf[j++] = L' ';
RegGetSZ(HKEY_LOCAL_MACHINE, Tmp, L"VendorIdentifier", Buf + j, BUFFER_SIZE - j);
RegGetSZ(HKEY_LOCAL_MACHINE, Tmp, L"VendorIdentifier", Buf + j, _countof(Buf) - j);
PrintRow(0, FALSE, L"%s", Buf);
}
//getting BIOS Version
/* Getting BIOS Version */
if (SMBiosBuf)
{
j = GetSMBiosStringW(DmiStrings[BIOS_VENDOR], Buf, BUFFER_SIZE, TRUE);
if (j + 1 < BUFFER_SIZE)
j = GetSMBiosStringW(DmiStrings[BIOS_VENDOR], Buf, _countof(Buf), TRUE);
if (j + 1 < _countof(Buf))
{
Buf[j++] = L' ';
Buf[j] = L'\0';
}
GetSMBiosStringW(DmiStrings[BIOS_VERSION], Buf + j, BUFFER_SIZE - j, TRUE);
GetSMBiosStringW(DmiStrings[BIOS_VERSION], Buf + j, _countof(Buf) - j, TRUE);
}
else
{
@ -449,14 +441,14 @@ AllSysInfo(VOID)
L"HARDWARE\\DESCRIPTION\\System",
L"SystemBiosVersion",
Buf,
BUFFER_SIZE);
_countof(Buf));
}
PrintRow(IDS_BIOS_VERSION, FALSE, L"%s", Buf);
//gettings BIOS date
/* Getting BIOS date */
if (SMBiosBuf)
{
GetSMBiosStringW(DmiStrings[BIOS_DATE], Buf, BUFFER_SIZE, TRUE);
GetSMBiosStringW(DmiStrings[BIOS_DATE], Buf, _countof(Buf), TRUE);
}
else
{
@ -464,87 +456,90 @@ AllSysInfo(VOID)
L"HARDWARE\\DESCRIPTION\\System",
L"SystemBiosDate",
Buf,
BUFFER_SIZE);
_countof(Buf));
}
PrintRow(IDS_BIOS_DATE, FALSE, L"%s", Buf);
// clean SMBIOS data
/* Clean SMBIOS data */
FreeSMBiosData(SMBiosBuf);
//getting ReactOS Directory
if (!GetWindowsDirectoryW(Buf, BUFFER_SIZE))
wprintf(L"Error! GetWindowsDirectory failed.");
/* Getting ReactOS Directory */
if (!GetWindowsDirectoryW(Buf, _countof(Buf)))
ConPrintf(StdErr, L"Error! GetWindowsDirectory failed.");
else
PrintRow(IDS_ROS_DIR, FALSE, L"%s", Buf);
//getting System Directory
/* Getting System Directory */
PrintRow(IDS_SYS_DIR, 0, L"%s", szSystemDir);
//getting Boot Device
/* Getting Boot Device */
RegGetSZ(HKEY_LOCAL_MACHINE,
L"SYSTEM\\Setup",
L"SystemPartition",
Buf,
BUFFER_SIZE);
_countof(Buf));
PrintRow(IDS_BOOT_DEV, FALSE, L"%s", Buf);
//getting System Locale
if (GetLocaleInfoW(LOCALE_SYSTEM_DEFAULT, LOCALE_ILANGUAGE, Tmp, BUFFER_SIZE))
/* Getting System Locale */
if (GetLocaleInfoW(LOCALE_SYSTEM_DEFAULT, LOCALE_ILANGUAGE, Tmp, _countof(Tmp)))
{
if (RegGetSZ(HKEY_CLASSES_ROOT,
L"MIME\\Database\\Rfc1766",
Tmp,
Buf,
BUFFER_SIZE))
_countof(Buf)))
{
/* get rid of @filename,resource */
/* Get rid of @filename,resource */
lpBuffer = wcschr(Buf, L';');
if (lpBuffer)
SHLoadIndirectString(lpBuffer+1, lpBuffer+1, BUFFER_SIZE - (lpBuffer-Buf) - 1, NULL);
SHLoadIndirectString(lpBuffer+1, lpBuffer+1, _countof(Buf) - (lpBuffer-Buf) - 1, NULL);
PrintRow(IDS_SYS_LOCALE, FALSE, L"%s", Buf);
}
}
//getting Input Locale
/* Getting Input Locale */
if (RegGetSZ(HKEY_CURRENT_USER,
L"Keyboard Layout\\Preload",
L"1",
Tmp,
BUFFER_SIZE) && wcslen(Tmp) > 4)
_countof(Tmp)) && wcslen(Tmp) > 4)
{
if (RegGetSZ(HKEY_CLASSES_ROOT,
L"MIME\\Database\\Rfc1766",
Tmp + 4,
Buf,
BUFFER_SIZE))
_countof(Buf)))
{
/* get rid of @filename,resource */
/* Get rid of @filename,resource */
lpBuffer = wcschr(Buf, L';');
if (lpBuffer)
SHLoadIndirectString(lpBuffer+1, lpBuffer+1, BUFFER_SIZE - (lpBuffer-Buf) - 1, NULL);
SHLoadIndirectString(lpBuffer+1, lpBuffer+1, _countof(Buf) - (lpBuffer-Buf) - 1, NULL);
PrintRow(IDS_INPUT_LOCALE, FALSE, L"%s", Buf);
}
}
//getting Time Zone
/* Getting Time Zone */
GetTimeZoneInformation(&TimeZoneInfo);
/* Open Time Zones key */
if(RegOpenKeyExW(HKEY_LOCAL_MACHINE,
L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones",
0,
KEY_ENUMERATE_SUB_KEYS|KEY_READ,
&hKey) == ERROR_SUCCESS)
if (RegOpenKeyExW(HKEY_LOCAL_MACHINE,
L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones",
0,
KEY_ENUMERATE_SUB_KEYS|KEY_READ,
&hKey) == ERROR_SUCCESS)
{
unsigned i;
/* Find current timezone */
dwCharCount = BUFFER_SIZE;
for(i = 0; RegEnumKeyExW(hKey, i, Tmp, &dwCharCount, NULL, NULL, NULL, NULL) == ERROR_SUCCESS; ++i, dwCharCount = 255)
UINT i;
dwCharCount = _countof(Tmp);
for (i = 0; RegEnumKeyExW(hKey, i, Tmp, &dwCharCount, NULL, NULL, NULL, NULL) == ERROR_SUCCESS; ++i, dwCharCount = 255)
{
RegGetSZ(hKey, Tmp, L"Std", Buf, BUFFER_SIZE);
RegGetSZ(hKey, Tmp, L"Std", Buf, _countof(Buf));
if (!wcscmp(Buf, TimeZoneInfo.StandardName))
{
RegGetSZ(hKey, Tmp, L"Display", Buf, BUFFER_SIZE);
RegGetSZ(hKey, Tmp, L"Display", Buf, _countof(Buf));
PrintRow(IDS_TIME_ZONE, FALSE, L"%s", Buf);
@ -554,37 +549,36 @@ AllSysInfo(VOID)
RegCloseKey(hKey);
}
//getting Total Physical Memory
/* Getting Total Physical Memory */
GlobalMemoryStatus(&MemoryStatus);
FormatBytes(Buf, MemoryStatus.dwTotalPhys);
PrintRow(IDS_TOTAL_PHYS_MEM, FALSE, L"%s", Buf);
//getting Available Physical Memory
/* Getting Available Physical Memory */
FormatBytes(Buf, MemoryStatus.dwAvailPhys);
PrintRow(IDS_AVAIL_PHISICAL_MEM, FALSE, L"%s", Buf);
//getting Virtual Memory: Max Size
/* Getting Virtual Memory: Max Size */
FormatBytes(Buf, MemoryStatus.dwTotalVirtual);
PrintRow(IDS_VIRT_MEM_MAX, FALSE, L"%s", Buf);
//getting Virtual Memory: Available
/* Getting Virtual Memory: Available */
FormatBytes(Buf, MemoryStatus.dwAvailVirtual);
PrintRow(IDS_VIRT_MEM_AVAIL, FALSE, L"%s", Buf);
//getting Virtual Memory: In Use
/* Getting Virtual Memory: In Use */
FormatBytes(Buf, MemoryStatus.dwTotalVirtual-MemoryStatus.dwAvailVirtual);
PrintRow(IDS_VIRT_MEM_INUSE, FALSE, L"%s", Buf);
//getting Page File Location(s)
/* Getting Page File Location(s) */
if (RegGetSZ(HKEY_LOCAL_MACHINE,
L"SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Memory Management",
L"PagingFiles",
Buf,
BUFFER_SIZE))
_countof(Buf)))
{
int i;
for(i = 0; Buf[i]; i++)
UINT i;
for (i = 0; Buf[i]; i++)
{
if (Buf[i] == L' ')
{
@ -596,7 +590,7 @@ AllSysInfo(VOID)
PrintRow(IDS_PAGEFILE_LOC, FALSE, L"%s", Buf);
}
//getting Domain
/* Getting Domain */
if (NetGetJoinInformation (NULL, &lpBuffer, &NetJoinStatus) == NERR_Success)
{
if (NetJoinStatus == NetSetupWorkgroupName || NetJoinStatus == NetSetupDomainName)
@ -605,12 +599,12 @@ AllSysInfo(VOID)
NetApiBufferFree(lpBuffer);
}
//getting Logon Server
/* Getting Logon Server */
//getting NetWork Card(s)
/* Getting NetWork Card(s) */
cbAdapters = 4096;
pAdapters = malloc(cbAdapters);
while((dwResult = GetAdaptersAddresses(AF_UNSPEC, 0x0002, NULL, pAdapters, &cbAdapters)) == ERROR_BUFFER_OVERFLOW)
while ((dwResult = GetAdaptersAddresses(AF_UNSPEC, GAA_FLAG_SKIP_ANYCAST, NULL, pAdapters, &cbAdapters)) == ERROR_BUFFER_OVERFLOW)
{
cbAdapters += 4096;
pAdapters = (PIP_ADAPTER_ADDRESSES)realloc(pAdapters, cbAdapters);
@ -619,54 +613,53 @@ AllSysInfo(VOID)
if (dwResult == ERROR_SUCCESS)
{
PIP_ADAPTER_ADDRESSES pCurrentAdapter = pAdapters;
unsigned cAdapters = 0;
UINT cAdapters = 0;
/* Count adapters */
for(i = 0; pCurrentAdapter; ++i)
for (i = 0; pCurrentAdapter; ++i)
{
if (pCurrentAdapter->IfType != 24 && pCurrentAdapter->IfType != 131)
if (pCurrentAdapter->IfType != IF_TYPE_SOFTWARE_LOOPBACK && pCurrentAdapter->IfType != IF_TYPE_TUNNEL)
++cAdapters;
pCurrentAdapter = pCurrentAdapter->Next;
}
/* Print adapters count */
if (!LoadStringW(GetModuleHandle(NULL), IDS_NETWORK_CARDS_FORMAT, Tmp, BUFFER_SIZE))
if (!LoadStringW(GetModuleHandle(NULL), IDS_NETWORK_CARDS_FORMAT, Tmp, _countof(Tmp)))
Tmp[0] = L'\0';
swprintf(Buf, Tmp, cAdapters);
PrintRow(IDS_NETWORK_CARDS, FALSE, L"%s", Buf);
/* Show information about each adapter */
pCurrentAdapter = pAdapters;
for(i = 0; pCurrentAdapter; ++i)
for (i = 0; pCurrentAdapter; ++i)
{
if (pCurrentAdapter->IfType != 24 && pCurrentAdapter->IfType != 131)//IF_TYPE_SOFTWARE_LOOPBACK)
if (pCurrentAdapter->IfType != IF_TYPE_SOFTWARE_LOOPBACK && pCurrentAdapter->IfType != IF_TYPE_TUNNEL)
{
PIP_ADAPTER_UNICAST_ADDRESS pAddress;
PrintRow(0, FALSE, L"[%02u]: %s", i + 1, pCurrentAdapter->Description);
PrintRow(IDS_CONNECTION_NAME, TRUE, L"%s", pCurrentAdapter->FriendlyName);
if (!(pCurrentAdapter->Flags & 0x0004))
if (!(pCurrentAdapter->Flags & IP_ADAPTER_DHCP_ENABLED))
{
if (!LoadStringW(GetModuleHandle(NULL), IDS_NO, Buf, BUFFER_SIZE))
if (!LoadStringW(GetModuleHandle(NULL), IDS_NO, Buf, _countof(Buf)))
Buf[0] = L'\0';
PrintRow(IDS_DHCP_ENABLED, TRUE, Buf);
}
if (pCurrentAdapter->OperStatus == IfOperStatusDown)
{
if (!LoadStringW(GetModuleHandle(NULL), IDS_MEDIA_DISCONNECTED, Buf, BUFFER_SIZE))
if (!LoadStringW(GetModuleHandle(NULL), IDS_MEDIA_DISCONNECTED, Buf, _countof(Buf)))
Buf[0] = L'\0';
PrintRow(IDS_STATUS, TRUE, Buf);
}
else
{
if (!LoadStringW(GetModuleHandle(NULL), IDS_IP_ADDRESSES, Buf, BUFFER_SIZE))
if (!LoadStringW(GetModuleHandle(NULL), IDS_IP_ADDRESSES, Buf, _countof(Buf)))
Buf[0] = L'\0';
PrintRow(0, TRUE, Buf);
pAddress = pCurrentAdapter->FirstUnicastAddress;
for (j = 0; pAddress; ++j)
{
dwCharCount = BUFFER_SIZE;
dwCharCount = _countof(Buf);
WSAAddressToStringW(pAddress->Address.lpSockaddr, pAddress->Address.iSockaddrLength, NULL, Buf, &dwCharCount);
PrintRow(0, TRUE, L"[%02u]: %s", j + 1, Buf);
pAddress = pAddress->Next;
@ -680,26 +673,26 @@ AllSysInfo(VOID)
}
/* Main program */
int
main(int argc, char *argv[])
int wmain(int argc, wchar_t *argv[])
{
WSADATA WsaData;
int i;
setlocale(LC_ALL, "");
/* Initialize the Console Standard Streams */
ConInitStdStreams();
WSAStartup(MAKEWORD(2, 2), &WsaData);
for (i = 1; i < argc; ++i)
{
if (!strcmp(argv[i], "/?") || !strcmp(argv[i], "-?"))
if (!wcscmp(argv[i], L"/?") || !wcscmp(argv[i], L"-?"))
{
Usage();
return 0;
}
else
{
printf("Unsupported argument: %s\n", argv[i]);
ConPrintf(StdErr, L"Unsupported argument: %s\n", argv[i]);
return -1;
}
}

View file

@ -1,6 +1,55 @@
#include <windef.h>
#include "resource.h"
#define REACTOS_STR_FILE_DESCRIPTION "System Information"
#define REACTOS_STR_INTERNAL_NAME "systeminfo"
#define REACTOS_STR_ORIGINAL_FILENAME "systeminfo.exe"
#include <reactos/version.rc>
#include "rsrc.rc"
LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
/* UTF-8 */
#pragma code_page(65001)
#ifdef LANGUAGE_DE_DE
#include "lang/de-DE.rc"
#endif
#ifdef LANGUAGE_EN_US
#include "lang/en-US.rc"
#endif
#ifdef LANGUAGE_ES_ES
#include "lang/es-ES.rc"
#endif
#ifdef LANGUAGE_FR_FR
#include "lang/fr-FR.rc"
#endif
#ifdef LANGUAGE_IT_IT
#include "lang/it-IT.rc"
#endif
#ifdef LANGUAGE_JA_JP
#include "lang/ja-JP.rc"
#endif
#ifdef LANGUAGE_NO_NO
#include "lang/no-NO.rc"
#endif
#ifdef LANGUAGE_PL_PL
#include "lang/pl-PL.rc"
#endif
#ifdef LANGUAGE_RO_RO
#include "lang/ro-RO.rc"
#endif
#ifdef LANGUAGE_SK_SK
#include "lang/sk-SK.rc"
#endif
#ifdef LANGUAGE_TR_TR
#include "lang/tr-TR.rc"
#endif
#ifdef LANGUAGE_UK_UA
#include "lang/uk-UA.rc"
#endif
#ifdef LANGUAGE_ZH_CN
#include "lang/zh-CN.rc"
#endif
#ifdef LANGUAGE_ZH_TW
#include "lang/zh-TW.rc"
#endif