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