OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 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. |
| 4 |
| 5 #include "chrome/browser/file_associations_win.h" |
| 6 |
| 7 #include <windows.h> |
| 8 #include <shlobj.h> |
| 9 |
| 10 #include "base/strings/string16.h" |
| 11 #include "base/strings/utf_string_conversions.h" |
| 12 #include "chrome/installer/util/shell_util.h" |
| 13 |
| 14 bool AddWindowsFileAssociations(const std::string& progid, |
| 15 const base::CommandLine& command_line, |
| 16 const std::string& file_type_name, |
| 17 const base::FilePath& icon_path, |
| 18 const std::set<std::string>& file_extensions) { |
| 19 std::set<base::string16> file_extensions_16; |
| 20 for (std::set<std::string>::const_iterator it = file_extensions.begin(); |
| 21 it != file_extensions.end(); |
| 22 ++it) { |
| 23 file_extensions_16.insert(base::UTF8ToUTF16(*it)); |
| 24 } |
| 25 if (!ShellUtil::AddFileAssociations(base::UTF8ToUTF16(progid), |
| 26 command_line, |
| 27 base::UTF8ToUTF16(file_type_name), |
| 28 icon_path, |
| 29 file_extensions_16)) { |
| 30 return false; |
| 31 } |
| 32 |
| 33 // Success. Tell Windows Explorer to update its cache. |
| 34 SHChangeNotify( |
| 35 SHCNE_ASSOCCHANGED, SHCNF_IDLIST | SHCNF_FLUSHNOWAIT, NULL, NULL); |
| 36 return true; |
| 37 } |
| 38 |
| 39 bool DeleteWindowsFileAssociations(const std::string& progid) { |
| 40 if (!ShellUtil::DeleteFileAssociations(base::UTF8ToUTF16(progid))) |
| 41 return false; |
| 42 |
| 43 // Success. Tell Windows Explorer to update its cache. |
| 44 SHChangeNotify( |
| 45 SHCNE_ASSOCCHANGED, SHCNF_IDLIST | SHCNF_FLUSHNOWAIT, NULL, NULL); |
| 46 return true; |
| 47 } |
OLD | NEW |