Skip to content

Commit 2a07364

Browse files
ccw808ccw808
authored andcommitted
Added VS runtime check in launcher (on load failure).
Fixed auto-update problems associated with file permissions.
1 parent 1b953bf commit 2a07364

File tree

4 files changed

+61
-22
lines changed

4 files changed

+61
-22
lines changed

MTA10/launch/Main.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,22 @@ int WINAPI WinMain ( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi
5858
}
5959
else
6060
{
61+
iReturnCode = 1;
6162
SString strError = GetSystemErrorMessage ( GetLastError () );
6263
SString strMessage ( "Failed to load: '%s'\n\n%s", *strLoaderDllPathFilename, *strError );
6364
AddReportLog ( 5711, strMessage );
64-
BrowseToSolution ( "loader-dll-missing", ASK_GO_ONLINE, strMessage );
65-
iReturnCode = 1;
65+
66+
// Check if runtime is loadable
67+
HMODULE hModule = LoadLibrary ( MSVCR_DLL );
68+
if ( hModule )
69+
{
70+
BrowseToSolution ( "loader-dll-missing", ASK_GO_ONLINE, strMessage );
71+
FreeLibrary ( hModule );
72+
}
73+
else
74+
{
75+
BrowseToSolution ( "launch-" MSVCR_DLL "-missing", ASK_GO_ONLINE, "Redistributable Packages for Visual Studio are not installed" );
76+
}
6677
}
6778

6879
return iReturnCode;

MTA10/launch/StdInc.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
#include "shellapi.h"
1212

1313
#include <shlobj.h>
14-
//#include <Psapi.h>
15-
//#include <time.h>
1614

17-
//#include "Main.h"
18-
//#include "Install.h"
19-
//#include "Utils.h"
20-
//#include "..\version.h"
21-
//#include "CInstallManager.h"
15+
#if _MSC_VER == 1500 // MSVC++ 9.0 (Visual Studio 2008)
16+
#define MSVCR_DLL "msvcr90.dll"
17+
#elif _MSC_VER == 1800 // MSVC++ 12.0 (Visual Studio 2013)
18+
#define MSVCR_DLL "msvcr120.dll"
19+
#else
20+
#error "Insert VCR info"
21+
#endif

MTA10/loader/Install.cpp

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -121,14 +121,15 @@ bool DoInstallFiles ( void )
121121
// Copy current(old) files into backup location
122122
for ( unsigned int i = 0 ; i < itemList.size () ; i++ )
123123
{
124-
if ( !FileCopy ( itemList[i].strDestPathFilename, itemList[i].strBackupPathFilename ) )
124+
const SFileItem& item = itemList[i];
125+
if ( !FileCopy ( item.strDestPathFilename, item.strBackupPathFilename ) )
125126
{
126-
if ( FileExists ( itemList[i].strDestPathFilename ) )
127+
if ( FileExists ( item.strDestPathFilename ) )
127128
{
128-
AddReportLog ( 5021, SString ( "InstallFiles: Couldn't backup '%s' to '%s'", itemList[i].strDestPathFilename.c_str (), itemList[i].strBackupPathFilename.c_str () ) );
129+
AddReportLog ( 5021, SString ( "InstallFiles: Couldn't backup '%s' to '%s'", *item.strDestPathFilename, *item.strBackupPathFilename ) );
129130
return false;
130131
}
131-
AddReportLog ( 4023, SString ( "InstallFiles: Couldn't backup '%s' as it does not exist", itemList[i].strDestPathFilename.c_str () ) );
132+
AddReportLog ( 4023, SString ( "InstallFiles: Couldn't backup '%s' as it does not exist", *item.strDestPathFilename ) );
132133
}
133134
}
134135

