Files
dolphin/Source/Core/DiscIO/BannerLoaderWii.cpp
T

152 lines
3.4 KiB
C++
Raw Normal View History

// Copyright 2013 Dolphin Emulator Project
// Licensed under GPLv2
// Refer to the license.txt file included.
2008-12-08 05:30:24 +00:00
2013-03-01 19:33:17 -06:00
#include <algorithm>
#include <cstddef>
2014-02-17 05:18:15 -05:00
#include <cstdio>
#include <string>
#include <vector>
2008-12-08 05:30:24 +00:00
2014-02-17 05:18:15 -05:00
#include "Common/ColorUtil.h"
#include "Common/CommonFuncs.h"
#include "Common/CommonTypes.h"
2014-02-17 05:18:15 -05:00
#include "Common/FileUtil.h"
#include "Common/StringUtil.h"
2014-02-17 05:18:15 -05:00
#include "DiscIO/BannerLoaderWii.h"
#include "DiscIO/Volume.h"
2008-12-08 05:30:24 +00:00
namespace DiscIO
{
2009-03-20 18:13:31 +00:00
CBannerLoaderWii::CBannerLoaderWii(DiscIO::IVolume *pVolume)
2008-12-08 05:30:24 +00:00
{
u64 TitleID;
pVolume->GetTitleID((u8*)&TitleID);
TitleID = Common::swap64(TitleID);
2014-06-03 01:08:54 -04: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 18:13:31 +00:00
if (!File::Exists(Filename))
{
// TODO(XK): Finish the 'commented' code. Turns out the banner.bin
// from the savefiles is very different from the banner.bin
// inside opening.bnr
#if 0
// Creating title folder
2014-06-03 01:08:54 -04:00
std::string titleFolder = StringFromFormat("%stitle/%08x/%08x/data/",
File::GetUserPath(D_WIIUSER_IDX).c_str(), (u32)(TitleID>>32), (u32)TitleID);
if (!File::Exists(titleFolder))
File::CreateFullPath(titleFolder);
// Extracting banner.bin from opening.bnr
2014-06-03 01:08:54 -04:00
std::string bnrFilename = StringFromFormat("%stitle/%08x/%08x/data/opening.bnr",
File::GetUserPath(D_WIIUSER_IDX).c_str(), (u32)(TitleID>>32), (u32)TitleID);
2014-06-03 01:08:54 -04:00
if (!_rFileSystem.ExportFile("opening.bnr", bnrFilename))
{
m_IsValid = false;
return;
}
CARCFile bnrArc (bnrFilename, 0x600);
2014-06-03 01:08:54 -04:00
if (!bnrArc.ExportFile("meta/banner.bin", Filename))
{
m_IsValid = false;
return;
}
// Now we have an LZ77-compressed file with a short IMD5 header
// TODO: Finish the job
File::Delete(bnrFilename);
#else
2009-03-20 18:13:31 +00:00
m_IsValid = false;
return;
#endif
2009-03-20 18:13:31 +00:00
}
2008-12-08 05:30:24 +00:00
// load the banner.bin
2008-12-20 18:46:49 +00:00
size_t FileSize = (size_t) File::GetSize(Filename);
2008-12-08 05:30:24 +00:00
if (FileSize > 0)
{
m_pBannerFile = new u8[FileSize];
File::IOFile pFile(Filename, "rb");
2009-03-20 18:13:31 +00:00
if (pFile)
2008-12-08 05:30:24 +00:00
{
pFile.ReadBytes(m_pBannerFile, FileSize);
2008-12-08 05:30:24 +00:00
m_IsValid = true;
}
}
}
CBannerLoaderWii::~CBannerLoaderWii()
{
if (m_pBannerFile)
{
delete [] m_pBannerFile;
2014-03-09 21:14:26 +01:00
m_pBannerFile = nullptr;
2008-12-08 05:30:24 +00:00
}
}
2013-09-25 03:05:36 -04:00
std::vector<u32> CBannerLoaderWii::GetBanner(int* pWidth, int* pHeight)
2008-12-08 05:30:24 +00:00
{
2013-09-25 03:05:36 -04:00
SWiiBanner* pBanner = (SWiiBanner*)m_pBannerFile;
std::vector<u32> Buffer;
Buffer.resize(192 * 64);
ColorUtil::decode5A3image(&Buffer[0], (u16*)pBanner->m_BannerTexture, 192, 64);
2013-09-25 03:05:36 -04:00
*pWidth = 192;
*pHeight = 64;
return Buffer;
2008-12-08 05:30:24 +00:00
}
2013-03-02 22:57:49 -06:00
bool CBannerLoaderWii::GetStringFromComments(const CommentIndex index, std::string& result)
2008-12-08 05:30:24 +00:00
{
if (IsValid())
{
2013-03-02 22:57:49 -06:00
auto const banner = reinterpret_cast<const SWiiBanner*>(m_pBannerFile);
auto const src_ptr = banner->m_Comment[index];
2014-03-09 21:14:26 +01:00
// Trim at first nullptr
2013-03-02 22:57:49 -06:00
auto const length = std::find(src_ptr, src_ptr + COMMENT_SIZE, 0x0) - src_ptr;
2013-03-02 22:57:49 -06:00
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;
2008-12-08 05:30:24 +00:00
}
2013-03-02 22:57:49 -06:00
return false;
2008-12-08 05:30:24 +00:00
}
2013-03-02 19:46:55 -06:00
std::vector<std::string> CBannerLoaderWii::GetNames()
{
2013-03-02 19:46:55 -06:00
std::vector<std::string> ret(1);
2013-03-02 19:46:55 -06:00
if (!GetStringFromComments(NAME_IDX, ret[0]))
ret.clear();
return ret;
}
2013-03-02 19:46:55 -06:00
std::string CBannerLoaderWii::GetCompany()
2008-12-08 05:30:24 +00:00
{
2013-03-02 19:46:55 -06:00
return "";
2008-12-08 05:30:24 +00:00
}
2013-03-02 19:46:55 -06:00
std::vector<std::string> CBannerLoaderWii::GetDescriptions()
2008-12-08 05:30:24 +00:00
{
2013-03-02 19:46:55 -06:00
std::vector<std::string> result(1);
if (!GetStringFromComments(DESC_IDX, result[0]))
result.clear();
return result;
2008-12-08 05:30:24 +00:00
}
2010-12-22 06:45:59 +00:00
} // namespace