for Push.

This commit is contained in:
nobobo
2026-06-01 12:28:44 +09:00
parent c845fb60a0
commit 33a5d7bbea
28 changed files with 2838 additions and 0 deletions
+53
View File
@@ -0,0 +1,53 @@
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace KssSmaPlaLib.Ini
{
public static class IniHelper
{
private const string INI_PATH = @".\Settings.ini";
// Win32 API宣言
[DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
private static extern int GetPrivateProfileString(
string lpAppName,
string lpKeyName,
string lpDefault,
StringBuilder lpReturnedString,
int nSize,
string lpFileName);
[DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
private static extern bool WritePrivateProfileString(
string lpAppName,
string lpKeyName,
string lpString,
string lpFileName);
/// <summary>
/// INIファイルから値を読み込み(セクション+キー指定)
/// </summary>
public static string ReadValue(string? iniPath, string section, string key, string defaultValue = "")
{
if (string.IsNullOrEmpty(iniPath)) iniPath = INI_PATH;
var sb = new StringBuilder(1024);
GetPrivateProfileString(section, key, defaultValue, sb, sb.Capacity, iniPath);
var str = sb.ToString();
str = string.IsNullOrEmpty(str) ? defaultValue : str;
return str;
}
/// <summary>
/// INIファイルに値を書き込み(セクション+キー+値指定)
/// </summary>
public static bool WriteValue(string iniPath, string section, string key, string value)
{
if (string.IsNullOrEmpty(iniPath)) iniPath = INI_PATH;
return WritePrivateProfileString(section, key, value, iniPath);
}
}
}
+55
View File
@@ -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));
// }
}
}
+75
View File
@@ -0,0 +1,75 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace KssSmaPlaLib.Ini
{
public static class IniReferenceResolveUxer
{
// public static Dictionary<string, string> ReadSectionWithReference(string path, string section, int maxDepth = 3)
// {
// var allLines = File.ReadAllLines(path);
// var allSections = ParseAllSections(allLines);
// var result = new Dictionary<string, string>();
// if (!allSections.ContainsKey(section)) return result;
// foreach (var kvp in allSections[section])
// {
// result[kvp.Key] = ResolveValue(allSections, kvp.Value, maxDepth);
// }
// return result;
// }
// private static Dictionary<string, Dictionary<string, string>> ParseAllSections(string[] lines)
// {
// var sections = new Dictionary<string, Dictionary<string, string>>();
// string currentSection = null;
// foreach (var line in lines)
// {
// var trimmed = line.Trim();
// if (trimmed.StartsWith(";") || string.IsNullOrEmpty(trimmed)) continue;
// if (trimmed.StartsWith("[") && trimmed.EndsWith("]"))
// {
// currentSection = trimmed.Substring(1, trimmed.Length - 2);
// sections[currentSection] = new Dictionary<string, string>();
// }
// else if (currentSection != null && trimmed.Contains("="))
// {
// var index = trimmed.IndexOf('=');
// var key = trimmed.Substring(0, index).Trim();
// var value = trimmed.Substring(index + 1).Trim();
// sections[currentSection][key] = value;
// }
// }
// return sections;
// }
private static string ResolveValue(Dictionary<string, Dictionary<string, string>> sections, string value, int depth)
{
if (depth <= 0 || string.IsNullOrEmpty(value)) return value;
var match = System.Text.RegularExpressions.Regex.Match(value, @"^\{\[(.+?)\](.+?)\}$");
if (match.Success)
{
var refSection = match.Groups[1].Value;
var refKey = match.Groups[2].Value;
if (sections.ContainsKey(refSection) && sections[refSection].ContainsKey(refKey))
{
var nextValue = sections[refSection][refKey];
return ResolveValue(sections, nextValue, depth - 1);
}
}
return value;
}
}
}