using System;\r
using System.Collections.Generic;\r
+using System.Globalization;\r
using System.Text;\r
using System.Runtime.InteropServices;\r
using System.Threading;\r
using System.Diagnostics;\r
using System.Windows.Forms;\r
+using System.IO;\r
+using FDK;\r
\r
namespace DTXMania\r
{\r
internal class Program\r
{\r
- #region [ 二重機動チェック、DLL存在チェック ]\r
+ #region [ 二重起動チェック、DLL存在チェック ]\r
//-----------------------------\r
private static Mutex mutex二重起動防止用;\r
\r
- private static bool tDLLの存在チェック( string strDll名, string str存在しないときに表示するエラー文字列 )\r
+ private static bool tDLLの存在チェック(string strDll名, string str存在しないときに表示するエラー文字列jp, string str存在しないときに表示するエラー文字列en, bool bLoadDllCheck)\r
{\r
- IntPtr hModule = LoadLibrary( strDll名 );\r
- if( hModule == IntPtr.Zero )\r
+ string str存在しないときに表示するエラー文字列 = (CultureInfo.CurrentCulture.TwoLetterISOLanguageName == "ja") ?\r
+ str存在しないときに表示するエラー文字列jp : str存在しないときに表示するエラー文字列en;\r
+ if (bLoadDllCheck)\r
{\r
- MessageBox.Show( str存在しないときに表示するエラー文字列, "DTXMania runtime error", MessageBoxButtons.OK, MessageBoxIcon.Hand );\r
- return false;\r
+ IntPtr hModule = LoadLibrary(strDll名); // 実際にLoadDll()してチェックする\r
+ if (hModule == IntPtr.Zero)\r
+ {\r
+ MessageBox.Show(str存在しないときに表示するエラー文字列, "DTXMania runtime error", MessageBoxButtons.OK, MessageBoxIcon.Hand);\r
+ return false;\r
+ }\r
+ FreeLibrary(hModule);\r
+ }\r
+ else\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
+ return false;\r
+ }\r
}\r
- FreeLibrary( hModule );\r
return true;\r
}\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
+ }\r
\r
- [DllImport( "kernel32", CharSet = CharSet.Unicode, SetLastError = true )]\r
- internal static extern void FreeLibrary( IntPtr hModule );\r
+ #region [DllImport]\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
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 flag = false;\r
-\r
- if( !tDLLの存在チェック( "FDK.dll", "FDK.dll またはその依存するdllが存在しません。" + newLine + "DTXManiaをダウンロードしなおしてください。" ) ) flag = true;\r
- if( !tDLLの存在チェック( "SlimDX" + CDTXMania.SLIMDXDLL, "SlimDX" + CDTXMania.SLIMDXDLL + ".dll またはその依存するdllが存在しません。" + newLine + "DTXManiaをダウンロードしなおしてください。" ) ) flag = true;\r
- if( !tDLLの存在チェック( "xadec.dll", "xadec.dll が存在しません。" + newLine + "DTXManiaをダウンロードしなおしてください。" ) ) flag = true;\r
- if( !tDLLの存在チェック( "SoundDecoder.dll", "SoundDecoder.dll またはその依存するdllが存在しません。" + newLine + "DTXManiaをダウンロードしなおしてください。" ) ) flag = true;\r
- if( !tDLLの存在チェック( CDTXMania.D3DXDLL, CDTXMania.D3DXDLL + " が存在しません。" + newLine + "Direct Regist フォルダの DXSETUP.exe を実行し、" + newLine + "必要な DirectX ランタイムをインストールしてください。" ) ) flag = true;\r
- if( !flag )\r
+ bool bDLLnotfound = false;\r
+\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
+ "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
+ ))\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
+ ))\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
+ ))\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
+ ))\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
+ ))\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
+ ))\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
+ ))\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
+ ))\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
+ ))\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
+ ))\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
+ ))\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
+ ))\r
+ bDLLnotfound = true;\r
+ #endregion\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
+\r
// BEGIN #23670 2010.11.13 from: キャッチされない例外は放出せずに、ログに詳細を出力する。\r
+ // BEGIM #24606 2011.03.08 from: DEBUG 時は例外発生箇所を直接デバッグできるようにするため、例外をキャッチしないようにする。\r
+#if !DEBUG\r
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
- catch( Exception e )\r
+#if !DEBUG\r
+ catch (Exception e)\r
{\r
- Trace.WriteLine( "" );\r
- Trace.Write( e.ToString() );\r
- Trace.WriteLine( "" );\r
- Trace.WriteLine( "エラーだゴメン!(涙" );\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
+\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
+\r
+ mutex二重起動防止用.ReleaseMutex();\r
+ mutex二重起動防止用 = null;\r
+\r
+ // END #24615 2011.03.09 from\r
+ }\r
+ else // DTXManiaが既に起動中\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
+ {\r
+ #region [ 既に起動中のDTXManiaプロセスを検索する。]\r
+ // このやり方だと、ShowInTaskbar=falseでタスクバーに表示されないパターンの時に検索に失敗するようだが\r
+ // DTXManiaでそのパターンはない?のでこのままいく。\r
+ // FindWindowを使えばこのパターンにも対応できるが、C#でビルドするアプリはウインドウクラス名を自前指定できないので、これは使わない。\r
+\r
+ Process current = Process.GetCurrentProcess();\r
+ Process[] running = Process.GetProcessesByName(current.ProcessName);\r
+ Process target = null;\r
+ //IntPtr hWnd = FindWindow( null, "DTXMania .NET style release " + CDTXMania.VERSION );\r
+\r
+ foreach (Process p in running)\r
+ {\r
+ if (p.Id != current.Id) // プロセス名は同じでかつ、プロセスIDが自分自身とは異なるものを探す\r
+ {\r
+ if (p.MainModule.FileName == current.MainModule.FileName && p.MainWindowHandle != IntPtr.Zero)\r
+ {\r
+ target = p;\r
+ break;\r
+ }\r
+ }\r
+ }\r
+ #endregion\r
+\r
+ #region [ 起動中のDTXManiaがいれば、そのプロセスにコマンドラインを投げる ]\r
+ if (target != null)\r
+ {\r
+ string[] commandLineArgs = Environment.GetCommandLineArgs();\r
+ if (commandLineArgs != null && commandLineArgs.Length > 1)\r
+ {\r
+ string arg = null;\r
+ for (int j = 1; j < commandLineArgs.Length; j++)\r
+ {\r
+ if (j == 1)\r
+ {\r
+ arg += commandLineArgs[j];\r
+ }\r
+ else\r
+ {\r
+ arg += " " + "\"" + commandLineArgs[j] + "\"";\r
+ }\r
+ }\r
+\r
+ //Trace.TraceInformation( "Message=" + arg + ", len(w/o null)=" + arg.Length );\r
+\r
+ if (arg != null)\r
+ {\r
+ FDK.CSendMessage.sendmessage(target.MainWindowHandle, current.MainWindowHandle, arg);\r
+ }\r
+ }\r
+ break;\r
+ }\r
+ #endregion\r
+ else\r
+ {\r
+ Trace.TraceInformation("メッセージ送信先のプロセスが見つからず。5回リトライします。");\r
+ Thread.Sleep(200);\r
+ }\r
}\r
}\r
}\r