From ab5611f15d0b815993182f4e0c56c5a28709c465 Mon Sep 17 00:00:00 2001 From: zxd Date: Sat, 3 Nov 2018 10:27:25 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=B6=88=E6=81=AF=E6=8F=90?= =?UTF-8?q?=E7=A4=BA=20=E6=B7=BB=E5=8A=A0ini=E6=96=87=E4=BB=B6=E8=AF=BB?= =?UTF-8?q?=E5=86=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Plane.Windows.Messages/Message.cs | 11 ++++++ Plane.Windows/IniHelper/IniFiles.cs | 58 +++++++++++++++++++++++++++++ Plane.Windows/Plane.Windows.csproj | 1 + 3 files changed, 70 insertions(+) create mode 100644 Plane.Windows/IniHelper/IniFiles.cs diff --git a/Plane.Windows.Messages/Message.cs b/Plane.Windows.Messages/Message.cs index 3d36b7d..b9f403f 100644 --- a/Plane.Windows.Messages/Message.cs +++ b/Plane.Windows.Messages/Message.cs @@ -8,6 +8,7 @@ namespace Plane.Windows.Messages public static class Message { private static Action ShowAction { get; set; } + private static Action ConnectAction { get; set; } public static void Configure(Action showAction) { @@ -18,5 +19,15 @@ namespace Plane.Windows.Messages { ShowAction?.Invoke(message); } + + public static void Configure(Action connectAction) + { + ConnectAction = connectAction; + } + + public static void Connect(bool isConnected) + { + ConnectAction?.Invoke(isConnected); + } } } diff --git a/Plane.Windows/IniHelper/IniFiles.cs b/Plane.Windows/IniHelper/IniFiles.cs new file mode 100644 index 0000000..98dfdd4 --- /dev/null +++ b/Plane.Windows/IniHelper/IniFiles.cs @@ -0,0 +1,58 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.InteropServices; +using System.Text; + +namespace Plane.Windows.IniHelper +{ + /// + /// IniFiles 的摘要说明。 + /// 示例文件路径:C:\file.ini + /// [Server] //[*] 表示缓存区 + /// name=localhost //name 表示主键,localhost 表示值 + /// + public class IniFiles + { + public string path; + [DllImport("kernel32")] //返回0表示失败,非0为成功 + private static extern long WritePrivateProfileString(string section, string key, string val, string filePath); + [DllImport("kernel32")] //返回取得字符串缓冲区的长度 + private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filePath); + /// + /// 保存ini文件的路径 + /// 调用示例:var ini = IniFiles("C:\file.ini"); + /// + /// + public IniFiles() + { + this.path = Environment.CurrentDirectory + @"\Config.ini"; + } + /// + /// 写Ini文件 + /// 调用示例:ini.IniWritevalue("Server","name","localhost"); + /// + /// [缓冲区] + /// 键 + /// 值 + public void IniWritevalue(string Section, string Key, string value) + { + WritePrivateProfileString(Section, Key, value, this.path); + } + /// + /// 读Ini文件 + /// 调用示例:ini.IniWritevalue("Server","name"); + /// + /// [缓冲区] + /// 键 + /// + public string IniReadvalue(string Section, string Key) + { + StringBuilder temp = new StringBuilder(255); + + int i = GetPrivateProfileString(Section, Key, "", temp, 255, this.path); + return temp.ToString(); + } + + } +} diff --git a/Plane.Windows/Plane.Windows.csproj b/Plane.Windows/Plane.Windows.csproj index 142d995..c5e52f1 100644 --- a/Plane.Windows/Plane.Windows.csproj +++ b/Plane.Windows/Plane.Windows.csproj @@ -51,6 +51,7 @@ +