1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// This file defines specific implementation of BrowserDistribution class for
// Google Chrome.
#include <algorithm>
#include <atlbase.h>
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "base/string_util.h"
#include "base/stringprintf.h"
#include "chrome/installer/util/language_selector.h"
namespace {
const installer::LanguageSelector& GetLanguageSelector() {
static const installer::LanguageSelector instance;
return instance;
}
} // namespace
namespace installer {
std::wstring GetLocalizedString(int base_message_id) {
std::wstring localized_string;
int message_id = base_message_id + GetLanguageSelector().offset();
const ATLSTRINGRESOURCEIMAGE* image = AtlGetStringResourceImage(
_AtlBaseModule.GetModuleInstance(), message_id);
if (image) {
localized_string = std::wstring(image->achString, image->nLength);
} else {
NOTREACHED() << "Unable to find resource id " << message_id;
}
return localized_string;
}
// Here we generate the url spec with the Microsoft res:// scheme which is
// explained here : http://support.microsoft.com/kb/220830
std::wstring GetLocalizedEulaResource() {
wchar_t full_exe_path[MAX_PATH];
int len = ::GetModuleFileName(NULL, full_exe_path, MAX_PATH);
if (len == 0 || len == MAX_PATH)
return L"";
// The resource names are more or less the upcased language names.
std::wstring language(GetLanguageSelector().selected_translation());
std::replace(language.begin(), language.end(), L'-', L'_');
StringToUpperASCII(&language);
std::wstring resource(L"IDR_OEMPG_");
resource.append(language).append(L".HTML");
// Fall back on "en" if we don't have a resource for this language.
if (NULL == FindResource(NULL, resource.c_str(), RT_HTML))
resource = L"IDR_OEMPG_EN.HTML";
// Spaces and DOS paths must be url encoded.
std::wstring url_path =
base::StringPrintf(L"res://%ls/#23/%ls", full_exe_path, resource.c_str());
// The cast is safe because url_path has limited length
// (see the definition of full_exe_path and resource).
DCHECK(kuint32max > (url_path.size() * 3));
DWORD count = static_cast<DWORD>(url_path.size() * 3);
scoped_array<wchar_t> url_canon(new wchar_t[count]);
HRESULT hr = ::UrlCanonicalizeW(url_path.c_str(), url_canon.get(),
&count, URL_ESCAPE_UNSAFE);
if (SUCCEEDED(hr))
return std::wstring(url_canon.get());
return url_path;
}
std::wstring GetCurrentTranslation() {
return GetLanguageSelector().selected_translation();
}
} // namespace installer
|