duheng
2024-09-11 d43b0f6eaf671b6432dc99b114f19d11ca7f5659
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
using System;
using System.IO;
using System.Reflection;
 
namespace IStation 
{
    /// <summary>
    /// 文件辅助类
    /// </summary>
    public class DataFolderHelper
    {
        /// <summary>
        /// 根目录
        /// </summary> 
        private static string _root_directory;
 
        /// <summary>
        /// 独立运行还是嵌入运行
        /// </summary>
        public static bool IsExeExcute = true; 
 
        /// <summary>
        /// 查询数据文件夹路径
        /// </summary>
        public static string GetRootPath()
        { 
            if (string.IsNullOrEmpty(_root_directory))
            {
                if(IsExeExcute)
                {
                    var directory = new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory).FullName; 
                    _root_directory = Path.Combine(directory, "Data");
                }
                else
                { 
                     var directory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
                    _root_directory = Path.Combine(directory, "Data");
                }
            }
            return _root_directory;  
        }
 
 
    }
}