Beispiel #1
0
        public void Read_Add(string filepath, Encoding encoding)
        {
            if (!File.Exists(filepath))
            {
                Util_Message.Show($"設定ファイルが見つかりません。[{filepath}]");
                goto gt_EndMethod;
            }

            List <List <string> > rows = Util_Csv.ReadCsv(filepath, encoding);

            // 最初の1行は削除。
            rows.RemoveRange(0, 1);

            //------------------------------
            // データ部だけが残っています。
            //------------------------------
            if ("" == this.FilepathsCsv)
            {
                this.FilepathsCsv = filepath;
            }
            else
            {
                this.FilepathsCsv = $"{this.FilepathsCsv},{filepath}";
            }
            //this.Properties.Clear();

            foreach (List <string> row in rows)
            {
                // 各行は、name,value の2列以上あるはずです。
                if (row.Count < 2)
                {
                    goto gt_NextColumn;
                }

                // name列が空っぽの行は無視します。
                if ("" == row[0])
                {
                    goto gt_NextColumn;
                }

                if (this.Properties.ContainsKey(row[0]))
                {
                    Util_Message.Show($"項目[{row[0]}]を上書きします。");
                    this.Properties[row[0]] = row[1];
                }
                else
                {
                    this.Properties.Add(row[0], row[1]);
                }

gt_NextColumn:
                ;
            }

gt_EndMethod:
            ;
        }
Beispiel #2
0
        public bool Write()
        {
            bool successfule = true;

            XmlDocument xDoc = new XmlDocument();

            // UTF-8 エンコーディングで書くものとします。
            XmlProcessingInstruction xPi = xDoc.CreateProcessingInstruction("xml", "version=\"1.0\" encoding=\"UTF-8\"");

            xDoc.AppendChild(xPi);


            try
            {
                // ルート要素 <kifunarabe> を作成
                XmlElement xKifunarabe = xDoc.CreateElement("kifunarabe");
                xDoc.AppendChild(xKifunarabe);

                // setteiFileVer="1.00.0"
                xKifunarabe.SetAttribute("setteiFileVer", this.SetteiFileVer);

                // コメント
                xKifunarabe.AppendChild(xDoc.CreateComment("v(^-^)vイェーイ☆ 『将棋GUI きふならべ』の設定ファイルなんだぜ☆! 今は一番上に書いてある <shogiEngine> を見に行くぜ☆"));

                // <shogiEngine>
                XmlElement xShogiEngine = xDoc.CreateElement("shogiEngine");

                // name="The将棋エンジン"
                xShogiEngine.SetAttribute("file", this.ShogiEngineName);

                // file="shogiEngine.exe"
                xShogiEngine.SetAttribute("file", this.ShogiEngineFilePath);

                xKifunarabe.AppendChild(xShogiEngine);

                // .xmlファイルを保存
                xDoc.Save(this.FileName);
            }
            catch (Exception ex)
            {
                // エラー
                successfule = false;
                Util_Message.Show($"{ex}");
            }

            return(successfule);
        }
Beispiel #3
0
        public string Get(string name)
        {
            string result;

            if (!this.Properties.ContainsKey(name))
            {
                Util_Message.Show($@"設定ファイル[{this.FilepathsCsv}]の中に、項目が見つかりません。
項目名[{ name }]
もしかして?
・ .odsを編集していて、.csvに出力していないとか?
・ エンコーディングは合っている?
");
                result = "";
                goto gt_EndMethod;
            }

            result = this.Properties[name];

gt_EndMethod:
            return(result);
        }