Exemplo n.º 1
0
/*
 * RcIoOpenInput
 * NB when an error occurs this function MUST return without altering errno
 */
FILE *RcIoOpenInput( const char *filename, bool text_mode )
/*********************************************************/
{
    FILE                *fp;
    FileStackEntry      *currfile;
    bool                no_handles_available;

    if( text_mode ) {
        fp = fopen( filename, "rt" );
    } else {
        fp = ResOpenFileRO( filename );
    }
    no_handles_available = ( fp == NULL && errno == EMFILE );
    if( no_handles_available ) {
        /* set currfile to be the first (not before first) entry */
        /* close open files except the current input file until able to open */
        /* don't close the current file because Offset isn't set */
        for( currfile = InStack.Stack + 1; currfile < InStack.Current && no_handles_available; ++currfile ) {
            if( currfile->Physical.IsOpen ) {
                ClosePhysicalFile( &(currfile->Physical) );
                if( text_mode ) {
                    fp = fopen( filename, "rt" );
                } else {
                    fp = ResOpenFileRO( filename );
                }
                no_handles_available = ( fp == NULL && errno == EMFILE );
            }
       }
    }
    return( fp );

} /* RcIoOpenInput */
Exemplo n.º 2
0
WRFileType WR_EXPORT WRIdentifyFile( const char *file )
{
    WRFileType  ftype;
    char        ext[_MAX_EXT];
    int         fh;
    int         ok;

    fh = -1;

    ok = (file != NULL);

    if( ok ) {
        _splitpath( file, NULL, NULL, NULL, ext );
        if( !stricmp( ext, ".bmp" ) ) {
            ftype = WRIdentifyWinBMPFile( file );
        } else if( !stricmp( ext, ".cur" ) ) {
            ftype = WRIdentifyWinICOFile( file );
        } else if( !stricmp( ext, ".ico" ) ) {
            ftype = WRIdentifyWinICOFile( file );
        } else if( !stricmp( ext, ".dlg" ) ) {
            //ftype = WRIdentifyWinRCFile( file );
            ftype = WR_WIN_RC_DLG;
        } else if( !stricmp( ext, ".rc" ) ) {
            ftype = WRIdentifyWinRCFile( file );
        } else if( !stricmp( ext, ".str" ) ) {
            ftype = WR_WIN_RC_STR;
        } else if( !stricmp( ext, ".mnu" ) ) {
            ftype = WR_WIN_RC_MENU;
        } else if( !stricmp( ext, ".acc" ) ) {
            ftype = WR_WIN_RC_ACCEL;
        } else if( !stricmp( ext, ".res" ) ) {
            ftype = WRIdentifyRESFile( file );
        } else if( !stricmp( ext, ".exe" ) ) {
            ok = ((fh = ResOpenFileRO( file )) != -1);
            if( ok ) {
                ftype = WRIdentifyEXEFile( fh, FALSE );
            }
        } else if( !stricmp( ext, ".dll" ) ) {
            ok = ((fh = ResOpenFileRO( file )) != -1);
            if ( ok ) {
                ftype = WRIdentifyEXEFile( fh, TRUE );
            }
        } else {
            ok = FALSE;
        }
    }

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

    if( ok ) {
        return( ftype );
    } else {
        return( WR_INVALID_FILE );
    }
}
Exemplo n.º 3
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 );
}
Exemplo n.º 4
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 );
}
Exemplo n.º 5
0
int ConvertFiles( void )
/**********************/
{
    WResFileID      infile;
    int             error;
    int             fileerror;      /* error while deleting or renaming */

    infile = ResOpenFileRO( CmdLineParms.InFileName );
    if (infile == -1) {
        perror( "Error (input file): " );
        return( TRUE );
    }

    if (WResIsWResFile( infile )) {
        /* the input file is in Open Watcom format so convert to MS format */
        error = ConvertFileWResToMRes( infile );
    } else {
        /* the input file is in MS format so convert to Open Watcom format */
        error = ConvertFileMResToWRes( infile );
    }

    ResCloseFile( infile );

    if (error) {
        puts("Error writing to output file");
        fileerror = remove( TMP_FILENAME );
        if (fileerror) {
            perror( NULL );
        }
    } else {
        error = ChangeTmpToOutFile();
    }

    return( error );
} /* ConvertFiles */
Exemplo n.º 6
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 );
}
Exemplo n.º 7
0
static int OpenFiles( WResFileID * fileid1, WResFileID * fileid2 )
/****************************************************************/
/* opens the files named in CmdLineParms and puts their file ids in */
/* fileid1 and fileid2 */
{
    int         error;

    *fileid1 = ResOpenFileRO( CmdLineParms.FileName1 );
    if (*fileid1 == -1) {
        printf( "Unable to open %s\n", CmdLineParms.FileName1 );
        *fileid2 = -1;
        return( true );
    }

    *fileid2 = ResOpenFileRO( CmdLineParms.FileName2 );
    if (*fileid2 == -1) {
        printf( "Unable to open %s\n", CmdLineParms.FileName2 );
        ResCloseFile( *fileid1 );
        *fileid1 = -1;
        return( true );
    }

    error = (!WResIsWResFile( *fileid1 ));
    if (error) {
        printf( "File %s is not a Open Watcom .RES file\n",
                    CmdLineParms.FileName1 );
    } else {
        error = (!WResIsWResFile( *fileid2 ));
        if (error) {
            printf( "File %s is not a Open Watcom .RES file\n",
                    CmdLineParms.FileName2 );
        }
    }

    return( error );
}
Exemplo n.º 8
0
int WRLoadResourceFromWin16EXE( WRInfo *info )
{
    WResFileID  file_handle;
    int         ok;

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

    if( ok ) {
        ok = WRLoadWResDirFromWin16EXE( file_handle, &info->dir );
    }

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

    return( ok );
}
Exemplo n.º 9
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 );
}
Exemplo n.º 10
0
void * WRAPI WRLoadResData( char *file, uint_32 offset, uint_32 length )
{
    void        *data;
    WResFileID  handle;
    int         ok;

    data = NULL;
    handle = -1;

    ok = (file != NULL && length != 0);

    if( ok ) {
        ok = ((data = WRMemAlloc( length )) != NULL);
    }

    if( ok ) {
        ok = ((handle = ResOpenFileRO( file )) != -1);
    }

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

    if( ok ) {
        ok = WRReadResData( handle, (BYTE *)data, length );
    }

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

    if( !ok ) {
        if( data != NULL ) {
            WRMemFree( data );
            data = NULL;
        }
    }

    return( data );
}
Exemplo n.º 11
0
static bool openExeFileInfoRO( const char *filename, ExeFileInfo *info )
/**********************************************************************/
{
    RcStatus        status;
    exe_pe_header   *pehdr;

    info->fp = ResOpenFileRO( filename );
    if( info->fp == NULL ) {
        RcError( ERR_CANT_OPEN_FILE, filename, strerror( errno ) );
        return( false );
    }
    info->IsOpen = true;
    info->Type = FindNEPELXHeader( info->fp, &info->WinHeadOffset );
    info->name = filename;
    switch( info->Type ) {
    case EXE_TYPE_NE_WIN:
    case EXE_TYPE_NE_OS2:
        status = SeekRead( info->fp, info->WinHeadOffset, &info->u.NEInfo.WinHead, sizeof( os2_exe_header ) );
        if( status != RS_OK ) {
            RcError( ERR_NOT_VALID_EXE, filename );
            return( false );
        } else {
            info->DebugOffset = info->WinHeadOffset + sizeof( os2_exe_header );
        }
        break;
    case EXE_TYPE_PE:
        pehdr = &info->u.PEInfo.WinHeadData;
        info->u.PEInfo.WinHead = pehdr;
        status = SeekRead( info->fp, info->WinHeadOffset, &PE32( *pehdr ), sizeof( pe_header ) );
        if( status != RS_OK ) {
            RcError( ERR_NOT_VALID_EXE, filename );
            return( false );
        }
        if( IS_PE64( *pehdr ) ) {
            status = SeekRead( info->fp, info->WinHeadOffset, &PE64( *pehdr ), sizeof( pe_header64 ) );
            if( status != RS_OK ) {
                RcError( ERR_NOT_VALID_EXE, filename );
                return( false );
            }
            info->DebugOffset = info->WinHeadOffset + sizeof( pe_header64 );
        } else {
            info->DebugOffset = info->WinHeadOffset + sizeof( pe_header );
        }
        break;
    case EXE_TYPE_LX:
        status = SeekRead( info->fp, info->WinHeadOffset, &info->u.LXInfo.OS2Head, sizeof( os2_flat_header ) );
        if( status != RS_OK ) {
            RcError( ERR_NOT_VALID_EXE, filename );
            return( false );
        } else {
            info->DebugOffset = info->WinHeadOffset + sizeof( os2_flat_header );
        }
        break;
    default:
        RcError( ERR_NOT_VALID_EXE, filename );
        return( false );
        break;
    }

    return( !RESSEEK( info->fp, 0, SEEK_SET ) );
} /* openExeFileInfoRO */
Exemplo n.º 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 );
}
Exemplo n.º 13
0
WdeDialogBoxInfo *WdeLoadDialogFromRes( WdeResInfo *res_info,
                                        WResLangNode *lnode, bool is32bit )
{
    DialogExHeader32        h32ex;
    DialogBoxHeader32       h32;
    DialogBoxHeader         h16;

    DialogBoxControl        c16;
    DialogBoxControl32      c32;
    DialogBoxExControl32    c32ex;

    WdeDialogBoxInfo        *dlg_info;
    WResFileID              fid;
    WdeDialogBoxControl     *control;
    LIST                    *prev_control;
#if 0
    WdeDialogBoxControl     *nc;
    LIST                    *clist;
#endif
    int                     index;
    char                    *file_name;
    bool                    ok;

    dlg_info = NULL;
    fid = WRES_NIL_HANDLE;

    ok = (res_info != NULL && lnode != NULL);

    if( ok ) {
        file_name = res_info->info->tmp_file;
        dlg_info = (WdeDialogBoxInfo *)WRMemAlloc( sizeof( WdeDialogBoxInfo ) );
        ok = (dlg_info != NULL);
    }

    if( ok ) {
        dlg_info->dialog_header = WdeAllocDialogBoxHeader();
        ok = (dlg_info->dialog_header != NULL);
    }

    if( ok ) {
        dlg_info->dialog_header->is32bit = is32bit;
        dlg_info->control_list = NULL;
        dlg_info->MemoryFlags = 0;
        ok = ((fid = ResOpenFileRO( file_name )) != WRES_NIL_HANDLE);
    }

    if( ok ) {
        dlg_info->MemoryFlags = lnode->Info.MemoryFlags;
        ok = (ResSeek( fid, lnode->Info.Offset, SEEK_SET ) != -1);
    }

    if( ok ) {
        if( is32bit ) {
            /* JPK - check if its an extended dialog */
            dlg_info->dialog_header->is32bitEx = ResIsDialogEx( fid );
            ResSeek( fid, lnode->Info.Offset, SEEK_SET );

            if( dlg_info->dialog_header->is32bitEx ) {
                ok = !ResReadDialogExHeader32( &h32, &h32ex, fid );
            } else {
                ok = !ResReadDialogBoxHeader32( &h32, fid );
            }
        } else {
            ok = !ResReadDialogBoxHeader( &h16, fid );
        }
    }

    if( ok ) {
        if( is32bit ) {
            if( dlg_info->dialog_header->is32bitEx ) {
                dlg_info->dialog_header->FontWeight = h32ex.FontWeight;
                dlg_info->dialog_header->FontItalic = h32ex.FontItalic;
                dlg_info->dialog_header->FontCharset = h32ex.FontCharset;
                dlg_info->dialog_header->HelpId = h32ex.HelpId;
                dlg_info->dialog_header->FontWeightDefined = (h32ex.FontWeightDefined != 0);
                dlg_info->dialog_header->FontItalicDefined = (h32ex.FontItalicDefined != 0);
                dlg_info->dialog_header->FontCharsetDefined = (h32ex.FontCharsetDefined != 0);
            }
            dlg_info->dialog_header->Style = h32.Style;
            dlg_info->dialog_header->ExtendedStyle = h32.ExtendedStyle;
            dlg_info->dialog_header->NumOfItems = h32.NumOfItems;
            dlg_info->dialog_header->Size = h32.Size;
            dlg_info->dialog_header->MenuName = h32.MenuName;
            dlg_info->dialog_header->ClassName = h32.ClassName;
            dlg_info->dialog_header->Caption = h32.Caption;
            dlg_info->dialog_header->PointSize = h32.PointSize;
            dlg_info->dialog_header->FontName = h32.FontName;
        } else {
            dlg_info->dialog_header->Style = h16.Style;
            dlg_info->dialog_header->NumOfItems = h16.NumOfItems;
            dlg_info->dialog_header->Size = h16.Size;
            dlg_info->dialog_header->MenuName = h16.MenuName;
            dlg_info->dialog_header->ClassName = h16.ClassName;
            dlg_info->dialog_header->Caption = h16.Caption;
            dlg_info->dialog_header->PointSize = h16.PointSize;
            dlg_info->dialog_header->FontName = h16.FontName;
        }

        prev_control = NULL;
        for( index = 0; index < GETHDR_NUMITEMS( dlg_info->dialog_header ); index++ ) {
            control = WdeAllocDialogBoxControl();
            if( control == NULL ) {
                ok = false;
                break;
            }
            if( is32bit ) {
                /*
                 * JPK - check which control structure to expect based on
                 *       whether this an extended dialog or not
                */
                if( dlg_info->dialog_header->is32bitEx ) {
                    if( ResReadDialogExControl32( &c32ex, fid ) ) {
                        ok = false;
                        break;
                    }
                    control->HelpId = c32ex.HelpId;
                    control->ExtendedStyle = c32ex.ExtendedStyle;
                    control->Style = c32ex.Style;
                    control->Size = c32ex.Size;
                    control->ID = c32ex.ID;
                    control->ClassID = c32ex.ClassID;
                    control->Text = c32ex.Text;
                    control->ExtraBytes = c32ex.ExtraBytes;
                } else {
                    if( ResReadDialogBoxControl32( &c32, fid ) ) {
                        ok = false;
                        break;
                    }
                    control->Style = c32.Style;
                    control->ExtendedStyle = c32.ExtendedStyle;
                    control->Size = c32.Size;
                    control->ID = c32.ID;
                    control->ClassID = c32.ClassID;
                    control->Text = c32.Text;
                    control->ExtraBytes = c32.ExtraBytes;
                }
            } else {
                if( ResReadDialogBoxControl( &c16, fid ) ) {
                    ok = false;
                    break;
                }
                control->Size = c16.Size;
                control->ID = c16.ID;
                control->Style = c16.Style;
                control->ClassID = c16.ClassID;
                control->Text = c16.Text;
                control->ExtraBytes = c16.ExtraBytes;
            }
            if ( prev_control == NULL ) {
                ListAddElt( &dlg_info->control_list, (void *)control );
                prev_control = dlg_info->control_list;
            } else {
                ListInsertElt( prev_control, (void *)control );
                prev_control = ListNext( prev_control );
            }
        }
    }

#if 0
    /*
     * JPK - if the dialog is 32 bit but not EX, then convert the dialog
     *       header and the control list to EX; this will force all
     *       dialogs to EX, for now
    */
    if( is32bit && !dlg_info->dialog_header->is32bitEx ) {
        /* deal with the dialog header first */
        dlg_info->dialog_header->is32bitEx = TRUE;

        dlg_info->dialog_header->FontWeight = 0;
        dlg_info->dialog_header->FontItalic = 0;
        dlg_info->dialog_header->FontCharset = DEFAULT_CHARSET;
        dlg_info->dialog_header->HelpId = 0;
        dlg_info->dialog_header->FontWeightDefined = FALSE;
        dlg_info->dialog_header->FontItalicDefined = FALSE;
        dlg_info->dialog_header->FontCharsetDefined = FALSE;

        /* now deal with the list of controls */
        nc = (WdeDialogBoxControl *)WRMemAlloc( sizeof( WdeDialogBoxControl ) );
        for( clist = dlg_info->control_list; clist != NULL; clist = ListNext( clist ) ) {
            control = (WdeDialogBoxControl *)ListElement( clist );
            memcpy( nc, control, sizeof( WdeDialogBoxControl ) );

            nc->HelpId = 0;
            nc->ExtendedStyle = control->ExtendedStyle;
            nc->Style = control->Style;
            memcpy( &nc->Size, &control->Size, sizeof( DialogSizeInfo ) );
            nc->ID = control->ID;
            nc->ClassID = control->ClassID;
            nc->Text = control->Text;
            nc->ExtraBytes = control->ExtraBytes;

            memcpy( control, nc, sizeof( WdeDialogBoxControl ) );
        }
        WRMemFree( nc );
    }
#endif

    if( !ok ) {
        if( dlg_info != NULL ) {
            WdeFreeDialogBoxInfo( dlg_info );
            dlg_info = NULL;
        }
    }

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

    return( dlg_info );
}
Exemplo n.º 14
0
static void copyMSFormatRes( WResID * name, WResID * type, ResMemFlags flags,
                ResLocation loc, WResLangType *lang )
