2013-04-17 22:43:11 -04:00
|
|
|
// Copyright 2013 Dolphin Emulator Project
|
|
|
|
// Licensed under GPLv2
|
|
|
|
// Refer to the license.txt file included.
|
2008-12-08 05:30:24 +00:00
|
|
|
|
2014-09-18 23:17:41 -05:00
|
|
|
#include "Common/CommonFuncs.h"
|
2014-02-17 05:18:15 -05:00
|
|
|
#include "Core/VolumeHandler.h"
|
|
|
|
#include "DiscIO/VolumeCreator.h"
|
2008-12-08 05:30:24 +00:00
|
|
|
|
|
|
|
namespace VolumeHandler
|
|
|
|
{
|
|
|
|
|
2014-07-08 15:58:25 +02:00
|
|
|
static DiscIO::IVolume* g_pVolume = nullptr;
|
2008-12-08 05:30:24 +00:00
|
|
|
|
2010-04-08 16:59:35 +00:00
|
|
|
DiscIO::IVolume *GetVolume()
|
|
|
|
{
|
2008-12-08 05:30:24 +00:00
|
|
|
return g_pVolume;
|
|
|
|
}
|
|
|
|
|
2013-10-29 01:23:17 -04:00
|
|
|
void EjectVolume()
|
2009-06-08 00:14:48 +00:00
|
|
|
{
|
|
|
|
if (g_pVolume)
|
|
|
|
{
|
|
|
|
// This code looks scary. Can the try/catch stuff be removed?
|
|
|
|
// This cause a "Unhandled exception ... Access violation
|
|
|
|
// reading location ..." after you have started and stopped two
|
|
|
|
// or three games
|
|
|
|
delete g_pVolume;
|
2014-03-09 21:14:26 +01:00
|
|
|
g_pVolume = nullptr;
|
2009-06-08 00:14:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-23 08:47:37 +00:00
|
|
|
bool SetVolumeName(const std::string& _rFullPath)
|
2008-12-08 05:30:24 +00:00
|
|
|
{
|
2013-04-16 23:14:36 -04:00
|
|
|
if (g_pVolume)
|
|
|
|
{
|
|
|
|
delete g_pVolume;
|
2014-03-09 21:14:26 +01:00
|
|
|
g_pVolume = nullptr;
|
2013-04-16 23:14:36 -04:00
|
|
|
}
|
2008-12-08 05:30:24 +00:00
|
|
|
|
2013-04-16 23:14:36 -04:00
|
|
|
g_pVolume = DiscIO::CreateVolumeFromFilename(_rFullPath);
|
2008-12-23 08:47:37 +00:00
|
|
|
|
2014-03-09 21:14:26 +01:00
|
|
|
return (g_pVolume != nullptr);
|
2008-12-08 05:30:24 +00:00
|
|
|
}
|
|
|
|
|
2009-12-10 09:16:10 +00:00
|
|
|
void SetVolumeDirectory(const std::string& _rFullPath, bool _bIsWii, const std::string& _rApploader, const std::string& _rDOL)
|
2008-12-08 05:30:24 +00:00
|
|
|
{
|
2013-04-16 23:14:36 -04:00
|
|
|
if (g_pVolume)
|
|
|
|
{
|
|
|
|
delete g_pVolume;
|
2014-03-09 21:14:26 +01:00
|
|
|
g_pVolume = nullptr;
|
2013-04-16 23:14:36 -04:00
|
|
|
}
|
2008-12-08 05:30:24 +00:00
|
|
|
|
2013-04-16 23:14:36 -04:00
|
|
|
g_pVolume = DiscIO::CreateVolumeFromDirectory(_rFullPath, _bIsWii, _rApploader, _rDOL);
|
2008-12-08 05:30:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
u32 Read32(u64 _Offset)
|
|
|
|
{
|
2014-03-09 21:14:26 +01:00
|
|
|
if (g_pVolume != nullptr)
|
2013-04-16 23:14:36 -04:00
|
|
|
{
|
|
|
|
u32 Temp;
|
|
|
|
g_pVolume->Read(_Offset, 4, (u8*)&Temp);
|
|
|
|
return Common::swap32(Temp);
|
|
|
|
}
|
|
|
|
return 0;
|
2008-12-08 05:30:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ReadToPtr(u8* ptr, u64 _dwOffset, u64 _dwLength)
|
|
|
|
{
|
2014-03-09 21:14:26 +01:00
|
|
|
if (g_pVolume != nullptr && ptr)
|
2013-04-16 23:14:36 -04:00
|
|
|
{
|
|
|
|
g_pVolume->Read(_dwOffset, _dwLength, ptr);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2008-12-08 05:30:24 +00:00
|
|
|
}
|
|
|
|
|
2009-02-22 13:59:06 +00:00
|
|
|
bool RAWReadToPtr( u8* ptr, u64 _dwOffset, u64 _dwLength )
|
|
|
|
{
|
2014-03-09 21:14:26 +01:00
|
|
|
if (g_pVolume != nullptr && ptr)
|
2009-02-22 13:59:06 +00:00
|
|
|
{
|
|
|
|
g_pVolume->RAWRead(_dwOffset, _dwLength, ptr);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-12-08 05:30:24 +00:00
|
|
|
bool IsValid()
|
|
|
|
{
|
2014-03-09 21:14:26 +01:00
|
|
|
return (g_pVolume != nullptr);
|
2008-12-08 05:30:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool IsWii()
|
|
|
|
{
|
|
|
|
if (g_pVolume)
|
|
|
|
return IsVolumeWiiDisc(g_pVolume);
|
|
|
|
|
2013-04-16 23:14:36 -04:00
|
|
|
return false;
|
2008-12-08 05:30:24 +00:00
|
|
|
}
|
|
|
|
|
2010-04-08 16:59:35 +00:00
|
|
|
} // end of namespace VolumeHandler
|