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 ); }
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; } } }