Various SCAN fixes + MP3 support

This commit is contained in:
parax0 2015-07-28 01:47:48 -04:00
parent d13d221165
commit 836d1d404a
11 changed files with 133 additions and 64 deletions

View File

@ -18,6 +18,11 @@ EResType CScan::Type()
return eScan; return eScan;
} }
EGame CScan::Version()
{
return mVersion;
}
CStringTable* CScan::ScanText() CStringTable* CScan::ScanText()
{ {
return mpStringTable; return mpStringTable;

View File

@ -3,6 +3,7 @@
#include "CResource.h" #include "CResource.h"
#include "CStringTable.h" #include "CStringTable.h"
#include "EFormatVersion.h"
#include <Core/CToken.h> #include <Core/CToken.h>
class CScan : public CResource class CScan : public CResource
@ -21,6 +22,7 @@ public:
}; };
private: private:
EGame mVersion;
CResource *mpFrame; CResource *mpFrame;
CStringTable *mpStringTable; CStringTable *mpStringTable;
CToken mFrameToken; CToken mFrameToken;
@ -33,6 +35,7 @@ public:
CScan(); CScan();
~CScan(); ~CScan();
EResType Type(); EResType Type();
EGame Version();
CStringTable* ScanText(); CStringTable* ScanText();
bool IsImportant(); bool IsImportant();
bool IsSlow(); bool IsSlow();

View File

@ -15,6 +15,7 @@ CScan* CScanLoader::LoadScanMP1(CInputStream &SCAN)
mpScan->mIsSlow = (SCAN.ReadLong() != 0); mpScan->mIsSlow = (SCAN.ReadLong() != 0);
mpScan->mCategory = (CScan::ELogbookCategory) SCAN.ReadLong(); mpScan->mCategory = (CScan::ELogbookCategory) SCAN.ReadLong();
mpScan->mIsImportant = (SCAN.ReadByte() == 1); mpScan->mIsImportant = (SCAN.ReadByte() == 1);
mpScan->mVersion = ePrime;
return mpScan; return mpScan;
} }
@ -60,7 +61,9 @@ CScan* CScanLoader::LoadScanMP2(CInputStream& SCAN)
case 0x14: case 0x14:
LoadParamsMP2(SCAN); LoadParamsMP2(SCAN);
break; break;
case 0x16:
LoadParamsMP3(SCAN);
break;
default: default:
Log::FileError(SCAN.GetSourceString(), SCAN.Tell() - 2, "Invalid SNFO property count: " + StringUtil::ToHexString(NumProperties)); Log::FileError(SCAN.GetSourceString(), SCAN.Tell() - 2, "Invalid SNFO property count: " + StringUtil::ToHexString(NumProperties));
delete mpScan; delete mpScan;
@ -70,7 +73,7 @@ CScan* CScanLoader::LoadScanMP2(CInputStream& SCAN)
return mpScan; return mpScan;
} }
void CScanLoader::LoadParamsMP2(CInputStream &SCAN) void CScanLoader::LoadParamsMP2(CInputStream& SCAN)
{ {
// Function begins after the SNFO property count // Function begins after the SNFO property count
for (u32 iProp = 0; iProp < 20; iProp++) for (u32 iProp = 0; iProp < 20; iProp++)
@ -93,11 +96,39 @@ void CScanLoader::LoadParamsMP2(CInputStream &SCAN)
case 0x7B714814: case 0x7B714814:
mpScan->mIsImportant = (SCAN.ReadByte() != 0); mpScan->mIsImportant = (SCAN.ReadByte() != 0);
break; break;
}
case 0x53336141: SCAN.Seek(Next, SEEK_SET);
u32 TextureID = SCAN.ReadLong(); }
if (TextureID != 0xFFFFFFFF)
Log::FileWarning(SCAN.GetSourceString(), "SCAN with texture found!"); mpScan->mCategory = CScan::eNone;
mpScan->mVersion = eEchoes;
}
void CScanLoader::LoadParamsMP3(CInputStream& SCAN)
{
// Function begins after the SNFO property count
// Function is near-identical to the MP2 one, but when I add support
// for the other params, there will be more differences
for (u32 iProp = 0; iProp < 20; iProp++)
{
u32 PropertyID = SCAN.ReadLong();
u16 PropertySize = SCAN.ReadShort();
u32 Next = SCAN.Tell() + PropertySize;
switch (PropertyID)
{
case 0x2F5B6423:
mpScan->mpStringTable = (CStringTable*) gResCache.GetResource(SCAN.ReadLongLong(), "STRG");
mpScan->mStringToken = CToken(mpScan->mpStringTable);
break;
case 0xC308A322:
mpScan->mIsSlow = (SCAN.ReadLong() != 0);
break;
case 0x7B714814:
mpScan->mIsImportant = (SCAN.ReadByte() != 0);
break; break;
} }
@ -105,6 +136,7 @@ void CScanLoader::LoadParamsMP2(CInputStream &SCAN)
} }
mpScan->mCategory = CScan::eNone; mpScan->mCategory = CScan::eNone;
mpScan->mVersion = eCorruption;
} }
// ************ STATIC/PUBLIC ************ // ************ STATIC/PUBLIC ************

