using KssSmaPlaLib.AutoTest.Command.Definition; using KssSmaPlaLib.AutoTest.Command.Translator; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; namespace KssSmaPlaLib.AutoTest.Command.Alias.Ini { public static class IniReaderUxer { public static bool Try(string iniFilePath, out Dictionary dic, out string resultMessage) { dic = new Dictionary(); resultMessage = string.Empty; try { if (!File.Exists(iniFilePath)) { resultMessage = "エイリアスファイルが存在しません。"; return false; } var lines = File.ReadAllLines(iniFilePath, System.Text.Encoding.GetEncoding("shift_jis")); // ここでDTOにパース(例:セクションごとに分ける、キーと値を読み込むなど) // ↓仮の処理(実際はINIパーサーCLがあると別府) foreach (var line in lines) { if (line.StartsWith("#") || line.StartsWith(";") || string.IsNullOrWhiteSpace(line)) continue; var parts = line.Split('='); if (parts.Length == 2) { var command = parts[0].Trim(); var alias = parts[1].Trim(); if (!CommandTranslatorUxer.TryTranslate(command, out var commandEnum)) { resultMessage = $"エイリアスファイルでコマンド名が不正です。[コマンド名:{command}]"; return false; } // エイリアス辞書登録 dic[alias] = commandEnum; } } return true; } catch (Exception ex) { resultMessage = $"エイリアスロードに失敗しました。[エラー内容:{ex.Message}]"; return false; } } } }