Chromium Code Reviews| Index: components/update_client/utils_win.cc |
| diff --git a/components/update_client/utils_win.cc b/components/update_client/utils_win.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..1b2a07443acd48dd72bc9798e9b7dc73f6c86288 |
| --- /dev/null |
| +++ b/components/update_client/utils_win.cc |
| @@ -0,0 +1,60 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "components/update_client/utils_win.h" |
| + |
| +#include <windows.h> |
| + |
| +#include "base/strings/string16.h" |
| +#include "base/strings/string_number_conversions.h" |
| +#include "base/strings/stringprintf.h" |
| +#include "base/sys_info.h" |
| +#include "base/win/registry.h" |
| + |
| +namespace update_client { |
| + |
| +namespace { |
| + |
| +constexpr wchar_t kRegKeyWindowsNTCurrentVersion[] = |
| + L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion"; |
| + |
| +constexpr wchar_t kRegValCurrentBuild[] = L"CurrentBuild"; |
| +constexpr wchar_t kRegValCurrentBuildNumber[] = L"CurrentBuildNumber"; |
| +constexpr wchar_t kRegValUBR[] = L"UBR"; |
| + |
| +} // namespace |
| + |
| +// This function implements a best-effort algorithm to return the |
| +// Windows build and patch numbers as part of the Windows OS version. |
| +// The build and patch numbers are read from |
| +// HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion and they are |
| +// replicated under the corresponding Wow6432 hive for the 32-bit programs to |
| +// read. |
| +std::string GetWindowsOSVersion() { |
| + int32_t major = 0; |
| + int32_t minor = 0; |
| + int32_t bugfix = 0; |
| + base::SysInfo::OperatingSystemVersionNumbers(&major, &minor, &bugfix); |
| + |
| + base::win::RegKey key; |
| + if (key.Open(HKEY_LOCAL_MACHINE, kRegKeyWindowsNTCurrentVersion, |
| + KEY_QUERY_VALUE) != ERROR_SUCCESS) { |
| + return base::StringPrintf("%d.%d.%d.%d", major, minor, bugfix, 0); |
| + } |
| + |
| + // Try "CurrentBuild", then fallback to "CurrentBuildNumber". Convert the |
|
grt (UTC plus 2)
2016/11/15 10:25:49
does this differ from the build # obtained by GetV
Sorin Jianu
2016/11/15 19:06:52
The same value is retrieved in both cases.
|
| + // string value to an integral type for validation. |
| + base::string16 build_str; |
| + if (key.ReadValue(kRegValCurrentBuild, &build_str) != ERROR_SUCCESS) |
| + key.ReadValue(kRegValCurrentBuildNumber, &build_str); |
| + unsigned int build_number = 0; |
| + base::StringToUint(build_str, &build_number); |
| + |
| + DWORD patch = 0; |
| + key.ReadValueDW(kRegValUBR, &patch); |
|
grt (UTC plus 2)
2016/11/15 10:25:49
i like having this value available. i like it so m
Sorin Jianu
2016/11/15 19:06:52
It makes sense. I am not quite sure what UBR repre
|
| + |
| + return base::StringPrintf("%d.%d.%u.%lu", major, minor, build_number, patch); |
|
grt (UTC plus 2)
2016/11/15 10:25:49
wdyt of putting UBR in the string returned by base
Sorin Jianu
2016/11/15 19:06:52
I thought about it but I am not sure what is going
|
| +} |
| + |
| +} // namespace update_client |