OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 #include "cloud_print/service/win/installer.h" | 5 #include "cloud_print/service/win/installer.h" |
6 | 6 |
7 #include <winerror.h> | 7 #include <winerror.h> |
8 | 8 |
9 #include "base/at_exit.h" | 9 #include "base/at_exit.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 base::win::SHORTCUT_REPLACE_EXISTING; | 57 base::win::SHORTCUT_REPLACE_EXISTING; |
58 CreateShortcut(base::DIR_COMMON_START_MENU, true, operation); | 58 CreateShortcut(base::DIR_COMMON_START_MENU, true, operation); |
59 CreateShortcut(base::DIR_COMMON_DESKTOP, false, operation); | 59 CreateShortcut(base::DIR_COMMON_DESKTOP, false, operation); |
60 } | 60 } |
61 | 61 |
62 void DeleteShortcut(int dir_key, bool with_subdir) { | 62 void DeleteShortcut(int dir_key, bool with_subdir) { |
63 base::FilePath path = GetShortcutPath(dir_key, with_subdir); | 63 base::FilePath path = GetShortcutPath(dir_key, with_subdir); |
64 if (path.empty()) | 64 if (path.empty()) |
65 return; | 65 return; |
66 if (with_subdir) | 66 if (with_subdir) |
67 file_util::Delete(path.DirName(), true); | 67 base::Delete(path.DirName(), true); |
68 else | 68 else |
69 file_util::Delete(path, false); | 69 base::Delete(path, false); |
70 } | 70 } |
71 | 71 |
72 void DeleteShortcuts() { | 72 void DeleteShortcuts() { |
73 DeleteShortcut(base::DIR_COMMON_START_MENU, true); | 73 DeleteShortcut(base::DIR_COMMON_START_MENU, true); |
74 DeleteShortcut(base::DIR_COMMON_DESKTOP, false); | 74 DeleteShortcut(base::DIR_COMMON_DESKTOP, false); |
75 } | 75 } |
76 | 76 |
77 } // namespace | 77 } // namespace |
78 | 78 |
79 HRESULT ProcessInstallerSwitches() { | 79 HRESULT ProcessInstallerSwitches() { |
80 const CommandLine& command_line(*CommandLine::ForCurrentProcess()); | 80 const CommandLine& command_line(*CommandLine::ForCurrentProcess()); |
81 | 81 |
82 if (command_line.HasSwitch(kInstallSwitch)) { | 82 if (command_line.HasSwitch(kInstallSwitch)) { |
83 base::FilePath old_location = | 83 base::FilePath old_location = |
84 cloud_print::GetInstallLocation(kGoogleUpdateId); | 84 cloud_print::GetInstallLocation(kGoogleUpdateId); |
85 | 85 |
86 cloud_print::CreateUninstallKey( | 86 cloud_print::CreateUninstallKey( |
87 kGoogleUpdateId, cloud_print::LoadLocalString(IDS_FULL_PRODUCT_NAME), | 87 kGoogleUpdateId, cloud_print::LoadLocalString(IDS_FULL_PRODUCT_NAME), |
88 kUninstallSwitch); | 88 kUninstallSwitch); |
89 | 89 |
90 ServiceController controller; | 90 ServiceController controller; |
91 HRESULT hr = controller.UpdateBinaryPath(); | 91 HRESULT hr = controller.UpdateBinaryPath(); |
92 if (FAILED(hr)) | 92 if (FAILED(hr)) |
93 return hr; | 93 return hr; |
94 | 94 |
95 if (!old_location.empty() && | 95 if (!old_location.empty() && |
96 cloud_print::IsProgramsFilesParent(old_location) && | 96 cloud_print::IsProgramsFilesParent(old_location) && |
97 old_location != cloud_print::GetInstallLocation(kGoogleUpdateId)) { | 97 old_location != cloud_print::GetInstallLocation(kGoogleUpdateId)) { |
98 file_util::Delete(old_location, true); | 98 base::Delete(old_location, true); |
99 } | 99 } |
100 | 100 |
101 cloud_print::SetGoogleUpdateKeys( | 101 cloud_print::SetGoogleUpdateKeys( |
102 kGoogleUpdateId, cloud_print::LoadLocalString(IDS_FULL_PRODUCT_NAME)); | 102 kGoogleUpdateId, cloud_print::LoadLocalString(IDS_FULL_PRODUCT_NAME)); |
103 | 103 |
104 CreateShortcuts(old_location.empty()); | 104 CreateShortcuts(old_location.empty()); |
105 | 105 |
106 return S_OK; | 106 return S_OK; |
107 } else if (command_line.HasSwitch(kUninstallSwitch)) { | 107 } else if (command_line.HasSwitch(kUninstallSwitch)) { |
108 ServiceController controller; | 108 ServiceController controller; |
109 HRESULT hr = controller.UninstallService(); | 109 HRESULT hr = controller.UninstallService(); |
110 if (FAILED(hr)) | 110 if (FAILED(hr)) |
111 return hr; | 111 return hr; |
112 | 112 |
113 DeleteShortcuts(); | 113 DeleteShortcuts(); |
114 | 114 |
115 cloud_print::DeleteGoogleUpdateKeys(kGoogleUpdateId); | 115 cloud_print::DeleteGoogleUpdateKeys(kGoogleUpdateId); |
116 cloud_print::DeleteUninstallKey(kGoogleUpdateId); | 116 cloud_print::DeleteUninstallKey(kGoogleUpdateId); |
117 cloud_print::DeleteProgramDir(kDeleteSwitch); | 117 cloud_print::DeleteProgramDir(kDeleteSwitch); |
118 return S_OK; | 118 return S_OK; |
119 } else if (command_line.HasSwitch(kDeleteSwitch)) { | 119 } else if (command_line.HasSwitch(kDeleteSwitch)) { |
120 base::FilePath delete_path = command_line.GetSwitchValuePath(kDeleteSwitch); | 120 base::FilePath delete_path = command_line.GetSwitchValuePath(kDeleteSwitch); |
121 if (!delete_path.empty() && | 121 if (!delete_path.empty() && |
122 cloud_print::IsProgramsFilesParent(delete_path)) { | 122 cloud_print::IsProgramsFilesParent(delete_path)) { |
123 file_util::Delete(delete_path, true); | 123 base::Delete(delete_path, true); |
124 } | 124 } |
125 return S_OK; | 125 return S_OK; |
126 } | 126 } |
127 | 127 |
128 return S_FALSE; | 128 return S_FALSE; |
129 } | 129 } |
130 | 130 |
131 class CloudPrintServiceSetupModule | 131 class CloudPrintServiceSetupModule |
132 : public ATL::CAtlExeModuleT<CloudPrintServiceSetupModule> { | 132 : public ATL::CAtlExeModuleT<CloudPrintServiceSetupModule> { |
133 }; | 133 }; |
134 | 134 |
135 CloudPrintServiceSetupModule _AtlModule; | 135 CloudPrintServiceSetupModule _AtlModule; |
136 | 136 |
137 int WINAPI WinMain(__in HINSTANCE hInstance, | 137 int WINAPI WinMain(__in HINSTANCE hInstance, |
138 __in HINSTANCE hPrevInstance, | 138 __in HINSTANCE hPrevInstance, |
139 __in LPSTR lpCmdLine, | 139 __in LPSTR lpCmdLine, |
140 __in int nCmdShow) { | 140 __in int nCmdShow) { |
141 base::AtExitManager at_exit; | 141 base::AtExitManager at_exit; |
142 CommandLine::Init(0, NULL); | 142 CommandLine::Init(0, NULL); |
143 return ProcessInstallerSwitches(); | 143 return ProcessInstallerSwitches(); |
144 } | 144 } |
OLD | NEW |