Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / installer / mini_installer / configuration.cc
blob87e08be387e3c3eaaea5ebeac5b5d72a7bc5047b
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) {
15 Clear();
18 Configuration::~Configuration() {
19 Clear();
22 const wchar_t* Configuration::program() const {
23 return args_ == NULL || argument_count_ < 1 ? NULL : args_[0];
26 void Configuration::Clear() {
27 if (args_ != NULL) {
28 ::LocalFree(args_);
29 args_ = NULL;
31 chrome_app_guid_ = google_update::kAppGuid;
32 command_line_ = NULL;
33 operation_ = INSTALL_PRODUCT;
34 argument_count_ = 0;
35 has_chrome_ = false;
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) {
43 Clear();
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
50 // not release it.
51 bool Configuration::ParseCommandLine(const wchar_t* command_line) {
52 command_line_ = command_line;
53 args_ = ::CommandLineToArgvW(command_line_, &argument_count_);
54 if (args_ != NULL) {
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"))
59 has_chrome_ = true;
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"))
67 operation_ = CLEANUP;
70 // Single-install defaults to Chrome.
71 if (!is_multi_install_)
72 has_chrome_ = !has_chrome_frame_;
75 return args_ != NULL;
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)
82 return;
84 HGLOBAL data_handle = LoadResource(module, resource_info_block);
85 if (!data_handle)
86 return;
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)
91 return;
93 void* version_data = LockResource(data_handle);
94 if (!version_data)
95 return;
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])
102 return;
104 previous_version_ = version_string;
107 } // namespace mini_installer