From 95a106600418e70be89f3201baaa44376453c209 Mon Sep 17 00:00:00 2001 From: Daniel Gibson Date: Sun, 17 Mar 2013 22:06:50 +0100 Subject: [PATCH] prepare unification of more sys/win32/ and sys/posix/ stuff because the code is almost the same anyway, so * add win32 support to sys/posix/posix_signin.cpp * add posix support to sys/win32/win_savegame.cpp --- neo/sys/posix/posix_session_local.cpp | 3 +++ neo/sys/posix/posix_signin.cpp | 9 +++++++-- neo/sys/win32/win_savegame.cpp | 28 ++++++++++++++++++++++++++- 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/neo/sys/posix/posix_session_local.cpp b/neo/sys/posix/posix_session_local.cpp index 0a34773a..927d5829 100644 --- a/neo/sys/posix/posix_session_local.cpp +++ b/neo/sys/posix/posix_session_local.cpp @@ -402,10 +402,13 @@ void idSessionLocalWin::Connect_f( const idCmdArgs& args ) lobbyConnectInfo_t connectInfo; Sys_StringToNetAdr( args.Argv( 1 ), &connectInfo.netAddr, true ); + // DG: don't use net_port to select port to connect to + // the port can be specified in the command, else the default port is used if( connectInfo.netAddr.port == 0 ) { connectInfo.netAddr.port = 27015; } + // DG end ConnectAndMoveToLobby( GetPartyLobby(), connectInfo, false ); } diff --git a/neo/sys/posix/posix_signin.cpp b/neo/sys/posix/posix_signin.cpp index 95866b1d..4d0bb22c 100644 --- a/neo/sys/posix/posix_signin.cpp +++ b/neo/sys/posix/posix_signin.cpp @@ -31,9 +31,9 @@ If you have questions concerning this license or the applicable additional terms #include "../../framework/PlayerProfile.h" #include "../sys_session_local.h" #include "posix_signin.h" - +#ifndef _WIN32 #include - +#endif #ifdef _DEBUG idCVar win_userPersistent( "win_userPersistent", "1", CVAR_BOOL, "debugging cvar for profile persistence status" ); idCVar win_userOnline( "win_userOnline", "1", CVAR_BOOL, "debugging cvar for profile online status" ); @@ -117,7 +117,12 @@ void idSignInManagerWin::RegisterLocalUser( int inputDevice ) if( idStr::Length( nameSource ) == 0 ) { // ui_name was empty => default to hostname +#ifdef _WIN32 + DWORD len = 128; + ::GetComputerName( machineName, &len ); +#else gethostname( machineName, sizeof( machineName ) ); +#endif nameSource = machineName; } // DG end diff --git a/neo/sys/win32/win_savegame.cpp b/neo/sys/win32/win_savegame.cpp index 0af0989b..c6f5b8e2 100644 --- a/neo/sys/win32/win_savegame.cpp +++ b/neo/sys/win32/win_savegame.cpp @@ -38,6 +38,11 @@ extern idCVar savegame_error; #define SAVEGAME_SENTINAL 0x12358932 +// RB begin +#ifndef _WIN32 // DG: unify win32 and posix savegames +#define ERROR_SUCCESS 0 +#endif +// RB end /* ======================== void Sys_ExecuteSavegameCommandAsync @@ -176,7 +181,11 @@ int idSaveGameThread::Save() idFile* outputFile = fileSystem->OpenFileWrite( tempFileName, "fs_savePath" ); if( outputFile == NULL ) { +#ifdef _WIN32 // DG: unify windows and posix savegames => replace GetLastError with strerror(errno) idLib::Warning( "[%s]: Couldn't open file for writing, %s. Error = %08x", __FUNCTION__, tempFileName.c_str(), GetLastError() ); +#else + idLib::Warning( "[%s]: Couldn't open file for writing, %s. Error = %s", __FUNCTION__, tempFileName.c_str(), strerror( errno ) ); +#endif // DG end file->error = true; callback->errorCode = SAVEGAME_E_UNKNOWN; ret = -1; @@ -194,7 +203,11 @@ int idSaveGameThread::Save() { if( ( size_t )outputFile->Write( block.data, block.bytes ) != block.bytes ) { +#ifdef _WIN32 // DG: unify windows and posix savegames => replace GetLastError with strerror(errno) idLib::Warning( "[%s]: Write failed. Error = %08x", __FUNCTION__, GetLastError() ); +#else + idLib::Warning( "[%s]: Write failed. Error = %s", __FUNCTION__, strerror( errno ) ); +#endif // DG end file->error = true; callback->errorCode = SAVEGAME_E_INSUFFICIENT_ROOM; ret = -1; @@ -214,7 +227,11 @@ int idSaveGameThread::Save() size_t size = outputFile->WriteBig( checksum ); if( size != sizeof( checksum ) ) { +#ifdef _WIN32 // DG: unify windows and posix savegames => replace GetLastError with strerror(errno) idLib::Warning( "[%s]: Write failed. Error = %08x", __FUNCTION__, GetLastError() ); +#else + idLib::Warning( "[%s]: Write failed. Error = %s", __FUNCTION__, strerror( errno ) ); +#endif // DG end file->error = true; callback->errorCode = SAVEGAME_E_INSUFFICIENT_ROOM; ret = -1; @@ -225,7 +242,11 @@ int idSaveGameThread::Save() size_t size = outputFile->Write( file->GetDataPtr(), file->Length() ); if( size != ( size_t )file->Length() ) { +#ifdef _WIN32 // DG: unify windows and posix savegames => replace GetLastError with strerror(errno) idLib::Warning( "[%s]: Write failed. Error = %08x", __FUNCTION__, GetLastError() ); +#else + idLib::Warning( "[%s]: Write failed. Error = %s", __FUNCTION__, strerror( errno ) ); +#endif // DG end file->error = true; callback->errorCode = SAVEGAME_E_INSUFFICIENT_ROOM; ret = -1; @@ -473,7 +494,7 @@ int idSaveGameThread::Enumerate() ret = -1; } } - +#ifdef _WIN32 // DG: unification of win32 and posix savagame code // Use the date from the directory WIN32_FILE_ATTRIBUTE_DATA attrData; BOOL attrRet = GetFileAttributesEx( file->GetFullPath(), GetFileExInfoStandard, &attrData ); @@ -500,6 +521,11 @@ int idSaveGameThread::Enumerate() itime.QuadPart /= second; details->date = itime.QuadPart; } +#else + // DG: just use the idFile object's timestamp - the windows code gets file attributes and + // other complicated stuff like that.. I'm wonderin what that was good for.. this seems to work. + details->date = file->Timestamp(); +#endif // DG end } else {