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.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/logging.h" | 11 #include "base/logging.h" |
11 #include "base/path_service.h" | 12 #include "base/path_service.h" |
12 | 13 |
13 // This has to be last. | 14 // This has to be last. |
14 #include <strsafe.h> | 15 #include <strsafe.h> |
15 | 16 |
16 FileVersionInfo::FileVersionInfo(void* data, int language, int code_page) | 17 FileVersionInfoWin::FileVersionInfoWin(void* data, int language, int code_page) |
17 : language_(language), code_page_(code_page) { | 18 : language_(language), code_page_(code_page) { |
18 data_.reset((char*) data); | 19 data_.reset((char*) data); |
19 fixed_file_info_ = NULL; | 20 fixed_file_info_ = NULL; |
20 UINT size; | 21 UINT size; |
21 ::VerQueryValue(data_.get(), L"\\", (LPVOID*)&fixed_file_info_, &size); | 22 ::VerQueryValue(data_.get(), L"\\", (LPVOID*)&fixed_file_info_, &size); |
22 } | 23 } |
23 | 24 |
24 FileVersionInfo::~FileVersionInfo() { | 25 FileVersionInfoWin::~FileVersionInfoWin() { |
25 DCHECK(data_.get()); | 26 DCHECK(data_.get()); |
26 } | 27 } |
27 | 28 |
28 typedef struct { | 29 typedef struct { |
29 WORD language; | 30 WORD language; |
30 WORD code_page; | 31 WORD code_page; |
31 } LanguageAndCodePage; | 32 } LanguageAndCodePage; |
32 | 33 |
33 // static | 34 // static |
34 FileVersionInfo* FileVersionInfo::CreateFileVersionInfoForCurrentModule() { | 35 FileVersionInfo* FileVersionInfo::CreateFileVersionInfoForCurrentModule() { |
(...skipping 21 matching lines...) Expand all Loading... |
56 free(data); | 57 free(data); |
57 return NULL; | 58 return NULL; |
58 } | 59 } |
59 | 60 |
60 LanguageAndCodePage* translate = NULL; | 61 LanguageAndCodePage* translate = NULL; |
61 uint32 page_count; | 62 uint32 page_count; |
62 BOOL query_result = VerQueryValue(data, L"\\VarFileInfo\\Translation", | 63 BOOL query_result = VerQueryValue(data, L"\\VarFileInfo\\Translation", |
63 (void**) &translate, &page_count); | 64 (void**) &translate, &page_count); |
64 | 65 |
65 if (query_result && translate) { | 66 if (query_result && translate) { |
66 return new FileVersionInfo(data, translate->language, | 67 return new FileVersionInfoWin(data, translate->language, |
67 translate->code_page); | 68 translate->code_page); |
68 | 69 |
69 } else { | 70 } else { |
70 free(data); | 71 free(data); |
71 return NULL; | 72 return NULL; |
72 } | 73 } |
73 } | 74 } |
74 | 75 |
| 76 // static |
75 FileVersionInfo* FileVersionInfo::CreateFileVersionInfo( | 77 FileVersionInfo* FileVersionInfo::CreateFileVersionInfo( |
76 const std::wstring& file_path) { | 78 const std::wstring& file_path) { |
77 FilePath file_path_fp = FilePath::FromWStringHack(file_path); | 79 FilePath file_path_fp = FilePath::FromWStringHack(file_path); |
78 return CreateFileVersionInfo(file_path_fp); | 80 return CreateFileVersionInfo(file_path_fp); |
79 } | 81 } |
80 | 82 |
81 std::wstring FileVersionInfo::company_name() { | 83 std::wstring FileVersionInfoWin::company_name() { |
82 return GetStringValue(L"CompanyName"); | 84 return GetStringValue(L"CompanyName"); |
83 } | 85 } |
84 | 86 |
85 std::wstring FileVersionInfo::company_short_name() { | 87 std::wstring FileVersionInfoWin::company_short_name() { |
86 return GetStringValue(L"CompanyShortName"); | 88 return GetStringValue(L"CompanyShortName"); |
87 } | 89 } |
88 | 90 |
89 std::wstring FileVersionInfo::internal_name() { | 91 std::wstring FileVersionInfoWin::internal_name() { |
90 return GetStringValue(L"InternalName"); | 92 return GetStringValue(L"InternalName"); |
91 } | 93 } |
92 | 94 |
93 std::wstring FileVersionInfo::product_name() { | 95 std::wstring FileVersionInfoWin::product_name() { |
94 return GetStringValue(L"ProductName"); | 96 return GetStringValue(L"ProductName"); |
95 } | 97 } |
96 | 98 |
97 std::wstring FileVersionInfo::product_short_name() { | 99 std::wstring FileVersionInfoWin::product_short_name() { |
98 return GetStringValue(L"ProductShortName"); | 100 return GetStringValue(L"ProductShortName"); |
99 } | 101 } |
100 | 102 |
101 std::wstring FileVersionInfo::comments() { | 103 std::wstring FileVersionInfoWin::comments() { |
102 return GetStringValue(L"Comments"); | 104 return GetStringValue(L"Comments"); |
103 } | 105 } |
104 | 106 |
105 std::wstring FileVersionInfo::legal_copyright() { | 107 std::wstring FileVersionInfoWin::legal_copyright() { |
106 return GetStringValue(L"LegalCopyright"); | 108 return GetStringValue(L"LegalCopyright"); |
107 } | 109 } |
108 | 110 |
109 std::wstring FileVersionInfo::product_version() { | 111 std::wstring FileVersionInfoWin::product_version() { |
110 return GetStringValue(L"ProductVersion"); | 112 return GetStringValue(L"ProductVersion"); |
111 } | 113 } |
112 | 114 |
113 std::wstring FileVersionInfo::file_description() { | 115 std::wstring FileVersionInfoWin::file_description() { |
114 return GetStringValue(L"FileDescription"); | 116 return GetStringValue(L"FileDescription"); |
115 } | 117 } |
116 | 118 |
117 std::wstring FileVersionInfo::legal_trademarks() { | 119 std::wstring FileVersionInfoWin::legal_trademarks() { |
118 return GetStringValue(L"LegalTrademarks"); | 120 return GetStringValue(L"LegalTrademarks"); |
119 } | 121 } |
120 | 122 |
121 std::wstring FileVersionInfo::private_build() { | 123 std::wstring FileVersionInfoWin::private_build() { |
122 return GetStringValue(L"PrivateBuild"); | 124 return GetStringValue(L"PrivateBuild"); |
123 } | 125 } |
124 | 126 |
125 std::wstring FileVersionInfo::file_version() { | 127 std::wstring FileVersionInfoWin::file_version() { |
126 return GetStringValue(L"FileVersion"); | 128 return GetStringValue(L"FileVersion"); |
127 } | 129 } |
128 | 130 |
129 std::wstring FileVersionInfo::original_filename() { | 131 std::wstring FileVersionInfoWin::original_filename() { |
130 return GetStringValue(L"OriginalFilename"); | 132 return GetStringValue(L"OriginalFilename"); |
131 } | 133 } |
132 | 134 |
133 std::wstring FileVersionInfo::special_build() { | 135 std::wstring FileVersionInfoWin::special_build() { |
134 return GetStringValue(L"SpecialBuild"); | 136 return GetStringValue(L"SpecialBuild"); |
135 } | 137 } |
136 | 138 |
137 std::wstring FileVersionInfo::last_change() { | 139 std::wstring FileVersionInfoWin::last_change() { |
138 return GetStringValue(L"LastChange"); | 140 return GetStringValue(L"LastChange"); |
139 } | 141 } |
140 | 142 |
141 bool FileVersionInfo::is_official_build() { | 143 bool FileVersionInfoWin::is_official_build() { |
142 return (GetStringValue(L"Official Build").compare(L"1") == 0); | 144 return (GetStringValue(L"Official Build").compare(L"1") == 0); |
143 } | 145 } |
144 | 146 |
145 bool FileVersionInfo::GetValue(const wchar_t* name, std::wstring* value_str) { | 147 bool FileVersionInfoWin::GetValue(const wchar_t* name, |
146 | 148 std::wstring* value_str) { |
147 WORD lang_codepage[8]; | 149 WORD lang_codepage[8]; |
148 int i = 0; | 150 int i = 0; |
149 // Use the language and codepage from the DLL. | 151 // Use the language and codepage from the DLL. |
150 lang_codepage[i++] = language_; | 152 lang_codepage[i++] = language_; |
151 lang_codepage[i++] = code_page_; | 153 lang_codepage[i++] = code_page_; |
152 // Use the default language and codepage from the DLL. | 154 // Use the default language and codepage from the DLL. |
153 lang_codepage[i++] = ::GetUserDefaultLangID(); | 155 lang_codepage[i++] = ::GetUserDefaultLangID(); |
154 lang_codepage[i++] = code_page_; | 156 lang_codepage[i++] = code_page_; |
155 // Use the language from the DLL and Latin codepage (most common). | 157 // Use the language from the DLL and Latin codepage (most common). |
156 lang_codepage[i++] = language_; | 158 lang_codepage[i++] = language_; |
(...skipping 13 matching lines...) Expand all Loading... |
170 uint32 size; | 172 uint32 size; |
171 BOOL r = ::VerQueryValue(data_.get(), sub_block, &value, &size); | 173 BOOL r = ::VerQueryValue(data_.get(), sub_block, &value, &size); |
172 if (r && value) { | 174 if (r && value) { |
173 value_str->assign(static_cast<wchar_t*>(value)); | 175 value_str->assign(static_cast<wchar_t*>(value)); |
174 return true; | 176 return true; |
175 } | 177 } |
176 } | 178 } |
177 return false; | 179 return false; |
178 } | 180 } |
179 | 181 |
180 std::wstring FileVersionInfo::GetStringValue(const wchar_t* name) { | 182 std::wstring FileVersionInfoWin::GetStringValue(const wchar_t* name) { |
181 std::wstring str; | 183 std::wstring str; |
182 if (GetValue(name, &str)) | 184 if (GetValue(name, &str)) |
183 return str; | 185 return str; |
184 else | 186 else |
185 return L""; | 187 return L""; |
186 } | 188 } |
OLD | NEW |