Exemplo n.º 1
0
/*
 * WResAddResource - Add the new entry to the directory. If type is NULL the
 *                   default is used.  If the entry is already in the
 *                   directory don't add anything, set duplicate TRUE
 *                   and return an error. Return is TRUE if any error has
 *                   occured (including duplicate entry)
 */
int WResAddResource( const WResID *type, const WResID *name,
                        uint_16 memflags, off_t offset, uint_32 length,
                        WResDir currdir, WResLangType *lang, int *duplicate )
/************************************************************/
{
    int                 rc;
    WResDirWindow       dup;

    rc = WResAddResource2( type, name, memflags, offset, length, currdir,
                             lang, &dup, NULL );
    if( duplicate != NULL ) {
        *duplicate = !WResIsEmptyWindow( dup );
    }
    return( rc );
}
Exemplo n.º 2
0
static int readMResDir( WResFileID handle, WResDir currdir, int *dup_discarded,
                        char iswin32, void *fileinfo )
/******************************************************************************/
{
    MResResourceHeader     *head = NULL;
    M32ResResourceHeader   *head32 = NULL;
    WResDirWindow           dup;
    int                     error;
    off_t                   seek_rc;
    WResID                 *name;
    WResID                 *type;

    error = FALSE;
    if( iswin32 ) {
        /* Read NULL header */
        head32 = M32ResReadResourceHeader( handle );
        if( head32 != NULL ) {
            MResFreeResourceHeader( head32->head16 );
            WRESFREE( head32 );
        } else {
            error = TRUE;
        }
        if( !error ) {
            head32 = M32ResReadResourceHeader( handle );
            if( head32 != NULL ) {
                head = head32->head16;
            } else {
                error = TRUE;
            }
        }
    } else {
        head = MResReadResourceHeader( handle );
        if( head == NULL ) error = TRUE;
    }
    if(  dup_discarded != NULL  ) {
        *dup_discarded = FALSE;
    }
    if( iswin32 ) {
        currdir->TargetOS = WRES_OS_WIN32;
    } else {
        currdir->TargetOS = WRES_OS_WIN16;
    }
    /* assume that a NULL head is the EOF which is the only way of detecting */
    /* the end of a MS .RES file */
    while( head != NULL && !( iswin32 && head32 == NULL ) && !error ) {
        name = WResIDFromNameOrOrd( head->Name );
        type = WResIDFromNameOrOrd( head->Type );
        error = (name == NULL || type == NULL);

        /* MResReadResourceHeader leaves the file at the start of the resource*/
        if( !error ) {
            if( !type->IsName && type->ID.Num == RT_NAMETABLE ) {
                error = FALSE;
            } else {
                error = WResAddResource2( type, name, head->MemoryFlags,
                                          WRESTELL( handle ), head->Size, currdir, NULL,
                                          &dup, fileinfo );
                if(  error && !WResIsEmptyWindow( dup ) ) {
                    error = FALSE;
                    if(  dup_discarded != NULL  ) {
                        *dup_discarded = TRUE;
                    }
                }
            }
        }

        if( !error ) {
            seek_rc = WRESSEEK( handle, head->Size, SEEK_CUR );
            if( seek_rc == -1L ) {
                error =  TRUE;
                WRES_ERROR( WRS_SEEK_FAILED );
            }
        }

        if( name != NULL ) {
            WRESFREE( name );
            name = NULL;
        }
        if( type != NULL ) {
            WRESFREE( type );
            type = NULL;
        }
        MResFreeResourceHeader( head );
        if( iswin32 ) {
            WRESFREE( head32 );
        }

        if( !error ) {
            if( iswin32 ) {
                head32 = M32ResReadResourceHeader( handle );
                if( head32 != NULL ) {
                    head = head32->head16;
                }
            } else {
                head = MResReadResourceHeader( handle );
            }
        }
    }

    return( error );

} /* readMResDir */