From 00c6424e58c4ae9d83d08e933e98397750336164 Mon Sep 17 00:00:00 2001 From: Sunny Date: Wed, 3 Jan 2024 15:02:30 +0800 Subject: [PATCH] =?UTF-8?q?*=20UIniConfig:=20=E4=BF=AE=E6=94=B9=E4=BF=9D?= =?UTF-8?q?=E5=AD=98=E6=96=87=E4=BB=B6=E7=9A=84=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SunnyUI/Common/UIniConfig.cs | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/SunnyUI/Common/UIniConfig.cs b/SunnyUI/Common/UIniConfig.cs index 952c71ad..e7256a89 100644 --- a/SunnyUI/Common/UIniConfig.cs +++ b/SunnyUI/Common/UIniConfig.cs @@ -132,7 +132,9 @@ namespace Sunny.UI } ConfigHelper.SaveConfigValue(Current, idents); - List strs = new List { ";", "" }; + StringBuilder strs = new StringBuilder(); + strs.AppendLine(";"); + strs.AppendLine(""); Dictionary> listidents = new Dictionary>(); foreach (var ident in idents.Values) { @@ -148,7 +150,7 @@ namespace Sunny.UI foreach (var values in listidents) { - strs.Add("[" + values.Key + "]"); + strs.AppendLine("[" + values.Key + "]"); SortedList slist = new SortedList(); foreach (var ident in values.Value) @@ -160,28 +162,36 @@ namespace Sunny.UI { if (!ident.Description.IsNullOrEmpty()) { - strs.Add(";"); + strs.AppendLine(";"); } if (ident.IsList) { for (int i = 0; i < ident.Values.Count; i++) { - strs.Add("Value" + i + "=" + ident.Values[i]); + strs.AppendLine("Value" + i + "=" + ident.Values[i]); } } else { - strs.Add(ident.Key + "=" + ident.Value); + strs.AppendLine(ident.Key + "=" + ident.Value); } } - strs.Add(""); + strs.AppendLine(""); } listidents.Clear(); DirEx.CreateDir(Path.GetDirectoryName(filename)); - File.WriteAllLines(filename, strs.ToArray(), IniEncoding); + string filetmp = filename + "." + RandomEx.RandomPureChar(3); + File.Delete(filetmp); + StreamWriter sw = new StreamWriter(filetmp); + sw.WriteLine(strs.ToString()); + sw.Flush(); + sw.Close(); + sw.Dispose(); + File.Delete(filename); + File.Move(filetmp, filename); } #endregion 加载