2013-04-18 03:09:55 +00:00
|
|
|
// Copyright 2013 Dolphin Emulator Project
|
|
|
|
// Licensed under GPLv2
|
|
|
|
// Refer to the license.txt file included.
|
2008-12-08 05:30:24 +00:00
|
|
|
|
|
|
|
#include "VolumeGC.h"
|
|
|
|
#include "StringUtil.h"
|
2009-09-04 11:34:21 +00:00
|
|
|
#include "FileMonitor.h"
|
2009-01-03 18:50:01 +00:00
|
|
|
|
2008-12-08 05:30:24 +00:00
|
|
|
namespace DiscIO
|
|
|
|
{
|
|
|
|
CVolumeGC::CVolumeGC(IBlobReader* _pReader)
|
|
|
|
: m_pReader(_pReader)
|
|
|
|
{}
|
|
|
|
|
|
|
|
CVolumeGC::~CVolumeGC()
|
|
|
|
{
|
|
|
|
delete m_pReader;
|
2009-01-04 21:53:41 +00:00
|
|
|
m_pReader = NULL; // I don't think this makes any difference, but anyway
|
2008-12-08 05:30:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CVolumeGC::Read(u64 _Offset, u64 _Length, u8* _pBuffer) const
|
|
|
|
{
|
|
|
|
if (m_pReader == NULL)
|
|
|
|
return false;
|
2009-07-03 03:26:23 +00:00
|
|
|
|
2009-09-03 20:00:09 +00:00
|
|
|
FileMon::FindFilename(_Offset);
|
|
|
|
|
2008-12-08 05:30:24 +00:00
|
|
|
return m_pReader->Read(_Offset, _Length, _pBuffer);
|
|
|
|
}
|
|
|
|
|
2012-03-23 06:04:13 +00:00
|
|
|
bool CVolumeGC::RAWRead(u64 _Offset, u64 _Length, u8* _pBuffer) const
|
2009-02-22 13:59:06 +00:00
|
|
|
{
|
2012-03-23 06:04:13 +00:00
|
|
|
return Read(_Offset, _Length, _pBuffer);
|
2009-02-22 13:59:06 +00:00
|
|
|
}
|
|
|
|
|
2008-12-08 05:30:24 +00:00
|
|
|
std::string CVolumeGC::GetUniqueID() const
|
|
|
|
{
|
|
|
|
static const std::string NO_UID("NO_UID");
|
|
|
|
if (m_pReader == NULL)
|
|
|
|
return NO_UID;
|
|
|
|
|
2011-01-30 17:58:02 +00:00
|
|
|
char ID[7];
|
|
|
|
|
|
|
|
if (!Read(0, sizeof(ID), reinterpret_cast<u8*>(ID)))
|
2008-12-08 05:30:24 +00:00
|
|
|
{
|
2011-01-13 02:05:58 +00:00
|
|
|
PanicAlertT("Failed to read unique ID from disc image");
|
2008-12-08 05:30:24 +00:00
|
|
|
return NO_UID;
|
|
|
|
}
|
|
|
|
|
2011-01-30 17:58:02 +00:00
|
|
|
ID[6] = '\0';
|
|
|
|
|
|
|
|
return ID;
|
2008-12-08 05:30:24 +00:00
|
|
|
}
|
|
|
|
|
2013-09-23 06:39:14 +00:00
|
|
|
std::string CVolumeGC::GetRevisionSpecificUniqueID() const
|
|
|
|
{
|
|
|
|
char rev[16];
|
|
|
|
sprintf(rev, "r%d", GetRevision());
|
|
|
|
return GetUniqueID() + rev;
|
|
|
|
}
|
|
|
|
|
2008-12-08 05:30:24 +00:00
|
|
|
IVolume::ECountry CVolumeGC::GetCountry() const
|
|
|
|
{
|
|
|
|
if (!m_pReader)
|
|
|
|
return COUNTRY_UNKNOWN;
|
|
|
|
|
|
|
|
u8 CountryCode;
|
|
|
|
m_pReader->Read(3, 1, &CountryCode);
|
|
|
|
|
2009-07-03 22:34:51 +00:00
|
|
|
return CountrySwitch(CountryCode);
|
2008-12-08 05:30:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string CVolumeGC::GetMakerID() const
|
|
|
|
{
|
|
|
|
if (m_pReader == NULL)
|
2010-08-13 19:07:59 +00:00
|
|
|
return std::string();
|
2008-12-08 05:30:24 +00:00
|
|
|
|
|
|
|
char makerID[3];
|
|
|
|
if (!Read(0x4, 0x2, (u8*)&makerID))
|
2010-08-13 19:07:59 +00:00
|
|
|
return std::string();
|
|
|
|
makerID[2] = '\0';
|
2008-12-08 05:30:24 +00:00
|
|
|
|
|
|
|
return makerID;
|
|
|
|
}
|
|
|
|
|
2013-04-17 03:29:01 +00:00
|
|
|
int CVolumeGC::GetRevision() const
|
|
|
|
{
|
|
|
|
if (!m_pReader)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
u8 Revision;
|
|
|
|
if (!Read(7, 1, &Revision))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return Revision;
|
|
|
|
}
|
|
|
|
|
2013-03-03 01:46:55 +00:00
|
|
|
std::vector<std::string> CVolumeGC::GetNames() const
|
2008-12-08 05:30:24 +00:00
|
|
|
{
|
2013-03-03 01:46:55 +00:00
|
|
|
std::vector<std::string> names;
|
2013-03-03 22:51:26 +00:00
|
|
|
|
|
|
|
auto const string_decoder = GetStringDecoder(GetCountry());
|
2008-12-08 05:30:24 +00:00
|
|
|
|
2013-03-03 22:51:26 +00:00
|
|
|
char name[0x60 + 1] = {};
|
|
|
|
if (m_pReader != NULL && Read(0x20, 0x60, (u8*)name))
|
|
|
|
names.push_back(string_decoder(name));
|
2008-12-08 05:30:24 +00:00
|
|
|
|
2013-03-03 01:46:55 +00:00
|
|
|
return names;
|
2008-12-08 05:30:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
u32 CVolumeGC::GetFSTSize() const
|
|
|
|
{
|
|
|
|
if (m_pReader == NULL)
|
2010-08-13 19:07:59 +00:00
|
|
|
return 0;
|
2008-12-08 05:30:24 +00:00
|
|
|
|
|
|
|
u32 size;
|
|
|
|
if (!Read(0x428, 0x4, (u8*)&size))
|
2010-08-13 19:07:59 +00:00
|
|
|
return 0;
|
2008-12-08 05:30:24 +00:00
|
|
|
|
|
|
|
return Common::swap32(size);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string CVolumeGC::GetApploaderDate() const
|
|
|
|
{
|
|
|
|
if (m_pReader == NULL)
|
2010-08-13 19:07:59 +00:00
|
|
|
return std::string();
|
2008-12-08 05:30:24 +00:00
|
|
|
|
|
|
|
char date[16];
|
|
|
|
if (!Read(0x2440, 0x10, (u8*)&date))
|
2010-08-13 19:07:59 +00:00
|
|
|
return std::string();
|
2008-12-08 05:30:24 +00:00
|
|
|
// Should be 0 already, but just in case
|
2010-08-13 19:07:59 +00:00
|
|
|
date[10] = '\0';
|
2008-12-08 05:30:24 +00:00
|
|
|
|
|
|
|
return date;
|
|
|
|
}
|
|
|
|
|
|
|
|
u64 CVolumeGC::GetSize() const
|
|
|
|
{
|
|
|
|
if (m_pReader)
|
2010-12-03 12:42:01 +00:00
|
|
|
return m_pReader->GetDataSize();
|
2008-12-08 05:30:24 +00:00
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-04-09 17:58:56 +00:00
|
|
|
u64 CVolumeGC::GetRawSize() const
|
|
|
|
{
|
|
|
|
if (m_pReader)
|
|
|
|
return m_pReader->GetRawSize();
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-01-26 02:28:04 +00:00
|
|
|
bool CVolumeGC::IsDiscTwo() const
|
|
|
|
{
|
|
|
|
bool discTwo;
|
|
|
|
Read(6,1, (u8*) &discTwo);
|
|
|
|
return discTwo;
|
|
|
|
}
|
|
|
|
|
2013-03-03 22:51:26 +00:00
|
|
|
auto CVolumeGC::GetStringDecoder(ECountry country) -> StringDecoder
|
|
|
|
{
|
|
|
|
return (COUNTRY_JAPAN == country || COUNTRY_TAIWAN == country) ?
|
|
|
|
SHIFTJISToUTF8 : CP1252ToUTF8;
|
|
|
|
}
|
|
|
|
|
2008-12-08 05:30:24 +00:00
|
|
|
} // namespace
|