예제 #1
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 );
}
예제 #2
0
bool WRHandleWinNTLangIDEntry( WResFileID file, WResDir *dir, WResID *type,
                               WResID *name, resource_dir_entry *rd_entry )
{
    WResLangType    lang;
    resource_entry  res_entry;
    uint_32         offset;
    bool            ok;

    ok = (name != NULL);

    if( ok ) {
        /* is the entry_rva is a subdir */
        if( rd_entry->entry_rva & PE_RESOURCE_MASK_ON ) {
            WRDisplayErrorMsg( WR_BADLANGDISCARDNAME );
            ok = false;
        } else {
            offset = WR_MAP_RES_RVA( rd_entry->entry_rva );
            ok = WRReadResourceEntry( file, offset, &res_entry );
        }
    }

    if( ok ) {
        offset = WR_MAP_DATA_RVA( res_entry.data_rva );
        lang.lang = HIWORD( rd_entry->id_name );
        lang.sublang = LOWORD( rd_entry->id_name );
        ok = !WResAddResource( type, name, 0, offset, res_entry.size, *dir, &lang, NULL );
    }

    return( ok );
}
예제 #3
0
Bool WREGetAndAddIconImage( BYTE *data, WResDir dir,
                            ICONDIRENTRY *id, int ord )
{
    BYTE                *icon;
    int                 dup;
    WResID              *tname;
    WResID              *rname;
    WResLangType        lang;
    Bool                ok;

    dup = FALSE;
    lang.lang = DEF_LANG;
    lang.sublang = DEF_SUBLANG;
    tname = NULL;
    rname = NULL;

    ok = ( data && dir && id && id->dwBytesInRes );

    if ( ok ) {
        icon = (BYTE *)WREMemAlloc( id->dwBytesInRes );
        ok = ( icon != NULL );
    }

    if( ok ) {
        memcpy( icon, data + id->dwImageOffset, id->dwBytesInRes );
        tname = WResIDFromNum( (uint_16)RT_ICON );
        ok = ( tname != NULL );
    }

    if( ok ) {
        rname = WResIDFromNum( ord );
        ok = ( rname != NULL );
    }

    if ( ok ) {
        ok = !WResAddResource( tname, rname, DEF_MEMFLAGS, 0,
                               id->dwBytesInRes, dir, &lang, &dup );
    }

    if( ok ) {
        ok = WRFindAndSetData( dir, tname, rname, &lang, icon );
    }

    if( !ok ) {
        if( icon != NULL ) {
            WREMemFree( icon );
        }
    }

    if( tname != NULL ) {
        WREMemFree( tname );
    }

    if( rname != NULL ) {
        WREMemFree( rname );
    }

    return( ok );
}
예제 #4
0
void SemAddResource2( WResID * name, WResID * type, ResMemFlags flags,
                ResLocation loc, char *filename )
