private VerbCapability GetFileType([NotNull] string progID, [NotNull] CommandMapper commandMapper)
{
#region Sanity checks
if (string.IsNullOrEmpty(progID)) throw new ArgumentNullException(nameof(progID));
if (commandMapper == null) throw new ArgumentNullException(nameof(commandMapper));
#endregion
using (var progIDKey = Registry.ClassesRoot.OpenSubKey(progID))
{
if (progIDKey == null) return null;
VerbCapability capability;
if (progIDKey.GetValue(DesktopIntegration.Windows.UrlProtocol.ProtocolIndicator) == null)
{ // Normal file type
var fileType = new FileType {ID = progID};
foreach (var fileAssoc in FileAssocs.Where(fileAssoc => fileAssoc.Value == progID && !string.IsNullOrEmpty(fileAssoc.Key)))
{
using (var assocKey = Registry.ClassesRoot.OpenSubKey(fileAssoc.Key))
{
if (assocKey == null) continue;
fileType.Extensions.Add(new FileTypeExtension
{
Value = fileAssoc.Key,
MimeType = assocKey.GetValue(DesktopIntegration.Windows.FileType.RegValueContentType, "").ToString(),
PerceivedType = assocKey.GetValue(DesktopIntegration.Windows.FileType.RegValuePerceivedType, "").ToString()
});
}
}
capability = fileType;
}
else
{ // URL protocol handler
capability = new UrlProtocol {ID = progID};
}
string description = progIDKey.GetValue(DesktopIntegration.Windows.FileType.RegValueFriendlyName, "").ToString();
if (string.IsNullOrEmpty(description)) description = progIDKey.GetValue("", "").ToString();
capability.Descriptions.Add(description);
capability.Verbs.AddRange(GetVerbs(progIDKey, commandMapper));
// Only return capabilities that have verbs associated with them
return capability.Verbs.Count == 0 ? null : capability;
}
}
}