xbmc
SystemInfo.h
1 /*
2  * Copyright (C) 2005-2018 Team Kodi
3  * This file is part of Kodi - https://kodi.tv
4  *
5  * SPDX-License-Identifier: GPL-2.0-or-later
6  * See LICENSES/README.md for more information.
7  */
8 
9 #pragma once
10 
11 #include "InfoLoader.h"
12 #include "settings/ISubSettings.h"
13 
14 #include <string>
15 
16 #define KB (1024) // 1 KiloByte (1KB) 1024 Byte (2^10 Byte)
17 #define MB (1024*KB) // 1 MegaByte (1MB) 1024 KB (2^10 KB)
18 #define GB (1024*MB) // 1 GigaByte (1GB) 1024 MB (2^10 MB)
19 #define TB (1024*GB) // 1 TerraByte (1TB) 1024 GB (2^10 GB)
20 
21 #define MAX_KNOWN_ATTRIBUTES 46
22 
23 #define REG_CURRENT_VERSION L"Software\\Microsoft\\Windows NT\\CurrentVersion"
24 
25 
26 class CSysData
27 {
28 public:
29  enum INTERNET_STATE { UNKNOWN, CONNECTED, DISCONNECTED };
30  CSysData()
31  {
32  Reset();
33  };
34 
35  void Reset()
36  {
37  internetState = UNKNOWN;
38  };
39 
40  std::string systemUptime;
41  std::string systemTotalUptime;
42  INTERNET_STATE internetState;
43  std::string videoEncoder;
44  std::string cpuFrequency;
45  std::string osVersionInfo;
46  std::string macAddress;
47  std::string batteryLevel;
48 };
49 
50 class CSysInfoJob : public CJob
51 {
52 public:
53  CSysInfoJob();
54 
55  bool DoWork() override;
56  const CSysData &GetData() const;
57 
58  static CSysData::INTERNET_STATE GetInternetState();
59 private:
60  static bool SystemUpTime(int iInputMinutes, int &iMinutes, int &iHours, int &iDays);
61  static std::string GetSystemUpTime(bool bTotalUptime);
62  static std::string GetMACAddress();
63  static std::string GetVideoEncoder();
64  static std::string GetBatteryLevel();
65 
66  CSysData m_info;
67 };
68 
69 class CSysInfo : public CInfoLoader, public ISubSettings
70 {
71 public:
72  enum WindowsVersion
73  {
74  WindowsVersionUnknown = -1, // Undetected, unsupported Windows version or OS in not Windows
75  WindowsVersionWin8_1, // Windows 8.1, Windows Server 2012 R2
76  WindowsVersionWin10, // Windows 10
77  WindowsVersionWin10_1709, // Windows 10 1709 (FCU)
78  WindowsVersionWin10_1803, // Windows 10 1803
79  WindowsVersionWin10_1809, // Windows 10 1809
80  WindowsVersionWin10_1903, // Windows 10 1903
81  WindowsVersionWin10_1909, // Windows 10 1909
82  WindowsVersionWin10_2004, // Windows 10 2004
83  WindowsVersionWin10_Future, // Windows 10 future build
84  WindowsVersionWin11, // Windows 11
85  /* Insert new Windows versions here, when they'll be known */
86  WindowsVersionFuture = 100 // Future Windows version, not known to code
87  };
88  enum WindowsDeviceFamily
89  {
90  Mobile = 1,
91  Desktop = 2,
92  IoT = 3,
93  Xbox = 4,
94  Surface = 5,
95  Other = 100
96  };
97 
98  CSysInfo(void);
99  ~CSysInfo() override;
100 
101  bool Load(const TiXmlNode *settings) override;
102  bool Save(TiXmlNode *settings) const override;
103 
104  char MD5_Sign[32 + 1];
105 
106  static const std::string& GetAppName(void); // the same name as CCompileInfo::GetAppName(), but const ref to std::string
107 
108  static std::string GetKernelName(bool emptyIfUnknown = false);
109  static std::string GetKernelVersionFull(void); // full version string, including "-generic", "-RELEASE" etc.
110  static std::string GetKernelVersion(void); // only digits with dots
111  static std::string GetOsName(bool emptyIfUnknown = false);
112  static std::string GetOsVersion(void);
113  static std::string GetOsPrettyNameWithVersion(void);
114  static std::string GetUserAgent();
115  static std::string GetDeviceName();
116  static std::string GetVersion();
117  static std::string GetVersionShort();
118  static std::string GetVersionCode();
119  static std::string GetVersionGit();
120  static std::string GetBuildDate();
121 
122  bool HasInternet();
123  bool IsAeroDisabled();
124  static bool IsWindowsVersion(WindowsVersion ver);
125  static bool IsWindowsVersionAtLeast(WindowsVersion ver);
126  static WindowsVersion GetWindowsVersion();
127  static int GetKernelBitness(void);
128  static int GetXbmcBitness(void);
129  static const std::string& GetKernelCpuFamily(void);
130  static std::string GetManufacturerName(void);
131  static std::string GetModelName(void);
132  bool GetDiskSpace(std::string drive,int& iTotal, int& iTotalFree, int& iTotalUsed, int& iPercentFree, int& iPercentUsed);
133  std::string GetHddSpaceInfo(int& percent, int drive, bool shortText=false);
134  std::string GetHddSpaceInfo(int drive, bool shortText=false);
135 
136  int GetTotalUptime() const { return m_iSystemTimeTotalUp; }
137  void SetTotalUptime(int uptime) { m_iSystemTimeTotalUp = uptime; }
138 
139  static std::string GetBuildTargetPlatformName(void);
140  static std::string GetBuildTargetPlatformVersion(void);
141  static std::string GetBuildTargetPlatformVersionDecoded(void);
142  static std::string GetBuildTargetCpuFamily(void);
143 
144  static std::string GetUsedCompilerNameAndVer(void);
145  std::string GetPrivacyPolicy();
146 
147  static WindowsDeviceFamily GetWindowsDeviceFamily();
148 
149 protected:
150  CJob *GetJob() const override;
151  std::string TranslateInfo(int info) const override;
152  void OnJobComplete(unsigned int jobID, bool success, CJob *job) override;
153 
154 private:
155  CSysData m_info;
156  std::string m_privacyPolicy;
157  static WindowsVersion m_WinVer;
158  int m_iSystemTimeTotalUp; // Uptime in minutes!
159  void Reset();
160 };
161 
162 extern CSysInfo g_sysinfo;
163 
Base class for jobs that are executed asynchronously.
Definition: Job.h:109
Definition: InfoLoader.h:15
Definition: SystemInfo.h:50
Definition: SystemInfo.h:69
Definition: SystemInfo.h:26
Definition: settings.py:1
Interface defining methods to load additional setting values from an XML file being loaded by the set...
Definition: ISubSettings.h:18