mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-05-29 15:26:35 +00:00
This makes the code cleaner and also leads to some user-visible changes: The wx game properties will no longer let the user select WAD languages that don't have any names. The Qt game list will now display names using the languages set in the configuration instead of always using English for PAL GC games and Japanese for WADs. If a WAD doesn't have a name in the user's preferred language, English is now selected as a fallback before Japanese.
122 lines
2.6 KiB
C++
122 lines
2.6 KiB
C++
// Copyright 2013 Dolphin Emulator Project
|
|
// Licensed under GPLv2
|
|
// Refer to the license.txt file included.
|
|
|
|
#include <algorithm>
|
|
#include <cstddef>
|
|
#include <cstdio>
|
|
#include <map>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#include "Common/ColorUtil.h"
|
|
#include "Common/CommonFuncs.h"
|
|
#include "Common/CommonTypes.h"
|
|
#include "Common/FileUtil.h"
|
|
#include "Common/StringUtil.h"
|
|
|
|
#include "DiscIO/BannerLoaderWii.h"
|
|
#include "DiscIO/Volume.h"
|
|
|
|
namespace DiscIO
|
|
{
|
|
|
|
CBannerLoaderWii::CBannerLoaderWii(DiscIO::IVolume *pVolume)
|
|
{
|
|
u64 TitleID = 0;
|
|
pVolume->GetTitleID((u8*)&TitleID);
|
|
TitleID = Common::swap64(TitleID);
|
|
|
|
std::string Filename = StringFromFormat("%stitle/%08x/%08x/data/banner.bin",
|
|
File::GetUserPath(D_WIIUSER_IDX).c_str(), (u32)(TitleID>>32), (u32)TitleID);
|
|
|
|
if (!File::Exists(Filename))
|
|
{
|
|
m_IsValid = false;
|
|
return;
|
|
}
|
|
|
|
// load the banner.bin
|
|
size_t FileSize = (size_t) File::GetSize(Filename);
|
|
|
|
if (FileSize > 0)
|
|
{
|
|
m_pBannerFile = new u8[FileSize];
|
|
File::IOFile pFile(Filename, "rb");
|
|
if (pFile)
|
|
{
|
|
pFile.ReadBytes(m_pBannerFile, FileSize);
|
|
m_IsValid = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
CBannerLoaderWii::~CBannerLoaderWii()
|
|
{
|
|
if (m_pBannerFile)
|
|
{
|
|
delete [] m_pBannerFile;
|
|
m_pBannerFile = nullptr;
|
|
}
|
|
}
|
|
|
|
std::vector<u32> CBannerLoaderWii::GetBanner(int* pWidth, int* pHeight)
|
|
{
|
|
SWiiBanner* pBanner = (SWiiBanner*)m_pBannerFile;
|
|
std::vector<u32> Buffer;
|
|
Buffer.resize(192 * 64);
|
|
ColorUtil::decode5A3image(&Buffer[0], (u16*)pBanner->m_BannerTexture, 192, 64);
|
|
*pWidth = 192;
|
|
*pHeight = 64;
|
|
return Buffer;
|
|
}
|
|
|
|
bool CBannerLoaderWii::GetStringFromComments(const CommentIndex index, std::string& result)
|
|
{
|
|
if (IsValid())
|
|
{
|
|
auto const banner = reinterpret_cast<const SWiiBanner*>(m_pBannerFile);
|
|
auto const src_ptr = banner->m_Comment[index];
|
|
|
|
// Trim at first nullptr
|
|
auto const length = std::find(src_ptr, src_ptr + COMMENT_SIZE, 0x0) - src_ptr;
|
|
|
|
std::wstring src;
|
|
src.resize(length);
|
|
std::transform(src_ptr, src_ptr + src.size(), src.begin(), (u16(&)(u16))Common::swap16);
|
|
result = UTF16ToUTF8(src);
|
|
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
std::map<IVolume::ELanguage, std::string> CBannerLoaderWii::GetNames()
|
|
{
|
|
std::map<IVolume::ELanguage, std::string> result;
|
|
|
|
std::string name;
|
|
if (GetStringFromComments(NAME_IDX, name))
|
|
result[IVolume::ELanguage::LANGUAGE_UNKNOWN] = name;
|
|
|
|
return result;
|
|
}
|
|
|
|
std::string CBannerLoaderWii::GetCompany()
|
|
{
|
|
return "";
|
|
}
|
|
|
|
std::map<IVolume::ELanguage, std::string> CBannerLoaderWii::GetDescriptions()
|
|
{
|
|
std::map<IVolume::ELanguage, std::string> result;
|
|
|
|
std::string name;
|
|
if (GetStringFromComments(DESC_IDX, name))
|
|
result[IVolume::ELanguage::LANGUAGE_UNKNOWN] = name;
|
|
|
|
return result;
|
|
}
|
|
|
|
} // namespace
|