Example #1
0
static bool WRWriteResourceToWRES( WResTypeNode *tnode, WResResNode *rnode,
                                  WResDir new_dir, WResFileID src_fid,
                                  WResFileID dst_fid, bool is32bit )
{
    WResLangType    lt;
    WResLangNode    *lnode;
    uint_32         offset;
    bool            dup;

    if( is32bit ) {
        if( ResWritePadDWord( dst_fid ) ) {
            return( false );
        }
    }

    offset = RESTELL( dst_fid );

    lnode = rnode->Head;

    while( lnode != NULL ) {
        lt = lnode->Info.lang;
        if( WResAddResource( &tnode->Info.TypeName, &rnode->Info.ResName,
                             lnode->Info.MemoryFlags, offset,
                             lnode->Info.Length, new_dir,
                             &lt, &dup ) || dup ) {
            if( dup ) {
                displayDupMsg( &tnode->Info.TypeName, &rnode->Info.ResName );
            }
            return( false );
        }

        if( lnode->data != NULL ) {
            if( !WRCopyResFromDataToFile( lnode->data, lnode->Info.Length, dst_fid ) ) {
                return( false );
            }
        } else {
            if( !WRCopyResFromFileToFile( src_fid, lnode->Info.Offset,
                                          lnode->Info.Length, dst_fid ) ) {
                return( false );
            }
        }
        if( lnode == rnode->Tail ) {
            break;
        }
        lnode = lnode->Next;
        offset += lnode->Info.Length;
    }

    return( true );
}
Example #2
0
static bool WRWriteResourceToMRES( WResTypeNode *tnode, WResResNode *rnode,
                                  WResFileID src_fid, WResFileID dst_fid )
{
    WResLangNode        *lnode;
    MResResourceHeader  mheader;
    bool                ok;

    lnode = rnode->Head;
    ok = true;

    while( lnode != NULL && ok ) {
        mheader.Size = lnode->Info.Length;
        mheader.MemoryFlags = lnode->Info.MemoryFlags;
        mheader.Type = WResIDToNameOrOrd( &tnode->Info.TypeName );
        mheader.Name = WRCreateMRESResName( rnode, lnode );
        ok = (mheader.Type != NULL && mheader.Name != NULL);
        if( ok ) {
            ok = !MResWriteResourceHeader( &mheader, dst_fid, FALSE );
        }
        if( ok ) {
            if( lnode->data != NULL ) {
                ok = WRCopyResFromDataToFile( lnode->data, lnode->Info.Length, dst_fid );
            } else {
                ok = WRCopyResFromFileToFile( src_fid, lnode->Info.Offset,
                                              lnode->Info.Length, dst_fid );
            }
        }
        if( mheader.Type != NULL ) {
            MemFree( mheader.Type );
        }
        if( mheader.Name != NULL ) {
            MemFree( mheader.Name );
        }
        if( lnode == rnode->Tail ) {
            break;
        }
        lnode = lnode->Next;
    }

    return( ok );
}
Example #3
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 );
}