| 545 | // added extra param so behind-the-scenes copying in savegames doesn't clutter up the screen -slc |
| 546 | void FS_CopyFile( char *fromOSPath, char *toOSPath, qboolean qbSilent = qfalse ); |
| 547 | void FS_CopyFile( char *fromOSPath, char *toOSPath, qboolean qbSilent ) { |
| 548 | FILE *f; |
| 549 | int len; |
| 550 | byte *buf; |
| 551 | |
| 552 | FS_CheckFilenameIsMutable( fromOSPath, __func__ ); |
| 553 | |
| 554 | if ( !qbSilent ) |
| 555 | Com_Printf( "copy %s to %s\n", fromOSPath, toOSPath ); |
| 556 | |
| 557 | f = fopen( fromOSPath, "rb" ); |
| 558 | if ( !f ) { |
| 559 | return; |
| 560 | } |
| 561 | fseek (f, 0, SEEK_END); |
| 562 | len = ftell (f); |
| 563 | fseek (f, 0, SEEK_SET); |
| 564 | |
| 565 | if ( len == EOF ) |
| 566 | { |
| 567 | fclose( f ); |
| 568 | if ( qbSilent ) |
| 569 | return; |
| 570 | Com_Error( ERR_FATAL, "Bad file length in FS_CopyFile()" ); |
| 571 | } |
| 572 | |
| 573 | // we are using direct malloc instead of Z_Malloc here, so it |
| 574 | // probably won't work on a mac... Its only for developers anyway... |
| 575 | buf = (unsigned char *)malloc( len ); |
| 576 | if (fread( buf, 1, len, f ) != (size_t)len) |
| 577 | { |
| 578 | fclose( f ); |
| 579 | free ( buf ); |
| 580 | if ( qbSilent ) |
| 581 | return; |
| 582 | Com_Error( ERR_FATAL, "Short read in FS_Copyfiles()\n" ); |
| 583 | } |
| 584 | fclose( f ); |
| 585 | |
| 586 | if( FS_CreatePath( toOSPath ) ) { |
| 587 | free ( buf ); |
| 588 | return; |
| 589 | } |
| 590 | |
| 591 | f = fopen( toOSPath, "wb" ); |
| 592 | if ( !f ) { |
| 593 | free ( buf ); |
| 594 | return; |
| 595 | } |
| 596 | if (fwrite( buf, 1, len, f ) != (size_t)len) |
| 597 | { |
| 598 | fclose( f ); |
| 599 | free ( buf ); |
| 600 | if ( qbSilent ) |
| 601 | return; |
| 602 | Com_Error( ERR_FATAL, "Short write in FS_Copyfiles()\n" ); |
| 603 | } |
| 604 | fclose( f ); |
no test coverage detected