using System.Runtime.Serialization;
using System.Xml;
using SharpDX.DirectInput;
+using FDK;
namespace SST.入力
{
- [DataContract( Name = "キーバインディング", Namespace = "" )]
+ [DataContract( Name = "KeyBindings", Namespace = "" )]
class キーバインディング : IExtensibleDataObject
{
/// <summary>
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 )
{
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.現在のメソッド名}" );
}
/// </summary>
public void キーバインディングを保存する()
{
- var xmlPath = SST.IO.Folder.絶対パスに含まれるフォルダ変数を展開して返す( this._KeyBindingsXmlファイルパス );
-
- Utilities.保存する( this._キーバインディング, xmlPath );
+ キーバインディング.保存する( this._キーバインディング );
}
/// <summary>
private キーバインディング _キーバインディング = null;
/// <summary>
- /// キーバインディングを保存する XML ファイルのパス。
- /// </summary>
- private readonly string _KeyBindingsXmlファイルパス = @"$(AppData)\KeyBindings.xml";
-
-
- /// <summary>
/// 単一の IInputDevice をポーリングし、対応表に従ってドラム入力へ変換して、ポーリング結果 に追加登録する。
/// </summary>
/// <param name="入力デバイス">ポーリングを行う入力デバイス。</param>