Debian Codegraph @

src/mpt/osinfo/windows_wine_version.hpp

raw
1 /* SPDX-License-Identifier: BSL-1.0 OR BSD-3-Clause */
2
3 #ifndef MPT_OSINFO_WINDOWS_WINE_VERSION_HPP
4 #define MPT_OSINFO_WINDOWS_WINE_VERSION_HPP
5
6
7
8 #include "mpt/base/detect.hpp"
9 #include "mpt/base/integer.hpp"
10 #include "mpt/base/macros.hpp"
11 #include "mpt/base/namespace.hpp"
12 #include "mpt/osinfo/windows_version.hpp"
13
14 #if MPT_OS_WINDOWS
15 #include <windows.h>
16 #endif // MPT_OS_WINDOWS
17
18
19
20 namespace mpt {
21 inline namespace MPT_INLINE_NS {
22
23
24
25 namespace osinfo {
26
27 namespace windows {
28
29
30
31 inline bool current_is_wine() {
32 bool result = false;
33 #if MPT_OS_WINDOWS && !MPT_OS_WINDOWS_WINRT
34 bool hasKB2533623 = false;
35 mpt::osinfo::windows::Version WindowsVersion = mpt::osinfo::windows::Version::Current();
36 if (WindowsVersion.IsAtLeast(mpt::osinfo::windows::Version::Win8)) {
37 hasKB2533623 = true;
38 } else if (WindowsVersion.IsAtLeast(mpt::osinfo::windows::Version::WinVista)) {
39 HMODULE hKernel32DLL = ::LoadLibrary(TEXT("kernel32.dll"));
40 if (hKernel32DLL) {
41 if (::GetProcAddress(hKernel32DLL, "SetDefaultDllDirectories") != nullptr) {
42 hasKB2533623 = true;
43 }
44 ::FreeLibrary(hKernel32DLL);
45 hKernel32DLL = NULL;
46 }
47 }
48 HMODULE hNTDLL = NULL;
49 MPT_MAYBE_CONSTANT_IF (hasKB2533623) {
50 #if defined(LOAD_LIBRARY_SEARCH_SYSTEM32)
51 hNTDLL = ::LoadLibraryEx(TEXT("ntdll.dll"), NULL, LOAD_LIBRARY_SEARCH_SYSTEM32);
52 #else
53 hNTDLL = ::LoadLibraryEx(TEXT("ntdll.dll"), NULL, 0x00000800);
54 #endif
55 } else {
56 hNTDLL = ::LoadLibrary(TEXT("ntdll.dll"));
57 }
58 if (hNTDLL) {
59 result = (::GetProcAddress(hNTDLL, "wine_get_version") != NULL);
60 ::FreeLibrary(hNTDLL);
61 }
62 #endif // MPT_OS_WINDOWS && !MPT_OS_WINDOWS_WINRT
63 return result;
64 }
65
66
67
68 namespace wine {
69
70 class version {
71 protected:
72 bool valid = false;
73 uint8 vmajor = 0;
74 uint8 vminor = 0;
75 uint8 vupdate = 0;
76
77 public:
78 version() {
79 return;
80 }
81 version(uint8 vmajor_, uint8 vminor_, uint8 vupdate_)
82 : valid(true)
83 , vmajor(vmajor_)
84 , vminor(vminor_)
85 , vupdate(vupdate_) {
86 return;
87 }
88
89 public:
90 bool IsValid() const {
91 return valid;
92 }
93
94 private:
95 static mpt::osinfo::windows::wine::version FromInteger(uint32 version) {
96 mpt::osinfo::windows::wine::version result;
97 result.valid = (version <= 0xffffff);
98 result.vmajor = static_cast<uint8>(version >> 16);
99 result.vminor = static_cast<uint8>(version >> 8);
100 result.vupdate = static_cast<uint8>(version >> 0);
101 return result;
102 }
103 uint32 AsInteger() const {
104 uint32 version = 0;
105 version |= static_cast<uint32>(vmajor) << 16;
106 version |= static_cast<uint32>(vminor) << 8;
107 version |= static_cast<uint32>(vupdate) << 0;
108 return version;
109 }
110
111 public:
112 bool IsBefore(mpt::osinfo::windows::wine::version other) const {
113 if (!IsValid()) {
114 return false;
115 }
116 return (AsInteger() < other.AsInteger());
117 }
118 bool IsAtLeast(mpt::osinfo::windows::wine::version other) const {
119 if (!IsValid()) {
120 return false;
121 }
122 return (AsInteger() >= other.AsInteger());
123 }
124 uint8 GetMajor() const {
125 return vmajor;
126 }
127 uint8 GetMinor() const {
128 return vminor;
129 }
130 uint8 GetUpdate() const {
131 return vupdate;
132 }
133 };
134
135 } // namespace wine
136
137
138
139 } // namespace windows
140
141 } // namespace osinfo
142
143
144
145 } // namespace MPT_INLINE_NS
146 } // namespace mpt
147
148
149
150 #endif // MPT_OSINFO_WINDOWS_WINE_VERSION_HPP