private static Capability GetAutoPlay([NotNull] string handler, [NotNull] RegistryKey hive, [NotNull, ItemNotNull] IEnumerable<ComparableTuple<string>> autoPlayAssocs, [NotNull] CommandMapper commandMapper)
{
#region Sanity checks
if (handler == null) throw new ArgumentNullException(nameof(handler));
if (hive == null) throw new ArgumentNullException(nameof(hive));
if (autoPlayAssocs == null) throw new ArgumentNullException(nameof(autoPlayAssocs));
if (commandMapper == null) throw new ArgumentNullException(nameof(commandMapper));
#endregion
using (var handlerKey = hive.OpenSubKey(DesktopIntegration.Windows.AutoPlay.RegKeyHandlers + @"\" + handler))
{
if (handlerKey == null) return null;
string progID = handlerKey.GetValue(DesktopIntegration.Windows.AutoPlay.RegValueProgID, "").ToString();
string verbName = handlerKey.GetValue(DesktopIntegration.Windows.AutoPlay.RegValueVerb, "").ToString();
using (var progIDKey = Registry.ClassesRoot.OpenSubKey(progID))
{
if (progIDKey == null) throw new IOException(progID + " key not found");
var autoPlay = new AutoPlay
{
ID = handler,
Provider = handlerKey.GetValue(DesktopIntegration.Windows.AutoPlay.RegValueProvider, "").ToString(),
Descriptions = {handlerKey.GetValue(DesktopIntegration.Windows.AutoPlay.RegValueDescription, "").ToString()},
Verb = GetVerb(progIDKey, commandMapper, verbName)
};
autoPlay.Events.AddRange(
from autoPlayAssoc in autoPlayAssocs
where autoPlayAssoc.Value == handler
select new AutoPlayEvent {Name = autoPlayAssoc.Key});
return autoPlay;
}
}
}
}