using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Configuration; using System.IO; using System.Reflection; 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. /// end with the "/" /// /// 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 process recipe directory /// /// public static string GetRecipeDir() { return GetDirectory("Recipes"); } public static string GetProductionRecipeDir() { return GetDirectory("Recipes/Production"); } public static string GetEngineeringRecipeDir() { return GetDirectory("Recipes/Engineering"); } /// /// Application's account file path /// /// public static string GetAccountFilePath() { return GetDirectory("Account"); } /// /// Lot Track file path /// /// public static string GetLotTrackFilePath() { return GetDirectory("LotTrack"); } /// /// 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; } }