Beispiel #1
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 */
Beispiel #2
0
int WResOpenNewFile( const char *filename )
/*****************************************/
{
    int     newhandle;

    newhandle = WRESOPEN( filename, O_CREAT | O_WRONLY | O_TRUNC | O_BINARY, PMODE_RW );
    if (newhandle == -1) {
        WRES_ERROR( WRS_OPEN_FAILED );
    } else {
        WResFileInit( newhandle );
    }

    return( newhandle );
}
Beispiel #3
0
static bool saveResourceToRES( WRInfo *info, bool backup, const char *save_name, const char *file_name )
{
    WResFileID  src_fid;
    WResFileID  dst_fid;
    bool        is_wres;
    bool        ok;
    bool        use_rename;
    WRFileType  save_type;

    src_fid = WRES_NIL_HANDLE;
    dst_fid = WRES_NIL_HANDLE;

    ok = true;

    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;
            }
        }
#ifndef __NT__
        ok = !WRIs32Bit( save_type );
        if( !ok ) {
            WRDisplayErrorMsg( WR_NOSAVE32IN16 );
        }
#endif
    }

    if( ok ) {
        if( backup && WRFileExists( save_name ) ) {
            use_rename = (file_name != NULL && stricmp( file_name, save_name ));
            ok = WRBackupFile( save_name, use_rename );
        }
    }

    if( ok ) {
        if( file_name != NULL ) {
            ok = ((src_fid = ResOpenFileRO( info->tmp_file )) != WRES_NIL_HANDLE);
        }
    }

    is_wres = (save_type == WR_WIN16W_RES || save_type == WR_WINNTW_RES);

    if( ok ) {
        ok = ((dst_fid = ResOpenNewFile( save_name )) != WRES_NIL_HANDLE);
        if( ok && is_wres ) {
            ok = !WResFileInit( dst_fid );
        }
    }

    if( ok ) {
        if( is_wres ) {
            ok = WRSaveResourceToWRES( info, src_fid, dst_fid );
        } else {
            ok = WRSaveResourceToMRES( info, src_fid, dst_fid );
        }
    }

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

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

    if( !ok ) {
        if( dst_fid != WRES_NIL_HANDLE ) {
            WRDeleteFile( save_name );
        }
    }

    return( ok );
}