mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-02-15 12:45:01 +00:00
Whitespace
This commit is contained in:
@@ -6,188 +6,185 @@ using ICD.Common.Utils.IO;
|
|||||||
|
|
||||||
namespace ICD.Common.Utils
|
namespace ICD.Common.Utils
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Provides util methods for working with file/directory paths.
|
/// Provides util methods for working with file/directory paths.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static class PathUtils
|
public static class PathUtils
|
||||||
{
|
{
|
||||||
#region Properties
|
#region Properties
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the path to the root directory of the processor.
|
/// Gets the path to the root directory of the processor.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
public static string RootPath { get { return IcdDirectory.GetDirectoryRoot("\\"); } }
|
public static string RootPath { get { return IcdDirectory.GetDirectoryRoot("\\"); } }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the path to the program directory
|
/// Gets the path to the program directory
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
public static string ProgramPath
|
public static string ProgramPath { get { return IcdDirectory.GetApplicationDirectory(); } }
|
||||||
{
|
|
||||||
get { return IcdDirectory.GetApplicationDirectory(); }
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the path to the NVRAM directory.
|
/// Gets the path to the NVRAM directory.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
public static string NvramPath { get { return Join(RootPath, "NVRAM"); } }
|
public static string NvramPath { get { return Join(RootPath, "NVRAM"); } }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns the absolute path to the configuration directory.
|
/// Returns the absolute path to the configuration directory.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value></value>
|
/// <value></value>
|
||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
public static string ProgramConfigPath
|
public static string ProgramConfigPath
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
string directoryName = string.Format("Program{0:D2}Config", ProgramUtils.ProgramNumber);
|
string directoryName = string.Format("Program{0:D2}Config", ProgramUtils.ProgramNumber);
|
||||||
return Join(NvramPath, directoryName);
|
return Join(NvramPath, directoryName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns the absolute path to the common configuration directory.
|
/// Returns the absolute path to the common configuration directory.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
public static string CommonConfigPath { get { return Join(NvramPath, "CommonConfig"); } }
|
public static string CommonConfigPath { get { return Join(NvramPath, "CommonConfig"); } }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns the absolute path to the common config library directory.
|
/// Returns the absolute path to the common config library directory.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
public static string CommonLibPath { get { return Join(CommonConfigPath, "Lib"); } }
|
public static string CommonLibPath { get { return Join(CommonConfigPath, "Lib"); } }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns the absolute path to the program config library directory.
|
/// Returns the absolute path to the program config library directory.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
public static string ProgramLibPath { get { return Join(ProgramConfigPath, "Lib"); } }
|
public static string ProgramLibPath { get { return Join(ProgramConfigPath, "Lib"); } }
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Methods
|
#region Methods
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a path from the given path nodes.
|
/// Creates a path from the given path nodes.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="items"></param>
|
/// <param name="items"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static string Join(params string[] items)
|
public static string Join(params string[] items)
|
||||||
{
|
{
|
||||||
return items.Length > 1
|
return items.Length > 1
|
||||||
? items.Skip(1).Aggregate(items.First(), IcdPath.Combine)
|
? items.Skip(1).Aggregate(items.First(), IcdPath.Combine)
|
||||||
: items.FirstOrDefault(string.Empty);
|
: items.FirstOrDefault(string.Empty);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the full path for the given path.
|
/// Gets the full path for the given path.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="path"></param>
|
/// <param name="path"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static string GetFullPath(string path)
|
public static string GetFullPath(string path)
|
||||||
{
|
{
|
||||||
return Join(IcdDirectory.GetApplicationDirectory(), path);
|
return Join(IcdDirectory.GetApplicationDirectory(), path);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Replaces the filename while leaving the directory and extension intact.
|
/// Replaces the filename while leaving the directory and extension intact.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="path"></param>
|
/// <param name="path"></param>
|
||||||
/// <param name="newName"></param>
|
/// <param name="newName"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static string ChangeFilenameWithoutExt(string path, string newName)
|
public static string ChangeFilenameWithoutExt(string path, string newName)
|
||||||
{
|
{
|
||||||
string dir = IcdPath.GetDirectoryName(path);
|
string dir = IcdPath.GetDirectoryName(path);
|
||||||
string ext = IcdPath.GetExtension(path);
|
string ext = IcdPath.GetExtension(path);
|
||||||
|
|
||||||
return Join(dir, newName + ext);
|
return Join(dir, newName + ext);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Removes the extension from the given path.
|
/// Removes the extension from the given path.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="path"></param>
|
/// <param name="path"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static string GetPathWithoutExtension(string path)
|
public static string GetPathWithoutExtension(string path)
|
||||||
{
|
{
|
||||||
string dir = IcdPath.GetDirectoryName(path);
|
string dir = IcdPath.GetDirectoryName(path);
|
||||||
string filename = IcdPath.GetFileNameWithoutExtension(path);
|
string filename = IcdPath.GetFileNameWithoutExtension(path);
|
||||||
|
|
||||||
return Join(dir, filename);
|
return Join(dir, filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Recurses over the file paths at the given directory.
|
/// Recurses over the file paths at the given directory.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="path"></param>
|
/// <param name="path"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static IEnumerable<string> RecurseFilePaths(string path)
|
public static IEnumerable<string> RecurseFilePaths(string path)
|
||||||
{
|
{
|
||||||
if (!IcdDirectory.Exists(path))
|
if (!IcdDirectory.Exists(path))
|
||||||
return Enumerable.Empty<string>();
|
return Enumerable.Empty<string>();
|
||||||
|
|
||||||
return RecursionUtils.BreadthFirstSearch(path, IcdDirectory.GetDirectories)
|
return RecursionUtils.BreadthFirstSearch(path, IcdDirectory.GetDirectories)
|
||||||
.SelectMany(p => IcdDirectory.GetFiles(p));
|
.SelectMany(p => IcdDirectory.GetFiles(p));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Searches the program config path, common config path, and application path to
|
/// Searches the program config path, common config path, and application path to
|
||||||
/// find the first config that exists with the given local path.
|
/// find the first config that exists with the given local path.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="localPath"></param>
|
/// <param name="localPath"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
public static string GetDefaultConfigPath(params string[] localPath)
|
public static string GetDefaultConfigPath(params string[] localPath)
|
||||||
{
|
{
|
||||||
string local = Join(localPath);
|
string local = Join(localPath);
|
||||||
|
|
||||||
// Program slot configuration
|
// Program slot configuration
|
||||||
string programPath = GetProgramConfigPath(localPath);
|
string programPath = GetProgramConfigPath(localPath);
|
||||||
if (PathExists(programPath))
|
if (PathExists(programPath))
|
||||||
return programPath;
|
return programPath;
|
||||||
|
|
||||||
// Common program configuration
|
// Common program configuration
|
||||||
string commonPath = GetCommonConfigPath(local);
|
string commonPath = GetCommonConfigPath(local);
|
||||||
if (PathExists(commonPath))
|
if (PathExists(commonPath))
|
||||||
return commonPath;
|
return commonPath;
|
||||||
|
|
||||||
return Join(IcdDirectory.GetApplicationDirectory(), local); // Installation defaults
|
return Join(IcdDirectory.GetApplicationDirectory(), local); // Installation defaults
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Appends the local path to the common config path.
|
/// Appends the local path to the common config path.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static string GetCommonConfigPath(params string[] localPath)
|
public static string GetCommonConfigPath(params string[] localPath)
|
||||||
{
|
{
|
||||||
string local = Join(localPath);
|
string local = Join(localPath);
|
||||||
return Join(CommonConfigPath, local);
|
return Join(CommonConfigPath, local);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Appends the local path to the program config path.
|
/// Appends the local path to the program config path.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static string GetProgramConfigPath(params string[] localPath)
|
public static string GetProgramConfigPath(params string[] localPath)
|
||||||
{
|
{
|
||||||
string local = Join(localPath);
|
string local = Join(localPath);
|
||||||
return Join(ProgramConfigPath, local);
|
return Join(ProgramConfigPath, local);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns true if the given path exists.
|
/// Returns true if the given path exists.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="path"></param>
|
/// <param name="path"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
public static bool PathExists(string path)
|
public static bool PathExists(string path)
|
||||||
{
|
{
|
||||||
return IcdFile.Exists(path) || IcdDirectory.Exists(path);
|
return IcdFile.Exists(path) || IcdDirectory.Exists(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -135,7 +135,7 @@ namespace ICD.Common.Utils
|
|||||||
|
|
||||||
// Edge case, root is the destination
|
// Edge case, root is the destination
|
||||||
foreach (T destination in
|
foreach (T destination in
|
||||||
destinationsToBeProcessed.Where(destination => comparer.Equals(root, destination)))
|
destinationsToBeProcessed.Where(destination => comparer.Equals(root, destination)))
|
||||||
{
|
{
|
||||||
destinationsProcessed.Add(destination);
|
destinationsProcessed.Add(destination);
|
||||||
pathsToReturn.Add(destination, new[] {root});
|
pathsToReturn.Add(destination, new[] {root});
|
||||||
@@ -163,7 +163,7 @@ namespace ICD.Common.Utils
|
|||||||
|
|
||||||
T closureNode = node;
|
T closureNode = node;
|
||||||
foreach (T destination in
|
foreach (T destination in
|
||||||
destinationsToBeProcessed.Where(destination => comparer.Equals(closureNode, destination)))
|
destinationsToBeProcessed.Where(destination => comparer.Equals(closureNode, destination)))
|
||||||
{
|
{
|
||||||
destinationsProcessed.Add(destination);
|
destinationsProcessed.Add(destination);
|
||||||
pathsToReturn.Add(destination, GetPath(destination, root, nodeParents, comparer).Reverse());
|
pathsToReturn.Add(destination, GetPath(destination, root, nodeParents, comparer).Reverse());
|
||||||
|
|||||||
@@ -308,9 +308,7 @@ namespace ICD.Common.Utils.Services
|
|||||||
m_ServicesSection.Enter();
|
m_ServicesSection.Enter();
|
||||||
|
|
||||||
if (m_Services.ContainsKey(tService))
|
if (m_Services.ContainsKey(tService))
|
||||||
{
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
m_Services.Add(tService, service);
|
m_Services.Add(tService, service);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -523,20 +523,18 @@ namespace ICD.Common.Utils
|
|||||||
return text == null ? null : new string(text.Where(c => !Char.IsWhiteSpace(c)).ToArray());
|
return text == null ? null : new string(text.Where(c => !Char.IsWhiteSpace(c)).ToArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns true if the string is entirely whitespace characters, or empty, or null.
|
/// Returns true if the string is entirely whitespace characters, or empty, or null.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="text"></param>
|
/// <param name="text"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static bool IsNullOrWhitespace(string text)
|
public static bool IsNullOrWhitespace(string text)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(text))
|
if (string.IsNullOrEmpty(text))
|
||||||
{
|
return true;
|
||||||
return true;
|
string trimmed = text.Trim();
|
||||||
}
|
return trimmed.Length == 0;
|
||||||
var trimmed = text.Trim();
|
}
|
||||||
return trimmed.Length == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns the password as a series of *s
|
/// Returns the password as a series of *s
|
||||||
|
|||||||
Reference in New Issue
Block a user