mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-04-13 20:47:24 +00:00
PathUtils.Join supports arrays of 0 or 1 items
This commit is contained in:
parent
3feb77dbf4
commit
e4bc8289cc
1 changed files with 20 additions and 13 deletions
|
|
@ -2,6 +2,7 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using ICD.Common.Properties;
|
using ICD.Common.Properties;
|
||||||
|
using ICD.Common.Utils.Extensions;
|
||||||
using ICD.Common.Utils.IO;
|
using ICD.Common.Utils.IO;
|
||||||
|
|
||||||
namespace ICD.Common.Utils
|
namespace ICD.Common.Utils
|
||||||
|
|
@ -68,14 +69,9 @@ namespace ICD.Common.Utils
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static string Join(params string[] items)
|
public static string Join(params string[] items)
|
||||||
{
|
{
|
||||||
try
|
return items.Length > 1
|
||||||
{
|
? items.Skip(1).Aggregate(items.First(), IcdPath.Combine)
|
||||||
return items.Skip(1).Aggregate(items.First(), IcdPath.Combine);
|
: items.FirstOrDefault(string.Empty);
|
||||||
}
|
|
||||||
catch (ArgumentException e)
|
|
||||||
{
|
|
||||||
throw new ArgumentException("Failed to join path: " + StringUtils.ArrayFormat(items), e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -141,15 +137,26 @@ namespace ICD.Common.Utils
|
||||||
string local = Join(localPath);
|
string local = Join(localPath);
|
||||||
|
|
||||||
// Program slot configuration
|
// Program slot configuration
|
||||||
string programPath = Join(ProgramConfigPath, local);
|
string programPath = GetProgramConfigPath(localPath);
|
||||||
if (PathExists(programPath))
|
if (PathExists(programPath))
|
||||||
return programPath;
|
return programPath;
|
||||||
|
|
||||||
// Common program configuration
|
// Common program configuration
|
||||||
string commonPath = Join(CommonConfigPath, local);
|
string commonPath = GetCommonConfigPath(local);
|
||||||
return PathExists(commonPath)
|
if (PathExists(commonPath))
|
||||||
? commonPath
|
return commonPath;
|
||||||
: Join(IcdDirectory.GetApplicationDirectory(), local); // Installation defaults
|
|
||||||
|
return Join(IcdDirectory.GetApplicationDirectory(), local); // Installation defaults
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Appends the local path to the common config path.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static string GetCommonConfigPath(params string[] localPath)
|
||||||
|
{
|
||||||
|
string local = Join(localPath);
|
||||||
|
return Join(CommonConfigPath, local);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue