Exemple #1
0
ResLocation SemCopyRawFile( const char *filename )
/************************************************/
{
    WResFileID      fid;
    RcStatus        ret;
    char            *buffer;
    char            full_filename[_MAX_PATH];
    ResLocation     loc;
    int             err_code;
    WResFileOffset  pos;

    buffer = RESALLOC( BUFFER_SIZE );

    if( RcFindResource( filename, full_filename ) == -1 ) {
        RcError( ERR_CANT_FIND_FILE, filename );
        goto HANDLE_ERROR;
    }

    if( AddDependency( full_filename ) )
        goto HANDLE_ERROR;

    fid = RcIoOpenInput( full_filename, false );
    if( fid == WRES_NIL_HANDLE ) {
        RcError( ERR_CANT_OPEN_FILE, filename, strerror( errno ) );
        goto HANDLE_ERROR;
    }

    loc.start = SemStartResource();

    pos = RESTELL( fid );
    if( pos == -1 ) {
        RcError( ERR_READING_DATA, full_filename, strerror( errno ) );
        RESCLOSE( fid );
        goto HANDLE_ERROR;
    } else {
        ret = SemCopyDataUntilEOF( pos, fid, buffer, BUFFER_SIZE, &err_code );
        if( ret != RS_OK ) {
            ReportCopyError( ret, ERR_READING_DATA, full_filename, err_code );
            RESCLOSE( fid );
            goto HANDLE_ERROR;
        }
    }

    loc.len = SemEndResource( loc.start );

    RESCLOSE( fid );

    RESFREE( buffer );

    return( loc );


HANDLE_ERROR:
    ErrorHasOccured = true;
    loc.start = 0;
    loc.len = 0;
    RESFREE( buffer );
    return( loc );
}
Exemple #2
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 #3
0
static void AddBitmapResource( WResID * name, ResMemFlags flags,
                            const char * filename )
/**************************************************************/
{
    BitmapFileHeader    head;
    WResFileID          handle;
    RcStatus            ret;
    int                 err_code;

    handle = RcIoOpenInput( filename, O_RDONLY | O_BINARY );
    if( handle == NIL_HANDLE)
        goto FILE_OPEN_ERROR;

    ret = readBitmapFileHeader( handle, &head, &err_code );
    if( ret != RS_OK )
        goto READ_HEADER_ERROR;

    if( head.Type != BITMAP_MAGIC )
        goto NOT_BITMAP_ERROR;

    ret = copyBitmap( &head, handle, name, flags, &err_code );
    if( ret != RS_OK )
        goto COPY_BITMAP_ERROR;

    RCCLOSE( handle );

    return;


FILE_OPEN_ERROR:
    RcError( ERR_CANT_OPEN_FILE, filename, strerror( errno ) );
    ErrorHasOccured = true;
    RCFREE( name );
    return;

READ_HEADER_ERROR:
    ReportCopyError( ret, ERR_READING_BITMAP, filename, err_code );
    ErrorHasOccured = true;
    RCFREE( name );
    RCCLOSE( handle );
    return;

NOT_BITMAP_ERROR:
    RcError( ERR_NOT_BITMAP_FILE, filename );
    ErrorHasOccured = true;
    RCFREE( name );
    RCCLOSE( handle );
    return;

COPY_BITMAP_ERROR:
    ReportCopyError( ret, ERR_READING_BITMAP, filename, err_code );
    ErrorHasOccured = true;
    RCCLOSE( handle );
    return;
}
Exemple #4
0
static int OpenPhysicalFile( PhysFileInfo * phys )
/************************************************/
{
    if( !phys->IsOpen ) {
        phys->Handle = RcIoOpenInput( phys->Filename, O_RDONLY | O_TEXT );
        if( phys->Handle == NIL_HANDLE ) {
            RcError( ERR_CANT_OPEN_FILE, phys->Filename, strerror( errno ) );
            return( TRUE );
        }
        phys->IsOpen = TRUE;
        if( RcSeek( phys->Handle, phys->Offset, SEEK_SET ) == -1 ) {
            RcError( ERR_READING_FILE, phys->Filename, strerror( errno ) );
            return( TRUE );
        }
    }

    return( FALSE );
} /* OpenPhysicalFile */
Exemple #5
0
static bool OpenPhysicalFile( PhysFileInfo *phys )
/************************************************/
{
    if( !phys->IsOpen ) {
        phys->fp = RcIoOpenInput( phys->Filename, true );
        if( phys->fp == NULL ) {
            RcError( ERR_CANT_OPEN_FILE, phys->Filename, strerror( errno ) );
            return( true );
        }
        phys->IsOpen = true;
        if( fseek( phys->fp, phys->Offset, SEEK_SET ) == -1 ) {
            RcError( ERR_READING_FILE, phys->Filename, strerror( errno ) );
            return( true );
        }
    }

    return( false );
} /* OpenPhysicalFile */
Exemple #6
0
static void AddFontResources( WResID * name, ResMemFlags flags,
                              const char * filename )
