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