winget-cli

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

OSInfo.cpp (1388B)


      1 // Copyright (c) Microsoft Corporation.
      2 // Licensed under the MIT License.
      3 
      4 #include "OSInfo.h"
      5 
      6 #ifdef _WIN32
      7 
      8 #include <windows.h>
      9 
     10 #include <sysinfoapi.h>
     11 
     12 #elif __linux__
     13 
     14 #include <sys/utsname.h>
     15 
     16 #endif
     17 
     18 using namespace SFS::details;
     19 
     20 namespace
     21 {
     22 #ifdef _WIN32
     23 std::string GetPlatform()
     24 {
     25     return "Windows";
     26 }
     27 
     28 std::string GetOSMachineInfo()
     29 {
     30     SYSTEM_INFO systemInfo;
     31     GetNativeSystemInfo(&systemInfo);
     32 
     33     switch (systemInfo.wProcessorArchitecture)
     34     {
     35     case PROCESSOR_ARCHITECTURE_AMD64:
     36         return "x64";
     37     case PROCESSOR_ARCHITECTURE_ARM:
     38         return "ARM";
     39     case PROCESSOR_ARCHITECTURE_ARM64:
     40         return "ARM64";
     41     case PROCESSOR_ARCHITECTURE_INTEL:
     42         return "x86";
     43     default:
     44         return "Unknown";
     45     }
     46 }
     47 
     48 #elif __linux__
     49 
     50 std::string GetPlatform()
     51 {
     52     // Return kernel name, usually "Linux"
     53     utsname buf;
     54     if (uname(&buf) >= 0)
     55     {
     56         return buf.sysname;
     57     }
     58     return "Unknown";
     59 }
     60 
     61 std::string GetOSMachineInfo()
     62 {
     63     utsname buf;
     64     if (uname(&buf) >= 0)
     65     {
     66         return buf.machine;
     67     }
     68     return "Unknown";
     69 }
     70 
     71 #else
     72 #error "Unsupported platform"
     73 #endif
     74 } // namespace
     75 
     76 std::string osinfo::GetPlatform()
     77 {
     78     return ::GetPlatform();
     79 }
     80 
     81 std::string osinfo::GetOSMachineInfo()
     82 {
     83     return ::GetOSMachineInfo();
     84 }