OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/file_version_info_win.h" | 5 #include "base/file_version_info_win.h" |
6 | 6 |
7 #include <windows.h> | 7 #include <windows.h> |
| 8 #include <stddef.h> |
| 9 #include <stdint.h> |
8 | 10 |
9 #include "base/file_version_info.h" | 11 #include "base/file_version_info.h" |
10 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
11 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/macros.h" |
12 #include "base/threading/thread_restrictions.h" | 15 #include "base/threading/thread_restrictions.h" |
13 | 16 |
14 using base::FilePath; | 17 using base::FilePath; |
15 | 18 |
16 FileVersionInfoWin::FileVersionInfoWin(void* data, | 19 FileVersionInfoWin::FileVersionInfoWin(void* data, |
17 WORD language, | 20 WORD language, |
18 WORD code_page) | 21 WORD code_page) |
19 : language_(language), code_page_(code_page) { | 22 : language_(language), code_page_(code_page) { |
20 base::ThreadRestrictions::AssertIOAllowed(); | 23 base::ThreadRestrictions::AssertIOAllowed(); |
21 data_.reset((char*) data); | 24 data_.reset((char*) data); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 void* data = calloc(length, 1); | 64 void* data = calloc(length, 1); |
62 if (!data) | 65 if (!data) |
63 return NULL; | 66 return NULL; |
64 | 67 |
65 if (!::GetFileVersionInfo(path, dummy, length, data)) { | 68 if (!::GetFileVersionInfo(path, dummy, length, data)) { |
66 free(data); | 69 free(data); |
67 return NULL; | 70 return NULL; |
68 } | 71 } |
69 | 72 |
70 LanguageAndCodePage* translate = NULL; | 73 LanguageAndCodePage* translate = NULL; |
71 uint32 page_count; | 74 uint32_t page_count; |
72 BOOL query_result = VerQueryValue(data, L"\\VarFileInfo\\Translation", | 75 BOOL query_result = VerQueryValue(data, L"\\VarFileInfo\\Translation", |
73 (void**) &translate, &page_count); | 76 (void**) &translate, &page_count); |
74 | 77 |
75 if (query_result && translate) { | 78 if (query_result && translate) { |
76 return new FileVersionInfoWin(data, translate->language, | 79 return new FileVersionInfoWin(data, translate->language, |
77 translate->code_page); | 80 translate->code_page); |
78 | 81 |
79 } else { | 82 } else { |
80 free(data); | 83 free(data); |
81 return NULL; | 84 return NULL; |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 lang_codepage[i++] = 1252; | 167 lang_codepage[i++] = 1252; |
165 | 168 |
166 i = 0; | 169 i = 0; |
167 while (i < arraysize(lang_codepage)) { | 170 while (i < arraysize(lang_codepage)) { |
168 wchar_t sub_block[MAX_PATH]; | 171 wchar_t sub_block[MAX_PATH]; |
169 WORD language = lang_codepage[i++]; | 172 WORD language = lang_codepage[i++]; |
170 WORD code_page = lang_codepage[i++]; | 173 WORD code_page = lang_codepage[i++]; |
171 _snwprintf_s(sub_block, MAX_PATH, MAX_PATH, | 174 _snwprintf_s(sub_block, MAX_PATH, MAX_PATH, |
172 L"\\StringFileInfo\\%04x%04x\\%ls", language, code_page, name); | 175 L"\\StringFileInfo\\%04x%04x\\%ls", language, code_page, name); |
173 LPVOID value = NULL; | 176 LPVOID value = NULL; |
174 uint32 size; | 177 uint32_t size; |
175 BOOL r = ::VerQueryValue(data_.get(), sub_block, &value, &size); | 178 BOOL r = ::VerQueryValue(data_.get(), sub_block, &value, &size); |
176 if (r && value) { | 179 if (r && value) { |
177 value_str->assign(static_cast<wchar_t*>(value)); | 180 value_str->assign(static_cast<wchar_t*>(value)); |
178 return true; | 181 return true; |
179 } | 182 } |
180 } | 183 } |
181 return false; | 184 return false; |
182 } | 185 } |
183 | 186 |
184 std::wstring FileVersionInfoWin::GetStringValue(const wchar_t* name) { | 187 std::wstring FileVersionInfoWin::GetStringValue(const wchar_t* name) { |
185 std::wstring str; | 188 std::wstring str; |
186 if (GetValue(name, &str)) | 189 if (GetValue(name, &str)) |
187 return str; | 190 return str; |
188 else | 191 else |
189 return L""; | 192 return L""; |
190 } | 193 } |
OLD | NEW |