View File

@ -13,6 +13,7 @@ class CScanLoader
CScan* LoadScanMP1(CInputStream& SCAN); CScan* LoadScanMP1(CInputStream& SCAN);
CScan* LoadScanMP2(CInputStream& SCAN); CScan* LoadScanMP2(CInputStream& SCAN);
void LoadParamsMP2(CInputStream& SCAN); void LoadParamsMP2(CInputStream& SCAN);
void LoadParamsMP3(CInputStream& SCAN);
public: public:
static CScan* LoadSCAN(CInputStream& SCAN); static CScan* LoadSCAN(CInputStream& SCAN);

View File

@ -16,9 +16,9 @@ IPreviewPanel* IPreviewPanel::CreatePanel(EResType Type, QWidget *pParent)
{ {
switch (Type) switch (Type)
{ {
case eTexture: return new WTexturePreviewPanel(pParent); case eTexture: return new WTexturePreviewPanel(pParent);
case eStringTable: return new WStringPreviewPanel(pParent); case eStringTable: return new WStringPreviewPanel(pParent);
case eScan: return new WScanPreviewPanel(pParent); case eScan: return new WScanPreviewPanel(pParent);
default: return nullptr; default: return nullptr;
} }
} }

View File

@ -139,7 +139,7 @@ void WResourceSelector::SetResource(CResource *pRes)
if (pRes) if (pRes)
{ {
mResourceValid = HasSupportedExtension(pRes); mResourceValid = HasSupportedExtension(pRes);
mUI.LineEdit->setText(QString::fromStdString(pRes->Source())); mUI.LineEdit->setText(QString::fromStdString(pRes->FullSource()));
} }
else else
@ -272,6 +272,7 @@ void WResourceSelector::LoadResource(const QString& ResPath)
{ {
mpResource = gResCache.GetResource(pathStr); mpResource = gResCache.GetResource(pathStr);
mResToken = CToken(mpResource); mResToken = CToken(mpResource);
mResourceValid = (mpResource != nullptr);
if (mPreviewPanelValid) mpPreviewPanel->SetResource(mpResource); if (mPreviewPanelValid) mpPreviewPanel->SetResource(mpResource);
} }
@ -287,6 +288,7 @@ void WResourceSelector::LoadResource(const QString& ResPath)
void WResourceSelector::CreatePreviewPanel() void WResourceSelector::CreatePreviewPanel()
{ {
delete mpPreviewPanel; delete mpPreviewPanel;
mpPreviewPanel = nullptr;
if (mResourceValid) if (mResourceValid)
mpPreviewPanel = IPreviewPanel::CreatePanel(mpResource->Type(), this); mpPreviewPanel = IPreviewPanel::CreatePanel(mpResource->Type(), this);

View File

@ -8,8 +8,9 @@ WScanPreviewPanel::WScanPreviewPanel(QWidget *parent) :
ui(new Ui::WScanPreviewPanel) ui(new Ui::WScanPreviewPanel)
{ {
ui->setupUi(this); ui->setupUi(this);
ui->ScanTextWidget->setFrameShape(QFrame::NoFrame); ui->ScanTextWidget->setFrameShape(QFrame::NoFrame);
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Minimum ); ui->ScanTextWidget->layout()->setContentsMargins(9,0,9,9);
} }
WScanPreviewPanel::~WScanPreviewPanel() WScanPreviewPanel::~WScanPreviewPanel()
@ -17,6 +18,11 @@ WScanPreviewPanel::~WScanPreviewPanel()
delete ui; delete ui;
} }
QSize WScanPreviewPanel::sizeHint() const
{
return QSize(400, 0);
}
EResType WScanPreviewPanel::ResType() EResType WScanPreviewPanel::ResType()
{ {
return eScan; return eScan;
@ -30,7 +36,7 @@ void WScanPreviewPanel::SetResource(CResource *pRes)
ui->ScanCategoryLabel->clear(); ui->ScanCategoryLabel->clear();
// Set up new UI // Set up new UI
if (pRes->Type() == eScan) if (pRes && (pRes->Type() == eScan))
{ {
CScan *pScan = static_cast<CScan*>(pRes); CScan *pScan = static_cast<CScan*>(pRes);
@ -38,7 +44,12 @@ void WScanPreviewPanel::SetResource(CResource *pRes)
if (pScan->IsImportant()) if (pScan->IsImportant())
ui->ScanTypeLabel->setText("<b><font color=\"red\">Important</font></b>"); ui->ScanTypeLabel->setText("<b><font color=\"red\">Important</font></b>");
else else
ui->ScanTypeLabel->setText("<b><font color=\"orange\">Normal</font></b>"); {
if (pScan->Version() <= ePrime)
ui->ScanTypeLabel->setText("<b><font color=\"#FF9030\">Normal</font></b>");
else
ui->ScanTypeLabel->setText("<b><font color=\"#A0A0FF\">Normal</font></b>");
}
// Scan speed // Scan speed
if (pScan->IsSlow()) if (pScan->IsSlow())
@ -68,6 +79,19 @@ void WScanPreviewPanel::SetResource(CResource *pRes)
// Scan text // Scan text
ui->ScanTextWidget->SetResource(pScan->ScanText()); ui->ScanTextWidget->SetResource(pScan->ScanText());
// Show logbook category? (Yes on MP1, no on MP2+)
if (pScan->Version() <= ePrime)
{
ui->CategoryInfoLabel->show();
ui->ScanCategoryLabel->show();
}
else
{
ui->CategoryInfoLabel->hide();
ui->ScanCategoryLabel->hide();
}
} }
else else

View File

@ -14,6 +14,7 @@ class WScanPreviewPanel : public IPreviewPanel
public: public:
explicit WScanPreviewPanel(QWidget *parent = 0); explicit WScanPreviewPanel(QWidget *parent = 0);
~WScanPreviewPanel(); ~WScanPreviewPanel();
QSize sizeHint() const;
EResType ResType(); EResType ResType();
void SetResource(CResource *pRes); void SetResource(CResource *pRes);

View File

@ -7,9 +7,15 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>400</width> <width>400</width>
<height>114</height> <height>47</height>
</rect> </rect>
</property> </property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="windowTitle"> <property name="windowTitle">
<string>Form</string> <string>Form</string>
</property> </property>
@ -27,7 +33,7 @@
<number>0</number> <number>0</number>
</property> </property>
<item> <item>
<layout class="QHBoxLayout" name="horizontalLayout_4"> <layout class="QHBoxLayout" name="ScanInfoLayout">
<property name="leftMargin"> <property name="leftMargin">
<number>9</number> <number>9</number>
</property> </property>
@ -41,7 +47,7 @@
<number>0</number> <number>0</number>
</property> </property>
<item> <item>
<layout class="QHBoxLayout" name="horizontalLayout"> <layout class="QHBoxLayout" name="ScanTypeInfoLayout">
<item> <item>
<widget class="QLabel" name="TypeInfoLabel"> <widget class="QLabel" name="TypeInfoLabel">
<property name="text"> <property name="text">
@ -59,7 +65,7 @@
</layout> </layout>
</item> </item>
<item> <item>
<spacer name="horizontalSpacer"> <spacer name="HorizSpacer1">
<property name="orientation"> <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>
@ -72,7 +78,38 @@
</spacer> </spacer>
</item> </item>
<item> <item>
<layout class="QHBoxLayout" name="horizontalLayout_2"> <layout class="QHBoxLayout" name="ScanCategoryInfoLayout">
<item>
<widget class="QLabel" name="CategoryInfoLabel">
<property name="text">
<string>Logbook:</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="ScanCategoryLabel">
<property name="text">
<string>TextLabel</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="HorizSpacer2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QHBoxLayout" name="ScanSpeedInfoLayout">
<item> <item>
<widget class="QLabel" name="SpeedInfoLabel"> <widget class="QLabel" name="SpeedInfoLabel">
<property name="text"> <property name="text">
@ -89,41 +126,10 @@
</item> </item>
</layout> </layout>
</item> </item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QLabel" name="LogbookInfoLabel">
<property name="text">
<string>Logbook:</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="ScanCategoryLabel">
<property name="text">
<string>TextLabel</string>
</property>
</widget>
</item>
</layout>
</item>
</layout> </layout>
</item> </item>
<item> <item>
<widget class="Line" name="line"> <widget class="Line" name="Divider">
<property name="orientation"> <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>
@ -132,7 +138,7 @@
<item> <item>
<widget class="WStringPreviewPanel" name="ScanTextWidget" native="true"> <widget class="WStringPreviewPanel" name="ScanTextWidget" native="true">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Expanding"> <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch> <horstretch>0</horstretch>
<verstretch>1</verstretch> <verstretch>1</verstretch>
</sizepolicy> </sizepolicy>

View File

@ -11,16 +11,17 @@ WStringPreviewPanel::WStringPreviewPanel(QWidget *pParent) : IPreviewPanel(pPare
mpLayout->setAlignment(Qt::AlignTop); mpLayout->setAlignment(Qt::AlignTop);
mpLayout->addWidget(mpTextLabel); mpLayout->addWidget(mpTextLabel);
setLayout(mpLayout); setLayout(mpLayout);
QFontMetrics metrics(mpTextLabel->font());
this->resize(400, 100);
this->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Minimum);
} }
WStringPreviewPanel::~WStringPreviewPanel() WStringPreviewPanel::~WStringPreviewPanel()
{ {
} }
QSize WStringPreviewPanel::sizeHint() const
{
return QSize(400, 0);
}
EResType WStringPreviewPanel::ResType() EResType WStringPreviewPanel::ResType()
{ {
return eStringTable; return eStringTable;
@ -30,23 +31,17 @@ void WStringPreviewPanel::SetResource(CResource *pRes)
{ {
mpTextLabel->clear(); mpTextLabel->clear();
if ((pRes) && (pRes->Type() == eStringTable)) if (pRes && (pRes->Type() == eStringTable))
{ {
CStringTable *pString = static_cast<CStringTable*>(pRes); CStringTable *pString = static_cast<CStringTable*>(pRes);
QString text; QString text;
// Build text string using first four strings from table (or less if there aren't 4) for (u32 iStr = 0; iStr < pString->GetStringCount(); iStr++)
u32 numStrings = (pString->GetStringCount() < 4 ? pString->GetStringCount() : 4);
for (u32 iStr = 0; iStr < numStrings; iStr++)
{ {
if (iStr > 0) text += "\n";
text += QString::fromStdWString(pString->GetString(0, iStr)); text += QString::fromStdWString(pString->GetString(0, iStr));
text += "\n";
} }
// Build text layout to determine where to elide the label
QTextLayout layout(text);
mpTextLabel->setText(text); mpTextLabel->setText(text);
} }
} }

View File

@ -12,11 +12,11 @@ class WStringPreviewPanel : public IPreviewPanel
QLabel *mpTextLabel; QLabel *mpTextLabel;
QVBoxLayout *mpLayout; QVBoxLayout *mpLayout;
QSpacerItem *mpSpacer;
public: public:
explicit WStringPreviewPanel(QWidget *pParent = 0); explicit WStringPreviewPanel(QWidget *pParent = 0);
~WStringPreviewPanel(); ~WStringPreviewPanel();
QSize sizeHint() const;
EResType ResType(); EResType ResType();
void SetResource(CResource *pRes); void SetResource(CResource *pRes);
}; };