|
23 | 23 | *********************************************************************************/ |
24 | 24 |
|
25 | 25 | #include "Icon.h" |
26 | | -#include "SelectionContext.h" |
27 | | -#include "PropertyManager.h" |
28 | | -#include "Win32Registry.h" |
| 26 | +#include "App.h" |
29 | 27 | #include "LoggerHelper.h" |
| 28 | +#include "PropertyManager.h" |
| 29 | +#include "SelectionContext.h" |
30 | 30 | #include "SaUtils.h" |
31 | 31 |
|
32 | 32 | #include "rapidassist/strings.h" |
33 | | -#include "rapidassist/environment.h" |
34 | 33 |
|
35 | 34 | namespace shellanything |
36 | 35 | { |
37 | | - Icon::FileExtensionSet Icon::mUnresolvedFileExtensions; |
38 | | - |
39 | 36 | Icon::Icon() : |
40 | 37 | mIndex(0) // As per documentation, "If the index is not specified, the value 0 is used." See Issue #17, #150 and #155. |
41 | 38 | { |
@@ -89,56 +86,30 @@ namespace shellanything |
89 | 86 |
|
90 | 87 | void Icon::ResolveFileExtensionIcon() |
91 | 88 | { |
92 | | - //is this menu have a file extension ? |
| 89 | + IIconResolutionService* icon_resolution_service = App::GetInstance().GetIconResolutionService(); |
| 90 | + if (icon_resolution_service == NULL) |
| 91 | + { |
| 92 | + SA_LOG(ERROR) << "No Icon Resolution service configured for resolving file extensions to icon."; |
| 93 | + return; |
| 94 | + } |
| 95 | + |
93 | 96 | shellanything::PropertyManager& pmgr = shellanything::PropertyManager::GetInstance(); |
94 | 97 | std::string file_extension = pmgr.Expand(mFileExtension); |
95 | | - if (!file_extension.empty()) |
| 98 | + |
| 99 | + const bool have_resolved_before = icon_resolution_service->HaveResolvedBefore(file_extension); |
| 100 | + const bool have_failed_before = icon_resolution_service->HaveFailedBefore(file_extension); |
| 101 | + |
| 102 | + //Do the actual resolution |
| 103 | + bool success = icon_resolution_service->ResolveFileExtensionIcon(*this); |
| 104 | + |
| 105 | + // Print a success/failure message once. Issue #98. |
| 106 | + if (success && !have_resolved_before) |
| 107 | + { |
| 108 | + SA_LOG(INFO) << "Resolving icon for file extension '" << file_extension << "' to file '" << mPath << "' with index '" << mIndex << "'"; |
| 109 | + } |
| 110 | + else if (!success && !have_failed_before) |
96 | 111 | { |
97 | | - //check for multiple values. keep the first value, forget about other selected file extensions. |
98 | | - const std::string separator = pmgr.GetProperty(SelectionContext::MULTI_SELECTION_SEPARATOR_PROPERTY_NAME); |
99 | | - if (file_extension.find(separator) != std::string::npos) |
100 | | - { |
101 | | - //multiple values detected. |
102 | | - ra::strings::StringVector extension_list = ra::strings::Split(file_extension, separator.c_str()); |
103 | | - if (!extension_list.empty()) |
104 | | - file_extension = extension_list[0]; |
105 | | - } |
106 | | - |
107 | | - //try to find the path to the icon module for the given file extension. |
108 | | - Win32Registry::REGISTRY_ICON resolved_icon = Win32Registry::GetFileTypeIcon(file_extension.c_str()); |
109 | | - |
110 | | - //An icon with a negative index is valid from the registry. |
111 | | - //Only the special case index = -1 should be considered invalid (Issue #17). |
112 | | - //And ShellAnything accept positive (index) and negative index (resource id). (Issue #155, Issue #164). |
113 | | - //See issue #17, 155, 164. |
114 | | - if (Win32Registry::IsValid(resolved_icon)) |
115 | | - { |
116 | | - //found the icon for the file extension |
117 | | - //replace this menu's icon with the new information |
118 | | - SA_LOG(INFO) << "Resolving icon for file extension '" << file_extension << "' to file '" << resolved_icon.path << "' with index '" << resolved_icon.index << "'"; |
119 | | - mPath = resolved_icon.path; |
120 | | - mIndex = resolved_icon.index; |
121 | | - mFileExtension = ""; |
122 | | - } |
123 | | - else |
124 | | - { |
125 | | - //failed to find a valid icon. |
126 | | - //using the default "unknown" icon |
127 | | - Win32Registry::REGISTRY_ICON unknown_file_icon = Win32Registry::GetUnknownFileTypeIcon(); |
128 | | - mPath = unknown_file_icon.path; |
129 | | - mIndex = unknown_file_icon.index; |
130 | | - mFileExtension = ""; |
131 | | - |
132 | | - //show the message only once in logs |
133 | | - const bool is_already_in_log = mUnresolvedFileExtensions.find(file_extension) != mUnresolvedFileExtensions.end(); |
134 | | - if (!is_already_in_log) |
135 | | - { |
136 | | - SA_LOG(WARNING) << "Failed to find icon for file extension '" << file_extension << "'. Resolving icon with default icon for unknown file type '" << unknown_file_icon.path << "' with index '" << unknown_file_icon.index << "'"; |
137 | | - |
138 | | - //remember this failure. |
139 | | - mUnresolvedFileExtensions.insert(file_extension); |
140 | | - } |
141 | | - } |
| 112 | + SA_LOG(WARNING) << "Failed to resolve icon for file extension '" << file_extension << "'."; |
142 | 113 | } |
143 | 114 | } |
144 | 115 |
|
|
0 commit comments