forked from myfreeer/aria2-build-msys2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
aria2-0006-feature-config-add-os-info-for-newer-windows.patch
146 lines (140 loc) · 4.19 KB
/
aria2-0006-feature-config-add-os-info-for-newer-windows.patch
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
From d36a15f8330057cee7c32b4035c8824bb03787af Mon Sep 17 00:00:00 2001
From: myfreeer <[email protected]>
Date: Fri, 10 Aug 2018 11:31:06 +0800
Subject: [PATCH] FeatureConfig: add os info for newer windows
getOperatingSystemInfo: partial refactor
replace GetVersionEx with RtlGetVersion, and link with ntdll
---
configure.ac | 2 +-
src/FeatureConfig.cc | 69 +++++++++++++++++++++++++++-----------------
src/FeatureConfig.h | 14 +++++++++
3 files changed, 58 insertions(+), 27 deletions(-)
diff --git a/configure.ac b/configure.ac
index 1ab1d32..55c5c07 100644
--- a/configure.ac
+++ b/configure.ac
@@ -34,7 +34,7 @@ EXTRALIBS=
case "$host" in
*mingw*)
win_build=yes
- EXTRALIBS="-lws2_32 -lwsock32 -lgdi32 -lwinmm -liphlpapi -lpsapi $EXTRALIBS"
+ EXTRALIBS="-lws2_32 -lwsock32 -lgdi32 -lwinmm -liphlpapi -lpsapi -lntdll $EXTRALIBS"
# Define _POSIX_C_SOURCE to 1. This makes {asc,local}time_r
# available from <time.h> even without (un)helpful interference
# from <pthread.h>, and also defines __USE_MINGW_ANSI_STDIO.
diff --git a/src/FeatureConfig.cc b/src/FeatureConfig.cc
index 2b43c8b..e477aa9 100644
--- a/src/FeatureConfig.cc
+++ b/src/FeatureConfig.cc
@@ -305,8 +305,8 @@ std::string getOperatingSystemInfo()
#ifdef _WIN32
std::stringstream rv;
rv << "Windows ";
- OSVERSIONINFOEX ovi = {sizeof(OSVERSIONINFOEX)};
- if (!GetVersionEx((LPOSVERSIONINFO)&ovi)) {
+ RTL_OSVERSIONINFOEXW ovi = {sizeof(RTL_OSVERSIONINFOEXW)};
+ if (RtlGetVersion((PRTL_OSVERSIONINFOEXW)&ovi) != STATUS_SUCCESS) {
rv << "Unknown";
return rv.str();
}
@@ -314,37 +314,54 @@ std::string getOperatingSystemInfo()
rv << "Legacy, probably XP";
return rv.str();
}
- switch (ovi.dwMinorVersion) {
- case 0:
- if (ovi.wProductType == VER_NT_WORKSTATION) {
+ DWORD dwVersion = (ovi.dwMajorVersion << 24U) | (ovi.dwMinorVersion << 8U) |
+ ovi.wProductType;
+#define WIN32_VERSION(major, minor, type) \
+ ((major##U << 24U) | (minor##U << 8U) | type)
+ switch (dwVersion) {
+ case WIN32_VERSION(6, 0, VER_NT_WORKSTATION):
rv << "Vista";
- }
- else {
+ break;
+ case WIN32_VERSION(6, 0, VER_NT_SERVER):
rv << "Server 2008";
- }
- break;
-
- case 1:
- if (ovi.wProductType == VER_NT_WORKSTATION) {
+ break;
+ case WIN32_VERSION(6, 1, VER_NT_WORKSTATION):
rv << "7";
- }
- else {
+ break;
+ case WIN32_VERSION(6, 1, VER_NT_SERVER):
rv << "Server 2008 R2";
- }
- break;
-
+ break;
+ case WIN32_VERSION(6, 2, VER_NT_WORKSTATION):
+ rv << "8";
+ break;
+ case WIN32_VERSION(6, 2, VER_NT_SERVER):
+ rv << "Server 2012";
+ break;
+ case WIN32_VERSION(6, 3, VER_NT_WORKSTATION):
+ rv << "8.1";
+ break;
+ case WIN32_VERSION(6, 3, VER_NT_SERVER):
+ rv << "Server 2012 R2";
+ break;
+ case WIN32_VERSION(10, 0, VER_NT_WORKSTATION):
+ rv << "10";
+ break;
+ case WIN32_VERSION(10, 0, VER_NT_SERVER):
+ rv << "Server 2016";
+ break;
default:
- // Windows above 6.2 does not actually say so. :p
+ // Windows above 6.2 does not actually say so. :p
- rv << ovi.dwMajorVersion;
- if (ovi.dwMinorVersion) {
- rv << "." << ovi.dwMinorVersion;
- }
- if (ovi.wProductType != VER_NT_WORKSTATION) {
- rv << " Server";
- }
- break;
+ rv << ovi.dwMajorVersion;
+ if (ovi.dwMinorVersion) {
+ rv << "." << ovi.dwMinorVersion;
+ }
+ if (ovi.wProductType != VER_NT_WORKSTATION) {
+ rv << " Server";
+ }
+ break;
}
+#undef WIN32_VERSION
if (ovi.szCSDVersion[0]) {
rv << " (" << ovi.szCSDVersion << ")";
}
diff --git a/src/FeatureConfig.h b/src/FeatureConfig.h
index 214dca2..55a3975 100644
--- a/src/FeatureConfig.h
+++ b/src/FeatureConfig.h
@@ -76,4 +76,18 @@ std::string getOperatingSystemInfo();
} // namespace aria2
+#ifdef _WIN32
+
+typedef LONG NTSTATUS;
+
+#ifndef STATUS_SUCCESS
+#define STATUS_SUCCESS ((NTSTATUS)0x00000000L) // ntsubauth
+#endif
+
+extern "C" NTSYSAPI NTSTATUS NTAPI RtlGetVersion(
+ _Out_ PRTL_OSVERSIONINFOEXW lpVersionInformation
+);
+
+#endif // _WIN32
+
#endif // D_FEATURE_CONFIG_H
--
2.18.0