2009-07-28 21:32:10 +00:00
|
|
|
// Copyright (C) 2003 Dolphin Project.
|
2008-12-08 05:30:24 +00:00
|
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, version 2.0.
|
|
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License 2.0 for more details.
|
|
|
|
|
|
|
|
// A copy of the GPL 2.0 should have been included with the program.
|
|
|
|
// If not, see http://www.gnu.org/licenses/
|
|
|
|
|
|
|
|
// Official SVN repository and contact information can be found at
|
|
|
|
// http://code.google.com/p/dolphin-emu/
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
#include <wx/mstream.h>
|
|
|
|
|
2010-07-20 03:23:25 +00:00
|
|
|
#include "Common.h"
|
|
|
|
#include "CommonPaths.h"
|
|
|
|
|
2008-12-08 05:30:24 +00:00
|
|
|
#include "Globals.h"
|
|
|
|
#include "FileUtil.h"
|
|
|
|
#include "ISOFile.h"
|
|
|
|
#include "StringUtil.h"
|
2010-11-11 09:17:57 +00:00
|
|
|
#include "Hash.h"
|
2011-03-23 04:31:00 +00:00
|
|
|
#include "IniFile.h"
|
2008-12-08 05:30:24 +00:00
|
|
|
|
|
|
|
#include "Filesystem.h"
|
|
|
|
#include "BannerLoader.h"
|
|
|
|
#include "FileSearch.h"
|
|
|
|
#include "CompressedBlob.h"
|
|
|
|
#include "ChunkFile.h"
|
|
|
|
#include "../resources/no_banner.cpp"
|
|
|
|
|
2011-12-22 23:53:41 +00:00
|
|
|
#define CACHE_REVISION 0x10D
|
2008-12-08 05:30:24 +00:00
|
|
|
|
|
|
|
#define DVD_BANNER_WIDTH 96
|
|
|
|
#define DVD_BANNER_HEIGHT 32
|
|
|
|
|
|
|
|
static u32 g_ImageTemp[DVD_BANNER_WIDTH * DVD_BANNER_HEIGHT];
|
|
|
|
|
2009-02-03 15:03:34 +00:00
|
|
|
GameListItem::GameListItem(const std::string& _rFileName)
|
2008-12-08 05:30:24 +00:00
|
|
|
: m_FileName(_rFileName)
|
2011-03-25 18:12:40 +00:00
|
|
|
, m_emu_state(0)
|
2008-12-08 05:30:24 +00:00
|
|
|
, m_FileSize(0)
|
|
|
|
, m_Valid(false)
|
|
|
|
, m_BlobCompressed(false)
|
|
|
|
{
|
2009-02-03 15:03:34 +00:00
|
|
|
if (LoadFromCache())
|
2008-12-08 05:30:24 +00:00
|
|
|
{
|
|
|
|
m_Valid = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DiscIO::IVolume* pVolume = DiscIO::CreateVolumeFromFilename(_rFileName);
|
|
|
|
|
|
|
|
if (pVolume != NULL)
|
|
|
|
{
|
2009-06-07 02:54:07 +00:00
|
|
|
if (!DiscIO::IsVolumeWadFile(pVolume))
|
|
|
|
m_Platform = DiscIO::IsVolumeWiiDisc(pVolume) ? WII_DISC : GAMECUBE_DISC;
|
|
|
|
else
|
2011-12-19 06:01:46 +00:00
|
|
|
{
|
2009-06-07 02:54:07 +00:00
|
|
|
m_Platform = WII_WAD;
|
2011-12-19 06:01:46 +00:00
|
|
|
pVolume->GetWName(m_wNames);
|
|
|
|
}
|
2009-05-27 06:41:01 +00:00
|
|
|
|
2009-02-07 17:31:35 +00:00
|
|
|
m_Company = "N/A";
|
2011-12-19 06:01:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
m_Name[0] = pVolume->GetName();
|
|
|
|
|
|
|
|
if(m_Name[0] == "") // Couldn't find the name in the WAD...
|
|
|
|
{
|
|
|
|
std::string FileName;
|
|
|
|
SplitPath(m_FileName, NULL, &FileName, NULL);
|
|
|
|
m_Name[0] = FileName; // Then just display the filename... Better than something like "No Name"
|
|
|
|
}
|
|
|
|
|
2009-03-07 04:46:06 +00:00
|
|
|
for (int i = 0; i < 6; i++)
|
|
|
|
{
|
2011-12-19 06:01:46 +00:00
|
|
|
m_Name[i] = m_Name[0];
|
2009-03-07 04:46:06 +00:00
|
|
|
m_Description[i] = "No Description";
|
|
|
|
}
|
2008-12-08 05:30:24 +00:00
|
|
|
m_Country = pVolume->GetCountry();
|
2011-03-01 03:06:14 +00:00
|
|
|
m_FileSize = File::GetSize(_rFileName);
|
2008-12-08 05:30:24 +00:00
|
|
|
m_VolumeSize = pVolume->GetSize();
|
2009-06-06 07:36:22 +00:00
|
|
|
|
2008-12-08 05:30:24 +00:00
|
|
|
m_UniqueID = pVolume->GetUniqueID();
|
|
|
|
m_BlobCompressed = DiscIO::IsCompressedBlob(_rFileName.c_str());
|
|
|
|
|
|
|
|
// check if we can get some infos from the banner file too
|
|
|
|
DiscIO::IFileSystem* pFileSystem = DiscIO::CreateFileSystem(pVolume);
|
|
|
|
|
2009-06-07 02:54:07 +00:00
|
|
|
if (pFileSystem != NULL || m_Platform == WII_WAD)
|
2008-12-08 05:30:24 +00:00
|
|
|
{
|
2009-06-07 02:54:07 +00:00
|
|
|
DiscIO::IBannerLoader* pBannerLoader = DiscIO::CreateBannerLoader(*pFileSystem, pVolume);
|
2008-12-08 05:30:24 +00:00
|
|
|
|
|
|
|
if (pBannerLoader != NULL)
|
|
|
|
{
|
|
|
|
if (pBannerLoader->IsValid())
|
|
|
|
{
|
2011-12-19 06:01:46 +00:00
|
|
|
m_wNames.clear();
|
2011-12-22 23:53:41 +00:00
|
|
|
pBannerLoader->GetName(m_wNames);
|
|
|
|
pBannerLoader->GetName(m_Name);
|
2008-12-08 05:30:24 +00:00
|
|
|
pBannerLoader->GetCompany(m_Company);
|
2011-12-22 23:53:41 +00:00
|
|
|
pBannerLoader->GetDescription(m_wDescription);
|
|
|
|
pBannerLoader->GetDescription(m_Description);
|
2011-12-19 06:01:46 +00:00
|
|
|
|
2008-12-08 05:30:24 +00:00
|
|
|
if (pBannerLoader->GetBanner(g_ImageTemp))
|
|
|
|
{
|
2011-03-22 07:27:23 +00:00
|
|
|
// resize vector to image size
|
|
|
|
m_pImage.resize(DVD_BANNER_WIDTH * DVD_BANNER_HEIGHT * 3);
|
2008-12-08 05:30:24 +00:00
|
|
|
|
|
|
|
for (size_t i = 0; i < DVD_BANNER_WIDTH * DVD_BANNER_HEIGHT; i++)
|
|
|
|
{
|
|
|
|
m_pImage[i * 3 + 0] = (g_ImageTemp[i] & 0xFF0000) >> 16;
|
|
|
|
m_pImage[i * 3 + 1] = (g_ImageTemp[i] & 0x00FF00) >> 8;
|
|
|
|
m_pImage[i * 3 + 2] = (g_ImageTemp[i] & 0x0000FF) >> 0;
|
2009-06-06 07:36:22 +00:00
|
|
|
}
|
2008-12-08 05:30:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
delete pBannerLoader;
|
|
|
|
}
|
|
|
|
|
|
|
|
delete pFileSystem;
|
|
|
|
}
|
2011-12-19 06:01:46 +00:00
|
|
|
std::vector<std::wstring>::iterator i, end = m_wNames.end();
|
|
|
|
std::wstring wFileName;
|
|
|
|
for (i = m_wNames.begin(); i != end; ++i)
|
|
|
|
{
|
|
|
|
if (*i == L"")
|
|
|
|
{
|
|
|
|
if (!wFileName.length())
|
|
|
|
{
|
|
|
|
std::string FileName;
|
|
|
|
SplitPath(m_FileName, NULL, &FileName, NULL);
|
|
|
|
int length = FileName.length();
|
|
|
|
wFileName.reserve(length+1);
|
2013-01-03 16:35:07 +00:00
|
|
|
for (int j = 0; j < length; ++j)
|
|
|
|
wFileName.push_back(FileName[j]);
|
2011-12-19 06:01:46 +00:00
|
|
|
wFileName.push_back(0);
|
|
|
|
}
|
|
|
|
*i = wFileName;
|
|
|
|
}
|
|
|
|
}
|
2008-12-08 05:30:24 +00:00
|
|
|
|
|
|
|
delete pVolume;
|
|
|
|
|
|
|
|
m_Valid = true;
|
|
|
|
|
2011-03-23 21:54:14 +00:00
|
|
|
// Create a cache file only if we have an image.
|
2008-12-08 05:30:24 +00:00
|
|
|
// Wii isos create their images after you have generated the first savegame
|
2011-03-23 21:54:14 +00:00
|
|
|
if (!m_pImage.empty())
|
2008-12-08 05:30:24 +00:00
|
|
|
SaveToCache();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-23 04:31:00 +00:00
|
|
|
if (IsValid())
|
|
|
|
{
|
|
|
|
IniFile ini;
|
|
|
|
ini.Load(File::GetUserPath(D_GAMECONFIG_IDX) + m_UniqueID + ".ini");
|
|
|
|
ini.Get("EmuState", "EmulationStateId", &m_emu_state);
|
|
|
|
ini.Get("EmuState", "EmulationIssues", &m_issues);
|
|
|
|
}
|
|
|
|
|
2011-03-22 07:27:23 +00:00
|
|
|
if (!m_pImage.empty())
|
2008-12-08 05:30:24 +00:00
|
|
|
{
|
2011-03-22 07:27:23 +00:00
|
|
|
m_Image.Create(DVD_BANNER_WIDTH, DVD_BANNER_HEIGHT, &m_pImage[0], true);
|
2008-12-08 05:30:24 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// default banner
|
|
|
|
wxMemoryInputStream istream(no_banner_png, sizeof no_banner_png);
|
|
|
|
wxImage iNoBanner(istream, wxBITMAP_TYPE_PNG);
|
|
|
|
m_Image = iNoBanner;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
GameListItem::~GameListItem()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GameListItem::LoadFromCache()
|
|
|
|
{
|
|
|
|
return CChunkFileReader::Load<GameListItem>(CreateCacheFilename(), CACHE_REVISION, *this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GameListItem::SaveToCache()
|
|
|
|
{
|
2011-03-01 03:06:14 +00:00
|
|
|
if (!File::IsDirectory(File::GetUserPath(D_CACHE_IDX)))
|
2008-12-08 05:30:24 +00:00
|
|
|
{
|
2011-03-01 03:06:14 +00:00
|
|
|
File::CreateDir(File::GetUserPath(D_CACHE_IDX));
|
2008-12-08 05:30:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CChunkFileReader::Save<GameListItem>(CreateCacheFilename(), CACHE_REVISION, *this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GameListItem::DoState(PointerWrap &p)
|
|
|
|
{
|
2009-02-03 15:03:34 +00:00
|
|
|
p.Do(m_Name[0]); p.Do(m_Name[1]); p.Do(m_Name[2]);
|
|
|
|
p.Do(m_Name[3]); p.Do(m_Name[4]); p.Do(m_Name[5]);
|
2011-12-19 06:01:46 +00:00
|
|
|
|
|
|
|
int wNamesSize = m_wNames.size();
|
|
|
|
p.Do(wNamesSize);
|
|
|
|
|
|
|
|
if (p.mode == p.MODE_READ)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < wNamesSize; ++i)
|
|
|
|
{
|
|
|
|
std::wstring temp;
|
|
|
|
p.Do(temp);
|
|
|
|
m_wNames.push_back(temp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (int i = 0; i < wNamesSize; ++i)
|
|
|
|
{
|
|
|
|
p.Do(m_wNames[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-08 05:30:24 +00:00
|
|
|
p.Do(m_Company);
|
2009-02-03 15:03:34 +00:00
|
|
|
p.Do(m_Description[0]); p.Do(m_Description[1]); p.Do(m_Description[2]);
|
|
|
|
p.Do(m_Description[3]); p.Do(m_Description[4]); p.Do(m_Description[5]);
|
2011-12-19 06:01:46 +00:00
|
|
|
p.Do(m_wDescription);
|
2008-12-08 05:30:24 +00:00
|
|
|
p.Do(m_UniqueID);
|
|
|
|
p.Do(m_FileSize);
|
|
|
|
p.Do(m_VolumeSize);
|
|
|
|
p.Do(m_Country);
|
|
|
|
p.Do(m_BlobCompressed);
|
2011-03-22 07:27:23 +00:00
|
|
|
p.Do(m_pImage);
|
2009-06-06 07:36:22 +00:00
|
|
|
p.Do(m_Platform);
|
2008-12-08 05:30:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string GameListItem::CreateCacheFilename()
|
|
|
|
{
|
2010-12-08 06:46:59 +00:00
|
|
|
std::string Filename, LegalPathname, extension;
|
|
|
|
SplitPath(m_FileName, &LegalPathname, &Filename, &extension);
|
2009-04-08 16:38:41 +00:00
|
|
|
|
2009-04-28 02:30:50 +00:00
|
|
|
if (Filename.empty()) return Filename; // Disc Drive
|
2010-11-11 09:17:57 +00:00
|
|
|
|
2010-12-08 06:46:59 +00:00
|
|
|
// Filename.extension_HashOfFolderPath_Size.cache
|
2010-11-11 09:17:57 +00:00
|
|
|
// Append hash to prevent ISO name-clashing in different folders.
|
2010-12-08 06:46:59 +00:00
|
|
|
Filename.append(StringFromFormat("%s_%x_%llx.cache",
|
|
|
|
extension.c_str(), HashFletcher((const u8 *)LegalPathname.c_str(), LegalPathname.size()),
|
2011-03-01 03:06:14 +00:00
|
|
|
File::GetSize(m_FileName)));
|
2008-12-08 05:30:24 +00:00
|
|
|
|
2011-02-28 20:40:15 +00:00
|
|
|
std::string fullname(File::GetUserPath(D_CACHE_IDX));
|
2008-12-08 05:30:24 +00:00
|
|
|
fullname += Filename;
|
|
|
|
return fullname;
|
|
|
|
}
|
2009-02-03 15:03:34 +00:00
|
|
|
|
|
|
|
const std::string& GameListItem::GetDescription(int index) const
|
|
|
|
{
|
|
|
|
if ((index >=0) && (index < 6))
|
|
|
|
{
|
|
|
|
return m_Description[index];
|
|
|
|
}
|
|
|
|
return m_Description[0];
|
|
|
|
}
|
|
|
|
|
2011-12-19 06:01:46 +00:00
|
|
|
const std::wstring& GameListItem::GetDescription() const
|
|
|
|
{
|
|
|
|
return m_wDescription;
|
|
|
|
}
|
|
|
|
|
2009-02-03 15:03:34 +00:00
|
|
|
const std::string& GameListItem::GetName(int index) const
|
|
|
|
{
|
|
|
|
if ((index >=0) && (index < 6))
|
|
|
|
{
|
|
|
|
return m_Name[index];
|
|
|
|
}
|
|
|
|
return m_Name[0];
|
|
|
|
}
|
2009-04-28 02:30:50 +00:00
|
|
|
|
2011-12-19 06:01:46 +00:00
|
|
|
bool GameListItem::GetName(std::wstring& wName, int index) const
|
|
|
|
{
|
|
|
|
// This function will only succeed for wii discs with banners or WADs
|
|
|
|
// utilize the same array as for gc discs (-1= Japanese, 0 = English etc
|
|
|
|
index++;
|
2013-01-03 16:35:07 +00:00
|
|
|
if ((index >= 0) && (index < 10))
|
2011-12-19 06:01:46 +00:00
|
|
|
{
|
2012-12-10 06:40:28 +00:00
|
|
|
if (m_wNames.size() > (size_t)index)
|
2011-12-19 06:01:46 +00:00
|
|
|
{
|
|
|
|
wName = m_wNames[index];
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (m_wNames.size() > 0)
|
|
|
|
{
|
|
|
|
wName = m_wNames[0];
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2009-05-02 18:06:42 +00:00
|
|
|
const std::string GameListItem::GetWiiFSPath() const
|
|
|
|
{
|
|
|
|
DiscIO::IVolume *Iso = DiscIO::CreateVolumeFromFilename(m_FileName);
|
2011-01-06 13:57:46 +00:00
|
|
|
std::string ret;
|
2009-05-02 18:06:42 +00:00
|
|
|
|
2011-01-06 13:57:46 +00:00
|
|
|
if (Iso == NULL)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
if (DiscIO::IsVolumeWiiDisc(Iso) || DiscIO::IsVolumeWadFile(Iso))
|
2009-05-02 18:06:42 +00:00
|
|
|
{
|
2011-01-06 13:57:46 +00:00
|
|
|
char Path[250];
|
|
|
|
u64 Title;
|
2009-05-02 18:06:42 +00:00
|
|
|
|
2011-01-06 13:57:46 +00:00
|
|
|
Iso->GetTitleID((u8*)&Title);
|
|
|
|
Title = Common::swap64(Title);
|
2009-05-02 18:06:42 +00:00
|
|
|
|
2011-02-28 20:40:15 +00:00
|
|
|
sprintf(Path, "%stitle/%08x/%08x/data/",
|
|
|
|
File::GetUserPath(D_WIIUSER_IDX).c_str(), (u32)(Title>>32), (u32)Title);
|
2009-05-02 18:06:42 +00:00
|
|
|
|
2011-01-06 13:57:46 +00:00
|
|
|
if (!File::Exists(Path))
|
|
|
|
File::CreateFullPath(Path);
|
2009-05-02 18:06:42 +00:00
|
|
|
|
2011-01-06 13:57:46 +00:00
|
|
|
if (Path[0] == '.')
|
|
|
|
ret = std::string(wxGetCwd().mb_str()) + std::string(Path).substr(strlen(ROOT_DIR));
|
|
|
|
else
|
|
|
|
ret = std::string(Path);
|
2009-05-02 18:06:42 +00:00
|
|
|
}
|
2011-01-06 13:57:46 +00:00
|
|
|
delete Iso;
|
2009-05-02 18:06:42 +00:00
|
|
|
|
2010-01-14 07:19:10 +00:00
|
|
|
return ret;
|
2009-05-02 18:06:42 +00:00
|
|
|
}
|
|
|
|
|