OSDN Git Service

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