using System; namespace Wayne.Lib.IO { /// /// Support class managing file paths of the Wayne system. /// public static class Paths { #region Construction static Paths() { pathsImplementation = FileSupport.fileSupport.Paths; } #endregion #region fields /// /// The current implementation to be used. /// private static IPaths pathsImplementation; #endregion #region Properties /// /// The root path used by Wayne applications. /// public static string Root { get { return pathsImplementation.Root; } } /// /// The base path to all config files. /// public static string Config { get { return pathsImplementation.Config; } } /// /// The base path to all transaction files. /// public static string Transactions { get { return pathsImplementation.Transactions; } } /// /// The base path to all log files. /// public static string Log { get { return pathsImplementation.Log; } } /// /// The complete path (including the file name) to the executable. /// public static string ExecutablePath { get { return pathsImplementation.ExecutablePath; } } /// /// The directory path to the executable. /// public static string ExecutableDirectory { get { return pathsImplementation.ExecutableDirectory; } } /// /// The base path to data files. /// public static string Data { get { return pathsImplementation.Data; } } #endregion #region Methods /// /// Combines the Root path and the given subPath. /// /// The sub path (under the main path). /// public static string Combine(string subPath) { return pathsImplementation.Combine(subPath); } /// /// Combines the Root path and the given subPath and file name. /// /// The sub path (under the main path). /// An additional sub path (or the name of a file). /// public static string Combine(string subPath, string subPath2) { return pathsImplementation.Combine(subPath, subPath2); } /// /// Returns the config path to the given config name. /// /// The name of the config. /// public static string GetConfigPath(string configName) { return pathsImplementation.GetConfigPath(configName); } /// /// Returns the config path to the given config name. /// /// The name of the config. /// The name of a config file. /// public static string GetConfigPath(string configName, string fileName) { return pathsImplementation.GetConfigPath(configName, fileName); } /// /// Returns the transaction file path to the given terminal type. /// /// The name of the terminal type. /// public static string GetTransactionsPath(string terminalType) { return pathsImplementation.GetTransactionsPath(terminalType); } /// /// Returns the transaction file path to the given terminal type. /// /// The name of the terminal type. /// The name of the sub state. /// public static string GetTransactionsPath(string terminalType, string subState) { return pathsImplementation.GetTransactionsPath(terminalType, subState); } /// /// Replaces the extension of a file (e.g. from C:\MyFile.aaa to C:\MyFile.bbb) /// /// /// /// public static string ReplaceExtension(string fileName, string newExtension) { return pathsImplementation.ReplaceExtension(fileName, newExtension); } #endregion #region Parse /// /// Parses the path to replace any %...% variables with the current actual path. /// /// /// public static string Parse(string path) { return pathsImplementation.Parse(path); } private static void Replace(ref string path, string variableName, string actualText) { int index = path.IndexOf(variableName, StringComparison.InvariantCultureIgnoreCase); if (index > -1) path = path.Remove(index, variableName.Length).Insert(index, actualText); } /// /// Checks if file exists /// /// /// [Obsolete("Use the DirectoryExists() in FileSupport instead!")] public static bool FileExists(string fileName) { return pathsImplementation.FileExists(Parse(fileName)); } /// /// Checks if directory exists /// /// /// [Obsolete("Use the DirectoryExists() in FileSupport instead!")] public static bool DirectoryExists(string path) { return pathsImplementation.EnsureDirectoryExists(path); } /// /// Ensures the directory exists by trying to create it if it does not exist already. /// /// /// [Obsolete("Use the DirectoryExists() in FileSupport instead!")] public static bool EnsureDirectoryExists(string path) { return pathsImplementation.EnsureDirectoryExists(path); } #endregion } }