OSDN Git Service

キーバインディングの保存と復元を、入力管理クラスからキーバインディングクラスへ移設。
authorくまかみ工房 <kumakamikoubou@gmail.com>
Mon, 13 Mar 2017 10:44:45 +0000 (19:44 +0900)
committerくまかみ工房 <kumakamikoubou@gmail.com>
Mon, 13 Mar 2017 10:55:28 +0000 (19:55 +0900)
キーバインディングのDataContract Name を KeyBindings に変更。(英語で合わせる)

StrokeStyleT/入力/キーバインディング.cs
StrokeStyleT/入力/入力管理.cs

index d220499..03dad08 100644 (file)
@@ -6,10 +6,11 @@ using System.Linq;
 using System.Runtime.Serialization;
 using System.Xml;
 using SharpDX.DirectInput;
+using FDK;
 
 namespace SST.入力
 {
-       [DataContract( Name = "キーバインディング", Namespace = "" )]
+       [DataContract( Name = "KeyBindings", Namespace = "" )]
        class キーバインディング : IExtensibleDataObject
        {
                /// <summary>
@@ -54,16 +55,67 @@ namespace SST.入力
                public Dictionary<IdKey, ドラム入力種別> MIDItoドラム { get; protected set; }
 
 
+               /// <summary>
+               ///             コンストラクタ。
+               /// </summary>
                public キーバインディング()
                {
                        this._既定値で初期化する( new StreamingContext() );
                }
 
+               /// <summary>
+               ///             XMLファイルに保存する。
+               /// </summary>
+               public static void 保存する( キーバインディング keyBindings )
+               {
+                       var xmlPath = SST.IO.Folder.絶対パスに含まれるフォルダ変数を展開して返す( _KeyBindingsXmlファイルパス );
+                       Utilities.保存する( keyBindings, xmlPath );
+               }
+
+               /// <summary>
+               ///             XMLファイルから復元する。
+               /// </summary>
+               public static キーバインディング 復元する()
+               {
+                       var keyBindings = (キーバインディング) null;
+                       var xmlPath = SST.IO.Folder.絶対パスに含まれるフォルダ変数を展開して返す( _KeyBindingsXmlファイルパス );
+
+                       if( File.Exists( xmlPath ) )
+                       {
+                               try
+                               {
+                                       keyBindings = Utilities.復元する<キーバインディング>( xmlPath );
+                                       Log.Info( $"XMLファイルからキーバインディングを復元しました。[{_KeyBindingsXmlファイルパス}]" );
+                               }
+                               catch
+                               {
+                                       Log.WARNING( $"XMLファイルからの復元に失敗しました。初期状態で生成します。[{_KeyBindingsXmlファイルパス}]" );
+                                       keyBindings = new キーバインディング();
+                               }
+                       }
+                       else
+                       {
+                               Log.WARNING( $"キーバインディングファイルが存在しません。新規作成します。[{_KeyBindingsXmlファイルパス}]" );
+                               keyBindings = new キーバインディング();
+
+                               Utilities.保存する( keyBindings, xmlPath );
+                       }
+
+                       return keyBindings;
+               }
+
+               /// <summary>
+               ///             キーバインディングを保存する XML ファイルのパス。
+               /// </summary>
+               private static readonly string _KeyBindingsXmlファイルパス = @"$(AppData)\KeyBindings.xml";
 
                /// <summary>
                ///             コンストラクタ時または逆シリアル化時のメンバの既定値を設定する。
                /// </summary>
                /// <param name="sc">未使用。</param>
+               /// <remarks>
+               ///             .NET 既定の初期値だと支障のある(逆シリアル化対象の)メンバがあれば、ここで初期化しておくこと。
+               /// </remarks>
                [OnDeserializing]
                private void _既定値で初期化する( StreamingContext context )
                {
index 0f9d462..a72cb7e 100644 (file)
@@ -54,33 +54,7 @@ namespace SST.入力
                        this.ポーリング結果.Clear();
 
                        this._入力履歴 = new List<ドラム入力イベント>( 最大履歴数 );
-
-                       #region " XMLファイルからキーバインディングを復元する。"
-                       //----------------
-                       var xmlPath = SST.IO.Folder.絶対パスに含まれるフォルダ変数を展開して返す( this._KeyBindingsXmlファイルパス );
-
-                       if( File.Exists( xmlPath ) )
-                       {
-                               try
-                               {
-                                       this._キーバインディング = Utilities.復元する<キーバインディング>( xmlPath );
-                                       Log.Info( $"XMLファイルからキーバインディングを復元しました。[{this._KeyBindingsXmlファイルパス}]" );
-                               }
-                               catch
-                               {
-                                       Log.WARNING( $"XMLファイルからの復元に失敗しました。初期状態で生成します。[{this._KeyBindingsXmlファイルパス}]" );
-                                       this._キーバインディング = new キーバインディング();
-                               }
-                       }
-                       else
-                       {
-                               Log.WARNING( $"キーバインディングファイルが存在しません。新規作成します。[{this._KeyBindingsXmlファイルパス}]" );
-                               this._キーバインディング = new キーバインディング();
-
-                               Utilities.保存する( this._キーバインディング, xmlPath );
-                       }
-                       //----------------
-                       #endregion
+                       this._キーバインディング = キーバインディング.復元する();
 
                        Log.EndInfo( $"{Utilities.現在のメソッド名}" );
                }
@@ -148,9 +122,7 @@ namespace SST.入力
                /// </summary>
                public void キーバインディングを保存する()
                {
-                       var xmlPath = SST.IO.Folder.絶対パスに含まれるフォルダ変数を展開して返す( this._KeyBindingsXmlファイルパス );
-
-                       Utilities.保存する( this._キーバインディング, xmlPath );
+                       キーバインディング.保存する( this._キーバインディング );
                }
 
                /// <summary>
@@ -227,12 +199,6 @@ namespace SST.入力
                private キーバインディング _キーバインディング = null;
 
                /// <summary>
-               ///             キーバインディングを保存する XML ファイルのパス。
-               /// </summary>
-               private readonly string _KeyBindingsXmlファイルパス = @"$(AppData)\KeyBindings.xml";
-
-
-               /// <summary>
                ///             単一の IInputDevice をポーリングし、対応表に従ってドラム入力へ変換して、ポーリング結果 に追加登録する。
                /// </summary>
                /// <param name="入力デバイス">ポーリングを行う入力デバイス。</param>