[iortcw] 129/152: All: Offer post-crash safe settings on a per-mod basis
Simon McVittie
smcv at debian.org
Fri Sep 8 10:40:23 UTC 2017
This is an automated email from the git hooks/post-receive script.
smcv pushed a commit to annotated tag 1.5a
in repository iortcw.
commit f69dd5fb9f0772d46a71e764c3be08d563550ed5
Author: MAN-AT-ARMS <M4N4T4RMS at gmail.com>
Date: Fri Oct 14 19:42:04 2016 -0400
All: Offer post-crash safe settings on a per-mod basis
---
MP/code/qcommon/common.c | 12 +---------
MP/code/qcommon/files.c | 54 +++++++++++++++++++++++++++-----------------
MP/code/qcommon/qcommon.h | 5 ++++-
MP/code/sys/sys_main.c | 57 +++++++++++++++++++++++++++++++++++++++--------
SP/code/qcommon/common.c | 12 +---------
SP/code/qcommon/files.c | 54 +++++++++++++++++++++++++++-----------------
SP/code/qcommon/qcommon.h | 5 ++++-
SP/code/sys/sys_main.c | 57 +++++++++++++++++++++++++++++++++++++++--------
8 files changed, 174 insertions(+), 82 deletions(-)
diff --git a/MP/code/qcommon/common.c b/MP/code/qcommon/common.c
index 5a1c88b..cb6a8a4 100644
--- a/MP/code/qcommon/common.c
+++ b/MP/code/qcommon/common.c
@@ -2855,17 +2855,7 @@ void Com_Init( char *commandLine ) {
Sys_Init();
- if( Sys_WritePIDFile( ) ) {
-#ifndef DEDICATED
- const char *message = "The last time " CLIENT_WINDOW_TITLE " ran, "
- "it didn't exit properly. This may be due to inappropriate video "
- "settings. Would you like to start with \"safe\" video settings?";
-
- if( Sys_Dialog( DT_YES_NO, message, "Abnormal Exit" ) == DR_YES ) {
- Cvar_Set( "com_abnormalExit", "1" );
- }
-#endif
- }
+ Sys_InitPIDFile( FS_GetCurrentGameDir() );
// Pick a random port value
Com_RandomBytes( (byte*)&qport, sizeof(int) );
diff --git a/MP/code/qcommon/files.c b/MP/code/qcommon/files.c
index 2ccbf32..174540b 100644
--- a/MP/code/qcommon/files.c
+++ b/MP/code/qcommon/files.c
@@ -2715,6 +2715,33 @@ static char** Sys_ConcatenateFileLists( char **list0, char **list1 )
/*
================
+FS_GetModDescription
+================
+*/
+void FS_GetModDescription( const char *modDir, char *description, int descriptionLen ) {
+ fileHandle_t descHandle;
+ char descPath[MAX_QPATH];
+ int nDescLen;
+ FILE *file;
+
+ Com_sprintf( descPath, sizeof ( descPath ), "%s/description.txt", modDir );
+ nDescLen = FS_SV_FOpenFileRead( descPath, &descHandle );
+
+ if ( nDescLen > 0 && descHandle ) {
+ file = FS_FileForHandle(descHandle);
+ Com_Memset( description, 0, descriptionLen );
+ nDescLen = fread(description, 1, descriptionLen, file);
+ if (nDescLen >= 0) {
+ description[nDescLen] = '\0';
+ }
+ FS_FCloseFile(descHandle);
+ } else {
+ Q_strncpyz( description, modDir, descriptionLen );
+ }
+}
+
+/*
+================
FS_GetModList
Returns a list of mod directory names
@@ -2727,8 +2754,7 @@ int FS_GetModList( char *listbuf, int bufsize ) {
char **pFiles = NULL;
char **pPaks = NULL;
char *name, *path;
- char descPath[MAX_OSPATH];
- fileHandle_t descHandle;
+ char description[MAX_OSPATH];
int dummy;
char **pFiles0 = NULL;
@@ -2813,28 +2839,13 @@ int FS_GetModList( char *listbuf, int bufsize ) {
nLen = strlen(name) + 1;
// nLen is the length of the mod path
// we need to see if there is a description available
- descPath[0] = '\0';
- strcpy(descPath, name);
- strcat(descPath, "/description.txt");
- nDescLen = FS_SV_FOpenFileRead( descPath, &descHandle );
- if ( nDescLen > 0 && descHandle) {
- FILE *file;
- file = FS_FileForHandle(descHandle);
- Com_Memset( descPath, 0, sizeof( descPath ) );
- nDescLen = fread(descPath, 1, 48, file);
- if (nDescLen >= 0) {
- descPath[nDescLen] = '\0';
- }
- FS_FCloseFile(descHandle);
- } else {
- strcpy(descPath, name);
- }
- nDescLen = strlen(descPath) + 1;
+ FS_GetModDescription( name, description, sizeof( description ) );
+ nDescLen = strlen(description) + 1;
if (nTotal + nLen + 1 + nDescLen + 1 < bufsize) {
strcpy(listbuf, name);
listbuf += nLen;
- strcpy(listbuf, descPath);
+ strcpy(listbuf, description);
listbuf += nDescLen;
nTotal += nLen + nDescLen;
nMods++;
@@ -4267,6 +4278,9 @@ void FS_Restart( int checksumFeed ) {
}
if ( Q_stricmp( fs_gamedirvar->string, lastValidGame ) ) {
+ Sys_RemovePIDFile( lastValidGame );
+ Sys_InitPIDFile( fs_gamedirvar->string );
+
// skip the wolfconfig.cfg if "safe" is on the command line
if ( !Com_SafeMode() ) {
Cbuf_AddText("exec " Q3CONFIG_CFG "\n");
diff --git a/MP/code/qcommon/qcommon.h b/MP/code/qcommon/qcommon.h
index 4be7ba2..1f23d0f 100644
--- a/MP/code/qcommon/qcommon.h
+++ b/MP/code/qcommon/qcommon.h
@@ -703,6 +703,8 @@ int FS_LoadStack( void );
int FS_GetFileList( const char *path, const char *extension, char *listbuf, int bufsize );
int FS_GetModList( char *listbuf, int bufsize );
+void FS_GetModDescription( const char *modDir, char *description, int descriptionLen );
+
fileHandle_t FS_FOpenFileWrite( const char *qpath );
fileHandle_t FS_FOpenFileAppend( const char *filename );
fileHandle_t FS_FCreateOpenPipeFile( const char *filename );
@@ -1281,7 +1283,8 @@ typedef enum
dialogResult_t Sys_Dialog( dialogType_t type, const char *message, const char *title );
-qboolean Sys_WritePIDFile( void );
+void Sys_RemovePIDFile( const char *gamedir );
+void Sys_InitPIDFile( const char *gamedir );
/* This is based on the Adaptive Huffman algorithm described in Sayood's Data
* Compression book. The ranks are not actually stored, but implicitly defined
diff --git a/MP/code/sys/sys_main.c b/MP/code/sys/sys_main.c
index 43a1261..b4181da 100644
--- a/MP/code/sys/sys_main.c
+++ b/MP/code/sys/sys_main.c
@@ -167,26 +167,39 @@ char *Sys_GetClipboardData(void)
Sys_PIDFileName
=================
*/
-static char *Sys_PIDFileName( void )
+static char *Sys_PIDFileName( const char *gamedir )
{
const char *homePath = Cvar_VariableString( "fs_homepath" );
if( *homePath != '\0' )
- return va( "%s/%s", homePath, PID_FILENAME );
+ return va( "%s/%s/%s", homePath, gamedir, PID_FILENAME );
return NULL;
}
/*
=================
+Sys_RemovePIDFile
+=================
+*/
+void Sys_RemovePIDFile( const char *gamedir )
+{
+ char *pidFile = Sys_PIDFileName( gamedir );
+
+ if( pidFile != NULL )
+ remove( pidFile );
+}
+
+/*
+=================
Sys_WritePIDFile
Return qtrue if there is an existing stale PID file
=================
*/
-qboolean Sys_WritePIDFile( void )
+static qboolean Sys_WritePIDFile( const char *gamedir )
{
- char *pidFile = Sys_PIDFileName( );
+ char *pidFile = Sys_PIDFileName( gamedir );
FILE *f;
qboolean stale = qfalse;
@@ -212,6 +225,10 @@ qboolean Sys_WritePIDFile( void )
stale = qtrue;
}
+ if( FS_CreatePath( pidFile ) ) {
+ return 0;
+ }
+
if( ( f = fopen( pidFile, "w" ) ) != NULL )
{
fprintf( f, "%d", Sys_PID( ) );
@@ -225,6 +242,31 @@ qboolean Sys_WritePIDFile( void )
/*
=================
+Sys_InitPIDFile
+=================
+*/
+void Sys_InitPIDFile( const char *gamedir ) {
+ if( Sys_WritePIDFile( gamedir ) ) {
+#ifndef DEDICATED
+ char message[1024];
+ char modName[MAX_OSPATH];
+
+ FS_GetModDescription( gamedir, modName, sizeof ( modName ) );
+ Q_CleanStr( modName );
+
+ Com_sprintf( message, sizeof (message), "The last time %s ran, "
+ "it didn't exit properly. This may be due to inappropriate video "
+ "settings. Would you like to start with \"safe\" video settings?", modName );
+
+ if( Sys_Dialog( DT_YES_NO, message, "Abnormal Exit" ) == DR_YES ) {
+ Cvar_Set( "com_abnormalExit", "1" );
+ }
+#endif
+ }
+}
+
+/*
+=================
Sys_Exit
Single exit point (regular exit or in case of error)
@@ -238,13 +280,10 @@ static __attribute__ ((noreturn)) void Sys_Exit( int exitCode )
SDL_Quit( );
#endif
- if( exitCode < 2 )
+ if( exitCode < 2 && com_fullyInitialized )
{
// Normal exit
- char *pidFile = Sys_PIDFileName( );
-
- if( pidFile != NULL )
- remove( pidFile );
+ Sys_RemovePIDFile( FS_GetCurrentGameDir() );
}
NET_Shutdown( );
diff --git a/SP/code/qcommon/common.c b/SP/code/qcommon/common.c
index 966268a..94f0da3 100644
--- a/SP/code/qcommon/common.c
+++ b/SP/code/qcommon/common.c
@@ -2395,17 +2395,7 @@ void Com_Init( char *commandLine ) {
Sys_Init();
- if( Sys_WritePIDFile( ) ) {
-#ifndef DEDICATED
- const char *message = "The last time " CLIENT_WINDOW_TITLE " ran, "
- "it didn't exit properly. This may be due to inappropriate video "
- "settings. Would you like to start with \"safe\" video settings?";
-
- if( Sys_Dialog( DT_YES_NO, message, "Abnormal Exit" ) == DR_YES ) {
- Cvar_Set( "com_abnormalExit", "1" );
- }
-#endif
- }
+ Sys_InitPIDFile( FS_GetCurrentGameDir() );
// Pick a random port value
Com_RandomBytes( (byte*)&qport, sizeof(int) );
diff --git a/SP/code/qcommon/files.c b/SP/code/qcommon/files.c
index eb70384..6cd6706 100644
--- a/SP/code/qcommon/files.c
+++ b/SP/code/qcommon/files.c
@@ -2750,6 +2750,33 @@ static char** Sys_ConcatenateFileLists( char **list0, char **list1 )
/*
================
+FS_GetModDescription
+================
+*/
+void FS_GetModDescription( const char *modDir, char *description, int descriptionLen ) {
+ fileHandle_t descHandle;
+ char descPath[MAX_QPATH];
+ int nDescLen;
+ FILE *file;
+
+ Com_sprintf( descPath, sizeof ( descPath ), "%s/description.txt", modDir );
+ nDescLen = FS_SV_FOpenFileRead( descPath, &descHandle );
+
+ if ( nDescLen > 0 && descHandle ) {
+ file = FS_FileForHandle(descHandle);
+ Com_Memset( description, 0, descriptionLen );
+ nDescLen = fread(description, 1, descriptionLen, file);
+ if (nDescLen >= 0) {
+ description[nDescLen] = '\0';
+ }
+ FS_FCloseFile(descHandle);
+ } else {
+ Q_strncpyz( description, modDir, descriptionLen );
+ }
+}
+
+/*
+================
FS_GetModList
Returns a list of mod directory names
@@ -2762,8 +2789,7 @@ int FS_GetModList( char *listbuf, int bufsize ) {
char **pFiles = NULL;
char **pPaks = NULL;
char *name, *path;
- char descPath[MAX_OSPATH];
- fileHandle_t descHandle;
+ char description[MAX_OSPATH];
int dummy;
char **pFiles0 = NULL;
@@ -2847,28 +2873,13 @@ int FS_GetModList( char *listbuf, int bufsize ) {
nLen = strlen(name) + 1;
// nLen is the length of the mod path
// we need to see if there is a description available
- descPath[0] = '\0';
- strcpy(descPath, name);
- strcat(descPath, "/description.txt");
- nDescLen = FS_SV_FOpenFileRead( descPath, &descHandle );
- if ( nDescLen > 0 && descHandle) {
- FILE *file;
- file = FS_FileForHandle(descHandle);
- Com_Memset( descPath, 0, sizeof( descPath ) );
- nDescLen = fread(descPath, 1, 48, file);
- if (nDescLen >= 0) {
- descPath[nDescLen] = '\0';
- }
- FS_FCloseFile(descHandle);
- } else {
- strcpy(descPath, name);
- }
- nDescLen = strlen(descPath) + 1;
+ FS_GetModDescription( name, description, sizeof( description ) );
+ nDescLen = strlen(description) + 1;
if (nTotal + nLen + 1 + nDescLen + 1 < bufsize) {
strcpy(listbuf, name);
listbuf += nLen;
- strcpy(listbuf, descPath);
+ strcpy(listbuf, description);
listbuf += nDescLen;
nTotal += nLen + nDescLen;
nMods++;
@@ -4278,6 +4289,9 @@ void FS_Restart( int checksumFeed ) {
}
if ( Q_stricmp( fs_gamedirvar->string, lastValidGame ) ) {
+ Sys_RemovePIDFile( lastValidGame );
+ Sys_InitPIDFile( fs_gamedirvar->string );
+
// skip the wolfconfig.cfg if "safe" is on the command line
if ( !Com_SafeMode() ) {
Cbuf_AddText ("exec " Q3CONFIG_CFG "\n");
diff --git a/SP/code/qcommon/qcommon.h b/SP/code/qcommon/qcommon.h
index 707fcd6..f424036 100644
--- a/SP/code/qcommon/qcommon.h
+++ b/SP/code/qcommon/qcommon.h
@@ -675,6 +675,8 @@ int FS_LoadStack( void );
int FS_GetFileList( const char *path, const char *extension, char *listbuf, int bufsize );
int FS_GetModList( char *listbuf, int bufsize );
+void FS_GetModDescription( const char *modDir, char *description, int descriptionLen );
+
fileHandle_t FS_FOpenFileWrite( const char *qpath );
fileHandle_t FS_FOpenFileAppend( const char *filename );
fileHandle_t FS_FCreateOpenPipeFile( const char *filename );
@@ -1188,7 +1190,8 @@ typedef enum
dialogResult_t Sys_Dialog( dialogType_t type, const char *message, const char *title );
-qboolean Sys_WritePIDFile( void );
+void Sys_RemovePIDFile( const char *gamedir );
+void Sys_InitPIDFile( const char *gamedir );
void Sys_StartProcess( char *cmdline, qboolean doexit ); // NERVE - SMF
// TTimo
diff --git a/SP/code/sys/sys_main.c b/SP/code/sys/sys_main.c
index d2c53cb..d24f402 100644
--- a/SP/code/sys/sys_main.c
+++ b/SP/code/sys/sys_main.c
@@ -167,26 +167,39 @@ char *Sys_GetClipboardData(void)
Sys_PIDFileName
=================
*/
-static char *Sys_PIDFileName( void )
+static char *Sys_PIDFileName( const char *gamedir )
{
const char *homePath = Cvar_VariableString( "fs_homepath" );
if( *homePath != '\0' )
- return va( "%s/%s", homePath, PID_FILENAME );
+ return va( "%s/%s/%s", homePath, gamedir, PID_FILENAME );
return NULL;
}
/*
=================
+Sys_RemovePIDFile
+=================
+*/
+void Sys_RemovePIDFile( const char *gamedir )
+{
+ char *pidFile = Sys_PIDFileName( gamedir );
+
+ if( pidFile != NULL )
+ remove( pidFile );
+}
+
+/*
+=================
Sys_WritePIDFile
Return qtrue if there is an existing stale PID file
=================
*/
-qboolean Sys_WritePIDFile( void )
+static qboolean Sys_WritePIDFile( const char *gamedir )
{
- char *pidFile = Sys_PIDFileName( );
+ char *pidFile = Sys_PIDFileName( gamedir );
FILE *f;
qboolean stale = qfalse;
@@ -212,6 +225,10 @@ qboolean Sys_WritePIDFile( void )
stale = qtrue;
}
+ if( FS_CreatePath( pidFile ) ) {
+ return 0;
+ }
+
if( ( f = fopen( pidFile, "w" ) ) != NULL )
{
fprintf( f, "%d", Sys_PID( ) );
@@ -225,6 +242,31 @@ qboolean Sys_WritePIDFile( void )
/*
=================
+Sys_InitPIDFile
+=================
+*/
+void Sys_InitPIDFile( const char *gamedir ) {
+ if( Sys_WritePIDFile( gamedir ) ) {
+#ifndef DEDICATED
+ char message[1024];
+ char modName[MAX_OSPATH];
+
+ FS_GetModDescription( gamedir, modName, sizeof ( modName ) );
+ Q_CleanStr( modName );
+
+ Com_sprintf( message, sizeof (message), "The last time %s ran, "
+ "it didn't exit properly. This may be due to inappropriate video "
+ "settings. Would you like to start with \"safe\" video settings?", modName );
+
+ if( Sys_Dialog( DT_YES_NO, message, "Abnormal Exit" ) == DR_YES ) {
+ Cvar_Set( "com_abnormalExit", "1" );
+ }
+#endif
+ }
+}
+
+/*
+=================
Sys_Exit
Single exit point (regular exit or in case of error)
@@ -238,13 +280,10 @@ static __attribute__ ((noreturn)) void Sys_Exit( int exitCode )
SDL_Quit( );
#endif
- if( exitCode < 2 )
+ if( exitCode < 2 && com_fullyInitialized )
{
// Normal exit
- char *pidFile = Sys_PIDFileName( );
-
- if( pidFile != NULL )
- remove( pidFile );
+ Sys_RemovePIDFile( FS_GetCurrentGameDir() );
}
NET_Shutdown( );
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-games/iortcw.git
More information about the Pkg-games-commits
mailing list