* IniFileEx: 增加两个函数
This commit is contained in:
parent
3194ade098
commit
3c8772aea8
Binary file not shown.
@ -26,6 +26,7 @@ using System.Globalization;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Sunny.UI
|
||||
@ -785,6 +786,25 @@ namespace Sunny.UI
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取文件的Encoding
|
||||
/// </summary>
|
||||
private static Encoding GetEncoding(string filename)
|
||||
{
|
||||
// This is a direct quote from MSDN:
|
||||
// The CurrentEncoding value can be different after the first
|
||||
// call to any Read method of StreamReader, since encoding
|
||||
// autodetection is not done until the first call to a Read method.
|
||||
|
||||
using (var reader = new StreamReader(filename, Encoding.Default, true))
|
||||
{
|
||||
if (reader.Peek() >= 0) // you need this!
|
||||
reader.Read();
|
||||
|
||||
return reader.CurrentEncoding;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -261,6 +261,18 @@ namespace Sunny.UI
|
||||
sw.Flush();
|
||||
}
|
||||
|
||||
public bool HasSection(string section)
|
||||
{
|
||||
return data.ContainsKey(section.ToLowerInvariant());
|
||||
}
|
||||
|
||||
public bool HasKey(string section, string key)
|
||||
{
|
||||
return
|
||||
data.ContainsKey(section) &&
|
||||
!string.IsNullOrEmpty(data[section][key]);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 写结构
|
||||
/// </summary>
|
||||
|
Loading…
x
Reference in New Issue
Block a user