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