| Index: base/file_version_info_win.cc
|
| diff --git a/base/file_version_info_win.cc b/base/file_version_info_win.cc
|
| index 6fa7a48e8e1f948e5102873cc175b0273b9d7afa..02a14db0032aa24335d52b546880162e63a3cf77 100644
|
| --- a/base/file_version_info_win.cc
|
| +++ b/base/file_version_info_win.cc
|
| @@ -6,63 +6,48 @@
|
|
|
| #include <windows.h>
|
| #include <stddef.h>
|
| +#include <stdint.h>
|
|
|
| +#include "base/file_version_info.h"
|
| #include "base/files/file_path.h"
|
| #include "base/logging.h"
|
| +#include "base/macros.h"
|
| #include "base/threading/thread_restrictions.h"
|
| -#include "base/win/resource_util.h"
|
|
|
| using base::FilePath;
|
|
|
| -namespace {
|
| +FileVersionInfoWin::FileVersionInfoWin(void* data,
|
| + WORD language,
|
| + WORD code_page)
|
| + : language_(language), code_page_(code_page) {
|
| + base::ThreadRestrictions::AssertIOAllowed();
|
| + data_.reset((char*) data);
|
| + fixed_file_info_ = NULL;
|
| + UINT size;
|
| + ::VerQueryValue(data_.get(), L"\\", (LPVOID*)&fixed_file_info_, &size);
|
| +}
|
|
|
| -struct LanguageAndCodePage {
|
| +FileVersionInfoWin::~FileVersionInfoWin() {
|
| + DCHECK(data_.get());
|
| +}
|
| +
|
| +typedef struct {
|
| WORD language;
|
| WORD code_page;
|
| -};
|
| -
|
| -// Returns the \\VarFileInfo\\Translation value extracted from the
|
| -// VS_VERSION_INFO resource in |data|.
|
| -LanguageAndCodePage* GetTranslate(const void* data) {
|
| - LanguageAndCodePage* translate = nullptr;
|
| - UINT length;
|
| - if (::VerQueryValue(data, L"\\VarFileInfo\\Translation",
|
| - reinterpret_cast<void**>(&translate), &length)) {
|
| - return translate;
|
| - }
|
| - return nullptr;
|
| -}
|
| -
|
| -VS_FIXEDFILEINFO* GetVsFixedFileInfo(const void* data) {
|
| - VS_FIXEDFILEINFO* fixed_file_info = nullptr;
|
| - UINT length;
|
| - if (::VerQueryValue(data, L"\\", reinterpret_cast<void**>(&fixed_file_info),
|
| - &length)) {
|
| - return fixed_file_info;
|
| - }
|
| - return nullptr;
|
| -}
|
| -
|
| -} // namespace
|
| -
|
| -FileVersionInfoWin::~FileVersionInfoWin() = default;
|
| +} LanguageAndCodePage;
|
|
|
| // static
|
| FileVersionInfo* FileVersionInfo::CreateFileVersionInfoForModule(
|
| HMODULE module) {
|
| - void* data;
|
| - size_t version_info_length;
|
| - const bool has_version_resource = base::win::GetResourceFromModule(
|
| - module, VS_VERSION_INFO, RT_VERSION, &data, &version_info_length);
|
| - if (!has_version_resource)
|
| - return nullptr;
|
| + // Note that the use of MAX_PATH is basically in line with what we do for
|
| + // all registered paths (PathProviderWin).
|
| + wchar_t system_buffer[MAX_PATH];
|
| + system_buffer[0] = 0;
|
| + if (!GetModuleFileName(module, system_buffer, MAX_PATH))
|
| + return NULL;
|
|
|
| - const LanguageAndCodePage* translate = GetTranslate(data);
|
| - if (!translate)
|
| - return nullptr;
|
| -
|
| - return new FileVersionInfoWin(data, translate->language,
|
| - translate->code_page);
|
| + FilePath app_path(system_buffer);
|
| + return CreateFileVersionInfo(app_path);
|
| }
|
|
|
| // static
|
| @@ -74,19 +59,30 @@
|
| const wchar_t* path = file_path.value().c_str();
|
| DWORD length = ::GetFileVersionInfoSize(path, &dummy);
|
| if (length == 0)
|
| - return nullptr;
|
| + return NULL;
|
|
|
| - std::vector<uint8_t> data(length, 0);
|
| + void* data = calloc(length, 1);
|
| + if (!data)
|
| + return NULL;
|
|
|
| - if (!::GetFileVersionInfo(path, dummy, data.size(), data.data()))
|
| - return nullptr;
|
| + if (!::GetFileVersionInfo(path, dummy, length, data)) {
|
| + free(data);
|
| + return NULL;
|
| + }
|
|
|
| - const LanguageAndCodePage* translate = GetTranslate(data.data());
|
| - if (!translate)
|
| - return nullptr;
|
| + LanguageAndCodePage* translate = NULL;
|
| + uint32_t page_count;
|
| + BOOL query_result = VerQueryValue(data, L"\\VarFileInfo\\Translation",
|
| + (void**) &translate, &page_count);
|
|
|
| - return new FileVersionInfoWin(std::move(data), translate->language,
|
| - translate->code_page);
|
| + if (query_result && translate) {
|
| + return new FileVersionInfoWin(data, translate->language,
|
| + translate->code_page);
|
| +
|
| + } else {
|
| + free(data);
|
| + return NULL;
|
| + }
|
| }
|
|
|
| base::string16 FileVersionInfoWin::company_name() {
|
| @@ -179,7 +175,7 @@
|
| L"\\StringFileInfo\\%04x%04x\\%ls", language, code_page, name);
|
| LPVOID value = NULL;
|
| uint32_t size;
|
| - BOOL r = ::VerQueryValue(data_, sub_block, &value, &size);
|
| + BOOL r = ::VerQueryValue(data_.get(), sub_block, &value, &size);
|
| if (r && value) {
|
| value_str->assign(static_cast<wchar_t*>(value));
|
| return true;
|
| @@ -195,24 +191,3 @@
|
| else
|
| return L"";
|
| }
|
| -
|
| -FileVersionInfoWin::FileVersionInfoWin(std::vector<uint8_t>&& data,
|
| - WORD language,
|
| - WORD code_page)
|
| - : owned_data_(std::move(data)),
|
| - data_(owned_data_.data()),
|
| - language_(language),
|
| - code_page_(code_page),
|
| - fixed_file_info_(GetVsFixedFileInfo(data_)) {
|
| - DCHECK(!owned_data_.empty());
|
| -}
|
| -
|
| -FileVersionInfoWin::FileVersionInfoWin(void* data,
|
| - WORD language,
|
| - WORD code_page)
|
| - : data_(data),
|
| - language_(language),
|
| - code_page_(code_page),
|
| - fixed_file_info_(GetVsFixedFileInfo(data)) {
|
| - DCHECK(data_);
|
| -}
|
|
|