mirror of
https://github.com/redstrate/Novus.git
synced 2025-06-08 14:17:45 +00:00
Add a standard way to detect game file types from their extensions
This is now used to populate the file properties window in the Data Explorer.
This commit is contained in:
parent
5c907b63da
commit
9d129163bb
5 changed files with 86 additions and 12 deletions
|
@ -6,6 +6,7 @@ target_sources(novus-common
|
||||||
PRIVATE
|
PRIVATE
|
||||||
include/aboutdata.h
|
include/aboutdata.h
|
||||||
include/filecache.h
|
include/filecache.h
|
||||||
|
include/filetypes.h
|
||||||
include/novusmainwindow.h
|
include/novusmainwindow.h
|
||||||
include/quaternionedit.h
|
include/quaternionedit.h
|
||||||
include/settings.h
|
include/settings.h
|
||||||
|
@ -13,6 +14,7 @@ target_sources(novus-common
|
||||||
|
|
||||||
src/aboutdata.cpp
|
src/aboutdata.cpp
|
||||||
src/filecache.cpp
|
src/filecache.cpp
|
||||||
|
src/filetypes.cpp
|
||||||
src/novusmainwindow.cpp
|
src/novusmainwindow.cpp
|
||||||
src/quaternionedit.cpp
|
src/quaternionedit.cpp
|
||||||
src/settings.cpp
|
src/settings.cpp
|
||||||
|
|
16
common/include/filetypes.h
Normal file
16
common/include/filetypes.h
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
// SPDX-FileCopyrightText: 2024 Joshua Goins <josh@redstrate.com>
|
||||||
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <QString>
|
||||||
|
|
||||||
|
enum class FileType { Unknown, ExcelList, ExcelHeader, ExcelData, Model, Texture, ShaderPackage, CharaMakeParams, Skeleton };
|
||||||
|
|
||||||
|
class FileTypes
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static FileType getFileType(const QString &extension);
|
||||||
|
|
||||||
|
static QString getFiletypeName(FileType fileType);
|
||||||
|
};
|
36
common/src/filetypes.cpp
Normal file
36
common/src/filetypes.cpp
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
// SPDX-FileCopyrightText: 2024 Joshua Goins <josh@redstrate.com>
|
||||||
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
#include "filetypes.h"
|
||||||
|
|
||||||
|
#include <KLocalizedString>
|
||||||
|
#include <QMap>
|
||||||
|
|
||||||
|
const static QMap<QString, FileType> extensionToType{{QStringLiteral("exl"), FileType::ExcelList},
|
||||||
|
{QStringLiteral("exh"), FileType::ExcelHeader},
|
||||||
|
{QStringLiteral("exd"), FileType::ExcelData},
|
||||||
|
{QStringLiteral("mdl"), FileType::Model},
|
||||||
|
{QStringLiteral("tex"), FileType::Texture},
|
||||||
|
{QStringLiteral("shpk"), FileType::ShaderPackage},
|
||||||
|
{QStringLiteral("cmp"), FileType::CharaMakeParams},
|
||||||
|
{QStringLiteral("sklb"), FileType::Skeleton}};
|
||||||
|
|
||||||
|
const static QMap<FileType, QString> typeToName{{FileType::Unknown, i18n("Unknown")},
|
||||||
|
{FileType::ExcelList, i18n("Excel List")},
|
||||||
|
{FileType::ExcelHeader, i18n("Excel Header")},
|
||||||
|
{FileType::ExcelData, i18n("Excel Data")},
|
||||||
|
{FileType::Model, i18n("Model")},
|
||||||
|
{FileType::Texture, i18n("Texture")},
|
||||||
|
{FileType::ShaderPackage, i18n("Shader Package")},
|
||||||
|
{FileType::CharaMakeParams, i18n("Chara Make Params")},
|
||||||
|
{FileType::Skeleton, i18n("Skeleton")}};
|
||||||
|
|
||||||
|
FileType FileTypes::getFileType(const QString &extension)
|
||||||
|
{
|
||||||
|
return extensionToType.value(extension, FileType::Unknown);
|
||||||
|
}
|
||||||
|
|
||||||
|
QString FileTypes::getFiletypeName(FileType fileType)
|
||||||
|
{
|
||||||
|
return typeToName.value(fileType);
|
||||||
|
}
|
|
@ -2,11 +2,13 @@
|
||||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
#include <KLocalizedString>
|
#include <KLocalizedString>
|
||||||
|
#include <QFileInfo>
|
||||||
#include <QFormLayout>
|
#include <QFormLayout>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QTreeWidget>
|
#include <QTreeWidget>
|
||||||
|
|
||||||
#include "filepropertieswindow.h"
|
#include "filepropertieswindow.h"
|
||||||
|
#include "filetypes.h"
|
||||||
|
|
||||||
FilePropertiesWindow::FilePropertiesWindow(const QString &path, physis_Buffer buffer, QWidget *parent)
|
FilePropertiesWindow::FilePropertiesWindow(const QString &path, physis_Buffer buffer, QWidget *parent)
|
||||||
: QWidget(parent)
|
: QWidget(parent)
|
||||||
|
@ -17,13 +19,17 @@ FilePropertiesWindow::FilePropertiesWindow(const QString &path, physis_Buffer bu
|
||||||
setLayout(layout);
|
setLayout(layout);
|
||||||
|
|
||||||
auto pathLabel = new QLabel(path);
|
auto pathLabel = new QLabel(path);
|
||||||
layout->addRow(i18nc("@label", "Path"), pathLabel);
|
layout->addRow(i18nc("@label", "Path:"), pathLabel);
|
||||||
|
|
||||||
auto typeLabel = new QLabel(i18n("Unknown type"));
|
QFileInfo info(path);
|
||||||
layout->addRow(i18nc("@label", "Type"), typeLabel);
|
|
||||||
|
const FileType type = FileTypes::getFileType(info.completeSuffix());
|
||||||
|
|
||||||
|
auto typeLabel = new QLabel(FileTypes::getFiletypeName(type));
|
||||||
|
layout->addRow(i18nc("@label", "Type:"), typeLabel);
|
||||||
|
|
||||||
auto sizeLabel = new QLabel(QString::number(buffer.size));
|
auto sizeLabel = new QLabel(QString::number(buffer.size));
|
||||||
layout->addRow(i18nc("@label", "Size (in bytes)"), sizeLabel);
|
layout->addRow(i18nc("@label", "Size (in bytes):"), sizeLabel);
|
||||||
}
|
}
|
||||||
|
|
||||||
#include "moc_filepropertieswindow.cpp"
|
#include "moc_filepropertieswindow.cpp"
|
|
@ -20,6 +20,7 @@
|
||||||
#include "exdpart.h"
|
#include "exdpart.h"
|
||||||
#include "exlpart.h"
|
#include "exlpart.h"
|
||||||
#include "filepropertieswindow.h"
|
#include "filepropertieswindow.h"
|
||||||
|
#include "filetypes.h"
|
||||||
#include "hexpart.h"
|
#include "hexpart.h"
|
||||||
#include "mdlpart.h"
|
#include "mdlpart.h"
|
||||||
#include "shpkpart.h"
|
#include "shpkpart.h"
|
||||||
|
@ -83,37 +84,50 @@ void MainWindow::refreshParts(const QString &path)
|
||||||
auto file = physis_gamedata_extract_file(data, path.toStdString().c_str());
|
auto file = physis_gamedata_extract_file(data, path.toStdString().c_str());
|
||||||
|
|
||||||
QFileInfo info(path);
|
QFileInfo info(path);
|
||||||
if (info.completeSuffix() == QStringLiteral("exl")) {
|
|
||||||
|
const FileType type = FileTypes::getFileType(info.completeSuffix());
|
||||||
|
switch (type) {
|
||||||
|
case FileType::ExcelList: {
|
||||||
auto exlWidget = new EXLPart(data);
|
auto exlWidget = new EXLPart(data);
|
||||||
exlWidget->load(file);
|
exlWidget->load(file);
|
||||||
partHolder->addTab(exlWidget, i18nc("@title:tab", "Excel List"));
|
partHolder->addTab(exlWidget, i18nc("@title:tab", "Excel List"));
|
||||||
} else if (info.completeSuffix() == QStringLiteral("exh")) {
|
} break;
|
||||||
|
case FileType::ExcelHeader: {
|
||||||
auto exdWidget = new EXDPart(data);
|
auto exdWidget = new EXDPart(data);
|
||||||
exdWidget->loadSheet(info.baseName(), file);
|
exdWidget->loadSheet(info.baseName(), file);
|
||||||
partHolder->addTab(exdWidget, i18nc("@title:tab", "Excel Sheet"));
|
partHolder->addTab(exdWidget, i18nc("@title:tab", "Excel Sheet"));
|
||||||
} else if (info.completeSuffix() == QStringLiteral("exd")) {
|
} break;
|
||||||
|
case FileType::ExcelData: {
|
||||||
auto exdWidget = new QLabel(i18n("Note: Excel data files cannot be previewed standalone, select the EXH file instead."));
|
auto exdWidget = new QLabel(i18n("Note: Excel data files cannot be previewed standalone, select the EXH file instead."));
|
||||||
partHolder->addTab(exdWidget, i18nc("@title:tab", "Note"));
|
partHolder->addTab(exdWidget, i18nc("@title:tab", "Note"));
|
||||||
} else if (info.completeSuffix() == QStringLiteral("mdl")) {
|
} break;
|
||||||
|
case FileType::Model: {
|
||||||
auto mdlWidget = new MDLPart(data, fileCache);
|
auto mdlWidget = new MDLPart(data, fileCache);
|
||||||
mdlWidget->addModel(physis_mdl_parse(file), false, glm::vec3(), QStringLiteral("mdl"), {}, 0);
|
mdlWidget->addModel(physis_mdl_parse(file), false, glm::vec3(), QStringLiteral("mdl"), {}, 0);
|
||||||
partHolder->addTab(mdlWidget, i18nc("@title:tab", "Model"));
|
partHolder->addTab(mdlWidget, i18nc("@title:tab", "Model"));
|
||||||
} else if (info.completeSuffix() == QStringLiteral("tex") || info.completeSuffix() == QStringLiteral("atex")) {
|
} break;
|
||||||
|
case FileType::Texture: {
|
||||||
auto texWidget = new TexPart(data);
|
auto texWidget = new TexPart(data);
|
||||||
texWidget->load(file);
|
texWidget->load(file);
|
||||||
partHolder->addTab(texWidget, i18nc("@title:tab", "Texture"));
|
partHolder->addTab(texWidget, i18nc("@title:tab", "Texture"));
|
||||||
} else if (info.completeSuffix() == QStringLiteral("shpk")) {
|
} break;
|
||||||
|
case FileType::ShaderPackage: {
|
||||||
auto shpkWidget = new SHPKPart(data);
|
auto shpkWidget = new SHPKPart(data);
|
||||||
shpkWidget->load(file);
|
shpkWidget->load(file);
|
||||||
partHolder->addTab(shpkWidget, i18nc("@title:tab", "Shader Package"));
|
partHolder->addTab(shpkWidget, i18nc("@title:tab", "Shader Package"));
|
||||||
} else if (info.completeSuffix() == QStringLiteral("cmp")) {
|
} break;
|
||||||
|
case FileType::CharaMakeParams: {
|
||||||
auto cmpWidget = new CmpPart(data);
|
auto cmpWidget = new CmpPart(data);
|
||||||
cmpWidget->load(file);
|
cmpWidget->load(file);
|
||||||
partHolder->addTab(cmpWidget, i18nc("@title:tab", "Chara Make Params"));
|
partHolder->addTab(cmpWidget, i18nc("@title:tab", "Chara Make Params"));
|
||||||
} else if (info.completeSuffix() == QStringLiteral("sklb")) {
|
} break;
|
||||||
|
case FileType::Skeleton: {
|
||||||
auto sklbWidget = new SklbPart();
|
auto sklbWidget = new SklbPart();
|
||||||
sklbWidget->load(physis_parse_skeleton(file));
|
sklbWidget->load(physis_parse_skeleton(file));
|
||||||
partHolder->addTab(sklbWidget, i18nc("@title:tab", "Skeleton"));
|
partHolder->addTab(sklbWidget, i18nc("@title:tab", "Skeleton"));
|
||||||
|
} break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto hexWidget = new HexPart();
|
auto hexWidget = new HexPart();
|
||||||
|
|
Loading…
Add table
Reference in a new issue