OLD | NEW |
(Empty) | |
| 1 #include "IE_version.h" |
| 2 #include "Registry.h" |
| 3 #include <cstdlib> |
| 4 |
| 5 using namespace AdblockPlus; |
| 6 |
| 7 /** |
| 8 * Internal implementation of the IE version string. |
| 9 * |
| 10 * This version throws exceptions for its errors, relying on its caller to handl
e them. |
| 11 * |
| 12 * Quoting http://support.microsoft.com/kb/969393: |
| 13 * "Note The version string value for Internet Explorer 10 is 9.10.9200.16384,
and the svcVersion string value is 10.0.9200.16384." |
| 14 * [EH 2014-06-20] My current version of IE 11 is reporting these values: |
| 15 * Version 9.11.9600.17041 |
| 16 * svcVersion 11.0.9600.17041 |
| 17 * |
| 18 * Warning: IE version 12 and later might not behave the same, so this function
should be reviewed with each new release. |
| 19 * |
| 20 * \par postcondition |
| 21 * Return value matches regex `^[0-9]{1,2}\.$`; this is a sanity check on the
format. |
| 22 */ |
| 23 std::wstring IE_version_string() |
| 24 { |
| 25 Registry_Key IE_key(HKEY_LOCAL_MACHINE, L"Software\\Microsoft\\Internet Explor
er"); |
| 26 std::wstring version(IE_key.value_wstring(L"Version")); |
| 27 /* |
| 28 * We're expecting a version string that matches the regex "^[1-9]\.". |
| 29 * Since IE versions 10 and 11 use a version string that begins with "9.", thi
s simplistic parsing method works adequately. |
| 30 */ |
| 31 if (version.length() < 2 || version[1] != '.' || version[0] < L'0' || version[
0] > L'9') |
| 32 { |
| 33 throw std::runtime_error("IE version string has unexpected format"); |
| 34 } |
| 35 if (version[0] != L'9') |
| 36 { |
| 37 return version; |
| 38 } |
| 39 // Assert the major version in the "Version" value is 9. |
| 40 /* |
| 41 * Version 9 might either be an actual version 9 or it might represent a versi
on >= 10 |
| 42 * If the value named "svcVersion" exists, we'll report that instead. |
| 43 */ |
| 44 try |
| 45 { |
| 46 version = IE_key.value_wstring(L"svcVersion"); // throws if value not found |
| 47 } |
| 48 catch (...) |
| 49 { |
| 50 // Assert svcVersion value not found |
| 51 // Thus the major version is 9 |
| 52 return version; |
| 53 } |
| 54 // Assert major version is >= 10 |
| 55 if (version.length() < 3 || version[0] < L'0' || version[0] > L'9' || version[
1] < L'0' || version[1] > L'9' || version[2] != L'.') |
| 56 { |
| 57 throw std::runtime_error("IE version string has unexpected format"); |
| 58 } |
| 59 return version; |
| 60 } |
| 61 |
| 62 std::wstring AdblockPlus::IE::InstalledVersionString() |
| 63 { |
| 64 try |
| 65 { |
| 66 return IE_version_string(); |
| 67 } |
| 68 catch (...) |
| 69 { |
| 70 return L""; |
| 71 } |
| 72 } |
| 73 |
| 74 int AdblockPlus::IE::InstalledMajorVersion() |
| 75 { |
| 76 try |
| 77 { |
| 78 std::wstring version = IE_version_string(); |
| 79 /* |
| 80 * The version number is either one or two digits, |
| 81 * and thus either the second or third character is a period, |
| 82 */ |
| 83 if (version[1] == L'.') |
| 84 { |
| 85 return version[0] - L'0'; |
| 86 } |
| 87 else if (version[2] == L'.') |
| 88 { |
| 89 return 10 * (version[0] - L'0') + (version[1] - L'0'); |
| 90 } |
| 91 } |
| 92 catch (...) |
| 93 { |
| 94 } |
| 95 return 0; |
| 96 } |
OLD | NEW |