123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- 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
- {
- /// <summary>
- /// Application directory
- /// </summary>
- /// <returns></returns>
- public static string GetAppDir()
- {
- return string.IsNullOrWhiteSpace(_appPath) ? _appPath = GetAppStartupDirectory() : _appPath;
- }
- /// <summary>
- /// Application config directory is relative to the directory of the currently running application,当前文件夹/Config
- /// </summary>
- /// <returns></returns>
- public static string GetCfgDir()
- {
- return GetDirectory("Config");
- }
- /// <summary>
- /// Application's log directory is relative to the directory of the currently running application.
- /// </summary>
- /// <returns></returns>
- public static string GetLogDir()
- {
- return GetDirectory("Logs");
- }
- /// <summary>
- /// Application's script directory
- /// </summary>
- /// <returns></returns>
- public static string GetScriptDir()
- {
- return GetDirectory("Script");
- }
- /// <summary>
- /// Application's process recipe directory
- /// </summary>
- /// <returns></returns>
- public static string GetRecipeDir()
- {
- return GetDirectory("Recipes");
- }
- /// <summary>
- /// Application's sequence recipe directory
- /// </summary>
- /// <returns></returns>
- public static string GetSequenceDir()
- {
- return GetDirectory("Sequences");
- }
- /// <summary>
- /// Application's account file path
- /// </summary>
- /// <returns></returns>
- public static string GetAccountFilePath()
- {
- return GetDirectory("Account");
- }
- public static string GetMagazineFilePath()
- {
- return GetDirectory("Magazine");
- }
- /// <summary>
- /// Application start up directory
- /// </summary>
- /// <returns></returns>
- 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;
- }
- }
|