File: mptOS.h

package info (click to toggle)
libopenmpt 0.4.3-1+deb10u1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 7,724 kB
  • sloc: cpp: 99,820; sh: 4,503; ansic: 3,449; makefile: 480
file content (274 lines) | stat: -rw-r--r-- 6,009 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
/*
 * mptOS.h
 * -------
 * Purpose: Operating system version information.
 * Notes  : (currently none)
 * Authors: OpenMPT Devs
 * The OpenMPT source code is released under the BSD license. Read LICENSE for more details.
 */


#pragma once

#include "BuildSettings.h"


#include "mptLibrary.h"


OPENMPT_NAMESPACE_BEGIN


namespace mpt
{
namespace Windows
{


class Version
{

public:

	enum Number : uint64
	{
		WinNT4   = 0x0000000400000000ull,
		Win2000  = 0x0000000500000000ull,
		WinXP    = 0x0000000500000001ull,
		WinXP64  = 0x0000000500000002ull,
		WinVista = 0x0000000600000000ull,
		Win7     = 0x0000000600000001ull,
		Win8     = 0x0000000600000002ull,
		Win81    = 0x0000000600000003ull,
		Win10    = 0x0000000a00000000ull,
		WinNewer = Win10 + 1ull
	};

	struct System
	{
		uint32 Major = 0;
		uint32 Minor = 0;
		System() = default;
		constexpr System(Number number) noexcept
			: Major(static_cast<uint32>((static_cast<uint64>(number) >> 32) & 0xffffffffu))
			, Minor(static_cast<uint32>((static_cast<uint64>(number) >>  0) & 0xffffffffu))
		{
		}
		explicit constexpr System(uint64 number) noexcept
			: Major(static_cast<uint32>((number >> 32) & 0xffffffffu))
			, Minor(static_cast<uint32>((number >>  0) & 0xffffffffu))
		{
		}
		explicit constexpr System(uint32 major, uint32 minor) noexcept
			: Major(major)
			, Minor(minor)
		{
		}
		constexpr operator uint64 () const noexcept
		{
			return (static_cast<uint64>(Major) << 32) | (static_cast<uint64>(Minor) << 0);
		}
	};

	struct ServicePack
	{
		uint16 Major = 0;
		uint16 Minor = 0;
		ServicePack() = default;
		explicit constexpr ServicePack(uint16 major, uint16 minor) noexcept
			: Major(major)
			, Minor(minor)
		{
		}
		constexpr bool HasServicePack() const noexcept
		{
			return Major != 0 || Minor != 0;
		}
		constexpr operator uint32 () const noexcept
		{
			return (static_cast<uint32>(Major) << 16) | (static_cast<uint32>(Minor) << 0);
		}
	};

	typedef uint32 Build;

	static mpt::ustring VersionToString(mpt::Windows::Version::System version);

private:

	bool m_SystemIsWindows;

	System m_System;
	ServicePack m_ServicePack;
	Build m_Build;

private:

	Version() noexcept;

public:

	static Version NoWindows() noexcept;

	Version(mpt::Windows::Version::System system, mpt::Windows::Version::ServicePack servicePack, mpt::Windows::Version::Build build) noexcept;

public:

	static mpt::Windows::Version Current() noexcept;

public:

	bool IsWindows() const noexcept;

	bool IsBefore(mpt::Windows::Version::System version) const noexcept;
	bool IsBefore(mpt::Windows::Version::System version, mpt::Windows::Version::ServicePack servicePack) const noexcept;
	bool IsBefore(mpt::Windows::Version::System version, mpt::Windows::Version::Build build) const noexcept;

	bool IsAtLeast(mpt::Windows::Version::System version) const noexcept;
	bool IsAtLeast(mpt::Windows::Version::System version, mpt::Windows::Version::ServicePack servicePack) const noexcept;
	bool IsAtLeast(mpt::Windows::Version::System version, mpt::Windows::Version::Build build) const noexcept;

	mpt::Windows::Version::System GetSystem() const noexcept;
	mpt::Windows::Version::ServicePack GetServicePack() const noexcept;
	mpt::Windows::Version::Build GetBuild() const noexcept;

	mpt::ustring GetName() const;
#ifdef MODPLUG_TRACKER
	mpt::ustring GetNameShort() const;
#endif // MODPLUG_TRACKER

public:

	static mpt::Windows::Version::System GetMinimumKernelLevel() noexcept;
	static mpt::Windows::Version::System GetMinimumAPILevel() noexcept;

}; // class Version

#if defined(MODPLUG_TRACKER) && MPT_OS_WINDOWS

enum class Architecture
{
	unknown = -1,

	x86     = 0x0401,
	amd64   = 0x0801,
	arm     = 0x0402,
	arm64   = 0x0802,

	mips    = 0x0403,
	ppc     = 0x0404,
	shx     = 0x0405,

	alpha   = 0x0406,
	alpha64 = 0x0806,

	ia64    = 0x0807,
};

enum class EmulationLevel
{
	Native,
	Virtual,
	Hardware,
	Software,
	NA,
};

int Bitness(Architecture arch) noexcept;

mpt::ustring Name(Architecture arch);

Architecture GetHostArchitecture() noexcept;
Architecture GetProcessArchitecture() noexcept;

EmulationLevel HostCanRun(Architecture host, Architecture process) noexcept;

std::vector<Architecture> GetSupportedProcessArchitectures(Architecture host);

uint64 GetSystemMemorySize();

#endif // MODPLUG_TRACKER && MPT_OS_WINDOWS


#if defined(MODPLUG_TRACKER)

void PreventWineDetection();

bool IsOriginal();
bool IsWine();

#endif // MODPLUG_TRACKER

} // namespace Windows
} // namespace mpt


#if defined(MODPLUG_TRACKER)

namespace mpt
{

namespace Wine
{

class Version
{
private:
	bool valid;
	uint8 vmajor;
	uint8 vminor;
	uint8 vupdate;
public:
	Version();
	Version(uint8 vmajor, uint8 vminor, uint8 vupdate);
	explicit Version(const mpt::ustring &version);
public:
	bool IsValid() const;
	mpt::ustring AsString() const;
private:
	static mpt::Wine::Version FromInteger(uint32 version);
	uint32 AsInteger() const;
public:
	bool IsBefore(mpt::Wine::Version other) const;
	bool IsAtLeast(mpt::Wine::Version other) const;
	uint8 GetMajor() const;
	uint8 GetMinor() const;
	uint8 GetUpdate() const;
};

mpt::Wine::Version GetMinimumWineVersion();

class VersionContext
{
protected:
	bool m_IsWine;
	mpt::Library m_NTDLL;
	std::string m_RawVersion;
	std::string m_RawBuildID;
	std::string m_RawHostSysName;
	std::string m_RawHostRelease;
	mpt::Wine::Version m_Version;
	bool m_HostIsLinux;
	bool m_HostIsBSD;
public:
	VersionContext();
public:
	bool IsWine() const { return m_IsWine; }
	mpt::Library NTDLL() const { return m_NTDLL; }
	std::string RawVersion() const { return m_RawVersion; }
	std::string RawBuildID() const { return m_RawBuildID; }
	std::string RawHostSysName() const { return m_RawHostSysName; }
	std::string RawHostRelease() const { return m_RawHostRelease; }
	mpt::Wine::Version Version() const { return m_Version; }
	bool HostIsLinux() const { return m_HostIsLinux; }
	bool HostIsBSD() const { return m_HostIsBSD; }
};

} // namespace Wine

} // namespace mpt

#endif // MODPLUG_TRACKER


OPENMPT_NAMESPACE_END