@@ -1046,61 +1046,58 @@ void CheckLibVersions()
1046
1046
BOOL StartGtaProcess (const SString& lpApplicationName, const SString& lpCommandLine, const SString& lpCurrentDirectory,
1047
1047
LPPROCESS_INFORMATION lpProcessInformation, DWORD& dwOutError, SString& strOutErrorContext)
1048
1048
{
1049
+ STARTUPINFOW startupInfo{};
1050
+ startupInfo.cb = sizeof (startupInfo);
1051
+ BOOL wasProcessCreated = CreateProcessW (*FromUTF8 (lpApplicationName), FromUTF8 (lpCommandLine).data (), nullptr , nullptr , FALSE , 0 , nullptr ,
1052
+ *FromUTF8 (lpCurrentDirectory), &startupInfo, lpProcessInformation);
1053
+
1054
+ if (wasProcessCreated)
1055
+ return true ;
1056
+
1049
1057
std::vector<DWORD> processIdListBefore = GetGTAProcessList ();
1050
- // Start GTA
1051
- BOOL bResult = ShellExecuteNonBlocking (" open" , lpApplicationName, lpCommandLine, lpCurrentDirectory);
1052
1058
1053
- if (bResult == FALSE )
1059
+ if (! ShellExecuteNonBlocking ( " open " , lpApplicationName, lpCommandLine, lpCurrentDirectory) )
1054
1060
{
1055
- STARTUPINFOW startupInfo{};
1056
- startupInfo.cb = sizeof (startupInfo);
1057
- bResult = CreateProcessW (*FromUTF8 (lpApplicationName), FromUTF8 (lpCommandLine).data (), nullptr , nullptr , FALSE , 0 , nullptr ,
1058
- *FromUTF8 (lpCurrentDirectory), &startupInfo, lpProcessInformation);
1059
-
1060
- if (!bResult)
1061
- {
1062
- dwOutError = GetLastError ();
1063
- strOutErrorContext = " CreateProcess" ;
1064
- }
1061
+ dwOutError = GetLastError ();
1062
+ strOutErrorContext = " ShellExecute" ;
1063
+ return false ;
1065
1064
}
1066
- else
1065
+
1066
+ // Determine pid of new gta process
1067
+ for (uint i = 0 ; i < 10 ; i++)
1067
1068
{
1068
- // Determine pid of new gta process
1069
- for (uint i = 0 ; i < 10 ; i++ )
1069
+ std::vector<DWORD> processIdList = GetGTAProcessList ();
1070
+ for (DWORD pid : processIdList )
1070
1071
{
1071
- std::vector<DWORD> processIdList = GetGTAProcessList ();
1072
- for (DWORD pid : processIdList)
1072
+ if (ListContains (processIdListBefore, pid))
1073
1073
{
1074
- if (ListContains (processIdListBefore, pid))
1075
- {
1076
- continue ;
1077
- }
1078
- lpProcessInformation->dwProcessId = pid;
1079
- lpProcessInformation->hProcess = OpenProcess (PROCESS_TERMINATE | PROCESS_QUERY_LIMITED_INFORMATION | SYNCHRONIZE, FALSE , pid);
1080
- break ;
1074
+ continue ;
1081
1075
}
1082
- if ( lpProcessInformation->dwProcessId )
1083
- break ;
1084
- Sleep ( 500 ) ;
1076
+ lpProcessInformation->dwProcessId = pid;
1077
+ lpProcessInformation-> hProcess = OpenProcess (PROCESS_TERMINATE | PROCESS_QUERY_LIMITED_INFORMATION | SYNCHRONIZE, FALSE , pid) ;
1078
+ break ;
1085
1079
}
1080
+ if (lpProcessInformation->dwProcessId )
1081
+ break ;
1082
+ Sleep (500 );
1083
+ }
1086
1084
1087
- if (lpProcessInformation->dwProcessId == 0 )
1088
- {
1089
- // Unable to get pid
1090
- dwOutError = ERROR_INVALID_FUNCTION;
1091
- strOutErrorContext = " FindPID" ;
1092
- bResult = false ;
1093
- }
1094
- else if (lpProcessInformation->hProcess == nullptr )
1095
- {
1096
- // Unable to OpenProcess
1097
- dwOutError = ERROR_ELEVATION_REQUIRED;
1098
- strOutErrorContext = " OpenProcess" ;
1099
- bResult = false ;
1100
- }
1085
+ if (lpProcessInformation->dwProcessId == 0 )
1086
+ {
1087
+ // Unable to get pid
1088
+ dwOutError = ERROR_INVALID_FUNCTION;
1089
+ strOutErrorContext = " FindPID" ;
1090
+ wasProcessCreated = false ;
1091
+ }
1092
+ else if (lpProcessInformation->hProcess == nullptr )
1093
+ {
1094
+ // Unable to OpenProcess
1095
+ dwOutError = ERROR_ELEVATION_REQUIRED;
1096
+ strOutErrorContext = " OpenProcess" ;
1097
+ wasProcessCreated = false ;
1101
1098
}
1102
1099
1103
- return bResult ;
1100
+ return wasProcessCreated ;
1104
1101
}
1105
1102
1106
1103
// ////////////////////////////////////////////////////////
0 commit comments