/******************************************************************/
{
    int                 error;
    int                 duplicate;
    char *              namestr;
    WResLangType        *lang;

    if( resourceHasLang ) {
        lang = &resourceLang;
        resourceHasLang = FALSE;
    } else {
        lang = &curLang;
    }
    // Windows 95 is currently unable to load an exe that contains a resource
    // with numeric type or numeric identifier greater than 0x7FFF
    // so we warn the user
    if( CmdLineParms.TargetOS == RC_TARGET_OS_WIN32 ) {
        if( !type->IsName && type->ID.Num > 0x7FFF ) {
            namestr = WResIDToStr( name );
            RcWarning( ERR_TYPE_GT_7FFF, namestr );
            RcMemFree( namestr );
        }
        if( !name->IsName && name->ID.Num > 0x7FFF ) {
            namestr = WResIDToStr( name );
            RcWarning( ERR_NAME_GT_7FFF, namestr );
            RcMemFree( namestr );
        }
    }
    error = WResAddResource( type, name, flags, loc.start, loc.len,
                        CurrResFile.dir, lang, &duplicate );

    if (duplicate) {
        if( filename == NULL ) {
            ReportDupResource( name, type, NULL, NULL, TRUE );
        } else {
            ReportDupResource( name, type, filename, CmdLineParms.InFileName,
                               TRUE );
        }
        /* The resource has already been written but we can't add it to */
        /* directory. This will make the .RES file larger but will otherwise */
        /* not affect it since there will be no references to the resource in */
        /* the directory. */
    } else if (error) {
        RcError( ERR_OUT_OF_MEMORY );
        ErrorHasOccured = TRUE;
    }

    if (!CurrResFile.IsWatcomRes) {
        if (!duplicate) {
            copyMSFormatRes( name, type, flags, loc, lang );
        }
        /* erase the temporary file */
        remove( MSFormatTmpFile );
        UnregisterTmpFile( MSFormatTmpFile );
        MSFormatTmpFile[0] = '\0';
    }
}
예제 #5
0
bool WRAPI WRGetAndAddIconImage( BYTE *data, WResDir dir, ICONDIRENTRY *id, int ord )
{
    BYTE                *icon;
    bool                dup;
    WResID              *tname;
    WResID              *rname;
    WResLangType        lang;
    bool                ok;

    dup = false;
    lang.lang = DEF_LANG;
    lang.sublang = DEF_SUBLANG;
    tname = NULL;
    rname = NULL;

    ok = (data != NULL && dir != NULL && id != NULL && id->dwBytesInRes != 0);

    if( ok ) {
        icon = (BYTE *)MemAlloc( id->dwBytesInRes );
        ok = (icon != NULL);
    }

    if( ok ) {
        memcpy( icon, data + id->dwImageOffset, id->dwBytesInRes );
        tname = WResIDFromNum( RESOURCE2INT( RT_ICON ) );
        ok = (tname != NULL);
    }

    if( ok ) {
        rname = WResIDFromNum( ord );
        ok = (rname != NULL);
    }

    if( ok ) {
        ok = !WResAddResource( tname, rname, DEF_MEMFLAGS, 0,
                               id->dwBytesInRes, dir, &lang, &dup );
    }

    if( ok ) {
        ok = WRFindAndSetData( dir, tname, rname, &lang, icon );
    }

    if( !ok ) {
        if( icon != NULL ) {
            MemFree( icon );
        }
    }

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

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

    return( ok );
}
예제 #6
0
bool WRHandleWinNTNameEntry( WResFileID file, WResDir *dir, WResID *type,
                             resource_dir_entry *rd_entry, bool is_name )
{
    WResLangType    def_lang;
    resource_entry  res_entry;
    uint_32         offset;
    WResID          *name;
    bool            add_now;
    bool            ok;

    def_lang.lang = DEF_LANG;
    def_lang.sublang = DEF_SUBLANG;

    /* verify the id_name */
    if ( ((rd_entry->id_name & PE_RESOURCE_MASK_ON) && !is_name) ||
            (!(rd_entry->id_name & PE_RESOURCE_MASK_ON) && is_name) ) {
        WRDisplayErrorMsg( WR_BADIDDISCARDNAME );
        return( FALSE );
    }

    if( is_name ) {
        name = WRGetUniCodeWResID( file, PE_RESOURCE_MASK & rd_entry->id_name );
    } else {
        name = WResIDFromNum( rd_entry->id_name );
    }

    ok = (name != NULL);

    if( ok ) {
        /* is the entry_rva is a subdir */
        if( rd_entry->entry_rva & PE_RESOURCE_MASK_ON ) {
            add_now = false;
            ok = WRHandleWinNTLangIDDir( file, dir, type, name,
                                         rd_entry->entry_rva & PE_RESOURCE_MASK );
        } else {
            /* will this to happen often ???? */
            add_now = true;
            offset = WR_MAP_RES_RVA( rd_entry->entry_rva );
            ok = WRReadResourceEntry( file, offset, &res_entry );
        }
    }

    if( ok ) {
        if( add_now ) {
            offset = WR_MAP_RES_RVA( res_entry.data_rva );
            ok = !WResAddResource( type, name, 0, offset, res_entry.size,
                                   *dir, &def_lang, NULL );
        }
    }

    if( name != NULL ) {
        WResIDFree( name );
    }

    return( ok );
}
예제 #7
0
static bool WRWriteResourceToWRES( WResTypeNode *tnode, WResResNode *rnode,
                                  WResDir new_dir, WResFileID src_fid,
                                  WResFileID dst_fid, bool is32bit )
{
    WResLangType    lt;
    WResLangNode    *lnode;
    uint_32         offset;
    bool            dup;

    if( is32bit ) {
        if( ResWritePadDWord( dst_fid ) ) {
            return( false );
        }
    }

    offset = RESTELL( dst_fid );

    lnode = rnode->Head;

    while( lnode != NULL ) {
        lt = lnode->Info.lang;
        if( WResAddResource( &tnode->Info.TypeName, &rnode->Info.ResName,
                             lnode->Info.MemoryFlags, offset,
                             lnode->Info.Length, new_dir,
                             &lt, &dup ) || dup ) {
            if( dup ) {
                displayDupMsg( &tnode->Info.TypeName, &rnode->Info.ResName );
            }
            return( false );
        }

        if( lnode->data != NULL ) {
            if( !WRCopyResFromDataToFile( lnode->data, lnode->Info.Length, dst_fid ) ) {
                return( false );
            }
        } else {
            if( !WRCopyResFromFileToFile( src_fid, lnode->Info.Offset,
                                          lnode->Info.Length, dst_fid ) ) {
                return( false );
            }
        }
        if( lnode == rnode->Tail ) {
            break;
        }
        lnode = lnode->Next;
        offset += lnode->Info.Length;
    }

    return( true );
}
예제 #8
0
static int ConvertMResources( WResFileID infile, WResFileID outfile,
                        WResDir outdir )
