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