/**************************************************************/
{
    FontInfo            info;
    char *              devicename;
    char *              facename;
    WResFileID          handle;
    RcStatus            ret;
    int                 err_code;
    ReadStrErrInfo      readstr_err;

    if( name->IsName ) {
        RcError( ERR_FONT_NAME );
        return;
    }

    handle = RcIoOpenInput( filename, O_RDONLY | O_BINARY );
    if( handle == NIL_HANDLE)
        goto FILE_OPEN_ERROR;

    ret = readFontInfo( handle, &info, &err_code );
    if( ret != RS_OK)
        goto READ_HEADER_ERROR;

    ret = copyFont( &info, handle, name, flags, &err_code );
    if( ret != RS_OK )
        goto COPY_FONT_ERROR;

    devicename = readString( handle, info.dfDevice, &readstr_err );
    if( devicename == NULL ) {
        ret = readstr_err.status;
        err_code = readstr_err.err_code;
        goto READ_HEADER_ERROR;
    }

    facename = readString( handle, info.dfFace, &readstr_err );
    if( facename == NULL ) {
        ret = readstr_err.status;
        err_code = readstr_err.err_code;
        RCFREE( devicename );
        goto READ_HEADER_ERROR;
    }

    AddFontToDir( &info, devicename, facename, name );

    RCFREE( devicename );
    RCFREE( facename );

    RCCLOSE( handle );

    return;


FILE_OPEN_ERROR:
    RcError( ERR_CANT_OPEN_FILE, filename, strerror( errno ) );
    ErrorHasOccured = true;
    RCFREE( name );
    return;

READ_HEADER_ERROR:
    ReportCopyError( ret, ERR_READING_FONT, filename, err_code );
    ErrorHasOccured = true;
    RCFREE( name );
    RCCLOSE( handle );
    return;

COPY_FONT_ERROR:
    ReportCopyError( ret, ERR_READING_FONT, filename, err_code );
    ErrorHasOccured = true;
    RCCLOSE( handle );
    return;
}
Exemple #7
0
static void AddCursorResource( WResID * name, ResMemFlags flags,
                      ResMemFlags group_flags, const char * filename )
/********************************************************************/
{
    WResFileID      handle;
    RcStatus        ret;
    bool            error;
    FullCurDir      dir;
    int             err_code;

    handle = RcIoOpenInput( filename, O_RDONLY | O_BINARY );
    if( handle == NIL_HANDLE)
        goto FILE_OPEN_ERROR;

    dir.Head = NULL;
    dir.Tail = NULL;

    ret = readCurFileDir( handle, &dir, &err_code );
    if( ret != RS_OK)
        goto READ_DIR_ERROR;

    ret = copyCursors( &dir, handle, flags, &err_code );
    if( ret != RS_OK )
        goto COPY_CURSORS_ERROR;

    error = writeCurDir( &dir, name, group_flags, &err_code );
    if( error)
        goto WRITE_DIR_ERROR;

    FreeCurDir( &dir );
    RCCLOSE( handle );

    return;


FILE_OPEN_ERROR:
    RcError( ERR_CANT_OPEN_FILE, filename, strerror( errno ) );
    ErrorHasOccured = true;
    RCFREE( name );
    return;

READ_DIR_ERROR:
    if( ret == RS_INVALID_RESOURCE ) {
        RcError( ERR_NOT_CURSOR_FILE, filename );
    } else {
        ReportCopyError( ret, ERR_READING_CURSOR, filename, err_code );
    }
    ErrorHasOccured = true;
    RCFREE( name );
    FreeCurDir( &dir );
    RCCLOSE( handle );
    return;

WRITE_DIR_ERROR:
    RcError( ERR_WRITTING_RES_FILE, CurrResFile.filename, strerror( err_code )  );
    ErrorHasOccured = true;
    FreeCurDir( &dir );
    RCCLOSE( handle );
    return;

COPY_CURSORS_ERROR:
    ReportCopyError( ret, ERR_READING_CURSOR, filename, err_code );
    ErrorHasOccured = true;
    RCFREE( name );
    FreeCurDir( &dir );
    RCCLOSE( handle );
    return;
} /* AddCursorResource */
Exemple #8
0
static void AddIconResource( WResID * name, ResMemFlags flags,
                  ResMemFlags group_flags, const char * filename )