/***************************************************************************/
{
    MResResourceHeader  ms_head;
    long                cur_byte_num;
    uint_8              cur_byte;
    long                seek_rc;
    int                 error;
    int                 tmp_handle;

    /* fill in and output a MS format resource header */
    ms_head.Type = WResIDToNameOrOrd( type );
    ms_head.Name = WResIDToNameOrOrd( name );
    ms_head.MemoryFlags = flags;
    ms_head.Size = loc.len;
    ms_head.LanguageId = MAKELANGID( lang->lang, lang->sublang );
    ms_head.Version = 0L; /* Currently Unsupported */
    ms_head.DataVersion = 0L;
    ms_head.Characteristics = 0L; /* Currently Unsupported */

    /* OS/2 resource header happens to be identical to Win16 */
    if( CmdLineParms.TargetOS == RC_TARGET_OS_WIN16 ||
        CmdLineParms.TargetOS == RC_TARGET_OS_OS2 ) {
        error = MResWriteResourceHeader( &ms_head, CurrResFile.handle, FALSE );
    } else {
        error = MResWriteResourceHeader( &ms_head, CurrResFile.handle, TRUE );
    }
    if (error) {
        RcError( ERR_WRITTING_RES_FILE, CurrResFile.filename,
                 LastWresErrStr() );
        RcMemFree( ms_head.Type );
        RcMemFree( ms_head.Name );
        ErrorHasOccured = TRUE;
    } else {
        RcMemFree( ms_head.Type );
        RcMemFree( ms_head.Name );
        tmp_handle = ResOpenFileRO( MSFormatTmpFile );
        if (tmp_handle == -1) {
            RcError( ERR_OPENING_TMP, MSFormatTmpFile, LastWresErrStr() );
            ErrorHasOccured = TRUE;
            return;
        }

        /* copy the data from the temperary file to the RES file */
        seek_rc = ResSeek( tmp_handle, loc.start, SEEK_SET );
        if (seek_rc == -1) {
            RcError( ERR_READING_TMP, MSFormatTmpFile, LastWresErrStr() );
            ResCloseFile( tmp_handle );
            ErrorHasOccured = TRUE;
            return;
        }

        /* this is very inefficient but hopefully the buffering in layer0.c */
        /* will make it tolerable */
        for (cur_byte_num = 0; cur_byte_num < loc.len; cur_byte_num++) {
            error = ResReadUint8( &cur_byte, tmp_handle );
            if( error ) {
                RcError( ERR_READING_TMP, MSFormatTmpFile, LastWresErrStr() );
                ResCloseFile( tmp_handle );
                ErrorHasOccured = TRUE;
                return;
            } else {
                error = ResWriteUint8( &cur_byte, CurrResFile.handle );
                if( error ) {
                    RcError( ERR_WRITTING_RES_FILE,
                             CurrResFile.filename, LastWresErrStr() );
                    ResCloseFile( tmp_handle );
                    ErrorHasOccured = TRUE;
                    return;
                }
            }
        }
        if( ResCloseFile( tmp_handle ) == -1 ) {
            RcError( ERR_WRITTING_RES_FILE, MSFormatTmpFile,
                     LastWresErrStr() );
            ErrorHasOccured = TRUE;
        }
    }
}
Exemplo n.º 15
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 );
}
Exemplo n.º 16
0
static int WRSaveImageToFile( WRInfo *info, WResTypeNode *tnode, int backup )
{
    WResFileID          src;
    WResFileID          dest;
    int                 ok;
    int                 use_rename;
    WResLangNode        *lnode;

    src   = -1;
    dest  = -1;
    lnode = NULL;

    ok = ( info && tnode );

    if( ok ) {
        if( backup && WRFileExists ( info->save_name ) ) {
            use_rename = ( info->file_name &&
                           stricmp( info->file_name, info->save_name ) );
            ok = WRBackupFile( info->save_name, use_rename );
        }
    }

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

    if( ok ) {
        dest = open( info->save_name, O_CREAT | O_WRONLY | O_TRUNC |
                                      O_BINARY, S_IWRITE | S_IREAD );
        ok = ( dest  != -1 );
    }

    if( ok ) {
        if( tnode->Head && tnode->Head->Head ) {
            lnode = tnode->Head->Head;
        }
        ok = ( lnode != NULL );
    }

    if( ok ) {
        if ( lnode->data ) {
            ok = WRCopyResFromDataToFile( lnode->data,
                                          lnode->Info.Length, dest );
        } else {
            ok = WRCopyResFromFileToFile( src, lnode->Info.Offset,
                                          lnode->Info.Length, dest );
        }
    }

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

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

    if ( !ok ) {
        if ( dest != -1 ) {
            WRDeleteFile ( info->save_name );
        }
    }

    return ( ok );
}
Exemplo n.º 17
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 );
}