nod/lib/nod.cpp

75 lines
1.8 KiB
C++
Raw Normal View History

2015-06-28 05:43:53 +00:00
#include <stdio.h>
2016-03-04 23:04:30 +00:00
#include "nod/nod.hpp"
#include "nod/DiscBase.hpp"
2015-06-28 05:43:53 +00:00
2016-03-04 23:04:30 +00:00
namespace nod
2015-06-28 05:43:53 +00:00
{
2016-03-04 23:04:30 +00:00
logvisor::Module LogModule("nod");
2015-07-02 18:33:55 +00:00
std::unique_ptr<IDiscIO> NewDiscIOISO(const SystemChar* path);
std::unique_ptr<IDiscIO> NewDiscIOWBFS(const SystemChar* path);
2015-06-28 05:43:53 +00:00
2015-07-02 18:33:55 +00:00
std::unique_ptr<DiscBase> OpenDiscFromImage(const SystemChar* path, bool& isWii)
2015-06-28 05:43:53 +00:00
{
/* Temporary file handle to determine image type */
2016-01-25 05:55:31 +00:00
std::unique_ptr<IFileIO> fio = NewFileIO(path);
if (!fio->exists())
2015-06-28 05:43:53 +00:00
{
2016-03-04 23:04:30 +00:00
LogModule.report(logvisor::Error, _S("Unable to open '%s'"), path);
2015-06-28 05:43:53 +00:00
return std::unique_ptr<DiscBase>();
}
2016-01-25 05:55:31 +00:00
std::unique_ptr<IFileIO::IReadStream> rs = fio->beginReadStream();
2015-06-28 05:43:53 +00:00
isWii = false;
std::unique_ptr<IDiscIO> discIO;
2016-01-25 05:55:31 +00:00
uint32_t magic = 0;
if (rs->read(&magic, 4) != 4)
2016-03-04 23:04:30 +00:00
LogModule.report(logvisor::Fatal, _S("Unable to read magic from '%s'"), path);
2016-01-25 05:55:31 +00:00
2016-03-04 23:04:30 +00:00
if (magic == nod::SBig((uint32_t)'WBFS'))
2015-06-28 05:43:53 +00:00
{
discIO = NewDiscIOWBFS(path);
isWii = true;
}
else
{
2016-01-25 05:55:31 +00:00
rs->seek(0x18, SEEK_SET);
rs->read(&magic, 4);
2016-03-04 23:04:30 +00:00
magic = nod::SBig(magic);
2015-06-28 05:43:53 +00:00
if (magic == 0x5D1C9EA3)
{
discIO = NewDiscIOISO(path);
isWii = true;
}
else
{
2016-01-25 05:55:31 +00:00
rs->read(&magic, 4);
2016-03-04 23:04:30 +00:00
magic = nod::SBig(magic);
2015-06-28 05:43:53 +00:00
if (magic == 0xC2339F3D)
discIO = NewDiscIOISO(path);
}
}
if (!discIO)
{
2016-03-04 23:04:30 +00:00
LogModule.report(logvisor::Error, _S("'%s' is not a valid image"), path);
2015-06-28 05:43:53 +00:00
return std::unique_ptr<DiscBase>();
}
if (isWii)
return std::unique_ptr<DiscBase>(new DiscWii(std::move(discIO)));
return std::unique_ptr<DiscBase>(new DiscGCN(std::move(discIO)));
}
2015-07-02 18:33:55 +00:00
std::unique_ptr<DiscBase> OpenDiscFromImage(const SystemChar* path)
2015-06-29 08:59:54 +00:00
{
bool isWii;
return OpenDiscFromImage(path, isWii);
}
2015-06-28 05:43:53 +00:00
}