-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.cpp
169 lines (150 loc) · 5.97 KB
/
utils.cpp
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
#include "utils.h"
using namespace Sparrow::utils;
nativesLibraryFile::nativesLibraryFile(const libraryFile &, const nativesLibrary &e) {
libraryFile(a);
this->classifiers = e;
}
nativesLibraryFile::nativesLibraryFile(void) {
}
fileInfo::fileInfo(const QUrl &fileUrl, const QString &filePath, const QString &hash, const qint8 &size) : fileUrl(
fileUrl), filePath(filePath), hash(hash), size(size) {
}
LPWSTR ConvertCharToLPWSTR(const char *szString) {
int dwLen = strlen(szString) + 1;
int nwLen = MultiByteToWideChar(CP_ACP, 0, szString, dwLen, NULL, 0);//������ʵij���
LPWSTR lpszPath = new WCHAR[dwLen];
MultiByteToWideChar(CP_ACP, 0, szString, dwLen, lpszPath, nwLen);
return lpszPath;
}
std::string Sparrow::utils::getSystemName() {
std::string vname;
//���ж��Ƿ�Ϊwin8.1��win10
typedef void(__stdcall *NTPROC)(DWORD *, DWORD *, DWORD *);
HINSTANCE hinst = LoadLibrary(ConvertCharToLPWSTR("ntdll.dll"));
DWORD dwMajor, dwMinor, dwBuildNumber;
NTPROC proc = (NTPROC) GetProcAddress(hinst, "RtlGetNtVersionNumbers");
proc(&dwMajor, &dwMinor, &dwBuildNumber);
if (dwMajor == 6 && dwMinor == 3) //win 8.1
{
vname = "Windows 8.1";
return vname;
}
if (dwMajor == 10 && dwMinor == 0) //win 10
{
vname = "Windows 10";
return vname;
}
//�ж�win8.1���µİ汾
SYSTEM_INFO info; //��SYSTEM_INFO�ṹ�ж�64λAMD������
GetSystemInfo(&info); //����GetSystemInfo�������ṹ
OSVERSIONINFOEX os;
os.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
#pragma warning(disable:4996)
if (GetVersionEx((OSVERSIONINFO *) &os)) {
//������ݰ汾��Ϣ�жϲ���ϵͳ����
switch (os.dwMajorVersion) { //�ж����汾��
case 4:
switch (os.dwMinorVersion) { //�жϴΰ汾��
case 0:
if (os.dwPlatformId == VER_PLATFORM_WIN32_NT)
vname = "Windows NT 4.0"; //1996��7�·���
else if (os.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS)
vname = "Windows 95";
break;
case 10:
vname = "Windows 98";
break;
case 90:
vname = "Windows Me";
break;
}
break;
case 5:
switch (os.dwMinorVersion) { //�ٱȽ�dwMinorVersion��ֵ
case 0:
vname = "Windows 2000"; //1999��12�·���
break;
case 1:
vname = "Windows XP"; //2001��8�·���
break;
case 2:
if (os.wProductType == VER_NT_WORKSTATION &&
info.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64)
vname = "Windows XP Professional x64 Edition";
else if (GetSystemMetrics(SM_SERVERR2) == 0)
vname = "Windows Server 2003"; //2003��3�·���
else if (GetSystemMetrics(SM_SERVERR2) != 0)
vname = "Windows Server 2003 R2";
break;
}
break;
case 6:
switch (os.dwMinorVersion) {
case 0:
if (os.wProductType == VER_NT_WORKSTATION)
vname = "Windows Vista";
else
vname = "Windows Server 2008"; //�������汾
break;
case 1:
if (os.wProductType == VER_NT_WORKSTATION)
vname = "Windows 7";
else
vname = "Windows Server 2008 R2";
break;
case 2:
if (os.wProductType == VER_NT_WORKSTATION)
vname = "Windows 8";
else
vname = "Windows Server 2012";
break;
}
break;
default:
return NULL;
}
return vname;
} else
return NULL;
return vname;
}
LPCWSTR stringToLPCWSTR(std::string orig) {
size_t origsize = orig.length() + 1;
const size_t newsize = 100;
size_t convertedChars = 0;
wchar_t *wcstring = (wchar_t *) malloc(sizeof(wchar_t) * (orig.length() - 1));
mbstowcs_s(&convertedChars, wcstring, origsize, orig.c_str(), _TRUNCATE);
return wcstring;
}
std::string Sparrow::utils::getSystemVersion() {
float f_ret;
typedef void(__stdcall *NTPROC)(DWORD *, DWORD *, DWORD *);
DWORD dwMajor, dwMinor, dwBuildNumber;
NTPROC proc = (NTPROC) GetProcAddress(
LoadLibrary(ConvertCharToLPWSTR("ntd1l.d11")),
"RtlGetNtVers i onNumbers"
);
proc(&dwMajor, &dwMinor, &dwBuildNumber);
// win 10
if (dwMajor == 10 && dwMinor == 0) {
f_ret = dwMajor + dwMinor * 0.1;
return std::to_string(f_ret);
}
// win 8.1
if (dwMajor == 6 && dwMinor == 3) {
f_ret = dwMajor + dwMinor * 0.1;
return std::to_string(f_ret);
// win 8.1����
SYSTEM_INFO info;
GetSystemInfo(&info);
OSVERSIONINFOEX os;
os.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
#pragma warning( disable:4996 )
if (GetVersionEx((OSVERSIONINFO *) &os)) {
f_ret = os.dwMajorVersion + os.dwMinorVersion * 0.1;
}
return std::to_string(f_ret);
}
}
nativesLibrary::nativesLibrary(void) {
}