for Push.
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using KssSmaPlaLib.Commons;
|
||||
|
||||
namespace KssSmaPlaLib.Ini
|
||||
{
|
||||
/// <summary>
|
||||
/// INIリーダー
|
||||
/// </summary>
|
||||
public static class IniReaderUxer
|
||||
{
|
||||
/// <summary>
|
||||
/// 指定セクションのINI値読み込み
|
||||
/// </summary>
|
||||
/// <param name="path">INIパス</param>
|
||||
/// <param name="section">セクション</param>
|
||||
/// <returns>指定のディクショナリ</returns>
|
||||
public static Dictionary<string, string> ReadSection(string path, string section)
|
||||
{
|
||||
var result = new Dictionary<string, string>();
|
||||
var lines = File.ReadAllLines(path);
|
||||
bool inSection = false;
|
||||
|
||||
foreach (var line in lines)
|
||||
{
|
||||
var trimmed = line.Trim();
|
||||
|
||||
// コメント行は飛ばす
|
||||
if (trimmed.StartsWith(";")) continue;
|
||||
|
||||
if (trimmed.StartsWith("[") && trimmed.EndsWith("]"))
|
||||
inSection = trimmed == $"[{section}]";
|
||||
else if (inSection && trimmed.Contains("="))
|
||||
{
|
||||
var index = trimmed.IndexOf('=');
|
||||
if (index > 0)
|
||||
{
|
||||
var key = trimmed.Substring(0, index).Trim();
|
||||
var value = trimmed.Substring(index + 1).Trim();
|
||||
result[key] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
// public static bool IsEmptyByIniDic(Dictionary<string,string> iniDic,string key)
|
||||
// {
|
||||
// return string.IsNullOrEmpty(DictionaryUxer.GetValueOrDefault(iniDic, key, string.Empty));
|
||||
// }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user