#endif
};
-bool CopyTree( const char* source, const char* dest );
+bool radCopyTree( const char* source, const char* dest, bool fatal_on_error = true );
typedef enum {
PATH_FAIL, // stat call failed (does not exist is likely)
// check a path for existence, return directory / file
EPathCheck CheckFile( const char *path );
-bool radCreateDirectory( const char *directory );
-bool radCopyFile( const char *lpExistingFileName, const char *lpNewFileName );
+bool radCreateDirectory( const char *directory, bool fatal_on_error = true );
+bool radCopyFile( const char *lpExistingFileName, const char *lpNewFileName, bool fatal_on_error = true );
#endif // _MISSING_H_
#include "missing.h"
#include "qsysprintf.h"
+#include "qe3.h"
#if defined ( __linux__ ) || defined ( __APPLE__ )
#include <stdlib.h>
#include <dirent.h>
-bool radCopyFile( const char *lpExistingFileName, const char *lpNewFileName ){
+bool radCopyFile( const char *lpExistingFileName, const char *lpNewFileName, bool fatal_on_error ){
FILE *src, *dst;
void* buf;
int l;
src = fopen( realsrc, "rb" );
if ( !src ) {
- return false;
+ if ( fatal_on_error ) {
+ Error( "Failed to open source for copy: %s\n", realsrc );
+ }
+ Sys_Printf( "Failed to open source for copy: %s\n", realsrc );
+ return false;
}
dst = fopen( realdest, "wb" );
if ( !dst ) {
- fclose( src );
- return false;
+ if ( fatal_on_error ) {
+ Error( "Failed to open destination for copy: %s\n", realdest );
+ }
+ Sys_Printf( "Failed to open destination for copy: %s\n", realdest );
+ fclose( src );
+ return false;
}
fseek( src, 0, SEEK_END );
}
}
}
+ if ( !ret ) {
+ if ( fatal_on_error ) {
+ Error( "short read or short write while copying %s to %s\n", realsrc, realdest );
+ }
+ Sys_Printf( "short read or short write while copying %s to %s\n", realsrc, realdest );
+ }
g_free( buf );
fclose( src );
return ret;
}
-bool radCreateDirectory( const char *directory ) {
- if ( mkdir( directory, 0777 ) == -1 ) {
- Sys_Printf( "mkdir %s failed\n", directory );
- return false;
- }
- return true;
+bool radCreateDirectory( const char *directory, bool fatal_on_error ) {
+ if ( mkdir( directory, 0777 ) >= 0 ) {
+ return true;
+ }
+ if ( fatal_on_error ) {
+ Error( "mkdir %s failed - check your permissions", directory );
+ }
+ Sys_Printf( "mkdir %s failed - check your permissions\n", directory );
+ return false;
}
int GetFullPathName( const char *lpFileName, int nBufferLength, char *lpBuffer, char **lpFilePart ){
return PATH_FILE;
}
-bool radCreateDirectory( const char *directory ) {
- return ( CreateDirectory( directory, NULL ) != false );
+bool radCreateDirectory( const char *directory, bool fatal_on_error ) {
+ if ( CreateDirectory( directory, NULL ) ) {
+ return true;
+ }
+ if ( fatal_on_error ) {
+ Error( "mkdir %s failed - check your permissions", directory );
+ }
+ Sys_Printf( "mkdir %s failed - check your permissions\n", directory );
+ return false;
}
-bool radCopyFile( const char *lpExistingFileName, const char *lpNewFileName ) {
- return ( CopyFile( lpExistingFileName, lpNewFileName, FALSE ) != false );
+bool radCopyFile( const char *lpExistingFileName, const char *lpNewFileName, bool fatal_on_error ) {
+ if ( CopyFile( lpExistingFileName, lpNewFileName, FALSE ) ) {
+ return true;
+ }
+ if ( fatal_on_error ) {
+ Error( "copy %s %s failed - check your permissions", lpExistingFileName, lpNewFileName );
+ }
+ Sys_Printf( "copy %s %s failed - check your permissions\n", lpExistingFileName, lpNewFileName );
+ return false;
}
#endif
-bool CopyTree( const char *source, const char *dest ) {
+bool radCopyTree( const char *source, const char *dest, bool fatal_on_error ) {
Str srcEntry;
Str dstEntry;
const char *dirname;
dstEntry += "/";
dstEntry += dirname;
switch ( CheckFile( srcEntry.GetBuffer() ) ) {
+ case PATH_FAIL: {
+ if ( fatal_on_error ) {
+ Error( "%s does not exist. check your permissions", srcEntry.GetBuffer() );
+ }
+ }
case PATH_DIRECTORY: {
if ( CheckFile( dstEntry.GetBuffer() ) == PATH_FAIL ) {
- if ( !radCreateDirectory( dstEntry.GetBuffer() ) ) {
- Sys_Printf( "create directory %s failed\n", dstEntry.GetBuffer() );
+ Sys_Printf( "Create directory %s\n", dstEntry.GetBuffer() );
+ if ( !radCreateDirectory( dstEntry.GetBuffer(), fatal_on_error ) ) {
return false;
}
}
bool ret;
- ret = CopyTree( srcEntry.GetBuffer(), dstEntry.GetBuffer() );
+ ret = radCopyTree( srcEntry.GetBuffer(), dstEntry.GetBuffer(), fatal_on_error );
if ( !ret ) {
return false;
}
break;
}
case PATH_FILE: {
- Sys_Printf( "copy %s -> %s\n", srcEntry.GetBuffer(), dstEntry.GetBuffer() );
- bool ret = radCopyFile( srcEntry.GetBuffer(), dstEntry.GetBuffer() );
+ Sys_Printf( "Copy %s -> %s\n", srcEntry.GetBuffer(), dstEntry.GetBuffer() );
+ bool ret = radCopyFile( srcEntry.GetBuffer(), dstEntry.GetBuffer(), fatal_on_error );
if ( !ret ) {
return false;
}
// write out the game file
Str gameFilePath = g_strAppPath.GetBuffer();
gameFilePath += "games/";
- if(CheckFile(gameFilePath) != PATH_DIRECTORY) {
- radCreateDirectory(gameFilePath);
+ if ( CheckFile( gameFilePath ) != PATH_DIRECTORY ) {
+ radCreateDirectory( gameFilePath );
}
switch ( m_availGames[ m_nComboSelect ] ) {
source += Q2_PACK;
source += "/install/";
Str dest = m_strEngine.GetBuffer();
- CopyTree( source.GetBuffer(), dest.GetBuffer() );
+ radCopyTree( source.GetBuffer(), dest.GetBuffer() );
fprintf( fg, " basegame=\"baseq2\"\n" );
break;
}
source += Q3_PACK;
source += "/install/";
Str dest = m_strEngine.GetBuffer();
- CopyTree( source.GetBuffer(), dest.GetBuffer() );
+ radCopyTree( source.GetBuffer(), dest.GetBuffer() );
// Hardcoded fix for "missing" shaderlist in gamepack
dest += "/baseq3/scripts/shaderlist.txt";
if(CheckFile(dest.GetBuffer()) != PATH_FILE) {
source += URT_PACK;
source += "/install/";
Str dest = m_strEngine.GetBuffer();
- CopyTree( source.GetBuffer(), dest.GetBuffer() );
+ radCopyTree( source.GetBuffer(), dest.GetBuffer() );
fprintf( fg, " basegame=\"q3ut4\"\n" );
break;
}
source += UFOAI_PACK;
source += "/install/";
Str dest = m_strEngine.GetBuffer();
- CopyTree( source.GetBuffer(), dest.GetBuffer() );
+ radCopyTree( source.GetBuffer(), dest.GetBuffer() );
fprintf( fg, " basegame=\"base\"\n" );
break;
}
source += Q2W_PACK;
source += "/install/";
Str dest = m_strEngine.GetBuffer();
- CopyTree( source.GetBuffer(), dest.GetBuffer() );
+ radCopyTree( source.GetBuffer(), dest.GetBuffer() );
fprintf( fg, " basegame=\"default\"\n" );
break;
}
source += WARSOW_PACK;
source += "/install/";
Str dest = m_strEngine.GetBuffer();
- CopyTree( source.GetBuffer(), dest.GetBuffer() );
+ radCopyTree( source.GetBuffer(), dest.GetBuffer() );
fprintf( fg, " basegame=\"basewsw\"\n" );
break;
}
source += NEXUIZ_PACK;
source += "/install/";
Str dest = m_strEngine.GetBuffer();
- CopyTree( source.GetBuffer(), dest.GetBuffer() );
+ radCopyTree( source.GetBuffer(), dest.GetBuffer() );
fprintf( fg, " basegame=\"data\"\n" );
break;
}
source += TREMULOUS_PACK;
source += "/install/";
Str dest = m_strEngine.GetBuffer();
- CopyTree( source.GetBuffer(), dest.GetBuffer() );
+ radCopyTree( source.GetBuffer(), dest.GetBuffer() );
fprintf( fg, " basegame=\"base\"\n" );
break;
}
source += JA_PACK;
source += "/install/";
Str dest = m_strEngine.GetBuffer();
- CopyTree( source.GetBuffer(), dest.GetBuffer() );
+ radCopyTree( source.GetBuffer(), dest.GetBuffer() );
fprintf( fg, " basegame=\"base\"\n" );
break;
}
source += REACTION_PACK;
source += "/install/";
Str dest = m_strEngine.GetBuffer();
- CopyTree( source.GetBuffer(), dest.GetBuffer() );
+ radCopyTree( source.GetBuffer(), dest.GetBuffer() );
fprintf( fg, " basegame=\"Boomstick\"\n" );
fprintf( fg, " default_scale=\"0.5\"\n" ); // Superfluous because the default is already 0.5,
// but demonstrates how to set the default texture scale
source += ET_PACK;
source += "/install/";
Str dest = m_strEngine.GetBuffer();
- CopyTree( source.GetBuffer(), dest.GetBuffer() );
+ radCopyTree( source.GetBuffer(), dest.GetBuffer() );
// Hardcoded fix for "missing" shaderlist in gamepack
dest += "/etmain/scripts/shaderlist.txt";
if(CheckFile(dest.GetBuffer()) != PATH_FILE) {