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

Side by Side 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.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 #include "IE_version.h"
2 #include "Registry.h"
3
4 using namespace AdblockPlus;
5
6 /**
7 * Internal implementation of the IE version string.
8 *
9 * This version throws exceptions for its errors, relying on its caller to handl e them.
10 *
11 * Quoting http://support.microsoft.com/kb/969393:
12 * "Note The version string value for Internet Explorer 10 is 9.10.9200.16384, and the svcVersion string value is 10.0.9200.16384."
13 * [EH 2014-06-20] My current version of IE 11 is reporting these values:
14 * Version 9.11.9600.17041
15 * svcVersion 11.0.9600.17041
16 *
17 * Warning: IE version 12 and later might not behave the same, so this function should be reviewed with each new release.
18 */
19 std::wstring IE_version_string()
20 {
21 Registry_Key IE_key( Registry_Key::Predefined::HKLM, L"Software\\Microsoft\\In ternet Explorer" );
Oleksandr 2014/07/25 22:23:46 Spacing before and after parentheses etc in this w
22 std::wstring version( IE_key.value_wstring( L"Version" ) );
23 /*
24 * We're expecting a version string that matches the regex "^[1-9]\.".
25 * Since IE versions 10 and 11 use a version string that begins with "9.", th is simplistic parsing method works adequately.
26 */
27 if ( version[1] != '.' || version[0] < L'0' || version[0] > L'9' )
28 {
29 throw std::runtime_error( "IE version string has unexpected format" );
30 }
31 if ( version[0] != L'9' )
32 {
33 return version;
34 }
35 // Assert the major version in the "Version" value is 9.
36 /*
37 * Version 9 might either be an actual version 9 or it might represent a vers ion >= 10
38 * If the value named "svcVersion" exists, we'll report that instead.
39 */
40 try
41 {
42 return IE_key.value_wstring( L"svcVersion" );
43 }
44 catch ( ... )
45 {
46 return version;
47 }
48 }
49
50 std::wstring AdblockPlus::IE::installed_version_string()
51 {
52 try
53 {
54 return IE_version_string();
55 }
56 catch ( ... )
57 {
58 return L"";
59 }
60 }
61
62 int AdblockPlus::IE::installed_major_version()
63 {
64 try
65 {
66 std::wstring version = IE_version_string();
67 /*
68 * If the second character is a period, we assume that the major version is a single digit.
69 */
70 if ( version[ 1 ] == L'.' )
71 {
72 return version[ 0 ] - L'0';
73 }
74 // Assert IE_version_string() did not verify the syntax of the version strin g.
75 /*
76 * In this case, we'll assume that the version returned is two digits follow ed by a period.
77 * If not, we'll assume an error.
78 */
79 if ( version[ 0 ] < L'0' || version[ 0 ] > L'9' || version[ 1 ] < L'0' || ve rsion[ 1 ] > L'9' || version[ 2 ] != L'.' )
80 {
81 return 0;
82 }
83 return 10 * ( version[ 0 ] - L'0' ) + ( version[ 1 ] - L'0' );
84 }
85 catch ( ... )
86 {
87 return 0;
88 }
89 }
OLDNEW

Powered by Google App Engine
This is Rietveld