mirror of
https://github.com/UberGames/ioef.git
synced 2025-02-26 05:11:03 +00:00
* 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
This commit is contained in:
parent
0f9a5e09eb
commit
108705d31f
2 changed files with 29 additions and 11 deletions
|
@ -437,10 +437,18 @@ Fix things up differently for win/unix/mac
|
||||||
*/
|
*/
|
||||||
static void FS_ReplaceSeparators( char *path ) {
|
static void FS_ReplaceSeparators( char *path ) {
|
||||||
char *s;
|
char *s;
|
||||||
|
qboolean lastCharWasSep = qfalse;
|
||||||
|
|
||||||
for ( s = path ; *s ; s++ ) {
|
for ( s = path ; *s ; s++ ) {
|
||||||
if ( *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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -480,6 +488,7 @@ Creates any directories needed to store the given filename
|
||||||
*/
|
*/
|
||||||
qboolean FS_CreatePath (char *OSPath) {
|
qboolean FS_CreatePath (char *OSPath) {
|
||||||
char *ofs;
|
char *ofs;
|
||||||
|
char path[MAX_OSPATH];
|
||||||
|
|
||||||
// make absolutely sure that it can't back up the path
|
// make absolutely sure that it can't back up the path
|
||||||
// FIXME: is c: allowed???
|
// FIXME: is c: allowed???
|
||||||
|
@ -488,17 +497,25 @@ qboolean FS_CreatePath (char *OSPath) {
|
||||||
return qtrue;
|
return qtrue;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (ofs = OSPath+1 ; *ofs ; ofs++) {
|
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) {
|
if (*ofs == PATH_SEP) {
|
||||||
// create the directory
|
// create the directory
|
||||||
*ofs = 0;
|
*ofs = 0;
|
||||||
if (!Sys_Mkdir (OSPath)) {
|
if (!Sys_Mkdir (path)) {
|
||||||
Com_Error( ERR_FATAL, "FS_CreatePath: failed to create path \"%s\"\n",
|
Com_Error( ERR_FATAL, "FS_CreatePath: failed to create path \"%s\"\n",
|
||||||
OSPath );
|
path );
|
||||||
}
|
}
|
||||||
*ofs = PATH_SEP;
|
*ofs = PATH_SEP;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return qfalse;
|
return qfalse;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2970,7 +2987,7 @@ static void FS_CheckPak0( void )
|
||||||
"the correct place and that every file "
|
"the correct place and that every file "
|
||||||
"in the \"%s\" directory is present and readable", BASEGAME));
|
"in the \"%s\" directory is present and readable", BASEGAME));
|
||||||
|
|
||||||
Com_Error(ERR_FATAL, errorText);
|
Com_Error(ERR_FATAL, "%s", errorText);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(foundPak & 1)
|
if(foundPak & 1)
|
||||||
|
|
|
@ -273,10 +273,11 @@ Sys_Mkdir
|
||||||
*/
|
*/
|
||||||
qboolean Sys_Mkdir( const char *path )
|
qboolean Sys_Mkdir( const char *path )
|
||||||
{
|
{
|
||||||
int result = _mkdir( path );
|
if( !CreateDirectory( path, NULL ) )
|
||||||
|
{
|
||||||
if( result != 0 )
|
if( GetLastError( ) != ERROR_ALREADY_EXISTS )
|
||||||
return errno == EEXIST;
|
return qfalse;
|
||||||
|
}
|
||||||
|
|
||||||
return qtrue;
|
return qtrue;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue