OSDN Git Service

#28263 DTX2WAV005:
[dtxmania/dtxmania.git] / DTXMania / コード / 全体 / CDTXMania.cs
1 using System;
2 using System.Collections.Generic;
3 using System.Globalization;
4 using System.Text;
5 using System.Windows.Forms;
6 using System.Drawing;
7 using System.Diagnostics;
8 using System.IO;
9 using System.Threading;
10 using System.Management;
11 using SharpDX;
12 using SharpDX.Direct3D9;
13 using FDK;
14 using SampleFramework;
15 using System.Runtime.Serialization;
16 using System.Xml;
17
18 using Point = System.Drawing.Point;
19 using Color = System.Drawing.Color;
20
21 namespace DTXMania
22 {
23         internal class CDTXMania : Game
24         {
25                 // プロパティ
26                 #region [ properties ]
27                 public static readonly string VERSION = "112(180201)";
28                 public static readonly string SLIMDXDLL = "c_net20x86_Jun2010";
29                 public static readonly string D3DXDLL = "d3dx9_43.dll";     // June 2010
30                                                                                                                                                                                                                                                                 //public static readonly string D3DXDLL = "d3dx9_42.dll";       // February 2010
31                                                                                                                                                                                                                                                                 //public static readonly string D3DXDLL = "d3dx9_41.dll";       // March 2009
32                 private static CDTXMania instance = new CDTXMania();
33
34                 public static CDTXMania Instance
35                 {
36                         get
37                         {
38                                 return instance;
39                         }
40                 }
41                 public C文字コンソール act文字コンソール { get; private set; }
42                 public bool bコンパクトモード { get; private set; }
43                 public CConfigXml ConfigIni;
44                 public CResources Resources;
45
46                 public CDTX DTX
47                 {
48                         get
49                         {
50                                 return dtx;
51                         }
52                         set
53                         {
54                                 if ((dtx != null) && (Instance != null))
55                                 {
56                                         dtx.On非活性化();
57                                         Instance.listトップレベルActivities.Remove(dtx);
58                                 }
59                                 dtx = value;
60                                 if ((dtx != null) && (Instance != null))
61                                 {
62                                         Instance.listトップレベルActivities.Add(dtx);
63                                 }
64                         }
65                 }
66                 public CFPS FPS { get; private set; }
67                 public CInput管理 Input管理 { get; private set; }
68                 #region [ 入力範囲ms ]
69                 public int nPerfect範囲ms
70                 {
71                         get
72                         {
73                                 if (stage選曲.r確定された曲 != null)
74                                 {
75                                         C曲リストノード c曲リストノード = stage選曲.r確定された曲.r親ノード;
76                                         if (((c曲リストノード != null) && (c曲リストノード.eノード種別 == C曲リストノード.Eノード種別.BOX)) && (c曲リストノード.nPerfect範囲ms >= 0))
77                                         {
78                                                 return c曲リストノード.nPerfect範囲ms;
79                                         }
80                                 }
81                                 return ConfigIni.nHitRange.Perfect;
82                         }
83                 }
84                 public int nGreat範囲ms
85                 {
86                         get
87                         {
88                                 if (stage選曲.r確定された曲 != null)
89                                 {
90                                         C曲リストノード c曲リストノード = stage選曲.r確定された曲.r親ノード;
91                                         if (((c曲リストノード != null) && (c曲リストノード.eノード種別 == C曲リストノード.Eノード種別.BOX)) && (c曲リストノード.nGreat範囲ms >= 0))
92                                         {
93                                                 return c曲リストノード.nGreat範囲ms;
94                                         }
95                                 }
96                                 return ConfigIni.nHitRange.Great;
97                         }
98                 }
99                 public int nGood範囲ms
100                 {
101                         get
102                         {
103                                 if (stage選曲.r確定された曲 != null)
104                                 {
105                                         C曲リストノード c曲リストノード = stage選曲.r確定された曲.r親ノード;
106                                         if (((c曲リストノード != null) && (c曲リストノード.eノード種別 == C曲リストノード.Eノード種別.BOX)) && (c曲リストノード.nGood範囲ms >= 0))
107                                         {
108                                                 return c曲リストノード.nGood範囲ms;
109                                         }
110                                 }
111                                 return ConfigIni.nHitRange.Good;
112                         }
113                 }
114                 public int nPoor範囲ms
115                 {
116                         get
117                         {
118                                 if (stage選曲.r確定された曲 != null)
119                                 {
120                                         C曲リストノード c曲リストノード = stage選曲.r確定された曲.r親ノード;
121                                         if (((c曲リストノード != null) && (c曲リストノード.eノード種別 == C曲リストノード.Eノード種別.BOX)) && (c曲リストノード.nPoor範囲ms >= 0))
122                                         {
123                                                 return c曲リストノード.nPoor範囲ms;
124                                         }
125                                 }
126                                 return ConfigIni.nHitRange.Poor;
127                         }
128                 }
129                 #endregion
130                 public CPad Pad { get; private set; }
131                 public Random Random { get; private set; }
132                 public CSkin Skin { get; private set; }
133                 public CSongs管理 Songs管理 { get; set; }// 2012.1.26 yyagi private解除 CStage起動でのdesirialize読み込みのため
134                 public CEnumSongs EnumSongs { get; private set; }
135                 public CActEnumSongs actEnumSongs { get; private set; }
136                 public CActFlushGPU actFlushGPU { get; private set; }
137
138                 public CSound管理 Sound管理 { get; private set; }
139                 public CStage起動 stage起動 { get; private set; }
140                 public CStageタイトル stageタイトル { get; private set; }
141                 public CStageコンフィグ stageコンフィグ { get; private set; }
142                 public CStage選曲 stage選曲 { get; private set; }
143                 public CStage曲読み込み stage曲読み込み { get; private set; }
144                 public CStage演奏画面共通 stage演奏画面 { get; private set; }
145                 public CStage結果 stage結果 { get; private set; }
146                 public CStageChangeSkin stageChangeSkin { get; private set; }
147                 public CStage終了 stage終了 { get; private set; }
148                 public CStage r現在のステージ = null;
149                 public CStage r直前のステージ = null;
150                 public CStage r1フレーム前のステージ = null;
151                 public string strEXEのあるフォルダ { get; private set; }
152                 public string strコンパクトモードファイル { get; private set; }
153                 public CTimer Timer { get; private set; }
154                 public Format TextureFormat = Format.A8R8G8B8;
155                 internal IPluginActivity act現在入力を占有中のプラグイン = null;
156                 public bool bApplicationActive { get; private set; }
157                 public bool b次のタイミングで垂直帰線同期切り替えを行う { get; set; }
158                 public bool b次のタイミングで全画面_ウィンドウ切り替えを行う { get; set; }
159                 public Coordinates.CCoordinates Coordinates;
160                 public Device Device
161                 {
162                         get
163                         {
164                                 return base.GraphicsDeviceManager.Direct3D9.Device;
165                         }
166                 }
167                 public CPluginHost PluginHost { get; private set; }
168                 public List<STPlugin> listプラグイン = new List<STPlugin>();
169
170                 private Size currentClientSize { get; set; }    // #23510 2010.10.27 add yyagi to keep current window size
171                                                                                                                                                                                                                 //              public static CTimer ct;
172                 public IntPtr WindowHandle                  // 2012.10.24 yyagi; to add ASIO support
173                 {
174                         get
175                         {
176                                 return base.Window.Handle;
177                         }
178                 }
179         public CDTXVmode DTXVmode;                       // #28821 2014.1.23 yyagi
180         public CDTX2WAVmode DTX2WAVmode;
181         public CCommandParse CommandParse;
182         #endregion
183
184         // コンストラクタ
185
186         private CDTXMania()
187                 {
188                 }
189
190                 public void InitializeInstance()
191                 {
192                         #region [ strEXEのあるフォルダを決定する ]
193                         // BEGIN #23629 2010.11.13 from: デバッグ時は Application.ExecutablePath が ($SolutionDir)/bin/x86/Debug/ などになり System/ の読み込みに失敗するので、カレントディレクトリを採用する。(プロジェクトのプロパティ→デバッグ→作業ディレクトリが有効になる)
194 #if DEBUG
195                         strEXEのあるフォルダ = Environment.CurrentDirectory + @"\";
196                         //strEXEのあるフォルダ = Path.GetDirectoryName( Environment.GetCommandLineArgs()[ 0 ] ) + @"\";
197 #else
198                         strEXEのあるフォルダ = Path.GetDirectoryName(Application.ExecutablePath) + @"\"; // #23629 2010.11.9 yyagi: set correct pathname where DTXManiaGR.exe is.
199 #endif
200                         // END #23629 2010.11.13 from
201                         #endregion
202
203                         #region [ 言語リソースの初期化 ]
204                         Trace.TraceInformation("言語リソースの初期化を行います。");
205                         Trace.Indent();
206                         try
207                         {
208                                 Resources = new CResources();
209                                 Resources.LoadResources("");
210                                 Trace.TraceInformation("言語リソースの初期化を完了しました。");
211                         }
212                         finally
213                         {
214                                 Trace.Unindent();
215                         }
216                         #endregion
217
218                         #region [ Config.ini の読込み ]
219                         ConfigIni = new CConfigXml();
220                         CDTXMania.Instance.LoadConfig();
221                         // #28200 2011.5.1 yyagi
222                         this.Window.EnableSystemMenu = CDTXMania.Instance.ConfigIni.bIsEnabledSystemMenu;
223                         // 2012.8.22 Config.iniが無いときに初期値が適用されるよう、この設定行をifブロック外に移動
224                         #endregion
225
226
227                         #region[座標値読み込み]
228                         Coordinates = new Coordinates.CCoordinates();
229                         UpdateCoordinates();
230                         //Coordinates = (DTXMania.Coordinates.CCoordinates) CDTXMania.DeserializeXML( strEXEのあるフォルダ + "Coordinates.xml", typeof( DTXMania.Coordinates.CCoordinates ) );
231                         //if ( Coordinates == null )
232                         //{
233                         //      if ( File.Exists( strEXEのあるフォルダ + "Coordinates.xml" ) )
234                         //      {
235                         //              Trace.TraceInformation( "Coordinates.xmlファイルは存在します。" );
236                         //      }
237                         //      Trace.TraceInformation( "Coordiantes.xmlファイルの読み込みができませんでした。無視して進めます。" );
238                         //      Coordinates = new Coordinates.CCoordinates();
239                         //}
240                         #endregion
241
242                         #region [ ログ出力開始 ]
243                         Trace.AutoFlush = true;
244                         if (ConfigIni.bLog)
245                         {
246                                 try
247                                 {
248                                         Trace.Listeners.Add(new CTraceLogListener(new StreamWriter(System.IO.Path.Combine(strEXEのあるフォルダ, "DTXManiaLog.txt"), false, Encoding.GetEncoding("utf-16"))));
249                                 }
250                                 catch (System.UnauthorizedAccessException)          // #24481 2011.2.20 yyagi
251                                 {
252                                         Resources.Language = instance.ConfigIni.strLanguage;
253                                         string mes = CDTXMania.Instance.Resources.Explanation("strErrorLogWrite");
254                                         MessageBox.Show(mes, "DTXMania boot error", MessageBoxButtons.OK, MessageBoxIcon.Error);
255                                         Environment.Exit(1);
256                                 }
257                         }
258                         Trace.WriteLine("");
259                         Trace.WriteLine("DTXMania powered by YAMAHA Silent Session Drums");
260                         Trace.WriteLine(string.Format("Release: {0}", VERSION));
261                         Trace.WriteLine("");
262                         Trace.TraceInformation("----------------------");
263                         Trace.TraceInformation("■ アプリケーションの初期化");
264
265                         PutSystemLog();
266
267
268                         #endregion
269
270                         #region [ 言語の設定 ]
271                         Trace.TraceInformation("言語情報の読み込みを開始します。");
272                         //Debug.WriteLine( "language=" + Resources.Language );
273                         //Debug.WriteLine( "settings=" + instance.ConfigIni.strLanguage );
274                         Resources.Language = instance.ConfigIni.strLanguage;
275                         Trace.TraceInformation("言語を{0}に設定しました。", Resources.Language);
276
277                         #endregion
278
279                         #region [ DTXVmodeクラス, DTX2WAVmodeクラス, CommandParseクラス の初期化 ]
280                         //Trace.TraceInformation( "DTXVモードの初期化を行います。" );
281                         //Trace.Indent();
282                         try
283                         {
284                                 DTXVmode = new CDTXVmode();
285                                 DTXVmode.Enabled = false;
286                 //Trace.TraceInformation( "DTXVモードの初期化を完了しました。" );
287
288                 DTX2WAVmode = new CDTX2WAVmode();
289                 //Trace.TraceInformation( "DTX2WAVモードの初期化を完了しました。" );
290
291                 CommandParse = new CCommandParse();
292                 //Trace.TraceInformation( "CommandParseの初期化を完了しました。" );
293             }
294             finally
295                         {
296                                 //Trace.Unindent();
297                         }
298                         #endregion
299                         #region [ コンパクトモードスイッチの有無、もしくは、DTXViewer/DTX2WAVとしての起動 ]
300                         bコンパクトモード = false;
301                         strコンパクトモードファイル = "";
302                         string[] commandLineArgs = Environment.GetCommandLineArgs();
303                         if ((commandLineArgs != null) && (commandLineArgs.Length > 1))
304                         {
305                                 bコンパクトモード = true;
306                                 string arg = "";
307
308                                 for (int i = 1; i < commandLineArgs.Length; i++)
309                                 {
310                                         if (i != 1)
311                                         {
312                                                 arg += " " + "\"" + commandLineArgs[i] + "\"";
313                                         }
314                                         else
315                                         {
316                                                 arg += commandLineArgs[i];
317                                         }
318                                 }
319                                 CommandParse.ParseArguments(arg, ref DTXVmode, ref DTX2WAVmode);
320                                 if (DTXVmode.Enabled)
321                                 {
322                                         DTXVmode.Refreshed = false;                             // 初回起動時は再読み込みに走らせない
323                                         strコンパクトモードファイル = DTXVmode.filename;
324                                         switch (DTXVmode.soundDeviceType)                       // サウンド再生方式の設定
325                                         {
326                                                 case ESoundDeviceType.DirectSound:
327                                                         ConfigIni.nSoundDeviceType.Value = ESoundDeviceTypeForConfig.DSound;
328                                                         break;
329                                                 case ESoundDeviceType.ExclusiveWASAPI:
330                                                         ConfigIni.nSoundDeviceType.Value = ESoundDeviceTypeForConfig.WASAPI_Exclusive;
331                                                         break;
332                                                 case ESoundDeviceType.SharedWASAPI:
333                                                         ConfigIni.nSoundDeviceType.Value = ESoundDeviceTypeForConfig.WASAPI_Shared;
334                                                         break;
335                                                 case ESoundDeviceType.ASIO:
336                                                         ConfigIni.nSoundDeviceType.Value = ESoundDeviceTypeForConfig.ASIO;
337                                                         ConfigIni.strASIODevice.Index = DTXVmode.nASIOdevice;
338                                                         break;
339                                         }
340
341                                         CDTXMania.Instance.ConfigIni.bVSyncWait.Value = DTXVmode.VSyncWait;
342                                         CDTXMania.Instance.ConfigIni.bTimeStretch.Value = DTXVmode.TimeStretch;
343                                         if (DTXVmode.GRmode)
344                                         {
345                                                 CDTXMania.Instance.ConfigIni.eActiveInst.Value = EActiveInstrument.GBOnly;
346                                         }
347                                         else
348                                         {
349                                                 CDTXMania.Instance.ConfigIni.eActiveInst.Value = EActiveInstrument.Both;
350                                         }
351
352                                         CDTXMania.Instance.ConfigIni.bFullScreen.Value = false;
353                                         CDTXMania.Instance.ConfigIni.rcWindow_backup = CDTXMania.Instance.ConfigIni.rcWindow;       // #36612 2016.9.12 yyagi
354                                         CDTXMania.Instance.ConfigIni.rcWindow.W = CDTXMania.Instance.ConfigIni.rcViewerWindow.W;
355                                         CDTXMania.Instance.ConfigIni.rcWindow.H = CDTXMania.Instance.ConfigIni.rcViewerWindow.H;
356                                         CDTXMania.Instance.ConfigIni.rcWindow.X = CDTXMania.Instance.ConfigIni.rcViewerWindow.X;
357                                         CDTXMania.Instance.ConfigIni.rcWindow.Y = CDTXMania.Instance.ConfigIni.rcViewerWindow.Y;
358                                 }
359                                 else if (DTX2WAVmode.Enabled)
360                                 {
361                                         strコンパクトモードファイル = DTX2WAVmode.dtxfilename;
362                                         #region [ FDKへの録音設定 ]
363                                         FDK.CSound管理.strRecordInputDTXfilename = DTX2WAVmode.dtxfilename;
364                                         FDK.CSound管理.strRecordOutFilename = DTX2WAVmode.outfilename;
365                                         FDK.CSound管理.strRecordFileType = DTX2WAVmode.Format.ToString();
366                                         for (int i = 0; i < (int)FDK.CSound.EInstType.Unknown; i++)
367                                         {
368                                                 FDK.CSound管理.nMixerVolume[ i ] = DTX2WAVmode.nMixerVolume[ i ];
369                                         }
370                                         ConfigIni.nMasterVolume.Value = DTX2WAVmode.nMixerVolume[(int)FDK.CSound.EInstType.Unknown];    // [5](Unknown)のところにMasterVolumeが入ってくるので注意
371                                                                                                                                                                                                                                         // CSound管理.nMixerVolume[5]は、結局ここからは変更しないため、
372                                                                                                                                                                                                                                         // 事実上初期値=100で固定。
373                                         #endregion
374                                         #region [ 録音用の本体設定 ]
375
376                                         // 本体プロセスの優先度を少し上げる (最小化状態で動作させると、処理性能が落ちるようなので
377                                         // → ほとんど効果がなかったので止めます
378                                         //Process thisProcess = System.Diagnostics.Process.GetCurrentProcess();
379                                         //thisProcess.PriorityClass = ProcessPriorityClass.AboveNormal;
380
381                                         // エンコーダーのパス設定 (=DLLフォルダ)
382                                         FDK.CSound管理.strEncoderPath = Path.Combine(strEXEのあるフォルダ, "DLL");
383
384                                         CDTXMania.Instance.ConfigIni.nSoundDeviceType.Value = ESoundDeviceTypeForConfig.WASAPI_Exclusive;
385                                         CDTXMania.Instance.ConfigIni.bEventDrivenWASAPI.Value = false;
386
387                                         CDTXMania.Instance.ConfigIni.bVSyncWait.Value = false;
388                                         CDTXMania.Instance.ConfigIni.bTimeStretch.Value = false;
389                                         CDTXMania.Instance.ConfigIni.eActiveInst.Value = EActiveInstrument.Both;
390
391                                         CDTXMania.Instance.ConfigIni.bFullScreen.Value = false;
392                                         CDTXMania.Instance.ConfigIni.rcWindow_backup = CDTXMania.Instance.ConfigIni.rcWindow;
393                                         CDTXMania.Instance.ConfigIni.rcWindow.W = CDTXMania.Instance.ConfigIni.rcViewerWindow.W;
394                                         CDTXMania.Instance.ConfigIni.rcWindow.H = CDTXMania.Instance.ConfigIni.rcViewerWindow.H;
395                                         CDTXMania.Instance.ConfigIni.rcWindow.X = CDTXMania.Instance.ConfigIni.rcViewerWindow.X;
396                                         CDTXMania.Instance.ConfigIni.rcWindow.Y = CDTXMania.Instance.ConfigIni.rcViewerWindow.Y;
397
398                                         //全オート
399                                         CDTXMania.instance.ConfigIni.bAutoPlay.LC.Value = true;
400                                         CDTXMania.instance.ConfigIni.bAutoPlay.HH.Value = true;
401                                         CDTXMania.instance.ConfigIni.bAutoPlay.HHO.Value = true;
402                                         CDTXMania.instance.ConfigIni.bAutoPlay.SD.Value = true;
403                                         CDTXMania.instance.ConfigIni.bAutoPlay.BD.Value = true;
404                                         CDTXMania.instance.ConfigIni.bAutoPlay.HT.Value = true;
405                                         CDTXMania.instance.ConfigIni.bAutoPlay.LT.Value = true;
406                                         CDTXMania.instance.ConfigIni.bAutoPlay.FT.Value = true;
407                                         CDTXMania.instance.ConfigIni.bAutoPlay.CY.Value = true;
408                                         CDTXMania.instance.ConfigIni.bAutoPlay.RD.Value = true;
409
410                                         CDTXMania.instance.ConfigIni.bAutoPlay.GtR.Value = true;
411                                         CDTXMania.instance.ConfigIni.bAutoPlay.GtG.Value = true;
412                                         CDTXMania.instance.ConfigIni.bAutoPlay.GtB.Value = true;
413                                         CDTXMania.instance.ConfigIni.bAutoPlay.GtPick.Value = true;
414                                         //CDTXMania.instance.ConfigIni.bAutoPlay.GtWail.Value = true;  // 無くてもよい 処理不可削減のため、敢えてWailはAutoにしない
415                                         CDTXMania.instance.ConfigIni.bAutoPlay.BsR.Value = true;
416                                         CDTXMania.instance.ConfigIni.bAutoPlay.BsG.Value = true;
417                                         CDTXMania.instance.ConfigIni.bAutoPlay.BsB.Value = true;
418                                         CDTXMania.instance.ConfigIni.bAutoPlay.BsPick.Value = true;
419                                         //CDTXMania.instance.ConfigIni.bAutoPlay.BsWail.Value = true;
420
421                                         //FillInオフ, 歓声オフ
422                                         CDTXMania.instance.ConfigIni.bFillin.Value = false;
423                                         CDTXMania.instance.ConfigIni.bAudience.Value = false;
424                                         //ストイックモード
425                                         CDTXMania.instance.ConfigIni.bStoicMode.Value = false;
426                                         //チップ非表示
427                                         CDTXMania.instance.ConfigIni.eSudHidInv.Drums.Value = ESudHidInv.FullInv;
428                                         CDTXMania.instance.ConfigIni.eSudHidInv.Guitar.Value = ESudHidInv.FullInv;
429                                         CDTXMania.instance.ConfigIni.eSudHidInv.Bass.Value = ESudHidInv.FullInv;
430
431                                         // Dark=Full
432                                         CDTXMania.instance.ConfigIni.eDark.Value = EDark.Full;
433
434                                         //多重再生数=4
435                                         CDTXMania.instance.ConfigIni.nPolyphonicSounds.Value = 4;
436
437                                         //再生速度x1
438                                         CDTXMania.instance.ConfigIni.nPlaySpeed.Value = 20;
439
440                                         //メトロノーム音量0
441                                         CDTXMania.instance.ConfigIni.eClickType.Value = EClickType.Off;
442                                         CDTXMania.instance.ConfigIni.nClickHighVolume.Value = 0;
443                                         CDTXMania.instance.ConfigIni.nClickLowVolume.Value = 0;
444
445                                         //自動再生音量=100
446                                         CDTXMania.instance.ConfigIni.nAutoVolume.Value = 100;
447                                         CDTXMania.instance.ConfigIni.nChipVolume.Value = 100;
448
449                                         //マスターボリューム100
450                                         //CDTXMania.instance.ConfigIni.nMasterVolume.Value = 100;       // DTX2WAV側から設定するので、ここでは触らない
451
452                                         //StageFailedオフ
453                                         CDTXMania.instance.ConfigIni.bStageFailed.Value = false;
454
455                                         //グラフ無効
456                                         CDTXMania.instance.ConfigIni.bGraph.Drums.Value = false;
457                                         CDTXMania.instance.ConfigIni.bGraph.Guitar.Value = false;
458                                         CDTXMania.instance.ConfigIni.bGraph.Bass.Value = false;
459
460                                         //コンボ非表示,判定非表示
461                                         CDTXMania.instance.ConfigIni.bDisplayCombo.Drums.Value = false;
462                                         CDTXMania.instance.ConfigIni.bDisplayCombo.Guitar.Value = false;
463                                         CDTXMania.instance.ConfigIni.bDisplayCombo.Bass.Value = false;
464                                         CDTXMania.instance.ConfigIni.bDisplayJudge.Drums.Value = false;
465                                         CDTXMania.instance.ConfigIni.bDisplayJudge.Guitar.Value = false;
466                                         CDTXMania.instance.ConfigIni.bDisplayJudge.Bass.Value = false;
467
468
469                                         //デバッグ表示オフ
470                                         //CDTXMania.instance.ConfigIni.b演奏情報を表示する = false;
471                                         CDTXMania.instance.ConfigIni.bDebugInfo.Value = false;
472
473                                         //BGAオフ, AVIオフ
474                                         CDTXMania.instance.ConfigIni.bBGA.Value = false;
475                                         CDTXMania.instance.ConfigIni.bAVI.Value = false;
476
477                                         //BGMオン、チップ音オン
478                                         CDTXMania.instance.ConfigIni.bBGMPlay.Value = true;
479                                         CDTXMania.instance.ConfigIni.bDrumsHitSound.Value = true;
480
481                                         //パート強調オフ
482                                         CDTXMania.Instance.ConfigIni.bEmphasizePlaySound.Drums.Value = false;
483                                         CDTXMania.Instance.ConfigIni.bEmphasizePlaySound.Guitar.Value = false;
484                                         CDTXMania.Instance.ConfigIni.bEmphasizePlaySound.Bass.Value = false;
485
486                                         // パッド入力等、基本操作の無効化 (ESCを除く)
487                                         //CDTXMania.Instance.ConfigIni.KeyAssign[][];
488                                         
489                                         #endregion
490                                 }
491                                 else                                                        // 通常のコンパクトモード
492                                 {
493                                         strコンパクトモードファイル = commandLineArgs[1];
494                                 }
495
496                                 if (!File.Exists(strコンパクトモードファイル))      // #32985 2014.1.23 yyagi 
497                                 {
498                                         Trace.TraceError("コンパクトモードで指定されたファイルが見つかりません。DTXManiaを終了します。[{0}]", strコンパクトモードファイル);
499 #if DEBUG
500                                         Environment.Exit(-1);
501 #else
502                                         if (strコンパクトモードファイル == "")      // DTXMania未起動状態で、DTXCで再生停止ボタンを押した場合は、何もせず終了
503                                         {
504                                                 Environment.Exit(-1);
505                                         }
506                                         else
507                                         {
508                                                 throw new FileNotFoundException("コンパクトモードで指定されたファイルが見つかりません。DTXManiaを終了します。", strコンパクトモードファイル);
509                                         }
510 #endif
511                                 }
512                                 if (DTXVmode.Enabled)
513                                 {
514                                         Trace.TraceInformation("DTXVモードで起動します。[{0}]", strコンパクトモードファイル);
515                                 }
516                                 else if (DTX2WAVmode.Enabled)
517                                 {
518                                         Trace.TraceInformation("DTX2WAVモードで起動します。[{0}]", strコンパクトモードファイル);
519                                         DTX2WAVmode.SendMessage2DTX2WAV("BOOT");
520                                 }
521                                 else
522                                 {
523                                         Trace.TraceInformation("コンパクトモードで起動します。[{0}]", strコンパクトモードファイル);
524                                 }
525                         }
526                         else
527                         {
528                                 Trace.TraceInformation("通常モードで起動します。");
529                         }
530                         #endregion
531
532                         #region [ 現在の電源プランをバックアップし、CONFIGのHighPower=ONの場合は HighPerformanceに変更 ]
533                         CPowerPlan.BackupCurrentPowerPlan();
534                         if (CDTXMania.Instance.ConfigIni.bForceHighPowerPlan)
535                         {
536                                 CPowerPlan.ChangeHighPerformance();
537                         }
538                         #endregion
539
540                         #region [ Input管理 の初期化 ]
541                         Trace.TraceInformation("DirectInput, MIDI入力の初期化を行います。");
542                         Trace.Indent();
543                         try
544                         {
545                                 bool bUseMIDIIn = !DTXVmode.Enabled;
546                                 Input管理 = new CInput管理(base.Window.Handle, bUseMIDIIn);
547                                 foreach (IInputDevice device in Input管理.list入力デバイス)
548                                 {
549                                         if ((device.e入力デバイス種別 == E入力デバイス種別.Joystick) && !ConfigIni.dicJoystick.Value.ContainsValue(device.GUID))
550                                         {
551                                                 int key = 0;
552                                                 while (ConfigIni.dicJoystick.Value.ContainsKey(key))
553                                                 {
554                                                         key++;
555                                                 }
556                                                 ConfigIni.dicJoystick.Value.Add(key, device.GUID);
557                                         }
558                                 }
559                                 foreach (IInputDevice device2 in Input管理.list入力デバイス)
560                                 {
561                                         if (device2.e入力デバイス種別 == E入力デバイス種別.Joystick)
562                                         {
563                                                 foreach (KeyValuePair<int, string> pair in ConfigIni.dicJoystick.Value)
564                                                 {
565                                                         if (device2.GUID.Equals(pair.Value))
566                                                         {
567                                                                 ((CInputJoystick)device2).SetID(pair.Key);
568                                                                 break;
569                                                         }
570                                                 }
571                                                 continue;
572                                         }
573                                 }
574                                 Trace.TraceInformation("DirectInput の初期化を完了しました。");
575                         }
576                         catch (Exception exception2)
577                         {
578                                 Trace.TraceError(exception2.Message);
579                                 Trace.TraceError("DirectInput, MIDI入力の初期化に失敗しました。");
580
581                                 string mes = CDTXMania.Instance.Resources.Explanation("strErrorLogWrite");
582                                 MessageBox.Show(mes, "DTXMania boot error", MessageBoxButtons.OK, MessageBoxIcon.Error);
583                                 Environment.Exit(1);
584                         }
585                         finally
586                         {
587                                 Trace.Unindent();
588                         }
589                         #endregion
590
591                         #region [ ウィンドウ初期化 ]
592                         // #30675 2013.02.04 ikanick add
593                         base.Window.StartPosition = FormStartPosition.Manual;
594                         base.Window.Location = new Point(ConfigIni.rcWindow.X, ConfigIni.rcWindow.Y);
595                         // 事前にDTXVmodeの実体を作っておくこと
596                         base.Window.Text = this.strWindowTitle;
597                         //base.Window.StartPosition = FormStartPosition.Manual;
598                         //base.Window.Location = new Point(ConfigIni.rcWindow.X, ConfigIni.rcWindow.Y);
599
600                         // #34510 yyagi 2010.10.31 to change window size got from Config.ini
601                         base.Window.ClientSize = new Size(ConfigIni.rcWindow.W, ConfigIni.rcWindow.H);
602 #if !WindowedFullscreen
603                         if (!ConfigIni.bウィンドウモード)                                               // #23510 2010.11.02 yyagi: add; to recover window size in case bootup with fullscreen mode
604                         {                                                                                                               // #30666 2013.02.02 yyagi: currentClientSize should be always made
605 #endif
606                         currentClientSize = new Size(ConfigIni.rcWindow.W, ConfigIni.rcWindow.H);
607 #if !WindowedFullscreen
608                         }
609 #endif
610                         // #23510 2010.11.04 yyagi: to support maximizing window
611                         base.Window.MaximizeBox = true;
612                         // #23510 2010.10.27 yyagi: changed from FixedDialog to Sizable, to support window resize
613                         base.Window.FormBorderStyle = FormBorderStyle.Sizable;
614                         // #30666 2013.02.02 yyagi: moved the code to t全画面・ウインドウモード切り替え()
615                         base.Window.ShowIcon = true;
616                         base.Window.Icon = Properties.Resources.dtx;
617                         base.Window.KeyDown += new KeyEventHandler(this.Window_KeyDown);
618                         base.Window.MouseUp += new MouseEventHandler(this.Window_MouseUp);
619                         // #23510 2010.11.13 yyagi: to go fullscreen mode
620                         base.Window.MouseDoubleClick += new MouseEventHandler(this.Window_MouseDoubleClick);
621                         // #23510 2010.11.20 yyagi: to set resized window size in Config.ini
622                         base.Window.ResizeEnd += new EventHandler(this.Window_ResizeEnd);
623                         base.Window.ApplicationActivated += new EventHandler(this.Window_ApplicationActivated);
624                         base.Window.ApplicationDeactivated += new EventHandler(this.Window_ApplicationDeactivated);
625                         base.Window.MouseMove += new MouseEventHandler(this.Window_MouseMove);
626                         #endregion
627
628                         #region [ Direct3D9Exを使うかどうか判定 ]
629                         #endregion
630
631                         #region [ Direct3D9 デバイスの生成 ]
632                         DeviceSettings settings = new DeviceSettings();
633 #if WindowedFullscreen
634                         // #30666 2013.2.2 yyagi: Fullscreenmode is "Maximized window" mode
635                         settings.Windowed = true;
636 #else
637                         settings.Windowed = ConfigIni.bウィンドウモード;
638 #endif
639                         settings.BackBufferWidth = SampleFramework.GameWindowSize.Width;
640                         settings.BackBufferHeight = SampleFramework.GameWindowSize.Height;
641                         settings.EnableVSync = ConfigIni.bVSyncWait;
642                         //settings.MultisampleType = MultisampleType.FourSamples;
643                         //settings.MultisampleQuality = 3;
644                         //settings.MultisampleType = MultisampleType.NonMaskable;
645                         //settings.Multithreaded = true;
646
647
648                         try
649                         {
650                                 base.GraphicsDeviceManager.ChangeDevice(settings);
651                         }
652                         catch (DeviceCreationException e)
653                         {
654                                 Trace.TraceError(e.ToString());
655                                 MessageBox.Show(e.Message + e.ToString(), "DTXMania failed to boot: DirectX9 Initialize Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
656                                 Environment.Exit(-1);
657                         }
658                         Trace.TraceInformation("DeviceCaps       = " + base.GraphicsDeviceManager.Direct3D9.Device.Capabilities.DeviceCaps.ToString());
659                         Trace.TraceInformation("DeviceCaps2      = " + base.GraphicsDeviceManager.Direct3D9.Device.Capabilities.DeviceCaps2.ToString());
660                         Trace.TraceInformation("MaxTextureWidth  = " + base.GraphicsDeviceManager.Direct3D9.Device.Capabilities.MaxTextureWidth);
661                         Trace.TraceInformation("MaxTextureHeight = " + base.GraphicsDeviceManager.Direct3D9.Device.Capabilities.MaxTextureHeight);
662                         Trace.TraceInformation("TextureCaps      = " + base.GraphicsDeviceManager.Direct3D9.Device.Capabilities.TextureCaps.ToString());
663                         Trace.TraceInformation("DeviceInformation= " + base.GraphicsDeviceManager.DeviceInformation.ToString());
664                         Trace.TraceInformation("DeviceStatics    = " + base.GraphicsDeviceManager.DeviceStatistics.ToString());
665
666                         base.IsFixedTimeStep = false;
667                         //                      base.TargetElapsedTime = TimeSpan.FromTicks( 10000000 / 75 );
668                         // #23510 2010.10.31 yyagi: to recover window size. width and height are able to get from Config.ini.
669                         base.Window.ClientSize = new Size(ConfigIni.rcWindow.W, ConfigIni.rcWindow.H);
670                         // #23568 2010.11.3 yyagi: to support valiable sleep value when !IsActive
671                         base.InactiveSleepTime = TimeSpan.FromMilliseconds((float)(ConfigIni.nSleepUnfocusMs));
672                         // #23568 2010.11.4 ikanick changed ( 1 -> ConfigIni )
673 #if WindowedFullscreen
674                         // #30666 2013.2.2 yyagi: finalize settings for "Maximized window mode"
675                         this.t全画面_ウィンドウモード切り替え();
676 #endif
677                         actFlushGPU = new CActFlushGPU();
678                         #endregion
679
680                         if (DTX2WAVmode.Enabled)
681                         {
682                                 this.Window.WindowState = FormWindowState.Minimized;            //DTX2WAVモード時は自動的に最小化
683                         }
684
685                         DTX = null;
686
687                         #region [ Skin の初期化 ]
688                         Trace.TraceInformation("スキンの初期化を行います。");
689                         Trace.Indent();
690                         try
691                         {
692                                 Skin = new CSkin(
693                                         CDTXMania.Instance.ConfigIni.strSystemSkinSubfolderPath,
694                                         CDTXMania.Instance.ConfigIni.bUseBoxDefSkin);
695                                 // 旧指定のSkinフォルダが消滅していた場合に備える
696                                 CDTXMania.Instance.ConfigIni.strSystemSkinSubfolderPath.Value = CDTXMania.Instance.Skin.GetCurrentSkinSubfolderFullName(true);
697                                 Trace.TraceInformation("スキンの初期化を完了しました。");
698                         }
699                         catch
700                         {
701                                 Trace.TraceInformation("スキンの初期化に失敗しました。");
702                                 throw;
703                         }
704                         finally
705                         {
706                                 Trace.Unindent();
707                         }
708
709                         #region [ Skin配下にある言語リソースの確認と初期化 ]
710                         Trace.TraceInformation("スキンフォルダに言語リソースがないか確認します。");
711                         Trace.Indent();
712                         try
713                         {
714                                 Resources.csvCurrentPath = CDTXMania.Instance.ConfigIni.strSystemSkinSubfolderPath.Value;
715                                 Trace.TraceInformation("Skin Path:" + Resources.csvCurrentPath);
716
717                                 bool ret = Resources.LoadResources(instance.ConfigIni.strLanguage);
718                                 if (ret)
719                                 {
720                                         Trace.TraceInformation("スキンフォルダ内に言語リソースが見つかりました。この言語リソースを使用します。");
721                                 }
722                                 else
723                                 {
724                                         Trace.TraceInformation("スキンフォルダ内の言語リソースを使用できません。既定の言語リソースを使用します。");
725
726                                 }
727                         }
728                         finally
729                         {
730                                 Trace.Unindent();
731                         }
732                         #endregion
733
734                         #endregion
735
736                         #region [ Timer の初期化 ]
737                         Trace.TraceInformation("タイマの初期化を行います。");
738                         Trace.Indent();
739                         try
740                         {
741                                 Timer = new CTimer(CTimer.E種別.MultiMedia);
742                                 Trace.TraceInformation("タイマの初期化を完了しました。");
743                         }
744                         finally
745                         {
746                                 Trace.Unindent();
747                         }
748                         #endregion
749
750                         #region [ マウス消去用のクラスを初期化 ]
751                         cMouseHideControl = new CMouseHideControl();
752                         #endregion
753
754                         #region [ FPS カウンタの初期化 ]
755                         Trace.TraceInformation("FPSカウンタの初期化を行います。");
756                         Trace.Indent();
757                         try
758                         {
759                                 FPS = new CFPS();
760                                 Trace.TraceInformation("FPSカウンタを生成しました。");
761                         }
762                         finally
763                         {
764                                 Trace.Unindent();
765                         }
766                         #endregion
767
768                         #region [ act文字コンソールの初期化 ]
769                         Trace.TraceInformation("文字コンソールの初期化を行います。");
770                         Trace.Indent();
771                         try
772                         {
773                                 act文字コンソール = new C文字コンソール();
774                                 Trace.TraceInformation("文字コンソールを生成しました。");
775                                 act文字コンソール.On活性化();
776                                 Trace.TraceInformation("文字コンソールを活性化しました。");
777                                 Trace.TraceInformation("文字コンソールの初期化を完了しました。");
778                         }
779                         catch (Exception exception)
780                         {
781                                 Trace.TraceError(exception.Message);
782                                 Trace.TraceError("文字コンソールの初期化に失敗しました。");
783                         }
784                         finally
785                         {
786                                 Trace.Unindent();
787                         }
788                         #endregion
789
790                         #region [ Pad の初期化 ]
791                         Trace.TraceInformation("パッドの初期化を行います。");
792                         Trace.Indent();
793                         try
794                         {
795                                 Pad = new CPad();
796                                 Trace.TraceInformation("パッドの初期化を完了しました。");
797                         }
798                         catch (Exception exception3)
799                         {
800                                 Trace.TraceError(exception3.Message);
801                                 Trace.TraceError("パッドの初期化に失敗しました。");
802                         }
803                         finally
804                         {
805                                 Trace.Unindent();
806                         }
807                         #endregion
808
809                         #region [ Sound管理 の初期化 ]
810                         Trace.TraceInformation("サウンドデバイスの初期化を行います。");
811                         Trace.Indent();
812                         try
813                         {
814                                 ESoundDeviceType soundDeviceType;
815                                 switch (CDTXMania.Instance.ConfigIni.nSoundDeviceType.Value)
816                                 {
817                                         case ESoundDeviceTypeForConfig.DSound:
818                                                 soundDeviceType = ESoundDeviceType.DirectSound;
819                                                 break;
820                                         case ESoundDeviceTypeForConfig.ASIO:
821                                                 soundDeviceType = ESoundDeviceType.ASIO;
822                                                 break;
823                                         case ESoundDeviceTypeForConfig.WASAPI_Exclusive:
824                                                 soundDeviceType = ESoundDeviceType.ExclusiveWASAPI;
825                                                 break;
826                                         case ESoundDeviceTypeForConfig.WASAPI_Shared:
827                                                 soundDeviceType = ESoundDeviceType.SharedWASAPI;
828                                                 break;
829                                         default:
830                                                 soundDeviceType = ESoundDeviceType.Unknown;
831                                                 break;
832                                 }
833                                 Sound管理 = new CSound管理(base.Window.Handle,
834                                                                                         soundDeviceType,
835                                                                                         CDTXMania.Instance.ConfigIni.nWASAPIBufferSizeMs,
836                                                                                         CDTXMania.instance.ConfigIni.bEventDrivenWASAPI,
837                                                                                         0,
838                                                                                         CDTXMania.Instance.ConfigIni.strASIODevice.Index,
839                                                                                         CDTXMania.Instance.ConfigIni.bUseOSTimer
840                                 );
841                                 //Sound管理 = FDK.CSound管理.Instance;
842                                 //Sound管理.t初期化( soundDeviceType, 0, 0, CDTXMania.Instance.ConfigIni.nASIODevice, base.Window.Handle );
843
844                                 ShowWindowTitleWithSoundType();
845                                 FDK.CSound管理.bIsTimeStretch = CDTXMania.Instance.ConfigIni.bTimeStretch;
846                                 Sound管理.nMasterVolume = CDTXMania.Instance.ConfigIni.nMasterVolume;
847                                 //FDK.CSound管理.bIsMP3DecodeByWindowsCodec = CDTXMania.Instance.ConfigIni.bNoMP3Streaming;
848                                 Trace.TraceInformation("サウンドデバイスの初期化を完了しました。");
849                         }
850                         catch (Exception e)
851                         {
852                                 Trace.TraceError(e.Message);
853                                 throw;
854                         }
855                         finally
856                         {
857                                 Trace.Unindent();
858                         }
859                         #endregion
860
861                         #region [ Songs管理 の初期化 ]
862                         //---------------------
863                         Trace.TraceInformation("曲リストの初期化を行います。");
864                         Trace.Indent();
865                         try
866                         {
867                                 Songs管理 = new CSongs管理();
868                                 //                              Songs管理_裏読 = new CSongs管理();
869                                 EnumSongs = new CEnumSongs();
870                                 actEnumSongs = new CActEnumSongs();
871                                 Trace.TraceInformation("曲リストの初期化を完了しました。");
872                         }
873                         catch (Exception e)
874                         {
875                                 Trace.TraceError(e.Message);
876                                 Trace.TraceError("曲リストの初期化に失敗しました。");
877                         }
878                         finally
879                         {
880                                 Trace.Unindent();
881                         }
882                         //---------------------
883                         #endregion
884
885                         #region [ CAvi の初期化 ]
886                         CAvi.t初期化();
887                         #endregion
888
889                         #region [ Random の初期化 ]
890                         Random = new Random((int)Timer.nシステム時刻);
891                         #endregion
892
893                         #region [ ステージの初期化 ]
894                         r現在のステージ = null;
895                         r直前のステージ = null;
896                         stage起動 = new CStage起動();
897                         stageタイトル = new CStageタイトル();
898                         stageコンフィグ = new CStageコンフィグ();
899                         stage選曲 = new CStage選曲();
900                         stage曲読み込み = new CStage曲読み込み();
901                         stage演奏画面 = new CStage演奏画面共通();
902                         stage結果 = new CStage結果();
903                         stageChangeSkin = new CStageChangeSkin();
904                         stage終了 = new CStage終了();
905
906                         this.listトップレベルActivities = new List<CActivity>();
907                         this.listトップレベルActivities.Add(actEnumSongs);
908                         this.listトップレベルActivities.Add(act文字コンソール);
909                         this.listトップレベルActivities.Add(stage起動);
910                         this.listトップレベルActivities.Add(stageタイトル);
911                         this.listトップレベルActivities.Add(stageコンフィグ);
912                         this.listトップレベルActivities.Add(stage選曲);
913                         this.listトップレベルActivities.Add(stage曲読み込み);
914                         this.listトップレベルActivities.Add(stage演奏画面);
915                         this.listトップレベルActivities.Add(stage結果);
916                         this.listトップレベルActivities.Add(stageChangeSkin);
917                         this.listトップレベルActivities.Add(stage終了);
918                         this.listトップレベルActivities.Add(actFlushGPU);
919                         #endregion
920
921                         #region [ プラグインの検索と生成 ]
922                         PluginHost = new CPluginHost();
923
924                         Trace.TraceInformation("プラグインの検索と生成を行います。");
925                         Trace.Indent();
926                         try
927                         {
928                                 this.tプラグイン検索と生成();
929                                 Trace.TraceInformation("プラグインの検索と生成を完了しました。");
930                         }
931                         finally
932                         {
933                                 Trace.Unindent();
934                         }
935                         #endregion
936
937                         #region [ プラグインの初期化 ]
938                         if (this.listプラグイン != null && this.listプラグイン.Count > 0)
939                         {
940                                 Trace.TraceInformation("プラグインの初期化を行います。");
941                                 Trace.Indent();
942                                 try
943                                 {
944                                         foreach (STPlugin st in this.listプラグイン)
945                                         {
946                                                 Directory.SetCurrentDirectory(st.strプラグインフォルダ);
947                                                 st.plugin.On初期化(this.PluginHost);
948                                                 st.plugin.OnManagedリソースの作成();
949                                                 st.plugin.OnUnmanagedリソースの作成();
950                                                 Directory.SetCurrentDirectory(CDTXMania.Instance.strEXEのあるフォルダ);
951                                         }
952                                         Trace.TraceInformation("すべてのプラグインの初期化を完了しました。");
953                                 }
954                                 catch
955                                 {
956                                         Trace.TraceError("プラグインのどれかの初期化に失敗しました。");
957                                         throw;
958                                 }
959                                 finally
960                                 {
961                                         Trace.Unindent();
962                                 }
963                         }
964                         #endregion
965
966
967                         Trace.TraceInformation("アプリケーションの初期化を完了しました。");
968
969                         #region [ 最初のステージの起動 ]
970                         Trace.TraceInformation("----------------------");
971                         Trace.TraceInformation("■ 起動");
972
973                         if (CDTXMania.Instance.bコンパクトモード)
974                         {
975                                 r現在のステージ = stage曲読み込み;
976                         }
977                         else
978                         {
979                                 r現在のステージ = stage起動;
980                         }
981                         r現在のステージ.On活性化();
982                         #endregion
983                 }
984
985
986                 public void t全画面_ウィンドウモード切り替え()
987                 {
988 #if WindowedFullscreen
989                         if (ConfigIni != null)
990 #else
991                         DeviceSettings settings = base.GraphicsDeviceManager.CurrentSettings.Clone();
992                         if ( ( ConfigIni != null ) && ( ConfigIni.bウィンドウモード != settings.Windowed ) )
993 #endif
994                         {
995 #if !WindowedFullscreen
996                                 settings.Windowed = ConfigIni.bウィンドウモード;
997 #endif
998                                 if (ConfigIni.bウィンドウモード == false)   // #23510 2010.10.27 yyagi: backup current window size before going fullscreen mode
999                                 {
1000                                         currentClientSize = this.Window.ClientSize;
1001                                         ConfigIni.rcWindow.W = this.Window.ClientSize.Width;
1002                                         ConfigIni.rcWindow.H = this.Window.ClientSize.Height;
1003                                         //                                      FDK.CTaskBar.ShowTaskBar( false );
1004                                 }
1005 #if !WindowedFullscreen
1006                                 base.GraphicsDeviceManager.ChangeDevice( settings );
1007 #endif
1008                                 if (ConfigIni.bウィンドウモード == true)    // #23510 2010.10.27 yyagi: to resume window size from backuped value
1009                                 {
1010 #if WindowedFullscreen
1011                                         // #30666 2013.2.2 yyagi Don't use Fullscreen mode becasue NVIDIA GeForce is
1012                                         // tend to delay drawing on Fullscreen mode. So DTXMania uses Maximized window
1013                                         // in spite of using fullscreen mode.
1014                                         Instance.Window.WindowState = FormWindowState.Normal;
1015                                         Instance.Window.FormBorderStyle = FormBorderStyle.Sizable;
1016                                         Instance.Window.WindowState = FormWindowState.Normal;
1017 #endif
1018                                         base.Window.ClientSize =
1019                                                         new Size(currentClientSize.Width, currentClientSize.Height);
1020                                         //                                      FDK.CTaskBar.ShowTaskBar( true );
1021                                 }
1022 #if WindowedFullscreen
1023                                 else
1024                                 {
1025                                         Instance.Window.WindowState = FormWindowState.Normal;
1026                                         Instance.Window.FormBorderStyle = FormBorderStyle.None;
1027                                         Instance.Window.WindowState = FormWindowState.Maximized;
1028                                 }
1029                                 if (cMouseHideControl != null)
1030                                 {
1031                                         if (ConfigIni.bウィンドウモード)
1032                                         {
1033                                                 cMouseHideControl.Show();
1034                                         }
1035                                         else
1036                                         {
1037                                                 cMouseHideControl.Hide();
1038                                         }
1039                                 }
1040 #endif
1041                         }
1042                 }
1043
1044                 #region [ #24609 リザルト画像をpngで保存する ]              // #24609 2011.3.14 yyagi; to save result screen in case BestRank or HiSkill.
1045                 /// <summary>
1046                 /// リザルト画像のキャプチャと保存。
1047                 /// </summary>
1048                 /// <param name="strFilename">保存するファイル名(フルパス)</param>
1049                 public bool SaveResultScreen(string strFullPath)
1050                 {
1051                         string strSavePath = Path.GetDirectoryName(strFullPath);
1052                         if (!Directory.Exists(strSavePath))
1053                         {
1054                                 try
1055                                 {
1056                                         Directory.CreateDirectory(strSavePath);
1057                                 }
1058                                 catch
1059                                 {
1060                                         return false;
1061                                 }
1062                         }
1063
1064                         // http://www.gamedev.net/topic/594369-dx9slimdxati-incorrect-saving-surface-to-file/
1065                         using (Surface pSurface = CDTXMania.Instance.Device.GetRenderTarget(0))
1066                         {
1067                                 Surface.ToFile(pSurface, strFullPath, ImageFileFormat.Png);
1068                         }
1069                         return true;
1070                 }
1071                 #endregion
1072
1073                 // Game 実装
1074
1075                 protected override void Initialize()
1076                 {
1077                         //                      new GCBeep();
1078                         //sw.Start();
1079                         //swlist1 = new List<int>( 8192 );
1080                         //swlist2 = new List<int>( 8192 );
1081                         //swlist3 = new List<int>( 8192 );
1082                         //swlist4 = new List<int>( 8192 );
1083                         //swlist5 = new List<int>( 8192 );
1084                         if (this.listトップレベルActivities != null)
1085                         {
1086                                 foreach (CActivity activity in this.listトップレベルActivities)
1087                                         activity.OnManagedリソースの作成();
1088                         }
1089
1090                         foreach (STPlugin st in this.listプラグイン)
1091                         {
1092                                 Directory.SetCurrentDirectory(st.strプラグインフォルダ);
1093                                 st.plugin.OnManagedリソースの作成();
1094                                 Directory.SetCurrentDirectory(CDTXMania.Instance.strEXEのあるフォルダ);
1095                         }
1096 #if GPUFlushAfterPresent
1097                         FrameEnd += dtxmania_FrameEnd;
1098 #endif
1099                 }
1100 #if GPUFlushAfterPresent
1101                 void dtxmania_FrameEnd( object sender, EventArgs e )    // GraphicsDeviceManager.game_FrameEnd()後に実行される
1102                 {                                                                                                               // → Present()直後にGPUをFlushする
1103                                                                                                                                 // → 画面のカクツキが頻発したため、ここでのFlushは行わない
1104                         actFlushGPU.On進行描画();           // Flush GPU
1105                 }
1106 #endif
1107                 protected override void LoadContent()
1108                 {
1109                         if (cMouseHideControl != null)
1110                         {
1111                                 if (ConfigIni.bウィンドウモード)
1112                                 {
1113                                         cMouseHideControl.Show();
1114                                 }
1115                                 else
1116                                 {
1117                                         cMouseHideControl.Hide();
1118                                 }
1119                         }
1120                         this.Device.SetTransform(TransformState.View, Matrix.LookAtLH(new Vector3(0f, 0f, (float)(-SampleFramework.GameWindowSize.Height / 2 * Math.Sqrt(3.0))), new Vector3(0f, 0f, 0f), new Vector3(0f, 1f, 0f)));
1121                         this.Device.SetTransform(TransformState.Projection, Matrix.PerspectiveFovLH(C変換.DegreeToRadian((float)60f), ((float)this.Device.Viewport.Width) / ((float)this.Device.Viewport.Height), -100f, 100f));
1122                         this.Device.SetRenderState(RenderState.Lighting, false);
1123                         this.Device.SetRenderState(RenderState.ZEnable, false);                                         // trueにすると、一部システムで画面表示できなくなる
1124                         this.Device.SetRenderState(RenderState.AntialiasedLineEnable, false);       // trueにすると、一部システムで画面表示できなくなる 
1125                         this.Device.SetRenderState(RenderState.AlphaTestEnable, true);
1126                         this.Device.SetRenderState(RenderState.AlphaRef, 10);
1127
1128                         this.Device.SetRenderState(RenderState.MultisampleAntialias, true);
1129                         this.Device.SetSamplerState(0, SamplerState.MinFilter, TextureFilter.Linear);
1130                         this.Device.SetSamplerState(0, SamplerState.MagFilter, TextureFilter.Linear);
1131
1132                         this.Device.SetRenderState<Compare>(RenderState.AlphaFunc, Compare.Greater);
1133                         this.Device.SetRenderState(RenderState.AlphaBlendEnable, true);
1134                         this.Device.SetRenderState<Blend>(RenderState.SourceBlend, Blend.SourceAlpha);
1135                         this.Device.SetRenderState<Blend>(RenderState.DestinationBlend, Blend.InverseSourceAlpha);
1136                         this.Device.SetTextureStageState(0, TextureStage.AlphaOperation, TextureOperation.Modulate);
1137                         this.Device.SetTextureStageState(0, TextureStage.AlphaArg1, 2);
1138                         this.Device.SetTextureStageState(0, TextureStage.AlphaArg2, 1);
1139
1140                         if (this.listトップレベルActivities != null)
1141                         {
1142                                 foreach (CActivity activity in this.listトップレベルActivities)
1143                                         activity.OnUnmanagedリソースの作成();
1144                         }
1145
1146                         foreach (STPlugin st in this.listプラグイン)
1147                         {
1148                                 Directory.SetCurrentDirectory(st.strプラグインフォルダ);
1149                                 st.plugin.OnUnmanagedリソースの作成();
1150                                 Directory.SetCurrentDirectory(CDTXMania.Instance.strEXEのあるフォルダ);
1151                         }
1152                 }
1153                 protected override void UnloadContent()
1154                 {
1155                         if (this.listトップレベルActivities != null)
1156                         {
1157                                 foreach (CActivity activity in this.listトップレベルActivities)
1158                                         activity.OnUnmanagedリソースの解放();
1159                         }
1160
1161                         foreach (STPlugin st in this.listプラグイン)
1162                         {
1163                                 Directory.SetCurrentDirectory(st.strプラグインフォルダ);
1164                                 st.plugin.OnUnmanagedリソースの解放();
1165                                 Directory.SetCurrentDirectory(CDTXMania.Instance.strEXEのあるフォルダ);
1166                         }
1167                 }
1168                 protected override void OnExiting(EventArgs e)
1169                 {
1170                         CPowerManagement.tEnableMonitorSuspend();       // スリープ抑止状態を解除
1171                         this.t終了処理();
1172                         base.OnExiting(e);
1173                 }
1174                 protected override void Update(GameTime gameTime)
1175                 {
1176                 }
1177                 protected override void Draw(GameTime gameTime)
1178                 {
1179                         if (Sound管理 == null)
1180                         {
1181                                 return;
1182                         }
1183                         Sound管理.t再生中の処理をする();
1184
1185                         if (Timer != null)
1186                                 Timer.t更新();
1187                         if (CSound管理.rc演奏用タイマ != null)
1188                                 CSound管理.rc演奏用タイマ.t更新();
1189
1190                         if (Input管理 != null)
1191                                 Input管理.tポーリング(this.bApplicationActive, CDTXMania.Instance.ConfigIni.bBufferedInput);
1192
1193                         if (FPS != null)
1194                                 FPS.tカウンタ更新();
1195
1196                         //if( Pad != null )                                     ポーリング時にクリアしたらダメ!曲の開始時に1回だけクリアする。(2010.9.11)
1197                         //      Pad.st検知したデバイス.Clear();
1198
1199                         if (this.Device == null)
1200                                 return;
1201
1202                         if (this.bApplicationActive)    // DTXMania本体起動中の本体/モニタの省電力モード移行を抑止
1203                                 CPowerManagement.tDisableMonitorSuspend();
1204
1205                         // #xxxxx 2013.4.8 yyagi; sleepの挿入位置を、EndScnene~Present間から、BeginScene前に移動。描画遅延を小さくするため。
1206                         #region [ スリープ ]
1207                         if (ConfigIni.nSleepPerFrameMs >= 0)            // #xxxxx 2011.11.27 yyagi
1208                         {
1209                                 Thread.Sleep(ConfigIni.nSleepPerFrameMs);
1210                         }
1211                         #endregion
1212
1213                         #region [ DTXCreator/DTX2WAVからの指示 ]
1214                         if (this.Window.IsReceivedMessage)  // ウインドウメッセージで、
1215                         {
1216                                 string strMes = this.Window.strMessage;
1217                                 this.Window.IsReceivedMessage = false;
1218                                 if (strMes != null)
1219                                 {
1220                                         CommandParse.ParseArguments(strMes, ref DTXVmode, ref DTX2WAVmode);
1221
1222                                         if (DTXVmode.Enabled)
1223                                         {
1224                                                 bコンパクトモード = true;
1225                                                 strコンパクトモードファイル = DTXVmode.filename;
1226                                                 if (DTXVmode.Command == CDTXVmode.ECommand.Preview)
1227                                                 {
1228                                                         // preview soundの再生
1229                                                         string strPreviewFilename = DTXVmode.previewFilename;
1230                                                         //Trace.TraceInformation( "Preview Filename=" + DTXVmode.previewFilename );
1231                                                         try
1232                                                         {
1233                                                                 if (this.previewSound != null)
1234                                                                 {
1235                                                                         this.previewSound.tサウンドを停止する();
1236                                                                         this.previewSound.Dispose();
1237                                                                         this.previewSound = null;
1238                                                                 }
1239                                                                 this.previewSound = CDTXMania.Instance.Sound管理.tサウンドを生成する(strPreviewFilename);
1240                                                                 this.previewSound.n音量 = DTXVmode.previewVolume;
1241                                                                 this.previewSound.n位置 = DTXVmode.previewPan;
1242                                                                 this.previewSound.t再生を開始する();
1243                                                                 Trace.TraceInformation("DTXCからの指示で、サウンドを生成しました。({0})", strPreviewFilename);
1244                                                         }
1245                                                         catch
1246                                                         {
1247                                                                 Trace.TraceError("DTXCからの指示での、サウンドの生成に失敗しました。({0})", strPreviewFilename);
1248                                                                 if (this.previewSound != null)
1249                                                                 {
1250                                                                         this.previewSound.Dispose();
1251                                                                 }
1252                                                                 this.previewSound = null;
1253                                                         }
1254                                                 }
1255                                         }
1256                                         if (DTX2WAVmode.Enabled)
1257                                         {
1258                                                 if (DTX2WAVmode.Command == CDTX2WAVmode.ECommand.Cancel)
1259                                                 {
1260                                                         Trace.TraceInformation("録音のCancelコマンドをDTXMania本体が受信しました。");
1261                                                         //Microsoft.VisualBasic.Interaction.AppActivate("メモ帳");
1262                                                         //SendKeys.Send("{ESC}");
1263                                                         //SendKeys.SendWait("%{F4}");
1264                                                         //Application.Exit();
1265                                                         DTX.t全チップの再生停止();
1266                                                         DTX.On非活性化();
1267                                                         r現在のステージ.On非活性化();
1268
1269                                                         //Environment.ExitCode = 10010;         // この組み合わせではダメ、返り値が反映されない
1270                                                         //base.Window.Close();
1271                                                         Environment.Exit(10010);                        // このやり方ならばOK
1272                                                 }
1273                                         }
1274                                 }
1275                         }
1276                         #endregion
1277
1278                         this.Device.BeginScene();
1279                         this.Device.Clear(ClearFlags.ZBuffer | ClearFlags.Target, SharpDX.Color.Black, 1f, 0);
1280
1281                         if (r現在のステージ != null)
1282                         {
1283                                 this.n進行描画の戻り値 = (r現在のステージ != null) ? r現在のステージ.On進行描画() : 0;
1284
1285                                 #region [ プラグインの進行描画 ]
1286                                 //---------------------
1287                                 foreach (STPlugin sp in this.listプラグイン)
1288                                 {
1289                                         Directory.SetCurrentDirectory(sp.strプラグインフォルダ);
1290
1291                                         if (CDTXMania.Instance.act現在入力を占有中のプラグイン == null || CDTXMania.Instance.act現在入力を占有中のプラグイン == sp.plugin)
1292                                                 sp.plugin.On進行描画(CDTXMania.Instance.Pad, CDTXMania.Instance.Input管理.Keyboard);
1293                                         else
1294                                                 sp.plugin.On進行描画(null, null);
1295
1296                                         Directory.SetCurrentDirectory(CDTXMania.Instance.strEXEのあるフォルダ);
1297                                 }
1298                                 //---------------------
1299                                 #endregion
1300
1301                                 #region [ DTX2WAVモード時、ステージが変わるたびに、そのことをDTX2WAVアプリ側に通知する ]
1302                                 if (DTX2WAVmode.Enabled && r現在のステージ != r1フレーム前のステージ)
1303                                 {
1304                                         r1フレーム前のステージ = r現在のステージ;
1305                                         //Trace.TraceInformation("Stage変更 to : " + r現在のステージ.eステージID.ToString());
1306                                         switch (r現在のステージ.eステージID)
1307                                         {
1308                                                 case CStage.Eステージ.曲読み込み:
1309                                                         DTX2WAVmode.SendMessage2DTX2WAV("LOAD");
1310                                                         break;
1311                                                 case CStage.Eステージ.演奏:
1312                                                         DTX2WAVmode.SendMessage2DTX2WAV("PLAY");
1313                                                         break;
1314                                                 default:
1315                                                         break;
1316                                         }
1317                                 }
1318                                 #endregion
1319
1320                                 CScoreIni scoreIni = null;
1321
1322                                 if (Control.IsKeyLocked(Keys.CapsLock))             // #30925 2013.3.11 yyagi; capslock=ON時は、EnumSongsしないようにして、起動負荷とASIOの音切れの関係を確認する
1323                                 {
1324                                         // → songs.db等の書き込み時だと音切れするっぽい
1325                                         actEnumSongs.On非活性化();
1326                                         EnumSongs.SongListEnumCompletelyDone();
1327                                         CDTXMania.Instance.stage選曲.bIsEnumeratingSongs = false;
1328                                 }
1329                                 #region [ 曲検索スレッドの起動/終了 ここに"Enumerating Songs..."表示を集約 ]
1330                                 if (!CDTXMania.Instance.bコンパクトモード)
1331                                 {
1332                                         actEnumSongs.On進行描画();                          // "Enumerating Songs..."アイコンの描画
1333                                 }
1334                                 switch (r現在のステージ.eステージID)
1335                                 {
1336                                         case CStage.Eステージ.タイトル:
1337                                         case CStage.Eステージ.コンフィグ:
1338                                         case CStage.Eステージ.選曲:
1339                                         case CStage.Eステージ.曲読み込み:
1340                                                 if (EnumSongs != null)
1341                                                 {
1342                             #region [ (特定条件時) 曲検索スレッドの起動・開始 ]
1343                                                         if (r現在のステージ.eステージID == CStage.Eステージ.タイトル &&
1344                                                                          r直前のステージ.eステージID == CStage.Eステージ.起動 &&
1345                                                                          this.n進行描画の戻り値 == (int)CStageタイトル.E戻り値.継続 &&
1346                                                                          !EnumSongs.IsSongListEnumStarted)
1347                                                         {
1348                                                                 actEnumSongs.On活性化();
1349                                                                 CDTXMania.Instance.stage選曲.bIsEnumeratingSongs = true;
1350                                                                 EnumSongs.Init(CDTXMania.Instance.Songs管理.listSongsDB, CDTXMania.Instance.Songs管理.nSongsDBから取得できたスコア数); // songs.db情報と、取得した曲数を、新インスタンスにも与える
1351                                                                 EnumSongs.StartEnumFromDisk();      // 曲検索スレッドの起動・開始
1352                                                                 if (CDTXMania.Instance.Songs管理.nSongsDBから取得できたスコア数 == 0)    // もし初回起動なら、検索スレッドのプライオリティをLowestでなくNormalにする
1353                                                                 {
1354                                                                         EnumSongs.ChangeEnumeratePriority(ThreadPriority.Normal);
1355                                                                 }
1356                                                         }
1357                                                         #endregion
1358
1359                                                         #region [ 曲検索の中断と再開 ]
1360                                                         if (r現在のステージ.eステージID == CStage.Eステージ.選曲 && !EnumSongs.IsSongListEnumCompletelyDone)
1361                                                         {
1362                                                                 switch (this.n進行描画の戻り値)
1363                                                                 {
1364                                                                         case 0:     // 何もない
1365                                                                                                                         //if ( CDTXMania.Instance.stage選曲.bIsEnumeratingSongs )
1366                                                                                 if (!CDTXMania.Instance.stage選曲.bIsPlayingPremovie)
1367                                                                                 {
1368                                                                                         EnumSongs.Resume();                     // #27060 2012.2.6 yyagi 中止していたバックグランド曲検索を再開
1369                                                                                         EnumSongs.IsSlowdown = false;
1370                                                                                 }
1371                                                                                 else
1372                                                                                 {
1373                                                                                         // EnumSongs.Suspend();                                 // #27060 2012.3.2 yyagi #PREMOVIE再生中は曲検索を低速化
1374                                                                                         EnumSongs.IsSlowdown = true;
1375                                                                                 }
1376                                                                                 actEnumSongs.On活性化();
1377                                                                                 break;
1378
1379                                                                         case 2:     // 曲決定
1380                                                                                 EnumSongs.Suspend();                        // #27060 バックグラウンドの曲検索を一時停止
1381                                                                                 actEnumSongs.On非活性化();
1382                                                                                 break;
1383                                                                 }
1384                                                         }
1385                                                         #endregion
1386
1387                                                         #region [ 曲探索中断待ち待機 ]
1388                                                         if (r現在のステージ.eステージID == CStage.Eステージ.曲読み込み && !EnumSongs.IsSongListEnumCompletelyDone &&
1389                                                                         EnumSongs.thDTXFileEnumerate != null)                           // #28700 2012.6.12 yyagi; at Compact mode, enumerating thread does not exist.
1390                                                         {
1391                                                                 EnumSongs.WaitUntilSuspended();                                 // 念のため、曲検索が一時中断されるまで待機
1392                                                         }
1393                                                         #endregion
1394
1395                                                         #region [ 曲検索が完了したら、実際の曲リストに反映する ]
1396                                                         // CStage選曲.On活性化() に回した方がいいかな?
1397                                                         if (EnumSongs.IsSongListEnumerated)
1398                                                         {
1399                                                                 actEnumSongs.On非活性化();
1400                                                                 CDTXMania.Instance.stage選曲.bIsEnumeratingSongs = false;
1401
1402                                                                 bool bRemakeSongTitleBar = (r現在のステージ.eステージID == CStage.Eステージ.選曲) ? true : false;
1403                                                                 CDTXMania.Instance.stage選曲.Refresh(EnumSongs.Songs管理, bRemakeSongTitleBar);
1404                                                                 EnumSongs.SongListEnumCompletelyDone();
1405                                                         }
1406                                                         #endregion
1407                                                 }
1408                                                 break;
1409                                 }
1410                                 #endregion
1411
1412                                 switch (r現在のステージ.eステージID)
1413                                 {
1414                                         case CStage.Eステージ.何もしない:
1415                                                 break;
1416
1417                                         case CStage.Eステージ.起動:
1418                                                 #region [ *** ]
1419                                                 //-----------------------------
1420                                                 if (this.n進行描画の戻り値 != 0)
1421                                                 {
1422                                                         if (!bコンパクトモード)
1423                                                         {
1424                                                                 r現在のステージ.On非活性化();
1425                                                                 Trace.TraceInformation("----------------------");
1426                                                                 Trace.TraceInformation("■ タイトル");
1427                                                                 stageタイトル.On活性化();
1428                                                                 r直前のステージ = r現在のステージ;
1429                                                                 r現在のステージ = stageタイトル;
1430                                                         }
1431                                                         else
1432                                                         {
1433                                                                 r現在のステージ.On非活性化();
1434                                                                 Trace.TraceInformation("----------------------");
1435                                                                 Trace.TraceInformation("■ 曲読み込み");
1436                                                                 stage曲読み込み.On活性化();
1437                                                                 r直前のステージ = r現在のステージ;
1438                                                                 r現在のステージ = stage曲読み込み;
1439
1440                                                         }
1441                                                         foreach (STPlugin pg in this.listプラグイン)
1442                                                         {
1443                                                                 Directory.SetCurrentDirectory(pg.strプラグインフォルダ);
1444                                                                 pg.plugin.Onステージ変更();
1445                                                                 Directory.SetCurrentDirectory(CDTXMania.Instance.strEXEのあるフォルダ);
1446                                                         }
1447
1448                                                         this.tガベージコレクションを実行する();
1449                                                 }
1450                                                 //-----------------------------
1451                                                 #endregion
1452                                                 break;
1453
1454                                         case CStage.Eステージ.タイトル:
1455                         #region [ *** ]
1456                         //-----------------------------
1457                         switch (this.n進行描画の戻り値)
1458                                                 {
1459                                                         case (int)CStageタイトル.E戻り値.GAMESTART:
1460                                                                 #region [ 選曲処理へ ]
1461                                                                 //-----------------------------
1462                                                                 r現在のステージ.On非活性化();
1463                                                                 Trace.TraceInformation("----------------------");
1464                                                                 Trace.TraceInformation("■ 選曲");
1465                                                                 stage選曲.On活性化();
1466                                                                 r直前のステージ = r現在のステージ;
1467                                                                 r現在のステージ = stage選曲;
1468                                                                 //-----------------------------
1469                                                                 #endregion
1470                                                                 break;
1471
1472                                                         #region [ OPTION: 廃止済 ]
1473                                                         //                                                      case 2:                                                                 // #24525 OPTIONとCONFIGの統合に伴い、OPTIONは廃止
1474                                                         //                                                              #region [ *** ]
1475                                                         //                                                              //-----------------------------
1476                                                         //                                                              r現在のステージ.On非活性化();
1477                                                         //                                                              Trace.TraceInformation( "----------------------" );
1478                                                         //                                                              Trace.TraceInformation( "■ オプション" );
1479                                                         //                                                              stageオプション.On活性化();
1480                                                         //                                                              r直前のステージ = r現在のステージ;
1481                                                         //                                                              r現在のステージ = stageオプション;
1482                                                         //                                                              //-----------------------------
1483                                                         //                                                              #endregion
1484                                                         //                                                              break;
1485                                                         #endregion
1486
1487                                                         case (int)CStageタイトル.E戻り値.CONFIG:
1488                                                                 #region [ *** ]
1489                                                                 //-----------------------------
1490                                                                 r現在のステージ.On非活性化();
1491                                                                 Trace.TraceInformation("----------------------");
1492                                                                 Trace.TraceInformation("■ コンフィグ");
1493                                                                 stageコンフィグ.On活性化();
1494                                                                 r直前のステージ = r現在のステージ;
1495                                                                 r現在のステージ = stageコンフィグ;
1496                                                                 //-----------------------------
1497                                                                 #endregion
1498                                                                 break;
1499
1500                                                         case (int)CStageタイトル.E戻り値.EXIT:
1501                                                                 #region [ *** ]
1502                                                                 //-----------------------------
1503                                                                 r現在のステージ.On非活性化();
1504                                                                 Trace.TraceInformation("----------------------");
1505                                                                 Trace.TraceInformation("■ 終了");
1506                                                                 stage終了.On活性化();
1507                                                                 r直前のステージ = r現在のステージ;
1508                                                                 r現在のステージ = stage終了;
1509                                                                 //-----------------------------
1510                                                                 #endregion
1511                                                                 break;
1512                                                 }
1513
1514                                                 foreach (STPlugin pg in this.listプラグイン)
1515                                                 {
1516                                                         Directory.SetCurrentDirectory(pg.strプラグインフォルダ);
1517                                                         pg.plugin.Onステージ変更();
1518                                                         Directory.SetCurrentDirectory(CDTXMania.Instance.strEXEのあるフォルダ);
1519                                                 }
1520
1521                                                 //this.tガベージコレクションを実行する();                // #31980 2013.9.3 yyagi タイトル画面でだけ、毎フレームGCを実行して重くなっていた問題の修正
1522                                                 //-----------------------------
1523                                                 #endregion
1524                                                 break;
1525
1526                                         case CStage.Eステージ.コンフィグ:
1527                                                 #region [ *** ]
1528                                                 //-----------------------------
1529                                                 if (this.n進行描画の戻り値 != 0)
1530                                                 {
1531                                                         switch (r直前のステージ.eステージID)
1532                                                         {
1533                                                                 case CStage.Eステージ.タイトル:
1534                                                                         #region [ *** ]
1535                                                                         //-----------------------------
1536                                                                         r現在のステージ.On非活性化();
1537                                                                         Trace.TraceInformation("----------------------");
1538                                                                         Trace.TraceInformation("■ タイトル");
1539                                                                         stageタイトル.On活性化();
1540                                                                         r直前のステージ = r現在のステージ;
1541                                                                         r現在のステージ = stageタイトル;
1542
1543                                                                         foreach (STPlugin pg in this.listプラグイン)
1544                                                                         {
1545                                                                                 Directory.SetCurrentDirectory(pg.strプラグインフォルダ);
1546                                                                                 pg.plugin.Onステージ変更();
1547                                                                                 Directory.SetCurrentDirectory(CDTXMania.Instance.strEXEのあるフォルダ);
1548                                                                         }
1549
1550                                                                         this.tガベージコレクションを実行する();
1551                                                                         break;
1552                                                                 //-----------------------------
1553                                                                 #endregion
1554
1555                                                                 case CStage.Eステージ.選曲:
1556                                                                         #region [ *** ]
1557                                                                         //-----------------------------
1558                                                                         r現在のステージ.On非活性化();
1559                                                                         Trace.TraceInformation("----------------------");
1560                                                                         Trace.TraceInformation("■ 選曲");
1561                                                                         stage選曲.On活性化();
1562                                                                         r直前のステージ = r現在のステージ;
1563                                                                         r現在のステージ = stage選曲;
1564
1565                                                                         foreach (STPlugin pg in this.listプラグイン)
1566                                                                         {
1567                                                                                 Directory.SetCurrentDirectory(pg.strプラグインフォルダ);
1568                                                                                 pg.plugin.Onステージ変更();
1569                                                                                 Directory.SetCurrentDirectory(CDTXMania.Instance.strEXEのあるフォルダ);
1570                                                                         }
1571
1572                                                                         this.tガベージコレクションを実行する();
1573                                                                         break;
1574                                                                         //-----------------------------
1575                                                                         #endregion
1576                                                         }
1577                                                 }
1578                                                 //-----------------------------
1579                                                 #endregion
1580                                                 break;
1581
1582                                         case CStage.Eステージ.選曲:
1583                                                 #region [ *** ]
1584                                                 //-----------------------------
1585                                                 switch (this.n進行描画の戻り値)
1586                                                 {
1587                                                         case (int)CStage選曲.E戻り値.タイトルに戻る:
1588                                                                 #region [ *** ]
1589                                                                 //-----------------------------
1590                                                                 r現在のステージ.On非活性化();
1591                                                                 Trace.TraceInformation("----------------------");
1592                                                                 Trace.TraceInformation("■ タイトル");
1593                                                                 stageタイトル.On活性化();
1594                                                                 r直前のステージ = r現在のステージ;
1595                                                                 r現在のステージ = stageタイトル;
1596
1597                                                                 foreach (STPlugin pg in this.listプラグイン)
1598                                                                 {
1599                                                                         Directory.SetCurrentDirectory(pg.strプラグインフォルダ);
1600                                                                         pg.plugin.Onステージ変更();
1601                                                                         Directory.SetCurrentDirectory(CDTXMania.Instance.strEXEのあるフォルダ);
1602                                                                 }
1603
1604                                                                 this.tガベージコレクションを実行する();
1605                                                                 break;
1606                                                         //-----------------------------
1607                                                         #endregion
1608
1609                                                         case (int)CStage選曲.E戻り値.選曲した:
1610                                                                 #region [ *** ]
1611                                                                 //-----------------------------
1612                                                                 r現在のステージ.On非活性化();
1613                                                                 Trace.TraceInformation("----------------------");
1614                                                                 Trace.TraceInformation("■ 曲読み込み");
1615                                                                 stage曲読み込み.On活性化();
1616                                                                 r直前のステージ = r現在のステージ;
1617                                                                 r現在のステージ = stage曲読み込み;
1618
1619                                                                 foreach (STPlugin pg in this.listプラグイン)
1620                                                                 {
1621                                                                         Directory.SetCurrentDirectory(pg.strプラグインフォルダ);
1622                                                                         pg.plugin.Onステージ変更();
1623                                                                         Directory.SetCurrentDirectory(CDTXMania.Instance.strEXEのあるフォルダ);
1624                                                                 }
1625
1626                                                                 this.tガベージコレクションを実行する();
1627                                                                 break;
1628                                                         //-----------------------------
1629                                                         #endregion
1630
1631                                                         case (int)CStage選曲.E戻り値.コンフィグ呼び出し:
1632                                                                 #region [ *** ]
1633                                                                 //-----------------------------
1634                                                                 r現在のステージ.On非活性化();
1635                                                                 Trace.TraceInformation("----------------------");
1636                                                                 Trace.TraceInformation("■ コンフィグ");
1637                                                                 stageコンフィグ.On活性化();
1638                                                                 r直前のステージ = r現在のステージ;
1639                                                                 r現在のステージ = stageコンフィグ;
1640
1641                                                                 foreach (STPlugin pg in this.listプラグイン)
1642                                                                 {
1643                                                                         Directory.SetCurrentDirectory(pg.strプラグインフォルダ);
1644                                                                         pg.plugin.Onステージ変更();
1645                                                                         Directory.SetCurrentDirectory(CDTXMania.Instance.strEXEのあるフォルダ);
1646                                                                 }
1647
1648                                                                 this.tガベージコレクションを実行する();
1649                                                                 break;
1650                                                         //-----------------------------
1651                                                         #endregion
1652
1653                                                         case (int)CStage選曲.E戻り値.スキン変更:
1654
1655                                                                 #region [ *** ]
1656                                                                 //-----------------------------
1657                                                                 r現在のステージ.On非活性化();
1658                                                                 Trace.TraceInformation("----------------------");
1659                                                                 Trace.TraceInformation("■ スキン切り替え");
1660                                                                 stageChangeSkin.On活性化();
1661                                                                 r直前のステージ = r現在のステージ;
1662                                                                 r現在のステージ = stageChangeSkin;
1663                                                                 break;
1664                                                                 //-----------------------------
1665                                                                 #endregion
1666                                                 }
1667                                                 //-----------------------------
1668                                                 #endregion
1669                                                 break;
1670
1671                                         case CStage.Eステージ.曲読み込み:
1672                                                 #region [ *** ]
1673                                                 //-----------------------------
1674                                                 DTXVmode.Refreshed = false;     // 曲のリロード中に発生した再リロードは、無視する。
1675                                                 if (this.n進行描画の戻り値 != 0)
1676                                                 {
1677                                                         CDTXMania.Instance.Pad.st検知したデバイス.Clear();  // 入力デバイスフラグクリア(2010.9.11)
1678                                                         r現在のステージ.On非活性化();
1679                                                         #region [ ESC押下時は、曲の読み込みを中止して選曲画面に戻る ]
1680                                                         if (this.n進行描画の戻り値 == (int)E曲読込画面の戻り値.読込中止)
1681                                                         {
1682                                                                 //DTX.t全チップの再生停止();
1683                                                                 DTX.On非活性化();
1684                                                                 Trace.TraceInformation("曲の読み込みを中止しました。");
1685                                                                 this.tガベージコレクションを実行する();
1686                                                                 Trace.TraceInformation("----------------------");
1687                                                                 Trace.TraceInformation("■ 選曲");
1688                                                                 stage選曲.On活性化();
1689                                                                 r直前のステージ = r現在のステージ;
1690                                                                 r現在のステージ = stage選曲;
1691                                                                 foreach (STPlugin pg in this.listプラグイン)
1692                                                                 {
1693                                                                         Directory.SetCurrentDirectory(pg.strプラグインフォルダ);
1694                                                                         pg.plugin.Onステージ変更();
1695                                                                         Directory.SetCurrentDirectory(CDTXMania.Instance.strEXEのあるフォルダ);
1696                                                                 }
1697                                                                 break;
1698                                                         }
1699                                                         #endregion
1700
1701                                                         Trace.TraceInformation("----------------------");
1702                                                         Trace.TraceInformation("■ 演奏(ドラム画面)");
1703                                                         r直前のステージ = r現在のステージ;
1704                                                         r現在のステージ = stage演奏画面;
1705
1706                                                         foreach (STPlugin pg in this.listプラグイン)
1707                                                         {
1708                                                                 Directory.SetCurrentDirectory(pg.strプラグインフォルダ);
1709                                                                 pg.plugin.Onステージ変更();
1710                                                                 Directory.SetCurrentDirectory(CDTXMania.Instance.strEXEのあるフォルダ);
1711                                                         }
1712
1713                                                         this.tガベージコレクションを実行する();
1714                                                 }
1715                                                 //-----------------------------
1716                                                 #endregion
1717                                                 break;
1718
1719                                         case CStage.Eステージ.演奏:
1720                                                 #region [ *** ]
1721                                                 //-----------------------------
1722                                                 //long n1 = FDK.CSound管理.rc演奏用タイマ.nシステム時刻ms;
1723                                                 //long n2 = FDK.CSound管理.SoundDevice.n経過時間ms;
1724                                                 //long n3 = FDK.CSound管理.SoundDevice.tmシステムタイマ.nシステム時刻ms;
1725                                                 //long n4 = FDK.CSound管理.rc演奏用タイマ.n現在時刻;
1726                                                 //long n5 = FDK.CSound管理.SoundDevice.n経過時間を更新したシステム時刻ms;
1727
1728                                                 //swlist1.Add( Convert.ToInt32(n1) );
1729                                                 //swlist2.Add( Convert.ToInt32(n2) );
1730                                                 //swlist3.Add( Convert.ToInt32( n3 ) );
1731                                                 //swlist4.Add( Convert.ToInt32( n4 ) );
1732                                                 //swlist5.Add( Convert.ToInt32( n5 ) );
1733
1734                                                 #region [ DTXVモード中にDTXCreatorから指示を受けた場合の処理 ]
1735                                                 if (DTXVmode.Enabled && DTXVmode.Refreshed)
1736                                                 {
1737                                                         DTXVmode.Refreshed = false;
1738
1739                                                         if (DTXVmode.Command == CDTXVmode.ECommand.Stop)
1740                                                         {
1741                                                                 CDTXMania.Instance.stage演奏画面.t停止();
1742
1743                                                                 if (previewSound != null)
1744                                                                 {
1745                                                                         this.previewSound.tサウンドを停止する();
1746                                                                         this.previewSound.Dispose();
1747                                                                         this.previewSound = null;
1748                                                                 }
1749                                                                 //{
1750                                                                 //    int lastd = 0;
1751                                                                 //    int f = 0;
1752                                                                 //    for ( int i = 0; i < swlist1.Count; i++ )
1753                                                                 //    {
1754                                                                 //        int d1 = swlist1[ i ];
1755                                                                 //        int d2 = swlist2[ i ];
1756                                                                 //        int d3 = swlist3[ i ];
1757                                                                 //        int d4 = swlist4[ i ];
1758                                                                 //        int d5 = swlist5[ i ];
1759
1760                                                                 //        int dif = d1 - lastd;
1761                                                                 //        string s = "";
1762                                                                 //        if ( 16 <= dif && dif <= 17 )
1763                                                                 //        {
1764                                                                 //        }
1765                                                                 //        else
1766                                                                 //        {
1767                                                                 //            s = "★";
1768                                                                 //        }
1769                                                                 //        Trace.TraceInformation( "frame {0:D4}: {1:D3} ( {2:D3}, {3:D3} - {7:D3}, {4:D3} ) {5}, n現在時刻={6}", f, dif, d1, d2, d3, s, d4, d5 );
1770                                                                 //        lastd = d1;
1771                                                                 //        f++;
1772                                                                 //    }
1773                                                                 //    swlist1.Clear();
1774                                                                 //    swlist2.Clear();
1775                                                                 //    swlist3.Clear();
1776                                                                 //    swlist4.Clear();
1777                                                                 //    swlist5.Clear();
1778
1779                                                                 //}
1780                                                         }
1781                                                         else if (DTXVmode.Command == CDTXVmode.ECommand.Play)
1782                                                         {
1783                                                                 if (DTXVmode.NeedReload)
1784                                                                 {
1785                                                                         CDTXMania.Instance.stage演奏画面.t再読込();
1786                                                                         if (DTXVmode.GRmode)
1787                                                                         {
1788                                                                                 CDTXMania.Instance.ConfigIni.eActiveInst.Value = EActiveInstrument.GBOnly;
1789                                                                         }
1790                                                                         else
1791                                                                         {
1792                                                                                 CDTXMania.Instance.ConfigIni.eActiveInst.Value = EActiveInstrument.Both;
1793                                                                         }
1794                                                                         CDTXMania.Instance.ConfigIni.bTimeStretch.Value = DTXVmode.TimeStretch;
1795                                                                         CSound管理.bIsTimeStretch = DTXVmode.TimeStretch;
1796                                                                         if (CDTXMania.Instance.ConfigIni.bVSyncWait != DTXVmode.VSyncWait)
1797                                                                         {
1798                                                                                 CDTXMania.Instance.ConfigIni.bVSyncWait.Value = DTXVmode.VSyncWait;
1799                                                                                 CDTXMania.Instance.b次のタイミングで垂直帰線同期切り替えを行う = true;
1800                                                                         }
1801                                                                 }
1802                                                                 else
1803                                                                 {
1804                                                                         CDTXMania.Instance.stage演奏画面.t演奏位置の変更(CDTXMania.Instance.DTXVmode.nStartBar);
1805                                                                 }
1806                                                         }
1807                                                 }
1808                                                 #endregion
1809
1810                                                 switch (this.n進行描画の戻り値)
1811                                                 {
1812                                                         case (int)E演奏画面の戻り値.再読込_再演奏:
1813                                                                 #region [ DTXファイルを再読み込みして、再演奏 ]
1814                                                                 DTX.t全チップの再生停止();
1815                                                                 DTX.On非活性化();
1816                                                                 r現在のステージ.On非活性化();
1817                                                                 stage曲読み込み.On活性化();
1818                                                                 r直前のステージ = r現在のステージ;
1819                                                                 r現在のステージ = stage曲読み込み;
1820                                                                 this.tガベージコレクションを実行する();
1821                                                                 break;
1822                                                         #endregion
1823
1824                                                         //case (int) E演奏画面の戻り値.再演奏:
1825                                                         #region [ 再読み込み無しで、再演奏 ]
1826                                                         #endregion
1827                                                         //      break;
1828
1829                                                         case (int)E演奏画面の戻り値.継続:
1830                                                                 break;
1831
1832                                                         case (int)E演奏画面の戻り値.演奏中断:
1833                                                                 #region [ 演奏キャンセル ]
1834                                                                 //-----------------------------
1835                                                                 scoreIni = this.tScoreIniへBGMAdjustとHistoryとPlayCountを更新("Play canceled");
1836                                                                 if (CDTXMania.Instance.ConfigIni.bIsSwappedGuitarBass)      // #35417 2015.8.18 yyagi Gt/Bsを入れ替えていたなら、演奏設定を元に戻す
1837                                                                 {
1838                                                                         //CDTXMania.Instance.DTX.SwapGuitarBassInfos();                                         // 譜面情報も元に戻す (現在は再演奏機能なしのため、元に戻す必要はない)
1839                                                                 }
1840
1841                                                                 //int lastd = 0;
1842                                                                 //int f = 0;
1843                                                                 //for (int i = 0; i < swlist1.Count; i++)
1844                                                                 //{
1845                                                                 //    int d1 = swlist1[ i ];
1846                                                                 //    int d2 = swlist2[ i ];
1847                                                                 //    int d3 = swlist3[ i ];
1848                                                                 //    int d4 = swlist4[ i ];
1849
1850                                                                 //    int dif = d1 - lastd;
1851                                                                 //    string s = "";
1852                                                                 //    if ( 16 <= dif && dif <= 17 )
1853                                                                 //    {
1854                                                                 //    }
1855                                                                 //    else
1856                                                                 //    {
1857                                                                 //        s = "★";
1858                                                                 //    }
1859                                                                 //    Trace.TraceInformation( "frame {0:D4}: {1:D3} ( {2:D3}, {3:D3}, {4:D3} ) {5}, n現在時刻={6}", f, dif, d1, d2, d3, s, d4 );
1860                                                                 //    lastd = d1;
1861                                                                 //    f++;
1862                                                                 //}
1863                                                                 //swlist1.Clear();
1864                                                                 //swlist2.Clear();
1865                                                                 //swlist3.Clear();
1866                                                                 //swlist4.Clear();
1867
1868                                                                 #region [ プラグイン On演奏キャンセル() の呼び出し ]
1869                                                                 //---------------------
1870                                                                 foreach (STPlugin pg in this.listプラグイン)
1871                                                                 {
1872                                                                         Directory.SetCurrentDirectory(pg.strプラグインフォルダ);
1873                                                                         pg.plugin.On演奏キャンセル(scoreIni);
1874                                                                         Directory.SetCurrentDirectory(CDTXMania.Instance.strEXEのあるフォルダ);
1875                                                                 }
1876                                                                 //---------------------
1877                                                                 #endregion
1878
1879                                                                 DTX.t全チップの再生停止();
1880                                                                 DTX.On非活性化();
1881                                                                 r現在のステージ.On非活性化();
1882                                                                 if (DTX2WAVmode.Enabled)
1883                                                                 {
1884                                                                         Environment.Exit(0);
1885                                                                 }
1886                                                                 if (bコンパクトモード)
1887                                                                 {
1888                                                                         base.Window.Close();
1889                                                                 }
1890                                                                 else
1891                                                                 {
1892                                                                         Trace.TraceInformation("----------------------");
1893                                                                         Trace.TraceInformation("■ 選曲");
1894                                                                         stage選曲.On活性化();
1895                                                                         r直前のステージ = r現在のステージ;
1896                                                                         r現在のステージ = stage選曲;
1897
1898                                                                         #region [ プラグイン Onステージ変更() の呼び出し ]
1899                                                                         //---------------------
1900                                                                         foreach (STPlugin pg in this.listプラグイン)
1901                                                                         {
1902                                                                                 Directory.SetCurrentDirectory(pg.strプラグインフォルダ);
1903                                                                                 pg.plugin.Onステージ変更();
1904                                                                                 Directory.SetCurrentDirectory(CDTXMania.Instance.strEXEのあるフォルダ);
1905                                                                         }
1906                                                                         //---------------------
1907                                                                         #endregion
1908
1909                                                                         this.tガベージコレクションを実行する();
1910                                                                 }
1911                                                                 break;
1912                                                         //-----------------------------
1913                                                         #endregion
1914
1915                                                         case (int)E演奏画面の戻り値.ステージ失敗:
1916                                                                 #region [ 演奏失敗(StageFailed) ]
1917                                                                 //-----------------------------
1918                                                                 scoreIni = this.tScoreIniへBGMAdjustとHistoryとPlayCountを更新("Stage failed");
1919
1920                                                                 #region [ プラグイン On演奏失敗() の呼び出し ]
1921                                                                 //---------------------
1922                                                                 foreach (STPlugin pg in this.listプラグイン)
1923                                                                 {
1924                                                                         Directory.SetCurrentDirectory(pg.strプラグインフォルダ);
1925                                                                         pg.plugin.On演奏失敗(scoreIni);
1926                                                                         Directory.SetCurrentDirectory(CDTXMania.Instance.strEXEのあるフォルダ);
1927                                                                 }
1928                                                                 //---------------------
1929                                                                 #endregion
1930
1931                                                                 DTX.t全チップの再生停止();
1932                                                                 DTX.On非活性化();
1933                                                                 r現在のステージ.On非活性化();
1934                                                                 if (bコンパクトモード)
1935                                                                 {
1936                                                                         base.Window.Close();
1937                                                                 }
1938                                                                 else
1939                                                                 {
1940                                                                         Trace.TraceInformation("----------------------");
1941                                                                         Trace.TraceInformation("■ 選曲");
1942                                                                         stage選曲.On活性化();
1943                                                                         r直前のステージ = r現在のステージ;
1944                                                                         r現在のステージ = stage選曲;
1945
1946                                                                         #region [ プラグイン Onステージ変更() の呼び出し ]
1947                                                                         //---------------------
1948                                                                         foreach (STPlugin pg in this.listプラグイン)
1949                                                                         {
1950                                                                                 Directory.SetCurrentDirectory(pg.strプラグインフォルダ);
1951                                                                                 pg.plugin.Onステージ変更();
1952                                                                                 Directory.SetCurrentDirectory(CDTXMania.Instance.strEXEのあるフォルダ);
1953                                                                         }
1954                                                                         //---------------------
1955                                                                         #endregion
1956
1957                                                                         this.tガベージコレクションを実行する();
1958                                                                 }
1959                                                                 break;
1960                                                         //-----------------------------
1961                                                         #endregion
1962
1963                                                         case (int)E演奏画面の戻り値.ステージクリア:
1964                                                                 #region [ 演奏クリア ]
1965                                                                 //-----------------------------
1966                                                                 STDGBSValue<CScoreIni.C演奏記録> record;
1967                                                                 record = stage演奏画面.Record;
1968
1969                                                                 double playskill = 0.0;
1970
1971                                                                 for (EPart inst = EPart.Drums; inst <= EPart.Bass; ++inst)
1972                                                                 {
1973                                                                         if (!record[inst].b全AUTOである && record[inst].n全チップ数 > 0)
1974                                                                         {
1975                                                                                 playskill = record[inst].db演奏型スキル値;
1976                                                                         }
1977                                                                 }
1978
1979                                                                 string str = "Cleared";
1980                                                                 switch (CScoreIni.t総合ランク値を計算して返す(record))
1981                                                                 {
1982                                                                         case CScoreIni.ERANK.SS:
1983                                                                                 str = string.Format("Cleared (SS: {0:F2})", playskill);
1984                                                                                 break;
1985
1986                                                                         case CScoreIni.ERANK.S:
1987                                                                                 str = string.Format("Cleared (S: {0:F2})", playskill);
1988                                                                                 break;
1989
1990                                                                         case CScoreIni.ERANK.A:
1991                                                                                 str = string.Format("Cleared (A: {0:F2})", playskill);
1992                                                                                 break;
1993
1994                                                                         case CScoreIni.ERANK.B:
1995                                                                                 str = string.Format("Cleared (B: {0:F2})", playskill);
1996                                                                                 break;
1997
1998                                                                         case CScoreIni.ERANK.C:
1999                                                                                 str = string.Format("Cleared (C: {0:F2})", playskill);
2000                                                                                 break;
2001
2002                                                                         case CScoreIni.ERANK.D:
2003                                                                                 str = string.Format("Cleared (D: {0:F2})", playskill);
2004                                                                                 break;
2005
2006                                                                         case CScoreIni.ERANK.E:
2007                                                                                 str = string.Format("Cleared (E: {0:F2})", playskill);
2008                                                                                 break;
2009
2010                                                                         case CScoreIni.ERANK.UNKNOWN:   // #23534 2010.10.28 yyagi add: 演奏チップが0個のとき
2011                                                                                 str = "Cleared (No chips)";
2012                                                                                 break;
2013                                                                 }
2014
2015                                                                 scoreIni = this.tScoreIniへBGMAdjustとHistoryとPlayCountを更新(str);
2016
2017                                                                 #region [ プラグイン On演奏クリア() の呼び出し ]
2018                                                                 //---------------------
2019                                                                 foreach (STPlugin pg in this.listプラグイン)
2020                                                                 {
2021                                                                         Directory.SetCurrentDirectory(pg.strプラグインフォルダ);
2022                                                                         pg.plugin.On演奏クリア(scoreIni);
2023                                                                         Directory.SetCurrentDirectory(CDTXMania.Instance.strEXEのあるフォルダ);
2024                                                                 }
2025                                                                 //---------------------
2026                                                                 #endregion
2027
2028                                                                 r現在のステージ.On非活性化();
2029                                                                 Trace.TraceInformation("----------------------");
2030                                                                 Trace.TraceInformation("■ 結果");
2031                                                                 stage結果.st演奏記録 = record;
2032                                                                 stage結果.r空うちドラムチップ = stage演奏画面.GetNoChipDrums();
2033                                                                 stage結果.On活性化();
2034                                                                 r直前のステージ = r現在のステージ;
2035                                                                 r現在のステージ = stage結果;
2036
2037                                                                 #region [ プラグイン Onステージ変更() の呼び出し ]
2038                                                                 //---------------------
2039                                                                 foreach (STPlugin pg in this.listプラグイン)
2040                                                                 {
2041                                                                         Directory.SetCurrentDirectory(pg.strプラグインフォルダ);
2042                                                                         pg.plugin.Onステージ変更();
2043                                                                         Directory.SetCurrentDirectory(CDTXMania.Instance.strEXEのあるフォルダ);
2044                                                                 }
2045                                                                 //---------------------
2046                                                                 #endregion
2047
2048                                                                 break;
2049                                                                 //-----------------------------
2050                                                                 #endregion
2051                                                 }
2052                                                 //-----------------------------
2053                                                 #endregion
2054                                                 break;
2055
2056                                         case CStage.Eステージ.結果:
2057                                                 #region [ *** ]
2058                                                 //-----------------------------
2059                                                 if (this.n進行描画の戻り値 != 0)
2060                                                 {
2061                                                         // #35417 2015.08.30 chnmr0 changed : ステージクリア処理で入れ替えるため元に戻した
2062                                                         // #35417 2015.8.18 yyagi: AUTO系のフラグ入れ替えは削除可能!?。以後AUTOフラグに全くアクセスしておらず、意味がないため。
2063                                                         if (CDTXMania.Instance.ConfigIni.bIsSwappedGuitarBass)      // #24415 2011.2.27 yyagi Gt/Bsを入れ替えていたなら、Auto状態をリザルト画面終了後に元に戻す
2064                                                         {
2065                                                                 CDTXMania.Instance.ConfigIni.SwapGuitarBassInfos_AutoFlags();   // Auto入れ替え
2066                                                         }
2067
2068                                                         DTX.t全チップの再生一時停止();
2069                                                         DTX.On非活性化();
2070                                                         r現在のステージ.On非活性化();
2071                                                         if (!bコンパクトモード)
2072                                                         {
2073                                                                 Trace.TraceInformation("----------------------");
2074                                                                 Trace.TraceInformation("■ 選曲");
2075                                                                 stage選曲.On活性化();
2076                                                                 r直前のステージ = r現在のステージ;
2077                                                                 r現在のステージ = stage選曲;
2078
2079                                                                 foreach (STPlugin pg in this.listプラグイン)
2080                                                                 {
2081                                                                         Directory.SetCurrentDirectory(pg.strプラグインフォルダ);
2082                                                                         pg.plugin.Onステージ変更();
2083                                                                         Directory.SetCurrentDirectory(CDTXMania.Instance.strEXEのあるフォルダ);
2084                                                                 }
2085
2086                                                                 this.tガベージコレクションを実行する();
2087                                                         }
2088                                                         else
2089                                                         {
2090                                                                 base.Window.Close();
2091                                                         }
2092                                                 }
2093                                                 //-----------------------------
2094                                                 #endregion
2095                                                 break;
2096
2097                                         case CStage.Eステージ.ChangeSkin:
2098                                                 #region [ *** ]
2099                                                 //-----------------------------
2100                                                 if (this.n進行描画の戻り値 != 0)
2101                                                 {
2102                                                         r現在のステージ.On非活性化();
2103                                                         Trace.TraceInformation("----------------------");
2104                                                         Trace.TraceInformation("■ 選曲");
2105                                                         stage選曲.On活性化();
2106                                                         r直前のステージ = r現在のステージ;
2107                                                         r現在のステージ = stage選曲;
2108                                                         this.tガベージコレクションを実行する();
2109                                                 }
2110                                                 //-----------------------------
2111                                                 #endregion
2112                                                 break;
2113
2114                                         case CStage.Eステージ.終了:
2115                                                 #region [ *** ]
2116                                                 //-----------------------------
2117                                                 if (this.n進行描画の戻り値 != 0)
2118                                                 {
2119                                                         base.Exit();
2120                                                 }
2121                                                 //-----------------------------
2122                                                 #endregion
2123                                                 break;
2124                                 }
2125                         }
2126                         this.Device.EndScene();
2127                         // Present()は game.csのOnFrameEnd()に登録された、GraphicsDeviceManager.game_FrameEnd() 内で実行されるので不要
2128                         // (つまり、Present()は、Draw()完了後に実行される)
2129 #if !GPUFlushAfterPresent
2130                         actFlushGPU.On進行描画();       // Flush GPU        // EndScene()~Present()間 (つまりVSync前) でFlush実行
2131 #endif
2132                         if (Sound管理.CurrentSoundDeviceType != ESoundDeviceType.DirectSound)
2133                         {
2134                                 Sound管理.t再生中の処理をする();   // サウンドバッファの更新; 画面描画と同期させることで、スクロールをスムーズにする
2135                         }
2136
2137                         #region [ マウスカーソル消去制御 ]
2138                         if (cMouseHideControl != null) cMouseHideControl.tHideCursorIfNeed();
2139                         #endregion
2140                         #region [ 全画面・ウインドウ切り替え ]
2141                         if (this.b次のタイミングで全画面_ウィンドウ切り替えを行う)
2142                         {
2143                                 // ConfigIni.bFullScreen.Value = !ConfigIni.bFullScreen;
2144                                 Instance.t全画面_ウィンドウモード切り替え();
2145                                 this.b次のタイミングで全画面_ウィンドウ切り替えを行う = false;
2146                         }
2147                         #endregion
2148                         #region [ 垂直基線同期切り替え ]
2149                         if (this.b次のタイミングで垂直帰線同期切り替えを行う)
2150                         {
2151                                 bool bIsMaximized = this.Window.IsMaximized;                                            // #23510 2010.11.3 yyagi: to backup current window mode before changing VSyncWait
2152                                 currentClientSize = this.Window.ClientSize;                                             // #23510 2010.11.3 yyagi: to backup current window size before changing VSyncWait
2153                                 DeviceSettings currentSettings = Instance.GraphicsDeviceManager.CurrentSettings;
2154                                 currentSettings.EnableVSync = ConfigIni.bVSyncWait;
2155                                 Instance.GraphicsDeviceManager.ChangeDevice(currentSettings);
2156                                 this.b次のタイミングで垂直帰線同期切り替えを行う = false;
2157                                 base.Window.ClientSize = new Size(currentClientSize.Width, currentClientSize.Height);   // #23510 2010.11.3 yyagi: to resume window size after changing VSyncWait
2158                                 if (bIsMaximized)
2159                                 {
2160                                         this.Window.WindowState = FormWindowState.Maximized;                                // #23510 2010.11.3 yyagi: to resume window mode after changing VSyncWait
2161                                 }
2162                         }
2163                         #endregion
2164
2165                         GC.Collect( 0, GCCollectionMode.Optimized, false );             // Rel105で処理が重くなっていることに対する、暫定処置。
2166                                                                                                                                         // 重くなっている原因に対する適切な処置をして、処理が104程度に軽くなったら、
2167                                                                                                                                         // この暫定処置は削除します。
2168                 }
2169
2170                 /// <summary>
2171                 /// XML ファイルからオブジェクトを生成します。
2172                 /// </summary>
2173                 /// <param name="xmlfile">オブジェクトが記述される XML のパス。これは DataContract によってシリアライズされていなければなりません。</param>
2174                 /// <returns>生成したオブジェクト。正しく生成できなかった場合 null 。</returns>
2175                 public static object DeserializeXML(string xmlpath, Type t)
2176                 {
2177                         object ret = null;
2178                         try
2179                         {
2180                                 if (File.Exists(xmlpath))
2181                                 {
2182                                         using (XmlReader xr = XmlReader.Create(xmlpath))
2183                                         {
2184                                                 DataContractSerializer serializer = new DataContractSerializer(t);
2185                                                 ret = serializer.ReadObject(xr);
2186                                         }
2187                                 }
2188                         }
2189                         catch (Exception e)
2190                         {
2191                                 Trace.TraceWarning( e.Message );
2192                                 ret = null;
2193                         }
2194                         return ret;
2195                 }
2196
2197                 /// <summary>
2198                 /// オブジェクトから XML ファイルを生成します。
2199                 /// </summary>
2200                 /// <param name="xmlfile">XML ファイルのパス。</param>
2201                 /// <param name="obj">XML としてシリアライズするオブジェクト。DataContract 属性を持つクラスからインスタンス化されたオブジェクトです。</param>
2202                 public static void SerializeXML(string xmlpath, object obj)
2203                 {
2204                         XmlWriterSettings settings = new XmlWriterSettings();
2205                         settings.IndentChars = "  ";
2206                         settings.Indent = true;
2207                         settings.NewLineChars = Environment.NewLine;
2208                         settings.Encoding = new System.Text.UTF8Encoding(false);
2209             using (FileStreamSSD fsssd = new FileStreamSSD(xmlpath))
2210             {
2211                 using (XmlWriter xw = XmlWriter.Create(fsssd, settings))
2212                 {
2213                     DataContractSerializer serializer = new DataContractSerializer(obj.GetType());
2214                     serializer.WriteObject(xw, obj);
2215                 }
2216             }
2217                 }
2218
2219                 public void SaveConfig()
2220                 {
2221                         #region [ Skinパスの絶対パス→相対パス変換 ]
2222                         string _strSystemSkinSubfolderPath = ConfigIni.strSystemSkinSubfolderPath.Value;
2223                         Uri uriRoot = new Uri( System.IO.Path.Combine( this.strEXEのあるフォルダ, "System" + System.IO.Path.DirectorySeparatorChar ) );
2224                         if ( ConfigIni.strSystemSkinSubfolderPath.Value != null && ConfigIni.strSystemSkinSubfolderPath.Value.Length == 0 )
2225                         {
2226                                 // Config.iniが空の状態でDTXManiaをViewerとして起動・終了すると、strSystemSkinSubfolderFullName が空の状態でここに来る。
2227                                 // → 初期値として Default/ を設定する。
2228                                 ConfigIni.strSystemSkinSubfolderPath.Value = System.IO.Path.Combine( this.strEXEのあるフォルダ, "System" + System.IO.Path.DirectorySeparatorChar + "Default" + System.IO.Path.DirectorySeparatorChar );
2229                         }
2230
2231                         // 起動直後は(Loadの前にSaveを通るため)Skinパスには初期値の相対パスが入っている場合がある。
2232                         // そのため、以下の処理を通すために、いったん絶対パスに変換
2233                         if ( !System.IO.Path.IsPathRooted( ConfigIni.strSystemSkinSubfolderPath.Value ) )
2234                         {
2235                                 ConfigIni.strSystemSkinSubfolderPath.Value =
2236                                         Path.Combine( Path.Combine( this.strEXEのあるフォルダ, "System" ), ConfigIni.strSystemSkinSubfolderPath );
2237                         }
2238
2239                         Uri uriPath = new Uri( System.IO.Path.Combine( ConfigIni.strSystemSkinSubfolderPath.Value, "." + System.IO.Path.DirectorySeparatorChar ) );
2240                         string relPath = uriRoot.MakeRelativeUri( uriPath ).ToString();                         // 相対パスを取得
2241                         relPath = System.Web.HttpUtility.UrlDecode( relPath );                                          // デコードする
2242                         relPath = relPath.Replace( '/', System.IO.Path.DirectorySeparatorChar );        // 区切り文字が\ではなく/なので置換する
2243                         ConfigIni.strSystemSkinSubfolderPath.Value = relPath;
2244                         #endregion
2245                         ConfigIni.strDTXManiaVersion.Value = CDTXMania.VERSION;
2246
2247                         CDTXMania.SerializeXML( strEXEのあるフォルダ + "Config.xml", ConfigIni );
2248
2249                         // 元の絶対パスに戻す
2250                         ConfigIni.strSystemSkinSubfolderPath.Value = _strSystemSkinSubfolderPath;
2251                 }
2252
2253                 public void LoadConfig()
2254                 {
2255                         string path = strEXEのあるフォルダ + "Config.xml";
2256
2257                         if (!File.Exists(path))
2258                         {
2259                                 SaveConfig();
2260                         }
2261                         if (File.Exists(path))
2262                         {
2263                                 ConfigIni = (CConfigXml)CDTXMania.DeserializeXML(path, typeof(CConfigXml));
2264                                 if (ConfigIni == null)
2265                                 {
2266                                         ConfigIni = new CConfigXml();
2267                                         SaveConfig();
2268                                 }
2269                                 // Skinパスの相対パスを、絶対パスに変換
2270                                 if ( !System.IO.Path.IsPathRooted( ConfigIni.strSystemSkinSubfolderPath.Value ) )
2271                                 {
2272                                         ConfigIni.strSystemSkinSubfolderPath.Value =
2273                                                 Path.Combine( Path.Combine( this.strEXEのあるフォルダ, "System" ), ConfigIni.strSystemSkinSubfolderPath );
2274                                 }
2275                         }
2276                 }
2277                 /// <summary>
2278                 /// 座標値を読み込む。Coordinates メンバ初期化後いつ呼び出しても構わない。
2279                 /// </summary>
2280                 public void UpdateCoordinates()
2281                 {
2282                         string coordXml = strEXEのあるフォルダ + "Coordinates.xml";
2283  
2284                         // デシリアライズ
2285                         if (File.Exists(coordXml))
2286                         {
2287                                 using (XmlReader xr = XmlReader.Create(coordXml))
2288                                 {
2289                                         DataContractSerializer serializer = new DataContractSerializer(typeof(Coordinates.CCoordinates));
2290                                         try
2291                                         {
2292                                                 Coordinates = (Coordinates.CCoordinates) serializer.ReadObject( xr );
2293                                         }
2294                                         catch (SerializationException e)
2295                                         {
2296                                                 Trace.TraceWarning( "Rel107以前の古いフォーマットのCoordinates.xmlが読み込まれました。無視します。\n" + e.Message );
2297                                         }
2298                                 }
2299                         }
2300                         // シリアライズ
2301                         XmlWriterSettings settings = new XmlWriterSettings();
2302                         settings.IndentChars = "  ";
2303                         settings.Indent = true;
2304                         settings.NewLineChars = Environment.NewLine;
2305                         settings.Encoding = new System.Text.UTF8Encoding( false );
2306                         using ( XmlWriter xw = XmlTextWriter.Create( coordXml, settings ) )
2307                         {
2308                                 //XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
2309                                 //ns.Add( String.Empty, String.Empty );
2310
2311                                 //StreamWriter sw = new StreamWriter( "test2.xml", false, Encoding.UTF8 );
2312                                 //serializer.Serialize( sw, item, ns );
2313                                 //sw.Close
2314
2315                                 DataContractSerializer serializer = new DataContractSerializer( typeof( Coordinates.CCoordinates ) );
2316                                 serializer.WriteObject( xw, Coordinates );
2317                                 //serializer.WriteStartObject( xw, Coordinates );
2318                                 //xw.WriteAttributeString( "xmlns", "d1p1", "http://www.w3.org/2000/xmlns/",
2319                                 //      "http://schemas.microsoft.com/2003/10/Serialization/" );
2320                                 //serializer.WriteObjectContent( xw, Coordinates );
2321                                 //serializer.WriteEndObject( xw );
2322                         }
2323
2324                         // もう一度デシリアライズ
2325                         if (File.Exists(coordXml))
2326                         {
2327                                 using (XmlReader xr = XmlReader.Create(coordXml))
2328                                 {
2329                                         DataContractSerializer serializer = new DataContractSerializer(typeof(Coordinates.CCoordinates));
2330                                         Coordinates = (Coordinates.CCoordinates)serializer.ReadObject(xr);
2331                                 }
2332                         }
2333                 }
2334
2335
2336                 /// <summary>
2337                 /// 保存するxmlからnamespaceを削除するためのXmlTextWriter
2338                 /// </summary>
2339                 //public class MyXmlTextWriter : XmlTextWriter
2340                 //{
2341                 //      private bool _ignoreAttr = false;
2342
2343                 //      public MyXmlTextWriter( TextWriter w  )
2344                 //              : base( w )
2345                 //      {
2346                 //              Debug.WriteLine( "create" );
2347                 //      }
2348
2349                 //      public override string LookupPrefix( string ns )
2350                 //      {
2351                 //              Debug.WriteLine( "luprefix" );
2352                 //              return string.Empty;
2353                 //      }
2354
2355                 //      public override void WriteStartAttribute( string prefix, string localName, string ns )
2356                 //      {
2357                 //              Debug.WriteLine( "writestartattribute" );
2358                 //              if ( String.Compare( prefix, "xmlns", true ) == 0 )
2359                 //              {
2360                 //                      Debug.WriteLine( "[!]" );
2361                 //                      this._ignoreAttr = true;
2362                 //                      return;
2363                 //              }
2364                 //      }
2365
2366                 //      public override void WriteEndAttribute()
2367                 //      {
2368                 //              if ( this._ignoreAttr )
2369                 //              {
2370                 //                      this._ignoreAttr = false;
2371                 //                      return;
2372                 //              }
2373                 //              base.WriteEndAttribute();
2374                 //      }
2375
2376                 //      public override void WriteString( string text )
2377                 //      {
2378                 //              Debug.WriteLine( "ws" );
2379                 //              if ( String.Compare( text, "http://www.w3.org/2001/XMLSchema-instance", true ) == 0 )
2380                 //              {
2381                 //                      return;
2382                 //              }
2383                 //              base.WriteString( text );
2384                 //      }
2385
2386                 //      public override void WriteStartElement( string prefix, string localName, string ns )
2387                 //      {
2388                 //              Debug.WriteLine( "wse" );
2389                 //              base.WriteStartElement( null, localName, null );
2390                 //      }
2391                 //}
2392
2393                 public void ShowWindowTitleWithSoundType()
2394                 {
2395                         string delay = "";
2396                         if (Sound管理.CurrentSoundDeviceType != ESoundDeviceType.DirectSound)
2397                         {
2398                                 delay = "(" + Sound管理.GetSoundDelay() + "ms)";
2399                         }
2400                         base.Window.Text = strWindowTitle;
2401                         if (!this.DTX2WAVmode.Enabled)
2402                         {
2403                                 base.Window.Text += " (" + Sound管理.GetCurrentSoundDeviceType() + delay + ")";
2404                         }
2405                 }
2406
2407                 #region [ private ]
2408                 //-----------------
2409                 private bool b終了処理完了済み;
2410                 private static CDTX dtx;
2411                 private List<CActivity> listトップレベルActivities;
2412                 private int n進行描画の戻り値;
2413                 private MouseButtons mb = System.Windows.Forms.MouseButtons.Left;
2414                 private string strWindowTitle
2415                 {
2416                         get
2417                         {
2418                                 if (DTXVmode.Enabled)
2419                                 {
2420                                         return "DTXMViewer release " + VERSION;
2421                                 }
2422                                 else if (DTX2WAVmode.Enabled)
2423                                 {
2424                                         return "DTX2WAV (" + VERSION + "): " + Path.GetFileName(this.DTX2WAVmode.dtxfilename);
2425                                 }
2426                                 else
2427                                 {
2428                                         return "DTXMania .NET style release " + VERSION;
2429                                 }
2430                         }
2431                 }
2432                 private CSound previewSound;
2433                 private CMouseHideControl cMouseHideControl = null;
2434
2435                 private void t終了処理()
2436                 {
2437                         if (!this.b終了処理完了済み)
2438                         {
2439                                 Trace.TraceInformation("----------------------");
2440                                 Trace.TraceInformation("■ アプリケーションの終了");
2441                                 #region[ 電源プランの復元 ]
2442                                 CPowerPlan.RestoreCurrentPowerPlan();           // 電源プランを元のものに戻す
2443                                 #endregion
2444                                 #region [ 曲検索の終了処理 ]
2445                                 //---------------------
2446                                 if (actEnumSongs != null)
2447                                 {
2448                                         Trace.TraceInformation("曲検索actの終了処理を行います。");
2449                                         Trace.Indent();
2450                                         try
2451                                         {
2452                                                 actEnumSongs.On非活性化();
2453                                                 actEnumSongs = null;
2454                                                 Trace.TraceInformation("曲検索actの終了処理を完了しました。");
2455                                         }
2456                                         catch (Exception e)
2457                                         {
2458                                                 Trace.TraceError(e.Message);
2459                                                 Trace.TraceError("曲検索actの終了処理に失敗しました。");
2460                                         }
2461                                         finally
2462                                         {
2463                                                 Trace.Unindent();
2464                                         }
2465                                 }
2466                                 //---------------------
2467                                 #endregion
2468                                 #region [ 現在のステージの終了処理 ]
2469                                 //---------------------
2470                                 if (CDTXMania.Instance.r現在のステージ != null && CDTXMania.Instance.r現在のステージ.b活性化してる)     // #25398 2011.06.07 MODIFY FROM
2471                                 {
2472                                         Trace.TraceInformation("現在のステージを終了します。");
2473                                         Trace.Indent();
2474                                         try
2475                                         {
2476                                                 r現在のステージ.On非活性化();
2477                                                 Trace.TraceInformation("現在のステージの終了処理を完了しました。");
2478                                         }
2479                                         finally
2480                                         {
2481                                                 Trace.Unindent();
2482                                         }
2483                                 }
2484                                 //---------------------
2485                                 #endregion
2486
2487                                 #region [ 選曲ステージの終了処理 ]
2488                                 stage選曲.On非活性化();
2489                                 #endregion
2490
2491                                 #region [ プラグインの終了処理 ]
2492                                 //---------------------
2493                                 if (this.listプラグイン != null && this.listプラグイン.Count > 0)
2494                                 {
2495                                         Trace.TraceInformation("すべてのプラグインを終了します。");
2496                                         Trace.Indent();
2497                                         try
2498                                         {
2499                                                 foreach (STPlugin st in this.listプラグイン)
2500                                                 {
2501                                                         Directory.SetCurrentDirectory(st.strプラグインフォルダ);
2502                                                         st.plugin.OnUnmanagedリソースの解放();
2503                                                         st.plugin.OnManagedリソースの解放();
2504                                                         st.plugin.On終了();
2505                                                         Directory.SetCurrentDirectory(CDTXMania.Instance.strEXEのあるフォルダ);
2506                                                 }
2507                                                 PluginHost = null;
2508                                                 Trace.TraceInformation("すべてのプラグインの終了処理を完了しました。");
2509                                         }
2510                                         finally
2511                                         {
2512                                                 Trace.Unindent();
2513                                         }
2514                                 }
2515                                 //---------------------
2516                                 #endregion
2517                                 #region [ 曲リストの終了処理 ]
2518                                 //---------------------
2519                                 if (Songs管理 != null)
2520                                 {
2521                                         Trace.TraceInformation("曲リストの終了処理を行います。");
2522                                         Trace.Indent();
2523                                         try
2524                                         {
2525                                                 Songs管理 = null;
2526                                                 Trace.TraceInformation("曲リストの終了処理を完了しました。");
2527                                         }
2528                                         catch (Exception exception)
2529                                         {
2530                                                 Trace.TraceError(exception.Message);
2531                                                 Trace.TraceError("曲リストの終了処理に失敗しました。");
2532                                         }
2533                                         finally
2534                                         {
2535                                                 Trace.Unindent();
2536                                         }
2537                                 }
2538                                 CAvi.t終了();
2539                                 //---------------------
2540                                 #endregion
2541                                 #region [ スキンの終了処理 ]
2542                                 //---------------------
2543                                 if (Skin != null)
2544                                 {
2545                                         Trace.TraceInformation("スキンの終了処理を行います。");
2546                                         Trace.Indent();
2547                                         try
2548                                         {
2549                                                 Skin.Dispose();
2550                                                 Skin = null;
2551                                                 Trace.TraceInformation("スキンの終了処理を完了しました。");
2552                                         }
2553                                         catch (Exception exception2)
2554                                         {
2555                                                 Trace.TraceError(exception2.Message);
2556                                                 Trace.TraceError("スキンの終了処理に失敗しました。");
2557                                         }
2558                                         finally
2559                                         {
2560                                                 Trace.Unindent();
2561                                         }
2562                                 }
2563                                 //---------------------
2564                                 #endregion
2565                                 #region [ DirectSoundの終了処理 ]
2566                                 //---------------------
2567                                 if (Sound管理 != null)
2568                                 {
2569                                         Trace.TraceInformation("DirectSound の終了処理を行います。");
2570                                         Trace.Indent();
2571                                         try
2572                                         {
2573                                                 Sound管理.Dispose();
2574                                                 Sound管理 = null;
2575                                                 Trace.TraceInformation("DirectSound の終了処理を完了しました。");
2576                                         }
2577                                         catch (Exception exception3)
2578                                         {
2579                                                 Trace.TraceError(exception3.Message);
2580                                                 Trace.TraceError("DirectSound の終了処理に失敗しました。");
2581                                         }
2582                                         finally
2583                                         {
2584                                                 Trace.Unindent();
2585                                         }
2586                                 }
2587                                 //---------------------
2588                                 #endregion
2589                                 #region [ パッドの終了処理 ]
2590                                 //---------------------
2591                                 if (Pad != null)
2592                                 {
2593                                         Trace.TraceInformation("パッドの終了処理を行います。");
2594                                         Trace.Indent();
2595                                         try
2596                                         {
2597                                                 Pad = null;
2598                                                 Trace.TraceInformation("パッドの終了処理を完了しました。");
2599                                         }
2600                                         catch (Exception exception4)
2601                                         {
2602                                                 Trace.TraceError(exception4.Message);
2603                                                 Trace.TraceError("パッドの終了処理に失敗しました。");
2604                                         }
2605                                         finally
2606                                         {
2607                                                 Trace.Unindent();
2608                                         }
2609                                 }
2610                                 //---------------------
2611                                 #endregion
2612                                 #region [ DirectInput, MIDI入力の終了処理 ]
2613                                 //---------------------
2614                                 if (Input管理 != null)
2615                                 {
2616                                         Trace.TraceInformation("DirectInput, MIDI入力の終了処理を行います。");
2617                                         Trace.Indent();
2618                                         try
2619                                         {
2620                                                 Input管理.Dispose();
2621                                                 Input管理 = null;
2622                                                 Trace.TraceInformation("DirectInput, MIDI入力の終了処理を完了しました。");
2623                                         }
2624                                         catch (Exception exception5)
2625                                         {
2626                                                 Trace.TraceError(exception5.Message);
2627                                                 Trace.TraceError("DirectInput, MIDI入力の終了処理に失敗しました。");
2628                                         }
2629                                         finally
2630                                         {
2631                                                 Trace.Unindent();
2632                                         }
2633                                 }
2634                                 //---------------------
2635                                 #endregion
2636                                 #region [ 文字コンソールの終了処理 ]
2637                                 //---------------------
2638                                 if (act文字コンソール != null)
2639                                 {
2640                                         Trace.TraceInformation("文字コンソールの終了処理を行います。");
2641                                         Trace.Indent();
2642                                         try
2643                                         {
2644                                                 act文字コンソール.On非活性化();
2645                                                 act文字コンソール = null;
2646                                                 Trace.TraceInformation("文字コンソールの終了処理を完了しました。");
2647                                         }
2648                                         catch (Exception exception6)
2649                                         {
2650                                                 Trace.TraceError(exception6.Message);
2651                                                 Trace.TraceError("文字コンソールの終了処理に失敗しました。");
2652                                         }
2653                                         finally
2654                                         {
2655                                                 Trace.Unindent();
2656                                         }
2657                                 }
2658                                 //---------------------
2659                                 #endregion
2660                                 #region [ FPSカウンタの終了処理 ]
2661                                 //---------------------
2662                                 Trace.TraceInformation("FPSカウンタの終了処理を行います。");
2663                                 Trace.Indent();
2664                                 try
2665                                 {
2666                                         if (FPS != null)
2667                                         {
2668                                                 FPS = null;
2669                                         }
2670                                         Trace.TraceInformation("FPSカウンタの終了処理を完了しました。");
2671                                 }
2672                                 finally
2673                                 {
2674                                         Trace.Unindent();
2675                                 }
2676                                 //---------------------
2677                                 #endregion
2678                                 #region [ タイマの終了処理 ]
2679                                 //---------------------
2680                                 Trace.TraceInformation("タイマの終了処理を行います。");
2681                                 Trace.Indent();
2682                                 try
2683                                 {
2684                                         if (Timer != null)
2685                                         {
2686                                                 Timer.Dispose();
2687                                                 Timer = null;
2688                                                 Trace.TraceInformation("タイマの終了処理を完了しました。");
2689                                         }
2690                                         else
2691                                         {
2692                                                 Trace.TraceInformation("タイマは使用されていません。");
2693                                         }
2694                                 }
2695                                 finally
2696                                 {
2697                                         Trace.Unindent();
2698                                 }
2699                                 //---------------------
2700                                 #endregion
2701                                 #region [ Config.iniの出力 ]
2702                                 //---------------------
2703                                 Trace.TraceInformation("Config.xml を出力します。");
2704                                 //                              if ( ConfigIni.bIsSwappedGuitarBass )                   // #24063 2011.1.16 yyagi ギターベースがスワップしているときは元に戻す
2705                                 if (ConfigIni.bIsSwappedGuitarBass_AutoFlagsAreSwapped) // #24415 2011.2.21 yyagi FLIP中かつ演奏中にalt-f4で終了したときは、AUTOのフラグをswapして戻す
2706                                 {
2707                                         ConfigIni.SwapGuitarBassInfos_AutoFlags();
2708                                 }
2709                                 /*
2710                                         if (ConfigIni.bIsSwappedGuitarBass_PlaySettingsAreSwapped)  // #35417 2015/8/18 yyagi FLIP中かつ演奏中にalt-f4で終了したときは、演奏設定のフラグをswapして戻す
2711                                         {
2712                                                         ConfigIni.SwapGuitarBassInfos_PlaySettings();
2713                                         }
2714                                  */
2715                                 string str = strEXEのあるフォルダ + "Config.xml";
2716                                 Trace.Indent();
2717                                 try
2718                                 {
2719                                         if (DTXVmode.Enabled)
2720                                         {
2721                                                 DTXVmode.tUpdateConfigIni();
2722                                                 Trace.TraceInformation("DTXVモードの設定情報を、Config.xmlに保存しました。");
2723                                         }
2724                                         else if (DTX2WAVmode.Enabled)
2725                                         {
2726                                                 DTX2WAVmode.tUpdateConfigIni();
2727                                                 Trace.TraceInformation("DTX2WAVモードの設定情報を、Config.xmlに保存しました。");
2728                                                 DTX2WAVmode.SendMessage2DTX2WAV("TERM");
2729                                         }
2730                                         else
2731                                         {
2732                                                 CDTXMania.Instance.SaveConfig();
2733                                                 Trace.TraceInformation("保存しました。({0})", str);
2734                                         }
2735                                 }
2736                                 catch (Exception e)
2737                                 {
2738                                         Trace.TraceError(e.Message);
2739                                         Trace.TraceError("Config.xml の出力に失敗しました。({0})", str);
2740                                 }
2741                                 finally
2742                                 {
2743                                         Trace.Unindent();
2744                                 }
2745                                 //---------------------
2746                                 #endregion
2747                                 #region [ DTXVmodeの終了処理 ]
2748                                 //---------------------
2749                                 //Trace.TraceInformation( "DTXVモードの終了処理を行います。" );
2750                                 //Trace.Indent();
2751                                 try
2752                                 {
2753                                         if (DTXVmode != null)
2754                                         {
2755                                                 DTXVmode = null;
2756                                                 //Trace.TraceInformation( "DTXVモードの終了処理を完了しました。" );
2757                                         }
2758                                         else
2759                                         {
2760                                                 //Trace.TraceInformation( "DTXVモードは使用されていません。" );
2761                                         }
2762                                 }
2763                                 finally
2764                                 {
2765                                         //Trace.Unindent();
2766                                 }
2767                                 //---------------------
2768                                 #endregion
2769                                 #region [ DirectXの終了処理 ]
2770                                 //---------------------
2771                                 base.GraphicsDeviceManager.Dispose();
2772                                 //---------------------
2773                                 #endregion
2774                                 Trace.TraceInformation( "アプリケーションの終了処理を完了しました。" );
2775
2776
2777                                 this.b終了処理完了済み = true;
2778                         }
2779                 }
2780                 private CScoreIni tScoreIniへBGMAdjustとHistoryとPlayCountを更新(string str新ヒストリ行)
2781                 {
2782                         STDGBSValue<bool> isUpdated = new STDGBSValue<bool>();
2783                         string strFilename = DTX.strファイル名の絶対パス + ".score.ini";
2784                         CScoreIni ini = new CScoreIni(strFilename);
2785                         if (!File.Exists(strFilename))
2786                         {
2787                                 ini.stファイル.Title = DTX.TITLE;
2788                                 ini.stファイル.Name = DTX.strファイル名;
2789                                 ini.stファイル.Hash = CScoreIni.tファイルのMD5を求めて返す(DTX.strファイル名の絶対パス);
2790                                 for (EPart i = EPart.Drums; i <= EPart.Bass; ++i)
2791                                 {
2792                                         ini.stセクション.HiScore[i].nPerfectになる範囲ms = nPerfect範囲ms;
2793                                         ini.stセクション.HiScore[i].nGreatになる範囲ms = nGreat範囲ms;
2794                                         ini.stセクション.HiScore[i].nGoodになる範囲ms = nGood範囲ms;
2795                                         ini.stセクション.HiScore[i].nPoorになる範囲ms = nPoor範囲ms;
2796
2797                                         ini.stセクション.HiSkill[i].nPerfectになる範囲ms = nPerfect範囲ms;
2798                                         ini.stセクション.HiSkill[i].nGreatになる範囲ms = nGreat範囲ms;
2799                                         ini.stセクション.HiSkill[i].nGoodになる範囲ms = nGood範囲ms;
2800                                         ini.stセクション.HiSkill[i].nPoorになる範囲ms = nPoor範囲ms;
2801
2802                                         ini.stセクション.LastPlay[i].nPerfectになる範囲ms = nPerfect範囲ms;
2803                                         ini.stセクション.LastPlay[i].nGreatになる範囲ms = nGreat範囲ms;
2804                                         ini.stセクション.LastPlay[i].nGoodになる範囲ms = nGood範囲ms;
2805                                         ini.stセクション.LastPlay[i].nPoorになる範囲ms = nPoor範囲ms;
2806                                 }
2807                         }
2808                         ini.stファイル.BGMAdjust = DTX.nBGMAdjust;
2809                         isUpdated = CScoreIni.t更新条件を取得する();
2810                         if (isUpdated.Drums || isUpdated.Guitar || isUpdated.Bass)
2811                         {
2812                                 if (isUpdated.Drums)
2813                                 {
2814                                         ini.stファイル.PlayCountDrums++;
2815                                 }
2816                                 if (isUpdated.Guitar)
2817                                 {
2818                                         ini.stファイル.PlayCountGuitar++;
2819                                 }
2820                                 if (isUpdated.Bass)
2821                                 {
2822                                         ini.stファイル.PlayCountBass++;
2823                                 }
2824                                 ini.tヒストリを追加する(str新ヒストリ行);
2825                                 if (!bコンパクトモード)
2826                                 {
2827                                         stage選曲.r現在選択中のスコア.譜面情報.演奏回数.Drums = ini.stファイル.PlayCountDrums;
2828                                         stage選曲.r現在選択中のスコア.譜面情報.演奏回数.Guitar = ini.stファイル.PlayCountGuitar;
2829                                         stage選曲.r現在選択中のスコア.譜面情報.演奏回数.Bass = ini.stファイル.PlayCountBass;
2830                                         for (int j = 0; j < ini.stファイル.History.Length; j++)
2831                                         {
2832                                                 stage選曲.r現在選択中のスコア.譜面情報.演奏履歴[j] = ini.stファイル.History[j];
2833                                         }
2834                                 }
2835                         }
2836                         if (ConfigIni.bScoreIni)
2837                         {
2838                                 ini.t書き出し(strFilename);
2839                         }
2840
2841                         return ini;
2842                 }
2843                 private void tガベージコレクションを実行する()
2844                 {
2845                         GC.Collect(0, GCCollectionMode.Optimized, true );
2846                         GC.WaitForPendingFinalizers();
2847                         GC.Collect(0, GCCollectionMode.Forced, true );
2848                         GC.WaitForPendingFinalizers();
2849                 }
2850                 private void tプラグイン検索と生成()
2851                 {
2852                         this.listプラグイン = new List<STPlugin>();
2853
2854                         string strIPluginActivityの名前 = typeof(IPluginActivity).FullName;
2855                         string strプラグインフォルダパス = strEXEのあるフォルダ + "Plugins\\";
2856
2857                         this.t指定フォルダ内でのプラグイン検索と生成(strプラグインフォルダパス, strIPluginActivityの名前);
2858
2859                         if (this.listプラグイン.Count > 0)
2860                                 Trace.TraceInformation(this.listプラグイン.Count + " 個のプラグインを読み込みました。");
2861                 }
2862
2863                 private System.Reflection.Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
2864                 {
2865                         var domain = (AppDomain)sender;
2866
2867                         foreach (var assembly in domain.GetAssemblies())
2868                         {
2869                                 if (assembly.FullName == args.Name)
2870                                         return assembly;
2871                         }
2872                         return null;
2873                 }
2874                 private void t指定フォルダ内でのプラグイン検索と生成(string strプラグインフォルダパス, string strプラグイン型名)
2875                 {
2876                         // 指定されたパスが存在しないとエラー
2877                         if (!Directory.Exists(strプラグインフォルダパス))
2878                         {
2879                                 Trace.TraceWarning("プラグインフォルダが存在しません。(" + strプラグインフォルダパス + ")");
2880                                 return;
2881                         }
2882
2883                         AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
2884
2885
2886                         // (1) すべての *.dll について…
2887                         string[] strDLLs = System.IO.Directory.GetFiles(strプラグインフォルダパス, "*.dll");
2888                         foreach (string dllName in strDLLs)
2889                         {
2890                                 if (Path.GetExtension(dllName).ToLower() != ".dll")
2891                                 {
2892                                         continue;
2893                                 }
2894                                 try
2895                                 {
2896                                         // (1-1) dll をアセンブリとして読み込む。
2897                                         System.Reflection.Assembly asm = System.Reflection.Assembly.LoadFrom(dllName);
2898
2899                                         // (1-2) アセンブリ内のすべての型について、プラグインとして有効か調べる
2900                                         foreach (Type t in asm.GetTypes())
2901                                         {
2902                                                 //  (1-3) ↓クラスであり↓Publicであり↓抽象クラスでなく↓IPlugin型のインスタンスが作れる 型を持っていれば有効
2903                                                 if (t.IsClass && t.IsPublic && !t.IsAbstract && t.GetInterface(strプラグイン型名) != null)
2904                                                 {
2905                                                         // (1-4) クラス名からインスタンスを作成する
2906                                                         var st = new STPlugin()
2907                                                         {
2908                                                                 plugin = (IPluginActivity)asm.CreateInstance(t.FullName),
2909                                                                 strプラグインフォルダ = Path.GetDirectoryName(dllName),
2910                                                                 strアセンブリ簡易名 = asm.GetName().Name,
2911                                                                 Version = asm.GetName().Version,
2912                                                         };
2913
2914                                                         // (1-5) プラグインリストへ登録
2915                                                         this.listプラグイン.Add(st);
2916                                                         Trace.TraceInformation("プラグイン {0} ({1}, {2}, {3}) を読み込みました。", t.FullName, Path.GetFileName(dllName), st.strアセンブリ簡易名, st.Version.ToString());
2917                                                 }
2918                                         }
2919                                 }
2920                                 catch (System.Reflection.ReflectionTypeLoadException e)
2921                                 {
2922                                         Trace.TraceInformation(dllName + " からプラグインを生成することに失敗しました。スキップします。");
2923                                         Trace.TraceInformation(e.ToString());
2924                                         Trace.TraceInformation(e.Message);
2925                                         {
2926                                                 StringBuilder sb = new StringBuilder();
2927                                                 foreach (Exception exSub in e.LoaderExceptions)
2928                                                 {
2929                                                         sb.AppendLine(exSub.Message);
2930                                                         FileNotFoundException exFileNotFound = exSub as FileNotFoundException;
2931                                                         if (exFileNotFound != null)
2932                                                         {
2933                                                                 if (!string.IsNullOrEmpty(exFileNotFound.FusionLog))
2934                                                                 {
2935                                                                         sb.AppendLine("Fusion Log:");
2936                                                                         sb.AppendLine(exFileNotFound.FusionLog);
2937                                                                 }
2938                                                         }
2939                                                         sb.AppendLine();
2940                                                 }
2941                                                 string errorMessage = sb.ToString();
2942                                                 //Display or log the error based on your application.
2943                                                 Trace.TraceInformation(errorMessage);
2944                                         }
2945                                 }
2946                                 catch (Exception e)
2947                                 {
2948                                         Trace.TraceInformation(dllName + " からプラグインを生成することに失敗しました。スキップします。");
2949                                         Trace.TraceInformation(e.ToString());
2950                                         Trace.TraceInformation(e.Message);
2951                                 }
2952                         }
2953
2954                         // (2) サブフォルダがあれば再帰する
2955                         string[] strDirs = Directory.GetDirectories(strプラグインフォルダパス, "*");
2956                         foreach (string dir in strDirs)
2957                                 this.t指定フォルダ内でのプラグイン検索と生成(dir + "\\", strプラグイン型名);
2958                 }
2959                 //-----------------
2960                 #region [ Windowイベント処理 ]
2961                 private void Window_ApplicationActivated( object sender, EventArgs e )
2962                 {
2963                         this.bApplicationActive = true;
2964                 }
2965                 private void Window_ApplicationDeactivated(object sender, EventArgs e)
2966                 {
2967                         this.bApplicationActive = false;
2968                         if (cMouseHideControl != null) cMouseHideControl.Show();
2969                 }
2970                 private void Window_KeyDown(object sender, KeyEventArgs e)
2971                 {
2972                         if (e.KeyCode == Keys.Menu)
2973                         {
2974                                 e.Handled = true;
2975                                 e.SuppressKeyPress = true;
2976                         }
2977                         else if ((e.KeyCode == Keys.Return) && e.Alt)
2978                         {
2979                                 if (ConfigIni != null)
2980                                 {
2981                                         ConfigIni.bウィンドウモード = !ConfigIni.bウィンドウモード;
2982                                         this.t全画面_ウィンドウモード切り替え();
2983                                 }
2984                                 e.Handled = true;
2985                                 e.SuppressKeyPress = true;
2986                         }
2987                         else
2988                         {
2989                                 for (int i = 0; i < CConfigXml.AssignableCodes; i++)
2990                                 {
2991                                         var captureCode = (SlimDX.DirectInput.Key) ConfigIni.KeyAssign[ EPad.Capture ][ i ].コード;
2992
2993                                         if( (int) captureCode > 0 &&
2994                                                 e.KeyCode == DeviceConstantConverter.KeyToKeys( captureCode ) )
2995                                         {
2996                                                 // Debug.WriteLine( "capture: " + string.Format( "{0:2x}", (int) e.KeyCode ) + " " + (int) e.KeyCode );
2997                                                 string strFullPath =
2998                                                                  Path.Combine( CDTXMania.Instance.strEXEのあるフォルダ, "Capture_img" );
2999                                                 strFullPath = Path.Combine( strFullPath, DateTime.Now.ToString( "yyyyMMddHHmmss" ) + ".png" );
3000                                                 SaveResultScreen( strFullPath );
3001                                         }
3002                                 }
3003                         }
3004                 }
3005                 private void Window_MouseUp(object sender, MouseEventArgs e)
3006                 {
3007                         mb = e.Button;
3008                 }
3009
3010                 private void Window_MouseDoubleClick(object sender, MouseEventArgs e)   // #23510 2010.11.13 yyagi: to go full screen mode
3011                 {
3012                         if (mb.Equals(MouseButtons.Left) && ConfigIni.bIsAllowedDoubleClickFullscreen)  // #26752 2011.11.27 yyagi
3013                         {
3014                                 ConfigIni.bウィンドウモード = false;
3015                                 this.t全画面_ウィンドウモード切り替え();
3016                         }
3017                 }
3018                 private void Window_MouseMove(object sender, MouseEventArgs e)
3019                 {
3020                         if (cMouseHideControl != null) cMouseHideControl.tResetCursorState(ConfigIni.bウィンドウモード, this.bApplicationActive);
3021                 }
3022
3023                 private void Window_ResizeEnd(object sender, EventArgs e)               // #23510 2010.11.20 yyagi: to get resized window size
3024                 {
3025                         if (ConfigIni.bウィンドウモード)
3026                         {
3027                                 ConfigIni.rcWindow.X = base.Window.Location.X; // #30675 2013.02.04 ikanick add
3028                                 ConfigIni.rcWindow.Y = base.Window.Location.Y; //
3029                         }
3030
3031                         ConfigIni.rcWindow.W = (ConfigIni.bウィンドウモード) ? base.Window.ClientSize.Width : currentClientSize.Width;   // #23510 2010.10.31 yyagi add
3032                         ConfigIni.rcWindow.H = (ConfigIni.bウィンドウモード) ? base.Window.ClientSize.Height : currentClientSize.Height;
3033                 }
3034                 #endregion
3035
3036                 //Stopwatch sw = new Stopwatch();
3037                 //List<int> swlist1, swlist2, swlist3, swlist4, swlist5;
3038
3039                 #endregion
3040
3041                 private class CMouseHideControl
3042                 {
3043                         private Point lastPosition;
3044                         private CCounter ccMouseShow;
3045                         private bool bマウスカーソル表示中;
3046
3047                         /// <summary>
3048                         /// コンストラクタ
3049                         /// </summary>
3050                         public CMouseHideControl()
3051                         {
3052                                 ccMouseShow = new CCounter();
3053                                 lastPosition = Cursor.Position;
3054                                 bマウスカーソル表示中 = true;
3055                                 t開始();
3056                         }
3057
3058                         public void t開始()
3059                         {
3060                                 ccMouseShow.t開始(0, 20, 100, CDTXMania.instance.Timer);
3061                         }
3062
3063                         public void tHideCursorIfNeed()
3064                         {
3065                                 ccMouseShow.t進行();
3066 //Trace.TraceInformation("n現在の経過時間ms" + ccMouseShow.n現在の経過時間ms + ", n現在の値=" + ccMouseShow.n現在の値 + ", b終了値に達した=" + ccMouseShow.b終了値に達した);
3067                                 if (bマウスカーソル表示中 && ccMouseShow.b終了値に達した)
3068                                 {
3069                                         Point client_point = CDTXMania.Instance.Window.PointToClient(Cursor.Position);
3070                                         if (client_point.Y >= 0)        // タイトルバー上にマウスカーソルがある場合は、隠さない
3071                                         {
3072                                                 Hide();
3073                                         }
3074                                 }
3075
3076                         }
3077
3078                         public void tResetCursorState(bool bWindowed, bool bApplicationActive)
3079                         {
3080 //Trace.TraceInformation("マウス移動: " + Cursor.Position.X + "," + Cursor.Position.Y);
3081                                 if ((bWindowed == true && bマウスカーソル表示中 == false) || bApplicationActive == false)   // #36168 2016.3.19 yyagi: do not to show mouse cursor in full screen mode
3082                                 {
3083                                         Point currentPosition = Cursor.Position;
3084 //Trace.TraceInformation("current=" + currentPosition.ToString() + ", last=" + lastPosition.ToString());
3085                                         if (lastPosition != currentPosition)
3086                                         {
3087 //Trace.TraceInformation("移動発生");
3088                                                 lastPosition = currentPosition;
3089                                                 Show();
3090                                                 t開始();
3091                                         }
3092                                 }
3093                         }
3094
3095                         public void Show()
3096                         {
3097                                 Cursor.Show();
3098                                 bマウスカーソル表示中 = true;
3099                         }
3100                         public void Hide()
3101                         {
3102                                 Cursor.Hide();
3103                                 bマウスカーソル表示中 = false;
3104                         }
3105                 }
3106
3107                 /// <summary>
3108                 /// システム環境のログを出力する
3109                 /// </summary>
3110                 private void PutSystemLog()
3111                 {
3112                         System.Management.ManagementClass mc =
3113                                 new System.Management.ManagementClass("Win32_Processor");
3114                         System.Management.ManagementObjectCollection moc = mc.GetInstances();
3115                         foreach (System.Management.ManagementObject mo in moc)
3116                         {
3117                                 Trace.TraceInformation("-------------------------");
3118                                 Trace.TraceInformation("CPU Information:");
3119                                 //Trace.TraceInformation("DeviceID      = {0}", mo["DeviceID"]);
3120                                 Trace.TraceInformation("Name          = {0}", mo["Name"]);
3121                                 Trace.TraceInformation("MaxClockSpeed = {0}MHz", mo["MaxClockSpeed"]);
3122                                 Trace.TraceInformation("L2CacheSize   = {0}KB", mo["L2CacheSize"]);
3123                                 Trace.TraceInformation("L3CacheSize   = {0}KB", mo["L3CacheSize"]);
3124                                 Trace.TraceInformation("NumberOfLogicalProcessors = {0}", mo["NumberOfLogicalProcessors"]);
3125                         }
3126                         moc.Dispose();
3127                         moc.Dispose();
3128
3129                         //System.Management.ManagementClass mc =
3130                         //      new System.Management.ManagementClass("Win32_OperatingSystem");
3131                         //System.Management.ManagementObjectCollection moc = mc.GetInstances();
3132                         mc =
3133                                 new System.Management.ManagementClass("Win32_OperatingSystem");
3134                         moc = mc.GetInstances();
3135                         foreach (System.Management.ManagementObject mo in moc)
3136                         {
3137                                 Trace.TraceInformation("-------------------------");
3138                                 Trace.TraceInformation("OS Information:");
3139                                 //簡単な説明(Windows 8.1では「Microsoft Windows 8.1 Pro」等)
3140                                 Trace.TraceInformation("OS: " + mo["Caption"]);
3141                                 //バージョン(Windows 8.1では、「6.3.9600」)
3142                                 Trace.TraceInformation("Version: " + mo["Version"]);
3143                                 //ビルド番号(Windows 8.1では「9600」)
3144                                 //Trace.TraceInformation( "BuildNumber: " + mo["BuildNumber"]);
3145
3146                                 //サービスパック(Windows 8.1ではNULL)
3147                                 Trace.TraceInformation("CSDVersion (ServicePack): " + mo["CSDVersion"]);
3148                                 //言語(日本語は「1041」)
3149                                 Trace.TraceInformation("OSLanguage: " + mo["OSLanguage"]);
3150
3151                                 Trace.TraceInformation("OSArchitecture: " + mo["OSArchitecture"]);
3152
3153                                 //Trace.TraceInformation("TotalVisibleMemorySize = {0}", mo["TotalVisibleMemorySize"]);
3154                         }
3155                         moc.Dispose();
3156                         mc.Dispose();
3157
3158                         Trace.TraceInformation("-------------------------");
3159                         Trace.TraceInformation("General Environment Information:");
3160                         //Trace.TraceInformation("OS Version: " + Environment.OSVersion);       // fake version will be returned (due to the lack of manifest settings)
3161                         //Trace.TraceInformation("ProcessorCount: " + Environment.ProcessorCount.ToString());
3162                         Trace.TraceInformation("CLR Version: " + Environment.Version.ToString());
3163                         Trace.TraceInformation("SystemPageSize: " + Environment.SystemPageSize.ToString());
3164
3165                         var cominfo = new Microsoft.VisualBasic.Devices.ComputerInfo();
3166                         Trace.TraceInformation("TotalPhysicalMemorySize: {0:F2}GB", (cominfo.TotalPhysicalMemory / 1024f / 1024f / 1024f));
3167                         Trace.TraceInformation("VirtialMemorySize: {0:F2}GB", (cominfo.TotalVirtualMemory / 1024f / 1024f / 1024f));
3168                         Trace.TraceInformation("FreePhysicalMemorySize: {0:F2}MB", (cominfo.AvailablePhysicalMemory / 1024f / 1024f));
3169                         Trace.TraceInformation("FreeVirtualMemorySize: {0:F2}MB", (cominfo.AvailableVirtualMemory / 1024f / 1024f));
3170                         //Trace.TraceInformation(cominfo.OSFullName + ", " + cominfo.OSPlatform + ", " + cominfo.OSVersion);
3171
3172                         mc = new System.Management.ManagementClass("Win32_PhysicalMemory");
3173                         moc = mc.GetInstances();
3174                         Trace.TraceInformation("-------------------------");
3175                         Trace.TraceInformation("Physical Memory Information:");
3176                         foreach (System.Management.ManagementObject mo in moc)
3177                         {
3178                                 Trace.TraceInformation("Capacity: {0:F2}GB", (Convert.ToInt64(mo["Capacity"]) / 1024f / 1024f / 1024f));
3179                         }
3180                         moc.Dispose();
3181                         mc.Dispose();
3182
3183                         mc = new System.Management.ManagementClass("Win32_DisplayControllerConfiguration");
3184                         moc = mc.GetInstances();
3185                         foreach (System.Management.ManagementObject mo in moc)
3186                         {
3187                                 Trace.TraceInformation("-------------------------");
3188                                 Trace.TraceInformation("Display Adapter Information:");
3189                                 Trace.TraceInformation("Name: " + mo["Name"]);
3190                                 Trace.TraceInformation("VideoMode: " + mo["VideoMode"]);
3191                                 Trace.TraceInformation("HorizontalResolution: " + mo["HorizontalResolution"]);
3192                                 Trace.TraceInformation("VerticalResolution: " + mo["VerticalResolution"]);
3193                                 Trace.TraceInformation("RefreshRate: " + mo["RefreshRate"]);
3194                         }
3195                         moc.Dispose();
3196                         mc.Dispose();
3197
3198                         mc = new System.Management.ManagementClass("Win32_VideoController");
3199                         moc = mc.GetInstances();
3200                         foreach (System.Management.ManagementObject mo in moc)
3201                         {
3202                                 Trace.TraceInformation("-------------------------");
3203                                 Trace.TraceInformation("Video Controller Information:");
3204                                 Trace.TraceInformation("Description: " + mo["Description"]);
3205                                 Trace.TraceInformation("AdapterRAM: {0}MB", (Convert.ToInt64(mo["AdapterRAM"]) / 1024f / 1024f));
3206                                 Trace.TraceInformation("CapabilityDescriptions: " + mo["CapabilityDescriptions"]);
3207                         }
3208                         moc.Dispose();
3209                         mc.Dispose();
3210
3211                         mc = new System.Management.ManagementClass("Win32_DesktopMonitor");
3212                         moc = mc.GetInstances();
3213                         foreach (System.Management.ManagementObject mo in moc)
3214                         {
3215                                 Trace.TraceInformation("-------------------------");
3216                                 Trace.TraceInformation("Display Information:");
3217                                 Trace.TraceInformation("Description: " + mo["Description"]);
3218                                 Trace.TraceInformation("PixelsPerXLogicalInch: " + mo["PixelsPerXLogicalInch"]);
3219                                 Trace.TraceInformation("PixelsPerYLogicalInch: " + mo["PixelsPerYLogicalInch"]);
3220                                 Trace.TraceInformation("ScreenWidth: " + mo["ScreenWidth"]);
3221                                 Trace.TraceInformation("ScreenHeight: " + mo["ScreenHeight"]);
3222                         }
3223                         moc.Dispose();
3224                         mc.Dispose();
3225
3226                         mc = new System.Management.ManagementClass("Win32_SoundDevice");
3227                         moc = mc.GetInstances();
3228                         foreach (System.Management.ManagementObject mo in moc)
3229                         {
3230                                 Trace.TraceInformation("-------------------------");
3231                                 Trace.TraceInformation("Sound Information:");
3232                                 //Trace.TraceInformation("Caption: " + mo["Caption"]);
3233                                 Trace.TraceInformation("ProductName: " + mo["ProductName"]);
3234                                 //Trace.TraceInformation("DMABufferSize: " + mo["DMABufferSize"]);
3235                         }
3236                         moc.Dispose();
3237                         mc.Dispose();
3238
3239                         Trace.TraceInformation("----------------------");
3240                         Trace.TraceInformation("DTXMania settings:");
3241                         Trace.TraceInformation("VSyncWait: " + ConfigIni.bVSyncWait.ToString());
3242                         Trace.TraceInformation("Fullscreen: " + ConfigIni.bFullScreen.ToString());
3243                         Trace.TraceInformation("----------------------");
3244                 }
3245
3246         }
3247 }