cog/Frameworks/OpenMPT.old/OpenMPT/common/mptOS.h

305 lines
6.2 KiB
C
Raw Normal View History

2018-02-19 04:25:43 +00:00
/*
* 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
2019-01-24 02:16:37 +00:00
#include "BuildSettings.h"
2018-02-19 04:25:43 +00:00
#include "mptLibrary.h"
OPENMPT_NAMESPACE_BEGIN
2020-09-22 04:54:24 +00:00
#if defined(MODPLUG_TRACKER)
namespace mpt
{
namespace OS
{
enum class Class
{
Unknown,
Windows,
Linux,
Darwin,
BSD,
Haiku,
DOS,
};
mpt::OS::Class GetClassFromSysname(mpt::ustring sysname);
mpt::OS::Class GetClass();
} // namespace OS
} // namespace mpt
#endif // MODPLUG_TRACKER
2018-02-19 04:25:43 +00:00
namespace mpt
{
namespace Windows
{
2019-01-24 02:16:37 +00:00
2018-02-19 04:25:43 +00:00
class Version
{
public:
2019-01-24 02:16:37 +00:00
enum Number : uint64
2018-02-19 04:25:43 +00:00
{
2019-01-24 02:16:37 +00:00
WinNT4 = 0x0000000400000000ull,
Win2000 = 0x0000000500000000ull,
WinXP = 0x0000000500000001ull,
WinXP64 = 0x0000000500000002ull,
WinVista = 0x0000000600000000ull,
Win7 = 0x0000000600000001ull,
Win8 = 0x0000000600000002ull,
Win81 = 0x0000000600000003ull,
Win10 = 0x0000000a00000000ull,
WinNewer = Win10 + 1ull
};
2018-02-19 04:25:43 +00:00
2019-01-24 02:16:37 +00:00
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);
}
};
2018-02-19 04:25:43 +00:00
2019-01-24 02:16:37 +00:00
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);
}
2018-02-19 04:25:43 +00:00
};
2019-01-24 02:16:37 +00:00
typedef uint32 Build;
2020-09-22 04:54:24 +00:00
typedef uint32 TypeId;
2019-01-24 02:16:37 +00:00
static mpt::ustring VersionToString(mpt::Windows::Version::System version);
2018-02-19 04:25:43 +00:00
private:
2019-01-24 02:16:37 +00:00
bool m_SystemIsWindows;
2018-02-19 04:25:43 +00:00
2019-01-24 02:16:37 +00:00
System m_System;
ServicePack m_ServicePack;
Build m_Build;
2020-09-22 04:54:24 +00:00
TypeId m_Type;
2018-02-19 04:25:43 +00:00
private:
2019-01-24 02:16:37 +00:00
Version() noexcept;
2018-02-19 04:25:43 +00:00
public:
2019-01-24 02:16:37 +00:00
static Version NoWindows() noexcept;
2020-09-22 04:54:24 +00:00
Version(mpt::Windows::Version::System system, mpt::Windows::Version::ServicePack servicePack, mpt::Windows::Version::Build build, mpt::Windows::Version::TypeId type) noexcept;
2019-01-24 02:16:37 +00:00
public:
static mpt::Windows::Version Current() noexcept;
2018-02-19 04:25:43 +00:00
public:
2019-01-24 02:16:37 +00:00
bool IsWindows() const noexcept;
2018-02-19 04:25:43 +00:00
2019-01-24 02:16:37 +00:00
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;
2020-09-22 04:54:24 +00:00
mpt::Windows::Version::TypeId GetTypeId() const noexcept;
2018-02-19 04:25:43 +00:00
mpt::ustring GetName() const;
#ifdef MODPLUG_TRACKER
mpt::ustring GetNameShort() const;
#endif // MODPLUG_TRACKER
public:
2019-01-24 02:16:37 +00:00
static mpt::Windows::Version::System GetMinimumKernelLevel() noexcept;
static mpt::Windows::Version::System GetMinimumAPILevel() noexcept;
2018-02-19 04:25:43 +00:00
}; // class Version
2019-01-24 02:16:37 +00:00
#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
2018-02-19 04:25:43 +00:00
#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;
2019-01-24 02:16:37 +00:00
uint8 GetMajor() const;
uint8 GetMinor() const;
uint8 GetUpdate() const;
2018-02-19 04:25:43 +00:00
};
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;
2020-09-22 04:54:24 +00:00
mpt::OS::Class m_HostClass;
2018-02-19 04:25:43 +00:00
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; }
2020-09-22 04:54:24 +00:00
mpt::OS::Class HostClass() const { return m_HostClass; }
2018-02-19 04:25:43 +00:00
};
} // namespace Wine
} // namespace mpt
#endif // MODPLUG_TRACKER
OPENMPT_NAMESPACE_END