From d704fdfc73f4e6ad12b389cd6237468b232e80f9 Mon Sep 17 00:00:00 2001 From: lfreist Date: Mon, 28 Nov 2022 10:18:13 +0100 Subject: [PATCH] format check --- .clang-format | 5 ++ .github/workflows/format-check.yml | 22 ++++++++ README.md | 2 + code_style_check.sh | 29 ++++++++++ include/hwinfo/WMIwrapper.h | 75 ++++++++++---------------- include/hwinfo/battery.h | 10 ++-- include/hwinfo/cpu.h | 3 +- include/hwinfo/cpuid.h | 1 - include/hwinfo/disk.h | 11 ++-- include/hwinfo/hwinfo.h | 12 ++--- include/hwinfo/mainboard.h | 13 ++--- include/hwinfo/platform.h | 2 +- include/hwinfo/ram.h | 10 ++-- include/hwinfo/system.h | 4 +- include/hwinfo/utils/stringutils.h | 45 ++++++++++------ include/hwinfo/utils/subprocess.h | 4 +- src/apple/battery.cpp | 32 +++-------- src/apple/cpu.cpp | 86 ++++++++++++++---------------- src/apple/gpu.cpp | 4 +- src/apple/mainboard.cpp | 1 - src/apple/os.cpp | 8 ++- src/apple/ram.cpp | 4 +- src/battery.cpp | 16 +++--- src/cpu.cpp | 39 ++++++-------- src/disk.cpp | 21 +++----- src/gpu.cpp | 14 ++--- src/linux/battery.cpp | 6 +-- src/linux/cpu.cpp | 76 +++++++++++++------------- src/linux/disk.cpp | 11 ++-- src/linux/gpu.cpp | 28 ++++++---- src/linux/mainboard.cpp | 9 ++-- src/linux/os.cpp | 18 +++---- src/linux/ram.cpp | 20 +++---- src/mainboard.cpp | 19 ++++--- src/os.cpp | 24 +++------ src/ram.cpp | 17 +++--- src/windows/battery.cpp | 45 ++++++---------- src/windows/cpu.cpp | 83 ++++++++++++++-------------- src/windows/disk.cpp | 16 +++--- src/windows/gpu.cpp | 2 +- src/windows/mainboard.cpp | 1 - src/windows/os.cpp | 52 +++++++++--------- src/windows/ram.cpp | 4 +- 43 files changed, 440 insertions(+), 464 deletions(-) create mode 100644 .clang-format create mode 100644 .github/workflows/format-check.yml create mode 100644 code_style_check.sh diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..ee9428c --- /dev/null +++ b/.clang-format @@ -0,0 +1,5 @@ +--- +BasedOnStyle: Google +DerivePointerAlignment: false +PointerAlignment: Left +ColumnLimit: 120 \ No newline at end of file diff --git a/.github/workflows/format-check.yml b/.github/workflows/format-check.yml new file mode 100644 index 0000000..2b087aa --- /dev/null +++ b/.github/workflows/format-check.yml @@ -0,0 +1,22 @@ +name: code-style + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +jobs: + build: + runs-on: ubuntu-22.04 + + steps: + - uses: actions/checkout@v2 + - name: Install dependencies + run: sudo apt-get install -y clang-format-14 + + - name: Run clang-format + run: | + chmod +x ./format_check.sh + ./code_style_check.sh + shell: bash \ No newline at end of file diff --git a/README.md b/README.md index 205133f..dd92e9d 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,8 @@ [![Windows (MinGW)](https://github.com/lfreist/hwinfo/actions/workflows/build-windows-mingw.yml/badge.svg)](https://github.com/lfreist/hwinfo/actions/workflows/build-windows-mingw.yml) [![Windows (Visual Studio)](https://github.com/lfreist/hwinfo/actions/workflows/build-windows-vs.yml/badge.svg)](https://github.com/lfreist/hwinfo/actions/workflows/build-windows-vs.yml) +[![clang format](https://github.com/lfreist/hwinfo/actions/workflows/format-check.yml/badge.svg)](https://github.com/lfreist/hwinfo/actions/workflows/format-check.yml) + # hwinfo hwinfo provides an easy-to-use and modern C++ API for retrieving hardware information of your systems components such as diff --git a/code_style_check.sh b/code_style_check.sh new file mode 100644 index 0000000..eba01a4 --- /dev/null +++ b/code_style_check.sh @@ -0,0 +1,29 @@ +#!/usr/bin/env bash + +printf "Checking sources for code style\n" +SOURCE_FILES=() +find ./src/ ./test/ ./include/ -regextype egrep -regex '.*\.(h|c)(pp|xx)?$' -print0 > sourcelist +while IFS= read -r -d $'\0'; do + SOURCE_FILES+=("$REPLY") +done < sourcelist + +ERROR=0 +for source in "${SOURCE_FILES[@]}"; do + clang-format-14 -output-replacements-xml "$source" | grep " /dev/null + HAS_WRONG_FILES=$? + if [ $HAS_WRONG_FILES -ne 1 ]; then + printf "Checking %s: \x1b[31mFAILED!\x1b[m\n" "$source" + ERROR=1 + else + printf "Checking %s: \x1b[32mPASSED\x1b[m\n" "$source" + fi +done + +rm sourcelist + +if [ $ERROR -eq 0 ]; then + printf "\x1b[32mCongratulations! All sources match the code style\x1b[m\n" +else + printf "\x1b[31mclang-format-14 discovered style issues in at least one file.\x1b[m\n" + exit 1 +fi \ No newline at end of file diff --git a/include/hwinfo/WMIwrapper.h b/include/hwinfo/WMIwrapper.h index 9e72adf..21863e5 100644 --- a/include/hwinfo/WMIwrapper.h +++ b/include/hwinfo/WMIwrapper.h @@ -1,28 +1,25 @@ // Copyright Leon Freist // Author Leon Freist - #if defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__) #pragma once -#include -#include -#include - +#include #include #include -#include #include + +#include +#include +#include #pragma comment(lib, "wbemuuid.lib") namespace hwinfo::wmi { -template -inline bool queryWMI(const std::string &WMIClass, - std::string field, - std::vector &value, - const std::string &serverName = "ROOT\\CIMV2") { +template +inline bool queryWMI(const std::string& WMIClass, std::string field, std::vector& value, + const std::string& serverName = "ROOT\\CIMV2") { std::string query("SELECT " + field + " FROM " + WMIClass); HRESULT hres; @@ -30,62 +27,45 @@ inline bool queryWMI(const std::string &WMIClass, if (FAILED(hres)) { return false; } - hres = CoInitializeSecurity(nullptr, - -1, - nullptr, - nullptr, - RPC_C_AUTHN_LEVEL_DEFAULT, - RPC_C_IMP_LEVEL_IMPERSONATE, - nullptr, - EOAC_NONE, - nullptr); + hres = CoInitializeSecurity(nullptr, -1, nullptr, nullptr, RPC_C_AUTHN_LEVEL_DEFAULT, RPC_C_IMP_LEVEL_IMPERSONATE, + nullptr, EOAC_NONE, nullptr); if (FAILED(hres)) { CoUninitialize(); return false; } - IWbemLocator *pLoc = nullptr; - hres = CoCreateInstance(CLSID_WbemLocator, nullptr, CLSCTX_INPROC_SERVER, IID_IWbemLocator, (LPVOID *) &pLoc); + IWbemLocator* pLoc = nullptr; + hres = CoCreateInstance(CLSID_WbemLocator, nullptr, CLSCTX_INPROC_SERVER, IID_IWbemLocator, (LPVOID*)&pLoc); if (FAILED(hres)) { CoUninitialize(); return false; } - IWbemServices *pSvc = nullptr; + IWbemServices* pSvc = nullptr; hres = pLoc->ConnectServer(_bstr_t(L"ROOT\\CIMV2"), nullptr, nullptr, nullptr, 0, nullptr, nullptr, &pSvc); if (FAILED(hres)) { pLoc->Release(); CoUninitialize(); return false; } - hres = CoSetProxyBlanket(pSvc, - RPC_C_AUTHN_WINNT, - RPC_C_AUTHZ_NONE, - nullptr, - RPC_C_AUTHN_LEVEL_CALL, - RPC_C_IMP_LEVEL_IMPERSONATE, - nullptr, - EOAC_NONE); + hres = CoSetProxyBlanket(pSvc, RPC_C_AUTHN_WINNT, RPC_C_AUTHZ_NONE, nullptr, RPC_C_AUTHN_LEVEL_CALL, + RPC_C_IMP_LEVEL_IMPERSONATE, nullptr, EOAC_NONE); if (FAILED(hres)) { pSvc->Release(); pLoc->Release(); CoUninitialize(); return false; } - IEnumWbemClassObject *pEnumerator = nullptr; - hres = pSvc->ExecQuery(bstr_t(L"WQL"), - bstr_t(std::wstring(query.begin(), query.end()).c_str()), - WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY, - nullptr, - &pEnumerator); + IEnumWbemClassObject* pEnumerator = nullptr; + hres = pSvc->ExecQuery(bstr_t(L"WQL"), bstr_t(std::wstring(query.begin(), query.end()).c_str()), + WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY, nullptr, &pEnumerator); if (FAILED(hres)) { pSvc->Release(); pLoc->Release(); CoUninitialize(); return false; } - IWbemClassObject *pclsObj = nullptr; + IWbemClassObject* pclsObj = nullptr; ULONG uReturn = 0; while (pEnumerator) { - pEnumerator->Next(WBEM_INFINITE, 1, &pclsObj, &uReturn); if (!uReturn) { @@ -96,19 +76,19 @@ inline bool queryWMI(const std::string &WMIClass, pclsObj->Get(std::wstring(field.begin(), field.end()).c_str(), 0, &vtProp, nullptr, nullptr); if (std::is_same::value || std::is_same::value) { - value.push_back((T) vtProp.intVal); + value.push_back((T)vtProp.intVal); } else if (std::is_same::value) { - value.push_back((T) vtProp.boolVal); + value.push_back((T)vtProp.boolVal); } else if (std::is_same::value) { - value.push_back((T) vtProp.uintVal); + value.push_back((T)vtProp.uintVal); } else if (std::is_same::value) { - value.push_back((T) vtProp.uiVal); + value.push_back((T)vtProp.uiVal); } else if (std::is_same::value) { - value.push_back((T) vtProp.llVal); + value.push_back((T)vtProp.llVal); } else if (std::is_same::value) { - value.push_back((T) vtProp.ullVal); + value.push_back((T)vtProp.ullVal); } else { - value.push_back((T) ((bstr_t) vtProp.bstrVal).copy()); + value.push_back((T)((bstr_t)vtProp.bstrVal).copy()); } VariantClear(&vtProp); @@ -121,8 +101,7 @@ inline bool queryWMI(const std::string &WMIClass, pSvc->Release(); pLoc->Release(); - if (pEnumerator) - pEnumerator->Release(); + if (pEnumerator) pEnumerator->Release(); CoUninitialize(); return true; } diff --git a/include/hwinfo/battery.h b/include/hwinfo/battery.h index 469a2cb..1341fb6 100644 --- a/include/hwinfo/battery.h +++ b/include/hwinfo/battery.h @@ -12,14 +12,15 @@ namespace hwinfo { class Battery { friend std::vector getAllBatteries(); + public: explicit Battery(int8_t id = 0); ~Battery() = default; - std::string &vendor(); - std::string &model(); - std::string &serialNumber(); - std::string &technology(); + std::string& vendor(); + std::string& model(); + std::string& serialNumber(); + std::string& technology(); uint32_t energyFull(); double capacity(); @@ -46,4 +47,3 @@ class Battery { std::vector getAllBatteries(); } // namespace hwinfo - diff --git a/include/hwinfo/cpu.h b/include/hwinfo/cpu.h index 1bf8d67..75b6bfd 100644 --- a/include/hwinfo/cpu.h +++ b/include/hwinfo/cpu.h @@ -3,9 +3,9 @@ #pragma once +#include #include #include -#include namespace hwinfo { @@ -24,6 +24,7 @@ struct InstructionSet { class CPU { friend std::optional getCPU(uint8_t socket_id); + public: CPU() = default; CPU(int id); diff --git a/include/hwinfo/cpuid.h b/include/hwinfo/cpuid.h index 4705849..b612ca0 100644 --- a/include/hwinfo/cpuid.h +++ b/include/hwinfo/cpuid.h @@ -26,7 +26,6 @@ #define LVL_TYPE 0x0000ff00 #define LVL_CORES 0x0000ffff - namespace hwinfo::cpuid { /** diff --git a/include/hwinfo/disk.h b/include/hwinfo/disk.h index 1cb760f..5301041 100644 --- a/include/hwinfo/disk.h +++ b/include/hwinfo/disk.h @@ -9,14 +9,15 @@ namespace hwinfo { class Disk { - friend std::vectorgetAllDisks(); + friend std::vector getAllDisks(); + public: - Disk(std::string &vendor, std::string &model, std::string &serialNumber, int64_t size_Bytes); + Disk(std::string& vendor, std::string& model, std::string& serialNumber, int64_t size_Bytes); ~Disk() = default; - [[nodiscard]] const std::string &vendor() const; - [[nodiscard]] const std::string &model() const; - [[nodiscard]] const std::string &serialNumber() const; + [[nodiscard]] const std::string& vendor() const; + [[nodiscard]] const std::string& model() const; + [[nodiscard]] const std::string& serialNumber() const; [[nodiscard]] int64_t size_Bytes() const; private: diff --git a/include/hwinfo/hwinfo.h b/include/hwinfo/hwinfo.h index 2b84502..e21039e 100644 --- a/include/hwinfo/hwinfo.h +++ b/include/hwinfo/hwinfo.h @@ -3,10 +3,10 @@ #pragma once -#include "hwinfo/cpu.h" -#include "hwinfo/ram.h" -#include "hwinfo/os.h" -#include "hwinfo/mainboard.h" -#include "hwinfo/gpu.h" -#include "hwinfo/disk.h" #include "hwinfo/battery.h" +#include "hwinfo/cpu.h" +#include "hwinfo/disk.h" +#include "hwinfo/gpu.h" +#include "hwinfo/mainboard.h" +#include "hwinfo/os.h" +#include "hwinfo/ram.h" diff --git a/include/hwinfo/mainboard.h b/include/hwinfo/mainboard.h index 903f245..666fad1 100644 --- a/include/hwinfo/mainboard.h +++ b/include/hwinfo/mainboard.h @@ -13,16 +13,13 @@ namespace hwinfo { class MainBoard { public: MainBoard() = default; - MainBoard(const std::string &vendor, - const std::string &product, - const std::string &version, - const std::string &serialNumber); + MainBoard(std::string vendor, std::string product, std::string version, std::string serialNumber); ~MainBoard() = default; - std::string &vendor(); - std::string &name(); - std::string &version(); - std::string &serialNumber(); + std::string& vendor(); + std::string& name(); + std::string& version(); + std::string& serialNumber(); static std::string getVendor(); static std::string getName(); diff --git a/include/hwinfo/platform.h b/include/hwinfo/platform.h index 62b367e..d0d8f9b 100644 --- a/include/hwinfo/platform.h +++ b/include/hwinfo/platform.h @@ -6,7 +6,7 @@ #if defined(__APPLE__) #define HWINFO_APPLE #endif -#if defined(_WIN32) || defined (_WIN64) || defined(__CYGWIN__) +#if defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__) #define HWINFO_WINDOWS #endif diff --git a/include/hwinfo/ram.h b/include/hwinfo/ram.h index 4b41d48..2045bbe 100644 --- a/include/hwinfo/ram.h +++ b/include/hwinfo/ram.h @@ -10,13 +10,13 @@ namespace hwinfo { class RAM { public: RAM() = default; - RAM(std::string &vendor, std::string &name, std::string &model, std::string &serialNumber, int64_t size_Bytes); + RAM(std::string& vendor, std::string& name, std::string& model, std::string& serialNumber, int64_t size_Bytes); ~RAM() = default; - std::string &vendor(); - std::string &name(); - std::string &model(); - std::string &serialNumber(); + std::string& vendor(); + std::string& name(); + std::string& model(); + std::string& serialNumber(); int64_t totalSize_Bytes(); static std::string getVendor(); diff --git a/include/hwinfo/system.h b/include/hwinfo/system.h index 6a51428..ff7e35c 100644 --- a/include/hwinfo/system.h +++ b/include/hwinfo/system.h @@ -7,9 +7,9 @@ #include #include "hwinfo/cpu.h" -#include "hwinfo/ram.h" -#include "hwinfo/gpu.h" #include "hwinfo/disk.h" +#include "hwinfo/gpu.h" +#include "hwinfo/ram.h" namespace hwinfo { diff --git a/include/hwinfo/utils/stringutils.h b/include/hwinfo/utils/stringutils.h index da80d3e..05a22cc 100644 --- a/include/hwinfo/utils/stringutils.h +++ b/include/hwinfo/utils/stringutils.h @@ -11,34 +11,39 @@ * @param input */ inline void strip(std::string& input) { - if (input.empty()) { return; } + if (input.empty()) { + return; + } // optimization for input size == 1 if (input.size() == 1) { if (input[0] == ' ' || input[0] == '\t' || input[0] == '\n') { input = ""; return; - } - else { + } else { return; } } size_t start_index = 0; while (true) { char c = input[start_index]; - if (c != ' ' && c != '\t' && c != '\n') { break; } + if (c != ' ' && c != '\t' && c != '\n') { + break; + } start_index++; } size_t end_index = input.size() - 1; while (true) { char c = input[end_index]; - if (c != ' ' && c != '\t' && c != '\n') { break; } + if (c != ' ' && c != '\t' && c != '\n') { + break; + } end_index--; } if (end_index <= start_index) { input.assign(""); return; } - input.assign(input.begin()+start_index, input.begin()+end_index+1); + input.assign(input.begin() + start_index, input.begin() + end_index + 1); } /** @@ -66,10 +71,12 @@ inline unsigned count_substring(const std::string& input, const std::string& sub inline std::vector split(const std::string& input, const std::string& delimiter) { std::vector result; size_t shift = 0; - while(true) { + while (true) { size_t match = input.find(delimiter, shift); - result.emplace_back(input.substr(shift, match-shift)); - if (match == std::string::npos) { break; } + result.emplace_back(input.substr(shift, match - shift)); + if (match == std::string::npos) { + break; + } shift = match + delimiter.size(); } return result; @@ -84,10 +91,12 @@ inline std::vector split(const std::string& input, const std::strin inline std::vector split(const std::string& input, const char delimiter) { std::vector result; size_t shift = 0; - while(true) { + while (true) { size_t match = input.find(delimiter, shift); - if (match == std::string::npos) { break; } - result.emplace_back(input.substr(shift, match-shift)); + if (match == std::string::npos) { + break; + } + result.emplace_back(input.substr(shift, match - shift)); shift = match + 1; } return result; @@ -104,11 +113,15 @@ inline std::vector split(const std::string& input, const char delim inline std::string split_get_index(const std::string& input, const std::string& delimiter, int index) { unsigned occ = count_substring(input, delimiter) + 1; index = index < 0 ? static_cast(occ + index) : index; - if (occ <= index) { return ""; } + if (occ <= index) { + return ""; + } std::string::size_type start_index = 0; while (true) { - if (index == 0) { break; } + if (index == 0) { + break; + } start_index = input.find(delimiter, start_index) + delimiter.size(); index--; } @@ -123,6 +136,4 @@ inline std::string split_get_index(const std::string& input, const std::string& * Convert windows wstring to string * @return */ -inline std::string wstring_to_string() { - return ""; -} \ No newline at end of file +inline std::string wstring_to_string() { return ""; } \ No newline at end of file diff --git a/include/hwinfo/utils/subprocess.h b/include/hwinfo/utils/subprocess.h index eeaeb8f..d29c264 100644 --- a/include/hwinfo/utils/subprocess.h +++ b/include/hwinfo/utils/subprocess.h @@ -4,10 +4,10 @@ #pragma once #include +#include +#include #include #include -#include -#include inline std::string exec(std::string& command) { std::string output; diff --git a/src/apple/battery.cpp b/src/apple/battery.cpp index 5625509..c5f1bfa 100644 --- a/src/apple/battery.cpp +++ b/src/apple/battery.cpp @@ -11,44 +11,28 @@ namespace hwinfo { // ===================================================================================================================== // _____________________________________________________________________________________________________________________ -std::string Battery::getVendor() const { - return ""; -} +std::string Battery::getVendor() const { return ""; } // _____________________________________________________________________________________________________________________ -std::string Battery::getModel() const { - return ""; -} +std::string Battery::getModel() const { return ""; } // _____________________________________________________________________________________________________________________ -std::string Battery::getSerialNumber() const { - return ""; -} +std::string Battery::getSerialNumber() const { return ""; } // _____________________________________________________________________________________________________________________ -std::string Battery::getTechnology() const { - return ""; -} +std::string Battery::getTechnology() const { return ""; } // _____________________________________________________________________________________________________________________ -uint32_t Battery::getEnergyFull() const { - return 0; -} +uint32_t Battery::getEnergyFull() const { return 0; } // _____________________________________________________________________________________________________________________ -uint32_t Battery::energyNow() const { - return 0; -} +uint32_t Battery::energyNow() const { return 0; } // _____________________________________________________________________________________________________________________ -bool Battery::charging() const { - return false; -} +bool Battery::charging() const { return false; } // _____________________________________________________________________________________________________________________ -bool Battery::discharging() const { - return false; -} +bool Battery::discharging() const { return false; } // ===================================================================================================================== // _____________________________________________________________________________________________________________________ diff --git a/src/apple/cpu.cpp b/src/apple/cpu.cpp index 38d0db4..c784453 100644 --- a/src/apple/cpu.cpp +++ b/src/apple/cpu.cpp @@ -5,20 +5,19 @@ #ifdef HWINFO_APPLE -#include -#include -#include - #include #include -#include #include #include +#include + +#include +#include +#include #include "hwinfo/cpu.h" #include "hwinfo/cpuid.h" - namespace hwinfo { // _____________________________________________________________________________________________________________________ @@ -31,11 +30,11 @@ int CPU::currentClockSpeed_kHz() { std::string CPU::getVendor() { #if defined(HWINFO_X86) std::string vendor; - uint32_t regs[4] {0}; + uint32_t regs[4]{0}; cpuid::cpuid(0, 0, regs); - vendor += std::string((const char *) ®s[1], 4); - vendor += std::string((const char *) ®s[3], 4); - vendor += std::string((const char *) ®s[2], 4); + vendor += std::string((const char*)®s[1], 4); + vendor += std::string((const char*)®s[3], 4); + vendor += std::string((const char*)®s[2], 4); return vendor; #else // TODO: implement @@ -47,25 +46,25 @@ std::string CPU::getVendor() { std::string CPU::getModelName() { #if defined(HWINFO_X86) std::string model; - uint32_t regs[4] {}; + uint32_t regs[4]{}; for (unsigned i = 0x80000002; i < 0x80000005; ++i) { cpuid::cpuid(i, 0, regs); - for(auto c : std::string((const char*)®s[0], 4)) { + for (auto c : std::string((const char*)®s[0], 4)) { if (std::isalnum(c) || c == '(' || c == ')' || c == '@' || c == ' ' || c == '-' || c == '.') { model += c; } } - for(auto c : std::string((const char*)®s[1], 4)) { + for (auto c : std::string((const char*)®s[1], 4)) { if (std::isalnum(c) || c == '(' || c == ')' || c == '@' || c == ' ' || c == '-' || c == '.') { model += c; } } - for(auto c : std::string((const char*)®s[2], 4)) { + for (auto c : std::string((const char*)®s[2], 4)) { if (std::isalnum(c) || c == '(' || c == ')' || c == '@' || c == ' ' || c == '-' || c == '.') { model += c; } } - for(auto c : std::string((const char*)®s[3], 4)) { + for (auto c : std::string((const char*)®s[3], 4)) { if (std::isalnum(c) || c == '(' || c == ')' || c == '@' || c == ' ' || c == '-' || c == '.') { model += c; } @@ -74,9 +73,9 @@ std::string CPU::getModelName() { return model; #else char* model_2[1024]; - size_t size=sizeof(model_2); + size_t size = sizeof(model_2); if (sysctlbyname("machdep.cpu.brand_string", model_2, &size, NULL, 0) < 0) { - perror("sysctl"); + perror("sysctl"); } return std::string(model); #endif @@ -85,19 +84,19 @@ std::string CPU::getModelName() { // _____________________________________________________________________________________________________________________ int CPU::getNumPhysicalCores() { #if defined(HWINFO_X86) - uint32_t regs[4] {}; + uint32_t regs[4]{}; std::string vendorId = getVendor(); - std::for_each(vendorId.begin(), vendorId.end(), [](char &in) { in = ::toupper(in); } ); + std::for_each(vendorId.begin(), vendorId.end(), [](char& in) { in = ::toupper(in); }); cpuid::cpuid(0, 0, regs); uint32_t HFS = regs[0]; if (vendorId.find("INTEL") != std::string::npos) { if (HFS >= 11) { for (int lvl = 0; lvl < MAX_INTEL_TOP_LVL; ++lvl) { - uint32_t regs_2[4] {}; + uint32_t regs_2[4]{}; cpuid::cpuid(0x0b, lvl, regs_2); uint32_t currLevel = (LVL_TYPE & regs_2[2]) >> 8; if (currLevel == 0x01) { - int numCores = getNumLogicalCores()/static_cast(LVL_CORES & regs_2[1]); + int numCores = getNumLogicalCores() / static_cast(LVL_CORES & regs_2[1]); if (numCores > 0) { return numCores; } @@ -105,9 +104,9 @@ int CPU::getNumPhysicalCores() { } } else { if (HFS >= 4) { - uint32_t regs_3[4] {}; + uint32_t regs_3[4]{}; cpuid::cpuid(4, 0, regs_3); - int numCores = getNumLogicalCores()/static_cast(1 + ((regs_3[0] >> 26) & 0x3f)); + int numCores = getNumLogicalCores() / static_cast(1 + ((regs_3[0] >> 26) & 0x3f)); if (numCores > 0) { return numCores; } @@ -115,7 +114,7 @@ int CPU::getNumPhysicalCores() { } } else if (vendorId.find("AMD") != std::string::npos) { if (HFS > 0) { - uint32_t regs_4[4] {}; + uint32_t regs_4[4]{}; cpuid::cpuid(0x80000000, 0, regs_4); if (regs_4[0] >= 8) { int numCores = 1 + (regs_4[2] & 0xff); @@ -128,11 +127,11 @@ int CPU::getNumPhysicalCores() { return -1; #else int physical = 0; - size_t physical_size = sizeof(physical); - if (sysctlbyname("hw.physicalcpu", &physical, &physical_size, nullptr, 0) != 0) { - return -1; - } - return physical; + size_t physical_size = sizeof(physical); + if (sysctlbyname("hw.physicalcpu", &physical, &physical_size, nullptr, 0) != 0) { + return -1; + } + return physical; #endif } @@ -140,14 +139,14 @@ int CPU::getNumPhysicalCores() { int CPU::getNumLogicalCores() { #if defined(HWINFO_X86) std::string vendorId = getVendor(); - std::for_each(vendorId.begin(), vendorId.end(), [](char &in) { in = ::toupper(in); } ); - uint32_t regs[4] {}; + std::for_each(vendorId.begin(), vendorId.end(), [](char& in) { in = ::toupper(in); }); + uint32_t regs[4]{}; cpuid::cpuid(0, 0, regs); uint32_t HFS = regs[0]; if (vendorId.find("INTEL") != std::string::npos) { if (HFS >= 0xb) { for (int lvl = 0; lvl < MAX_INTEL_TOP_LVL; ++lvl) { - uint32_t regs_2[4] {}; + uint32_t regs_2[4]{}; cpuid::cpuid(0x0b, lvl, regs_2); uint32_t currLevel = (LVL_TYPE & regs_2[2]) >> 8; if (currLevel == 0x02) { @@ -204,8 +203,8 @@ int CPU::getCacheSize_Bytes() { if (line.starts_with("cache size")) { try { stream.close(); - return std::stoi(line.substr(line.find(": ")+2, line.length()-3)) * 1000; - } catch (std::invalid_argument &e) { + return std::stoi(line.substr(line.find(": ") + 2, line.length() - 3)) * 1000; + } catch (std::invalid_argument& e) { return -1; } } @@ -215,23 +214,22 @@ int CPU::getCacheSize_Bytes() { #elif defined(__APPLE__) return -1; #elif defined(_WIN32) || defined(_WIN64) - std::vector cacheSize {}; + std::vector cacheSize{}; wmi::queryWMI("Win32_Processor", "L3CacheSize", cacheSize); - if (cacheSize.empty()) { return -1; } + if (cacheSize.empty()) { + return -1; + } return cacheSize[0]; #else return -1; #endif } - // ===================================================================================================================== // _____________________________________________________________________________________________________________________ // Helper function for linux: parses /proc/cpuinfo. socket_id == physical_id. // _____________________________________________________________________________________________________________________ -std::optional getCPU(uint8_t socket_id) { - return {}; -} +std::optional getCPU(uint8_t socket_id) { return {}; } // ===== Socket ======================================================================================================== // _____________________________________________________________________________________________________________________ @@ -243,15 +241,11 @@ Socket::Socket(uint8_t id) : _id(id) { } // _____________________________________________________________________________________________________________________ -Socket::Socket(uint8_t id, const class CPU& cpu) : _id(id) { - _cpu = cpu; -} +Socket::Socket(uint8_t id, const class CPU& cpu) : _id(id) { _cpu = cpu; } // ===================================================================================================================== // _____________________________________________________________________________________________________________________ -std::vector getAllSockets() { - return {}; -} +std::vector getAllSockets() { return {}; } } // namespace hwinfo diff --git a/src/apple/gpu.cpp b/src/apple/gpu.cpp index 5791ca7..cbc9dc9 100644 --- a/src/apple/gpu.cpp +++ b/src/apple/gpu.cpp @@ -5,9 +5,9 @@ #ifdef HWINFO_APPLE -#include -#include #include +#include +#include #include "hwinfo/gpu.h" diff --git a/src/apple/mainboard.cpp b/src/apple/mainboard.cpp index a3a9884..d033e9c 100644 --- a/src/apple/mainboard.cpp +++ b/src/apple/mainboard.cpp @@ -7,7 +7,6 @@ #include "hwinfo/mainboard.h" - namespace hwinfo { // _____________________________________________________________________________________________________________________ diff --git a/src/apple/os.cpp b/src/apple/os.cpp index 92e2100..09a8908 100644 --- a/src/apple/os.cpp +++ b/src/apple/os.cpp @@ -5,11 +5,11 @@ #ifdef HWINFO_APPLE +#include + #include #include -#include - #include "hwinfo/os.h" namespace hwinfo { @@ -54,9 +54,7 @@ std::string OS::getKernel() { } // _____________________________________________________________________________________________________________________ -bool OS::getIs64bit() { - return true; -} +bool OS::getIs64bit() { return true; } } // namespace hwinfo diff --git a/src/apple/ram.cpp b/src/apple/ram.cpp index 0c41067..fea2f05 100644 --- a/src/apple/ram.cpp +++ b/src/apple/ram.cpp @@ -5,11 +5,11 @@ #ifdef HWINFO_APPLE +#include + #include #include -#include - #include "hwinfo/ram.h" namespace hwinfo { diff --git a/src/battery.cpp b/src/battery.cpp index 8db84fa..fea560b 100644 --- a/src/battery.cpp +++ b/src/battery.cpp @@ -7,12 +7,10 @@ namespace hwinfo { // ===================================================================================================================== // _____________________________________________________________________________________________________________________ -Battery::Battery(int8_t id) { - _id = id; -} +Battery::Battery(int8_t id) { _id = id; } // _____________________________________________________________________________________________________________________ -std::string &Battery::vendor() { +std::string& Battery::vendor() { if (_vendor.empty()) { _vendor = getVendor(); } @@ -20,7 +18,7 @@ std::string &Battery::vendor() { } // _____________________________________________________________________________________________________________________ -std::string &Battery::model() { +std::string& Battery::model() { if (_model.empty()) { _model = getModel(); } @@ -28,7 +26,7 @@ std::string &Battery::model() { } // _____________________________________________________________________________________________________________________ -std::string &Battery::serialNumber() { +std::string& Battery::serialNumber() { if (_serialNumber.empty()) { _serialNumber = getSerialNumber(); } @@ -36,7 +34,7 @@ std::string &Battery::serialNumber() { } // _____________________________________________________________________________________________________________________ -std::string &Battery::technology() { +std::string& Battery::technology() { if (_technology.empty()) { _technology = getTechnology(); } @@ -52,8 +50,6 @@ uint32_t Battery::energyFull() { } // _____________________________________________________________________________________________________________________ -double Battery::capacity() { - return static_cast(energyNow()) / energyFull(); -} +double Battery::capacity() { return static_cast(energyNow()) / energyFull(); } } // namespace hwinfo \ No newline at end of file diff --git a/src/cpu.cpp b/src/cpu.cpp index d4f1d31..bf10de1 100644 --- a/src/cpu.cpp +++ b/src/cpu.cpp @@ -1,20 +1,18 @@ // Copyright (c) Leon Freist // This software is part of HWBenchmark +#include "hwinfo/cpu.h" + #include #include -#include "hwinfo/cpu.h" -#include "hwinfo/platform.h" - #include "hwinfo/cpuid.h" +#include "hwinfo/platform.h" namespace hwinfo { // _____________________________________________________________________________________________________________________ -CPU::CPU(int id) { - _id = id; -} +CPU::CPU(int id) { _id = id; } // _____________________________________________________________________________________________________________________ std::string& CPU::modelName() { @@ -73,22 +71,20 @@ int CPU::regularClockSpeed_kHz() { } // _____________________________________________________________________________________________________________________ -InstructionSet &CPU::instructionSet() { +InstructionSet& CPU::instructionSet() { if (!_instructionSet._init_) { #if defined(HWINFO_X86) - uint32_t regs[4] {}; + uint32_t regs[4]{}; cpuid::cpuid(1, 0, regs); - _instructionSet = InstructionSet { - static_cast(regs[3] & AVX_POS), - static_cast(regs[3] & SSE_POS), - static_cast(regs[3] & SSE2_POS), - static_cast(regs[2] & SSE3_POS), - static_cast(regs[2] & SSE41_POS), - static_cast(regs[2] & SSE42_POS), - static_cast(regs[2] & AVX_POS), - false, - true - }; + _instructionSet = InstructionSet{static_cast(regs[3] & AVX_POS), + static_cast(regs[3] & SSE_POS), + static_cast(regs[3] & SSE2_POS), + static_cast(regs[2] & SSE3_POS), + static_cast(regs[2] & SSE41_POS), + static_cast(regs[2] & SSE42_POS), + static_cast(regs[2] & AVX_POS), + false, + true}; cpuid::cpuid(7, 0, regs); _instructionSet._isAVX2 = static_cast(regs[1] & AVX2_POS); #else @@ -100,9 +96,6 @@ InstructionSet &CPU::instructionSet() { // ===== Socket ======================================================================================================== // _____________________________________________________________________________________________________________________ -CPU &Socket::CPU() { - return _cpu; -} - +CPU& Socket::CPU() { return _cpu; } } // namespace hwinfo \ No newline at end of file diff --git a/src/disk.cpp b/src/disk.cpp index 1012ee5..4efb6ba 100644 --- a/src/disk.cpp +++ b/src/disk.cpp @@ -2,34 +2,27 @@ // Author Leon Freist #include "hwinfo/disk.h" + #include "hwinfo/utils/stringutils.h" namespace hwinfo { // _____________________________________________________________________________________________________________________ -Disk::Disk(std::string &vendor, std::string &model, std::string &serialNumber, int64_t size_Bytes) - : _vendor(vendor), _model(model), _serialNumber(serialNumber) { +Disk::Disk(std::string& vendor, std::string& model, std::string& serialNumber, int64_t size_Bytes) + : _vendor(vendor), _model(model), _serialNumber(serialNumber) { _size_Bytes = size_Bytes; } // _____________________________________________________________________________________________________________________ -const std::string &Disk::vendor() const { - return _vendor; -} +const std::string& Disk::vendor() const { return _vendor; } // _____________________________________________________________________________________________________________________ -const std::string &Disk::model() const { - return _model; -} +const std::string& Disk::model() const { return _model; } // _____________________________________________________________________________________________________________________ -const std::string &Disk::serialNumber() const { - return _serialNumber; -} +const std::string& Disk::serialNumber() const { return _serialNumber; } // _____________________________________________________________________________________________________________________ -int64_t Disk::size_Bytes() const { - return _size_Bytes; -} +int64_t Disk::size_Bytes() const { return _size_Bytes; } } // namespace hwinfo diff --git a/src/gpu.cpp b/src/gpu.cpp index 8eef52c..dab9486 100644 --- a/src/gpu.cpp +++ b/src/gpu.cpp @@ -1,9 +1,9 @@ // Copyright Leon Freist // Author Leon Freist -#include -#include #include +#include +#include #if defined(unix) || defined(__unix) || defined(__unix__) #include "hwinfo/utils/subprocess.h" @@ -18,13 +18,13 @@ namespace hwinfo { // _____________________________________________________________________________________________________________________ -GPU::GPU(const std::string& vendor, const std::string &name, const std::string &driverVersion, int64_t memory_Bytes) - : _vendor(vendor), _name(name), _driverVersion(driverVersion) { +GPU::GPU(const std::string& vendor, const std::string& name, const std::string& driverVersion, int64_t memory_Bytes) + : _vendor(vendor), _name(name), _driverVersion(driverVersion) { _memory_Bytes = memory_Bytes; } // _____________________________________________________________________________________________________________________ -std::string &GPU::vendor() { +std::string& GPU::vendor() { if (_vendor.empty()) { _vendor = getVendor(); } @@ -32,7 +32,7 @@ std::string &GPU::vendor() { } // _____________________________________________________________________________________________________________________ -std::string &GPU::name() { +std::string& GPU::name() { if (_name.empty()) { _name = getName(); } @@ -40,7 +40,7 @@ std::string &GPU::name() { } // _____________________________________________________________________________________________________________________ -std::string &GPU::driverVersion() { +std::string& GPU::driverVersion() { if (_driverVersion.empty()) { _driverVersion = getDriverVersion(); } diff --git a/src/linux/battery.cpp b/src/linux/battery.cpp index cdf7bee..72c1703 100644 --- a/src/linux/battery.cpp +++ b/src/linux/battery.cpp @@ -5,8 +5,8 @@ #ifdef HWINFO_UNIX -#include #include +#include #include "hwinfo/battery.h" @@ -114,9 +114,7 @@ bool Battery::charging() const { } // _____________________________________________________________________________________________________________________ -bool Battery::discharging() const { - return !charging(); -} +bool Battery::discharging() const { return !charging(); } // ===================================================================================================================== // _____________________________________________________________________________________________________________________ diff --git a/src/linux/cpu.cpp b/src/linux/cpu.cpp index e89094e..12249e0 100644 --- a/src/linux/cpu.cpp +++ b/src/linux/cpu.cpp @@ -5,17 +5,16 @@ #ifdef HWINFO_UNIX -#include -#include #include -#include #include #include +#include +#include +#include #include "hwinfo/cpu.h" #include "hwinfo/utils/stringutils.h" - #if defined(HWINFO_X86) #include "hwinfo/cpuid.h" #endif @@ -33,7 +32,7 @@ int CPU::currentClockSpeed_kHz() { stream.close(); try { return std::stoi(line); - } catch (std::invalid_argument &e) { + } catch (std::invalid_argument& e) { return -1; } } @@ -42,11 +41,11 @@ int CPU::currentClockSpeed_kHz() { std::string CPU::getVendor() { #if defined(HWINFO_X86) std::string vendor; - uint32_t regs[4] {0}; + uint32_t regs[4]{0}; cpuid::cpuid(0, 0, regs); - vendor += std::string((const char *) ®s[1], 4); - vendor += std::string((const char *) ®s[3], 4); - vendor += std::string((const char *) ®s[2], 4); + vendor += std::string((const char*)®s[1], 4); + vendor += std::string((const char*)®s[3], 4); + vendor += std::string((const char*)®s[2], 4); return vendor; #else std::string line; @@ -57,7 +56,7 @@ std::string CPU::getVendor() { while (getline(stream, line)) { if (line.starts_with("vendor_id")) { stream.close(); - return line.substr(line.find(": ")+2, line.length()); + return line.substr(line.find(": ") + 2, line.length()); } } return ""; @@ -69,25 +68,25 @@ std::string CPU::getVendor() { std::string CPU::getModelName() { #if defined(HWINFO_X86) std::string model; - uint32_t regs[4] {}; + uint32_t regs[4]{}; for (unsigned i = 0x80000002; i < 0x80000005; ++i) { cpuid::cpuid(i, 0, regs); - for(auto c : std::string((const char*)®s[0], 4)) { + for (auto c : std::string((const char*)®s[0], 4)) { if (std::isalnum(c) || c == '(' || c == ')' || c == '@' || c == ' ' || c == '-' || c == '.') { model += c; } } - for(auto c : std::string((const char*)®s[1], 4)) { + for (auto c : std::string((const char*)®s[1], 4)) { if (std::isalnum(c) || c == '(' || c == ')' || c == '@' || c == ' ' || c == '-' || c == '.') { model += c; } } - for(auto c : std::string((const char*)®s[2], 4)) { + for (auto c : std::string((const char*)®s[2], 4)) { if (std::isalnum(c) || c == '(' || c == ')' || c == '@' || c == ' ' || c == '-' || c == '.') { model += c; } } - for(auto c : std::string((const char*)®s[3], 4)) { + for (auto c : std::string((const char*)®s[3], 4)) { if (std::isalnum(c) || c == '(' || c == ')' || c == '@' || c == ' ' || c == '-' || c == '.') { model += c; } @@ -103,7 +102,7 @@ std::string CPU::getModelName() { while (getline(stream, line)) { if (line.starts_with("model name")) { stream.close(); - return line.substr(line.find(": ")+2, line.length()); + return line.substr(line.find(": ") + 2, line.length()); } } return ""; @@ -114,19 +113,19 @@ std::string CPU::getModelName() { // _____________________________________________________________________________________________________________________ int CPU::getNumPhysicalCores() { #if defined(HWINFO_X86) - uint32_t regs[4] {}; + uint32_t regs[4]{}; std::string vendorId = getVendor(); - std::for_each(vendorId.begin(), vendorId.end(), [](char &in) { in = ::toupper(in); } ); + std::for_each(vendorId.begin(), vendorId.end(), [](char& in) { in = ::toupper(in); }); cpuid::cpuid(0, 0, regs); uint32_t HFS = regs[0]; if (vendorId.find("INTEL") != std::string::npos) { if (HFS >= 11) { for (int lvl = 0; lvl < MAX_INTEL_TOP_LVL; ++lvl) { - uint32_t regs_2[4] {}; + uint32_t regs_2[4]{}; cpuid::cpuid(0x0b, lvl, regs_2); uint32_t currLevel = (LVL_TYPE & regs_2[2]) >> 8; if (currLevel == 0x01) { - int numCores = getNumLogicalCores()/static_cast(LVL_CORES & regs_2[1]); + int numCores = getNumLogicalCores() / static_cast(LVL_CORES & regs_2[1]); if (numCores > 0) { return numCores; } @@ -134,9 +133,9 @@ int CPU::getNumPhysicalCores() { } } else { if (HFS >= 4) { - uint32_t regs_3[4] {}; + uint32_t regs_3[4]{}; cpuid::cpuid(4, 0, regs_3); - int numCores = getNumLogicalCores()/static_cast(1 + ((regs_3[0] >> 26) & 0x3f)); + int numCores = getNumLogicalCores() / static_cast(1 + ((regs_3[0] >> 26) & 0x3f)); if (numCores > 0) { return numCores; } @@ -144,7 +143,7 @@ int CPU::getNumPhysicalCores() { } } else if (vendorId.find("AMD") != std::string::npos) { if (HFS > 0) { - uint32_t regs_4[4] {}; + uint32_t regs_4[4]{}; cpuid::cpuid(0x80000000, 0, regs_4); if (regs_4[0] >= 8) { int numCores = 1 + (regs_4[2] & 0xff); @@ -169,14 +168,14 @@ int CPU::getNumPhysicalCores() { int CPU::getNumLogicalCores() { #if defined(HWINFO_X86) std::string vendorId = getVendor(); - std::for_each(vendorId.begin(), vendorId.end(), [](char &in) { in = ::toupper(in); } ); - uint32_t regs[4] {}; + std::for_each(vendorId.begin(), vendorId.end(), [](char& in) { in = ::toupper(in); }); + uint32_t regs[4]{}; cpuid::cpuid(0, 0, regs); uint32_t HFS = regs[0]; if (vendorId.find("INTEL") != std::string::npos) { if (HFS >= 0xb) { for (int lvl = 0; lvl < MAX_INTEL_TOP_LVL; ++lvl) { - uint32_t regs_2[4] {}; + uint32_t regs_2[4]{}; cpuid::cpuid(0x0b, lvl, regs_2); uint32_t currLevel = (LVL_TYPE & regs_2[2]) >> 8; if (currLevel == 0x02) { @@ -212,7 +211,7 @@ int CPU::getMaxClockSpeed_kHz() { stream.close(); try { return std::stoi(line); - } catch (std::invalid_argument &e) { + } catch (std::invalid_argument& e) { return -1; } } @@ -228,8 +227,8 @@ int CPU::getRegularClockSpeed_kHz() { if (line.starts_with("cpu MHz")) { try { stream.close(); - return static_cast(std::stof(line.substr(line.find(": ")+2, line.length()))) * 1000; - } catch (std::invalid_argument &e) { + return static_cast(std::stof(line.substr(line.find(": ") + 2, line.length()))) * 1000; + } catch (std::invalid_argument& e) { return -1; } } @@ -248,8 +247,8 @@ int CPU::getCacheSize_Bytes() { if (line.starts_with("cache size")) { try { stream.close(); - return std::stoi(line.substr(line.find(": ")+2, line.length()-3)) * 1000; - } catch (std::invalid_argument &e) { + return std::stoi(line.substr(line.find(": ") + 2, line.length() - 3)) * 1000; + } catch (std::invalid_argument& e) { return -1; } } @@ -267,22 +266,23 @@ std::optional getCPU(uint8_t socket_id) { if (!cpuinfo.is_open()) { return {}; } - std::string file((std::istreambuf_iterator(cpuinfo)), - (std::istreambuf_iterator())); + std::string file((std::istreambuf_iterator(cpuinfo)), (std::istreambuf_iterator())); cpuinfo.close(); auto cpu_blocks_string = split(file, "\n\n"); std::map cpu_block; bool physical_id_found = false; - for (const auto &block: cpu_blocks_string) { + for (const auto& block : cpu_blocks_string) { if (physical_id_found) { break; } auto lines = split(block, '\n'); std::map cpu_map; bool add = true; - for (const auto &line: lines) { + for (const auto& line : lines) { auto pair = split(line, "\t: "); - if (pair.size() != 2) { continue; } + if (pair.size() != 2) { + continue; + } strip(pair[0]); strip(pair[1]); if (pair[0] == "physical id" && pair[1] != std::to_string(socket_id)) { @@ -337,9 +337,7 @@ Socket::Socket(uint8_t id) : _id(id) { } // _____________________________________________________________________________________________________________________ -Socket::Socket(uint8_t id, const class CPU& cpu) : _id(id) { - _cpu = cpu; -} +Socket::Socket(uint8_t id, const class CPU& cpu) : _id(id) { _cpu = cpu; } // ===================================================================================================================== // _____________________________________________________________________________________________________________________ diff --git a/src/linux/disk.cpp b/src/linux/disk.cpp index 521d06e..f0d2673 100644 --- a/src/linux/disk.cpp +++ b/src/linux/disk.cpp @@ -21,7 +21,7 @@ std::vector getAllDisks() { std::string vendor; std::string model; std::string serialNumber; - for (const auto& entry: std::filesystem::directory_iterator(base_path)) { + for (const auto& entry : std::filesystem::directory_iterator(base_path)) { std::string path = entry.path().string() + "/device/"; if (!std::filesystem::exists(std::filesystem::path(path))) { continue; @@ -29,20 +29,23 @@ std::vector getAllDisks() { std::ifstream f(path + "vendor"); if (f) { getline(f, vendor); + } else { + vendor = ""; } - else { vendor = ""; } f.close(); f.open(path + "model"); if (f) { getline(f, model); + } else { + vendor = ""; } - else { vendor = ""; } f.close(); f.open(path + "serial"); if (f) { getline(f, serialNumber); + } else { + serialNumber = ""; } - else { serialNumber = ""; } f.close(); strip(vendor); strip(model); diff --git a/src/linux/gpu.cpp b/src/linux/gpu.cpp index ecf30c9..2280549 100644 --- a/src/linux/gpu.cpp +++ b/src/linux/gpu.cpp @@ -1,3 +1,4 @@ + // Copyright Leon Freist // Author Leon Freist @@ -5,13 +6,12 @@ #ifdef HWINFO_UNIX -#include -#include #include - -#include "hwinfo/utils/subprocess.h" +#include +#include #include "hwinfo/gpu.h" +#include "hwinfo/utils/subprocess.h" namespace hwinfo { @@ -28,12 +28,16 @@ std::string GPU::getVendor() { char prev = '\0'; bool add = false; std::string tmp = match[0]; - for (auto& c: tmp) { - if (c == '\n') { break; } + for (auto& c : tmp) { + if (c == '\n') { + break; + } if (add) { vendor += c; } - if (prev == ':') { add = true; } + if (prev == ':') { + add = true; + } prev = c; } } @@ -52,12 +56,16 @@ std::string GPU::getName() { if (std::regex_search(output.cbegin(), output.cend(), match, matcher)) { bool add = false; std::string tmp = match[0]; - for (auto& c: tmp) { - if (c == ']') { break; } + for (auto& c : tmp) { + if (c == ']') { + break; + } if (add) { name += c; } - if (c == '[') { add = true; } + if (c == '[') { + add = true; + } } } return name; diff --git a/src/linux/mainboard.cpp b/src/linux/mainboard.cpp index 5d1f01d..7f81270 100644 --- a/src/linux/mainboard.cpp +++ b/src/linux/mainboard.cpp @@ -9,13 +9,12 @@ #include "hwinfo/mainboard.h" - namespace hwinfo { // _____________________________________________________________________________________________________________________ std::string MainBoard::getVendor() { std::string manufacturer; - for (const auto& path: _candidates) { + for (const auto& path : _candidates) { std::string full_path = path + "id/board_vendor"; std::ifstream f(full_path); if (f) { @@ -31,7 +30,7 @@ std::string MainBoard::getVendor() { // _____________________________________________________________________________________________________________________ std::string MainBoard::getName() { std::string name; - for (const auto& path: _candidates) { + for (const auto& path : _candidates) { std::string full_path = path + "id/board_name"; std::ifstream f(full_path); if (f) { @@ -47,7 +46,7 @@ std::string MainBoard::getName() { // _____________________________________________________________________________________________________________________ std::string MainBoard::getVersion() { std::string version; - for (const auto& path: _candidates) { + for (const auto& path : _candidates) { std::string full_path = path + "id/board_version"; std::ifstream f(full_path); if (f) { @@ -63,7 +62,7 @@ std::string MainBoard::getVersion() { // _____________________________________________________________________________________________________________________ std::string MainBoard::getSerialNumber() { std::string serialNumber; - for (const auto& path: _candidates) { + for (const auto& path : _candidates) { std::string full_path = path + "id/board_serial"; std::ifstream f(full_path); if (f) { diff --git a/src/linux/os.cpp b/src/linux/os.cpp index a52bc71..b999d63 100644 --- a/src/linux/os.cpp +++ b/src/linux/os.cpp @@ -5,13 +5,13 @@ #ifdef HWINFO_UNIX -#include -#include - -#include #include #include +#include +#include +#include + #include "hwinfo/os.h" namespace hwinfo { @@ -25,9 +25,9 @@ std::string OS::getFullName() { } while (getline(stream, line)) { if (line.starts_with("DISTRIB_DESCRIPTION")) { - line = line.substr(line.find('=')+1, line.length()); + line = line.substr(line.find('=') + 1, line.length()); // remove \" at begin and end of the substring result - return {line.begin()+1, line.end()-1}; + return {line.begin() + 1, line.end() - 1}; } } stream.close(); @@ -43,7 +43,7 @@ std::string OS::getName() { } while (getline(stream, line)) { if (line.starts_with("DISTRIB_ID")) { - return line.substr(line.find('=')+1, line.length()); + return line.substr(line.find('=') + 1, line.length()); } } stream.close(); @@ -59,7 +59,7 @@ std::string OS::getVersion() { } while (getline(stream, line)) { if (line.starts_with("DISTRIB_RELEASE")) { - return line.substr(line.find('=')+1, line.length()); + return line.substr(line.find('=') + 1, line.length()); } } stream.close(); @@ -77,7 +77,7 @@ std::string OS::getKernel() { // _____________________________________________________________________________________________________________________ bool OS::getIs64bit() { - struct stat buffer{}; + struct stat buffer {}; return (stat("/lib64/ld-linux-x86-64.so.2", &buffer) == 0); } diff --git a/src/linux/ram.cpp b/src/linux/ram.cpp index 57ae898..e55ba12 100644 --- a/src/linux/ram.cpp +++ b/src/linux/ram.cpp @@ -5,34 +5,26 @@ #ifdef HWINFO_UNIX +#include + #include #include -#include - #include "hwinfo/ram.h" namespace hwinfo { // _____________________________________________________________________________________________________________________ -std::string RAM::getVendor() { - return ""; -} +std::string RAM::getVendor() { return ""; } // _____________________________________________________________________________________________________________________ -std::string RAM::getName() { - return ""; -} +std::string RAM::getName() { return ""; } // _____________________________________________________________________________________________________________________ -std::string RAM::getModel() { - return ""; -} +std::string RAM::getModel() { return ""; } // _____________________________________________________________________________________________________________________ -std::string RAM::getSerialNumber() { - return ""; -} +std::string RAM::getSerialNumber() { return ""; } // _____________________________________________________________________________________________________________________ int64_t RAM::getTotalSize_Bytes() { diff --git a/src/mainboard.cpp b/src/mainboard.cpp index 71a4407..1c86930 100644 --- a/src/mainboard.cpp +++ b/src/mainboard.cpp @@ -1,22 +1,21 @@ // Copyright (c) Leon Freist // This software is part of HWBenchmark -#include - -#include "hwinfo/WMIwrapper.h" - #include "hwinfo/mainboard.h" +#include +#include + +#include "hwinfo/WMIwrapper.h" namespace hwinfo { // _____________________________________________________________________________________________________________________ -MainBoard::MainBoard(const std::string &vendor, - const std::string &product, - const std::string &version, - const std::string &serialNumber) - : _vendor(vendor), _name(product), _version(version), _serialNumber(serialNumber) { -} +MainBoard::MainBoard(std::string vendor, std::string product, std::string version, std::string serialNumber) + : _vendor(std::move(vendor)), + _name(std::move(product)), + _version(std::move(version)), + _serialNumber(std::move(serialNumber)) {} // _____________________________________________________________________________________________________________________ std::string& MainBoard::vendor() { diff --git a/src/os.cpp b/src/os.cpp index f5b9706..0241ad6 100644 --- a/src/os.cpp +++ b/src/os.cpp @@ -1,10 +1,10 @@ // Copyright (c) Leon Freist // This software is part of HWBenchmark -#include - #include "hwinfo/os.h" +#include + namespace hwinfo { // _____________________________________________________________________________________________________________________ @@ -48,29 +48,19 @@ std::string OS::kernel() { } // _____________________________________________________________________________________________________________________ -bool OS::is32bit() const { - return _32bit; -} +bool OS::is32bit() const { return _32bit; } // _____________________________________________________________________________________________________________________ -bool OS::is64bit() const { - return _64bit; -} +bool OS::is64bit() const { return _64bit; } // _____________________________________________________________________________________________________________________ -bool OS::isBigEndian() const { - return _bigEndian; -} +bool OS::isBigEndian() const { return _bigEndian; } // _____________________________________________________________________________________________________________________ -bool OS::isLittleEndian() const { - return _littleEndian; -} +bool OS::isLittleEndian() const { return _littleEndian; } // _____________________________________________________________________________________________________________________ -bool OS::getIs32bit() { - return !getIs64bit(); -} +bool OS::getIs32bit() { return !getIs64bit(); } // _____________________________________________________________________________________________________________________ bool OS::getIsBigEndian() { diff --git a/src/ram.cpp b/src/ram.cpp index 630f5fe..d497ea8 100644 --- a/src/ram.cpp +++ b/src/ram.cpp @@ -10,6 +10,7 @@ #include #elif defined(_WIN32) || defined(_WIN64) #include + #include "hwinfo/WMIwrapper.h" #endif #include "hwinfo/ram.h" @@ -17,17 +18,13 @@ namespace hwinfo { // _____________________________________________________________________________________________________________________ -RAM::RAM(std::string &vendor, - std::string &name, - std::string &model, - std::string &serialNumber, - int64_t size_Bytes) - : _vendor(vendor), _name(name), _model(model), _serialNumber(serialNumber) { +RAM::RAM(std::string& vendor, std::string& name, std::string& model, std::string& serialNumber, int64_t size_Bytes) + : _vendor(vendor), _name(name), _model(model), _serialNumber(serialNumber) { _totalSize_Bytes = size_Bytes; } // _____________________________________________________________________________________________________________________ -std::string &RAM::vendor() { +std::string& RAM::vendor() { if (_vendor.empty()) { _vendor = getVendor(); } @@ -35,7 +32,7 @@ std::string &RAM::vendor() { } // _____________________________________________________________________________________________________________________ -std::string &RAM::name() { +std::string& RAM::name() { if (_name.empty()) { _name = getName(); } @@ -43,7 +40,7 @@ std::string &RAM::name() { } // _____________________________________________________________________________________________________________________ -std::string &RAM::model() { +std::string& RAM::model() { if (_model.empty()) { _model = getModel(); } @@ -51,7 +48,7 @@ std::string &RAM::model() { } // _____________________________________________________________________________________________________________________ -std::string &RAM::serialNumber() { +std::string& RAM::serialNumber() { if (_serialNumber.empty()) { _serialNumber = getSerialNumber(); } diff --git a/src/windows/battery.cpp b/src/windows/battery.cpp index d1d0ccf..6f4c19c 100644 --- a/src/windows/battery.cpp +++ b/src/windows/battery.cpp @@ -2,69 +2,56 @@ // Author Leon Freist #include + #include "hwinfo/platform.h" #ifdef HWINFO_WINDOWS -#include "hwinfo/battery.h" #include "hwinfo/WMIwrapper.h" +#include "hwinfo/battery.h" namespace hwinfo { // ===================================================================================================================== // _____________________________________________________________________________________________________________________ -std::string Battery::getVendor() const { - return ""; -} +std::string Battery::getVendor() const { return ""; } // _____________________________________________________________________________________________________________________ -std::string Battery::getModel() const { - return _model; -} +std::string Battery::getModel() const { return _model; } // _____________________________________________________________________________________________________________________ -std::string Battery::getSerialNumber() const { - return ""; -} +std::string Battery::getSerialNumber() const { return ""; } // _____________________________________________________________________________________________________________________ -std::string Battery::getTechnology() const { - return ""; -} +std::string Battery::getTechnology() const { return ""; } // _____________________________________________________________________________________________________________________ -uint32_t Battery::getEnergyFull() const { - return 0; -} +uint32_t Battery::getEnergyFull() const { return 0; } // _____________________________________________________________________________________________________________________ -uint32_t Battery::energyNow() const { - return 0; -} +uint32_t Battery::energyNow() const { return 0; } // _____________________________________________________________________________________________________________________ -bool Battery::charging() const { - return false; -} +bool Battery::charging() const { return false; } // _____________________________________________________________________________________________________________________ -bool Battery::discharging() const { - return false; -} +bool Battery::discharging() const { return false; } // ===================================================================================================================== // _____________________________________________________________________________________________________________________ std::vector getAllBatteries() { std::vector batteries; - std::vector res {}; + std::vector res{}; wmi::queryWMI("Win32_Battery", "Name", res); - if (res.empty() || res.at(0) == nullptr) { return {}; } + if (res.empty() || res.at(0) == nullptr) { + return {}; + } std::cout << res.size() << std::endl; int8_t counter = 0; - for (const auto &v: res) { + for (const auto& v : res) { std::wstring tmp(v); batteries.emplace_back(counter++); - batteries.back()._model = { tmp.begin(), tmp.end() }; + batteries.back()._model = {tmp.begin(), tmp.end()}; } res.clear(); return batteries; diff --git a/src/windows/cpu.cpp b/src/windows/cpu.cpp index 23c5a41..9d21820 100644 --- a/src/windows/cpu.cpp +++ b/src/windows/cpu.cpp @@ -5,38 +5,38 @@ #ifdef HWINFO_WINDOWS +#include #include #include -#include #include "hwinfo/WMIwrapper.h" #include "hwinfo/cpu.h" - #include "hwinfo/cpuid.h" - namespace hwinfo { // _____________________________________________________________________________________________________________________ int CPU::currentClockSpeed_kHz() { - std::vector speed {}; + std::vector speed{}; wmi::queryWMI("Win32_Processor", "CurrentClockSpeed", speed); - if (speed.empty()) { return -1; } + if (speed.empty()) { + return -1; + } return speed[0]; } // _____________________________________________________________________________________________________________________ std::string CPU::getVendor() { - std::vector vendor {}; + std::vector vendor{}; wmi::queryWMI("Win32_Processor", "Manufacturer", vendor); if (vendor.empty()) { #if defined(HWINFO_X86) std::string v; - uint32_t regs[4] {0}; + uint32_t regs[4]{0}; cpuid::cpuid(0, 0, regs); - v += std::string((const char *) ®s[1], 4); - v += std::string((const char *) ®s[3], 4); - v += std::string((const char *) ®s[2], 4); + v += std::string((const char*)®s[1], 4); + v += std::string((const char*)®s[3], 4); + v += std::string((const char*)®s[2], 4); return v; #else return ""; @@ -49,30 +49,30 @@ std::string CPU::getVendor() { // _____________________________________________________________________________________________________________________ std::string CPU::getModelName() { - std::vector vendor {}; + std::vector vendor{}; wmi::queryWMI("Win32_Processor", "Name", vendor); if (vendor.empty()) { #if defined(HWINFO_X86) std::string model; - uint32_t regs[4] {}; + uint32_t regs[4]{}; for (unsigned i = 0x80000002; i < 0x80000005; ++i) { cpuid::cpuid(i, 0, regs); - for(auto c : std::string((const char*)®s[0], 4)) { + for (auto c : std::string((const char*)®s[0], 4)) { if (std::isalnum(c) || c == '(' || c == ')' || c == '@' || c == ' ' || c == '-' || c == '.') { model += c; } } - for(auto c : std::string((const char*)®s[1], 4)) { + for (auto c : std::string((const char*)®s[1], 4)) { if (std::isalnum(c) || c == '(' || c == ')' || c == '@' || c == ' ' || c == '-' || c == '.') { model += c; } } - for(auto c : std::string((const char*)®s[2], 4)) { + for (auto c : std::string((const char*)®s[2], 4)) { if (std::isalnum(c) || c == '(' || c == ')' || c == '@' || c == ' ' || c == '-' || c == '.') { model += c; } } - for(auto c : std::string((const char*)®s[3], 4)) { + for (auto c : std::string((const char*)®s[3], 4)) { if (std::isalnum(c) || c == '(' || c == ')' || c == '@' || c == ' ' || c == '-' || c == '.') { model += c; } @@ -89,23 +89,23 @@ std::string CPU::getModelName() { // _____________________________________________________________________________________________________________________ int CPU::getNumPhysicalCores() { - std::vector cores {}; + std::vector cores{}; wmi::queryWMI("Win32_Processor", "NumberOfCores", cores); if (cores.empty()) { #if defined(HWINFO_X86) - uint32_t regs[4] {}; + uint32_t regs[4]{}; std::string vendorId = getVendor(); - std::for_each(vendorId.begin(), vendorId.end(), [](char &in) { in = ::toupper(in); } ); + std::for_each(vendorId.begin(), vendorId.end(), [](char& in) { in = ::toupper(in); }); cpuid::cpuid(0, 0, regs); uint32_t HFS = regs[0]; if (vendorId.find("INTEL") != std::string::npos) { if (HFS >= 11) { for (int lvl = 0; lvl < MAX_INTEL_TOP_LVL; ++lvl) { - uint32_t regs_2[4] {}; + uint32_t regs_2[4]{}; cpuid::cpuid(0x0b, lvl, regs_2); uint32_t currLevel = (LVL_TYPE & regs_2[2]) >> 8; if (currLevel == 0x01) { - int numCores = getNumLogicalCores()/static_cast(LVL_CORES & regs_2[1]); + int numCores = getNumLogicalCores() / static_cast(LVL_CORES & regs_2[1]); if (numCores > 0) { return numCores; } @@ -113,9 +113,9 @@ int CPU::getNumPhysicalCores() { } } else { if (HFS >= 4) { - uint32_t regs_3[4] {}; + uint32_t regs_3[4]{}; cpuid::cpuid(4, 0, regs_3); - int numCores = getNumLogicalCores()/static_cast(1 + ((regs_3[0] >> 26) & 0x3f)); + int numCores = getNumLogicalCores() / static_cast(1 + ((regs_3[0] >> 26) & 0x3f)); if (numCores > 0) { return numCores; } @@ -123,7 +123,7 @@ int CPU::getNumPhysicalCores() { } } else if (vendorId.find("AMD") != std::string::npos) { if (HFS > 0) { - uint32_t regs_4[4] {}; + uint32_t regs_4[4]{}; cpuid::cpuid(0x80000000, 0, regs_4); if (regs_4[0] >= 8) { int numCores = 1 + (regs_4[2] & 0xff); @@ -141,19 +141,19 @@ int CPU::getNumPhysicalCores() { // _____________________________________________________________________________________________________________________ int CPU::getNumLogicalCores() { - std::vector cores {}; + std::vector cores{}; wmi::queryWMI("Win32_Processor", "NumberOfLogicalProcessors", cores); if (cores.empty()) { #if defined(HWINFO_X86) std::string vendorId = getVendor(); - std::for_each(vendorId.begin(), vendorId.end(), [](char &in) { in = ::toupper(in); } ); - uint32_t regs[4] {}; + std::for_each(vendorId.begin(), vendorId.end(), [](char& in) { in = ::toupper(in); }); + uint32_t regs[4]{}; cpuid::cpuid(0, 0, regs); uint32_t HFS = regs[0]; if (vendorId.find("INTEL") != std::string::npos) { if (HFS >= 0xb) { for (int lvl = 0; lvl < MAX_INTEL_TOP_LVL; ++lvl) { - uint32_t regs_2[4] {}; + uint32_t regs_2[4]{}; cpuid::cpuid(0x0b, lvl, regs_2); uint32_t currLevel = (LVL_TYPE & regs_2[2]) >> 8; if (currLevel == 0x02) { @@ -178,35 +178,38 @@ int CPU::getNumLogicalCores() { // _____________________________________________________________________________________________________________________ int CPU::getMaxClockSpeed_kHz() { - std::vector speed {}; + std::vector speed{}; wmi::queryWMI("Win32_Processor", "MaxClockSpeed", speed); - if (speed.empty()) { return -1; } + if (speed.empty()) { + return -1; + } return speed[0] * 1000; } // _____________________________________________________________________________________________________________________ int CPU::getRegularClockSpeed_kHz() { - std::vector speed {}; + std::vector speed{}; wmi::queryWMI("Win32_Processor", "CurrentClockSpeed", speed); - if (speed.empty()) { return -1; } + if (speed.empty()) { + return -1; + } return speed[0] * 1000; } int CPU::getCacheSize_Bytes() { - std::vector cacheSize {}; + std::vector cacheSize{}; wmi::queryWMI("Win32_Processor", "L3CacheSize", cacheSize); - if (cacheSize.empty()) { return -1; } + if (cacheSize.empty()) { + return -1; + } return cacheSize[0]; } - // ===================================================================================================================== // _____________________________________________________________________________________________________________________ // Helper function for linux: parses /proc/cpuinfo. socket_id == physical_id. // _____________________________________________________________________________________________________________________ -std::optional getCPU(uint8_t socket_id) { - return {}; -} +std::optional getCPU(uint8_t socket_id) { return {}; } // ===== Socket ======================================================================================================== // _____________________________________________________________________________________________________________________ @@ -218,9 +221,7 @@ Socket::Socket(uint8_t id) : _id(id) { } // _____________________________________________________________________________________________________________________ -Socket::Socket(uint8_t id, const class CPU& cpu) : _id(id) { - _cpu = cpu; -} +Socket::Socket(uint8_t id, const class CPU& cpu) : _id(id) { _cpu = cpu; } // ===================================================================================================================== // _____________________________________________________________________________________________________________________ diff --git a/src/windows/disk.cpp b/src/windows/disk.cpp index d836957..175a9ea 100644 --- a/src/windows/disk.cpp +++ b/src/windows/disk.cpp @@ -7,22 +7,24 @@ #include +#include "hwinfo/WMIwrapper.h" #include "hwinfo/disk.h" #include "hwinfo/utils/stringutils.h" -#include "hwinfo/WMIwrapper.h" namespace hwinfo { // _____________________________________________________________________________________________________________________ std::vector getAllDisks() { std::vector disks; - std::vector res {}; + std::vector res{}; wmi::queryWMI("Win32_DiskDrive", "Manufacturer", res); - if (res.empty()) { return {}; } - for (const auto &v: res) { + if (res.empty()) { + return {}; + } + for (const auto& v : res) { std::wstring tmp(v); disks.push_back(Disk()); - disks.back()._vendor = { tmp.begin(), tmp.end() }; + disks.back()._vendor = {tmp.begin(), tmp.end()}; } res.clear(); wmi::queryWMI("Win32_DiskDrive", "Model", res); @@ -31,7 +33,7 @@ std::vector getAllDisks() { break; } std::wstring tmp(res[i]); - disks[i]._model = { tmp.begin(), tmp.end() }; + disks[i]._model = {tmp.begin(), tmp.end()}; } res.clear(); wmi::queryWMI("Win32_DiskDrive", "SerialNumber", res); @@ -40,7 +42,7 @@ std::vector getAllDisks() { break; } std::wstring tmp(res[i]); - disks[i]._serialNumber = { tmp.begin(), tmp.end() }; + disks[i]._serialNumber = {tmp.begin(), tmp.end()}; } std::vector res2; // this returns a random same number for all disks... diff --git a/src/windows/gpu.cpp b/src/windows/gpu.cpp index 228f2c5..19b01be 100644 --- a/src/windows/gpu.cpp +++ b/src/windows/gpu.cpp @@ -5,8 +5,8 @@ #ifdef HWINFO_WINDOWS -#include #include +#include #include "hwinfo/WMIwrapper.h" #pragma comment(lib, "wbemuuid.lib") diff --git a/src/windows/mainboard.cpp b/src/windows/mainboard.cpp index 1fd062d..253f79e 100644 --- a/src/windows/mainboard.cpp +++ b/src/windows/mainboard.cpp @@ -10,7 +10,6 @@ #include "hwinfo/WMIwrapper.h" #include "hwinfo/mainboard.h" - namespace hwinfo { // _____________________________________________________________________________________________________________________ diff --git a/src/windows/os.cpp b/src/windows/os.cpp index 4edc2ea..02994b5 100644 --- a/src/windows/os.cpp +++ b/src/windows/os.cpp @@ -5,11 +5,11 @@ #ifdef HWINFO_WINDOWS -#include -#include - #include #include + +#include +#include #define STATUS_SUCCESS 0x00000000 #include "hwinfo/os.h" @@ -18,9 +18,15 @@ namespace hwinfo { // _____________________________________________________________________________________________________________________ std::string OS::getFullName() { - static NTSTATUS(__stdcall *RtlGetVersion)(OUT PRTL_OSVERSIONINFOEXW lpVersionInformation) = (NTSTATUS(__stdcall*)(PRTL_OSVERSIONINFOEXW))GetProcAddress(GetModuleHandle("ntdll.dll"), "RtlGetVersion"); - static void(__stdcall *GetNativeSystemInfo)(OUT LPSYSTEM_INFO lpSystemInfo) = (void(__stdcall*)(LPSYSTEM_INFO))GetProcAddress(GetModuleHandle("kernel32.dll"), "GetNativeSystemInfo"); - static BOOL(__stdcall *GetProductInfo)(IN DWORD dwOSMajorVersion, IN DWORD dwOSMinorVersion, IN DWORD dwSpMajorVersion, IN DWORD dwSpMinorVersion, OUT PDWORD pdwReturnedProductType) = (BOOL(__stdcall*)(DWORD, DWORD, DWORD, DWORD, PDWORD))GetProcAddress(GetModuleHandle("kernel32.dll"), "GetProductInfo"); + static NTSTATUS(__stdcall * RtlGetVersion)(OUT PRTL_OSVERSIONINFOEXW lpVersionInformation) = + (NTSTATUS(__stdcall*)(PRTL_OSVERSIONINFOEXW))GetProcAddress(GetModuleHandle("ntdll.dll"), "RtlGetVersion"); + static void(__stdcall * GetNativeSystemInfo)(OUT LPSYSTEM_INFO lpSystemInfo) = + (void(__stdcall*)(LPSYSTEM_INFO))GetProcAddress(GetModuleHandle("kernel32.dll"), "GetNativeSystemInfo"); + static BOOL(__stdcall * GetProductInfo)(IN DWORD dwOSMajorVersion, IN DWORD dwOSMinorVersion, + IN DWORD dwSpMajorVersion, IN DWORD dwSpMinorVersion, + OUT PDWORD pdwReturnedProductType) = + (BOOL(__stdcall*)(DWORD, DWORD, DWORD, DWORD, PDWORD))GetProcAddress(GetModuleHandle("kernel32.dll"), + "GetProductInfo"); OSVERSIONINFOEXW osvi; ZeroMemory(&osvi, sizeof(OSVERSIONINFOEXW)); @@ -34,7 +40,7 @@ std::string OS::getFullName() { } else { #if defined(_MSC_VER) #pragma warning(push) -#pragma warning(disable: 4996) // C4996: 'function': was declared deprecated +#pragma warning(disable : 4996) // C4996: 'function': was declared deprecated #endif BOOL bOsVersionInfoEx = GetVersionExW((OSVERSIONINFOW*)&osvi); if (bOsVersionInfoEx == 0) { @@ -83,8 +89,7 @@ std::string OS::getFullName() { if (osvi.dwMinorVersion == 3) { if (osvi.wProductType == VER_NT_WORKSTATION) { os << "Windows 8.1 "; - } - else { + } else { os << "Windows Server 2012 R2 "; } } else if (osvi.dwMinorVersion == 2) { @@ -177,17 +182,18 @@ std::string OS::getFullName() { } else if (osvi.wSuiteMask & VER_SUITE_WH_SERVER) { os << "Windows Home Server"; } else if ((osvi.wProductType == VER_NT_WORKSTATION) && - (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64)) { + (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64)) { os << "Windows XP Professional x64 Edition"; } else { os << "Windows Server 2003, "; - } if (osvi.wProductType != VER_NT_WORKSTATION) { - if (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_IA64) { - if (osvi.wSuiteMask & VER_SUITE_DATACENTER) { - os << "Datacenter Edition for Itanium-based Systems"; - } else if (osvi.wSuiteMask & VER_SUITE_ENTERPRISE) { - os << "Enterprise Edition for Itanium-based Systems"; - } + } + if (osvi.wProductType != VER_NT_WORKSTATION) { + if (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_IA64) { + if (osvi.wSuiteMask & VER_SUITE_DATACENTER) { + os << "Datacenter Edition for Itanium-based Systems"; + } else if (osvi.wSuiteMask & VER_SUITE_ENTERPRISE) { + os << "Enterprise Edition for Itanium-based Systems"; + } } else if (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64) { if (osvi.wSuiteMask & VER_SUITE_DATACENTER) { os << "Datacenter x64 Edition"; @@ -236,19 +242,13 @@ std::string OS::getFullName() { } // _____________________________________________________________________________________________________________________ -std::string OS::getName() { - return "Windows"; -} +std::string OS::getName() { return "Windows"; } // _____________________________________________________________________________________________________________________ -std::string OS::getVersion() { - return ""; -} +std::string OS::getVersion() { return ""; } // _____________________________________________________________________________________________________________________ -std::string OS::getKernel() { - return ""; -} +std::string OS::getKernel() { return ""; } // _____________________________________________________________________________________________________________________ bool OS::getIs64bit() { diff --git a/src/windows/ram.cpp b/src/windows/ram.cpp index aa61df7..a2526e0 100644 --- a/src/windows/ram.cpp +++ b/src/windows/ram.cpp @@ -5,11 +5,11 @@ #ifdef HWINFO_WINDOWS +#include + #include #include -#include - #include "hwinfo/WMIwrapper.h" #include "hwinfo/ram.h"