56 lines
1.8 KiB
C#
56 lines
1.8 KiB
C#
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, System.Text.Encoding.GetEncoding("shift_jis"));
|
|
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));
|
|
}
|
|
}
|
|
}
|