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

Delta Between Two Patch Sets: src/shared/IE_version.cpp

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

Powered by Google App Engine
This is Rietveld