You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
121 lines
3.0 KiB
C#
121 lines
3.0 KiB
C#
// <copyright file="ConfigUtils.cs" company="jindongfang">
|
|
// Copyright (c) jindongfang. All rights reserved.
|
|
// </copyright>
|
|
|
|
using SharpConfig;
|
|
using System.IO;
|
|
using System.Reflection;
|
|
using WorkData;
|
|
namespace WellWorkDataUI
|
|
{
|
|
/// <summary>
|
|
/// 配置文件操作类.
|
|
/// </summary>
|
|
internal static partial class ConfigUtils
|
|
{
|
|
/// <summary>
|
|
/// 配置文件路径
|
|
/// </summary>
|
|
private static string kFilename => Path.Combine(Config.ProjectPath, "Map", "Config.cfg");
|
|
|
|
/// <summary>
|
|
/// 属性列表
|
|
/// </summary>
|
|
private static PropertyInfo[] kProperties = typeof(ConfigUtils).GetProperties(BindingFlags.Static | BindingFlags.Public);
|
|
|
|
/// <summary>
|
|
/// 加载属性.
|
|
/// </summary>
|
|
public static void Load()
|
|
{
|
|
LoadFrom(kFilename);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 保存属性.
|
|
/// </summary>
|
|
public static void Save()
|
|
{
|
|
SaveTo(kFilename);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 从其他文件加载配置.
|
|
/// </summary>
|
|
/// <param name="filename">The filename.</param>
|
|
public static void LoadFrom(string filename)
|
|
{
|
|
if (File.Exists(filename))
|
|
{
|
|
var cfg = Configuration.LoadFromFile(filename);
|
|
|
|
foreach (var item in kProperties)
|
|
{
|
|
item.SetValue(null, cfg[item.PropertyType.Name].ToObject(item.PropertyType));
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 另存配置文件.
|
|
/// </summary>
|
|
/// <param name="filename">The filename.</param>
|
|
public static void SaveTo(string filename)
|
|
{
|
|
var cfg = new Configuration();
|
|
|
|
foreach (var item in kProperties)
|
|
{
|
|
cfg.Add(Section.FromObject(item.PropertyType.Name, item.GetValue(null)));
|
|
}
|
|
|
|
cfg.SaveToFile(filename);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 配置文件操作类.
|
|
/// </summary>
|
|
internal partial class ConfigUtils
|
|
{
|
|
/// <summary>
|
|
/// Gets the general data.
|
|
/// </summary>
|
|
/// <value>The general data.</value>
|
|
public static Interpret InterpretData { get; private set; } = new Interpret();
|
|
|
|
/// <summary>
|
|
/// Interpret设置.
|
|
/// </summary>
|
|
public class Interpret
|
|
{
|
|
/// <summary>
|
|
/// 查看模式.
|
|
/// </summary>
|
|
/// <value>The view mode.</value>
|
|
public ViewMode ViewMode { get; set; } = ViewMode.Data;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 查看模式
|
|
/// </summary>
|
|
public enum ViewMode
|
|
{
|
|
/// <summary>
|
|
/// 显示数据
|
|
/// </summary>
|
|
Data = 0x01,
|
|
|
|
/// <summary>
|
|
/// 显示图表
|
|
/// </summary>
|
|
Chart = 0x02,
|
|
|
|
/// <summary>
|
|
/// 全部显示
|
|
/// </summary>
|
|
Both = Data | Chart,
|
|
}
|
|
}
|