diff --git a/utils/mdldec/qc.c b/utils/mdldec/qc.c index e6f6da90..bf78af70 100644 --- a/utils/mdldec/qc.c +++ b/utils/mdldec/qc.c @@ -22,6 +22,8 @@ GNU General Public License for more details. #include "version.h" #include "mdldec.h" #include "utils.h" +#include "smd.h" +#include "texture.h" #include "qc.h" static char **activity_names; @@ -62,7 +64,7 @@ qboolean LoadActivityList( const char *appname ) if( !fp ) { - fputs( "ERROR: Can't open file " ACTIVITIES_FILE ".\n", stderr ); + fputs( "ERROR: Couldn't open file " ACTIVITIES_FILE ".\n", stderr ); return false; } } @@ -474,11 +476,11 @@ static void WriteSequenceInfo( FILE *fp ) if( seqdesc->numblends > 1 ) { for( j = 0; j < seqdesc->numblends; j++ ) - fprintf( fp, "\t\"%s_blend%02i\"\n", seqdesc->label, j + 1 ); + fprintf( fp, "\t\"" DEFAULT_SEQUENCEPATH "%s_blend%02i\"\n", seqdesc->label, j + 1 ); } else { - fprintf( fp, "\t\"%s\"\n", seqdesc->label ); + fprintf( fp, "\t\"" DEFAULT_SEQUENCEPATH "%s\"\n", seqdesc->label ); } if( seqdesc->activity ) @@ -565,7 +567,7 @@ void WriteQCScript( void ) if( len == -1 ) { - fprintf( stderr, "ERROR: Destination path is too long. Can't write %s.qc\n", modelfile ); + fprintf( stderr, "ERROR: Destination path is too long. Couldn't write %s.qc\n", modelfile ); return; } @@ -573,7 +575,7 @@ void WriteQCScript( void ) if( !fp ) { - fprintf( stderr, "ERROR: Can't write %s\n", filename ); + fprintf( stderr, "ERROR: Couldn't write %s\n", filename ); return; } @@ -594,7 +596,7 @@ void WriteQCScript( void ) fprintf( fp, "$modelname \"%s.mdl\"\n", modelfile ); fputs( "$cd \".\"\n", fp ); - fputs( "$cdtexture \".\"\n", fp ); + fputs( "$cdtexture \"./" DEFAULT_TEXTUREPATH "\"\n", fp ); fputs( "$cliptotextures\n", fp ); fputs( "$scale 1.0\n", fp ); fputs( "\n", fp ); diff --git a/utils/mdldec/smd.c b/utils/mdldec/smd.c index 236324af..a21260db 100644 --- a/utils/mdldec/smd.c +++ b/utils/mdldec/smd.c @@ -23,6 +23,7 @@ GNU General Public License for more details. #include "studio.h" #include "mdldec.h" #include "smd.h" +#include "utils.h" static matrix3x4 *bonetransform; static matrix3x4 *worldtransform; @@ -520,7 +521,7 @@ static void WriteReferences( void ) if( len == -1 ) { - fprintf( stderr, "ERROR: Destination path is too long. Can't write %s.smd\n", model->name ); + fprintf( stderr, "ERROR: Destination path is too long. Couldn't write %s.smd\n", model->name ); goto _fail; } @@ -528,7 +529,7 @@ static void WriteReferences( void ) if( !fp ) { - fprintf( stderr, "ERROR: Can't write %s\n", filename ); + fprintf( stderr, "ERROR: Couldn't write %s\n", filename ); goto _fail; } @@ -559,31 +560,41 @@ WriteSequences static void WriteSequences( void ) { int i, j; - int len; + int len, namelen, emptyplace; FILE *fp; - char filename[MAX_SYSPATH]; + char path[MAX_SYSPATH]; mstudioseqdesc_t *seqdesc = (mstudioseqdesc_t *)( (byte *)model_hdr + model_hdr->seqindex ); + len = Q_snprintf( path, MAX_SYSPATH, "%s" DEFAULT_SEQUENCEPATH, destdir ); + + if( len == -1 || !MakeDirectory( path )) + { + fputs( "ERROR: Destination path is too long or write permission denied. Couldn't create directory for sequences\n", stderr ); + return; + } + + emptyplace = MAX_SYSPATH - len; + for( i = 0; i < model_hdr->numseq; ++i, ++seqdesc ) { for( j = 0; j < seqdesc->numblends; j++ ) { if( seqdesc->numblends == 1 ) - len = Q_snprintf( filename, MAX_SYSPATH, "%s%s.smd", destdir, seqdesc->label ); + namelen = Q_snprintf( &path[len], emptyplace, "%s.smd", seqdesc->label ); else - len = Q_snprintf( filename, MAX_SYSPATH, "%s%s_blend%02i.smd", destdir, seqdesc->label, j + 1 ); + namelen = Q_snprintf( &path[len], emptyplace, "%s_blend%02i.smd", seqdesc->label, j + 1 ); - if( len == -1 ) + if( namelen == -1 ) { - fprintf( stderr, "ERROR: Destination path is too long. Can't write %s.smd\n", seqdesc->label ); + fprintf( stderr, "ERROR: Destination path is too long. Couldn't write %s.smd\n", seqdesc->label ); return; } - fp = fopen( filename, "w" ); + fp = fopen( path, "w" ); if( !fp ) { - fprintf( stderr, "ERROR: Can't write %s\n", filename ); + fprintf( stderr, "ERROR: Couldn't write %s\n", path ); return; } @@ -594,7 +605,7 @@ static void WriteSequences( void ) fclose( fp ); - printf( "Sequence: %s\n", filename ); + printf( "Sequence: %s\n", path ); } } } diff --git a/utils/mdldec/smd.h b/utils/mdldec/smd.h index 2bcdcadb..295e3cc4 100644 --- a/utils/mdldec/smd.h +++ b/utils/mdldec/smd.h @@ -16,6 +16,8 @@ GNU General Public License for more details. #ifndef SMD_H #define SMD_H +#define DEFAULT_SEQUENCEPATH "anims/" + void WriteSMD( void ); #endif // SMD_H diff --git a/utils/mdldec/texture.c b/utils/mdldec/texture.c index 7736c660..42ddf560 100644 --- a/utils/mdldec/texture.c +++ b/utils/mdldec/texture.c @@ -23,6 +23,7 @@ GNU General Public License for more details. #include "img_tga.h" #include "mdldec.h" #include "texture.h" +#include "utils.h" /* ============ @@ -130,27 +131,37 @@ WriteTextures */ void WriteTextures( void ) { - int i, len; + int i, len, namelen, emptyplace; FILE *fp; mstudiotexture_t *texture = (mstudiotexture_t *)( (byte *)texture_hdr + texture_hdr->textureindex ); - char filename[MAX_SYSPATH]; + char path[MAX_SYSPATH]; + + len = Q_snprintf( path, MAX_SYSPATH, "%s" DEFAULT_TEXTUREPATH, destdir ); + + if( len == -1 || !MakeDirectory( path )) + { + fputs( "ERROR: Destination path is too long or write permission denied. Couldn't create directory for textures\n", stderr ); + return; + } + + emptyplace = MAX_SYSPATH - len; for( i = 0; i < texture_hdr->numtextures; ++i, ++texture ) { - len = Q_snprintf( filename, MAX_SYSPATH, "%s%s", destdir, texture->name ); + namelen = Q_strncpy( &path[len], texture->name, emptyplace ); - if( len == -1 ) + if( emptyplace - namelen < 0 ) { - fprintf( stderr, "ERROR: Destination path is too long. Can't write %s\n", texture->name ); - continue; + fprintf( stderr, "ERROR: Destination path is too long. Couldn't write %s\n", texture->name ); + return; } - fp = fopen( filename, "wb" ); + fp = fopen( path, "wb" ); if( !fp ) { - fprintf( stderr, "ERROR: Can't write texture file %s\n", filename ); - continue; + fprintf( stderr, "ERROR: Couldn't write texture file %s\n", path ); + return; } if( !Q_stricmp( COM_FileExtension( texture->name ), "tga" )) @@ -160,7 +171,7 @@ void WriteTextures( void ) fclose( fp ); - printf( "Texture: %s\n", filename ); + printf( "Texture: %s\n", path ); } } diff --git a/utils/mdldec/texture.h b/utils/mdldec/texture.h index ba1cbe0b..da067e34 100644 --- a/utils/mdldec/texture.h +++ b/utils/mdldec/texture.h @@ -16,6 +16,8 @@ GNU General Public License for more details. #ifndef TEXTURE_H #define TEXTURE_H +#define DEFAULT_TEXTUREPATH "textures/" + void WriteTextures( void ); #endif // TEXTURE_H