Play-/tools/PsfPlayer/Source/PsfArchive.cpp

47 lines
978 B
C++
Raw Permalink Normal View History

#include "PsfArchive.h"
2018-07-26 09:44:47 -04:00
#ifdef RAR_SUPPORT
#include "PsfRarArchive.h"
2018-07-26 09:44:47 -04:00
#endif
#include "PsfZipArchive.h"
#include "stricmp.h"
2016-11-17 23:29:47 -05:00
#include "make_unique.h"
2019-10-31 13:02:44 -04:00
CPsfArchive::PsfArchivePtr CPsfArchive::CreateFromPath(const fs::path& filePath)
{
2016-11-13 11:01:10 -05:00
auto extension = filePath.extension().string();
PsfArchivePtr result;
if(!strcmp(extension.c_str(), ".zip"))
{
2016-11-13 11:01:10 -05:00
result = std::make_unique<CPsfZipArchive>();
}
#ifdef RAR_SUPPORT
else if(!strcmp(extension.c_str(), ".rar"))
{
2016-11-13 11:01:10 -05:00
result = std::make_unique<CPsfRarArchive>();
}
#endif
else
{
throw std::runtime_error("Unsupported archive type.");
}
result->Open(filePath);
return result;
}
const CPsfArchive::FileList& CPsfArchive::GetFiles() const
{
return m_files;
}
const CPsfArchive::FILEINFO* CPsfArchive::GetFileInfo(const char* path) const
{
for(const auto& fileInfo : m_files)
{
if(!stricmp(fileInfo.name.c_str(), path))
{
return &fileInfo;
}
}
return nullptr;
}