PathManager.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Configuration;
  6. using System.IO;
  7. namespace Aitex.Common.Util
  8. {
  9. public class PathManager
  10. {
  11. /// <summary>
  12. /// Application directory
  13. /// </summary>
  14. /// <returns></returns>
  15. public static string GetAppDir()
  16. {
  17. return string.IsNullOrWhiteSpace(_appPath) ? _appPath = GetAppStartupDirectory() : _appPath;
  18. }
  19. /// <summary>
  20. /// Application config directory is relative to the directory of the currently running application,当前文件夹/Config
  21. /// </summary>
  22. /// <returns></returns>
  23. public static string GetCfgDir()
  24. {
  25. return GetDirectory("Config");
  26. }
  27. /// <summary>
  28. /// Application's log directory is relative to the directory of the currently running application.
  29. /// </summary>
  30. /// <returns></returns>
  31. public static string GetLogDir()
  32. {
  33. return GetDirectory("Logs");
  34. }
  35. /// <summary>
  36. /// Application's script directory
  37. /// </summary>
  38. /// <returns></returns>
  39. public static string GetScriptDir()
  40. {
  41. return GetDirectory("Script");
  42. }
  43. /// <summary>
  44. /// Application's process recipe directory
  45. /// </summary>
  46. /// <returns></returns>
  47. public static string GetRecipeDir()
  48. {
  49. return GetDirectory("Recipes");
  50. }
  51. /// <summary>
  52. /// Application's sequence recipe directory
  53. /// </summary>
  54. /// <returns></returns>
  55. public static string GetSequenceDir()
  56. {
  57. return GetDirectory("Sequences");
  58. }
  59. /// <summary>
  60. /// Application's account file path
  61. /// </summary>
  62. /// <returns></returns>
  63. public static string GetAccountFilePath()
  64. {
  65. return GetDirectory("Account");
  66. }
  67. public static string GetMagazineFilePath()
  68. {
  69. return GetDirectory("Magazine");
  70. }
  71. /// <summary>
  72. /// Application start up directory
  73. /// </summary>
  74. /// <returns></returns>
  75. static string GetAppStartupDirectory()
  76. {
  77. var startupPath = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;
  78. string dir = Path.GetDirectoryName(startupPath);
  79. return dir;
  80. }
  81. public static string GetDirectory(string directoryPath)
  82. {
  83. var ret = Path.Combine(GetAppDir(), directoryPath);
  84. if (!ret.EndsWith(Path.DirectorySeparatorChar.ToString()))
  85. ret = ret + Path.DirectorySeparatorChar;
  86. if (!Directory.Exists(ret))
  87. Directory.CreateDirectory(ret);
  88. return ret;
  89. }
  90. static string _appPath;
  91. }
  92. }