using System; using System.Collections.Generic; using System.Text; using Microsoft.Win32; namespace DelphiProjectHandler.LibraryPaths { public class DelphiLibraryPathsProvider: ILibraryPathsProvider { #region (Public Methods) public DelphiLibraryPathsProvider(LibraryPathType iType) { fLibraryType = iType; } #endregion #region ILibraryPathsProvider Members IList ILibraryPathsProvider.List() { List vPaths = ListPaths(LibraryType); IDictionary vEnvironmentPaths = ListEnvironmentPaths(LibraryType); return BuildPaths(vPaths, vEnvironmentPaths); } #endregion #region (Protected Methods) protected string ReadString(RegistryKey iKey, string iValueName) { return iKey.GetValue(iValueName).ToString(); } protected List ListPaths(LibraryPathType iType) { List vResult = new List(); vResult.AddRange(ReadString(DelphiRegistryKeys.LibraryKey(iType), "Search Path").ToString().Split(';')); return vResult; } protected IDictionary ListEnvironmentPaths(LibraryPathType iType) { Dictionary vResult = new Dictionary(); try { vResult.Add("delphi", ReadString(DelphiRegistryKeys.RootDirKey(iType), "RootDir")); RegistryKey vKey = DelphiRegistryKeys.EnvironmentPathsKey(iType); foreach (string vValueName in vKey.GetValueNames()) vResult.Add(vValueName, vKey.GetValue(vValueName).ToString()); } catch (NotSupportedException) { // In this case return empty dictionary - no environment variables to return } return vResult; } protected IList BuildPaths(List vPaths, IDictionary vEnvironmentPaths) { ILibraryPathsBuilder vBuilder = new DelphiLibraryPathsBuilder(); return vBuilder.Build(vPaths, vEnvironmentPaths); } #endregion #region (Protected Properties) protected LibraryPathType LibraryType { get { return fLibraryType; } } public LibraryPathType fLibraryType; #endregion } }