static bool copyResourcesFromRes( const char *full_filename ) /***********************************************************/ { WResFileID fid; WResDir dir; bool dup_discarded; WResDirWindow wind; char *buffer; bool error; buffer = NULL; dir = WResInitDir(); fid = RcIoOpenInput( full_filename, false ); if( fid == WRES_NIL_HANDLE ) { RcError( ERR_CANT_OPEN_FILE, full_filename, strerror( errno ) ); goto HANDLE_ERROR; } error = WResReadDir( fid, dir, &dup_discarded ); if( error ) { switch( LastWresStatus() ) { case WRS_BAD_SIG: RcError( ERR_INVALID_RES, full_filename ); break; case WRS_BAD_VERSION: RcError( ERR_BAD_RES_VER, full_filename ); break; default: RcError( ERR_READING_RES, full_filename, LastWresErrStr() ); break; } goto HANDLE_ERROR; } if( WResGetTargetOS( dir ) != WResGetTargetOS( CurrResFile.dir ) ) { RcError( ERR_RES_OS_MISMATCH, full_filename ); goto HANDLE_ERROR; } buffer = RESALLOC( BUFFER_SIZE ); wind = WResFirstResource( dir ); while( !WResIsEmptyWindow( wind ) ) { copyAResource( fid, &wind, buffer, full_filename ); wind = WResNextResource( wind, dir ); } RESFREE( buffer ); WResFreeDir( dir ); RESCLOSE( fid ); return( false ); HANDLE_ERROR: ErrorHasOccured = true; WResFreeDir( dir ); if( fid != WRES_NIL_HANDLE ) RESCLOSE( fid ); return( true ); }
static int DumpDir( WResDir dir, WResFileID handle ) /**************************************************/ { int retcode; bool error; WResDirWindow wind; uint_16 os; retcode = 0; if( WResIsEmpty( dir ) ) { printf( "Directory in file %s is empty\n", CmdLineParms.FileName ); } else { os = WResGetTargetOS( dir ); wind = WResFirstResource( dir ); while( !WResIsLastResource( wind, dir ) ) { error = DumpResource( wind, handle, os ); if( error ) { retcode = 2; } wind = WResNextResource( wind, dir ); } error = DumpResource( wind, handle, os ); if( error ) { retcode = 2; } } return( retcode ); }
bool WRLoadResourceFrom_RC( WRInfo *info ) { WResTargetOS target_os; WRFileType target; char fn_path[_MAX_PATH]; bool is_wres; bool ok; ok = (info != NULL && info->file_name != NULL); if( ok ) { WRGetInternalRESName( info->file_name, fn_path ); } #ifndef __NT__ if( ok ) { target = WRIdentifyFile( fn_path ); ok = !WRIs32Bit( target ); if( !ok ) { WRDisplayErrorMsg( WR_NOLOAD32IN16 ); } } #endif if( ok ) { ok = loadResDirFromRES( info, fn_path, &is_wres ); } if( ok ) { target_os = WResGetTargetOS( info->dir ); target = WR_INVALID_FILE; switch( target_os ) { case WRES_OS_WIN16: target = WR_WIN16M_RES; if( is_wres ) { target = WR_WIN16W_RES; } break; case WRES_OS_WIN32: target = WR_WINNTM_RES; if( is_wres ) { target = WR_WINNTW_RES; } break; } info->internal_type = target; if( target == WR_INVALID_FILE ) { WRDisplayErrorMsg( WR_INVALIDFILE ); ok = false; } } if( ok ) { info->internal_filename = WRStrDup( fn_path ); ok = (info->internal_filename != NULL); } return( ok ); }
bool WRLoadResourceFromRES( WRInfo *info ) { WResTargetOS target_os; WRFileType target; bool is_wres; bool ok; ok = WRLoadResDirFromRES( info, &is_wres ); if( ok ) { target_os = WResGetTargetOS( info->dir ); target = WR_INVALID_FILE; switch( target_os ) { case WRES_OS_WIN16: target = WR_WIN16M_RES; if( is_wres ) { target = WR_WIN16W_RES; } break; case WRES_OS_WIN32: target = WR_WINNTM_RES; if( is_wres ) { target = WR_WINNTW_RES; } break; } if( target == WR_INVALID_FILE ) { WRDisplayErrorMsg( WR_INVALIDFILE ); ok = false; } else if( target != info->file_type ) { if( target == WR_WIN16W_RES ) { WRDisplayErrorMsg( WR_BADFILEWWIN16 ); } else if( target == WR_WINNTW_RES ) { WRDisplayErrorMsg( WR_BADFILEWWINNT ); } else if( target == WR_WIN16M_RES ) { WRDisplayErrorMsg( WR_BADFILEMWIN16 ); } else if( target == WR_WINNTM_RES ) { WRDisplayErrorMsg( WR_BADFILEMWINNT ); } ok = false; } } return( ok ); }
extern int DumpFile( void ) /*************************/ { int error; int retcode; WResFileID handle; WResDir dir; handle = ResOpenFileRO( CmdLineParms.FileName ); if (handle == -1) { return( 2 ); } if (WResIsWResFile( handle )) { puts( "WATCOM format .RES file" ); } else { puts( "MS format .RES file" ); } dir = WResInitDir(); if (dir == NULL) { FatalError( "Out of memory" ); } error = WResReadDir( handle, dir, NULL ); if (error) { puts( "Unable to read directory" ); retcode = 2; } else { if( WResGetTargetOS( dir ) == WRES_OS_WIN16 ) { puts( "Target OS: Win16" ); } else { puts( "Target OS: Win32" ); } puts( "Type Name Language Flags" ); puts( "==== ==== ======== =====" ); retcode = DumpDir( dir, handle ); } WResFreeDir( dir ); ResCloseFile( handle ); return( retcode ); }
WRFileType WRIdentifyRESFile( const char *file ) { WRFileType ftype; WRInfo info; bool is_wres; bool ok; memset( &info, 0, sizeof( WRInfo ) ); info.file_name = (char *)file; ok = WRLoadResDirFromRES( &info, &is_wres ); if( ok ) { switch( WResGetTargetOS( info.dir ) ) { case WRES_OS_WIN16: if( is_wres ) { ftype = WR_WIN16W_RES; } else { ftype = WR_WIN16M_RES; } break; case WRES_OS_WIN32: if( is_wres ) { ftype = WR_WINNTW_RES; } else { ftype = WR_WINNTM_RES; } break; default: ftype = WR_INVALID_FILE; break; } if( info.dir != NULL ) { WResFreeDir( info.dir ); } } if( ok ) { return( ftype ); } else { return( WR_INVALID_FILE ); } }