| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <windows.h> | 5 #include <windows.h> |
| 6 | 6 |
| 7 #include "base/file_version_info.h" | 7 #include "base/file_version_info.h" |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 FileVersionInfo* FileVersionInfo::CreateFileVersionInfoForCurrentModule() { | 33 FileVersionInfo* FileVersionInfo::CreateFileVersionInfoForCurrentModule() { |
| 34 std::wstring app_path; | 34 std::wstring app_path; |
| 35 if (!PathService::Get(base::FILE_MODULE, &app_path)) | 35 if (!PathService::Get(base::FILE_MODULE, &app_path)) |
| 36 return NULL; | 36 return NULL; |
| 37 | 37 |
| 38 return CreateFileVersionInfo(app_path); | 38 return CreateFileVersionInfo(app_path); |
| 39 } | 39 } |
| 40 | 40 |
| 41 // static | 41 // static |
| 42 FileVersionInfo* FileVersionInfo::CreateFileVersionInfo( | 42 FileVersionInfo* FileVersionInfo::CreateFileVersionInfo( |
| 43 const std::wstring& file_path) { | 43 const FilePath& file_path) { |
| 44 DWORD dummy; | 44 DWORD dummy; |
| 45 const wchar_t* path = file_path.c_str(); | 45 const wchar_t* path = file_path.value().c_str(); |
| 46 DWORD length = ::GetFileVersionInfoSize(path, &dummy); | 46 DWORD length = ::GetFileVersionInfoSize(path, &dummy); |
| 47 if (length == 0) | 47 if (length == 0) |
| 48 return NULL; | 48 return NULL; |
| 49 | 49 |
| 50 void* data = calloc(length, 1); | 50 void* data = calloc(length, 1); |
| 51 if (!data) | 51 if (!data) |
| 52 return NULL; | 52 return NULL; |
| 53 | 53 |
| 54 if (!::GetFileVersionInfo(path, dummy, length, data)) { | 54 if (!::GetFileVersionInfo(path, dummy, length, data)) { |
| 55 free(data); | 55 free(data); |
| 56 return NULL; | 56 return NULL; |
| 57 } | 57 } |
| 58 | 58 |
| 59 LanguageAndCodePage* translate = NULL; | 59 LanguageAndCodePage* translate = NULL; |
| 60 uint32 page_count; | 60 uint32 page_count; |
| 61 BOOL query_result = VerQueryValue(data, L"\\VarFileInfo\\Translation", | 61 BOOL query_result = VerQueryValue(data, L"\\VarFileInfo\\Translation", |
| 62 (void**) &translate, &page_count); | 62 (void**) &translate, &page_count); |
| 63 | 63 |
| 64 if (query_result && translate) { | 64 if (query_result && translate) { |
| 65 return new FileVersionInfo(data, translate->language, | 65 return new FileVersionInfo(data, translate->language, |
| 66 translate->code_page); | 66 translate->code_page); |
| 67 | 67 |
| 68 } else { | 68 } else { |
| 69 free(data); | 69 free(data); |
| 70 return NULL; | 70 return NULL; |
| 71 } | 71 } |
| 72 } | 72 } |
| 73 | 73 |
| 74 FileVersionInfo* FileVersionInfo::CreateFileVersionInfo( |
| 75 const std::wstring& file_path) { |
| 76 FilePath file_path_fp = FilePath::FromWStringHack(file_path); |
| 77 return CreateFileVersionInfo(file_path_fp); |
| 78 } |
| 79 |
| 74 std::wstring FileVersionInfo::company_name() { | 80 std::wstring FileVersionInfo::company_name() { |
| 75 return GetStringValue(L"CompanyName"); | 81 return GetStringValue(L"CompanyName"); |
| 76 } | 82 } |
| 77 | 83 |
| 78 std::wstring FileVersionInfo::company_short_name() { | 84 std::wstring FileVersionInfo::company_short_name() { |
| 79 return GetStringValue(L"CompanyShortName"); | 85 return GetStringValue(L"CompanyShortName"); |
| 80 } | 86 } |
| 81 | 87 |
| 82 std::wstring FileVersionInfo::internal_name() { | 88 std::wstring FileVersionInfo::internal_name() { |
| 83 return GetStringValue(L"InternalName"); | 89 return GetStringValue(L"InternalName"); |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 | 178 |
| 173 std::wstring FileVersionInfo::GetStringValue(const wchar_t* name) { | 179 std::wstring FileVersionInfo::GetStringValue(const wchar_t* name) { |
| 174 std::wstring str; | 180 std::wstring str; |
| 175 if (GetValue(name, &str)) | 181 if (GetValue(name, &str)) |
| 176 return str; | 182 return str; |
| 177 else | 183 else |
| 178 return L""; | 184 return L""; |
| 179 } | 185 } |
| 180 | 186 |
| 181 | 187 |
| OLD | NEW |