diff --git a/Bin/net40/SunnyUI.dll b/Bin/net40/SunnyUI.dll index 1f0e6e19..59a42bb4 100644 Binary files a/Bin/net40/SunnyUI.dll and b/Bin/net40/SunnyUI.dll differ diff --git a/SunnyUI/Common/UFile.cs b/SunnyUI/Common/UFile.cs index 49f00737..ec659ed6 100644 --- a/SunnyUI/Common/UFile.cs +++ b/SunnyUI/Common/UFile.cs @@ -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; } + + /// + /// 获取文件的Encoding + /// + 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; + } + } } /// diff --git a/SunnyUI/Common/UIniFileEx.cs b/SunnyUI/Common/UIniFileEx.cs index d94aea00..a6372b1b 100644 --- a/SunnyUI/Common/UIniFileEx.cs +++ b/SunnyUI/Common/UIniFileEx.cs @@ -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]); + } + /// /// 写结构 ///