mirror of
https://github.com/tribufu/ServerManagers
synced 2026-05-06 15:17:34 +00:00
Deserialize code optimisations
1. reading ini files 2. regex match of section names.
This commit is contained in:
parent
f73b8c530d
commit
5c06fd00d5
2 changed files with 143 additions and 80 deletions
|
|
@ -85,10 +85,14 @@ namespace ServerManagerTool.Common.Utils
|
|||
public static IniFile ReadFromFile(string file)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(file))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!File.Exists(file))
|
||||
{
|
||||
return new IniFile();
|
||||
}
|
||||
|
||||
var iniFile = new IniFile();
|
||||
|
||||
|
|
@ -96,18 +100,24 @@ namespace ServerManagerTool.Common.Utils
|
|||
{
|
||||
while (!reader.EndOfStream)
|
||||
{
|
||||
var line = reader.ReadLine();
|
||||
var line = reader.ReadLine().Trim();
|
||||
|
||||
if (string.IsNullOrWhiteSpace(line) || line.StartsWith(";") || line.StartsWith("#"))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var sectionName = Regex.Match(line, @"(?<=^\[).*(?=\]$)").Value.Trim();
|
||||
var sectionName = string.Empty;
|
||||
if (line.StartsWith("[") && line.EndsWith("]"))
|
||||
{
|
||||
sectionName = Regex.Match(line, @"(?<=^\[).*(?=\]$)").Value.Trim();
|
||||
}
|
||||
|
||||
var section = iniFile.AddSection(sectionName);
|
||||
if (section != null)
|
||||
continue;
|
||||
|
||||
iniFile.AddKey(line);
|
||||
if (section is null)
|
||||
{
|
||||
iniFile.AddKey(line);
|
||||
}
|
||||
}
|
||||
|
||||
reader.Close();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue