2013-04-17 21:09:55 -06:00
|
|
|
// Copyright 2013 Dolphin Emulator Project
|
|
|
|
// Licensed under GPLv2
|
|
|
|
// Refer to the license.txt file included.
|
2008-12-07 22:30:24 -07:00
|
|
|
|
2013-03-01 18:33:17 -07:00
|
|
|
#include <algorithm>
|
2014-02-20 17:47:53 -07:00
|
|
|
#include <cstddef>
|
2014-02-17 03:18:15 -07:00
|
|
|
#include <cstdio>
|
2014-02-20 17:47:53 -07:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
2008-12-07 22:30:24 -07:00
|
|
|
|
2014-02-17 03:18:15 -07:00
|
|
|
#include "Common/ColorUtil.h"
|
2014-02-20 17:47:53 -07:00
|
|
|
#include "Common/CommonFuncs.h"
|
2014-02-18 18:02:01 -07:00
|
|
|
#include "Common/CommonTypes.h"
|
2014-02-17 03:18:15 -07:00
|
|
|
#include "Common/FileUtil.h"
|
2014-02-20 17:47:53 -07:00
|
|
|
#include "Common/StringUtil.h"
|
2014-02-17 03:18:15 -07:00
|
|
|
|
|
|
|
#include "DiscIO/BannerLoaderWii.h"
|
2014-02-20 17:47:53 -07:00
|
|
|
#include "DiscIO/Volume.h"
|
2008-12-07 22:30:24 -07:00
|
|
|
|
|
|
|
namespace DiscIO
|
|
|
|
{
|
2009-03-20 12:13:31 -06:00
|
|
|
|
2013-10-28 23:23:17 -06:00
|
|
|
CBannerLoaderWii::CBannerLoaderWii(DiscIO::IVolume *pVolume)
|
2008-12-07 22:30:24 -07:00
|
|
|
{
|
2014-08-27 19:35:20 -06:00
|
|
|
u64 TitleID = 0;
|
2010-01-16 20:25:42 -07:00
|
|
|
pVolume->GetTitleID((u8*)&TitleID);
|
2009-04-28 17:47:18 -06:00
|
|
|
TitleID = Common::swap64(TitleID);
|
|
|
|
|
2014-06-02 23:08:54 -06:00
|
|
|
std::string Filename = StringFromFormat("%stitle/%08x/%08x/data/banner.bin",
|
|
|
|
File::GetUserPath(D_WIIUSER_IDX).c_str(), (u32)(TitleID>>32), (u32)TitleID);
|
2009-03-20 12:13:31 -06:00
|
|
|
|
|
|
|
if (!File::Exists(Filename))
|
|
|
|
{
|
|
|
|
m_IsValid = false;
|
|
|
|
return;
|
|
|
|
}
|
2008-12-07 22:30:24 -07:00
|
|
|
|
2009-06-06 08:33:52 -06:00
|
|
|
// load the banner.bin
|
2008-12-20 11:46:49 -07:00
|
|
|
size_t FileSize = (size_t) File::GetSize(Filename);
|
2008-12-07 22:30:24 -07:00
|
|
|
|
|
|
|
if (FileSize > 0)
|
|
|
|
{
|
|
|
|
m_pBannerFile = new u8[FileSize];
|
2011-03-11 03:21:46 -07:00
|
|
|
File::IOFile pFile(Filename, "rb");
|
2009-03-20 12:13:31 -06:00
|
|
|
if (pFile)
|
2008-12-07 22:30:24 -07:00
|
|
|
{
|
2011-03-11 03:21:46 -07:00
|
|
|
pFile.ReadBytes(m_pBannerFile, FileSize);
|
2008-12-07 22:30:24 -07:00
|
|
|
m_IsValid = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CBannerLoaderWii::~CBannerLoaderWii()
|
|
|
|
{
|
|
|
|
if (m_pBannerFile)
|
|
|
|
{
|
|
|
|
delete [] m_pBannerFile;
|
2014-03-09 14:14:26 -06:00
|
|
|
m_pBannerFile = nullptr;
|
2008-12-07 22:30:24 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-25 01:05:36 -06:00
|
|
|
std::vector<u32> CBannerLoaderWii::GetBanner(int* pWidth, int* pHeight)
|
2008-12-07 22:30:24 -07:00
|
|
|
{
|
2013-09-25 01:05:36 -06:00
|
|
|
SWiiBanner* pBanner = (SWiiBanner*)m_pBannerFile;
|
|
|
|
std::vector<u32> Buffer;
|
|
|
|
Buffer.resize(192 * 64);
|
2013-10-02 16:18:54 -06:00
|
|
|
ColorUtil::decode5A3image(&Buffer[0], (u16*)pBanner->m_BannerTexture, 192, 64);
|
2013-09-25 01:05:36 -06:00
|
|
|
*pWidth = 192;
|
|
|
|
*pHeight = 64;
|
2013-09-26 19:15:35 -06:00
|
|
|
return Buffer;
|
2008-12-07 22:30:24 -07:00
|
|
|
}
|
|
|
|
|
2013-03-02 21:57:49 -07:00
|
|
|
bool CBannerLoaderWii::GetStringFromComments(const CommentIndex index, std::string& result)
|
2008-12-07 22:30:24 -07:00
|
|
|
{
|
2009-02-07 10:31:35 -07:00
|
|
|
if (IsValid())
|
2009-02-03 08:03:34 -07:00
|
|
|
{
|
2013-03-02 21:57:49 -07:00
|
|
|
auto const banner = reinterpret_cast<const SWiiBanner*>(m_pBannerFile);
|
|
|
|
auto const src_ptr = banner->m_Comment[index];
|
2013-10-28 23:23:17 -06:00
|
|
|
|
2014-03-09 14:14:26 -06:00
|
|
|
// Trim at first nullptr
|
2013-03-02 21:57:49 -07:00
|
|
|
auto const length = std::find(src_ptr, src_ptr + COMMENT_SIZE, 0x0) - src_ptr;
|
2013-10-28 23:23:17 -06:00
|
|
|
|
2013-03-02 21:57:49 -07:00
|
|
|
std::wstring src;
|
|
|
|
src.resize(length);
|
|
|
|
std::transform(src_ptr, src_ptr + src.size(), src.begin(), (u16(&)(u16))Common::swap16);
|
|
|
|
result = UTF16ToUTF8(src);
|
2013-10-28 23:23:17 -06:00
|
|
|
|
2011-12-18 22:56:13 -07:00
|
|
|
return true;
|
|
|
|
}
|
2013-03-02 21:57:49 -07:00
|
|
|
|
2011-12-18 22:56:13 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-03-02 18:46:55 -07:00
|
|
|
std::vector<std::string> CBannerLoaderWii::GetNames()
|
2011-11-28 00:17:10 -07:00
|
|
|
{
|
2013-03-02 18:46:55 -07:00
|
|
|
std::vector<std::string> ret(1);
|
2013-10-28 23:23:17 -06:00
|
|
|
|
2013-03-02 18:46:55 -07:00
|
|
|
if (!GetStringFromComments(NAME_IDX, ret[0]))
|
|
|
|
ret.clear();
|
2011-11-28 00:17:10 -07:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-03-02 18:46:55 -07:00
|
|
|
std::string CBannerLoaderWii::GetCompany()
|
2008-12-07 22:30:24 -07:00
|
|
|
{
|
2013-03-02 18:46:55 -07:00
|
|
|
return "";
|
2008-12-07 22:30:24 -07:00
|
|
|
}
|
|
|
|
|
2013-03-02 18:46:55 -07:00
|
|
|
std::vector<std::string> CBannerLoaderWii::GetDescriptions()
|
2008-12-07 22:30:24 -07:00
|
|
|
{
|
2013-03-02 18:46:55 -07:00
|
|
|
std::vector<std::string> result(1);
|
|
|
|
if (!GetStringFromComments(DESC_IDX, result[0]))
|
|
|
|
result.clear();
|
|
|
|
return result;
|
2008-12-07 22:30:24 -07:00
|
|
|
}
|
|
|
|
|
2010-12-21 23:45:59 -07:00
|
|
|
} // namespace
|