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 #include "utils/Job.h"
14 
15 #include <string>
16 #include <vector>
17 
18 #define KB (1024) // 1 KiloByte (1KB) 1024 Byte (2^10 Byte)
19 #define MB (1024*KB) // 1 MegaByte (1MB) 1024 KB (2^10 KB)
20 #define GB (1024*MB) // 1 GigaByte (1GB) 1024 MB (2^10 MB)
21 #define TB (1024*GB) // 1 TerraByte (1TB) 1024 GB (2^10 GB)
22 
23 #define MAX_KNOWN_ATTRIBUTES 46
24 
25 #define REG_CURRENT_VERSION L"Software\\Microsoft\\Windows NT\\CurrentVersion"
26 
27 
28 class CSysData
29 {
30 public:
31  enum INTERNET_STATE { UNKNOWN, CONNECTED, DISCONNECTED };
32  CSysData()
33  {
34  Reset();
35  };
36 
37  void Reset()
38  {
39  internetState = UNKNOWN;
40  };
41 
42  std::string systemUptime;
43  std::string systemTotalUptime;
44  INTERNET_STATE internetState;
45  std::string videoEncoder;
46  std::string cpuFrequency;
47  std::string osVersionInfo;
48  std::string macAddress;
49  std::string ipAddress;
50  std::string netMask;
51  std::string gatewayAddress;
52  std::string networkLinkState;
53  std::vector<std::string> dnsServers;
54  std::string batteryLevel;
55 };
56 
57 class CSysInfoJob : public CJob
58 {
59 public:
60  CSysInfoJob();
61 
62  bool DoWork() override;
63  const CSysData &GetData() const;
64 
65  static CSysData::INTERNET_STATE GetInternetState();
66 private:
67  static bool SystemUpTime(int iInputMinutes, int &iMinutes, int &iHours, int &iDays);
68  static std::string GetSystemUpTime(bool bTotalUptime);
69  static std::string GetMACAddress();
70  static std::string GetIPAddress();
71  static std::string GetNetMask();
72  static std::string GetGatewayAddress();
73  static std::string GetNetworkLinkState();
74  static std::string GetVideoEncoder();
75  static std::string GetBatteryLevel();
76  static std::vector<std::string> GetDNSServers();
77 
78  CSysData m_info;
79 };
80 
81 class CSysInfo : public CInfoLoader, public ISubSettings
82 {
83 public:
84  enum WindowsVersion
85  {
86  // clang-format off
87  WindowsVersionUnknown = -1, // Undetected, unsupported Windows version or OS in not Windows
88  WindowsVersionWin8_1, // Windows 8.1, Windows Server 2012 R2
89  WindowsVersionWin10, // Windows 10
90  WindowsVersionWin10_1607, // Windows 10 1607
91  WindowsVersionWin10_1703, // Windows 10 1703 - Creators Update
92  WindowsVersionWin10_1709, // Windows 10 1709 - Fall Creators Update
93  WindowsVersionWin10_1803, // Windows 10 1803
94  WindowsVersionWin10_1809, // Windows 10 1809
95  WindowsVersionWin10_1903, // Windows 10 1903
96  WindowsVersionWin10_1909, // Windows 10 1909
97  WindowsVersionWin10_2004, // Windows 10 2004
98  WindowsVersionWin10_20H2, // Windows 10 20H2
99  WindowsVersionWin10_21H1, // Windows 10 21H1
100  WindowsVersionWin10_21H2, // Windows 10 21H2
101  WindowsVersionWin10_22H2, // Windows 10 22H2
102  WindowsVersionWin10_Future, // Windows 10 future build
103  WindowsVersionWin11_21H2, // Windows 11 21H2 - Sun Valley
104  WindowsVersionWin11_22H2, // Windows 11 22H2 - Sun Valley 2
105  WindowsVersionWin11_Future, // Windows 11 future build
106  /* Insert new Windows versions here, when they'll be known */
107  WindowsVersionFuture = 100 // Future Windows version, not known to code
108  // clang-format on
109  };
110  enum WindowsDeviceFamily
111  {
112  Mobile = 1,
113  Desktop = 2,
114  IoT = 3,
115  Xbox = 4,
116  Surface = 5,
117  Other = 100
118  };
119 
120  CSysInfo(void);
121  ~CSysInfo() override;
122 
123  bool Load(const TiXmlNode *settings) override;
124  bool Save(TiXmlNode *settings) const override;
125 
126  char MD5_Sign[32 + 1];
127 
128  static const std::string& GetAppName(void); // the same name as CCompileInfo::GetAppName(), but const ref to std::string
129 
130  static std::string GetKernelName(bool emptyIfUnknown = false);
131  static std::string GetKernelVersionFull(void); // full version string, including "-generic", "-RELEASE" etc.
132  static std::string GetKernelVersion(void); // only digits with dots
133  static std::string GetOsName(bool emptyIfUnknown = false);
134  static std::string GetOsVersion(void);
135  static std::string GetOsPrettyNameWithVersion(void);
136  static std::string GetUserAgent();
137  static std::string GetDeviceName();
138  static std::string GetVersion();
139  static std::string GetVersionShort();
140  static std::string GetVersionCode();
141  static std::string GetVersionGit();
142  static std::string GetBuildDate();
143 
144  bool HasInternet();
145  bool IsAeroDisabled();
146  static bool IsWindowsVersion(WindowsVersion ver);
147  static bool IsWindowsVersionAtLeast(WindowsVersion ver);
148  static WindowsVersion GetWindowsVersion();
149  static int GetKernelBitness(void);
150  static int GetXbmcBitness(void);
151  static const std::string& GetKernelCpuFamily(void);
152  static std::string GetManufacturerName(void);
153  static std::string GetModelName(void);
154  bool GetDiskSpace(std::string drive,int& iTotal, int& iTotalFree, int& iTotalUsed, int& iPercentFree, int& iPercentUsed);
155  std::string GetHddSpaceInfo(int& percent, int drive, bool shortText=false);
156  std::string GetHddSpaceInfo(int drive, bool shortText=false);
157 
158  int GetTotalUptime() const { return m_iSystemTimeTotalUp; }
159  void SetTotalUptime(int uptime) { m_iSystemTimeTotalUp = uptime; }
160 
161  static std::string GetBuildTargetPlatformName(void);
162  static std::string GetBuildTargetPlatformVersion(void);
163  static std::string GetBuildTargetPlatformVersionDecoded(void);
164  static std::string GetBuildTargetCpuFamily(void);
165 
166  static std::string GetUsedCompilerNameAndVer(void);
167  std::string GetPrivacyPolicy();
168 
169  static WindowsDeviceFamily GetWindowsDeviceFamily();
170 
171 protected:
172  CJob *GetJob() const override;
173  std::string TranslateInfo(int info) const override;
174  void OnJobComplete(unsigned int jobID, bool success, CJob *job) override;
175 
176 private:
177  CSysData m_info;
178  std::string m_privacyPolicy;
179  static WindowsVersion m_WinVer;
180  int m_iSystemTimeTotalUp; // Uptime in minutes!
181  void Reset();
182 };
183 
184 extern CSysInfo g_sysinfo;
185 
Base class for jobs that are executed asynchronously.
Definition: Job.h:109
Definition: InfoLoader.h:15
Definition: SystemInfo.h:57
Definition: SystemInfo.h:81
Definition: SystemInfo.h:28
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