@@ -137,30 +138,40 @@ bool DoInstallFiles ( void )
137138
std::vector < SFileItem > fileListSuccess;
138139
for ( unsigned int i = 0 ; i < itemList.size () ; i++ )
139140
{
140-
if ( !FileCopy ( itemList[i].strSrcPathFilename, itemList[i].strDestPathFilename ) )
141+
const SFileItem& item = itemList[i];
142+
if ( !FileCopy ( item.strSrcPathFilename, item.strDestPathFilename ) )
141143
{
142-
AddReportLog ( 5022, SString ( "InstallFiles: Couldn't copy '%s' to '%s'", itemList[i].strSrcPathFilename.c_str (), itemList[i].strDestPathFilename.c_str () ) );
143-
bOk = false;
144-
break;
144+
// If copy failed, check if we really need to copy the file
145+
if ( GenerateSha256HexStringFromFile( item.strSrcPathFilename ) != GenerateSha256HexStringFromFile( item.strDestPathFilename ) )
146+
{
147+
AddReportLog ( 5022, SString ( "InstallFiles: Couldn't copy '%s' to '%s'", *item.strSrcPathFilename, *item.strDestPathFilename ) );
148+
bOk = false;
149+
break;
150+
}
145151
}
146-
fileListSuccess.push_back ( itemList[i] );
152+
fileListSuccess.push_back ( item );
147153
}
148154

149155
// If fail, copy back old files
150156
if ( !bOk )
151157
{
152158
bool bPossibleDisaster = false;
153-
for ( unsigned int i = 0 ; i < fileListSuccess.size () ; i++ )
159+
for ( unsigned int i = 0 ; i < fileListSuccess.size () ; i++ )
154160
{
161+
const SFileItem& item = fileListSuccess[i];
155162
int iRetryCount = 3;
156163
while ( true )
157164
{
158-
if ( FileCopy ( fileListSuccess[i].strBackupPathFilename, fileListSuccess[i].strDestPathFilename ) )
165+
if ( FileCopy ( item.strBackupPathFilename, item.strDestPathFilename ) )
166+
break;
167+
168+
// If copy failed, check if we really need to copy the file
169+
if ( GenerateSha256HexStringFromFile( item.strBackupPathFilename ) != GenerateSha256HexStringFromFile( item.strDestPathFilename ) )
159170
break;
160171

161172
if ( !--iRetryCount )
162173
{
163-
AddReportLog ( 5023, SString ( "InstallFiles: Possible disaster restoring '%s' to '%s'", itemList[i].strBackupPathFilename.c_str (), itemList[i].strDestPathFilename.c_str () ) );
174+
AddReportLog ( 5023, SString ( "InstallFiles: Possible disaster restoring '%s' to '%s'", *item.strBackupPathFilename, *item.strDestPathFilename ) );
164175
bPossibleDisaster = true;
165176
break;
166177
}

Shared/installer/nightly.nsi

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,10 +508,24 @@ DontInstallRedistVC12:
508508
DetailPrint "$(INFO_UPDATE_PERMISSIONS)"
509509

510510
# Fix permissions for MTA install directory
511+
512+
# Check if install path begins with "..Program Files (x86)\M" or "..Program Files\M"
513+
StrCpy $3 "0"
511514
StrCpy $0 "$PROGRAMFILES\M"
512515
StrLen $2 $0
513516
StrCpy $1 "$INSTDIR" $2
514517
${If} $0 == $1
518+
StrCpy $3 "1"
519+
${EndIf}
520+
521+
StrCpy $0 "$PROGRAMFILES64\M"
522+
StrLen $2 $0
523+
StrCpy $1 "$INSTDIR" $2
524+
${If} $0 == $1
525+
StrCpy $3 "1"
526+
${EndIf}
527+
528+
${If} $3 == "1"
515529
FastPerms::FullAccessPlox "$INSTDIR"
516530
${Else}
517531
# More conservative permissions blat if install directory it too different from default
@@ -714,7 +728,10 @@ DontInstallRedistVC12:
714728
!ifndef LIGHTBUILD
715729
File "${FILES_ROOT}\MTA San Andreas\Multi Theft Auto.exe.dat"
716730
!endif
717-
731+
732+
# Ensure exe file can be updated without admin
733+
AccessControl::GrantOnFile "$INSTDIR\Multi Theft Auto.exe" "(BU)" "FullAccess"
734+
718735
${If} $AddToGameExplorer == 1
719736
${GameExplorer_UpdateGame} ${GUID}
720737
${If} ${Errors}

0 commit comments

Comments
 (0)