123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace CassiniDev
- {
- public class userConfig
- {
- public userConfig() {
-
- }
- static int _WebPort = 0;
- /// <summary>
- /// 端口
- /// </summary>
- public static int WebPort
- {
- get { return _WebPort; }
- set { _WebPort = value; }
- }
- public static void LoadWebPort()
- {
- try
- {
- if (System.IO.File.Exists(configPath0))
- {
- _WebPort = Convert.ToInt32(System.IO.File.ReadAllText(configPath0, Encoding.UTF8));
- }
- else {
- if (System.IO.File.Exists(configPath))
- {
- _WebPort = Convert.ToInt32(System.IO.File.ReadAllText(configPath, Encoding.UTF8));
- }
- }
-
- }
- catch {
- _WebPort = 0;
- }
- }
- public static void SaveWebPort(int port)
- {
- try
- {
- _WebPort = port;
- System.IO.File.WriteAllText(configPath,port.ToString(),Encoding.UTF8);
- }
- catch { }
- try
- {
- System.IO.File.WriteAllText(configPath0, port.ToString(), Encoding.UTF8);
- }
- catch { }
- }
- static string configPath0 = BasePath + "Bin\\AspNet40.ini";
- static string configPath = BasePath + "userConfig.txt";
- /// <summary>
- /// WebForm和WinForm通用的取当前根目录的方法
- /// </summary>
- public static string BasePath
- {
- get
- {
- System.Diagnostics.Process p = System.Diagnostics.Process.GetCurrentProcess();
- //WebDev.WebServer visual studio web server
- //xxx.vhost Winform
- //w3wp IIS7
- //aspnet_wp IIS6
- string processName = p.ProcessName.ToLower();
- string retPath = System.Windows.Forms.Application.StartupPath;
- if (processName == "aspnet_wp" || processName == "w3wp" || processName == "webdev.webserver" || processName == "iisexpress")
- {
- if (System.Web.HttpContext.Current != null)
- retPath = System.Web.HttpContext.Current.Server.MapPath("~/").TrimEnd(new char[] { '\\' });
- else //当控件在定时器的触发程序中使用时就为空
- {
- retPath = System.AppDomain.CurrentDomain.BaseDirectory.TrimEnd(new char[] { '\\' });
- }
- }
- return GetFullDirectoryPath(retPath);
- }
- }
- /// <summary>
- /// 获取完整路径 只能为文件夹目录路径 检查路径结尾是否存在 “\”符号 如果不存在添加上
- /// </summary>
- /// <param name="directoryPath"></param>
- /// <returns></returns>
- public static string GetFullDirectoryPath(string directoryPath)
- {
- if (directoryPath.LastIndexOf("\\") != directoryPath.Length - 1)
- {
- directoryPath = directoryPath + "\\";
- }
- return directoryPath;
- }
- }
- }
|