修改消息提示
添加ini文件读写
This commit is contained in:
parent
5e5817b8a4
commit
ab5611f15d
@ -8,6 +8,7 @@ namespace Plane.Windows.Messages
|
||||
public static class Message
|
||||
{
|
||||
private static Action<string> ShowAction { get; set; }
|
||||
private static Action<bool> ConnectAction { get; set; }
|
||||
|
||||
public static void Configure(Action<string> showAction)
|
||||
{
|
||||
@ -18,5 +19,15 @@ namespace Plane.Windows.Messages
|
||||
{
|
||||
ShowAction?.Invoke(message);
|
||||
}
|
||||
|
||||
public static void Configure(Action<bool> connectAction)
|
||||
{
|
||||
ConnectAction = connectAction;
|
||||
}
|
||||
|
||||
public static void Connect(bool isConnected)
|
||||
{
|
||||
ConnectAction?.Invoke(isConnected);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
58
Plane.Windows/IniHelper/IniFiles.cs
Normal file
58
Plane.Windows/IniHelper/IniFiles.cs
Normal file
@ -0,0 +1,58 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
namespace Plane.Windows.IniHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// IniFiles 的摘要说明。
|
||||
/// 示例文件路径:C:\file.ini
|
||||
/// [Server] //[*] 表示缓存区
|
||||
/// name=localhost //name 表示主键,localhost 表示值
|
||||
/// </summary>
|
||||
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);
|
||||
/// <summary>
|
||||
/// 保存ini文件的路径
|
||||
/// 调用示例:var ini = IniFiles("C:\file.ini");
|
||||
/// </summary>
|
||||
/// <param name="INIPath"></param>
|
||||
public IniFiles()
|
||||
{
|
||||
this.path = Environment.CurrentDirectory + @"\Config.ini";
|
||||
}
|
||||
/// <summary>
|
||||
/// 写Ini文件
|
||||
/// 调用示例:ini.IniWritevalue("Server","name","localhost");
|
||||
/// </summary>
|
||||
/// <param name="Section">[缓冲区]</param>
|
||||
/// <param name="Key">键</param>
|
||||
/// <param name="value">值</param>
|
||||
public void IniWritevalue(string Section, string Key, string value)
|
||||
{
|
||||
WritePrivateProfileString(Section, Key, value, this.path);
|
||||
}
|
||||
/// <summary>
|
||||
/// 读Ini文件
|
||||
/// 调用示例:ini.IniWritevalue("Server","name");
|
||||
/// </summary>
|
||||
/// <param name="Section">[缓冲区]</param>
|
||||
/// <param name="Key">键</param>
|
||||
/// <returns>值</returns>
|
||||
public string IniReadvalue(string Section, string Key)
|
||||
{
|
||||
StringBuilder temp = new StringBuilder(255);
|
||||
|
||||
int i = GetPrivateProfileString(Section, Key, "", temp, 255, this.path);
|
||||
return temp.ToString();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -51,6 +51,7 @@
|
||||
<Compile Include="Converters\BooleanConverter.cs" />
|
||||
<Compile Include="Converters\InverseBooleanConverter.cs" />
|
||||
<Compile Include="Converters\NullableBooleanToVisibilityConverter.cs" />
|
||||
<Compile Include="IniHelper\IniFiles.cs" />
|
||||
<Compile Include="UpdateChecker.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
|
Loading…
Reference in New Issue
Block a user