mirror of
https://github.com/Dark98/threeSD.git
synced 2026-07-04 08:39:05 +00:00
Preliminary work for a title info dialog
pending DRY fixes, etc
This commit is contained in:
@@ -0,0 +1,149 @@
|
||||
// Copyright 2021 threeSD Project
|
||||
// Licensed under GPLv2 or any later version
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#include <QDesktopWidget>
|
||||
#include <QMessageBox>
|
||||
#include <QPixmap>
|
||||
#include <fmt/format.h>
|
||||
#include "common/string_util.h"
|
||||
#include "core/file_sys/ncch_container.h"
|
||||
#include "core/file_sys/title_metadata.h"
|
||||
#include "core/importer.h"
|
||||
#include "frontend/title_info_dialog.h"
|
||||
#include "ui_title_info_dialog.h"
|
||||
|
||||
TitleInfoDialog::TitleInfoDialog(QWidget* parent, const Core::Config& config,
|
||||
Core::SDMCImporter& importer,
|
||||
const Core::ContentSpecifier& specifier)
|
||||
: QDialog(parent), ui(std::make_unique<Ui::TitleInfoDialog>()) {
|
||||
|
||||
ui->setupUi(this);
|
||||
|
||||
const double scale = qApp->desktop()->logicalDpiX() / 96.0;
|
||||
resize(static_cast<int>(width() * scale), static_cast<int>(height() * scale));
|
||||
|
||||
InitializeInfo(config, importer, specifier);
|
||||
InitializeLanguageComboBox();
|
||||
|
||||
connect(ui->buttonBox, &QDialogButtonBox::accepted, this, &TitleInfoDialog::accept);
|
||||
}
|
||||
|
||||
TitleInfoDialog::~TitleInfoDialog() = default;
|
||||
|
||||
void TitleInfoDialog::InitializeInfo(const Core::Config& config, Core::SDMCImporter& importer,
|
||||
const Core::ContentSpecifier& specifier) {
|
||||
Core::TitleMetadata tmd;
|
||||
if (!importer.LoadTMD(specifier, tmd)) {
|
||||
QMessageBox::warning(this, tr("threeSD"), tr("Could not load title information."));
|
||||
reject();
|
||||
return;
|
||||
}
|
||||
ui->versionLineEdit->setText(QString::fromStdString(tmd.GetTitleVersionString()));
|
||||
ui->titleIDLineEdit->setText(QStringLiteral("%1").arg(specifier.id, 16, 16, QLatin1Char{'0'}));
|
||||
|
||||
const bool is_nand = specifier.type == Core::ContentType::SystemTitle ||
|
||||
specifier.type == Core::ContentType::SystemApplet;
|
||||
const auto physical_path =
|
||||
is_nand ? fmt::format("{}{:08x}/{:08x}/content/", config.system_titles_path,
|
||||
(specifier.id >> 32), (specifier.id & 0xFFFFFFFF))
|
||||
: fmt::format("{}title/{:08x}/{:08x}/content/", config.sdmc_path,
|
||||
(specifier.id >> 32), (specifier.id & 0xFFFFFFFF));
|
||||
const auto boot_content_path =
|
||||
fmt::format("{}{:08x}.app", physical_path, tmd.GetBootContentID());
|
||||
Core::NCCHContainer ncch;
|
||||
if (is_nand) {
|
||||
ncch.OpenFile(std::make_shared<FileUtil::IOFile>(boot_content_path, "rb"));
|
||||
} else {
|
||||
const auto relative_path = boot_content_path.substr(config.sdmc_path.size() - 1);
|
||||
ncch.OpenFile(std::make_shared<Core::SDMCFile>(config.sdmc_path, relative_path, "rb"));
|
||||
}
|
||||
|
||||
static const std::unordered_map<Core::EncryptionType, const char*> EncryptionTypeMap{{
|
||||
{Core::EncryptionType::None, QT_TR_NOOP("None")},
|
||||
{Core::EncryptionType::FixedKey, QT_TR_NOOP("FixedKey")},
|
||||
{Core::EncryptionType::NCCHSecure1, QT_TR_NOOP("Secure1")},
|
||||
{Core::EncryptionType::NCCHSecure2, QT_TR_NOOP("Secure2")},
|
||||
{Core::EncryptionType::NCCHSecure3, QT_TR_NOOP("Secure3")},
|
||||
{Core::EncryptionType::NCCHSecure4, QT_TR_NOOP("Secure4")},
|
||||
}};
|
||||
|
||||
Core::EncryptionType encryption = Core::EncryptionType::None;
|
||||
ncch.ReadEncryptionType(encryption);
|
||||
|
||||
bool seed_crypto = false;
|
||||
ncch.ReadSeedCrypto(seed_crypto);
|
||||
|
||||
QString encryption_text = tr(EncryptionTypeMap.at(encryption));
|
||||
if (seed_crypto) {
|
||||
encryption_text.append(tr(" (Seed)"));
|
||||
}
|
||||
ui->encryptionLineEdit->setText(encryption_text);
|
||||
|
||||
// Load SMDH
|
||||
std::vector<u8> smdh_buffer;
|
||||
if (!ncch.LoadSectionExeFS("icon", smdh_buffer) || smdh_buffer.size() != sizeof(Core::SMDH) ||
|
||||
!Core::IsValidSMDH(smdh_buffer)) {
|
||||
|
||||
LOG_WARNING(Core, "Failed to load SMDH");
|
||||
ui->namesGroupBox->setEnabled(false);
|
||||
return;
|
||||
}
|
||||
|
||||
std::memcpy(&smdh, smdh_buffer.data(), smdh_buffer.size());
|
||||
// Load icon
|
||||
ui->iconLargeLabel->setPixmap(
|
||||
QPixmap::fromImage(QImage(reinterpret_cast<const uchar*>(smdh.GetIcon(true).data()), 48, 48,
|
||||
QImage::Format::Format_RGB16)));
|
||||
ui->iconSmallLabel->setPixmap(
|
||||
QPixmap::fromImage(QImage(reinterpret_cast<const uchar*>(smdh.GetIcon(false).data()), 24,
|
||||
24, QImage::Format::Format_RGB16)));
|
||||
}
|
||||
|
||||
void TitleInfoDialog::InitializeLanguageComboBox() {
|
||||
if (!ui->namesGroupBox->isEnabled()) { // SMDH not available
|
||||
return;
|
||||
}
|
||||
// Corresponds to the indices of the languages defined in SMDH
|
||||
static constexpr std::array<const char*, 12> LanguageNames{{
|
||||
QT_TR_NOOP("Japanese"),
|
||||
QT_TR_NOOP("English"),
|
||||
QT_TR_NOOP("French"),
|
||||
QT_TR_NOOP("German"),
|
||||
QT_TR_NOOP("Italian"),
|
||||
QT_TR_NOOP("Spanish"),
|
||||
QT_TR_NOOP("Chinese (Simplified)"),
|
||||
QT_TR_NOOP("Korean"),
|
||||
QT_TR_NOOP("Dutch"),
|
||||
QT_TR_NOOP("Portuguese"),
|
||||
QT_TR_NOOP("Russian"),
|
||||
QT_TR_NOOP("Chinese (Traditional)"),
|
||||
}};
|
||||
for (std::size_t i = 0; i < LanguageNames.size(); ++i) {
|
||||
const auto& title = smdh.titles.at(i);
|
||||
if (Common::UTF16BufferToUTF8(title.short_title).empty() &&
|
||||
Common::UTF16BufferToUTF8(title.long_title).empty() &&
|
||||
Common::UTF16BufferToUTF8(title.publisher).empty()) {
|
||||
// All empty, ignore this language
|
||||
continue;
|
||||
}
|
||||
|
||||
ui->languageComboBox->addItem(tr(LanguageNames.at(i)), static_cast<int>(i));
|
||||
if (i == 1) { // English
|
||||
ui->languageComboBox->setCurrentIndex(ui->languageComboBox->count() - 1);
|
||||
}
|
||||
}
|
||||
connect(ui->languageComboBox, qOverload<int>(&QComboBox::currentIndexChanged), this,
|
||||
&TitleInfoDialog::UpdateNames);
|
||||
UpdateNames();
|
||||
}
|
||||
|
||||
void TitleInfoDialog::UpdateNames() {
|
||||
const auto& title = smdh.titles.at(ui->languageComboBox->currentData().toInt());
|
||||
ui->shortTitleLineEdit->setText(
|
||||
QString::fromStdString(Common::UTF16BufferToUTF8(title.short_title)));
|
||||
ui->longTitleLineEdit->setText(
|
||||
QString::fromStdString(Common::UTF16BufferToUTF8(title.long_title)));
|
||||
ui->publisherLineEdit->setText(
|
||||
QString::fromStdString(Common::UTF16BufferToUTF8(title.publisher)));
|
||||
}
|
||||
Reference in New Issue
Block a user