From 108705d31f2ec782265fd57625a5244bc8c99662 Mon Sep 17 00:00:00 2001 From: Tim Angus Date: Sat, 7 Nov 2009 16:43:02 +0000 Subject: [PATCH] * Rewrite win32 Sys_Mkdir to use CreateDirectory * Make FS_ReplaceSeparators filter out runs of multiple separators * Make FS_CreatePath skip creation of the root directory --- code/qcommon/files.c | 31 ++++++++++++++++++++++++------- code/sys/sys_win32.c | 9 +++++---- 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/code/qcommon/files.c b/code/qcommon/files.c index f38d0659..f5d83419 100644 --- a/code/qcommon/files.c +++ b/code/qcommon/files.c @@ -437,10 +437,18 @@ Fix things up differently for win/unix/mac */ static void FS_ReplaceSeparators( char *path ) { char *s; + qboolean lastCharWasSep = qfalse; for ( s = path ; *s ; s++ ) { if ( *s == '/' || *s == '\\' ) { - *s = PATH_SEP; + if ( !lastCharWasSep ) { + *s = PATH_SEP; + lastCharWasSep = qtrue; + } else { + memmove (s, s + 1, strlen (s)); + } + } else { + lastCharWasSep = qfalse; } } } @@ -464,7 +472,7 @@ char *FS_BuildOSPath( const char *base, const char *game, const char *qpath ) { } Com_sprintf( temp, sizeof(temp), "/%s/%s", game, qpath ); - FS_ReplaceSeparators( temp ); + FS_ReplaceSeparators( temp ); Com_sprintf( ospath[toggle], sizeof( ospath[0] ), "%s%s", base, temp ); return ospath[toggle]; @@ -480,6 +488,7 @@ Creates any directories needed to store the given filename */ qboolean FS_CreatePath (char *OSPath) { char *ofs; + char path[MAX_OSPATH]; // make absolutely sure that it can't back up the path // FIXME: is c: allowed??? @@ -488,17 +497,25 @@ qboolean FS_CreatePath (char *OSPath) { return qtrue; } - for (ofs = OSPath+1 ; *ofs ; ofs++) { - if (*ofs == PATH_SEP) { + Q_strncpyz( path, OSPath, sizeof( path ) ); + FS_ReplaceSeparators( path ); + + // Skip creation of the root directory as it will always be there + ofs = strchr( path, PATH_SEP ); + ofs++; + + for (; ofs != NULL && *ofs ; ofs++) { + if (*ofs == PATH_SEP) { // create the directory *ofs = 0; - if (!Sys_Mkdir (OSPath)) { + if (!Sys_Mkdir (path)) { Com_Error( ERR_FATAL, "FS_CreatePath: failed to create path \"%s\"\n", - OSPath ); + path ); } *ofs = PATH_SEP; } } + return qfalse; } @@ -2970,7 +2987,7 @@ static void FS_CheckPak0( void ) "the correct place and that every file " "in the \"%s\" directory is present and readable", BASEGAME)); - Com_Error(ERR_FATAL, errorText); + Com_Error(ERR_FATAL, "%s", errorText); } if(foundPak & 1) diff --git a/code/sys/sys_win32.c b/code/sys/sys_win32.c index 6c6ac0d7..c4285336 100644 --- a/code/sys/sys_win32.c +++ b/code/sys/sys_win32.c @@ -273,10 +273,11 @@ Sys_Mkdir */ qboolean Sys_Mkdir( const char *path ) { - int result = _mkdir( path ); - - if( result != 0 ) - return errno == EEXIST; + if( !CreateDirectory( path, NULL ) ) + { + if( GetLastError( ) != ERROR_ALREADY_EXISTS ) + return qfalse; + } return qtrue; }