Left: | ||
Right: |
OLD | NEW |
---|---|
1 #include <memory> | 1 #include <memory> |
2 #include <stdexcept> | 2 #include <stdexcept> |
3 #include <vector> | 3 #include <vector> |
4 | 4 |
5 #include <Windows.h> | 5 #include <Windows.h> |
6 #include <ShlObj.h> | 6 #include <ShlObj.h> |
7 | 7 |
8 #include "Utils.h" | 8 #include "Utils.h" |
9 | 9 |
10 namespace | 10 namespace |
11 { | 11 { |
12 // See http://blogs.msdn.com/b/oldnewthing/archive/2004/10/25/247180.aspx | 12 // See http://blogs.msdn.com/b/oldnewthing/archive/2004/10/25/247180.aspx |
13 EXTERN_C IMAGE_DOS_HEADER __ImageBase; | 13 EXTERN_C IMAGE_DOS_HEADER __ImageBase; |
14 | 14 |
15 std::wstring appDataPath; | 15 std::wstring appDataPath; |
16 | 16 |
17 } | 17 } |
18 | 18 |
19 bool IsWindowsVistaOrLater() | 19 bool IsWindowsVistaOrLater() |
20 { | 20 { |
21 OSVERSIONINFOEX osvi; | 21 OSVERSIONINFOEX osvi; |
22 ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX)); | 22 ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX)); |
23 osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); | 23 osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); |
24 GetVersionEx(reinterpret_cast<LPOSVERSIONINFO>(&osvi)); | 24 GetVersionEx(reinterpret_cast<LPOSVERSIONINFO>(&osvi)); |
25 return osvi.dwMajorVersion >= 6; | 25 return osvi.dwMajorVersion >= 6; |
26 } | 26 } |
27 | 27 |
28 bool IsAppContainersSupported() | 28 bool IsWindows8OrLater() |
Eric
2014/06/25 16:13:00
How about combining the duplicated code to get the
| |
29 { | 29 { |
30 //Try to allocate SID of AppContainer and see if it's succesful | 30 OSVERSIONINFOEX osvi; |
31 PSID allAppContainersSid = 0; | 31 ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX)); |
32 SID_IDENTIFIER_AUTHORITY applicationAuthority = SECURITY_APP_PACKAGE_AUTHORITY ; | 32 osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); |
33 BOOL res = AllocateAndInitializeSid(&applicationAuthority, | 33 GetVersionEx(reinterpret_cast<LPOSVERSIONINFO>(&osvi)); |
34 SECURITY_BUILTIN_APP_PACKAGE_RID_COUNT, | 34 return osvi.dwMajorVersion >= 6 && osvi.dwMinorVersion >= 2; |
Wladimir Palant
2014/05/15 07:36:18
So if dwMajorVersion is 7 and dwMinorVersion is 0
| |
35 SECURITY_APP_PACKAGE_BASE_RID, | |
36 SECURITY_BUILTIN_PACKAGE_ANY_PACKAGE, | |
37 0, 0, 0, 0, 0, 0, | |
38 &allAppContainersSid); | |
39 | |
40 if (res == FALSE) | |
41 { | |
42 return false; | |
43 } | |
44 else | |
45 { | |
46 FreeSid(allAppContainersSid); | |
47 return true; | |
48 } | |
49 } | 35 } |
50 | 36 |
51 std::string ToUtf8String(const std::wstring& str) | 37 std::string ToUtf8String(const std::wstring& str) |
52 { | 38 { |
53 int length = static_cast<int>(str.size()); | 39 int length = static_cast<int>(str.size()); |
54 if (length == 0) | 40 if (length == 0) |
55 return std::string(); | 41 return std::string(); |
56 | 42 |
57 int utf8StringLength = WideCharToMultiByte(CP_UTF8, 0, str.c_str(), length, 0, 0, 0, 0); | 43 int utf8StringLength = WideCharToMultiByte(CP_UTF8, 0, str.c_str(), length, 0, 0, 0, 0); |
58 if (utf8StringLength == 0) | 44 if (utf8StringLength == 0) |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
135 } | 121 } |
136 | 122 |
137 void ReplaceString(std::wstring& input, const std::wstring placeholder, const st d::wstring replacement) | 123 void ReplaceString(std::wstring& input, const std::wstring placeholder, const st d::wstring replacement) |
138 { | 124 { |
139 size_t replaceStart = input.find(placeholder); | 125 size_t replaceStart = input.find(placeholder); |
140 if (replaceStart != std::string::npos) | 126 if (replaceStart != std::string::npos) |
141 { | 127 { |
142 input.replace(replaceStart, placeholder.length(), replacement); | 128 input.replace(replaceStart, placeholder.length(), replacement); |
143 } | 129 } |
144 } | 130 } |
OLD | NEW |