/****************************************************************/
{
    WResFileID      fid;
    RcStatus        ret;
    bool            error;
    FullIconDir     dir;
    int             err_code;

    fid = RcIoOpenInput( filename, false );
    if( fid == WRES_NIL_HANDLE)
        goto FILE_OPEN_ERROR;

    dir.Head = NULL;
    dir.Tail = NULL;

    ret = readIcoFileDir( fid, &dir, &err_code );
    if( ret != RS_OK )
        goto READ_DIR_ERROR;

    ret = copyIcons( &dir, fid, flags, &err_code );
    if( ret != RS_OK )
        goto COPY_ICONS_ERROR;

    error = writeIconDir( &dir, name, group_flags, &err_code );
    if( error)
        goto WRITE_DIR_ERROR;

    FreeIconDir( &dir );
    RESCLOSE( fid );

    return;


FILE_OPEN_ERROR:
    RcError( ERR_CANT_OPEN_FILE, filename, strerror( errno ) );
    ErrorHasOccured = true;
    RESFREE( name );
    return;

READ_DIR_ERROR:
    if( ret == RS_INVALID_RESOURCE ) {
        RcError( ERR_NOT_ICON_FILE, filename );
    } else {
        ReportCopyError( ret, ERR_READING_ICON, filename, err_code );
    }
    ErrorHasOccured = true;
    RESFREE( name );
    FreeIconDir( &dir );
    RESCLOSE( fid );
    return;

WRITE_DIR_ERROR:
    RcError( ERR_WRITTING_RES_FILE, CurrResFile.filename, strerror( err_code ) );
    ErrorHasOccured = true;
    FreeIconDir( &dir );
    RESCLOSE( fid );
    return;

COPY_ICONS_ERROR:
    ReportCopyError( ret, ERR_READING_ICON, filename, err_code );
    ErrorHasOccured = true;
    RESFREE( name );
    FreeIconDir( &dir );
    RESCLOSE( fid );
    return;
} /* AddIconResource */
Exemple #9
0
static void AddFontResources( WResID * name, ResMemFlags flags,
                              char * filename )
/**************************************************************/
{
    FontInfo            info;
    char *              devicename;
    char *              facename;
    int                 handle;
    int                 error;
    int                 err_code;
    ReadStrErrInfo      readstr_err;

    if (name->IsName) {
        RcError( ERR_FONT_NAME );
        return;
    }

    handle = RcIoOpenInput( filename, O_RDONLY | O_BINARY );
    if (handle == -1) goto FILE_OPEN_ERROR;

    error = readFontInfo( handle, &info, &err_code );
    if( error != RS_OK) goto READ_HEADER_ERROR;

    error = copyFont( &info, handle, name, flags, &err_code );
    if( error != RS_OK ) goto COPY_FONT_ERROR;

    devicename = readString( handle, info.dfDevice, &readstr_err );
    if( devicename == NULL ) {
        error = readstr_err.status;
        err_code = readstr_err.err_code;
        goto READ_HEADER_ERROR;
    }

    facename = readString( handle, info.dfFace, &readstr_err );
    if (facename == NULL) {
        error = readstr_err.status;
        err_code = readstr_err.err_code;
        RcMemFree( devicename );
        goto READ_HEADER_ERROR;
    }

    AddFontToDir( &info, devicename, facename, name );

    RcMemFree( devicename );
    RcMemFree( facename );

    RcClose( handle );

    return;


FILE_OPEN_ERROR:
    RcError( ERR_CANT_OPEN_FILE, filename, strerror( errno ) );
    ErrorHasOccured = TRUE;
    RcMemFree( name );
    return;

READ_HEADER_ERROR:
    ReportCopyError( error, ERR_READING_FONT, filename, err_code );
    ErrorHasOccured = TRUE;
    RcMemFree( name );
    RcClose( handle );
    return;

COPY_FONT_ERROR:
    ReportCopyError( error, ERR_READING_FONT, filename, err_code );
    ErrorHasOccured = TRUE;
    RcClose( handle );
    return;
}