/* * 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 */ #include "sysinfo.hpp" #include "win32/windows.hpp" #include "win32/except.hpp" #include /////////////////////////////////////////////////////////////////////////////// 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; } { MEMORYSTATUSEX status {}; status.dwLength = sizeof (status); if (!GlobalMemoryStatusEx (&status)) win32::error::throw_code (); os << ", ram: { total: " << status.ullTotalPhys << ", available: " << status.ullAvailPhys << " },"; }; return os << " }"; }