Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Unified Diff: cloud_print/service/win/installer.cc

Issue 14358019: Added Cloud Print Service installer/uninstaller. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « cloud_print/service/win/installer.h ('k') | cloud_print/service/win/service_controller.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cloud_print/service/win/installer.cc
diff --git a/cloud_print/service/win/installer.cc b/cloud_print/service/win/installer.cc
new file mode 100644
index 0000000000000000000000000000000000000000..c82b1c814c8ad8e1a27a6a82a95c5d0ab43f76cd
--- /dev/null
+++ b/cloud_print/service/win/installer.cc
@@ -0,0 +1,125 @@
+// Copyright 2013 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.
+
+#include "cloud_print/service/win/installer.h"
+
+#include <winerror.h>
+
+#include "base/command_line.h"
+#include "base/file_util.h"
+#include "base/path_service.h"
+#include "base/win/scoped_com_initializer.h"
+#include "base/win/shortcut.h"
+#include "cloud_print/common/win/cloud_print_utils.h"
+#include "cloud_print/common/win/install_utils.h"
+#include "cloud_print/service/service_constants.h"
+#include "cloud_print/service/service_switches.h"
+#include "cloud_print/service/win/service_controller.h"
+
+namespace {
+
+base::FilePath GetShortcutPath(int dir_key, bool with_subdir) {
+ base::FilePath path;
+ if (!PathService::Get(dir_key, &path))
+ return base::FilePath();
+ path = path.Append(cloud_print::LoadLocalString(IDS_FULL_PRODUCT_NAME));
+ if (with_subdir)
+ path = path.Append(cloud_print::LoadLocalString(IDS_FULL_PRODUCT_NAME));
+ return path.InsertBeforeExtension(L".lnk");
+}
+
+void CreateShortcut(int dir_key, bool with_subdir,
+ base::win::ShortcutOperation operation) {
+ base::FilePath path = GetShortcutPath(dir_key, with_subdir);
+ if (path.empty())
+ return;
+ file_util::CreateDirectory(path.DirName());
+ base::win::ShortcutProperties properties;
+
+ base::FilePath exe_path;
+ if (!PathService::Get(base::FILE_EXE, &exe_path))
+ return;
+ properties.set_target(exe_path);
+ properties.set_working_dir(exe_path.DirName());
+ CreateOrUpdateShortcutLink(path, properties, operation);
+}
+
+void CreateShortcuts(bool create_always) {
+ base::win::ScopedCOMInitializer co_init;
+ base::win::ShortcutOperation operation =
+ create_always ? base::win::SHORTCUT_CREATE_ALWAYS :
+ base::win::SHORTCUT_REPLACE_EXISTING;
+ CreateShortcut(base::DIR_COMMON_START_MENU, true, operation);
+ CreateShortcut(base::DIR_COMMON_DESKTOP, false, operation);
+}
+
+void DeleteShortcut(int dir_key, bool with_subdir) {
+ base::FilePath path = GetShortcutPath(dir_key, with_subdir);
+ if (path.empty())
+ return;
+ if (with_subdir)
+ file_util::Delete(path.DirName(), true);
+ else
+ file_util::Delete(path, false);
+}
+
+void DeleteShortcuts() {
+ DeleteShortcut(base::DIR_COMMON_START_MENU, true);
+ DeleteShortcut(base::DIR_COMMON_DESKTOP, false);
+}
+
+} // namespace
+
+HRESULT ProcessInstallerSwitches() {
+ const CommandLine& command_line(*CommandLine::ForCurrentProcess());
+
+ if (command_line.HasSwitch(kInstallSwitch)) {
+ base::FilePath old_location =
+ cloud_print::GetInstallLocation(kGoogleUpdateId);
+
+ cloud_print::CreateUninstallKey(
+ kGoogleUpdateId, cloud_print::LoadLocalString(IDS_FULL_PRODUCT_NAME),
+ kUninstallSwitch);
+
+ ServiceController controller(cloud_print::LoadLocalString(IDS_SERVICENAME));
+ HRESULT hr = controller.UpdateBinaryPath();
+ if (FAILED(hr))
+ return hr;
+
+ if (!old_location.empty() &&
+ cloud_print::IsProgramsFilesParent(old_location) &&
+ old_location != cloud_print::GetInstallLocation(kGoogleUpdateId)) {
+ file_util::Delete(old_location, true);
+ }
+
+ cloud_print::SetGoogleUpdateKeys(
+ kGoogleUpdateId, cloud_print::LoadLocalString(IDS_FULL_PRODUCT_NAME));
+
+ CreateShortcuts(old_location.empty());
+
+ return S_OK;
+ } else if (command_line.HasSwitch(kUninstallSwitch)) {
+ ServiceController controller(cloud_print::LoadLocalString(IDS_SERVICENAME));
+ HRESULT hr = controller.UninstallService();
+ if (FAILED(hr))
+ return hr;
+
+ DeleteShortcuts();
+
+ cloud_print::DeleteGoogleUpdateKeys(kGoogleUpdateId);
+ cloud_print::DeleteUninstallKey(kGoogleUpdateId);
+ cloud_print::DeleteProgramDir(kDeleteSwitch);
+ return S_OK;
+ } else if (command_line.HasSwitch(kDeleteSwitch)) {
+ base::FilePath delete_path = command_line.GetSwitchValuePath(kDeleteSwitch);
+ if (!delete_path.empty() &&
+ cloud_print::IsProgramsFilesParent(delete_path)) {
+ file_util::Delete(delete_path, true);
+ }
+ return S_OK;
+ }
+
+ return S_FALSE;
+}
+
« no previous file with comments | « cloud_print/service/win/installer.h ('k') | cloud_print/service/win/service_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698