Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Experimental/win static link #95

Merged
merged 5 commits into from
Nov 10, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Client/core/CCrashDumpWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,10 +254,10 @@ long WINAPI CCrashDumpWriter::HandleExceptionGlobal ( _EXCEPTION_POINTERS* pExce
void CCrashDumpWriter::DumpCoreLog ( CExceptionInformation* pExceptionInformation )
{
// Write crash flag for next launch (Simple flag in case of double faults later)
fclose( fopen ( CalcMTASAPath ( "mta\\core.log.flag" ), "w" ) );
fclose( File::Fopen ( CalcMTASAPath ( "mta\\core.log.flag" ), "w" ) );

// Write a log with the generic exception information
FILE* pFile = fopen ( CalcMTASAPath ( "mta\\core.log" ), "a+" );
FILE* pFile = File::Fopen ( CalcMTASAPath ( "mta\\core.log" ), "a+" );
if ( pFile )
{
// Header
Expand Down
4 changes: 2 additions & 2 deletions Client/core/CScreenShot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ void CScreenShot::SetPath ( const char *szPath )
strncpy ( szScreenShotPath, szPath, MAX_PATH - 1 );

// make sure the directory exists
mkdir ( szPath );
File::Mkdir ( szPath );
}

int CScreenShot::GetScreenShots ( void )
Expand Down Expand Up @@ -164,7 +164,7 @@ DWORD CScreenShot::ThreadProc ( LPVOID lpdwThreadParam )
}

MakeSureDirExists( ms_strFileName );
FILE *file = fopen (ms_strFileName, "wb");
FILE *file = File::Fopen (ms_strFileName, "wb");
if ( file )
{
png_struct* png_ptr = png_create_write_struct ( PNG_LIBPNG_VER_STRING, NULL, NULL, NULL );
Expand Down
2 changes: 1 addition & 1 deletion Client/core/CVersionUpdater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3164,7 +3164,7 @@ int CVersionUpdater::DoSendDownloadRequestToNextServer ( void )
{
SString strGTARootDir;
CFilePathTranslator().GetGTARootDirectory( strGTARootDir );
if ( FILE* fh = fopen( PathJoin( strGTARootDir, "audio", "SFX", "SPC_EA" ), "rb" ) )
if ( FILE* fh = File::Fopen( PathJoin( strGTARootDir, "audio", "SFX", "SPC_EA" ), "rb" ) )
{
strSoundCut = "y";
fseek( fh, 0x38BDC80, SEEK_SET );
Expand Down
22 changes: 11 additions & 11 deletions Client/loader/CExePatchedStatus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ EPatchResult UpdatePatchStatusTimestamp( const SString& strGTAEXEPath, EPatchMod
{
// Get the top byte of the file link timestamp
uchar ucTimeStamp = 0;
FILE* fh = fopen ( strGTAEXEPath, "rb" );
FILE* fh = File::Fopen ( strGTAEXEPath, "rb" );
if ( fh )
{
if ( !fseek ( fh, 0x8B, SEEK_SET ) )
Expand Down Expand Up @@ -274,7 +274,7 @@ EPatchResult UpdatePatchStatusTimestamp( const SString& strGTAEXEPath, EPatchMod
{
// Change needed!
SetFileAttributes ( strGTAEXEPath, FILE_ATTRIBUTE_NORMAL );
FILE* fh = fopen ( strGTAEXEPath, "r+b" );
FILE* fh = File::Fopen ( strGTAEXEPath, "r+b" );
if ( !fh )
{
return PATCH_SET_RESULT_REQ_ADMIN;
Expand All @@ -301,7 +301,7 @@ EPatchResult UpdatePatchStatusLargeMem( const SString& strGTAEXEPath, EPatchMode
{
// Get file position of IMAGE_FILE_HEADER->Characteristics
uint uiFilePosition = 0;
FILE* fh = fopen ( strGTAEXEPath, "rb" );
FILE* fh = File::Fopen ( strGTAEXEPath, "rb" );
if ( fh )
{
// 60 is offset of IMAGE_DOS_HEADER->e_lfanew
Expand All @@ -320,7 +320,7 @@ EPatchResult UpdatePatchStatusLargeMem( const SString& strGTAEXEPath, EPatchMode

// Get the value from the header
ushort usCharacteristics = 0;
fh = fopen ( strGTAEXEPath, "rb" );
fh = File::Fopen ( strGTAEXEPath, "rb" );
if ( fh )
{
if ( !fseek ( fh, uiFilePosition, SEEK_SET ) )
Expand Down Expand Up @@ -355,7 +355,7 @@ EPatchResult UpdatePatchStatusLargeMem( const SString& strGTAEXEPath, EPatchMode
{
// Change needed!
SetFileAttributes ( strGTAEXEPath, FILE_ATTRIBUTE_NORMAL );
FILE* fh = fopen ( strGTAEXEPath, "r+b" );
FILE* fh = File::Fopen ( strGTAEXEPath, "r+b" );
if ( !fh )
{
return PATCH_SET_RESULT_REQ_ADMIN;
Expand Down Expand Up @@ -386,7 +386,7 @@ EPatchResult UpdatePatchStatusDep( const SString& strGTAEXEPath, EPatchMode mode
{
// Get the value from the header
ulong ulDllCharacteristics = 0;
FILE* fh = fopen ( strGTAEXEPath, "rb" );
FILE* fh = File::Fopen ( strGTAEXEPath, "rb" );
if ( fh )
{
if ( !fseek ( fh, 0xDC, SEEK_SET ) )
Expand Down Expand Up @@ -421,7 +421,7 @@ EPatchResult UpdatePatchStatusDep( const SString& strGTAEXEPath, EPatchMode mode
{
// Change needed!
SetFileAttributes ( strGTAEXEPath, FILE_ATTRIBUTE_NORMAL );
FILE* fh = fopen ( strGTAEXEPath, "r+b" );
FILE* fh = File::Fopen ( strGTAEXEPath, "r+b" );
if ( !fh )
{
return PATCH_SET_RESULT_REQ_ADMIN;
Expand Down Expand Up @@ -487,7 +487,7 @@ EPatchResult UpdatePatchStatusNvightmare( const SString& strGTAEXEPath, EPatchMo
bool bHasExportTable = true;
uint uiExportValue = 0;
bool bUnknownBytes = false;
FILE* fh = fopen( strGTAEXEPath, "rb" );
FILE* fh = File::Fopen( strGTAEXEPath, "rb" );
bool bFileError = ( fh == NULL );
if( !bFileError )
{
Expand Down Expand Up @@ -548,7 +548,7 @@ EPatchResult UpdatePatchStatusNvightmare( const SString& strGTAEXEPath, EPatchMo
{
// Change needed!
SetFileAttributes( strGTAEXEPath, FILE_ATTRIBUTE_NORMAL );
FILE* fh = fopen( strGTAEXEPath, "r+b" );
FILE* fh = File::Fopen( strGTAEXEPath, "r+b" );
if ( !fh )
{
return PATCH_SET_RESULT_REQ_ADMIN;
Expand Down Expand Up @@ -668,7 +668,7 @@ EPatchResult UpdatePatchStatusAltModules( const SString& strGTAEXEPath, EPatchMo
uint uiNumOldNames = 0;
uint uiNumNewNames = 0;

FILE* fh = fopen ( strGTAEXEPath, "rb" );
FILE* fh = File::Fopen ( strGTAEXEPath, "rb" );
if ( fh )
{
for ( uint i = 0 ; i < NUMELMS( searchList ) ; i++ )
Expand Down Expand Up @@ -729,7 +729,7 @@ EPatchResult UpdatePatchStatusAltModules( const SString& strGTAEXEPath, EPatchMo
assert( !strGTAEXEPath.EndsWithI( "gta_sa.exe" ) );

SetFileAttributes ( strGTAEXEPath, FILE_ATTRIBUTE_NORMAL );
FILE* fh = fopen ( strGTAEXEPath, "r+b" );
FILE* fh = File::Fopen ( strGTAEXEPath, "r+b" );
if ( !fh )
{
return PATCH_SET_RESULT_REQ_ADMIN;
Expand Down
2 changes: 1 addition & 1 deletion Client/loader/CInstallManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,7 @@ SString CInstallManager::_ProcessLangFileChecks( void )

// Get language that will be used
SString strSettingsFilename = PathJoin( GetSystemPersonalPath(), "GTA San Andreas User Files", "gta_sa.set" );
FILE* fh = fopen( strSettingsFilename, "rb" );
FILE* fh = File::Fopen( strSettingsFilename, "rb" );
if ( fh )
{
fseek( fh, 0xB3B, SEEK_SET );
Expand Down
2 changes: 1 addition & 1 deletion Client/mods/deathmatch/logic/CLogger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ void CLogger::SetLogFile ( const char* szLogFile )
// Eventually open a new file
if ( szLogFile && szLogFile[0] )
{
m_pLogFile = fopen ( szLogFile, "a+" );
m_pLogFile = File::Fopen ( szLogFile, "a+" );
}
}

Expand Down
2 changes: 1 addition & 1 deletion Client/mods/deathmatch/logic/CPacketHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1411,7 +1411,7 @@ void CPacketHandler::Packet_DebugEcho ( NetBitStreamInterface& bitStream )
date[29] = '\0';

// open the file for append access
FILE * pFile = fopen ( strFileName.c_str (), "a" );
FILE * pFile = File::Fopen ( strFileName.c_str (), "a" );
if ( pFile )
{
// write out the data
Expand Down
2 changes: 1 addition & 1 deletion Client/mods/deathmatch/logic/CScriptDebugging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ bool CScriptDebugging::SetLogfile ( const char* szFilename, unsigned int uiLevel


// Try to load the new file
FILE* pFile = fopen ( szFilename, "a+" );
FILE* pFile = File::Fopen ( szFilename, "a+" );
if ( pFile )
{
// [2014-07-09 14:39:31] WARNING: Bad argument @ 'setElementPosition' [Expected element at argument 1, got nil] [string "return addEventHandler("onClientRender", ro..."]
Expand Down
6 changes: 3 additions & 3 deletions Server/core/CCrashHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ static void SaveBacktraceSummary()
bool DumpCallback( const google_breakpad::MinidumpDescriptor& descriptor, void* context, bool succeeded )
{
// Set inital dump file name (Safeish)
rename( descriptor.path(), ms_strDumpPathFilename );
File::Rename( descriptor.path(), ms_strDumpPathFilename );

// Set final dump file name (Not so safe)
time_t pTime = time( NULL );
Expand All @@ -149,7 +149,7 @@ bool DumpCallback( const google_breakpad::MinidumpDescriptor& descriptor, void*
tm->tm_min
);
SString strFinalDumpPathFilename = PathJoin( ms_strDumpPath, strFilename );
rename( ms_strDumpPathFilename, strFinalDumpPathFilename );
File::Rename( ms_strDumpPathFilename, strFinalDumpPathFilename );

SaveBacktraceSummary();
FileSave( PathJoin( ms_strDumpPath, "server_pending_upload_filename" ), strFinalDumpPathFilename );
Expand Down Expand Up @@ -256,7 +256,7 @@ void CCrashHandler::DumpMiniDump ( _EXCEPTION_POINTERS* pException, CExceptionIn
}

// Write a log with the generic exception information
FILE* pFile = fopen ( PathJoin( ms_strDumpPath, "server_pending_upload.log" ), "a+" );
FILE* pFile = File::Fopen ( PathJoin( ms_strDumpPath, "server_pending_upload.log" ), "a+" );
if ( pFile )
{
// Header
Expand Down
6 changes: 5 additions & 1 deletion Server/launcher/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
// Linux gcc 4.4.5 memory corruption on destruction of g_StatEvents (Reason unknown)
#include "SharedUtil.hpp"
#else
FILE* SharedUtil::File::Fopen(const char* szFilename, const char* szMode)
{
return fopen(szFilename, szMode);
}
bool SString::Contains ( const SString& strOther ) const
{
return find ( strOther ) != std::string::npos;
Expand Down Expand Up @@ -124,7 +128,7 @@ int main ( int argc, char* argv [] )
#endif

// If we are unable to access the core module, try changing to the directory of the launched file
FILE* fh = fopen ( LIB_CORE, "r" );
FILE* fh = File::Fopen ( LIB_CORE, "r" );
if ( !fh )
{
#ifdef WIN32
Expand Down
2 changes: 1 addition & 1 deletion Server/mods/deathmatch/logic/CCommandFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ m_Client ( Client )

{
// Load the given file
m_pFile = fopen ( szFilename, "r" );
m_pFile = File::Fopen ( szFilename, "r" );
m_bEcho = true;
}

Expand Down
2 changes: 1 addition & 1 deletion Server/mods/deathmatch/logic/CGame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,7 @@ bool CGame::Start ( int iArgumentCount, char* szArguments [] )

// Create cache readme
SString strReadmeFilename ( "%s/DO_NOT_MODIFY_Readme.txt", strResourceCachePath.c_str () );
FILE *fh = fopen ( strReadmeFilename, "w" );
FILE *fh = File::Fopen ( strReadmeFilename, "w" );
if ( fh )
{
fprintf ( fh, "---------------------------------------------------------------------------\n" );
Expand Down
4 changes: 2 additions & 2 deletions Server/mods/deathmatch/logic/CLogger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ bool CLogger::SetLogFile ( const char* szLogFile )
MakeSureDirExists ( szLogFile );

// Create the file
m_pLogFile = fopen ( szLogFile, "a+" );
m_pLogFile = File::Fopen ( szLogFile, "a+" );
return m_pLogFile != NULL;
}

Expand All @@ -171,7 +171,7 @@ bool CLogger::SetAuthFile ( const char* szAuthFile )
MakeSureDirExists ( szAuthFile );

// Create the file
m_pAuthFile = fopen ( szAuthFile, "a+" );
m_pAuthFile = File::Fopen ( szAuthFile, "a+" );
return m_pAuthFile != NULL;
}

Expand Down
43 changes: 30 additions & 13 deletions Server/mods/deathmatch/logic/CResource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,23 @@ extern CGame* g_pGame;
extern int errno;
#endif

//
// Helper function to avoid fopen in Window builds
//
static unzFile unzOpenUtf8(const char *path)
{
#ifdef WIN32
// This will use CreateFile instead of fopen
zlib_filefunc_def ffunc;
fill_win32_filefunc (&ffunc);
return unzOpen2( path, &ffunc );
#else
return unzOpen( path );
#endif
}



// (IJs) This class contains very nasty unchecked and unproper code. Please revise.

CResource::CResource ( CResourceManager * resourceManager, bool bIsZipped, const char * szAbsPath, const char * szResourceName )
Expand Down Expand Up @@ -150,7 +167,7 @@ bool CResource::Load ( void )
if ( m_bResourceIsZip )
{
// See if zip file is actually a zip file
m_zipfile = unzOpen ( m_strResourceZip.c_str () );
m_zipfile = unzOpenUtf8 ( m_strResourceZip.c_str () );
if ( !m_zipfile )
{
//Unregister EHS stuff
Expand Down Expand Up @@ -1036,10 +1053,10 @@ bool CResource::Start ( list<CResource *> * dependents, bool bStartedManually, b
// Add us to the running resources list
m_StartedResources.push_back ( this );

// Sort by priority, for start grouping on the client
m_StartedResources.sort([](CResource* a, CResource* b)
{
return a->m_iDownloadPriorityGroup > b->m_iDownloadPriorityGroup;
// Sort by priority, for start grouping on the client
m_StartedResources.sort([](CResource* a, CResource* b)
{
return a->m_iDownloadPriorityGroup > b->m_iDownloadPriorityGroup;
});
}
return m_bActive;
Expand Down Expand Up @@ -1284,7 +1301,7 @@ bool CResource::ExtractFile ( const char * szFilename )
{
// Load the zip file if it isn't already loaded. Return false if it can't be loaded.
if ( !m_zipfile )
m_zipfile = unzOpen(m_strResourceZip.c_str ());
m_zipfile = unzOpenUtf8(m_strResourceZip.c_str ());

if ( !m_zipfile ) return false;

Expand All @@ -1307,7 +1324,7 @@ bool CResource::ExtractFile ( const char * szFilename )
bool CResource::DoesFileExistInZip ( const char * szFilename )
{
if ( !m_zipfile )
m_zipfile = unzOpen(m_strResourceZip.c_str ());
m_zipfile = unzOpenUtf8(m_strResourceZip.c_str ());
bool bRes = false;
if ( m_zipfile )
{
Expand Down Expand Up @@ -1336,7 +1353,7 @@ bool CResource::GetFilePath ( const char * szFilename, string& strPath )
{
// first, check the resource folder, then check the zip file
strPath = m_strResourceDirectoryPath + szFilename;
FILE * temp = fopen ( strPath.c_str (), "r" );
FILE * temp = File::Fopen ( strPath.c_str (), "r" );
if ( temp )
{
fclose ( temp );
Expand All @@ -1351,13 +1368,13 @@ bool CResource::GetFilePath ( const char * szFilename, string& strPath )
return false;

if ( !m_zipfile )
m_zipfile = unzOpen(m_strResourceZip.c_str ());
m_zipfile = unzOpenUtf8(m_strResourceZip.c_str ());
if ( m_zipfile )
{
if ( unzLocateFile ( m_zipfile, szFilename, false ) != UNZ_END_OF_LIST_OF_FILE )
{
strPath = m_strResourceCachePath + szFilename;
temp = fopen ( strPath.c_str (), "r" );
temp = File::Fopen ( strPath.c_str (), "r" );
if ( temp )
{
fclose ( temp );
Expand Down Expand Up @@ -2128,7 +2145,7 @@ bool CResource::RemoveFile ( const char* szName )
// Delete the file
char szFullFilepath [MAX_PATH + 1];
snprintf ( szFullFilepath, MAX_PATH, "%s%s", m_strResourceDirectoryPath.c_str (), szName );
if ( unlink ( szFullFilepath ) != 0 )
if ( File::Delete ( szFullFilepath ) != 0 )
CLogger::LogPrintf ( "WARNING: Problems deleting the actual file, but was removed from resource" );

// Delete the metafile
Expand Down Expand Up @@ -3328,7 +3345,7 @@ int do_extract_currentfile(unzFile uf,const int* popt_extract_without_path,int*p

if ((skip==0) && (err==UNZ_OK))
{
fout=fopen(szOutFile,"wb");
fout=File::Fopen(szOutFile,"wb");

/* some zipfile don't contain directory alone before file */
if ((fout==NULL) && ((*popt_extract_without_path)==0) &&
Expand All @@ -3339,7 +3356,7 @@ int do_extract_currentfile(unzFile uf,const int* popt_extract_without_path,int*p
*(filename_withoutpath-1)='\0';
//makedir((char *)write_filename);
*(filename_withoutpath-1)=c;
fout=fopen(szOutFile,"wb");
fout=File::Fopen(szOutFile,"wb");
}

if (fout==NULL)
Expand Down
Loading