Browse Source

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

pull/2/head
Andrey Akhmichin 2 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 ) @@ -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 ) @@ -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 )
{

16
utils/mdldec/utils.c

@ -18,22 +18,22 @@ GNU General Public License for more details. @@ -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 ) @@ -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 ) @@ -71,7 +71,7 @@ byte *LoadFile( const char *filename )
if( !fp )
return NULL;
size = GetFileSize( fp );
size = GetSizeOfFile( fp );
buf = malloc( size );

4
utils/mdldec/utils.h

@ -16,8 +16,8 @@ GNU General Public License for more details. @@ -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

Loading…
Cancel
Save