2015-04-02 16:07:32 +08:00
|
|
|
/* fssops.cpp
|
|
|
|
|
|
|
|
Copyright (c) 2015, Nikolaj Schlej. All rights reserved.
|
|
|
|
This program and the accompanying materials
|
|
|
|
are licensed and made available under the terms and conditions of the BSD License
|
|
|
|
which accompanies this distribution. The full text of the license may be found at
|
|
|
|
http://opensource.org/licenses/bsd-license.php
|
|
|
|
|
|
|
|
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "ffsops.h"
|
2016-10-10 14:05:04 +08:00
|
|
|
#include "ffs.h"
|
|
|
|
#include "utility.h"
|
2015-04-02 16:07:32 +08:00
|
|
|
|
2016-07-07 13:57:45 +08:00
|
|
|
USTATUS FfsOperations::extract(const UModelIndex & index, UString & name, UByteArray & extracted, const UINT8 mode)
|
2015-04-02 16:07:32 +08:00
|
|
|
{
|
|
|
|
// Sanity check
|
|
|
|
if (!index.isValid())
|
2016-07-07 13:57:45 +08:00
|
|
|
return U_INVALID_PARAMETER;
|
2015-04-02 16:07:32 +08:00
|
|
|
|
2016-04-17 07:25:44 +08:00
|
|
|
// Default name
|
2016-10-28 00:31:15 +08:00
|
|
|
name = uniqueItemName(index);
|
2015-04-02 16:07:32 +08:00
|
|
|
|
|
|
|
// Get extracted data
|
|
|
|
if (mode == EXTRACT_MODE_AS_IS) {
|
|
|
|
// Extract as is, with header body and tail
|
|
|
|
extracted.clear();
|
|
|
|
extracted.append(model->header(index));
|
|
|
|
extracted.append(model->body(index));
|
2016-04-21 04:41:18 +08:00
|
|
|
extracted.append(model->tail(index));
|
2015-04-02 16:07:32 +08:00
|
|
|
}
|
|
|
|
else if (mode == EXTRACT_MODE_BODY) {
|
2016-03-01 15:20:44 +08:00
|
|
|
name += QObject::tr("_body");
|
2015-04-02 16:07:32 +08:00
|
|
|
// Extract without header and tail
|
|
|
|
extracted.clear();
|
|
|
|
extracted.append(model->body(index));
|
|
|
|
}
|
2015-09-01 03:34:42 +08:00
|
|
|
else if (mode == EXTRACT_MODE_BODY_UNCOMPRESSED) {
|
2016-03-01 15:20:44 +08:00
|
|
|
name += QObject::tr("_body_unc");
|
2015-09-01 03:34:42 +08:00
|
|
|
// Extract without header and tail, uncompressed
|
|
|
|
extracted.clear();
|
|
|
|
// There is no need to redo decompression, we can use child items
|
|
|
|
for (int i = 0; i < model->rowCount(index); i++) {
|
2016-07-07 13:57:45 +08:00
|
|
|
UModelIndex childIndex = index.child(i, 0);
|
2016-04-21 04:41:18 +08:00
|
|
|
// Ensure 4-byte alignment of current section
|
2016-07-07 13:57:45 +08:00
|
|
|
extracted.append(UByteArray('\x00', ALIGN4((UINT32)extracted.size()) - (UINT32)extracted.size()));
|
2016-04-21 04:41:18 +08:00
|
|
|
// Add current section header, body and tail
|
2015-09-01 03:34:42 +08:00
|
|
|
extracted.append(model->header(childIndex));
|
|
|
|
extracted.append(model->body(childIndex));
|
2016-04-21 04:41:18 +08:00
|
|
|
extracted.append(model->tail(childIndex));
|
2015-09-01 03:34:42 +08:00
|
|
|
}
|
|
|
|
}
|
2015-04-02 16:07:32 +08:00
|
|
|
else
|
2016-07-07 13:57:45 +08:00
|
|
|
return U_UNKNOWN_EXTRACT_MODE;
|
2015-04-02 16:07:32 +08:00
|
|
|
|
2016-07-07 13:57:45 +08:00
|
|
|
return U_SUCCESS;
|
2015-04-02 16:07:32 +08:00
|
|
|
}
|
|
|
|
|
2016-07-07 13:57:45 +08:00
|
|
|
USTATUS FfsOperations::replace(const UModelIndex & index, const UString & data, const UINT8 mode)
|
2016-03-01 15:20:44 +08:00
|
|
|
{
|
2016-11-03 03:40:38 +08:00
|
|
|
U_UNUSED_PARAMETER(data);
|
|
|
|
|
2016-03-01 15:20:44 +08:00
|
|
|
// Sanity check
|
|
|
|
if (!index.isValid())
|
2016-07-07 13:57:45 +08:00
|
|
|
return U_INVALID_PARAMETER;
|
2016-03-01 15:20:44 +08:00
|
|
|
|
|
|
|
if (mode == REPLACE_MODE_AS_IS) {
|
2016-07-07 13:57:45 +08:00
|
|
|
return U_NOT_IMPLEMENTED;
|
2016-03-01 15:20:44 +08:00
|
|
|
}
|
|
|
|
else if (mode == REPLACE_MODE_BODY) {
|
2016-07-07 13:57:45 +08:00
|
|
|
return U_NOT_IMPLEMENTED;
|
2016-03-01 15:20:44 +08:00
|
|
|
}
|
|
|
|
|
2018-05-08 23:42:16 +08:00
|
|
|
return U_UNKNOWN_REPLACE_MODE;
|
2016-03-01 15:20:44 +08:00
|
|
|
}
|
|
|
|
|
2016-07-07 13:57:45 +08:00
|
|
|
USTATUS FfsOperations::remove(const UModelIndex & index)
|
2016-03-01 15:20:44 +08:00
|
|
|
{
|
|
|
|
// Sanity check
|
|
|
|
if (!index.isValid())
|
2016-07-07 13:57:45 +08:00
|
|
|
return U_INVALID_PARAMETER;
|
2016-03-01 15:20:44 +08:00
|
|
|
|
|
|
|
// Set remove action
|
|
|
|
model->setAction(index, Actions::Remove);
|
|
|
|
|
2016-07-07 13:57:45 +08:00
|
|
|
return U_SUCCESS;
|
2016-03-01 15:20:44 +08:00
|
|
|
}
|
|
|
|
|
2016-07-07 13:57:45 +08:00
|
|
|
USTATUS FfsOperations::rebuild(const UModelIndex & index)
|
2016-03-01 15:20:44 +08:00
|
|
|
{
|
|
|
|
// Sanity check
|
|
|
|
if (!index.isValid())
|
2016-07-07 13:57:45 +08:00
|
|
|
return U_INVALID_PARAMETER;
|
2016-03-01 15:20:44 +08:00
|
|
|
|
|
|
|
// On insert action, set insert action for children
|
|
|
|
//if (action == Actions::Insert)
|
|
|
|
// for (int i = 0; i < item->childCount(); i++)
|
|
|
|
// setAction(index.child(i, 0), Actions::Insert);
|
|
|
|
|
|
|
|
// Set rebuild action
|
|
|
|
model->setAction(index, Actions::Rebuild);
|
|
|
|
|
|
|
|
// Rebuild parent, if it has no action now
|
2016-07-07 13:57:45 +08:00
|
|
|
UModelIndex parent = index.parent();
|
2016-03-01 15:20:44 +08:00
|
|
|
if (parent.isValid() && model->type(parent) != Types::Root
|
|
|
|
&& model->action(parent) == Actions::NoAction)
|
|
|
|
rebuild(parent);
|
|
|
|
|
2016-07-07 13:57:45 +08:00
|
|
|
return U_SUCCESS;
|
2016-03-01 15:20:44 +08:00
|
|
|
}
|