OSDN Git Service

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