62 lines
1.7 KiB
C#
62 lines
1.7 KiB
C#
using LightSetupBase;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Text.Json;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace LightSetupMd5
|
|
{
|
|
internal class Md5ConfigRead
|
|
{
|
|
private const string Separator = "\n";
|
|
public Md5Config ReadConfig(Md5MainArgs arg)
|
|
{
|
|
if (!File.Exists(arg.ConfigPath))
|
|
{
|
|
throw new Exception("配置文件" + arg.ConfigPath + "不存在");
|
|
}
|
|
string json = File.ReadAllText(arg.ConfigPath, Encoding.UTF8);
|
|
|
|
Md5Config config = JsonSerializer.Deserialize<Md5Config>(json, Md5Config.getOption());
|
|
if (String.IsNullOrEmpty(config.FileName))
|
|
{
|
|
config.FileName = "md5_version.json";
|
|
}
|
|
if (String.IsNullOrEmpty(config.FileFormat))
|
|
{
|
|
config.FileName = @"{
|
|
""md5"":""{md5}"",
|
|
""ip"":""{ip}"",
|
|
""computerName"":""{computerName}""
|
|
}";
|
|
}
|
|
config.Filter = convertFilter(config.Filter);
|
|
config.Contain = convertFilter(config.Contain);
|
|
return config;
|
|
}
|
|
|
|
private string convertFilter(string filter)
|
|
{
|
|
string[] strings = filter.Split(Separator);
|
|
StringBuilder sb = new StringBuilder();
|
|
foreach (string str in strings)
|
|
{
|
|
string to = str.Trim();
|
|
if (String.IsNullOrEmpty(to))
|
|
{
|
|
continue;
|
|
}
|
|
if (sb.Length > 0)
|
|
{
|
|
sb.Append(Separator);
|
|
}
|
|
sb.Append(to);
|
|
}
|
|
return sb.ToString();
|
|
}
|
|
|
|
}
|
|
}
|