| Index: src/shared/IE_version.cpp |
| =================================================================== |
| new file mode 100644 |
| --- /dev/null |
| +++ b/src/shared/IE_version.cpp |
| @@ -0,0 +1,89 @@ |
| +#include "IE_version.h" |
| +#include "Registry.h" |
| + |
| +using namespace AdblockPlus; |
| + |
| +/** |
| + * Internal implementation of the IE version string. |
| + * |
| + * This version throws exceptions for its errors, relying on its caller to handle them. |
| + * |
| + * Quoting http://support.microsoft.com/kb/969393: |
| + * "Note The version string value for Internet Explorer 10 is 9.10.9200.16384, and the svcVersion string value is 10.0.9200.16384." |
| + * [EH 2014-06-20] My current version of IE 11 is reporting these values: |
| + * Version 9.11.9600.17041 |
| + * svcVersion 11.0.9600.17041 |
| + * |
| + * Warning: IE version 12 and later might not behave the same, so this function should be reviewed with each new release. |
| + */ |
| +std::wstring IE_version_string() |
| +{ |
| + Registry_Key IE_key(Registry_Key::Predefined::HKLM, L"Software\\Microsoft\\Internet Explorer"); |
| + std::wstring version(IE_key.value_wstring(L"Version")); |
| + /* |
| + * We're expecting a version string that matches the regex "^[1-9]\.". |
| + * Since IE versions 10 and 11 use a version string that begins with "9.", this simplistic parsing method works adequately. |
| + */ |
| + if (version[1] != '.' || version[0] < L'0' || version[0] > L'9') |
| + { |
| + throw std::runtime_error("IE version string has unexpected format"); |
| + } |
| + if (version[0] != L'9') |
| + { |
| + return version; |
| + } |
| + // Assert the major version in the "Version" value is 9. |
| + /* |
| + * Version 9 might either be an actual version 9 or it might represent a version >= 10 |
| + * If the value named "svcVersion" exists, we'll report that instead. |
| + */ |
| + try |
| + { |
| + return IE_key.value_wstring(L"svcVersion"); |
| + } |
| + catch (...) |
| + { |
| + return version; |
| + } |
| +} |
| + |
| +std::wstring AdblockPlus::IE::installed_version_string() |
| +{ |
| + try |
| + { |
| + return IE_version_string(); |
| + } |
| + catch (...) |
| + { |
| + return L""; |
| + } |
| +} |
| + |
| +int AdblockPlus::IE::installed_major_version() |
| +{ |
| + try |
| + { |
| + std::wstring version = IE_version_string(); |
| + /* |
| + * If the second character is a period, we assume that the major version is a single digit. |
| + */ |
| + if (version[ 1 ] == L'.') |
| + { |
| + return version[ 0 ] - L'0'; |
| + } |
| + // Assert IE_version_string() did not verify the syntax of the version string. |
| + /* |
| + * In this case, we'll assume that the version returned is two digits followed by a period. |
| + * If not, we'll assume an error. |
| + */ |
| + if (version[ 0 ] < L'0' || version[ 0 ] > L'9' || version[ 1 ] < L'0' || version[ 1 ] > L'9' || version[ 2 ] != L'.') |
| + { |
| + return 0; |
| + } |
| + return 10 * (version[ 0 ] - L'0') + (version[ 1 ] - L'0'); |
| + } |
| + catch (...) |
| + { |
| + return 0; |
| + } |
| +} |