/******************************************************************/
{
    MResResourceHeader *    mheader;
    WResID *                name;
    WResID *                type;
    int                     error;
    int                     lastheader;     /*TRUE if lastheader has been read*/
    uint_32                 offset;
    int                     duplicate;

    mheader = MResReadResourceHeader( infile );
    /* assume that any error reading here means end of file */
    lastheader = (mheader == NULL);
    error = FALSE;

    while (!lastheader && !error) {
        name = ConvertNameOrOrdToID( mheader->Name );
        type = ConvertNameOrOrdToID( mheader->Type );
        offset = tell( outfile );

        /* copy the resource if it isn't a name table or if the user */
        /* requested that name tables be copied */
        if (type->IsName || type->ID.Num != RT_NAMETABLE ||
                        CmdLineParms.KeepNameTable ) {
            error = WResAddResource( type, name, mheader->MemoryFlags, offset,
                        mheader->Size, outdir, NULL, &(duplicate) );
            if (duplicate) {
                /* print message and continue */
                puts( "Error: duplicate entry" );
                error = FALSE;
            } else {
                error = BinaryCopy( infile, outfile, mheader->Size );
            }
        } else {
            lseek( infile, mheader->Size, SEEK_CUR );
        }

        WResIDFree( name );
        WResIDFree( type );
        MResFreeResourceHeader( mheader );

        mheader = MResReadResourceHeader( infile );
        /* assume that any error reading here means end of file */
        lastheader = (mheader == NULL);
    }

    return( error );
} /* ConvertMResources */
예제 #9
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 );
}
예제 #10
0
static bool ConvertMResources( FILE *in_fp, FILE *out_fp, WResDir outdir )
/************************************************************************/
{
    MResResourceHeader *    mheader;
    WResID *                name;
    WResID *                type;
    bool                    error;
    bool                    lastheader; /* true if lastheader has been read */
    uint_32                 offset;
    bool                    duplicate;

    mheader = MResReadResourceHeader( in_fp );
    /* assume that any error reading here means end of file */
    lastheader = ( mheader == NULL );
    error = false;

    while( !lastheader && !error ) {
        name = ConvertNameOrOrdToID( mheader->Name );
        type = ConvertNameOrOrdToID( mheader->Type );
        offset = RESTELL( out_fp );

        /* copy the resource if it isn't a name table or if the user */
        /* requested that name tables be copied */
        if( type->IsName || type->ID.Num != RESOURCE2INT( RT_NAMETABLE ) ||
                        CmdLineParms.KeepNameTable ) {
            error = WResAddResource( type, name, mheader->MemoryFlags, offset,
                        mheader->Size, outdir, NULL, &duplicate );
            if( duplicate ) {
                /* print message and continue */
                puts( "Error: duplicate entry" );
                error = false;
            } else {
                error = BinaryCopy( in_fp, out_fp, mheader->Size );
            }
        } else {
            RESSEEK( in_fp, mheader->Size, SEEK_CUR );
        }

        WResIDFree( name );
        WResIDFree( type );
        MResFreeResourceHeader( mheader );

        mheader = MResReadResourceHeader( in_fp );
        /* assume that any error reading here means end of file */
        lastheader = ( mheader == NULL );
    }

    return( error );
} /* ConvertMResources */
예제 #11
0
Bool WREGetAndAddCursorImage( BYTE *data, WResDir dir, CURSORDIRENTRY *cd, int ord )
{
    BYTE                *cursor;
    int                 dup;
    uint_32             size;
    WResID              *tname;
    WResID              *rname;
    WResLangType        lang;
    CURSORHOTSPOT       hotspot;
    Bool                ok;

    dup = FALSE;
    lang.lang = DEF_LANG;
    lang.sublang = DEF_SUBLANG;
    tname = NULL;
    rname = NULL;

    ok = (data != NULL && dir != NULL && cd != NULL && cd->dwBytesInRes != 0);

    if ( ok ) {
        cursor = (BYTE *)WREMemAlloc( cd->dwBytesInRes );
        ok = (cursor != NULL);
    }

    if( ok ) {
        memcpy( cursor, data + cd->dwImageOffset, cd->dwBytesInRes );
        hotspot.xHotspot = cd->wXHotspot;
        hotspot.yHotspot = cd->wYHotspot;
        size = cd->dwBytesInRes;
        ok = WREAddCursorHotspot( &cursor, &size, &hotspot );
    }

    if( ok ) {
        tname = WResIDFromNum( (uint_16)RT_CURSOR );
        ok = (tname != NULL);
    }

    if( ok ) {
        rname = WResIDFromNum( ord );
        ok = (rname != NULL);
    }

    if( ok ) {
        ok = !WResAddResource( tname, rname, DEF_MEMFLAGS, 0,
                               size, dir, &lang, &dup );
    }

    if( ok ) {
        ok = WRFindAndSetData( dir, tname, rname, &lang, cursor );
    }

    if( !ok ) {
        if( cursor != NULL ) {
            WREMemFree( cursor );
        }
    }

    if( tname != NULL ) {
        WREMemFree( tname );
    }

    if( rname != NULL ) {
        WREMemFree( rname );
    }

    return( ok );
}
예제 #12
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 );
}
예제 #13
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 );
}