From 1fa5b427b245d9263a1a0c857893d218ddc81e13 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=E3=81=8F=E3=81=BE=E3=81=8B=E3=81=BF=E5=B7=A5=E6=88=BF?= Date: Thu, 10 Nov 2016 18:19:46 +0900 Subject: [PATCH] =?utf8?q?SST=E3=82=B5=E3=83=BC=E3=83=93=E3=82=B9=E3=81=8C?= =?utf8?q?=E5=88=87=E6=96=AD=E3=81=95=E3=82=8C=E3=81=A6=E3=81=8B=E3=82=89?= =?utf8?q?=E3=83=93=E3=83=A5=E3=82=A2=E3=83=BC=E3=82=92=E5=86=8D=E5=BA=A6?= =?utf8?q?=E8=B5=B7=E5=8B=95=E3=81=97=E3=81=9F=E3=81=A8=E3=81=8D=E3=81=AB?= =?utf8?q?=E4=BE=8B=E5=A4=96=E3=81=8C=E7=99=BA=E7=94=9F=E3=81=97=E3=81=A6?= =?utf8?q?=E3=81=9F=E3=83=9F=E3=82=B9=E3=82=92=E4=BF=AE=E6=AD=A3=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- SSTFEditor/メインフォーム.cs | 68 ++++++++++++++++++++++++++++++------- 1 file changed, 56 insertions(+), 12 deletions(-) diff --git a/SSTFEditor/メインフォーム.cs b/SSTFEditor/メインフォーム.cs index a6fe705..60b5dc9 100644 --- a/SSTFEditor/メインフォーム.cs +++ b/SSTFEditor/メインフォーム.cs @@ -229,6 +229,7 @@ namespace SSTFEditor protected ChannelFactory SSTファクトリ = null; protected SST.IStrokeStyleTService SSTサービス = null; + protected IClientChannel SSTサービスチャンネル = null; private bool bs_未保存である = false; private SSTFormat.チップ種別 bs_e現在のチップ種別; @@ -299,14 +300,18 @@ namespace SSTFEditor protected void Actアプリを終了する() { // SSTファクトリを閉じる。 - this.SSTサービス = null; // サービスは解放処理なし try { + this.SSTサービスチャンネル?.Close(); + this.SSTサービスチャンネル = null; + this.SSTサービス = null; + this.SSTファクトリ?.Close(); + this.SSTファクトリ = null; } - catch( CommunicationException ) + catch { - // すでに通信が閉じられている(SSTサービスホストが終了している)。 + // エラーは無視。 } // 一時ファイルが残っていれば、削除する。 @@ -785,12 +790,31 @@ namespace SSTFEditor // SSTサービスを取得する。 this.SSTサービスが起動していれば取得する(); - // SSTサービスが起動していない場合は、Viewer プロセスを起動する。 + // プロセスの起動が必要か? + bool ビュアープロセスを起動する = false; + if( null == this.SSTサービス ) { + ビュアープロセスを起動する = true; + } + else + { + try + { + this.SSTサービス.GetSoundDelay(); + } + catch + { + ビュアープロセスを起動する = true; + } + } + + // 必要ならビュアープロセスを起動する。 + if( ビュアープロセスを起動する ) + { try { - Process.Start( this.Config.ViewerPath ); + Process.Start( this.Config.ViewerPath, "-v" ); // ビュアーオプション付き } catch { @@ -798,6 +822,7 @@ namespace SSTFEditor } // Viewer の提供するSSTサービスへ接続する。 + this.SSTファクトリ = null; for( int retry = 0; retry < 10; retry++ ) // 最大10回リトライ。 { this.SSTサービスが起動していれば取得する(); @@ -825,10 +850,17 @@ namespace SSTFEditor } // 演奏開始を指示する。 - this.SSTサービス.ViewerPlay( - path: this.最後にプレイヤーに渡した一時ファイル名, - startPart: 小節番号, - drumsSound: 仮想ドラムを使う ); + try + { + this.SSTサービス.ViewerPlay( + path: this.最後にプレイヤーに渡した一時ファイル名, + startPart: 小節番号, + drumsSound: 仮想ドラムを使う ); + } + catch + { + // 例外は無視。 + } } protected void Act再生を停止する() { @@ -1569,18 +1601,30 @@ namespace SSTFEditor { // ファクトリが未生成なら生成する。 if( null == this.SSTファクトリ ) + { this.SSTファクトリ = new ChannelFactory( new NetNamedPipeBinding( NetNamedPipeSecurityMode.None ) ); + this.SSTサービスチャンネル = null; + this.SSTサービス = null; + } // サービスが未取得なら取得する。 - if( null == this.SSTサービス ) + if( ( null == this.SSTサービス ) || ( null == this.SSTサービスチャンネル ) ) // サービスとチャンネルは同じオブジェクト。 { try { this.SSTサービス = this.SSTファクトリ.CreateChannel( new EndpointAddress( "net.pipe://localhost/StrokeStyleT/Viewer" ) ); + this.SSTサービスチャンネル = this.SSTサービス as IClientChannel; + this.SSTサービスチャンネル.Open(); + this.SSTサービスチャンネル.Closed += ( sender, e ) => { + this.SSTサービスチャンネル = null; + this.SSTサービス = null; + }; } - catch( EndpointNotFoundException ) + catch { - this.SSTサービス = null; // 取得失敗。 + // 取得失敗。 + this.SSTサービス = null; + this.SSTサービスチャンネル = null; } } } -- 2.11.0