utils: mdldec: try to create user defined destination directory.

This commit is contained in:
Andrey Akhmichin 2022-06-21 11:32:05 +05:00 committed by a1batross
parent 8211acf4e0
commit cbcb90638b
3 changed files with 13 additions and 13 deletions

View File

@ -164,9 +164,9 @@ static qboolean LoadMDL( const char *modelname )
if( destdir[0] != '\0' )
{
if( !IsFileExists( destdir ) )
if( !MakeDirectory( destdir ) )
{
fprintf( stderr, "ERROR: Couldn't find directory %s\n", destdir );
fprintf( stderr, "ERROR: Couldn't create directory %s\n", destdir );
return false;
}
@ -175,7 +175,7 @@ static qboolean LoadMDL( const char *modelname )
else
COM_ExtractFilePath( modelname, destdir );
len -= 4; // path length without extension
len -= ( sizeof( ".mdl" ) - 1 ); // path length without extension
if( !model_hdr->numtextures )
{

View File

@ -18,22 +18,22 @@ GNU General Public License for more details.
#include <string.h>
#include <sys/stat.h>
#include "xash3d_types.h"
#include "port.h"
#include "crtlib.h"
#include "utils.h"
/*
============
IsFileExists
MakeDirectory
============
*/
qboolean IsFileExists( const char *filename )
qboolean MakeDirectory( const char *path )
{
struct stat st;
int ret;
ret = stat( filename, &st );
if( ret == -1 )
if( -1 == _mkdir( path )
&& ( -1 == stat( path, &st )
|| !S_ISDIR(st.st_mode ) ) )
return false;
return true;
@ -44,7 +44,7 @@ qboolean IsFileExists( const char *filename )
GetFileSize
============
*/
off_t GetFileSize( FILE *fp )
off_t GetSizeOfFile( FILE *fp )
{
struct stat st;
int fd;
@ -71,7 +71,7 @@ byte *LoadFile( const char *filename )
if( !fp )
return NULL;
size = GetFileSize( fp );
size = GetSizeOfFile( fp );
buf = malloc( size );

View File

@ -16,8 +16,8 @@ GNU General Public License for more details.
#ifndef UTILS_H
#define UTILS_H
qboolean IsFileExists( const char *filename );
off_t GetFileSize( FILE *fp );
qboolean MakeDirectory( const char *path );
off_t GetSizeOfFile( FILE *fp );
byte *LoadFile( const char *filename );
#endif // UTILS_H