libcruft-util/sysinfo_win32.cpp

72 lines
1.8 KiB
C++
Raw Normal View History

/*
* 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 << "{ ";
{
OSVERSIONINFO version;
if (!GetVersionExA (&version))
win32::error::throw_code ();
os << "os: { name: win32, "
<< ", version: " << +version.dwMajorVersion << '.'
<< +version.dwMinorVersion << '.'
<< +version.dwPlatformId
<< "}";
}
DWORD size = 0;
std::string name;
{
if (!GetComputerNameExA (ComputerNamePhysicalNetBIOS, nullptr, &size))
win32::error::throw_code ();
name.resize (size);
if (!GetComputerNameExA (ComputerNamePhysicalNetBIOS, &name[0], &size))
win32::error::throw_code ();
os << ", hostname: " << name;
}
{
size = 0;
if (!GetUserNameA (nullptr, &size))
win32::error::throw_code ();
name.resize (size);
if (!GetUserNameA (&name[0], &size))
win32::error::throw_code ();
os << ", username: " << name;
}
2019-06-20 12:50:33 +10:00
{
MEMORYSTATUSEX status {};
status.dwLength = sizeof (status);
if (!GlobalMemoryStatusEx (&status))
win32::error::throw_code ();
os << ", ram: { total: " << status.ullTotalPhys << ", available: " << status.ullAvailPhys << " },";
};
return os << " }";
}