Exemplo n.º 1
0
        public static void Clear(string root = "", EnumIniFileType fileType = EnumIniFileType.Upgrade)
        {
            if (string.IsNullOrEmpty(root))
            {
                root = AppDomain.CurrentDomain.BaseDirectory;
            }

            var sPath = Path.Combine(root, $"{fileType.ToString().ToLower()}.ini");

            if (File.Exists(sPath))
            {
                File.Delete(sPath);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 读取
        /// </summary>
        /// <param name="sectionName"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        public static string Read(string sectionName, string key, string root = "", EnumIniFileType fileType = EnumIniFileType.Upgrade, int length = 1000)
        {
            if (string.IsNullOrEmpty(root))
            {
                root = AppDomain.CurrentDomain.BaseDirectory;
            }

            var sPath = Path.Combine(root, $"{fileType.ToString().ToLower()}.ini");

            if (!File.Exists(sPath))
            {
                return(null);
            }
            // 每次从ini中读取多少字节
            var temp = new StringBuilder(length);

            // section=配置节,key=键名,temp=上面,path=路径
            GetPrivateProfileString(sectionName, key, "", temp, length, sPath);
            return(temp.ToString());
        }
Exemplo n.º 3
0
        /// <summary>
        /// 写入
        /// </summary>
        /// <param name="sectionName">配置节</param>
        /// <param name="key">键名</param>
        /// <param name="value">键值</param>
        public static void Write(string sectionName, string key, string value, string root = "", EnumIniFileType fileType = EnumIniFileType.Upgrade)
        {
            if (string.IsNullOrEmpty(root))
            {
                root = AppDomain.CurrentDomain.BaseDirectory;
            }

            var sPath = Path.Combine(root, $"{fileType.ToString().ToLower()}.ini");

            if (!File.Exists(sPath))
            {
                using (FileStream fs = File.Create(sPath)) { }
            }
            // section=配置节,key=键名,value=键值,path=路径
            WritePrivateProfileString(sectionName, key, value, sPath);
        }