2019-06-20 12:37:48 +10:00
|
|
|
/*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*
|
|
|
|
* Copyright 2019 Danny Robson <danny@nerdcruft.net>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "sysinfo.hpp"
|
|
|
|
|
|
|
|
#include "win32/windows.hpp"
|
|
|
|
#include "win32/except.hpp"
|
|
|
|
|
|
|
|
#include <ostream>
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
std::ostream&
|
|
|
|
cruft::util::operator<< (std::ostream &os, sysinfo const &)
|
|
|
|
{
|
|
|
|
os << "{ ";
|
|
|
|
|
|
|
|
{
|
2019-06-20 17:21:35 +10:00
|
|
|
OSVERSIONINFO version {};
|
|
|
|
version.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);
|
2019-06-20 12:37:48 +10:00
|
|
|
if (!GetVersionExA (&version))
|
|
|
|
win32::error::throw_code ();
|
|
|
|
|
2019-06-20 17:21:35 +10:00
|
|
|
os << "os: { name: win32"
|
2019-06-20 12:37:48 +10:00
|
|
|
<< ", version: " << +version.dwMajorVersion << '.'
|
|
|
|
<< +version.dwMinorVersion << '.'
|
|
|
|
<< +version.dwPlatformId
|
|
|
|
<< "}";
|
|
|
|
}
|
|
|
|
|
|
|
|
DWORD size = 0;
|
|
|
|
std::string name;
|
|
|
|
|
|
|
|
{
|
2019-06-20 17:21:35 +10:00
|
|
|
if (0 == GetComputerNameExA (ComputerNamePhysicalNetBIOS, nullptr, &size)) {
|
|
|
|
auto const code = win32::error::last_code ();
|
|
|
|
if (code != ERROR_MORE_DATA)
|
|
|
|
win32::error::throw_code (code);
|
|
|
|
}
|
2019-06-20 12:37:48 +10:00
|
|
|
name.resize (size);
|
|
|
|
|
2019-06-20 17:21:35 +10:00
|
|
|
if (0 == GetComputerNameExA (ComputerNamePhysicalNetBIOS, &name[0], &size))
|
2019-06-20 12:37:48 +10:00
|
|
|
win32::error::throw_code ();
|
2019-06-20 17:21:35 +10:00
|
|
|
name.resize (size);
|
|
|
|
|
2019-06-20 12:37:48 +10:00
|
|
|
os << ", hostname: " << name;
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
size = 0;
|
2019-06-20 17:21:35 +10:00
|
|
|
if (0 == GetUserNameA (nullptr, &size)) {
|
|
|
|
auto const code = win32::error::last_code ();
|
|
|
|
if (code != ERROR_INSUFFICIENT_BUFFER)
|
|
|
|
win32::error::throw_code (code);
|
|
|
|
|
|
|
|
}
|
2019-06-20 12:37:48 +10:00
|
|
|
name.resize (size);
|
|
|
|
|
2019-06-20 17:21:35 +10:00
|
|
|
if (0 == GetUserNameA (&name[0], &size))
|
2019-06-20 12:37:48 +10:00
|
|
|
win32::error::throw_code ();
|
2019-06-28 15:14:34 +10:00
|
|
|
// Remove the provided trailing null terminator
|
|
|
|
name.resize (size - 1);
|
2019-06-20 12:37:48 +10:00
|
|
|
|
|
|
|
os << ", username: " << name;
|
|
|
|
}
|
|
|
|
|
2019-06-20 12:50:33 +10:00
|
|
|
{
|
|
|
|
MEMORYSTATUSEX status {};
|
|
|
|
status.dwLength = sizeof (status);
|
|
|
|
|
2019-06-20 17:21:35 +10:00
|
|
|
if (0 == GlobalMemoryStatusEx (&status))
|
2019-06-20 12:50:33 +10:00
|
|
|
win32::error::throw_code ();
|
|
|
|
|
|
|
|
os << ", ram: { total: " << status.ullTotalPhys << ", available: " << status.ullAvailPhys << " },";
|
|
|
|
};
|
|
|
|
|
2019-06-20 12:37:48 +10:00
|
|
|
return os << " }";
|
|
|
|
}
|