Paths.cs 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. using System;
  2. using System.IO;
  3. namespace Wayne.Lib.IO
  4. {
  5. /// <summary>
  6. /// Static access to filesupports paths object.
  7. /// </summary>
  8. public static class Paths
  9. {
  10. #region Construction
  11. static Paths()
  12. {
  13. pathsImplementation = FileSupport.fileSupport.Paths;
  14. }
  15. #endregion
  16. #region fields
  17. /// <summary>
  18. /// The current implementation to be used.
  19. /// </summary>
  20. private static IPaths pathsImplementation;
  21. #endregion
  22. #region Properties
  23. /// <summary>
  24. /// The root path used by Wayne applications.
  25. /// </summary>
  26. public static string Root { get { return pathsImplementation.Root; } }
  27. /// <summary>
  28. /// The base path to all config files.
  29. /// </summary>
  30. public static string Config { get { return pathsImplementation.Config; } }
  31. /// <summary>
  32. /// The base path to all transaction files.
  33. /// </summary>
  34. public static string Transactions { get { return pathsImplementation.Transactions; } }
  35. /// <summary>
  36. /// The base path to all log files.
  37. /// </summary>
  38. public static string Log { get { return pathsImplementation.Log; } }
  39. /// <summary>
  40. /// The complete path (including the file name) to the executable.
  41. /// </summary>
  42. public static string ExecutablePath { get { return pathsImplementation.ExecutablePath; } }
  43. /// <summary>
  44. /// The directory path to the executable.
  45. /// </summary>
  46. public static string ExecutableDirectory { get { return pathsImplementation.ExecutableDirectory; } }
  47. /// <summary>
  48. /// The base path to data files.
  49. /// </summary>
  50. public static string Data { get { return pathsImplementation.Data; } }
  51. #endregion
  52. #region Methods
  53. /// <summary>
  54. /// Combines the Root path and the given subPath.
  55. /// </summary>
  56. /// <param name="subPath">The sub path (under the main path).</param>
  57. /// <returns></returns>
  58. public static string Combine(string subPath)
  59. {
  60. return pathsImplementation.Combine(subPath);
  61. }
  62. /// <summary>
  63. /// Combines the Root path and the given subPath and file name.
  64. /// </summary>
  65. /// <param name="subPath">The sub path (under the main path).</param>
  66. /// <param name="subPath2">An additional sub path (or the name of a file).</param>
  67. /// <returns></returns>
  68. public static string Combine(string subPath, string subPath2)
  69. {
  70. return pathsImplementation.Combine(subPath, subPath2);
  71. }
  72. /// <summary>
  73. /// Returns the config path to the given config name.
  74. /// </summary>
  75. /// <param name="configName">The name of the config.</param>
  76. /// <returns></returns>
  77. public static string GetConfigPath(string configName)
  78. {
  79. return pathsImplementation.GetConfigPath(configName);
  80. }
  81. /// <summary>
  82. /// Returns the config path to the given config name.
  83. /// </summary>
  84. /// <param name="configName">The name of the config.</param>
  85. /// <param name="fileName">The name of a config file.</param>
  86. /// <returns></returns>
  87. public static string GetConfigPath(string configName, string fileName)
  88. {
  89. return pathsImplementation.GetConfigPath(configName, fileName);
  90. }
  91. /// <summary>
  92. /// Returns the transaction file path to the given terminal type.
  93. /// </summary>
  94. /// <param name="terminalType">The name of the terminal type.</param>
  95. /// <returns></returns>
  96. public static string GetTransactionsPath(string terminalType)
  97. {
  98. return pathsImplementation.GetTransactionsPath(terminalType);
  99. }
  100. /// <summary>
  101. /// Returns the transaction file path to the given terminal type.
  102. /// </summary>
  103. /// <param name="terminalType">The name of the terminal type.</param>
  104. /// <param name="subState">The name of the sub state.</param>
  105. /// <returns></returns>
  106. public static string GetTransactionsPath(string terminalType, string subState)
  107. {
  108. return pathsImplementation.GetTransactionsPath(terminalType, subState);
  109. }
  110. /// <summary>
  111. /// Replaces the extension of a file (e.g. from C:\MyFile.aaa to C:\MyFile.bbb)
  112. /// </summary>
  113. /// <param name="fileName"></param>
  114. /// <param name="newExtension"></param>
  115. /// <returns></returns>
  116. public static string ReplaceExtension(string fileName, string newExtension)
  117. {
  118. return pathsImplementation.ReplaceExtension(fileName, newExtension);
  119. }
  120. #endregion
  121. #region Parse
  122. /// <summary>
  123. /// Parses the path to replace any %...% variables with the current actual path.
  124. /// </summary>
  125. /// <param name="path"></param>
  126. /// <returns></returns>
  127. public static string Parse(string path)
  128. {
  129. return pathsImplementation.Parse(path);
  130. }
  131. /// <summary>
  132. /// Checks if file exists
  133. /// </summary>
  134. /// <param name="fileName"></param>
  135. /// <returns></returns>
  136. [Obsolete("Use the DirectoryExists() in FileSupport instead!")]
  137. public static bool FileExists(string fileName)
  138. {
  139. return pathsImplementation.FileExists(Parse(fileName));
  140. }
  141. /// <summary>
  142. /// Checks if directory exists
  143. /// </summary>
  144. /// <param name="path"></param>
  145. /// <returns></returns>
  146. [Obsolete("Use the DirectoryExists() in FileSupport instead!")]
  147. public static bool DirectoryExists(string path)
  148. {
  149. return pathsImplementation.EnsureDirectoryExists(path);
  150. }
  151. /// <summary>
  152. /// Ensures the directory exists by trying to create it if it does not exist already.
  153. /// </summary>
  154. /// <param name="path"></param>
  155. /// <returns></returns>
  156. [Obsolete("Use the DirectoryExists() in FileSupport instead!")]
  157. public static bool EnsureDirectoryExists(string path)
  158. {
  159. return pathsImplementation.EnsureDirectoryExists(path);
  160. }
  161. #endregion
  162. }
  163. }