⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wrmain.c

📁 开放源码的编译器open watcom 1.6.0版的源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
    int           ok;

    info = NULL;

    ok = ( file && idata->type && idata->name && idata->data &&
           ( ( file_type == WR_WIN_BITMAP ) ||
             ( file_type == WR_WIN_CURSOR ) ||
             ( file_type == WR_WIN_ICON ) ||
             ( file_type == WR_WIN_RC ) ||
             ( file_type == WR_WIN_RC_STR ) ||
             ( file_type == WR_WIN_RC_MENU ) ||
             ( file_type == WR_WIN_RC_ACCEL ) ||
             ( file_type == WR_WIN_RC_DLG ) ||
             ( file_type == WR_WIN16M_RES ) ||
             ( file_type == WR_WIN16W_RES ) ||
             ( file_type == WR_WINNTM_RES ) ||
             ( file_type == WR_WINNTW_RES ) ) );

    if ( ok ) {
        info = WRAllocWRInfo ();
        ok = ( info != NULL );
    }

    if ( ok ) {
        ok = ( ( info->dir = WResInitDir() ) != NULL );
    }

    if ( ok ) {
        info->save_type = file_type;
        info->save_name = (char *) file;
    }

    while( ok && idata ) {
        type = WResIDToNum( idata->type );
        if( type == (long)RT_GROUP_ICON ) {
            ok = WREDoSaveImageAs( info, idata, TRUE );
        } else if( type == (long)RT_GROUP_CURSOR ) {
            ok = WREDoSaveImageAs( info, idata, FALSE );
        } else {
            ok = WREDoSaveObjectAs( info, idata );
        }
        idata = idata->next;
    }

    if ( ok ) {
        ok = WRSaveResource( info, TRUE );
    }

    if ( info ) {
        info->save_name = NULL;
        WRCleanDir( info->dir );
        WRFreeWRInfo ( info );
    }

    return ( ok );
}

int WR_EXPORT WRSaveObjectInto ( const char *file, WRSaveIntoData *idata,
                                 int *dup )
{
    WRInfo       *info;
    char         *tmp_file;
    char          ext[_MAX_EXT];
    long          type;
    int           ok;

    info        = NULL;
    tmp_file    = NULL;

    ok = ( file && idata && dup );

    if( ok ) {
        info = WRLoadResource( file, WR_DONT_KNOW );
        ok = ( info != NULL );
    }

    if( ok ) {
        _splitpath( info->file_name, NULL, NULL, NULL, ext );
        ok = ( ( tmp_file = WRGetTempFileName ( ext ) ) != NULL );
    }

    if( ok ) {
        info->save_type = info->file_type;
        info->save_name = tmp_file;
    }

    // loop thru all of the data
    while( ok && idata ) {
        type = WResIDToNum( idata->type );
        if( type == (long)RT_GROUP_ICON ) {
            ok = WREDoSaveImageInto ( info, idata, dup, TRUE );
        } else if( type == (long)RT_GROUP_CURSOR ) {
            ok = WREDoSaveImageInto ( info, idata, dup, FALSE );
        } else {
            ok = WREDoSaveObjectInto( info, idata, dup );
        }
        idata = idata->next;
    }

    if( ok ) {
        ok = WRSaveResource( info, TRUE );
    }

    if( ok ) {
        ok = WRRenameFile( info->file_name, info->save_name );
    }

    if( info ) {
        info->save_name = NULL;
        WRCleanDir( info->dir );
        WRFreeWRInfo( info );
    }

    if( tmp_file ) {
        WRMemFree( tmp_file );
    }

    return( ok );
}

int WR_EXPORT WRFindAndSetData( WResDir dir, WResID *type, WResID *name,
                                WResLangType *lang, void *data )
{
    WResLangNode *lnode;
    int           ok;

    ok = ( dir && type && name && lang && data );

    if( ok ) {
        lnode = WRFindLangNode( dir, type, name, lang );
        ok = ( lnode != NULL );
    }

    if( ok ) {
        lnode->data = data;
    }

    return( ok );
}

