Exemple #1
0
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 );
    }
}
Exemple #2
0
static bool loadResDirFromRES( WRInfo *info, const char *filename, bool *is_wres )
{
    WResFileID  fid;
    bool        dup_discarded;
    bool        ok;

    ok = ((fid = ResOpenFileRO( filename )) != WRES_NIL_HANDLE);

    if( ok ) {
        *is_wres = WResIsWResFile( fid );
    }

    if( ok ) {
        ok = ((info->dir = WResInitDir()) != NULL);
    }

    if( ok ) {
        ok = !WResReadDir( fid, info->dir, &dup_discarded );
        if( ok && dup_discarded ) {
            WRDisplayErrorMsg( WR_DUPRESDISCARD );
        }
    }

    if( fid != WRES_NIL_HANDLE ) {
        ResCloseFile( fid );
    }

    return( ok );
}
Exemple #3
0
int WRLoadBitmapFile( WRInfo *info )
{
    int                 ok;
    int                 file_handle;
    long int            file_length;
    char                fn[_MAX_FNAME];
    WResID              *type;
    WResID              *name;
    WResLangType        def_lang;

    file_handle         = -1;
    def_lang.sublang    = DEF_LANG;
    def_lang.lang       = DEF_SUBLANG;

    ok = ( info != NULL );

    if( ok ) {
        ok = ( ( file_handle = ResOpenFileRO( info->file_name ) ) != -1 );
    }

    if( ok ) {
        file_length = filelength( file_handle );
        ok = ( ( file_length != 0 ) && ( file_length != -1 ) );
    }

    if( ok ) {
        type = WResIDFromNum( (long)RT_BITMAP );
        ok = ( type != NULL );
    }

    if( ok ) {
        _splitpath( info->file_name, NULL, NULL, fn, NULL );
        name = WResIDFromStr( fn );
        ok = ( name != NULL );
    }

    if( ok ) {
        ok = ( ( info->dir = WResInitDir() ) != NULL );
    }

    if( ok ) {
        ok = !WResAddResource( type, name, 0, sizeof(BITMAPFILEHEADER),
                               file_length - sizeof(BITMAPFILEHEADER),
                               info->dir, &def_lang, NULL );
    }

    if( file_handle != -1 ) {
        ResCloseFile( file_handle );
    }

    if( name ) {
        WRMemFree( name );
    }

    if( type ) {
        WRMemFree( type );
    }

    return( ok );
}
Exemple #4
0
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 );
}
Exemple #5
0
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 );
}
Exemple #6
0
static bool Pass1InitRes( void )
/******************************/
{
    WResID        null_id;
    ResMemFlags   null_memflags;
    ResLocation   null_loc;

    memset( &CurrResFile, 0, sizeof( CurrResFile ) );

    /* open the temporary file */
    CurrResFile.filename = "Temporary file 0 (res)";
    CurrResFile.fp = ResOpenFileTmp( NULL );
    if( CurrResFile.fp == NULL ) {
        RcError( ERR_OPENING_TMP, CurrResFile.filename, LastWresErrStr() );
        return( true );
    }

    /* initialize the directory */
    CurrResFile.dir = WResInitDir();
    if( CurrResFile.dir == NULL ) {
        RcError( ERR_OUT_OF_MEMORY );
        ResCloseFile( CurrResFile.fp );
        CurrResFile.fp = NULL;
        return( true );
    }

    if( CmdLineParms.TargetOS == RC_TARGET_OS_WIN16 ) {
        WResSetTargetOS( CurrResFile.dir, WRES_OS_WIN16 );
    } else if( CmdLineParms.TargetOS == RC_TARGET_OS_WIN32 ) {
        WResSetTargetOS( CurrResFile.dir, WRES_OS_WIN32 );
    } else {
        WResSetTargetOS( CurrResFile.dir, WRES_OS_OS2 );
    }

    if( CmdLineParms.MSResFormat ) {
        CurrResFile.IsWatcomRes = false;
        /* write null header here if it is win32 */
        if( CmdLineParms.TargetOS == RC_TARGET_OS_WIN32 ) {
            null_loc.start = SemStartResource();
            null_loc.len = SemEndResource( null_loc.start );
            null_id.IsName = false;
            null_id.ID.Num = 0;
            null_memflags = 0;
            SemAddResource( &null_id, &null_id, null_memflags, null_loc );
        }
    } else {
        CurrResFile.IsWatcomRes = true;
        WResFileInit( CurrResFile.fp );
    }
    CurrResFile.NextCurOrIcon = 1;
    return( false );
} /* Pass1InitRes */
Exemple #7
0
bool WRENewResource( WRECurrentResInfo *curr, WResID *tname, WResID *rname,
                     uint_16 memflags, uint_32 offset, uint_32 length,
                     WResLangType *lang, bool *dup, uint_16 type,
                     bool new_type )
{
    bool   ok;

    ok = (curr != NULL && curr->info != NULL && tname != NULL && rname != NULL &&
          lang != NULL);

    if( ok && ( curr->info->info->dir == NULL ) ) {
        ok = ((curr->info->info->dir = WResInitDir()) != NULL);
    }

    if( ok ) {
        ok = !WResAddResource( tname, rname, memflags, offset, length,
                               curr->info->info->dir, lang, dup );
    }

    if( ok ) {
        ok = (dup == NULL || (dup != NULL && !*dup));
    }

    if( ok ) {
        if( new_type ) {
            curr->info->current_type = 0;
            ok = WREInitResourceWindow( curr->info, type );
        } else {
            WRESetResNamesFromType( curr->info, type, TRUE, rname, 0 );
        }
    }

    if( ok && new_type ) {
        curr->type = WREFindTypeNodeFromWResID( curr->info->info->dir, tname );
        ok = (curr->type != NULL);
    }

    if( ok ) {
        curr->res = WREFindResNodeFromWResID( curr->type, rname );
        ok = (curr->res != NULL);
    }

    if( ok ) {
        curr->lang = WREFindLangNodeFromLangType( curr->res, lang );
        ok = (curr->lang != NULL);
    }

    return( ok );
}
Exemple #8
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 );
}
Exemple #9
0
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 */
Exemple #10
0
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 */
Exemple #11
0
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 );
}
Exemple #12
0
int WRLoadWResDirFromWin16EXE( WResFileID file_handle, WResDir *dir )
{
    os2_exe_header  win_header;
    long int        offset;
    uint_16         align_shift;
    uint_32         name_offset;
    WResTypeNode    *type_node;
    uint_8          *name_table;
    uint_8          *leftover;
    uint_32         name_table_len;
    uint_32         num_leftover;
    int             ok;

    ok = (file_handle != -1);

    if( ok ) {
        ok = ((*dir = WResInitDir()) != NULL);
    }

    if( ok ) {
        ok = ((offset = WRReadWin16ExeHeader( file_handle, &win_header )) != 0);
    }

    /* check if a resource table is present */
    if( ok ) {
        ok = WRWin16HeaderHasResourceTable( &win_header );
        if( !ok ) {
            return( TRUE );
        }
    }

    if( ok ) {
        ok = (ResSeek( file_handle, offset, SEEK_SET ) != -1);
    }

    if( ok ) {
        ok = (ResSeek( file_handle, win_header.resource_off, SEEK_CUR ) != -1);
    }

    if( ok ) {
        ResReadUint16( &align_shift, file_handle );
        ok = (align_shift <= 16);
        if( !ok ) {
            WRDisplayErrorMsg( WR_BADEXE );
        }
    }

    if( ok ) {
        (*dir)->NumResources = 0;
        type_node = WRReadWResTypeNodeFromExe( file_handle, align_shift );
        while( type_node != NULL ) {
            type_node->Next = NULL;
            type_node->Prev = (*dir)->Tail;
            if( (*dir)->Tail != NULL ) {
                (*dir)->Tail->Next = type_node;
            }
            if ( (*dir)->Head == NULL ) {
                (*dir)->Head = type_node;
            }
            (*dir)->Tail = type_node;
            (*dir)->NumTypes++;
            (*dir)->NumResources += type_node->Info.NumResources;
            type_node = WRReadWResTypeNodeFromExe ( file_handle, align_shift );
        }
        name_offset = tell( file_handle ) - offset - win_header.resource_off;
        ok = WRReadResourceNames( *dir, file_handle, name_offset );
    }

    if( ok && win_header.expver <= 0x300 ) {
        num_leftover = 0;
        leftover = NULL;
        name_table_len = WRReadNameTable( *dir, file_handle,
                                          &name_table, num_leftover, leftover );
        while( name_table_len != 0 ) {
            num_leftover = WRUseNameTable( *dir, name_table, name_table_len, &leftover );
            if( name_table != NULL ) {
                WRMemFree( name_table );
            }
            name_table_len = WRReadNameTable( NULL, file_handle, &name_table,
                                              num_leftover, leftover );
            if( leftover != NULL ) {
                WRMemFree( leftover );
                leftover = NULL;
            }
        }
    }

    return( ok );
}
Exemple #13
0
bool WdeInfoToData( WdeResInfo *info )
{
    WResTypeNode        *dnode;
    WResResNode         *rnode;
    LIST                *dlist;
    WdeResDlgItem       *ditem;
    void                *data;
    uint_32             size;
    WResLangType        def_lang;


    if( info == NULL ) {
        return( FALSE );
    }

    def_lang.lang = DEF_SUBLANG;
    def_lang.sublang = DEF_SUBLANG;
    dnode = info->dlg_entry;
    dlist = info->dlg_item_list;

    while( dlist != NULL ) {
        ditem = (WdeResDlgItem *)ListElement( dlist );

        data = NULL;
        size = 0;

        if( ditem->object != NULL || ditem->dialog_info != NULL ) {
            if( !WdeGetItemData( ditem, &data, &size ) ) {
                return( FALSE );
            }
        }

        if( ditem->rnode != NULL && ditem->lnode != NULL ) {
            if( data != NULL ) {
                rnode = WdeRenameWResResNode( dnode, ditem->rnode, ditem->dialog_name );
                if( rnode == NULL ) {
                    WRMemFree( data );
                    return( FALSE );
                }
                ditem->rnode = rnode;
                ditem->lnode->data = data;
                ditem->lnode->Info.Length = size;
                ditem->lnode->Info.Offset = 0;
                ditem->lnode->Info.MemoryFlags = ditem->dialog_info->MemoryFlags;
            }
        } else {
            rnode = WdeCreateWResResNode( 1, ditem->dialog_name, &def_lang,
                                          ditem->dialog_info->MemoryFlags, 0,
                                          size, data );
            if( rnode != NULL ) {
                if( info->info->dir == NULL ) {
                    info->info->dir = WResInitDir();
                }
                if( dnode == NULL ) {
                    dnode = WdeAddTypeToDir( info->info->dir, (uint_16)(pointer_int)RT_DIALOG );
                    info->dlg_entry = dnode;
                }
                if( info->info->dir != NULL && dnode != NULL ) {
                    WdeAddResToType( dnode, rnode );
                    ditem->rnode = rnode;
                    ditem->lnode = rnode->Head;
                } else {
                    WRMemFree( rnode->Head );
                    WRMemFree( rnode );
                    WRMemFree( data );
                    return( FALSE );
                }
            } else {
                WRMemFree( data );
                return( FALSE );
            }

            info->info->dir->NumResources++;
        }

        dlist = ListNext( dlist );
    }

    return( TRUE );
}
Exemple #14
0
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 );
}
Exemple #15
0
static int Pass1InitRes( void )
/*****************************/
{
    WResID        null_id;
    ResMemFlags   null_memflags;
    ResLocation   null_loc;

    /* put the temporary file in the same location as the output file */
    CurrResFile.filename = CurrResFile.namebuf;
#ifdef USE_TEMPFILE
    MakeTmpInSameDir( CmdLineParms.OutResFileName, CurrResFile.filename,
                    "res" );
#else
    strcpy( CurrResFile.filename, CmdLineParms.OutResFileName );
#endif

    /* initialize the directory */
    CurrResFile.dir = WResInitDir();
    if( CurrResFile.dir == NULL ) {
        RcError( ERR_OUT_OF_MEMORY );
        CurrResFile.IsOpen = false;
        return( TRUE );
    }

    if( CmdLineParms.TargetOS == RC_TARGET_OS_WIN16 ) {
        WResSetTargetOS( CurrResFile.dir, WRES_OS_WIN16 );
    } else if( CmdLineParms.TargetOS == RC_TARGET_OS_WIN32 ) {
        WResSetTargetOS( CurrResFile.dir, WRES_OS_WIN32 );
    } else {
        WResSetTargetOS( CurrResFile.dir, WRES_OS_OS2 );
    }

    /* open the temporary file */
    if( CmdLineParms.MSResFormat ) {
        CurrResFile.IsWatcomRes = FALSE;
        CurrResFile.handle = MResOpenNewFile( CurrResFile.filename );

    /* write null header here if it is win32 */
        if( CmdLineParms.TargetOS == RC_TARGET_OS_WIN32 &&
                                     CmdLineParms.MSResFormat ) {
            null_loc.start = SemStartResource();
            null_loc.len = SemEndResource( null_loc.start );
            null_id.IsName = FALSE;
            null_id.ID.Num = 0;
            null_memflags = 0;
            SemAddResource( &null_id, &null_id, null_memflags, null_loc );
        }
    } else {
        CurrResFile.IsWatcomRes = TRUE;
        CurrResFile.handle = WResOpenNewFile( CurrResFile.filename );
    }
    if( CurrResFile.handle == NIL_HANDLE ) {
        RcError( ERR_OPENING_TMP, CurrResFile.filename, LastWresErrStr() );
        CurrResFile.IsOpen = false;
        return( TRUE );
    }
    RegisterTmpFile( CurrResFile.filename );

    CurrResFile.IsOpen = true;
    CurrResFile.StringTable = NULL;
    CurrResFile.ErrorTable = NULL;
    CurrResFile.FontDir = NULL;
    CurrResFile.NextCurOrIcon = 1;
    return( FALSE );
} /* Pass1InitRes */
Exemple #16
0
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 );
}
Exemple #17
0
bool WRLoadWResDirFromWinNTEXE( WResFileID file_handle, WResDir *dir )
{
    exe_pe_header       nt_header;
    pe_object           *otable;
    uint_32             physical_size;
    uint_32             physical_offset;
    int                 i;
    bool                ok;
    unsigned_32         resource_rva;

    ok = (file_handle != -1);

    if( ok ) {
        ok = ((*dir = WResInitDir()) != NULL);
    }

    if( ok ) {
        ok = (WRReadWinNTExeHeader( file_handle, &nt_header ) != 0);
    }

    /* check if a resource table is present */
    if( ok ) {
        ok = WRWinNTHeaderHasResourceTable( &nt_header );
        if( !ok ) {
            WRDisplayErrorMsg( WR_EXENORES );
            return( TRUE );
        }
    }

    /* read NT object table */
    otable = NULL;
    if( ok ) {
        ok = WRReadNTObjectTable( file_handle, &nt_header, &otable );
    }

    /* find resource object in object table */
    resource_rva = 0;
    if( ok ) {
        int         num_objects;
        unsigned_32 file_align;

        physical_size = 0;
        physical_offset = 0;
        if( IS_PE64( nt_header ) ) {
            resource_rva = PE64( nt_header ).table[PE_TBL_RESOURCE].rva;
            num_objects = PE64( nt_header ).num_objects;
            file_align = PE64( nt_header ).file_align;
        } else {
            resource_rva = PE32( nt_header ).table[PE_TBL_RESOURCE].rva;
            num_objects = PE32( nt_header ).num_objects;
            file_align = PE32( nt_header ).file_align;
        }
        for( i = 0; i < num_objects; i++ ) {
            if( otable[i].rva == resource_rva ) {
                physical_size = otable[i].physical_size;
                physical_offset = otable[i].physical_offset;
                break;
            }
        }
        ok = (physical_size != 0 && physical_offset != 0 && physical_size % file_align == 0 && physical_offset % file_align == 0);
    }

    if( otable != NULL ) {
        MemFree( otable );
    }

    /* read the resource information */
    if( ok ) {
        res_offset = physical_offset;
        res_rva = resource_rva;
        ok = WRHandleWinNTTypeDir( file_handle, dir, physical_offset );
    }

    return( ok );
}