2016-06-25 18:22:28 +08:00
|
|
|
/* fssreport.cpp
|
|
|
|
|
|
|
|
Copyright (c) 2016, 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 "ffsreport.h"
|
|
|
|
|
2016-06-26 11:54:21 +08:00
|
|
|
std::vector<UString> FfsReport::generate()
|
2016-06-25 18:22:28 +08:00
|
|
|
{
|
2016-06-26 11:54:21 +08:00
|
|
|
std::vector<UString> report;
|
2016-06-25 18:22:28 +08:00
|
|
|
|
|
|
|
// Check model pointer
|
|
|
|
if (!model) {
|
2016-06-26 11:54:21 +08:00
|
|
|
report.push_back(UString("ERROR: Invalid model pointer provided"));
|
2016-06-25 18:22:28 +08:00
|
|
|
return report;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check root index to be valid
|
2016-06-26 11:54:21 +08:00
|
|
|
UModelIndex root = model->index(0,0);
|
2016-06-25 18:22:28 +08:00
|
|
|
if (!root.isValid()) {
|
2016-06-26 11:54:21 +08:00
|
|
|
report.push_back(UString("ERROR: Model root index is invalid"));
|
2016-06-25 18:22:28 +08:00
|
|
|
return report;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Generate report recursive
|
2016-06-26 11:54:21 +08:00
|
|
|
report.push_back(UString(" Type | Subtype | Size | CRC32 | Name "));
|
|
|
|
USTATUS result = generateRecursive(report, root);
|
2016-06-25 18:22:28 +08:00
|
|
|
if (result) {
|
2016-06-26 11:54:21 +08:00
|
|
|
report.push_back(UString("ERROR: generateRecursive returned ") + errorCodeToUString(result));
|
2016-06-25 18:22:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return report;
|
|
|
|
}
|
|
|
|
|
2016-06-26 11:54:21 +08:00
|
|
|
USTATUS FfsReport::generateRecursive(std::vector<UString> & report, UModelIndex index, UINT32 level)
|
2016-06-25 18:22:28 +08:00
|
|
|
{
|
|
|
|
if (!index.isValid())
|
2016-06-26 11:54:21 +08:00
|
|
|
return U_SUCCESS; //Nothing to report for invalid index
|
2016-06-25 18:22:28 +08:00
|
|
|
|
|
|
|
// Calculate item CRC32
|
2016-06-26 11:54:21 +08:00
|
|
|
UByteArray data = model->header(index) + model->body(index) + model->tail(index);
|
2016-06-25 18:22:28 +08:00
|
|
|
UINT32 crc = crc32(0, (const UINT8*)data.constData(), data.size());
|
|
|
|
|
|
|
|
// Information on current item
|
2016-06-26 11:54:21 +08:00
|
|
|
UString text = model->text(index);
|
|
|
|
report.push_back(
|
|
|
|
UString(" ") + itemTypeToUString(model->type(index)).leftJustified(16)
|
|
|
|
+ UString("| ") + itemSubtypeToUString(model->type(index), model->subtype(index)).leftJustified(22)
|
|
|
|
+ usprintf("| %08X | %08X | ", data.size(), crc)
|
|
|
|
+ UString(level, '-') + UString(" ") + model->name(index) + (text.isEmpty() ? UString("") : UString(" | ") + text)
|
2016-06-25 18:22:28 +08:00
|
|
|
);
|
|
|
|
|
|
|
|
// Information on child items
|
|
|
|
for (int i = 0; i < model->rowCount(index); i++) {
|
|
|
|
generateRecursive(report, index.child(i,0), level + 1);
|
|
|
|
}
|
|
|
|
|
2016-06-26 11:54:21 +08:00
|
|
|
return U_SUCCESS;
|
2016-06-25 18:22:28 +08:00
|
|
|
}
|