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 "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 | 8 |
9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
10 #include "base/file_version_info.h" | 10 #include "base/file_version_info.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/path_service.h" | 12 #include "base/path_service.h" |
| 13 #include "base/thread_restrictions.h" |
13 | 14 |
14 // This has to be last. | 15 // This has to be last. |
15 #include <strsafe.h> | 16 #include <strsafe.h> |
16 | 17 |
17 FileVersionInfoWin::FileVersionInfoWin(void* data, int language, int code_page) | 18 FileVersionInfoWin::FileVersionInfoWin(void* data, int language, int code_page) |
18 : language_(language), code_page_(code_page) { | 19 : language_(language), code_page_(code_page) { |
| 20 base::ThreadRestrictions::AssertIOAllowed(); |
19 data_.reset((char*) data); | 21 data_.reset((char*) data); |
20 fixed_file_info_ = NULL; | 22 fixed_file_info_ = NULL; |
21 UINT size; | 23 UINT size; |
22 ::VerQueryValue(data_.get(), L"\\", (LPVOID*)&fixed_file_info_, &size); | 24 ::VerQueryValue(data_.get(), L"\\", (LPVOID*)&fixed_file_info_, &size); |
23 } | 25 } |
24 | 26 |
25 FileVersionInfoWin::~FileVersionInfoWin() { | 27 FileVersionInfoWin::~FileVersionInfoWin() { |
26 DCHECK(data_.get()); | 28 DCHECK(data_.get()); |
27 } | 29 } |
28 | 30 |
29 typedef struct { | 31 typedef struct { |
30 WORD language; | 32 WORD language; |
31 WORD code_page; | 33 WORD code_page; |
32 } LanguageAndCodePage; | 34 } LanguageAndCodePage; |
33 | 35 |
34 // static | 36 // static |
35 FileVersionInfo* FileVersionInfo::CreateFileVersionInfoForCurrentModule() { | 37 FileVersionInfo* FileVersionInfo::CreateFileVersionInfoForCurrentModule() { |
36 FilePath app_path; | 38 FilePath app_path; |
37 if (!PathService::Get(base::FILE_MODULE, &app_path)) | 39 if (!PathService::Get(base::FILE_MODULE, &app_path)) |
38 return NULL; | 40 return NULL; |
39 | 41 |
40 return CreateFileVersionInfo(app_path); | 42 return CreateFileVersionInfo(app_path); |
41 } | 43 } |
42 | 44 |
43 // static | 45 // static |
44 FileVersionInfo* FileVersionInfo::CreateFileVersionInfo( | 46 FileVersionInfo* FileVersionInfo::CreateFileVersionInfo( |
45 const FilePath& file_path) { | 47 const FilePath& file_path) { |
| 48 base::ThreadRestrictions::AssertIOAllowed(); |
| 49 |
46 DWORD dummy; | 50 DWORD dummy; |
47 const wchar_t* path = file_path.value().c_str(); | 51 const wchar_t* path = file_path.value().c_str(); |
48 DWORD length = ::GetFileVersionInfoSize(path, &dummy); | 52 DWORD length = ::GetFileVersionInfoSize(path, &dummy); |
49 if (length == 0) | 53 if (length == 0) |
50 return NULL; | 54 return NULL; |
51 | 55 |
52 void* data = calloc(length, 1); | 56 void* data = calloc(length, 1); |
53 if (!data) | 57 if (!data) |
54 return NULL; | 58 return NULL; |
55 | 59 |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 return false; | 183 return false; |
180 } | 184 } |
181 | 185 |
182 std::wstring FileVersionInfoWin::GetStringValue(const wchar_t* name) { | 186 std::wstring FileVersionInfoWin::GetStringValue(const wchar_t* name) { |
183 std::wstring str; | 187 std::wstring str; |
184 if (GetValue(name, &str)) | 188 if (GetValue(name, &str)) |
185 return str; | 189 return str; |
186 else | 190 else |
187 return L""; | 191 return L""; |
188 } | 192 } |
OLD | NEW |