Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: src/shared/IE_version.cpp

Issue 5171515343503360: Issue #41 - Bring method of determining IE version up to date (Closed)
Patch Set: Created July 23, 2014, 4:55 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
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" );
Oleksandr 2014/07/25 22:23:46 Spacing before and after parentheses etc in this w
+ 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;
+ }
+}

Powered by Google App Engine
This is Rietveld