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 ); }
void WR_EXPORT WRFreeWRInfo( WRInfo *info ) { if( info != NULL ) { if( info->file_name != NULL ) { WRMemFree( info->file_name ); } if( info->save_name != NULL ) { WRMemFree( info->save_name ); } if( info->internal_filename != NULL ) { WRMemFree( info->internal_filename ); } if( info->tmp_file != NULL ) { if( WRFileExists( info->tmp_file ) ) { WRDeleteFile( info->tmp_file ); } WRMemFree( info->tmp_file ); } if( info->dir != NULL ) { WRFreeWResDirData( info->dir ); WResFreeDir( info->dir ); } WRMemFree( info ); } }
static void Pass1ResFileShutdown( void ) /**************************************/ { bool error; error = false; if( CurrResFile.fp != NULL ) { if( CmdLineParms.TargetOS == RC_TARGET_OS_OS2 ) { WriteOS2Tables(); } else { WriteWINTables(); } if( !ErrorHasOccured ) { if( CurrResFile.IsWatcomRes ) { error = WResWriteDir( CurrResFile.fp, CurrResFile.dir ); if( error ) { RcError( ERR_WRITTING_RES_FILE, CurrResFile.filename, LastWresErrStr() ); } } if( !error ) { ChangeTmpToOutFile( CurrResFile.fp, CmdLineParms.OutResFileName ); } } if( CurrResFile.dir != NULL ) { WResFreeDir( CurrResFile.dir ); CurrResFile.dir = NULL; } if( ResCloseFile( CurrResFile.fp ) ) { RcError( ERR_CLOSING_TMP, CurrResFile.filename, LastWresErrStr() ); } CurrResFile.fp = NULL; } } /* Pass1ResFileShutdown */
DepInfo *WResGetAutoDep( const char *fname ) { WResFileID handle; WResDir dir; bool dup_discarded; WResID *name; WResID *type; WResDirWindow window; WResLangInfo *info; DepInfo *ret; WResFileSSize numread; ret = NULL; handle = ResOpenFileRO( fname ); if( handle != WRES_NIL_HANDLE ) { if( WResIsWResFile( handle ) && (dir = WResInitDir()) != NULL ) { if( !WResReadDir( handle, dir, &dup_discarded ) ) { name = WResIDFromStr( DEP_LIST_NAME ); type = WResIDFromNum( DEP_LIST_TYPE ); if( name != NULL && type != NULL ) { window = WResFindResource( type, name, dir, NULL ); if( WResIsEmptyWindow( window ) ) { WRES_ERROR( WRS_RES_NOT_FOUND ); } else { info = WResGetLangInfo( window ); if( WRESSEEK( handle, info->Offset, SEEK_SET ) == -1 ) { WRES_ERROR( WRS_SEEK_FAILED ); } else { ret = WRESALLOC( info->Length ); if( ret == NULL ) { WRES_ERROR( WRS_MALLOC_FAILED ); } else { numread = WRESREAD( handle, ret, info->Length ); if( numread != (WResFileSSize)info->Length ) { WRES_ERROR( WRESIOERR( handle, numread ) ? WRS_READ_FAILED : WRS_READ_INCOMPLETE ); ret = NULL; } } } } } if( name != NULL ) { WResIDFree( name ); } if( type != NULL ) { WResIDFree( type ); } } WResFreeDir( dir ); } ResCloseFile( handle ); } return( ret ); }
int CompareContents( FILE *fp1, FILE *fp2 ) /*****************************************/ { int retcode; /* -1: error 0: same 1: different */ int oldretcode; bool dup_discarded; int error; WResDir dir1; WResDir dir2; retcode = CompareHeaders( fp1, fp2 ); if( (retcode == -1) || (retcode == 1 && !CmdLineParms.CheckAll) ) { return( retcode ); } oldretcode = retcode; dir1 = WResInitDir(); if( dir1 == NULL ) { return( -1 ); } dir2 = WResInitDir(); if( dir2 == NULL ) { WResFreeDir( dir1 ); return( -1 ); } error = WResReadDir( fp1, dir1, &dup_discarded ); if( error || dup_discarded ) { WResFreeDir( dir1 ); WResFreeDir( dir2 ); return( -1 ); } error = WResReadDir( fp2, dir2, &dup_discarded ); if( error || dup_discarded ) { WResFreeDir( dir1 ); WResFreeDir( dir2 ); return( -1 ); } retcode = CompareResources( fp1, dir1, fp2, dir2 ); WResFreeDir( dir1 ); WResFreeDir( dir2 ); if( retcode == -1 ) { return( -1 ); } else if( retcode == 1 || oldretcode == 1 ) { return( 1 ); } else { return( 0 ); } }
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 ); } }
int ConvertMResToWRes( WResFileID infile, WResFileID outfile ) /************************************************************/ { WResDir outdir; int error; outdir = WResInitDir(); if (WResDirInitError( outdir )) { return( TRUE ); } error = ConvertMResources( infile, outfile, outdir ); if (!error) { error = WResWriteDir( outfile, outdir ); } WResFreeDir( outdir ); return( error ); } /* ConvertMResToWres */
bool ConvertMResToWRes( FILE *in_fp, FILE *out_fp ) /*************************************************/ { WResDir outdir; bool error; outdir = WResInitDir(); if( WResDirInitError( outdir ) ) { return( true ); } error = ConvertMResources( in_fp, out_fp, outdir ); if( !error ) { error = WResWriteDir( out_fp, outdir ); } WResFreeDir( outdir ); return( error ); } /* ConvertMResToWres */
static void Pass1ResFileShutdown( void ) /**************************************/ { int error; error = FALSE; if( CurrResFile.IsOpen ) { if( CmdLineParms.TargetOS == RC_TARGET_OS_OS2 ) WriteOS2Tables(); else WriteTables(); if( ErrorHasOccured ) { ResCloseFile( CurrResFile.handle ); CurrResFile.IsOpen = false; RemoveCurrResFile(); } else { if (CurrResFile.IsWatcomRes) { error = WResWriteDir( CurrResFile.handle, CurrResFile.dir ); if( error ) { RcError( ERR_WRITTING_RES_FILE, CurrResFile.filename, LastWresErrStr() ); } } if( ResCloseFile( CurrResFile.handle ) == -1 ) { RcError( ERR_CLOSING_TMP, CurrResFile.filename, LastWresErrStr() ); remove( CurrResFile.filename ); UnregisterTmpFile( CurrResFile.filename ); } else if( !error ) { #ifdef USE_TEMPFILE ChangeTmpToOutFile( CurrResFile.filename, CmdLineParms.OutResFileName ); #endif } CurrResFile.IsOpen = false; } WResFreeDir( CurrResFile.dir ); CurrResFile.dir = NULL; } } /* Pass1ResFileShutdown */
static bool WRSaveResourceToWRES( WRInfo *info, WResFileID src_fid, WResFileID dst_fid ) { WResDir new_dir; WRFileType save_type; bool is32bit; bool ok; ok = ((new_dir = WResInitDir()) != NULL); if( ok ) { save_type = info->save_type; if( save_type != WR_WIN16M_RES && save_type != WR_WIN16W_RES && save_type != WR_WINNTM_RES && save_type != WR_WINNTW_RES ) { if( info->internal_type != WR_DONT_KNOW ) { save_type = info->internal_type; } } is32bit = WRIs32Bit( save_type ); if( is32bit ) { new_dir->TargetOS = WRES_OS_WIN32; } } if( ok ) { ok = WRWriteResourcesToWRES( info, new_dir, src_fid, dst_fid, is32bit ); } if( ok ) { ok = !WResWriteDir( dst_fid, new_dir ); } if( new_dir != NULL ) { WResFreeDir( new_dir ); } return( ok ); }
int WRLoadCursorFile( WRInfo *info ) { BYTE *data; uint_32 data_size; CURSORHEADER *ch; uint_32 chsize; RESCURSORHEADER *rch; uint_32 rchsize; WResFileID file; WResID *tname; WResID *rname; WResLangType lang; char fn[_MAX_FNAME]; int dup; int i; int ok; data = NULL; rch = NULL; dup = FALSE; file = -1; lang.lang = DEF_LANG; lang.sublang = DEF_SUBLANG; tname = NULL; rname = NULL; ok = ( info && info->file_name ); if( ok ) { ok = ( ( file = ResOpenFileRO( info->file_name ) ) != -1 ); } if( ok ) { ok = WRReadEntireFile( file, &data, &data_size ); } if( ok ) { ch = (CURSORHEADER *) data; chsize = sizeof(CURSORHEADER); chsize += sizeof(CURSORDIRENTRY)*(ch->cdCount-1); ok = WRCreateCursorResHeader( &rch, &rchsize, data, data_size ); } if( ok ) { ok = ( ( info->dir = WResInitDir() ) != NULL ); } if( ok ) { tname = WResIDFromNum( (uint_16)RT_GROUP_CURSOR ); ok = ( tname != NULL ); } if( ok ) { _splitpath( info->file_name, NULL, NULL, fn, NULL ); rname = WResIDFromStr( fn ); ok = ( rname != NULL ); } if ( ok ) { ok = !WResAddResource( tname, rname, DEF_MEMFLAGS, 0, rchsize, info->dir, &lang, &dup ); } if( ok ) { ok = WRFindAndSetData( info->dir, tname, rname, &lang, rch ); } if( ok ) { for( i=0; ok && i<ch->cdCount ; i++ ) { ok = WRGetAndAddCursorImage( data, info->dir, &ch->cdEntries[i], i+1 ); } } if( !ok ) { if( info->dir ) { WRFreeWResDirData( info->dir ); WResFreeDir( info->dir ); info->dir = NULL; } } if( tname != NULL ) { WRMemFree( tname ); } if( rname != NULL ) { WRMemFree( rname ); } if( file != -1 ) { ResCloseFile( file ); } return( ok ); }
int WRLoadIconFile( WRInfo *info ) { BYTE *data; uint_32 data_size; ICONHEADER *pih; uint_32 pihsize; RESICONHEADER *rih; uint_32 rihsize; WResFileID file; WResID *tname; WResID *rname; WResLangType lang; char fn[_MAX_FNAME]; int dup; int i; int ok; data = NULL; rih = NULL; dup = FALSE; file = -1; lang.lang = DEF_LANG; lang.sublang = DEF_SUBLANG; tname = NULL; rname = NULL; ok = (info != NULL && info->file_name != NULL); if( ok ) { ok = ((file = ResOpenFileRO( info->file_name )) != -1); } if( ok ) { ok = WRReadEntireFile( file, &data, &data_size ); } if( ok ) { pih = (ICONHEADER *)data; pihsize = sizeof( ICONHEADER ); pihsize += sizeof( ICONDIRENTRY ) * (pih->idCount - 1); ok = WRCreateIconResHeader( &rih, &rihsize, data, data_size ); } if( ok ) { ok = ((info->dir = WResInitDir()) != NULL); } if( ok ) { tname = WResIDFromNum( (uint_16)RT_GROUP_ICON ); ok = (tname != NULL); } if( ok ) { _splitpath( info->file_name, NULL, NULL, fn, NULL ); rname = WResIDFromStr( fn ); ok = (rname != NULL); } if ( ok ) { ok = !WResAddResource( tname, rname, DEF_MEMFLAGS, 0, rihsize, info->dir, &lang, &dup ); } if( ok ) { ok = WRFindAndSetData( info->dir, tname, rname, &lang, rih ); } if( ok ) { for( i = 0; ok && i < pih->idCount; i++ ) { ok = WRGetAndAddIconImage( data, info->dir, &pih->idEntries[i], i + 1 ); } } if( !ok ) { if( info->dir != NULL ) { WRFreeWResDirData( info->dir ); WResFreeDir( info->dir ); info->dir = NULL; } } if( data != NULL ) { WRMemFree( data ); } if( tname != NULL ) { WRMemFree( tname ); } if( rname != NULL ) { WRMemFree( rname ); } if( file != -1 ) { ResCloseFile( file ); } return( ok ); }