OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // This file defines utility functions for fetching localized resources. | 5 // This file defines utility functions for fetching localized resources. |
6 | 6 |
7 #include "chrome/installer/util/l10n_string_util.h" | 7 #include "chrome/installer/util/l10n_string_util.h" |
8 | 8 |
9 #include <atlbase.h> | 9 #include <atlbase.h> |
10 | 10 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 | 65 |
66 // Here we generate the url spec with the Microsoft res:// scheme which is | 66 // Here we generate the url spec with the Microsoft res:// scheme which is |
67 // explained here : http://support.microsoft.com/kb/220830 | 67 // explained here : http://support.microsoft.com/kb/220830 |
68 std::wstring GetLocalizedEulaResource() { | 68 std::wstring GetLocalizedEulaResource() { |
69 wchar_t full_exe_path[MAX_PATH]; | 69 wchar_t full_exe_path[MAX_PATH]; |
70 int len = ::GetModuleFileName(NULL, full_exe_path, MAX_PATH); | 70 int len = ::GetModuleFileName(NULL, full_exe_path, MAX_PATH); |
71 if (len == 0 || len == MAX_PATH) | 71 if (len == 0 || len == MAX_PATH) |
72 return L""; | 72 return L""; |
73 | 73 |
74 // The resource names are more or less the upcased language names. | 74 // The resource names are more or less the upcased language names. |
75 std::wstring language(GetLanguageSelector().selected_translation()); | 75 base::string16 language(GetLanguageSelector().selected_translation()); |
76 std::replace(language.begin(), language.end(), L'-', L'_'); | 76 std::replace(language.begin(), language.end(), L'-', L'_'); |
77 base::StringToUpperASCII(&language); | 77 language = base::ToUpperASCII(language); |
78 | 78 |
79 std::wstring resource(L"IDR_OEMPG_"); | 79 std::wstring resource(L"IDR_OEMPG_"); |
80 resource.append(language).append(L".HTML"); | 80 resource.append(language).append(L".HTML"); |
81 | 81 |
82 // Fall back on "en" if we don't have a resource for this language. | 82 // Fall back on "en" if we don't have a resource for this language. |
83 if (NULL == FindResource(NULL, resource.c_str(), RT_HTML)) | 83 if (NULL == FindResource(NULL, resource.c_str(), RT_HTML)) |
84 resource = L"IDR_OEMPG_EN.HTML"; | 84 resource = L"IDR_OEMPG_EN.HTML"; |
85 | 85 |
86 // Spaces and DOS paths must be url encoded. | 86 // Spaces and DOS paths must be url encoded. |
87 std::wstring url_path = | 87 std::wstring url_path = |
88 base::StringPrintf(L"res://%ls/#23/%ls", full_exe_path, resource.c_str()); | 88 base::StringPrintf(L"res://%ls/#23/%ls", full_exe_path, resource.c_str()); |
89 | 89 |
90 // The cast is safe because url_path has limited length | 90 // The cast is safe because url_path has limited length |
91 // (see the definition of full_exe_path and resource). | 91 // (see the definition of full_exe_path and resource). |
92 DCHECK(kuint32max > (url_path.size() * 3)); | 92 DCHECK(kuint32max > (url_path.size() * 3)); |
93 DWORD count = static_cast<DWORD>(url_path.size() * 3); | 93 DWORD count = static_cast<DWORD>(url_path.size() * 3); |
94 scoped_ptr<wchar_t[]> url_canon(new wchar_t[count]); | 94 scoped_ptr<wchar_t[]> url_canon(new wchar_t[count]); |
95 HRESULT hr = ::UrlCanonicalizeW(url_path.c_str(), url_canon.get(), | 95 HRESULT hr = ::UrlCanonicalizeW(url_path.c_str(), url_canon.get(), |
96 &count, URL_ESCAPE_UNSAFE); | 96 &count, URL_ESCAPE_UNSAFE); |
97 if (SUCCEEDED(hr)) | 97 if (SUCCEEDED(hr)) |
98 return std::wstring(url_canon.get()); | 98 return std::wstring(url_canon.get()); |
99 return url_path; | 99 return url_path; |
100 } | 100 } |
101 | 101 |
102 std::wstring GetCurrentTranslation() { | 102 std::wstring GetCurrentTranslation() { |
103 return GetLanguageSelector().selected_translation(); | 103 return GetLanguageSelector().selected_translation(); |
104 } | 104 } |
105 | 105 |
106 } // namespace installer | 106 } // namespace installer |
OLD | NEW |