| 2561 | } |
| 2562 | |
| 2563 | UINT8 FfsEngine::replace(const QModelIndex & index, const QByteArray & object, const UINT8 mode) |
| 2564 | { |
| 2565 | if (!index.isValid()) |
| 2566 | return ERR_INVALID_PARAMETER; |
| 2567 | |
| 2568 | // Determine type of item to replace |
| 2569 | UINT32 headerSize; |
| 2570 | UINT8 result; |
| 2571 | if (model->type(index) == Types::Region) { |
| 2572 | if (mode == REPLACE_MODE_AS_IS) |
| 2573 | result = create(index, Types::Region, QByteArray(), object, CREATE_MODE_AFTER, Actions::Replace); |
| 2574 | else |
| 2575 | return ERR_NOT_IMPLEMENTED; |
| 2576 | } |
| 2577 | else if (model->type(index) == Types::Padding) { |
| 2578 | if (mode == REPLACE_MODE_AS_IS) |
| 2579 | result = create(index, Types::Padding, QByteArray(), object, CREATE_MODE_AFTER, Actions::Replace); |
| 2580 | else |
| 2581 | return ERR_NOT_IMPLEMENTED; |
| 2582 | } |
| 2583 | else if (model->type(index) == Types::Volume) { |
| 2584 | if (mode == REPLACE_MODE_AS_IS) { |
| 2585 | result = create(index, Types::Volume, QByteArray(), object, CREATE_MODE_AFTER, Actions::Replace); |
| 2586 | } |
| 2587 | else if (mode == REPLACE_MODE_BODY) { |
| 2588 | result = create(index, Types::Volume, model->header(index), object, CREATE_MODE_AFTER, Actions::Replace); |
| 2589 | } |
| 2590 | else |
| 2591 | return ERR_NOT_IMPLEMENTED; |
| 2592 | } |
| 2593 | else if (model->type(index) == Types::File) { |
| 2594 | if (mode == REPLACE_MODE_AS_IS) { |
| 2595 | headerSize = sizeof(EFI_FFS_FILE_HEADER); |
| 2596 | result = create(index, Types::File, object.left(headerSize), object.right(object.size() - headerSize), CREATE_MODE_AFTER, Actions::Replace); |
| 2597 | } |
| 2598 | else if (mode == REPLACE_MODE_BODY) |
| 2599 | result = create(index, Types::File, model->header(index), object, CREATE_MODE_AFTER, Actions::Replace); |
| 2600 | else |
| 2601 | return ERR_NOT_IMPLEMENTED; |
| 2602 | } |
| 2603 | else if (model->type(index) == Types::Section) { |
| 2604 | if (mode == REPLACE_MODE_AS_IS) { |
| 2605 | const EFI_COMMON_SECTION_HEADER* commonHeader = (const EFI_COMMON_SECTION_HEADER*)object.constData(); |
| 2606 | headerSize = sizeOfSectionHeader(commonHeader); |
| 2607 | result = create(index, Types::Section, object.left(headerSize), object.right(object.size() - headerSize), CREATE_MODE_AFTER, Actions::Replace); |
| 2608 | } |
| 2609 | else if (mode == REPLACE_MODE_BODY) { |
| 2610 | result = create(index, Types::Section, model->header(index), object, CREATE_MODE_AFTER, Actions::Replace, model->compression(index)); |
| 2611 | } |
| 2612 | else |
| 2613 | return ERR_NOT_IMPLEMENTED; |
| 2614 | } |
| 2615 | else |
| 2616 | return ERR_NOT_IMPLEMENTED; |
| 2617 | |
| 2618 | // Check create result |
| 2619 | if (result) |
| 2620 | return result; |
no test coverage detected