private (string path, bool success) ResolveRegistryDirectory(IncludeDirRule directory) { string path = null; var success = true; var registryPath = directory.Path.Substring(1); var indexOfSubPath = registryPath.IndexOf(";"); var subPath = ""; if (indexOfSubPath >= 0) { subPath = registryPath.Substring(indexOfSubPath + 1); registryPath = registryPath.Substring(0, indexOfSubPath); } var indexOfKey = registryPath.LastIndexOf("\\"); var subKeyStr = registryPath.Substring(indexOfKey + 1); registryPath = registryPath.Substring(0, indexOfKey); var indexOfHive = registryPath.IndexOf("\\"); var hiveStr = registryPath.Substring(0, indexOfHive).ToUpper(); registryPath = registryPath.Substring(indexOfHive + 1); try { var hive = RegistryHive.LocalMachine; switch (hiveStr) { case "HKEY_LOCAL_MACHINE": hive = RegistryHive.LocalMachine; break; case "HKEY_CURRENT_USER": hive = RegistryHive.CurrentUser; break; case "HKEY_CURRENT_CONFIG": hive = RegistryHive.CurrentConfig; break; } var rootKey = RegistryKey.OpenBaseKey(hive, RegistryView.Registry32); var subKey = rootKey.OpenSubKey(registryPath); if (subKey == null) { Logger.Error("Unable to locate key [{0}] in registry", registryPath); success = false; } path = Path.Combine(subKey.GetValue(subKeyStr).ToString(), subPath); } catch (Exception) { Logger.Error("Unable to locate key [{0}] in registry", registryPath); success = false; } return(path, success); }
public Item(string path, IncludeDirRule rule) { Path = path; Rule = rule; }