WResLangNode * WR_EXPORT WRFindLangNode( WResDir dir, WResID *type,
                                         WResID *name, WResLangType *lang )
{
    WResTypeNode *tnode;
    WResResNode  *rnode;
    WResLangNode *lnode;
    int           ok;

    ok = ( dir && type && name && lang );

    if( ok ) {
        tnode = WRFindTypeNodeFromWResID( dir, type );
        ok = ( tnode != NULL );
    }

    if( ok ) {
        rnode = WRFindResNodeFromWResID( tnode, name );
        ok = ( rnode != NULL );
    }

    if( ok ) {
        lnode = WRFindLangNodeFromLangType( rnode, lang );
        ok = ( lnode != NULL );
    }

    if( !ok ) {
        lnode = NULL;
    }

    return( lnode );
}

int WREDoSaveObjectAs( WRInfo *info, WRSaveIntoData *idata )
{
    int           ok;

    ok = ( info && info->dir && idata && idata->type && idata->name &&
           idata->data );

    if( ok ) {
        ok = !WResAddResource( idata->type, idata->name, idata->MemFlags, 0,
                               idata->size, info->dir, &idata->lang, NULL );
    }

    if( ok ) {
        ok = WRFindAndSetData( info->dir, idata->type, idata->name,
                               &idata->lang, idata->data );
    }

    return( ok );
}

int WREDoSaveImageAs( WRInfo *info, WRSaveIntoData *idata, int is_icon )
{
    int                 ok;
    BYTE                *data;
    uint_32             size;
    WResLangNode        *lnode;

    data = NULL;
    ok = ( info && info->dir && idata && idata->type && idata->name &&
           idata->data && idata->info );

    if( ok ) {
        lnode = WRFindLangNode( idata->info->dir, idata->type,
                                idata->name, &idata->lang );
        ok = ( lnode != NULL );
    }

    if( ok ) {
        if( is_icon ) {
            ok = WRCreateIconData( idata->info, lnode, &data, &size );
        } else {
            ok = WRCreateCursorData( idata->info, lnode, &data, &size );
        }
    }

    if( ok ) {
        ok = !WResAddResource( idata->type, idata->name, idata->MemFlags, 0,
                               idata->size, info->dir, &idata->lang, NULL );
    }

    if( ok ) {
        lnode = WRFindLangNode( info->dir, idata->type,
                                idata->name, &idata->lang );
        ok = ( lnode != NULL );
    }

    if( ok ) {
        if( is_icon ) {
            ok = WRCreateIconEntries( info, lnode, data, size );
        } else {
            ok = WRCreateCursorEntries( info, lnode, data, size );
        }
    }

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

    return( ok );
}

int WREDoSaveObjectInto( WRInfo *info, WRSaveIntoData *idata, int *dup )
{
    int ok;
    int replace_nixed;

    replace_nixed = FALSE;

    ok = ( info && idata && idata->type && idata->name && idata->data
           && dup );

    if( ok ) {
        ok = WRTestReplace( info, idata );
        replace_nixed = !ok;
    }

    if( ok ) {
        ok = !WResAddResource( idata->type, idata->name, idata->MemFlags, 0,
                               idata->size, info->dir, &idata->lang, dup );
        ok = ok && !*dup;
    }

    if( ok ) {
        ok = WRFindAndSetData( info->dir, idata->type, idata->name,
                               &idata->lang, idata->data );
    }

    if( replace_nixed ) {
        return( TRUE );
    }

    return( ok );
}

int WREDoSaveImageInto( WRInfo *info, WRSaveIntoData *idata,
                        int *dup, int is_icon )
{
    BYTE                *data;
    uint_32             size;
    WResLangNode        *lnode;
    int                 replace_nixed;
    int                 ok;

    replace_nixed = FALSE;
    data = NULL;
    ok = ( info && info->dir && idata && idata->type && idata->name &&
           idata->data && idata->info && dup );

    if( ok ) {
        ok = WRTestReplace( info, idata );
        replace_nixed = !ok;
    }

    if( ok ) {
        lnode = WRFindLangNode( idata->info->dir, idata->type,
                                idata->name, &idata->lang );
        ok = ( lnode != NULL );
    }

    if( ok ) {
        if( is_icon ) {
            ok = WRCreateIconData( idata->info, lnode, &data, &size );
        } else {
            ok = WRCreateCursorData( idata->info, lnode, &data, &size );
        }
    }

    if( ok ) {
        ok = !WResAddResource( idata->type, idata->name, idata->MemFlags, 0,
                               idata->size, info->dir, &idata->lang, dup );
        ok = ok && !*dup;
    }

    if( ok ) {
        lnode = WRFindLangNode( info->dir, idata->type,
                                idata->name, &idata->lang );
        ok = ( lnode != NULL );
    }

    if( ok ) {
        if( is_icon ) {
            ok = WRCreateIconEntries( info, lnode, data, size );
        } else {
            ok = WRCreateCursorEntries( info, lnode, data, size );
        }
    }

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

    if( replace_nixed ) {
        return( TRUE );
    }

    return( ok );
}

