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
|
|
|
|
2014-02-20 17:47:53 -07:00
|
|
|
#include <cstddef>
|
2015-04-09 09:44:53 -06:00
|
|
|
#include <map>
|
2014-08-31 07:34:58 -06:00
|
|
|
#include <memory>
|
2014-02-20 17:47:53 -07:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
2014-09-07 19:06:58 -06:00
|
|
|
#include "Common/CommonTypes.h"
|
2014-02-17 03:18:15 -07:00
|
|
|
#include "Common/StringUtil.h"
|
2014-02-20 17:47:53 -07:00
|
|
|
#include "DiscIO/Blob.h"
|
2014-02-17 03:18:15 -07:00
|
|
|
#include "DiscIO/FileMonitor.h"
|
2014-02-20 17:47:53 -07:00
|
|
|
#include "DiscIO/Volume.h"
|
2014-02-17 03:18:15 -07:00
|
|
|
#include "DiscIO/VolumeGC.h"
|
2009-01-03 11:50:01 -07:00
|
|
|
|
2008-12-07 22:30:24 -07:00
|
|
|
namespace DiscIO
|
|
|
|
{
|
|
|
|
CVolumeGC::CVolumeGC(IBlobReader* _pReader)
|
|
|
|
: m_pReader(_pReader)
|
|
|
|
{}
|
|
|
|
|
|
|
|
CVolumeGC::~CVolumeGC()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-12-28 02:35:48 -07:00
|
|
|
bool CVolumeGC::Read(u64 _Offset, u64 _Length, u8* _pBuffer, bool decrypt) const
|
2008-12-07 22:30:24 -07:00
|
|
|
{
|
2014-12-28 02:35:48 -07:00
|
|
|
if (decrypt)
|
|
|
|
PanicAlertT("Tried to decrypt data from a non-Wii volume");
|
|
|
|
|
2014-03-09 14:14:26 -06:00
|
|
|
if (m_pReader == nullptr)
|
2008-12-07 22:30:24 -07:00
|
|
|
return false;
|
2009-07-02 21:26:23 -06:00
|
|
|
|
2009-09-03 14:00:09 -06:00
|
|
|
FileMon::FindFilename(_Offset);
|
|
|
|
|
2008-12-07 22:30:24 -07:00
|
|
|
return m_pReader->Read(_Offset, _Length, _pBuffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string CVolumeGC::GetUniqueID() const
|
|
|
|
{
|
|
|
|
static const std::string NO_UID("NO_UID");
|
2014-03-09 14:14:26 -06:00
|
|
|
if (m_pReader == nullptr)
|
2008-12-07 22:30:24 -07:00
|
|
|
return NO_UID;
|
|
|
|
|
2011-01-30 10:58:02 -07:00
|
|
|
char ID[7];
|
|
|
|
|
|
|
|
if (!Read(0, sizeof(ID), reinterpret_cast<u8*>(ID)))
|
2008-12-07 22:30:24 -07:00
|
|
|
{
|
2011-01-12 19:05:58 -07:00
|
|
|
PanicAlertT("Failed to read unique ID from disc image");
|
2008-12-07 22:30:24 -07:00
|
|
|
return NO_UID;
|
|
|
|
}
|
|
|
|
|
2011-01-30 10:58:02 -07:00
|
|
|
ID[6] = '\0';
|
|
|
|
|
|
|
|
return ID;
|
2008-12-07 22:30:24 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
IVolume::ECountry CVolumeGC::GetCountry() const
|
|
|
|
{
|
|
|
|
if (!m_pReader)
|
|
|
|
return COUNTRY_UNKNOWN;
|
|
|
|
|
2015-02-23 18:43:29 -07:00
|
|
|
u8 country_code;
|
|
|
|
m_pReader->Read(3, 1, &country_code);
|
2008-12-07 22:30:24 -07:00
|
|
|
|
2015-02-23 18:43:29 -07:00
|
|
|
return CountrySwitch(country_code);
|
2008-12-07 22:30:24 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string CVolumeGC::GetMakerID() const
|
|
|
|
{
|
2014-03-09 14:14:26 -06:00
|
|
|
if (m_pReader == nullptr)
|
2010-08-13 13:07:59 -06:00
|
|
|
return std::string();
|
2008-12-07 22:30:24 -07:00
|
|
|
|
|
|
|
char makerID[3];
|
|
|
|
if (!Read(0x4, 0x2, (u8*)&makerID))
|
2010-08-13 13:07:59 -06:00
|
|
|
return std::string();
|
|
|
|
makerID[2] = '\0';
|
2008-12-07 22:30:24 -07:00
|
|
|
|
|
|
|
return makerID;
|
|
|
|
}
|
|
|
|
|
2013-04-16 21:29:01 -06:00
|
|
|
int CVolumeGC::GetRevision() const
|
|
|
|
{
|
|
|
|
if (!m_pReader)
|
|
|
|
return 0;
|
|
|
|
|
2014-11-14 18:59:39 -07:00
|
|
|
u8 revision;
|
|
|
|
if (!Read(7, 1, &revision))
|
2013-04-16 21:29:01 -06:00
|
|
|
return 0;
|
|
|
|
|
2014-11-14 18:59:39 -07:00
|
|
|
return revision;
|
2013-04-16 21:29:01 -06:00
|
|
|
}
|
|
|
|
|
2015-04-09 09:44:53 -06:00
|
|
|
std::map<IVolume::ELanguage, std::string> CVolumeGC::GetNames() const
|
2008-12-07 22:30:24 -07:00
|
|
|
{
|
2015-04-09 09:44:53 -06:00
|
|
|
std::map<IVolume::ELanguage, std::string> names;
|
2013-10-28 23:23:17 -06:00
|
|
|
|
2013-03-03 15:51:26 -07:00
|
|
|
auto const string_decoder = GetStringDecoder(GetCountry());
|
2008-12-07 22:30:24 -07:00
|
|
|
|
2013-03-03 15:51:26 -07:00
|
|
|
char name[0x60 + 1] = {};
|
2014-03-09 14:14:26 -06:00
|
|
|
if (m_pReader != nullptr && Read(0x20, 0x60, (u8*)name))
|
2015-04-09 09:44:53 -06:00
|
|
|
names[IVolume::ELanguage::LANGUAGE_UNKNOWN] = string_decoder(name);
|
2008-12-07 22:30:24 -07:00
|
|
|
|
2013-03-02 18:46:55 -07:00
|
|
|
return names;
|
2008-12-07 22:30:24 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
u32 CVolumeGC::GetFSTSize() const
|
|
|
|
{
|
2014-03-09 14:14:26 -06:00
|
|
|
if (m_pReader == nullptr)
|
2010-08-13 13:07:59 -06:00
|
|
|
return 0;
|
2008-12-07 22:30:24 -07:00
|
|
|
|
|
|
|
u32 size;
|
|
|
|
if (!Read(0x428, 0x4, (u8*)&size))
|
2010-08-13 13:07:59 -06:00
|
|
|
return 0;
|
2008-12-07 22:30:24 -07:00
|
|
|
|
|
|
|
return Common::swap32(size);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string CVolumeGC::GetApploaderDate() const
|
|
|
|
{
|
2014-03-09 14:14:26 -06:00
|
|
|
if (m_pReader == nullptr)
|
2010-08-13 13:07:59 -06:00
|
|
|
return std::string();
|
2008-12-07 22:30:24 -07:00
|
|
|
|
|
|
|
char date[16];
|
|
|
|
if (!Read(0x2440, 0x10, (u8*)&date))
|
2010-08-13 13:07:59 -06:00
|
|
|
return std::string();
|
2008-12-07 22:30:24 -07:00
|
|
|
// Should be 0 already, but just in case
|
2010-08-13 13:07:59 -06:00
|
|
|
date[10] = '\0';
|
2008-12-07 22:30:24 -07:00
|
|
|
|
|
|
|
return date;
|
|
|
|
}
|
|
|
|
|
|
|
|
u64 CVolumeGC::GetSize() const
|
|
|
|
{
|
|
|
|
if (m_pReader)
|
2010-12-03 05:42:01 -07:00
|
|
|
return m_pReader->GetDataSize();
|
2008-12-07 22:30:24 -07:00
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-04-09 11:58:56 -06:00
|
|
|
u64 CVolumeGC::GetRawSize() const
|
|
|
|
{
|
|
|
|
if (m_pReader)
|
|
|
|
return m_pReader->GetRawSize();
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-01-25 19:28:04 -07:00
|
|
|
bool CVolumeGC::IsDiscTwo() const
|
|
|
|
{
|
2015-02-28 20:03:53 -07:00
|
|
|
u8 disc_two_check;
|
|
|
|
Read(6, 1, &disc_two_check);
|
|
|
|
return (disc_two_check == 1);
|
2013-01-25 19:28:04 -07:00
|
|
|
}
|
|
|
|
|
2014-10-07 19:15:14 -06:00
|
|
|
CVolumeGC::StringDecoder CVolumeGC::GetStringDecoder(ECountry country)
|
2013-03-03 15:51:26 -07:00
|
|
|
{
|
|
|
|
return (COUNTRY_JAPAN == country || COUNTRY_TAIWAN == country) ?
|
|
|
|
SHIFTJISToUTF8 : CP1252ToUTF8;
|
|
|
|
}
|
|
|
|
|
2008-12-07 22:30:24 -07:00
|
|
|
} // namespace
|