@@ -200,81 +200,38 @@ void HandleSpecialLaunchOptions()
200
200
// ////////////////////////////////////////////////////////
201
201
void HandleDuplicateLaunching ()
202
202
{
203
- LPSTR lpCmdLine = GetCommandLine ();
203
+ LPWSTR szCommandLine = GetCommandLineW ();
204
204
205
- int iRecheckTimeLimit = 2000 ;
206
- while (!CreateSingleInstanceMutex ())
207
- {
208
- if (strcmp (lpCmdLine, " " ) != 0 )
209
- {
210
- HWND hwMTAWindow = FindWindow (NULL , " MTA: San Andreas" );
205
+ if (!szCommandLine[0 ])
206
+ return ;
207
+
208
+ HWND gameWindow = FindWindowA (nullptr , " MTA: San Andreas" );
211
209
#ifdef MTA_DEBUG
212
- if (hwMTAWindow == NULL )
213
- hwMTAWindow = FindWindow ( NULL , " MTA: San Andreas [DEBUG]" );
210
+ if (gameWindow == nullptr )
211
+ gameWindow = FindWindowA ( nullptr , " MTA: San Andreas [DEBUG]" );
214
212
#endif
215
- if (hwMTAWindow != NULL )
216
- {
217
- LPWSTR szCommandLine = GetCommandLineW ();
218
- int numArgs;
219
- LPWSTR* aCommandLineArgs = CommandLineToArgvW (szCommandLine, &numArgs);
220
- for (int i = 1 ; i < numArgs; ++i)
221
- {
222
- if (WStringX (aCommandLineArgs[i]).BeginsWith (L" mtasa://" ))
223
- {
224
- WString wideConnectInfo = aCommandLineArgs[i];
225
- SString strConnectInfo = ToUTF8 (wideConnectInfo);
226
213
227
- COPYDATASTRUCT cdStruct;
228
- cdStruct.cbData = strConnectInfo.length () + 1 ;
229
- cdStruct.lpData = const_cast <char *>(strConnectInfo.c_str ());
230
- cdStruct.dwData = URI_CONNECT;
214
+ if (gameWindow == nullptr )
215
+ return ;
231
216
232
- SendMessage (hwMTAWindow, WM_COPYDATA, NULL , (LPARAM)&cdStruct);
233
- break ;
234
- }
235
- }
236
- }
237
- else
238
- {
239
- if (iRecheckTimeLimit > 0 )
240
- {
241
- // Sleep a little bit and check the mutex again
242
- Sleep (500 );
243
- iRecheckTimeLimit -= 500 ;
244
- continue ;
245
- }
246
- SString strMessage;
247
- strMessage +=
248
- _ (" Trouble restarting MTA:SA\n\n "
249
- " If the problem persists, open Task Manager and\n "
250
- " stop the 'gta_sa.exe' and 'Multi Theft Auto.exe' processes\n\n\n "
251
- " Try to launch MTA:SA again?" );
252
- if (MessageBoxUTF8 (0 , strMessage, _ (" Error" ) + _E (" CL04" ), MB_ICONWARNING | MB_YESNO | MB_TOPMOST) ==
253
- IDYES) // Trouble restarting MTA:SA
254
- {
255
- TerminateGTAIfRunning ();
256
- TerminateOtherMTAIfRunning ();
257
- ShellExecuteNonBlocking (" open" , PathJoin (GetMTASAPath (), MTA_EXE_NAME), lpCmdLine);
258
- }
259
- return ExitProcess (EXIT_ERROR);
260
- }
261
- }
262
- else
217
+ int numArgs;
218
+ LPWSTR* aCommandLineArgs = CommandLineToArgvW (szCommandLine, &numArgs);
219
+
220
+ for (int i = 1 ; i < numArgs; ++i)
221
+ {
222
+ if (WStringX (aCommandLineArgs[i]).BeginsWith (L" mtasa://" ))
263
223
{
264
- if (!IsGTARunning () && !IsOtherMTARunning ())
265
- {
266
- MessageBoxUTF8 (0 , _ (" Another instance of MTA is already running.\n\n If this problem persists, please restart your computer" ),
267
- _ (" Error" ) + _E (" CL05" ), MB_ICONERROR | MB_TOPMOST);
268
- }
269
- else if (MessageBoxUTF8 (0 , _ (" Another instance of MTA is already running.\n\n Do you want to terminate it?" ), _ (" Error" ) + _E (" CL06" ),
270
- MB_ICONQUESTION | MB_YESNO | MB_TOPMOST) == IDYES)
271
- {
272
- TerminateGTAIfRunning ();
273
- TerminateOtherMTAIfRunning ();
274
- ShellExecuteNonBlocking (" open" , PathJoin (GetMTASAPath (), MTA_EXE_NAME), lpCmdLine);
275
- }
224
+ WString wideConnectInfo = aCommandLineArgs[i];
225
+ SString strConnectInfo = ToUTF8 (wideConnectInfo);
226
+
227
+ COPYDATASTRUCT cdStruct;
228
+ cdStruct.cbData = strConnectInfo.length () + 1 ;
229
+ cdStruct.lpData = const_cast <char *>(strConnectInfo.c_str ());
230
+ cdStruct.dwData = URI_CONNECT;
231
+
232
+ SendMessage (gameWindow, WM_COPYDATA, NULL , (LPARAM)&cdStruct);
233
+ return ExitProcess (EXIT_ERROR);
276
234
}
277
- return ExitProcess (EXIT_ERROR);
278
235
}
279
236
}
280
237
@@ -480,8 +437,6 @@ void HandleCustomStartMessage()
480
437
// ////////////////////////////////////////////////////////
481
438
void PreLaunchWatchDogs ()
482
439
{
483
- assert (!CreateSingleInstanceMutex ());
484
-
485
440
//
486
441
// "L0" is opened before the launch sequence and is closed if MTA shutsdown with no error
487
442
// "L1" is opened before the launch sequence and is closed if GTA is succesfully started
@@ -587,35 +542,6 @@ void PostRunWatchDogs(int iReturnCode)
587
542
}
588
543
}
589
544
590
- // ////////////////////////////////////////////////////////
591
- //
592
- // HandleIfGTAIsAlreadyRunning
593
- //
594
- // Check for and maybe stop a running GTA process
595
- //
596
- // ////////////////////////////////////////////////////////
597
- void HandleIfGTAIsAlreadyRunning ()
598
- {
599
- if (IsGTARunning ())
600
- {
601
- if (MessageBoxUTF8 (
602
- 0 , _ (" An instance of GTA: San Andreas is already running. It needs to be terminated before MTA:SA can be started. Do you want to do that now?" ),
603
- _ (" Information" ) + _E (" CL10" ), MB_YESNO | MB_ICONQUESTION | MB_TOPMOST) == IDYES)
604
- {
605
- TerminateOtherMTAIfRunning ();
606
- TerminateGTAIfRunning ();
607
- if (IsGTARunning ())
608
- {
609
- MessageBoxUTF8 (0 , _ (" Unable to terminate GTA: San Andreas. If the problem persists, please restart your computer." ),
610
- _ (" Information" ) + _E (" CL11" ), MB_OK | MB_ICONERROR | MB_TOPMOST);
611
- return ExitProcess (EXIT_ERROR);
612
- }
613
- }
614
- else
615
- return ExitProcess (EXIT_OK);
616
- }
617
- }
618
-
619
545
// ////////////////////////////////////////////////////////
620
546
//
621
547
// ValidateGTAPath
@@ -844,7 +770,6 @@ void CheckDataFiles()
844
770
{
845
771
SString strMessage (_ (" Main file has an incorrect name (%s)" ), *GetLaunchFilename ());
846
772
int iResponse = MessageBoxUTF8 (NULL , strMessage, _ (" Error" ) + _E (" CL33" ), MB_RETRYCANCEL | MB_ICONERROR | MB_TOPMOST);
847
- ReleaseSingleInstanceMutex ();
848
773
if (iResponse == IDRETRY)
849
774
ShellExecuteNonBlocking (" open" , PathJoin (strMTASAPath, MTA_EXE_NAME));
850
775
return ExitProcess (EXIT_ERROR);
@@ -1272,7 +1197,6 @@ int LaunchGame(SString strCmdLine)
1272
1197
//
1273
1198
// Cleanup and exit.
1274
1199
CloseHandle (piLoadee.hProcess );
1275
- ReleaseSingleInstanceMutex ();
1276
1200
1277
1201
// Success, maybe
1278
1202
return dwExitCode;
0 commit comments