Browse Source

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

pull/2/head
Andrey Akhmichin 3 years ago committed by a1batross
parent
commit
cbcb90638b
  1. 6
      utils/mdldec/mdldec.c
  2. 16
      utils/mdldec/utils.c
  3. 4
      utils/mdldec/utils.h

6
utils/mdldec/mdldec.c

@ -164,9 +164,9 @@ static qboolean LoadMDL( const char *modelname )
if( destdir[0] != '\0' ) 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; return false;
} }
@ -175,7 +175,7 @@ static qboolean LoadMDL( const char *modelname )
else else
COM_ExtractFilePath( modelname, destdir ); COM_ExtractFilePath( modelname, destdir );
len -= 4; // path length without extension len -= ( sizeof( ".mdl" ) - 1 ); // path length without extension
if( !model_hdr->numtextures ) if( !model_hdr->numtextures )
{ {

16
utils/mdldec/utils.c

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

4
utils/mdldec/utils.h

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

Loading…
Cancel
Save