* UIniFile: 增加读取字符串长度到4096,增加文件编码
* UIniConfig: 增加文件编码,通过Load传入
This commit is contained in:
parent
6aff886a99
commit
d8d3eeac53
@ -17,6 +17,7 @@
|
|||||||
* 创建日期: 2020-01-01
|
* 创建日期: 2020-01-01
|
||||||
*
|
*
|
||||||
* 2020-01-01: V2.2.0 增加文件说明
|
* 2020-01-01: V2.2.0 增加文件说明
|
||||||
|
* 2022-11-01: V3.2.6 增加文件编码,通过Load传入
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
@ -24,6 +25,7 @@ using System.Collections.Concurrent;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Collections.Specialized;
|
using System.Collections.Specialized;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
namespace Sunny.UI
|
namespace Sunny.UI
|
||||||
{
|
{
|
||||||
@ -35,6 +37,17 @@ namespace Sunny.UI
|
|||||||
{
|
{
|
||||||
#region 加载
|
#region 加载
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Ini文件编码格式
|
||||||
|
/// </summary>
|
||||||
|
public Encoding IniEncoding { get; private set; } = Encoding.Default;
|
||||||
|
|
||||||
|
public bool Load(string fileName, Encoding encoding)
|
||||||
|
{
|
||||||
|
IniEncoding = encoding;
|
||||||
|
return Load(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>加载指定配置文件</summary>
|
/// <summary>加载指定配置文件</summary>
|
||||||
/// <param name="filename">文件名</param>
|
/// <param name="filename">文件名</param>
|
||||||
/// <returns>结果</returns>
|
/// <returns>结果</returns>
|
||||||
@ -66,7 +79,7 @@ namespace Sunny.UI
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
IniFile ini = new IniFile(filename);
|
IniFile ini = new IniFile(filename, IniEncoding);
|
||||||
foreach (var ident in idents.Values)
|
foreach (var ident in idents.Values)
|
||||||
{
|
{
|
||||||
if (ident.IsList)
|
if (ident.IsList)
|
||||||
@ -167,7 +180,7 @@ namespace Sunny.UI
|
|||||||
|
|
||||||
listidents.Clear();
|
listidents.Clear();
|
||||||
DirEx.CreateDir(Path.GetDirectoryName(filename));
|
DirEx.CreateDir(Path.GetDirectoryName(filename));
|
||||||
File.WriteAllLines(filename, strs.ToArray(), IniBase.IniEncoding);
|
File.WriteAllLines(filename, strs.ToArray(), IniEncoding);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion 加载
|
#endregion 加载
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
* 创建日期: 2020-01-01
|
* 创建日期: 2020-01-01
|
||||||
*
|
*
|
||||||
* 2020-01-01: V2.2.0 增加文件说明
|
* 2020-01-01: V2.2.0 增加文件说明
|
||||||
|
* 2022-11-01: V3.2.6 增加读取字符串长度到4096,增加文件编码
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
|
||||||
using Sunny.UI.Win32;
|
using Sunny.UI.Win32;
|
||||||
@ -46,13 +47,13 @@ namespace Sunny.UI
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Ini文件编码格式
|
/// Ini文件编码格式
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static readonly Encoding IniEncoding = Encoding.Default;
|
public Encoding IniEncoding { get; set; } = Encoding.Default;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 类的构造函数,文件名必须是完全路径,不能是相对路径
|
/// 类的构造函数,文件名必须是完全路径,不能是相对路径
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="fileName">文件名</param>
|
/// <param name="fileName">文件名</param>
|
||||||
protected IniBase(string fileName)
|
public IniBase(string fileName)
|
||||||
{
|
{
|
||||||
//必须是完全路径,不能是相对路径
|
//必须是完全路径,不能是相对路径
|
||||||
FileName = fileName;
|
FileName = fileName;
|
||||||
@ -68,6 +69,11 @@ namespace Sunny.UI
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IniBase(string fileName, Encoding encoding) : this(fileName)
|
||||||
|
{
|
||||||
|
IniEncoding = encoding;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 确保资源的释放
|
/// 确保资源的释放
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -128,7 +134,7 @@ namespace Sunny.UI
|
|||||||
/// <returns>结果</returns>
|
/// <returns>结果</returns>
|
||||||
public string Read(string section, string key, string Default)
|
public string Read(string section, string key, string Default)
|
||||||
{
|
{
|
||||||
byte[] buffer = new byte[2048];
|
byte[] buffer = new byte[4096];
|
||||||
if (Default == null)
|
if (Default == null)
|
||||||
{
|
{
|
||||||
Default = "";
|
Default = "";
|
||||||
@ -797,5 +803,10 @@ namespace Sunny.UI
|
|||||||
public IniFile(string fileName) : base(fileName)
|
public IniFile(string fileName) : base(fileName)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IniFile(string fileName, Encoding encoding) : base(fileName, encoding)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user