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 { /// /// INIリーダー /// public static class IniReaderUxer { /// /// 指定セクションのINI値読み込み /// /// INIパス /// セクション /// 指定のディクショナリ public static Dictionary ReadSection(string path, string section) { var result = new Dictionary(); 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 iniDic,string key) { return string.IsNullOrEmpty(DictionaryUxer.GetValueOrDefault(iniDic, key, string.Empty)); } } }