2015-05-24 06:55:12 +02:00
|
|
|
// Copyright 2008 Dolphin Emulator Project
|
2015-05-18 01:08:10 +02:00
|
|
|
// Licensed under GPLv2+
|
2013-04-17 23:09:55 -04:00
|
|
|
// Refer to the license.txt file included.
|
2008-12-08 05:30:24 +00:00
|
|
|
|
2014-02-21 01:47:53 +01:00
|
|
|
#include <cstddef>
|
|
|
|
#include <cstring>
|
2015-08-31 19:27:18 -04:00
|
|
|
#include <memory>
|
2014-02-21 01:47:53 +01:00
|
|
|
#include <string>
|
2015-08-31 19:27:18 -04:00
|
|
|
#include <utility>
|
2008-12-08 05:30:24 +00:00
|
|
|
#include <vector>
|
|
|
|
|
2014-09-07 20:06:58 -05:00
|
|
|
#include "Common/CommonTypes.h"
|
2015-09-26 17:13:07 -04:00
|
|
|
#include "Common/Logging/Log.h"
|
2016-06-24 10:43:46 +02:00
|
|
|
#include "Common/StringUtil.h"
|
2014-02-21 01:47:53 +01:00
|
|
|
#include "DiscIO/Blob.h"
|
2014-02-17 05:18:15 -05:00
|
|
|
#include "DiscIO/Volume.h"
|
2014-07-08 14:29:26 +02:00
|
|
|
#include "DiscIO/VolumeCreator.h"
|
2014-02-17 05:18:15 -05:00
|
|
|
#include "DiscIO/VolumeDirectory.h"
|
|
|
|
#include "DiscIO/VolumeGC.h"
|
|
|
|
#include "DiscIO/VolumeWad.h"
|
|
|
|
#include "DiscIO/VolumeWiiCrypted.h"
|
2008-12-08 05:30:24 +00:00
|
|
|
|
|
|
|
namespace DiscIO
|
|
|
|
{
|
|
|
|
enum EDiscType
|
|
|
|
{
|
2016-06-24 10:43:46 +02:00
|
|
|
DISC_TYPE_UNK,
|
|
|
|
DISC_TYPE_WII,
|
|
|
|
DISC_TYPE_WII_CONTAINER,
|
|
|
|
DISC_TYPE_GC,
|
|
|
|
DISC_TYPE_WAD
|
2008-12-08 05:30:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
EDiscType GetDiscType(IBlobReader& _rReader);
|
|
|
|
|
2015-06-13 12:51:24 +02:00
|
|
|
std::unique_ptr<IVolume> CreateVolumeFromFilename(const std::string& filename)
|
2008-12-08 05:30:24 +00:00
|
|
|
{
|
2016-06-24 10:43:46 +02:00
|
|
|
std::unique_ptr<IBlobReader> reader(CreateBlobReader(filename));
|
|
|
|
if (reader == nullptr)
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
switch (GetDiscType(*reader))
|
|
|
|
{
|
|
|
|
case DISC_TYPE_WII:
|
|
|
|
case DISC_TYPE_GC:
|
|
|
|
return std::make_unique<CVolumeGC>(std::move(reader));
|
|
|
|
|
|
|
|
case DISC_TYPE_WAD:
|
|
|
|
return std::make_unique<CVolumeWAD>(std::move(reader));
|
|
|
|
|
|
|
|
case DISC_TYPE_WII_CONTAINER:
|
2015-06-13 12:51:24 +02:00
|
|
|
return std::make_unique<CVolumeWiiCrypted>(std::move(reader));
|
2016-06-24 10:43:46 +02:00
|
|
|
|
|
|
|
case DISC_TYPE_UNK:
|
2016-10-29 13:08:24 +02:00
|
|
|
return nullptr;
|
2016-06-24 10:43:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
2008-12-08 05:30:24 +00:00
|
|
|
}
|
|
|
|
|
2016-06-24 10:43:46 +02:00
|
|
|
std::unique_ptr<IVolume> CreateVolumeFromDirectory(const std::string& directory, bool is_wii,
|
|
|
|
const std::string& apploader,
|
|
|
|
const std::string& dol)
|
2008-12-08 05:30:24 +00:00
|
|
|
{
|
2016-06-24 10:43:46 +02:00
|
|
|
if (CVolumeDirectory::IsValidDirectory(directory))
|
|
|
|
return std::make_unique<CVolumeDirectory>(directory, is_wii, apploader, dol);
|
2013-10-29 01:23:17 -04:00
|
|
|
|
2016-06-24 10:43:46 +02:00
|
|
|
return nullptr;
|
2008-12-08 05:30:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
EDiscType GetDiscType(IBlobReader& _rReader)
|
|
|
|
{
|
2016-06-24 10:43:46 +02:00
|
|
|
CBlobBigEndianReader Reader(_rReader);
|
|
|
|
|
|
|
|
// Check for Wii
|
|
|
|
u32 WiiMagic = 0;
|
|
|
|
Reader.ReadSwapped(0x18, &WiiMagic);
|
|
|
|
u32 WiiContainerMagic = 0;
|
|
|
|
Reader.ReadSwapped(0x60, &WiiContainerMagic);
|
|
|
|
if (WiiMagic == 0x5D1C9EA3 && WiiContainerMagic != 0)
|
|
|
|
return DISC_TYPE_WII;
|
|
|
|
if (WiiMagic == 0x5D1C9EA3 && WiiContainerMagic == 0)
|
|
|
|
return DISC_TYPE_WII_CONTAINER;
|
|
|
|
|
|
|
|
// Check for WAD
|
|
|
|
// 0x206962 for boot2 wads
|
|
|
|
u32 WADMagic = 0;
|
|
|
|
Reader.ReadSwapped(0x02, &WADMagic);
|
|
|
|
if (WADMagic == 0x00204973 || WADMagic == 0x00206962)
|
|
|
|
return DISC_TYPE_WAD;
|
|
|
|
|
|
|
|
// Check for GC
|
|
|
|
u32 GCMagic = 0;
|
|
|
|
Reader.ReadSwapped(0x1C, &GCMagic);
|
|
|
|
if (GCMagic == 0xC2339F3D)
|
|
|
|
return DISC_TYPE_GC;
|
|
|
|
|
2016-10-29 13:08:24 +02:00
|
|
|
// No known magic words found
|
2016-06-24 10:43:46 +02:00
|
|
|
return DISC_TYPE_UNK;
|
2008-12-08 05:30:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|