int WQueryReplaceObject( void )
{
    int         ret;
    UINT        style;
    char        *title;
    char        *text;

    title = WRAllocRCString( WR_COPYRESINTO );
    text = WRAllocRCString( WR_REPLACERES );

    style = MB_YESNO | MB_APPLMODAL | MB_ICONEXCLAMATION;

    ret = MessageBox( HWND_DESKTOP, text, title, style );

    if( title ) {
        WRFreeRCString( title );
    }

    if( text ) {
        WRFreeRCString( text );
    }

    if( ret == IDNO ) {
        return( FALSE );
    }

    return( TRUE );
}

int WQueryMergeStrings( WResID *rname )
{
    int         ret;
    UINT        style;
    char        *text;
    char        *title;
    char        *str;

    ret = IDNO;
    style = MB_YESNO | MB_APPLMODAL | MB_ICONEXCLAMATION;

    title = WRAllocRCString( WR_COPYRESINTO );
    text = WRAllocRCString( WR_REPLACESTR );

    if( text ) {
        str = (char *)WRMemAlloc( strlen(text) + 1 + 10 ); // space for 10 digits
        if( str ) {
            sprintf( str, text, rname->ID.Num );
            ret = MessageBox ( HWND_DESKTOP, str, title, style );
            WRMemFree( str );
        }
        WRFreeRCString( text );
    }


    if( title ) {
        WRFreeRCString( title );
    }

    if( ret == IDNO ) {
        return( FALSE );
    }

    return( TRUE );
}

// this function returns TRUE if the save into may continue
int WRTestReplace( WRInfo *info, WRSaveIntoData *idata )
{
    WResTypeNode *tnode;
    WResResNode  *rnode;
    WResLangNode *lnode;
    long          type;
    void         *data;
    int           size;
    int           strings;

    if( !info || !info->dir || !idata || !idata->type ||
        !idata->name ) {
        return( FALSE );
    }

    type = WResIDToNum( idata->type );

    strings = ( type == (long)RT_STRING );

    tnode = WRFindTypeNodeFromWResID( info->dir, idata->type );
    if( tnode == NULL ) {
        return( TRUE );
    }

    rnode = WRFindResNodeFromWResID( tnode, idata->name );
    if( rnode == NULL ) {
        return( TRUE );
    }

    lnode = WRFindLangNodeFromLangType( rnode, &idata->lang );
    if( lnode == NULL ) {
        return( TRUE );
    }

    if( strings ) {
        if( !WQueryMergeStrings( idata->name ) ) {
            return( FALSE );
        }
        data = WRLoadResData( info->file_name, lnode->Info.Offset,
                              lnode->Info.Length );
        size = lnode->Info.Length;
        if( !WRMergeStringData( &data, &size, idata->data, idata->size,
                                WRIs32Bit( info->save_type), TRUE ) ) {
            if( data ) {
                WRMemFree( data );
            }
            return( FALSE );
        }
        if( idata->data ) {
            WRMemFree( idata->data );
        }
        idata->data = data;
        idata->size = size;
    } else {
        if( !WQueryReplaceObject() ) {
            return( FALSE );
        }
    }

    if( ( type == (long)RT_GROUP_ICON ) || ( type == (long)RT_GROUP_CURSOR ) ) {
        if( !WRDeleteGroupImages( info, lnode, type ) ) {
            return( FALSE );
        }
    }

    if( !WRRemoveLangNodeFromDir( info->dir, &tnode, &rnode, &lnode ) ) {
        return( FALSE );
    }

    return( TRUE );
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -