OSDN Git Service

#36057 コンフィグまわりのリファクタ(リソース不完全なので注意)
[dtxmania/dtxmania.git] / DTXManiaプロジェクト / コード / 全体 / Program.cs
index 7aa520b..4cbd810 100644 (file)
@@ -17,118 +17,130 @@ namespace DTXMania
                //-----------------------------\r
                private static Mutex mutex二重起動防止用;\r
 \r
-               private static bool tDLLの存在チェック( string strDll名, string str存在しないときに表示するエラー文字列jp, string str存在しないときに表示するエラー文字列en, bool bLoadDllCheck )\r
+               private static bool tDLLの存在チェック(string strDll名, string str存在しないときに表示するエラー文字列jp, string str存在しないときに表示するエラー文字列en, bool bLoadDllCheck)\r
                {\r
-                       string str存在しないときに表示するエラー文字列 = ( CultureInfo.CurrentCulture.TwoLetterISOLanguageName == "ja" ) ?\r
+                       string str存在しないときに表示するエラー文字列 = (CultureInfo.CurrentCulture.TwoLetterISOLanguageName == "ja") ?\r
                                str存在しないときに表示するエラー文字列jp : str存在しないときに表示するエラー文字列en;\r
-                       if ( bLoadDllCheck )\r
+                       if (bLoadDllCheck)\r
                        {\r
-                               IntPtr hModule = LoadLibrary( strDll名 );              // 実際にLoadDll()してチェックする\r
-                               if ( hModule == IntPtr.Zero )\r
+                               IntPtr hModule = LoadLibrary(strDll名);    // 実際にLoadDll()してチェックする\r
+                               if (hModule == IntPtr.Zero)\r
                                {\r
-                                       MessageBox.Show( str存在しないときに表示するエラー文字列, "DTXMania runtime error", MessageBoxButtons.OK, MessageBoxIcon.Hand );\r
+                                       MessageBox.Show(str存在しないときに表示するエラー文字列, "DTXMania runtime error", MessageBoxButtons.OK, MessageBoxIcon.Hand);\r
                                        return false;\r
                                }\r
-                               FreeLibrary( hModule );\r
+                               FreeLibrary(hModule);\r
                        }\r
                        else\r
-                       {                                                                                                       // 単純にファイルの存在有無をチェックするだけ (プロジェクトで「参照」していたり、アンマネージドなDLLが暗黙リンクされるものはこちら)\r
-                               string path = Path.Combine( System.IO.Directory.GetCurrentDirectory(), strDll名 );\r
-                               if ( !File.Exists( path ) )\r
+                       {                         // 単純にファイルの存在有無をチェックするだけ (プロジェクトで「参照」していたり、アンマネージドなDLLが暗黙リンクされるものはこちら)\r
+                               string path = Path.Combine(System.IO.Directory.GetCurrentDirectory(), strDll名);\r
+                               if (!File.Exists(path))\r
                                {\r
-                                       MessageBox.Show( str存在しないときに表示するエラー文字列, "DTXMania runtime error", MessageBoxButtons.OK, MessageBoxIcon.Hand );\r
+                                       MessageBox.Show(str存在しないときに表示するエラー文字列, "DTXMania runtime error", MessageBoxButtons.OK, MessageBoxIcon.Hand);\r
                                        return false;\r
                                }\r
                        }\r
                        return true;\r
                }\r
-               private static bool tDLLの存在チェック( string strDll名, string str存在しないときに表示するエラー文字列jp, string str存在しないときに表示するエラー文字列en )\r
+               private static bool tDLLの存在チェック(string strDll名, string str存在しないときに表示するエラー文字列jp, string str存在しないときに表示するエラー文字列en)\r
                {\r
                        //return true;\r
-                       return tDLLの存在チェック( strDll名, str存在しないときに表示するエラー文字列jp, str存在しないときに表示するエラー文字列en, false );\r
+                       return tDLLの存在チェック(strDll名, str存在しないときに表示するエラー文字列jp, str存在しないときに表示するエラー文字列en, false);\r
                }\r
 \r
                #region [DllImport]\r
-               [DllImport( "kernel32", CharSet = CharSet.Unicode, SetLastError = true )]\r
-               internal static extern void FreeLibrary( IntPtr hModule );\r
+               [DllImport("kernel32", CharSet = CharSet.Unicode, SetLastError = true)]\r
+               internal static extern void FreeLibrary(IntPtr hModule);\r
 \r
-               [DllImport( "kernel32", CharSet = CharSet.Unicode, SetLastError = true )]\r
-               internal static extern IntPtr LoadLibrary( string lpFileName );\r
+               [DllImport("kernel32", CharSet = CharSet.Unicode, SetLastError = true)]\r
+               internal static extern IntPtr LoadLibrary(string lpFileName);\r
                #endregion\r
                //-----------------------------\r
                #endregion\r
 \r
-               [STAThread] \r
+               [STAThread]\r
                private static void Main()\r
                {\r
-                       mutex二重起動防止用 = new Mutex( false, "DTXManiaMutex" );\r
+                       mutex二重起動防止用 = new Mutex(false, "DTXManiaMutex");\r
 \r
-                       if ( mutex二重起動防止用.WaitOne( 0, false ) )\r
+                       if (mutex二重起動防止用.WaitOne(0, false))\r
                        {\r
                                string newLine = Environment.NewLine;\r
                                bool bDLLnotfound = false;\r
 \r
-                               Trace.WriteLine( "Current Directory: " + Environment.CurrentDirectory );\r
-                               Trace.WriteLine( "EXEのあるフォルダ: " + Path.GetDirectoryName( Application.ExecutablePath ) );\r
+                               Trace.WriteLine("Current Directory: " + Environment.CurrentDirectory);\r
+                               Trace.WriteLine("EXEのあるフォルダ: " + Path.GetDirectoryName(Application.ExecutablePath));\r
 \r
                                #region [DLLの存在チェック]\r
-                               if ( !tDLLの存在チェック( "dll\\SlimDX" + CDTXMania.SLIMDXDLL + ".dll",\r
+                               if (!tDLLの存在チェック("dll\\SlimDX" + CDTXMania.SLIMDXDLL + ".dll",\r
                                        "SlimDX" + CDTXMania.SLIMDXDLL + ".dll またはその依存するdllが存在しません。" + newLine + "DTXManiaをダウンロードしなおしてください。",\r
                                        "SlimDX" + CDTXMania.SLIMDXDLL + ".dll, or its depended DLL, is not found." + newLine + "Please download DTXMania again."\r
-                                       ) ) bDLLnotfound = true;\r
-                               if ( !tDLLの存在チェック( "dll\\FDK.dll",\r
+                                       ))\r
+                                       bDLLnotfound = true;\r
+                               if (!tDLLの存在チェック("dll\\FDK.dll",\r
                                        "FDK.dll またはその依存するdllが存在しません。" + newLine + "DTXManiaをダウンロードしなおしてください。",\r
                                        "FDK.dll, or its depended DLL, is not found." + newLine + "Please download DTXMania again."\r
-                                       ) ) bDLLnotfound = true;\r
-                               if ( !tDLLの存在チェック( "xadec.dll",           // #35444 2015.8.27 yyagi; Changed dll path\r
+                                       ))\r
+                                       bDLLnotfound = true;\r
+                               if (!tDLLの存在チェック("xadec.dll",   // #35444 2015.8.27 yyagi; Changed dll path\r
                                        "xadec.dll が存在しません。" + newLine + "DTXManiaをダウンロードしなおしてください。",\r
                                        "xadec.dll is not found." + newLine + "Please download DTXMania again."\r
-                                       ) ) bDLLnotfound = true;\r
-                               if ( !tDLLの存在チェック( "dll\\SoundDecoder.dll",\r
+                                       ))\r
+                                       bDLLnotfound = true;\r
+                               if (!tDLLの存在チェック("dll\\SoundDecoder.dll",\r
                                        "SoundDecoder.dll またはその依存するdllが存在しません。" + newLine + "DTXManiaをダウンロードしなおしてください。",\r
                                        "SoundDecoder.dll, or its depended DLL, is not found." + newLine + "Please download DTXMania again."\r
-                                       ) ) bDLLnotfound = true;\r
-                               if ( !tDLLの存在チェック( CDTXMania.D3DXDLL,\r
+                                       ))\r
+                                       bDLLnotfound = true;\r
+                               if (!tDLLの存在チェック(CDTXMania.D3DXDLL,\r
                                        CDTXMania.D3DXDLL + " が存在しません。" + newLine + "DirectX Redist フォルダの DXSETUP.exe を実行し、" + newLine + "必要な DirectX ランタイムをインストールしてください。",\r
                                        CDTXMania.D3DXDLL + " is not found." + newLine + "Please execute DXSETUP.exe in \"DirectX Redist\" folder, to install DirectX runtimes required for DTXMania.",\r
                                        true\r
-                                       ) ) bDLLnotfound = true;\r
-                               if ( !tDLLの存在チェック( "dll\\bass.dll",\r
+                                       ))\r
+                                       bDLLnotfound = true;\r
+                               if (!tDLLの存在チェック("dll\\bass.dll",\r
                                        "bass.dll が存在しません。" + newLine + "DTXManiaをダウンロードしなおしてください。",\r
                                        "baas.dll is not found." + newLine + "Please download DTXMania again."\r
-                                       ) ) bDLLnotfound = true;\r
-                               if ( !tDLLの存在チェック( "dll\\Bass.Net.dll",\r
+                                       ))\r
+                                       bDLLnotfound = true;\r
+                               if (!tDLLの存在チェック("dll\\Bass.Net.dll",\r
                                        "Bass.Net.dll が存在しません。" + newLine + "DTXManiaをダウンロードしなおしてください。",\r
                                        "Bass.Net.dll is not found." + newLine + "Please download DTXMania again."\r
-                                       ) ) bDLLnotfound = true;\r
-                               if ( !tDLLの存在チェック( "dll\\bassmix.dll",\r
+                                       ))\r
+                                       bDLLnotfound = true;\r
+                               if (!tDLLの存在チェック("dll\\bassmix.dll",\r
                                        "bassmix.dll を読み込めません。bassmix.dll か bass.dll が存在しません。" + newLine + "DTXManiaをダウンロードしなおしてください。",\r
                                        "bassmix.dll is not loaded. bassmix.dll or bass.dll must not exist." + newLine + "Please download DTXMania again."\r
-                                       ) ) bDLLnotfound = true;\r
-                               if ( !tDLLの存在チェック( "dll\\bassasio.dll",\r
+                                       ))\r
+                                       bDLLnotfound = true;\r
+                               if (!tDLLの存在チェック("dll\\bassasio.dll",\r
                                        "bassasio.dll を読み込めません。bassasio.dll か bass.dll が存在しません。" + newLine + "DTXManiaをダウンロードしなおしてください。",\r
                                        "bassasio.dll is not loaded. bassasio.dll or bass.dll must not exist." + newLine + "Please download DTXMania again."\r
-                                       ) ) bDLLnotfound = true;\r
-                               if ( !tDLLの存在チェック( "dll\\basswasapi.dll",\r
+                                       ))\r
+                                       bDLLnotfound = true;\r
+                               if (!tDLLの存在チェック("dll\\basswasapi.dll",\r
                                        "basswasapi.dll を読み込めません。basswasapi.dll か bass.dll が存在しません。" + newLine + "DTXManiaをダウンロードしなおしてください。",\r
                                        "basswasapi.dll is not loaded. basswasapi.dll or bass.dll must not exist." + newLine + "Please download DTXMania again."\r
-                                       ) ) bDLLnotfound = true;\r
-                               if ( !tDLLの存在チェック( "dll\\bass_fx.dll",\r
+                                       ))\r
+                                       bDLLnotfound = true;\r
+                               if (!tDLLの存在チェック("dll\\bass_fx.dll",\r
                                        "bass_fx.dll を読み込めません。bass_fx.dll か bass.dll が存在しません。" + newLine + "DTXManiaをダウンロードしなおしてください。",\r
                                        "bass_fx.dll is not loaded. bass_fx.dll or bass.dll must not exist." + newLine + "Please download DTXMania again."\r
-                                       ) ) bDLLnotfound = true;\r
-                               if ( !tDLLの存在チェック( "dll\\DirectShowLib-2005.dll",\r
+                                       ))\r
+                                       bDLLnotfound = true;\r
+                               if (!tDLLの存在チェック("dll\\DirectShowLib-2005.dll",\r
                                        "DirectShowLib-2005.dll が存在しません。" + newLine + "DTXManiaをダウンロードしなおしてください。",\r
                                        "DirectShowLib-2005.dll is not found." + newLine + "Please download DTXMania again."\r
-                                       ) ) bDLLnotfound = true;\r
+                                       ))\r
+                                       bDLLnotfound = true;\r
                                #endregion\r
-                               if ( !bDLLnotfound )\r
+                               if (!bDLLnotfound)\r
                                {\r
 #if DEBUG && TEST_ENGLISH\r
                                        Thread.CurrentThread.CurrentCulture = new CultureInfo( "en-US" );\r
 #endif\r
 \r
-                                       DWM.EnableComposition( false ); // Disable AeroGrass temporally\r
+                                       DWM.EnableComposition(false); // Disable AeroGrass temporally\r
 \r
                                        // BEGIN #23670 2010.11.13 from: キャッチされない例外は放出せずに、ログに詳細を出力する。\r
                                        // BEGIM #24606 2011.03.08 from: DEBUG 時は例外発生箇所を直接デバッグできるようにするため、例外をキャッチしないようにする。\r
@@ -136,27 +148,26 @@ namespace DTXMania
                                        try\r
 #endif\r
                                        {\r
-                                               using ( var mania = new CDTXMania() )\r
-                                                       mania.Run();\r
-\r
-                                               Trace.WriteLine( "" );\r
-                                               Trace.WriteLine( "遊んでくれてありがとう!" );\r
+                                               CDTXMania.Instance.InitializeInstance();\r
+                                               CDTXMania.Instance.Run();\r
+                                               Trace.WriteLine("");\r
+                                               Trace.WriteLine("遊んでくれてありがとう!");\r
                                        }\r
 #if !DEBUG\r
-                                       catch( Exception e )\r
+                                       catch (Exception e)\r
                                        {\r
-                                               Trace.WriteLine( "" );\r
-                                               Trace.Write( e.ToString() );\r
-                                               Trace.WriteLine( "" );\r
-                                               Trace.WriteLine( "エラーだゴメン!(涙" );\r
-                                               MessageBox.Show( e.ToString(), "DTXMania Error", MessageBoxButtons.OK, MessageBoxIcon.Error );  // #23670 2011.2.28 yyagi to show error dialog\r
+                                               Trace.WriteLine("");\r
+                                               Trace.Write(e.ToString());\r
+                                               Trace.WriteLine("");\r
+                                               Trace.WriteLine("エラーだゴメン!(涙");\r
+                                               MessageBox.Show(e.ToString(), "DTXMania Error", MessageBoxButtons.OK, MessageBoxIcon.Error);    // #23670 2011.2.28 yyagi to show error dialog\r
                                        }\r
 #endif\r
                                        // END #24606 2011.03.08 from\r
                                        // END #23670 2010.11.13 from\r
 \r
-                                       if ( Trace.Listeners.Count > 1 )\r
-                                               Trace.Listeners.RemoveAt( 1 );\r
+                                       if (Trace.Listeners.Count > 1)\r
+                                               Trace.Listeners.RemoveAt(1);\r
                                }\r
 \r
                                // BEGIN #24615 2011.03.09 from: Mutex.WaitOne() が true を返した場合は、Mutex のリリースが必要である。\r
@@ -166,13 +177,13 @@ namespace DTXMania
 \r
                                // END #24615 2011.03.09 from\r
                        }\r
-                       else            // DTXManiaが既に起動中\r
+                       else    // DTXManiaが既に起動中\r
                        {\r
-                               \r
+\r
                                // → 引数が0個の時はそのまま終了\r
                                // 1個( コンパクトモード or DTXV -S) か2個 (DTXV -Nxxx ファイル名)のときは、そのプロセスにコマンドラインを丸々投げて終了する\r
 \r
-                               for ( int i = 0; i < 5; i++ )           // 検索結果のハンドルがZeroになることがあるので、200ms間隔で5回リトライする\r
+                               for (int i = 0; i < 5; i++)   // 検索結果のハンドルがZeroになることがあるので、200ms間隔で5回リトライする\r
                                {\r
                                        #region [ 既に起動中のDTXManiaプロセスを検索する。]\r
                                        // このやり方だと、ShowInTaskbar=falseでタスクバーに表示されないパターンの時に検索に失敗するようだが\r
@@ -180,15 +191,15 @@ namespace DTXMania
                                        // FindWindowを使えばこのパターンにも対応できるが、C#でビルドするアプリはウインドウクラス名を自前指定できないので、これは使わない。\r
 \r
                                        Process current = Process.GetCurrentProcess();\r
-                                       Process[] running = Process.GetProcessesByName( current.ProcessName );\r
+                                       Process[] running = Process.GetProcessesByName(current.ProcessName);\r
                                        Process target = null;\r
-                                       //IntPtr hWnd = FindWindow( null, "DTXMania .NET style release " + CDTXMania.app.VERSION );\r
+                                       //IntPtr hWnd = FindWindow( null, "DTXMania .NET style release " + CDTXMania.VERSION );\r
 \r
-                                       foreach ( Process p in running )\r
+                                       foreach (Process p in running)\r
                                        {\r
-                                               if ( p.Id != current.Id )       // プロセス名は同じでかつ、プロセスIDが自分自身とは異なるものを探す\r
+                                               if (p.Id != current.Id) // プロセス名は同じでかつ、プロセスIDが自分自身とは異なるものを探す\r
                                                {\r
-                                                       if ( p.MainModule.FileName == current.MainModule.FileName && p.MainWindowHandle != IntPtr.Zero )\r
+                                                       if (p.MainModule.FileName == current.MainModule.FileName && p.MainWindowHandle != IntPtr.Zero)\r
                                                        {\r
                                                                target = p;\r
                                                                break;\r
@@ -198,29 +209,29 @@ namespace DTXMania
                                        #endregion\r
 \r
                                        #region [ 起動中のDTXManiaがいれば、そのプロセスにコマンドラインを投げる ]\r
-                                       if ( target != null )\r
+                                       if (target != null)\r
                                        {\r
                                                string[] commandLineArgs = Environment.GetCommandLineArgs();\r
-                                               if ( commandLineArgs != null && commandLineArgs.Length > 1 )\r
+                                               if (commandLineArgs != null && commandLineArgs.Length > 1)\r
                                                {\r
                                                        string arg = null;\r
-                                                       for ( int j = 1; j < commandLineArgs.Length; j++ )\r
+                                                       for (int j = 1; j < commandLineArgs.Length; j++)\r
                                                        {\r
-                                                               if ( j == 1 )\r
+                                                               if (j == 1)\r
                                                                {\r
-                                                                       arg += commandLineArgs[ j ];\r
+                                                                       arg += commandLineArgs[j];\r
                                                                }\r
                                                                else\r
                                                                {\r
-                                                                       arg += " " + "\"" + commandLineArgs[ j ] + "\"";\r
+                                                                       arg += " " + "\"" + commandLineArgs[j] + "\"";\r
                                                                }\r
                                                        }\r
 \r
-//Trace.TraceInformation( "Message=" + arg + ", len(w/o null)=" + arg.Length );\r
+                                                       //Trace.TraceInformation( "Message=" + arg + ", len(w/o null)=" + arg.Length );\r
 \r
-                                                       if ( arg != null )\r
+                                                       if (arg != null)\r
                                                        {\r
-                                                               FDK.CSendMessage.sendmessage( target.MainWindowHandle, current.MainWindowHandle, arg );\r
+                                                               FDK.CSendMessage.sendmessage(target.MainWindowHandle, current.MainWindowHandle, arg);\r
                                                        }\r
                                                }\r
                                                break;\r
@@ -228,8 +239,8 @@ namespace DTXMania
                                        #endregion\r
                                        else\r
                                        {\r
-                                               Trace.TraceInformation( "メッセージ送信先のプロセスが見つからず。5回リトライします。" );\r
-                                               Thread.Sleep( 200 );\r
+                                               Trace.TraceInformation("メッセージ送信先のプロセスが見つからず。5回リトライします。");\r
+                                               Thread.Sleep(200);\r
                                        }\r
                                }\r
                        }\r