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
3 // found in the LICENSE file.
5 #include "chrome/installer/mini_installer/configuration.h"
7 #include <shellapi.h> // NOLINT
9 #include "chrome/installer/mini_installer/appid.h"
10 #include "chrome/installer/mini_installer/mini_installer_resource.h"
12 namespace mini_installer
{
14 Configuration::Configuration() : args_(NULL
) {
18 Configuration::~Configuration() {
22 const wchar_t* Configuration::program() const {
23 return args_
== NULL
|| argument_count_
< 1 ? NULL
: args_
[0];
26 void Configuration::Clear() {
31 chrome_app_guid_
= google_update::kAppGuid
;
33 operation_
= INSTALL_PRODUCT
;
36 has_chrome_frame_
= false;
37 is_multi_install_
= false;
38 is_system_level_
= false;
39 previous_version_
= NULL
;
42 bool Configuration::Initialize(HMODULE module
) {
44 ReadResources(module
);
45 return ParseCommandLine(::GetCommandLine());
48 // |command_line| is shared with this instance in the sense that this
49 // instance may refer to it at will throughout its lifetime, yet it will
51 bool Configuration::ParseCommandLine(const wchar_t* command_line
) {
52 command_line_
= command_line
;
53 args_
= ::CommandLineToArgvW(command_line_
, &argument_count_
);
55 for (int i
= 1; i
< argument_count_
; ++i
) {
56 if (0 == ::lstrcmpi(args_
[i
], L
"--chrome-sxs"))
57 chrome_app_guid_
= google_update::kSxSAppGuid
;
58 else if (0 == ::lstrcmpi(args_
[i
], L
"--chrome"))
60 else if (0 == ::lstrcmpi(args_
[i
], L
"--chrome-frame"))
61 has_chrome_frame_
= true;
62 else if (0 == ::lstrcmpi(args_
[i
], L
"--multi-install"))
63 is_multi_install_
= true;
64 else if (0 == ::lstrcmpi(args_
[i
], L
"--system-level"))
65 is_system_level_
= true;
66 else if (0 == ::lstrcmpi(args_
[i
], L
"--cleanup"))
70 // Single-install defaults to Chrome.
71 if (!is_multi_install_
)
72 has_chrome_
= !has_chrome_frame_
;
78 void Configuration::ReadResources(HMODULE module
) {
79 HRSRC resource_info_block
=
80 FindResource(module
, MAKEINTRESOURCE(ID_PREVIOUS_VERSION
), RT_RCDATA
);
81 if (!resource_info_block
)
84 HGLOBAL data_handle
= LoadResource(module
, resource_info_block
);
88 // The data is a Unicode string, so it must be a multiple of two bytes.
89 DWORD version_size
= SizeofResource(module
, resource_info_block
);
90 if (!version_size
|| (version_size
& 0x01) != 0)
93 void* version_data
= LockResource(data_handle
);
97 const wchar_t* version_string
= reinterpret_cast<wchar_t*>(version_data
);
98 size_t version_len
= version_size
/ sizeof(wchar_t);
100 // The string must be terminated.
101 if (version_string
[version_len
- 1])
104 previous_version_
= version_string
;
107 } // namespace mini_installer