| 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/common/win/install_utils.h" | 5 #include "cloud_print/common/win/install_utils.h" |
| 6 | 6 |
| 7 #include <windows.h> | 7 #include <windows.h> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 const wchar_t kDisplayVersion[] = L"DisplayVersion"; | 36 const wchar_t kDisplayVersion[] = L"DisplayVersion"; |
| 37 const wchar_t kDisplayIcon[] = L"DisplayIcon"; | 37 const wchar_t kDisplayIcon[] = L"DisplayIcon"; |
| 38 const wchar_t kDisplayName[] = L"DisplayName"; | 38 const wchar_t kDisplayName[] = L"DisplayName"; |
| 39 const wchar_t kPublisher[] = L"Publisher"; | 39 const wchar_t kPublisher[] = L"Publisher"; |
| 40 const wchar_t kNoModify[] = L"NoModify"; | 40 const wchar_t kNoModify[] = L"NoModify"; |
| 41 const wchar_t kNoRepair[] = L"NoRepair"; | 41 const wchar_t kNoRepair[] = L"NoRepair"; |
| 42 | 42 |
| 43 } // namespace | 43 } // namespace |
| 44 | 44 |
| 45 | 45 |
| 46 void SetGoogleUpdateKeys(const string16& product_id, | 46 void SetGoogleUpdateKeys(const base::string16& product_id, |
| 47 const string16& product_name) { | 47 const base::string16& product_name) { |
| 48 base::win::RegKey key; | 48 base::win::RegKey key; |
| 49 if (key.Create(HKEY_LOCAL_MACHINE, | 49 if (key.Create(HKEY_LOCAL_MACHINE, |
| 50 (cloud_print::kClientsKey + product_id).c_str(), | 50 (cloud_print::kClientsKey + product_id).c_str(), |
| 51 KEY_SET_VALUE) != ERROR_SUCCESS) { | 51 KEY_SET_VALUE) != ERROR_SUCCESS) { |
| 52 LOG(ERROR) << "Unable to open key"; | 52 LOG(ERROR) << "Unable to open key"; |
| 53 } | 53 } |
| 54 | 54 |
| 55 // Get the version from the resource file. | 55 // Get the version from the resource file. |
| 56 string16 version_string; | 56 base::string16 version_string; |
| 57 scoped_ptr<FileVersionInfo> version_info( | 57 scoped_ptr<FileVersionInfo> version_info( |
| 58 FileVersionInfo::CreateFileVersionInfoForCurrentModule()); | 58 FileVersionInfo::CreateFileVersionInfoForCurrentModule()); |
| 59 | 59 |
| 60 if (version_info.get()) { | 60 if (version_info.get()) { |
| 61 FileVersionInfoWin* version_info_win = | 61 FileVersionInfoWin* version_info_win = |
| 62 static_cast<FileVersionInfoWin*>(version_info.get()); | 62 static_cast<FileVersionInfoWin*>(version_info.get()); |
| 63 version_string = version_info_win->product_version(); | 63 version_string = version_info_win->product_version(); |
| 64 } else { | 64 } else { |
| 65 LOG(ERROR) << "Unable to get version string"; | 65 LOG(ERROR) << "Unable to get version string"; |
| 66 // Use a random version string so that Google Update has something to go by. | 66 // Use a random version string so that Google Update has something to go by. |
| 67 version_string = L"0.0.0.99"; | 67 version_string = L"0.0.0.99"; |
| 68 } | 68 } |
| 69 | 69 |
| 70 if (key.WriteValue(kVersionKey, version_string.c_str()) != ERROR_SUCCESS || | 70 if (key.WriteValue(kVersionKey, version_string.c_str()) != ERROR_SUCCESS || |
| 71 key.WriteValue(kNameKey, product_name.c_str()) != ERROR_SUCCESS) { | 71 key.WriteValue(kNameKey, product_name.c_str()) != ERROR_SUCCESS) { |
| 72 LOG(ERROR) << "Unable to set registry keys"; | 72 LOG(ERROR) << "Unable to set registry keys"; |
| 73 } | 73 } |
| 74 } | 74 } |
| 75 | 75 |
| 76 void SetGoogleUpdateError(const string16& product_id, const string16& message) { | 76 void SetGoogleUpdateError(const base::string16& product_id, |
| 77 const base::string16& message) { |
| 77 LOG(ERROR) << message; | 78 LOG(ERROR) << message; |
| 78 base::win::RegKey key; | 79 base::win::RegKey key; |
| 79 if (key.Create(HKEY_LOCAL_MACHINE, | 80 if (key.Create(HKEY_LOCAL_MACHINE, |
| 80 (cloud_print::kClientStateKey + product_id).c_str(), | 81 (cloud_print::kClientStateKey + product_id).c_str(), |
| 81 KEY_SET_VALUE) != ERROR_SUCCESS) { | 82 KEY_SET_VALUE) != ERROR_SUCCESS) { |
| 82 LOG(ERROR) << "Unable to open key"; | 83 LOG(ERROR) << "Unable to open key"; |
| 83 } | 84 } |
| 84 | 85 |
| 85 if (key.WriteValue(kRegValueInstallerResult, | 86 if (key.WriteValue(kRegValueInstallerResult, |
| 86 kInstallerResultFailedCustomError) != ERROR_SUCCESS || | 87 kInstallerResultFailedCustomError) != ERROR_SUCCESS || |
| 87 key.WriteValue(kRegValueInstallerResultUIString, | 88 key.WriteValue(kRegValueInstallerResultUIString, |
| 88 message.c_str()) != ERROR_SUCCESS) { | 89 message.c_str()) != ERROR_SUCCESS) { |
| 89 LOG(ERROR) << "Unable to set registry keys"; | 90 LOG(ERROR) << "Unable to set registry keys"; |
| 90 } | 91 } |
| 91 } | 92 } |
| 92 | 93 |
| 93 void DeleteGoogleUpdateKeys(const string16& product_id) { | 94 void DeleteGoogleUpdateKeys(const base::string16& product_id) { |
| 94 base::win::RegKey key; | 95 base::win::RegKey key; |
| 95 if (key.Open(HKEY_LOCAL_MACHINE, | 96 if (key.Open(HKEY_LOCAL_MACHINE, |
| 96 (cloud_print::kClientsKey + product_id).c_str(), | 97 (cloud_print::kClientsKey + product_id).c_str(), |
| 97 DELETE) != ERROR_SUCCESS) { | 98 DELETE) != ERROR_SUCCESS) { |
| 98 LOG(ERROR) << "Unable to open key to delete"; | 99 LOG(ERROR) << "Unable to open key to delete"; |
| 99 return; | 100 return; |
| 100 } | 101 } |
| 101 if (key.DeleteKey(L"") != ERROR_SUCCESS) { | 102 if (key.DeleteKey(L"") != ERROR_SUCCESS) { |
| 102 LOG(ERROR) << "Unable to delete key"; | 103 LOG(ERROR) << "Unable to delete key"; |
| 103 } | 104 } |
| 104 } | 105 } |
| 105 | 106 |
| 106 void CreateUninstallKey(const string16& uninstall_id, | 107 void CreateUninstallKey(const base::string16& uninstall_id, |
| 107 const string16& product_name, | 108 const base::string16& product_name, |
| 108 const std::string& uninstall_switch) { | 109 const std::string& uninstall_switch) { |
| 109 // Now write the Windows Uninstall entries | 110 // Now write the Windows Uninstall entries |
| 110 // Minimal error checking here since the install can continue | 111 // Minimal error checking here since the install can continue |
| 111 // if this fails. | 112 // if this fails. |
| 112 base::win::RegKey key; | 113 base::win::RegKey key; |
| 113 if (key.Create(HKEY_LOCAL_MACHINE, | 114 if (key.Create(HKEY_LOCAL_MACHINE, |
| 114 (cloud_print::kUninstallKey + uninstall_id).c_str(), | 115 (cloud_print::kUninstallKey + uninstall_id).c_str(), |
| 115 KEY_SET_VALUE) != ERROR_SUCCESS) { | 116 KEY_SET_VALUE) != ERROR_SUCCESS) { |
| 116 LOG(ERROR) << "Unable to open key"; | 117 LOG(ERROR) << "Unable to open key"; |
| 117 return; | 118 return; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 139 key.WriteValue(kPublisher, version_info_win->company_name().c_str()); | 140 key.WriteValue(kPublisher, version_info_win->company_name().c_str()); |
| 140 } else { | 141 } else { |
| 141 LOG(ERROR) << "Unable to get version string"; | 142 LOG(ERROR) << "Unable to get version string"; |
| 142 } | 143 } |
| 143 key.WriteValue(kDisplayName, product_name.c_str()); | 144 key.WriteValue(kDisplayName, product_name.c_str()); |
| 144 key.WriteValue(kDisplayIcon, unstall_binary.value().c_str()); | 145 key.WriteValue(kDisplayIcon, unstall_binary.value().c_str()); |
| 145 key.WriteValue(kNoModify, 1); | 146 key.WriteValue(kNoModify, 1); |
| 146 key.WriteValue(kNoRepair, 1); | 147 key.WriteValue(kNoRepair, 1); |
| 147 } | 148 } |
| 148 | 149 |
| 149 void DeleteUninstallKey(const string16& uninstall_id) { | 150 void DeleteUninstallKey(const base::string16& uninstall_id) { |
| 150 ::RegDeleteKey(HKEY_LOCAL_MACHINE, | 151 ::RegDeleteKey(HKEY_LOCAL_MACHINE, |
| 151 (cloud_print::kUninstallKey + uninstall_id).c_str()); | 152 (cloud_print::kUninstallKey + uninstall_id).c_str()); |
| 152 } | 153 } |
| 153 | 154 |
| 154 base::FilePath GetInstallLocation(const string16& uninstall_id) { | 155 base::FilePath GetInstallLocation(const base::string16& uninstall_id) { |
| 155 base::win::RegKey key; | 156 base::win::RegKey key; |
| 156 if (key.Open(HKEY_LOCAL_MACHINE, | 157 if (key.Open(HKEY_LOCAL_MACHINE, |
| 157 (cloud_print::kUninstallKey + uninstall_id).c_str(), | 158 (cloud_print::kUninstallKey + uninstall_id).c_str(), |
| 158 KEY_QUERY_VALUE) != ERROR_SUCCESS) { | 159 KEY_QUERY_VALUE) != ERROR_SUCCESS) { |
| 159 // Not installed. | 160 // Not installed. |
| 160 return base::FilePath(); | 161 return base::FilePath(); |
| 161 } | 162 } |
| 162 string16 install_path_value; | 163 base::string16 install_path_value; |
| 163 key.ReadValue(kInstallLocation, &install_path_value); | 164 key.ReadValue(kInstallLocation, &install_path_value); |
| 164 return base::FilePath(install_path_value); | 165 return base::FilePath(install_path_value); |
| 165 } | 166 } |
| 166 | 167 |
| 167 void DeleteProgramDir(const std::string& delete_switch) { | 168 void DeleteProgramDir(const std::string& delete_switch) { |
| 168 base::FilePath installer_source; | 169 base::FilePath installer_source; |
| 169 if (!PathService::Get(base::FILE_EXE, &installer_source)) | 170 if (!PathService::Get(base::FILE_EXE, &installer_source)) |
| 170 return; | 171 return; |
| 171 // Deletes only subdirs of program files. | 172 // Deletes only subdirs of program files. |
| 172 if (!IsProgramsFilesParent(installer_source)) | 173 if (!IsProgramsFilesParent(installer_source)) |
| (...skipping 14 matching lines...) Expand all Loading... |
| 187 | 188 |
| 188 bool IsProgramsFilesParent(const base::FilePath& path) { | 189 bool IsProgramsFilesParent(const base::FilePath& path) { |
| 189 base::FilePath program_files; | 190 base::FilePath program_files; |
| 190 if (!PathService::Get(base::DIR_PROGRAM_FILESX86, &program_files)) | 191 if (!PathService::Get(base::DIR_PROGRAM_FILESX86, &program_files)) |
| 191 return false; | 192 return false; |
| 192 return program_files.IsParent(path); | 193 return program_files.IsParent(path); |
| 193 } | 194 } |
| 194 | 195 |
| 195 } // namespace cloud_print | 196 } // namespace cloud_print |
| 196 | 197 |
| OLD | NEW |