Skip to content

Commit

Permalink
A few small changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
Lakritzator committed Oct 1, 2015
1 parent da4f2d7 commit 6e98693
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Dapplo.Config/Ini/IniConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion Dapplo.Config/Language/LanguageLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand Down
42 changes: 29 additions & 13 deletions Dapplo.Config/Support/FileLocations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static class FileLocations
/// Scan the supplied directories for files which match the passed file pattern
/// </summary>
/// <param name="directories"></param>
/// <param name="filePattern"></param>
/// <param name="filePattern">Regular expression for the filename</param>
/// <returns>IEnumerable&lt;Tuple&lt;string,Match&gt;&gt;</returns>
public static IEnumerable<Tuple<string, Match>> Scan(ICollection<string> directories, Regex filePattern)
{
Expand All @@ -49,24 +49,40 @@ where match.Success
select Tuple.Create(file, match);
}

/// <summary>
/// Scan the supplied directories for files which match the passed file pattern
/// </summary>
/// <param name="directories"></param>
/// <param name="simplePattern"></param>
/// <returns>IEnumerable&lt;string&gt;</returns>
public static IEnumerable<string> Scan(ICollection<string> directories, string simplePattern)
{
return from path in directories
where Directory.Exists(path)
from file in Directory.EnumerateFiles(path, simplePattern, SearchOption.AllDirectories)
select file;
}

/// <summary>
/// Get the startup location, which is either the location of the entry assemby, or the executing assembly
/// </summary>
/// <returns>string with the directory of where the running code/applicationName was started</returns>
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;
}

/// <summary>
Expand Down

0 comments on commit 6e98693

Please sign in to comment.