Support game icon selection based on language

This commit is contained in:
lynxnb 2021-09-23 11:36:10 +02:00 committed by ◱ Mark
parent 01ce09183b
commit 0077833667
8 changed files with 18 additions and 24 deletions

View File

@ -60,7 +60,7 @@ extern "C" JNIEXPORT jint JNICALL Java_emu_skyline_loader_RomFile_populate(JNIEn
env->SetObjectField(thiz, applicationNameField, env->NewStringUTF(loader->nacp->GetApplicationName(language).c_str())); env->SetObjectField(thiz, applicationNameField, env->NewStringUTF(loader->nacp->GetApplicationName(language).c_str()));
env->SetObjectField(thiz, applicationAuthorField, env->NewStringUTF(loader->nacp->GetApplicationPublisher(language).c_str())); env->SetObjectField(thiz, applicationAuthorField, env->NewStringUTF(loader->nacp->GetApplicationPublisher(language).c_str()));
auto icon{loader->GetIcon()}; auto icon{loader->GetIcon(language)};
jbyteArray iconByteArray{env->NewByteArray(icon.size())}; jbyteArray iconByteArray{env->NewByteArray(icon.size())};
env->SetByteArrayRegion(iconByteArray, 0, icon.size(), reinterpret_cast<const jbyte *>(icon.data())); env->SetByteArrayRegion(iconByteArray, 0, icon.size(), reinterpret_cast<const jbyte *>(icon.data()));
env->SetObjectField(thiz, rawIconField, iconByteArray); env->SetObjectField(thiz, rawIconField, iconByteArray);

View File

@ -87,7 +87,7 @@ namespace skyline::loader {
virtual ~Loader() = default; virtual ~Loader() = default;
virtual std::vector<u8> GetIcon() { virtual std::vector<u8> GetIcon(languages::ApplicationLanguage language) {
return std::vector<u8>(); return std::vector<u8>();
} }

View File

@ -29,7 +29,7 @@ namespace skyline::loader {
} }
} }
std::vector<u8> NroLoader::GetIcon() { std::vector<u8> NroLoader::GetIcon(languages::ApplicationLanguage language) {
NroAssetSection &segmentHeader{assetHeader.icon}; NroAssetSection &segmentHeader{assetHeader.icon};
std::vector<u8> buffer(segmentHeader.size); std::vector<u8> buffer(segmentHeader.size);

View File

@ -70,7 +70,7 @@ namespace skyline::loader {
public: public:
NroLoader(std::shared_ptr<vfs::Backing> backing); NroLoader(std::shared_ptr<vfs::Backing> backing);
std::vector<u8> GetIcon() override; std::vector<u8> GetIcon(languages::ApplicationLanguage language) override;
void *LoadProcessData(const std::shared_ptr<kernel::type::KProcess> &process, const DeviceState &state) override; void *LoadProcessData(const std::shared_ptr<kernel::type::KProcess> &process, const DeviceState &state) override;
}; };

View File

@ -57,19 +57,16 @@ namespace skyline::loader {
return NcaLoader::LoadExeFs(this, programNca->exeFs, process, state); return NcaLoader::LoadExeFs(this, programNca->exeFs, process, state);
} }
std::vector<u8> NspLoader::GetIcon() { std::vector<u8> NspLoader::GetIcon(languages::ApplicationLanguage language) {
if (romFs == nullptr) if (controlRomFs == nullptr)
return std::vector<u8>(); return std::vector<u8>();
auto root{controlRomFs->OpenDirectory("", {false, true})};
std::shared_ptr<vfs::Backing> icon{}; std::shared_ptr<vfs::Backing> icon{};
// Use the first icon file available auto iconName{fmt::format("icon_{}.dat", languages::ToString(language))};
for (const auto &entry : root->Read()) { if (!(icon = controlRomFs->OpenFileUnchecked(iconName, {true, false, false}))) {
if (entry.name.rfind("icon") == 0) { iconName = fmt::format("icon_{}.dat", languages::ToString(nacp->GetFirstSupportedTitleLanguage()));
icon = controlRomFs->OpenFileUnchecked(entry.name); icon = controlRomFs->OpenFileUnchecked(iconName, {true, false, false});
break;
}
} }
if (icon == nullptr) if (icon == nullptr)

View File

@ -24,7 +24,7 @@ namespace skyline::loader {
public: public:
NspLoader(const std::shared_ptr<vfs::Backing> &backing, const std::shared_ptr<crypto::KeyStore> &keyStore); NspLoader(const std::shared_ptr<vfs::Backing> &backing, const std::shared_ptr<crypto::KeyStore> &keyStore);
std::vector<u8> GetIcon() override; std::vector<u8> GetIcon(languages::ApplicationLanguage language) override;
void *LoadProcessData(const std::shared_ptr<kernel::type::KProcess> &process, const DeviceState &state) override; void *LoadProcessData(const std::shared_ptr<kernel::type::KProcess> &process, const DeviceState &state) override;
}; };

View File

@ -65,19 +65,16 @@ namespace skyline::loader {
return NcaLoader::LoadExeFs(this, programNca->exeFs, process, state); return NcaLoader::LoadExeFs(this, programNca->exeFs, process, state);
} }
std::vector<u8> XciLoader::GetIcon() { std::vector<u8> XciLoader::GetIcon(languages::ApplicationLanguage language) {
if (romFs == nullptr) if (controlRomFs == nullptr)
return std::vector<u8>(); return std::vector<u8>();
auto root{controlRomFs->OpenDirectory("", {false, true})};
std::shared_ptr<vfs::Backing> icon{}; std::shared_ptr<vfs::Backing> icon{};
// Use the first icon file available auto iconName{fmt::format("icon_{}.dat", languages::ToString(language))};
for (const auto &entry : root->Read()) { if (!(icon = controlRomFs->OpenFileUnchecked(iconName, {true, false, false}))) {
if (entry.name.rfind("icon") == 0) { iconName = fmt::format("icon_{}.dat", languages::ToString(nacp->GetFirstSupportedTitleLanguage()));
icon = controlRomFs->OpenFile(entry.name); icon = controlRomFs->OpenFileUnchecked(iconName, {true, false, false});
break;
}
} }
if (icon == nullptr) if (icon == nullptr)

View File

@ -117,7 +117,7 @@ namespace skyline::loader {
public: public:
XciLoader(const std::shared_ptr<vfs::Backing> &backing, const std::shared_ptr<crypto::KeyStore> &keyStore); XciLoader(const std::shared_ptr<vfs::Backing> &backing, const std::shared_ptr<crypto::KeyStore> &keyStore);
std::vector<u8> GetIcon() override; std::vector<u8> GetIcon(languages::ApplicationLanguage language) override;
void *LoadProcessData(const std::shared_ptr<kernel::type::KProcess> &process, const DeviceState &state) override; void *LoadProcessData(const std::shared_ptr<kernel::type::KProcess> &process, const DeviceState &state) override;
}; };