using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Configuration; using System.IO; namespace Aitex.Common.Util { public class PathManager { /// /// Application directory /// /// public static string GetAppDir() { return string.IsNullOrWhiteSpace(_appPath) ? _appPath = GetAppStartupDirectory() : _appPath; } /// /// Application config directory is relative to the directory of the currently running application,当前文件夹/Config /// /// public static string GetCfgDir() { return GetDirectory("Config"); } /// /// Application's log directory is relative to the directory of the currently running application. /// /// public static string GetLogDir() { return GetDirectory("Logs"); } /// /// Application's script directory /// /// public static string GetScriptDir() { return GetDirectory("Script"); } /// /// Application's process recipe directory /// /// public static string GetRecipeDir() { return GetDirectory("Recipes"); } /// /// Application's sequence recipe directory /// /// public static string GetSequenceDir() { return GetDirectory("Sequences"); } /// /// Application's account file path /// /// public static string GetAccountFilePath() { return GetDirectory("Account"); } public static string GetMagazineFilePath() { return GetDirectory("Magazine"); } /// /// Application start up directory /// /// static string GetAppStartupDirectory() { var startupPath = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName; string dir = Path.GetDirectoryName(startupPath); return dir; } public static string GetDirectory(string directoryPath) { var ret = Path.Combine(GetAppDir(), directoryPath); if (!ret.EndsWith(Path.DirectorySeparatorChar.ToString())) ret = ret + Path.DirectorySeparatorChar; if (!Directory.Exists(ret)) Directory.CreateDirectory(ret); return ret; } static string _appPath; } }