2013-04-17 21:43:35 -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
|
|
|
|
2014-02-17 03:18:15 -07:00
|
|
|
#include <cinttypes>
|
2014-02-22 15:36:30 -07:00
|
|
|
#include <cstdio>
|
|
|
|
#include <cstring>
|
2014-11-15 11:25:21 -07:00
|
|
|
#include <memory>
|
2008-12-07 22:30:24 -07:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
2014-11-17 18:11:34 -07:00
|
|
|
#include <wx/app.h>
|
2014-02-22 15:36:30 -07:00
|
|
|
#include <wx/bitmap.h>
|
|
|
|
#include <wx/filefn.h>
|
|
|
|
#include <wx/gdicmn.h>
|
|
|
|
#include <wx/image.h>
|
|
|
|
#include <wx/string.h>
|
2014-11-17 18:11:34 -07:00
|
|
|
#include <wx/window.h>
|
2008-12-07 22:30:24 -07:00
|
|
|
|
2014-02-17 03:18:15 -07:00
|
|
|
#include "Common/ChunkFile.h"
|
|
|
|
#include "Common/CommonPaths.h"
|
2014-09-07 19:06:58 -06:00
|
|
|
#include "Common/CommonTypes.h"
|
2014-02-17 03:18:15 -07:00
|
|
|
#include "Common/FileUtil.h"
|
|
|
|
#include "Common/Hash.h"
|
|
|
|
#include "Common/IniFile.h"
|
|
|
|
#include "Common/StringUtil.h"
|
|
|
|
|
|
|
|
#include "Core/ConfigManager.h"
|
2014-02-22 15:36:30 -07:00
|
|
|
#include "Core/CoreParameter.h"
|
|
|
|
#include "Core/Boot/Boot.h"
|
2014-02-17 03:18:15 -07:00
|
|
|
|
|
|
|
#include "DiscIO/BannerLoader.h"
|
|
|
|
#include "DiscIO/CompressedBlob.h"
|
|
|
|
#include "DiscIO/Filesystem.h"
|
2014-02-22 15:36:30 -07:00
|
|
|
#include "DiscIO/Volume.h"
|
|
|
|
#include "DiscIO/VolumeCreator.h"
|
2014-02-17 03:18:15 -07:00
|
|
|
|
|
|
|
#include "DolphinWX/ISOFile.h"
|
|
|
|
#include "DolphinWX/WxUtils.h"
|
2008-12-07 22:30:24 -07:00
|
|
|
|
2015-04-08 16:55:16 -06:00
|
|
|
static const u32 CACHE_REVISION = 0x122;
|
2008-12-07 22:30:24 -07:00
|
|
|
|
|
|
|
#define DVD_BANNER_WIDTH 96
|
|
|
|
#define DVD_BANNER_HEIGHT 32
|
|
|
|
|
2009-02-03 08:03:34 -07:00
|
|
|
GameListItem::GameListItem(const std::string& _rFileName)
|
2008-12-07 22:30:24 -07:00
|
|
|
: m_FileName(_rFileName)
|
2011-03-25 12:12:40 -06:00
|
|
|
, m_emu_state(0)
|
2008-12-07 22:30:24 -07:00
|
|
|
, m_FileSize(0)
|
2013-04-16 21:29:01 -06:00
|
|
|
, m_Revision(0)
|
2008-12-07 22:30:24 -07:00
|
|
|
, m_Valid(false)
|
|
|
|
, m_BlobCompressed(false)
|
2013-09-25 01:05:36 -06:00
|
|
|
, m_ImageWidth(0)
|
|
|
|
, m_ImageHeight(0)
|
2008-12-07 22:30:24 -07:00
|
|
|
{
|
2009-02-03 08:03:34 -07:00
|
|
|
if (LoadFromCache())
|
2008-12-07 22:30:24 -07:00
|
|
|
{
|
|
|
|
m_Valid = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DiscIO::IVolume* pVolume = DiscIO::CreateVolumeFromFilename(_rFileName);
|
|
|
|
|
2014-03-09 14:14:26 -06:00
|
|
|
if (pVolume != nullptr)
|
2008-12-07 22:30:24 -07:00
|
|
|
{
|
2015-01-17 05:21:02 -07:00
|
|
|
if (!pVolume->IsWadFile())
|
|
|
|
m_Platform = pVolume->IsWiiDisc() ? WII_DISC : GAMECUBE_DISC;
|
2009-06-06 20:54:07 -06:00
|
|
|
else
|
|
|
|
m_Platform = WII_WAD;
|
2009-05-27 00:41:01 -06:00
|
|
|
|
2013-03-02 18:46:55 -07:00
|
|
|
m_volume_names = pVolume->GetNames();
|
2011-12-18 23:01:46 -07:00
|
|
|
|
2015-01-17 05:21:02 -07:00
|
|
|
m_Country = pVolume->GetCountry();
|
2013-04-09 11:58:56 -06:00
|
|
|
m_FileSize = pVolume->GetRawSize();
|
2008-12-07 22:30:24 -07:00
|
|
|
m_VolumeSize = pVolume->GetSize();
|
2009-06-06 01:36:22 -06:00
|
|
|
|
2008-12-07 22:30:24 -07:00
|
|
|
m_UniqueID = pVolume->GetUniqueID();
|
2014-03-12 13:33:41 -06:00
|
|
|
m_BlobCompressed = DiscIO::IsCompressedBlob(_rFileName);
|
2013-01-25 19:28:04 -07:00
|
|
|
m_IsDiscTwo = pVolume->IsDiscTwo();
|
2013-04-16 21:29:01 -06:00
|
|
|
m_Revision = pVolume->GetRevision();
|
2008-12-07 22:30:24 -07:00
|
|
|
|
2013-04-19 07:21:45 -06:00
|
|
|
// check if we can get some info from the banner file too
|
2008-12-07 22:30:24 -07:00
|
|
|
DiscIO::IFileSystem* pFileSystem = DiscIO::CreateFileSystem(pVolume);
|
|
|
|
|
2014-03-09 14:14:26 -06:00
|
|
|
if (pFileSystem != nullptr || m_Platform == WII_WAD)
|
2008-12-07 22:30:24 -07:00
|
|
|
{
|
2014-11-15 11:25:21 -07:00
|
|
|
std::unique_ptr<DiscIO::IBannerLoader> pBannerLoader(DiscIO::CreateBannerLoader(*pFileSystem, pVolume));
|
2008-12-07 22:30:24 -07:00
|
|
|
|
2014-11-15 11:25:21 -07:00
|
|
|
if (pBannerLoader != nullptr && pBannerLoader->IsValid())
|
2008-12-07 22:30:24 -07:00
|
|
|
{
|
2014-11-15 11:25:21 -07:00
|
|
|
if (m_Platform != WII_WAD)
|
|
|
|
m_banner_names = pBannerLoader->GetNames();
|
|
|
|
m_company = pBannerLoader->GetCompany();
|
|
|
|
m_descriptions = pBannerLoader->GetDescriptions();
|
|
|
|
|
|
|
|
std::vector<u32> Buffer = pBannerLoader->GetBanner(&m_ImageWidth, &m_ImageHeight);
|
|
|
|
u32* pData = &Buffer[0];
|
|
|
|
// resize vector to image size
|
|
|
|
m_pImage.resize(m_ImageWidth * m_ImageHeight * 3);
|
|
|
|
|
|
|
|
for (int i = 0; i < m_ImageWidth * m_ImageHeight; i++)
|
2008-12-07 22:30:24 -07:00
|
|
|
{
|
2014-11-15 11:25:21 -07:00
|
|
|
m_pImage[i * 3 + 0] = (pData[i] & 0xFF0000) >> 16;
|
|
|
|
m_pImage[i * 3 + 1] = (pData[i] & 0x00FF00) >> 8;
|
|
|
|
m_pImage[i * 3 + 2] = (pData[i] & 0x0000FF) >> 0;
|
2008-12-07 22:30:24 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
delete pFileSystem;
|
|
|
|
}
|
|
|
|
|
|
|
|
delete pVolume;
|
|
|
|
|
|
|
|
m_Valid = true;
|
|
|
|
|
2011-03-23 15:54:14 -06:00
|
|
|
// Create a cache file only if we have an image.
|
2014-11-14 12:46:49 -07:00
|
|
|
// Wii ISOs create their images after you have generated the first savegame
|
2011-03-23 15:54:14 -06:00
|
|
|
if (!m_pImage.empty())
|
2008-12-07 22:30:24 -07:00
|
|
|
SaveToCache();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-22 22:31:00 -06:00
|
|
|
if (IsValid())
|
|
|
|
{
|
2015-02-07 13:27:26 -07:00
|
|
|
IniFile ini = SCoreStartupParameter::LoadGameIni(m_UniqueID, m_Revision);
|
|
|
|
ini.GetIfExists("EmuState", "EmulationStateId", &m_emu_state);
|
|
|
|
ini.GetIfExists("EmuState", "EmulationIssues", &m_issues);
|
2011-03-22 22:31:00 -06:00
|
|
|
}
|
|
|
|
|
2011-03-22 01:27:23 -06:00
|
|
|
if (!m_pImage.empty())
|
2008-12-07 22:30:24 -07:00
|
|
|
{
|
2013-09-25 01:05:36 -06:00
|
|
|
wxImage Image(m_ImageWidth, m_ImageHeight, &m_pImage[0], true);
|
2014-11-17 18:11:34 -07:00
|
|
|
double Scale = wxTheApp->GetTopWindow()->GetContentScaleFactor();
|
2013-09-25 01:05:36 -06:00
|
|
|
// Note: This uses nearest neighbor, which subjectively looks a lot
|
|
|
|
// better for GC banners than smooths caling.
|
|
|
|
Image.Rescale(DVD_BANNER_WIDTH * Scale, DVD_BANNER_HEIGHT * Scale);
|
|
|
|
#ifdef __APPLE__
|
|
|
|
m_Bitmap = wxBitmap(Image, -1, Scale);
|
|
|
|
#else
|
|
|
|
m_Bitmap = wxBitmap(Image, -1);
|
|
|
|
#endif
|
2008-12-07 22:30:24 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// default banner
|
2013-09-25 01:05:36 -06:00
|
|
|
m_Bitmap.LoadFile(StrToWxStr(File::GetThemeDir(SConfig::GetInstance().m_LocalCoreStartupParameter.theme_name)) + "nobanner.png", wxBITMAP_TYPE_PNG);
|
2008-12-07 22:30:24 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
GameListItem::~GameListItem()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GameListItem::LoadFromCache()
|
|
|
|
{
|
|
|
|
return CChunkFileReader::Load<GameListItem>(CreateCacheFilename(), CACHE_REVISION, *this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GameListItem::SaveToCache()
|
|
|
|
{
|
2011-02-28 20:06:14 -07:00
|
|
|
if (!File::IsDirectory(File::GetUserPath(D_CACHE_IDX)))
|
|
|
|
File::CreateDir(File::GetUserPath(D_CACHE_IDX));
|
2008-12-07 22:30:24 -07:00
|
|
|
|
|
|
|
CChunkFileReader::Save<GameListItem>(CreateCacheFilename(), CACHE_REVISION, *this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GameListItem::DoState(PointerWrap &p)
|
|
|
|
{
|
2013-03-02 18:46:55 -07:00
|
|
|
p.Do(m_volume_names);
|
|
|
|
p.Do(m_company);
|
2014-10-07 17:14:11 -06:00
|
|
|
p.Do(m_banner_names);
|
2013-03-02 18:46:55 -07:00
|
|
|
p.Do(m_descriptions);
|
2008-12-07 22:30:24 -07:00
|
|
|
p.Do(m_UniqueID);
|
|
|
|
p.Do(m_FileSize);
|
|
|
|
p.Do(m_VolumeSize);
|
|
|
|
p.Do(m_Country);
|
|
|
|
p.Do(m_BlobCompressed);
|
2011-03-22 01:27:23 -06:00
|
|
|
p.Do(m_pImage);
|
2013-09-25 01:05:36 -06:00
|
|
|
p.Do(m_ImageWidth);
|
|
|
|
p.Do(m_ImageHeight);
|
2009-06-06 01:36:22 -06:00
|
|
|
p.Do(m_Platform);
|
2013-01-25 19:28:04 -07:00
|
|
|
p.Do(m_IsDiscTwo);
|
2013-04-16 21:29:01 -06:00
|
|
|
p.Do(m_Revision);
|
2008-12-07 22:30:24 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string GameListItem::CreateCacheFilename()
|
|
|
|
{
|
2010-12-07 23:46:59 -07:00
|
|
|
std::string Filename, LegalPathname, extension;
|
|
|
|
SplitPath(m_FileName, &LegalPathname, &Filename, &extension);
|
2009-04-08 10:38:41 -06:00
|
|
|
|
2009-04-27 20:30:50 -06:00
|
|
|
if (Filename.empty()) return Filename; // Disc Drive
|
2010-11-11 02:17:57 -07:00
|
|
|
|
2010-12-07 23:46:59 -07:00
|
|
|
// Filename.extension_HashOfFolderPath_Size.cache
|
2010-11-11 02:17:57 -07:00
|
|
|
// Append hash to prevent ISO name-clashing in different folders.
|
2014-02-12 13:08:23 -07:00
|
|
|
Filename.append(StringFromFormat("%s_%x_%" PRIx64 ".cache",
|
2010-12-07 23:46:59 -07:00
|
|
|
extension.c_str(), HashFletcher((const u8 *)LegalPathname.c_str(), LegalPathname.size()),
|
2011-02-28 20:06:14 -07:00
|
|
|
File::GetSize(m_FileName)));
|
2008-12-07 22:30:24 -07:00
|
|
|
|
2011-02-28 13:40:15 -07:00
|
|
|
std::string fullname(File::GetUserPath(D_CACHE_IDX));
|
2008-12-07 22:30:24 -07:00
|
|
|
fullname += Filename;
|
|
|
|
return fullname;
|
|
|
|
}
|
2009-02-03 08:03:34 -07:00
|
|
|
|
2013-03-02 18:46:55 -07:00
|
|
|
std::string GameListItem::GetCompany() const
|
2009-02-03 08:03:34 -07:00
|
|
|
{
|
2013-03-02 18:46:55 -07:00
|
|
|
if (m_company.empty())
|
|
|
|
return "N/A";
|
|
|
|
else
|
|
|
|
return m_company;
|
2009-02-03 08:03:34 -07:00
|
|
|
}
|
|
|
|
|
2013-03-27 13:25:48 -06:00
|
|
|
// (-1 = Japanese, 0 = English, etc)?
|
2013-03-02 18:46:55 -07:00
|
|
|
std::string GameListItem::GetDescription(int _index) const
|
2009-02-03 08:03:34 -07:00
|
|
|
{
|
2013-03-27 13:25:48 -06:00
|
|
|
const u32 index = _index;
|
2013-03-02 18:46:55 -07:00
|
|
|
|
|
|
|
if (index < m_descriptions.size())
|
|
|
|
return m_descriptions[index];
|
2013-10-28 23:23:17 -06:00
|
|
|
|
2013-03-02 18:46:55 -07:00
|
|
|
if (!m_descriptions.empty())
|
|
|
|
return m_descriptions[0];
|
|
|
|
|
|
|
|
return "";
|
2009-02-03 08:03:34 -07:00
|
|
|
}
|
2009-04-27 20:30:50 -06:00
|
|
|
|
2013-03-27 13:25:48 -06:00
|
|
|
// (-1 = Japanese, 0 = English, etc)?
|
2013-03-03 17:29:56 -07:00
|
|
|
std::string GameListItem::GetVolumeName(int _index) const
|
|
|
|
{
|
2013-03-27 13:25:48 -06:00
|
|
|
u32 const index = _index;
|
2013-03-03 17:29:56 -07:00
|
|
|
|
|
|
|
if (index < m_volume_names.size() && !m_volume_names[index].empty())
|
|
|
|
return m_volume_names[index];
|
|
|
|
|
|
|
|
if (!m_volume_names.empty())
|
|
|
|
return m_volume_names[0];
|
2013-10-28 23:23:17 -06:00
|
|
|
|
2013-03-03 17:29:56 -07:00
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2013-03-27 13:25:48 -06:00
|
|
|
// (-1 = Japanese, 0 = English, etc)?
|
2013-03-03 17:29:56 -07:00
|
|
|
std::string GameListItem::GetBannerName(int _index) const
|
2011-12-18 23:01:46 -07:00
|
|
|
{
|
2013-03-27 13:25:48 -06:00
|
|
|
u32 const index = _index;
|
2013-03-02 18:46:55 -07:00
|
|
|
|
2014-10-07 17:14:11 -06:00
|
|
|
if (index < m_banner_names.size() && !m_banner_names[index].empty())
|
|
|
|
return m_banner_names[index];
|
2013-10-28 23:23:17 -06:00
|
|
|
|
2014-10-07 17:14:11 -06:00
|
|
|
if (!m_banner_names.empty())
|
|
|
|
return m_banner_names[0];
|
2013-03-02 18:46:55 -07:00
|
|
|
|
2013-03-03 17:29:56 -07:00
|
|
|
return "";
|
|
|
|
}
|
2013-03-02 18:46:55 -07:00
|
|
|
|
2013-03-27 13:25:48 -06:00
|
|
|
// (-1 = Japanese, 0 = English, etc)?
|
2013-03-03 17:29:56 -07:00
|
|
|
std::string GameListItem::GetName(int _index) const
|
|
|
|
{
|
|
|
|
// Prefer name from banner, fallback to name from volume, fallback to filename
|
2013-10-28 23:23:17 -06:00
|
|
|
|
2013-03-03 17:29:56 -07:00
|
|
|
std::string name = GetBannerName(_index);
|
2013-10-28 23:23:17 -06:00
|
|
|
|
2013-03-03 17:29:56 -07:00
|
|
|
if (name.empty())
|
|
|
|
name = GetVolumeName(_index);
|
|
|
|
|
|
|
|
if (name.empty())
|
|
|
|
{
|
|
|
|
// No usable name, return filename (better than nothing)
|
2014-03-09 14:14:26 -06:00
|
|
|
SplitPath(GetFileName(), nullptr, &name, nullptr);
|
2013-03-03 17:29:56 -07:00
|
|
|
}
|
2013-03-02 18:46:55 -07:00
|
|
|
|
2013-03-03 17:29:56 -07:00
|
|
|
return name;
|
2011-12-18 23:01:46 -07:00
|
|
|
}
|
|
|
|
|
2009-05-02 12:06:42 -06:00
|
|
|
const std::string GameListItem::GetWiiFSPath() const
|
|
|
|
{
|
2014-03-12 13:33:41 -06:00
|
|
|
DiscIO::IVolume *iso = DiscIO::CreateVolumeFromFilename(m_FileName);
|
2011-01-06 06:57:46 -07:00
|
|
|
std::string ret;
|
2009-05-02 12:06:42 -06:00
|
|
|
|
2014-03-12 13:33:41 -06:00
|
|
|
if (iso == nullptr)
|
2011-01-06 06:57:46 -07:00
|
|
|
return ret;
|
|
|
|
|
2015-01-17 05:21:02 -07:00
|
|
|
if (iso->IsWiiDisc() || iso->IsWadFile())
|
2009-05-02 12:06:42 -06:00
|
|
|
{
|
2014-08-27 19:35:20 -06:00
|
|
|
u64 title = 0;
|
2009-05-02 12:06:42 -06:00
|
|
|
|
2014-03-12 13:33:41 -06:00
|
|
|
iso->GetTitleID((u8*)&title);
|
|
|
|
title = Common::swap64(title);
|
2009-05-02 12:06:42 -06:00
|
|
|
|
2014-03-12 13:33:41 -06:00
|
|
|
const std::string path = StringFromFormat("%stitle/%08x/%08x/data/",
|
|
|
|
File::GetUserPath(D_WIIUSER_IDX).c_str(), (u32)(title>>32), (u32)title);
|
2009-05-02 12:06:42 -06:00
|
|
|
|
2014-03-12 13:33:41 -06:00
|
|
|
if (!File::Exists(path))
|
|
|
|
File::CreateFullPath(path);
|
2009-05-02 12:06:42 -06:00
|
|
|
|
2014-03-12 13:33:41 -06:00
|
|
|
if (path[0] == '.')
|
|
|
|
ret = WxStrToStr(wxGetCwd()) + path.substr(strlen(ROOT_DIR));
|
2011-01-06 06:57:46 -07:00
|
|
|
else
|
2014-03-12 13:33:41 -06:00
|
|
|
ret = path;
|
2009-05-02 12:06:42 -06:00
|
|
|
}
|
2014-03-12 13:33:41 -06:00
|
|
|
delete iso;
|
2009-05-02 12:06:42 -06:00
|
|
|
|
2010-01-14 00:19:10 -07:00
|
|
|
return ret;
|
2009-05-02 12:06:42 -06:00
|
|
|
}
|
|
|
|
|