From 6e986931cc31a4d61c9aa77809c07cf40064c7e1 Mon Sep 17 00:00:00 2001 From: Robin Krom Date: Thu, 1 Oct 2015 10:04:17 +0200 Subject: [PATCH] A few small changes. --- Dapplo.Config/Ini/IniConfig.cs | 2 +- Dapplo.Config/Language/LanguageLoader.cs | 2 +- Dapplo.Config/Support/FileLocations.cs | 42 ++++++++++++++++-------- 3 files changed, 31 insertions(+), 15 deletions(-) diff --git a/Dapplo.Config/Ini/IniConfig.cs b/Dapplo.Config/Ini/IniConfig.cs index f38e7c1..141f8b8 100644 --- a/Dapplo.Config/Ini/IniConfig.cs +++ b/Dapplo.Config/Ini/IniConfig.cs @@ -379,7 +379,7 @@ private string CreateFileLocation(bool checkStartupDirectory, string postfix = " { if (checkStartupDirectory) { - var startPath = FileLocations.StartupDirectory(); + var startPath = FileLocations.StartupDirectory; if (startPath != null) { file = Path.Combine(startPath, string.Format("{0}{1}.{2}", _fileName, postfix, IniExtension)); diff --git a/Dapplo.Config/Language/LanguageLoader.cs b/Dapplo.Config/Language/LanguageLoader.cs index f127088..b9e362c 100644 --- a/Dapplo.Config/Language/LanguageLoader.cs +++ b/Dapplo.Config/Language/LanguageLoader.cs @@ -218,7 +218,7 @@ private void ScanFiles(bool checkStartupDirectory, bool checkAppDataDirectory = } if (checkStartupDirectory) { - var startupDirectory = FileLocations.StartupDirectory(); + var startupDirectory = FileLocations.StartupDirectory; if (startupDirectory != null) { directories.Add(Path.Combine(startupDirectory, "languages")); diff --git a/Dapplo.Config/Support/FileLocations.cs b/Dapplo.Config/Support/FileLocations.cs index 292b004..4f18244 100644 --- a/Dapplo.Config/Support/FileLocations.cs +++ b/Dapplo.Config/Support/FileLocations.cs @@ -37,7 +37,7 @@ public static class FileLocations /// Scan the supplied directories for files which match the passed file pattern /// /// - /// + /// Regular expression for the filename /// IEnumerable<Tuple<string,Match>> public static IEnumerable> Scan(ICollection directories, Regex filePattern) { @@ -49,24 +49,40 @@ where match.Success select Tuple.Create(file, match); } + /// + /// Scan the supplied directories for files which match the passed file pattern + /// + /// + /// + /// IEnumerable<string> + public static IEnumerable Scan(ICollection directories, string simplePattern) + { + return from path in directories + where Directory.Exists(path) + from file in Directory.EnumerateFiles(path, simplePattern, SearchOption.AllDirectories) + select file; + } + /// /// Get the startup location, which is either the location of the entry assemby, or the executing assembly /// /// string with the directory of where the running code/applicationName was started - public static string StartupDirectory() + public static string StartupDirectory { - var entryAssembly = Assembly.GetEntryAssembly(); - string startupDirectory; - if (entryAssembly != null) - { - startupDirectory = Path.GetDirectoryName(entryAssembly.Location); - } - else - { - var executingAssembly = Assembly.GetExecutingAssembly(); - startupDirectory = Path.GetDirectoryName(executingAssembly.Location); + get { + var entryAssembly = Assembly.GetEntryAssembly(); + string startupDirectory; + if (entryAssembly != null) + { + startupDirectory = Path.GetDirectoryName(entryAssembly.Location); + } + else + { + var executingAssembly = Assembly.GetExecutingAssembly(); + startupDirectory = Path.GetDirectoryName(executingAssembly.Location); + } + return startupDirectory; } - return startupDirectory; } ///