fix 2 more warnings for vs2013.
parent
2eb8ff7136
commit
d1afd97ec2
|
@ -4,7 +4,6 @@ Open Asset Import Library (assimp)
|
||||||
|
|
||||||
Copyright (c) 2006-2020, assimp team
|
Copyright (c) 2006-2020, assimp team
|
||||||
|
|
||||||
|
|
||||||
All rights reserved.
|
All rights reserved.
|
||||||
|
|
||||||
Redistribution and use of this software in source and binary forms,
|
Redistribution and use of this software in source and binary forms,
|
||||||
|
@ -44,8 +43,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
* @brief Zip File I/O implementation for #Importer
|
* @brief Zip File I/O implementation for #Importer
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <assimp/ZipArchiveIOSystem.h>
|
|
||||||
#include <assimp/BaseImporter.h>
|
#include <assimp/BaseImporter.h>
|
||||||
|
#include <assimp/ZipArchiveIOSystem.h>
|
||||||
|
|
||||||
#include <assimp/ai_assert.h>
|
#include <assimp/ai_assert.h>
|
||||||
|
|
||||||
|
@ -59,32 +58,31 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace Assimp {
|
namespace Assimp {
|
||||||
// ----------------------------------------------------------------
|
|
||||||
// Wraps an existing Assimp::IOSystem for unzip
|
// ----------------------------------------------------------------
|
||||||
class IOSystem2Unzip {
|
// Wraps an existing Assimp::IOSystem for unzip
|
||||||
public:
|
class IOSystem2Unzip {
|
||||||
static voidpf open(voidpf opaque, const char* filename, int mode);
|
public:
|
||||||
static uLong read(voidpf opaque, voidpf stream, void* buf, uLong size);
|
static voidpf open(voidpf opaque, const char *filename, int mode);
|
||||||
static uLong write(voidpf opaque, voidpf stream, const void* buf, uLong size);
|
static uLong read(voidpf opaque, voidpf stream, void *buf, uLong size);
|
||||||
|
static uLong write(voidpf opaque, voidpf stream, const void *buf, uLong size);
|
||||||
static long tell(voidpf opaque, voidpf stream);
|
static long tell(voidpf opaque, voidpf stream);
|
||||||
static long seek(voidpf opaque, voidpf stream, uLong offset, int origin);
|
static long seek(voidpf opaque, voidpf stream, uLong offset, int origin);
|
||||||
static int close(voidpf opaque, voidpf stream);
|
static int close(voidpf opaque, voidpf stream);
|
||||||
static int testerror(voidpf opaque, voidpf stream);
|
static int testerror(voidpf opaque, voidpf stream);
|
||||||
static zlib_filefunc_def get(IOSystem* pIOHandler);
|
static zlib_filefunc_def get(IOSystem *pIOHandler);
|
||||||
};
|
};
|
||||||
|
|
||||||
voidpf IOSystem2Unzip::open(voidpf opaque, const char* filename, int mode) {
|
voidpf IOSystem2Unzip::open(voidpf opaque, const char *filename, int mode) {
|
||||||
IOSystem* io_system = reinterpret_cast<IOSystem*>(opaque);
|
IOSystem *io_system = reinterpret_cast<IOSystem *>(opaque);
|
||||||
|
|
||||||
const char* mode_fopen = nullptr;
|
const char *mode_fopen = nullptr;
|
||||||
if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER) == ZLIB_FILEFUNC_MODE_READ) {
|
if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER) == ZLIB_FILEFUNC_MODE_READ) {
|
||||||
mode_fopen = "rb";
|
mode_fopen = "rb";
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
if (mode & ZLIB_FILEFUNC_MODE_EXISTING) {
|
if (mode & ZLIB_FILEFUNC_MODE_EXISTING) {
|
||||||
mode_fopen = "r+b";
|
mode_fopen = "r+b";
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
if (mode & ZLIB_FILEFUNC_MODE_CREATE) {
|
if (mode & ZLIB_FILEFUNC_MODE_CREATE) {
|
||||||
mode_fopen = "wb";
|
mode_fopen = "wb";
|
||||||
}
|
}
|
||||||
|
@ -92,28 +90,28 @@ namespace Assimp {
|
||||||
}
|
}
|
||||||
|
|
||||||
return (voidpf)io_system->Open(filename, mode_fopen);
|
return (voidpf)io_system->Open(filename, mode_fopen);
|
||||||
}
|
}
|
||||||
|
|
||||||
uLong IOSystem2Unzip::read(voidpf /*opaque*/, voidpf stream, void* buf, uLong size) {
|
uLong IOSystem2Unzip::read(voidpf /*opaque*/, voidpf stream, void *buf, uLong size) {
|
||||||
IOStream* io_stream = (IOStream*)stream;
|
IOStream *io_stream = (IOStream *)stream;
|
||||||
|
|
||||||
return static_cast<uLong>(io_stream->Read(buf, 1, size));
|
return static_cast<uLong>(io_stream->Read(buf, 1, size));
|
||||||
}
|
}
|
||||||
|
|
||||||
uLong IOSystem2Unzip::write(voidpf /*opaque*/, voidpf stream, const void* buf, uLong size) {
|
uLong IOSystem2Unzip::write(voidpf /*opaque*/, voidpf stream, const void *buf, uLong size) {
|
||||||
IOStream* io_stream = (IOStream*)stream;
|
IOStream *io_stream = (IOStream *)stream;
|
||||||
|
|
||||||
return static_cast<uLong>(io_stream->Write(buf, 1, size));
|
return static_cast<uLong>(io_stream->Write(buf, 1, size));
|
||||||
}
|
}
|
||||||
|
|
||||||
long IOSystem2Unzip::tell(voidpf /*opaque*/, voidpf stream) {
|
long IOSystem2Unzip::tell(voidpf /*opaque*/, voidpf stream) {
|
||||||
IOStream* io_stream = (IOStream*)stream;
|
IOStream *io_stream = (IOStream *)stream;
|
||||||
|
|
||||||
return static_cast<long>(io_stream->Tell());
|
return static_cast<long>(io_stream->Tell());
|
||||||
}
|
}
|
||||||
|
|
||||||
long IOSystem2Unzip::seek(voidpf /*opaque*/, voidpf stream, uLong offset, int origin) {
|
long IOSystem2Unzip::seek(voidpf /*opaque*/, voidpf stream, uLong offset, int origin) {
|
||||||
IOStream* io_stream = (IOStream*)stream;
|
IOStream *io_stream = (IOStream *)stream;
|
||||||
|
|
||||||
aiOrigin assimp_origin;
|
aiOrigin assimp_origin;
|
||||||
switch (origin) {
|
switch (origin) {
|
||||||
|
@ -130,22 +128,22 @@ namespace Assimp {
|
||||||
}
|
}
|
||||||
|
|
||||||
return (io_stream->Seek(offset, assimp_origin) == aiReturn_SUCCESS ? 0 : -1);
|
return (io_stream->Seek(offset, assimp_origin) == aiReturn_SUCCESS ? 0 : -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int IOSystem2Unzip::close(voidpf opaque, voidpf stream) {
|
int IOSystem2Unzip::close(voidpf opaque, voidpf stream) {
|
||||||
IOSystem* io_system = (IOSystem*)opaque;
|
IOSystem *io_system = (IOSystem *)opaque;
|
||||||
IOStream* io_stream = (IOStream*)stream;
|
IOStream *io_stream = (IOStream *)stream;
|
||||||
|
|
||||||
io_system->Close(io_stream);
|
io_system->Close(io_stream);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int IOSystem2Unzip::testerror(voidpf /*opaque*/, voidpf /*stream*/) {
|
int IOSystem2Unzip::testerror(voidpf /*opaque*/, voidpf /*stream*/) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
zlib_filefunc_def IOSystem2Unzip::get(IOSystem* pIOHandler) {
|
zlib_filefunc_def IOSystem2Unzip::get(IOSystem *pIOHandler) {
|
||||||
zlib_filefunc_def mapping;
|
zlib_filefunc_def mapping;
|
||||||
|
|
||||||
#ifdef ASSIMP_USE_HUNTER
|
#ifdef ASSIMP_USE_HUNTER
|
||||||
|
@ -168,59 +166,58 @@ namespace Assimp {
|
||||||
mapping.opaque = reinterpret_cast<voidpf>(pIOHandler);
|
mapping.opaque = reinterpret_cast<voidpf>(pIOHandler);
|
||||||
|
|
||||||
return mapping;
|
return mapping;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------
|
// ----------------------------------------------------------------
|
||||||
// A read-only file inside a ZIP
|
// A read-only file inside a ZIP
|
||||||
|
|
||||||
class ZipFile : public IOStream {
|
class ZipFile : public IOStream {
|
||||||
friend class ZipFileInfo;
|
friend class ZipFileInfo;
|
||||||
explicit ZipFile(size_t size);
|
explicit ZipFile(size_t size);
|
||||||
public:
|
|
||||||
|
public:
|
||||||
virtual ~ZipFile();
|
virtual ~ZipFile();
|
||||||
|
|
||||||
// IOStream interface
|
// IOStream interface
|
||||||
size_t Read(void* pvBuffer, size_t pSize, size_t pCount) override;
|
size_t Read(void *pvBuffer, size_t pSize, size_t pCount) override;
|
||||||
size_t Write(const void* /*pvBuffer*/, size_t /*pSize*/, size_t /*pCount*/) override { return 0; }
|
size_t Write(const void * /*pvBuffer*/, size_t /*pSize*/, size_t /*pCount*/) override { return 0; }
|
||||||
size_t FileSize() const override;
|
size_t FileSize() const override;
|
||||||
aiReturn Seek(size_t pOffset, aiOrigin pOrigin) override;
|
aiReturn Seek(size_t pOffset, aiOrigin pOrigin) override;
|
||||||
size_t Tell() const override;
|
size_t Tell() const override;
|
||||||
void Flush() override {}
|
void Flush() override {}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
size_t m_Size = 0;
|
size_t m_Size = 0;
|
||||||
size_t m_SeekPtr = 0;
|
size_t m_SeekPtr = 0;
|
||||||
std::unique_ptr<uint8_t[]> m_Buffer;
|
std::unique_ptr<uint8_t[]> m_Buffer;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------
|
||||||
// ----------------------------------------------------------------
|
// Info about a read-only file inside a ZIP
|
||||||
// Info about a read-only file inside a ZIP
|
class ZipFileInfo {
|
||||||
class ZipFileInfo
|
public:
|
||||||
{
|
|
||||||
public:
|
|
||||||
explicit ZipFileInfo(unzFile zip_handle, size_t size);
|
explicit ZipFileInfo(unzFile zip_handle, size_t size);
|
||||||
|
|
||||||
// Allocate and Extract data from the ZIP
|
// Allocate and Extract data from the ZIP
|
||||||
ZipFile * Extract(unzFile zip_handle) const;
|
ZipFile *Extract(unzFile zip_handle) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
size_t m_Size = 0;
|
size_t m_Size = 0;
|
||||||
unz_file_pos_s m_ZipFilePos;
|
unz_file_pos_s m_ZipFilePos;
|
||||||
};
|
};
|
||||||
|
|
||||||
ZipFileInfo::ZipFileInfo(unzFile zip_handle, size_t size)
|
ZipFileInfo::ZipFileInfo(unzFile zip_handle, size_t size) :
|
||||||
: m_Size(size) {
|
m_Size(size) {
|
||||||
ai_assert(m_Size != 0);
|
ai_assert(m_Size != 0);
|
||||||
// Workaround for MSVC 2013 - C2797
|
// Workaround for MSVC 2013 - C2797
|
||||||
m_ZipFilePos.num_of_file = 0;
|
m_ZipFilePos.num_of_file = 0;
|
||||||
m_ZipFilePos.pos_in_zip_directory = 0;
|
m_ZipFilePos.pos_in_zip_directory = 0;
|
||||||
unzGetFilePos(zip_handle, &(m_ZipFilePos));
|
unzGetFilePos(zip_handle, &(m_ZipFilePos));
|
||||||
}
|
}
|
||||||
|
|
||||||
ZipFile * ZipFileInfo::Extract(unzFile zip_handle) const {
|
ZipFile *ZipFileInfo::Extract(unzFile zip_handle) const {
|
||||||
// Find in the ZIP. This cannot fail
|
// Find in the ZIP. This cannot fail
|
||||||
unz_file_pos_s *filepos = const_cast<unz_file_pos_s*>(&(m_ZipFilePos));
|
unz_file_pos_s *filepos = const_cast<unz_file_pos_s *>(&(m_ZipFilePos));
|
||||||
if (unzGoToFilePos(zip_handle, filepos) != UNZ_OK)
|
if (unzGoToFilePos(zip_handle, filepos) != UNZ_OK)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
|
@ -229,8 +226,7 @@ namespace Assimp {
|
||||||
|
|
||||||
ZipFile *zip_file = new ZipFile(m_Size);
|
ZipFile *zip_file = new ZipFile(m_Size);
|
||||||
|
|
||||||
if (unzReadCurrentFile(zip_handle, zip_file->m_Buffer.get(), static_cast<unsigned int>(m_Size)) != static_cast<int>(m_Size))
|
if (unzReadCurrentFile(zip_handle, zip_file->m_Buffer.get(), static_cast<unsigned int>(m_Size)) != static_cast<int>(m_Size)) {
|
||||||
{
|
|
||||||
// Failed, release the memory
|
// Failed, release the memory
|
||||||
delete zip_file;
|
delete zip_file;
|
||||||
zip_file = nullptr;
|
zip_file = nullptr;
|
||||||
|
@ -238,26 +234,25 @@ namespace Assimp {
|
||||||
|
|
||||||
ai_assert(unzCloseCurrentFile(zip_handle) == UNZ_OK);
|
ai_assert(unzCloseCurrentFile(zip_handle) == UNZ_OK);
|
||||||
return zip_file;
|
return zip_file;
|
||||||
}
|
}
|
||||||
|
|
||||||
ZipFile::ZipFile(size_t size)
|
ZipFile::ZipFile(size_t size) :
|
||||||
: m_Size(size) {
|
m_Size(size) {
|
||||||
ai_assert(m_Size != 0);
|
ai_assert(m_Size != 0);
|
||||||
m_Buffer = std::unique_ptr<uint8_t[]>(new uint8_t[m_Size]);
|
m_Buffer = std::unique_ptr<uint8_t[]>(new uint8_t[m_Size]);
|
||||||
}
|
}
|
||||||
|
|
||||||
ZipFile::~ZipFile() {
|
ZipFile::~ZipFile() {
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t ZipFile::Read(void* pvBuffer, size_t pSize, size_t pCount) {
|
size_t ZipFile::Read(void *pvBuffer, size_t pSize, size_t pCount) {
|
||||||
// Should be impossible
|
// Should be impossible
|
||||||
ai_assert(m_Buffer != nullptr);
|
ai_assert(m_Buffer != nullptr);
|
||||||
ai_assert(NULL != pvBuffer && 0 != pSize && 0 != pCount);
|
ai_assert(NULL != pvBuffer && 0 != pSize && 0 != pCount);
|
||||||
|
|
||||||
// Clip down to file size
|
// Clip down to file size
|
||||||
size_t byteSize = pSize * pCount;
|
size_t byteSize = pSize * pCount;
|
||||||
if ((byteSize + m_SeekPtr) > m_Size)
|
if ((byteSize + m_SeekPtr) > m_Size) {
|
||||||
{
|
|
||||||
pCount = (m_Size - m_SeekPtr) / pSize;
|
pCount = (m_Size - m_SeekPtr) / pSize;
|
||||||
byteSize = pSize * pCount;
|
byteSize = pSize * pCount;
|
||||||
if (byteSize == 0)
|
if (byteSize == 0)
|
||||||
|
@ -269,15 +264,14 @@ namespace Assimp {
|
||||||
m_SeekPtr += byteSize;
|
m_SeekPtr += byteSize;
|
||||||
|
|
||||||
return pCount;
|
return pCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t ZipFile::FileSize() const {
|
size_t ZipFile::FileSize() const {
|
||||||
return m_Size;
|
return m_Size;
|
||||||
}
|
}
|
||||||
|
|
||||||
aiReturn ZipFile::Seek(size_t pOffset, aiOrigin pOrigin) {
|
aiReturn ZipFile::Seek(size_t pOffset, aiOrigin pOrigin) {
|
||||||
switch (pOrigin)
|
switch (pOrigin) {
|
||||||
{
|
|
||||||
case aiOrigin_SET: {
|
case aiOrigin_SET: {
|
||||||
if (pOffset > m_Size) return aiReturn_FAILURE;
|
if (pOffset > m_Size) return aiReturn_FAILURE;
|
||||||
m_SeekPtr = pOffset;
|
m_SeekPtr = pOffset;
|
||||||
|
@ -299,57 +293,58 @@ namespace Assimp {
|
||||||
}
|
}
|
||||||
|
|
||||||
return aiReturn_FAILURE;
|
return aiReturn_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t ZipFile::Tell() const {
|
size_t ZipFile::Tell() const {
|
||||||
return m_SeekPtr;
|
return m_SeekPtr;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------
|
// ----------------------------------------------------------------
|
||||||
// pImpl of the Zip Archive IO
|
// pImpl of the Zip Archive IO
|
||||||
class ZipArchiveIOSystem::Implement {
|
class ZipArchiveIOSystem::Implement {
|
||||||
public:
|
public:
|
||||||
static const unsigned int FileNameSize = 256;
|
static const unsigned int FileNameSize = 256;
|
||||||
|
|
||||||
Implement(IOSystem* pIOHandler, const char* pFilename, const char* pMode);
|
Implement(IOSystem *pIOHandler, const char *pFilename, const char *pMode);
|
||||||
~Implement();
|
~Implement();
|
||||||
|
|
||||||
bool isOpen() const;
|
bool isOpen() const;
|
||||||
void getFileList(std::vector<std::string>& rFileList);
|
void getFileList(std::vector<std::string> &rFileList);
|
||||||
void getFileListExtension(std::vector<std::string>& rFileList, const std::string& extension);
|
void getFileListExtension(std::vector<std::string> &rFileList, const std::string &extension);
|
||||||
bool Exists(std::string& filename);
|
bool Exists(std::string &filename);
|
||||||
IOStream* OpenFile(std::string& filename);
|
IOStream *OpenFile(std::string &filename);
|
||||||
|
|
||||||
static void SimplifyFilename(std::string& filename);
|
static void SimplifyFilename(std::string &filename);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void MapArchive();
|
void MapArchive();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
typedef std::map<std::string, ZipFileInfo> ZipFileInfoMap;
|
typedef std::map<std::string, ZipFileInfo> ZipFileInfoMap;
|
||||||
|
|
||||||
unzFile m_ZipFileHandle = nullptr;
|
unzFile m_ZipFileHandle = nullptr;
|
||||||
ZipFileInfoMap m_ArchiveMap;
|
ZipFileInfoMap m_ArchiveMap;
|
||||||
};
|
};
|
||||||
|
|
||||||
ZipArchiveIOSystem::Implement::Implement(IOSystem* pIOHandler, const char* pFilename, const char* pMode) {
|
ZipArchiveIOSystem::Implement::Implement(IOSystem *pIOHandler, const char *pFilename, const char *pMode) {
|
||||||
ai_assert(strcmp(pMode, "r") == 0);
|
ai_assert(strcmp(pMode, "r") == 0);
|
||||||
ai_assert(pFilename != nullptr);
|
ai_assert(pFilename != nullptr);
|
||||||
if (pFilename[0] == 0)
|
if (pFilename[0] == 0 || nullptr == pMode) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
zlib_filefunc_def mapping = IOSystem2Unzip::get(pIOHandler);
|
zlib_filefunc_def mapping = IOSystem2Unzip::get(pIOHandler);
|
||||||
m_ZipFileHandle = unzOpen2(pFilename, &mapping);
|
m_ZipFileHandle = unzOpen2(pFilename, &mapping);
|
||||||
}
|
}
|
||||||
|
|
||||||
ZipArchiveIOSystem::Implement::~Implement() {
|
ZipArchiveIOSystem::Implement::~Implement() {
|
||||||
if (m_ZipFileHandle != nullptr) {
|
if (m_ZipFileHandle != nullptr) {
|
||||||
unzClose(m_ZipFileHandle);
|
unzClose(m_ZipFileHandle);
|
||||||
m_ZipFileHandle = nullptr;
|
m_ZipFileHandle = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ZipArchiveIOSystem::Implement::MapArchive() {
|
void ZipArchiveIOSystem::Implement::MapArchive() {
|
||||||
if (m_ZipFileHandle == nullptr)
|
if (m_ZipFileHandle == nullptr)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -373,22 +368,22 @@ namespace Assimp {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} while (unzGoToNextFile(m_ZipFileHandle) != UNZ_END_OF_LIST_OF_FILE);
|
} while (unzGoToNextFile(m_ZipFileHandle) != UNZ_END_OF_LIST_OF_FILE);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ZipArchiveIOSystem::Implement::isOpen() const {
|
bool ZipArchiveIOSystem::Implement::isOpen() const {
|
||||||
return (m_ZipFileHandle != nullptr);
|
return (m_ZipFileHandle != nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ZipArchiveIOSystem::Implement::getFileList(std::vector<std::string>& rFileList) {
|
void ZipArchiveIOSystem::Implement::getFileList(std::vector<std::string> &rFileList) {
|
||||||
MapArchive();
|
MapArchive();
|
||||||
rFileList.clear();
|
rFileList.clear();
|
||||||
|
|
||||||
for (const auto &file : m_ArchiveMap) {
|
for (const auto &file : m_ArchiveMap) {
|
||||||
rFileList.push_back(file.first);
|
rFileList.push_back(file.first);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ZipArchiveIOSystem::Implement::getFileListExtension(std::vector<std::string>& rFileList, const std::string& extension) {
|
void ZipArchiveIOSystem::Implement::getFileListExtension(std::vector<std::string> &rFileList, const std::string &extension) {
|
||||||
MapArchive();
|
MapArchive();
|
||||||
rFileList.clear();
|
rFileList.clear();
|
||||||
|
|
||||||
|
@ -396,16 +391,16 @@ namespace Assimp {
|
||||||
if (extension == BaseImporter::GetExtension(file.first))
|
if (extension == BaseImporter::GetExtension(file.first))
|
||||||
rFileList.push_back(file.first);
|
rFileList.push_back(file.first);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ZipArchiveIOSystem::Implement::Exists(std::string& filename) {
|
bool ZipArchiveIOSystem::Implement::Exists(std::string &filename) {
|
||||||
MapArchive();
|
MapArchive();
|
||||||
|
|
||||||
ZipFileInfoMap::const_iterator it = m_ArchiveMap.find(filename);
|
ZipFileInfoMap::const_iterator it = m_ArchiveMap.find(filename);
|
||||||
return (it != m_ArchiveMap.end());
|
return (it != m_ArchiveMap.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
IOStream * ZipArchiveIOSystem::Implement::OpenFile(std::string& filename) {
|
IOStream *ZipArchiveIOSystem::Implement::OpenFile(std::string &filename) {
|
||||||
MapArchive();
|
MapArchive();
|
||||||
|
|
||||||
SimplifyFilename(filename);
|
SimplifyFilename(filename);
|
||||||
|
@ -417,28 +412,25 @@ namespace Assimp {
|
||||||
|
|
||||||
const ZipFileInfo &zip_file = (*zip_it).second;
|
const ZipFileInfo &zip_file = (*zip_it).second;
|
||||||
return zip_file.Extract(m_ZipFileHandle);
|
return zip_file.Extract(m_ZipFileHandle);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void ReplaceAll(std::string& data, const std::string& before, const std::string& after) {
|
inline void ReplaceAll(std::string &data, const std::string &before, const std::string &after) {
|
||||||
size_t pos = data.find(before);
|
size_t pos = data.find(before);
|
||||||
while (pos != std::string::npos)
|
while (pos != std::string::npos) {
|
||||||
{
|
|
||||||
data.replace(pos, before.size(), after);
|
data.replace(pos, before.size(), after);
|
||||||
pos = data.find(before, pos + after.size());
|
pos = data.find(before, pos + after.size());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void ReplaceAllChar(std::string& data, const char before, const char after) {
|
inline void ReplaceAllChar(std::string &data, const char before, const char after) {
|
||||||
size_t pos = data.find(before);
|
size_t pos = data.find(before);
|
||||||
while (pos != std::string::npos)
|
while (pos != std::string::npos) {
|
||||||
{
|
|
||||||
data[pos] = after;
|
data[pos] = after;
|
||||||
pos = data.find(before, pos + 1);
|
pos = data.find(before, pos + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ZipArchiveIOSystem::Implement::SimplifyFilename(std::string& filename)
|
void ZipArchiveIOSystem::Implement::SimplifyFilename(std::string &filename) {
|
||||||
{
|
|
||||||
ReplaceAllChar(filename, '\\', '/');
|
ReplaceAllChar(filename, '\\', '/');
|
||||||
|
|
||||||
// Remove all . and / from the beginning of the path
|
// Remove all . and / from the beginning of the path
|
||||||
|
@ -450,8 +442,7 @@ namespace Assimp {
|
||||||
static const std::string relative("/../");
|
static const std::string relative("/../");
|
||||||
const size_t relsize = relative.size() - 1;
|
const size_t relsize = relative.size() - 1;
|
||||||
pos = filename.find(relative);
|
pos = filename.find(relative);
|
||||||
while (pos != std::string::npos)
|
while (pos != std::string::npos) {
|
||||||
{
|
|
||||||
// Previous slash
|
// Previous slash
|
||||||
size_t prevpos = filename.rfind('/', pos - 1);
|
size_t prevpos = filename.rfind('/', pos - 1);
|
||||||
if (prevpos == pos)
|
if (prevpos == pos)
|
||||||
|
@ -461,24 +452,23 @@ namespace Assimp {
|
||||||
|
|
||||||
pos = filename.find(relative);
|
pos = filename.find(relative);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ZipArchiveIOSystem::ZipArchiveIOSystem(IOSystem* pIOHandler, const char* pFilename, const char* pMode)
|
ZipArchiveIOSystem::ZipArchiveIOSystem(IOSystem *pIOHandler, const char *pFilename, const char *pMode) :
|
||||||
: pImpl(new Implement(pIOHandler, pFilename, pMode)) {
|
pImpl(new Implement(pIOHandler, pFilename, pMode)) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------
|
// ----------------------------------------------------------------
|
||||||
// The ZipArchiveIO
|
// The ZipArchiveIO
|
||||||
ZipArchiveIOSystem::ZipArchiveIOSystem(IOSystem* pIOHandler, const std::string& rFilename, const char* pMode)
|
ZipArchiveIOSystem::ZipArchiveIOSystem(IOSystem *pIOHandler, const std::string &rFilename, const char *pMode) :
|
||||||
: pImpl(new Implement(pIOHandler, rFilename.c_str(), pMode))
|
pImpl(new Implement(pIOHandler, rFilename.c_str(), pMode)) {
|
||||||
{
|
}
|
||||||
}
|
|
||||||
|
|
||||||
ZipArchiveIOSystem::~ZipArchiveIOSystem() {
|
ZipArchiveIOSystem::~ZipArchiveIOSystem() {
|
||||||
delete pImpl;
|
delete pImpl;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ZipArchiveIOSystem::Exists(const char* pFilename) const {
|
bool ZipArchiveIOSystem::Exists(const char *pFilename) const {
|
||||||
ai_assert(pFilename != nullptr);
|
ai_assert(pFilename != nullptr);
|
||||||
|
|
||||||
if (pFilename == nullptr) {
|
if (pFilename == nullptr) {
|
||||||
|
@ -487,19 +477,18 @@ namespace Assimp {
|
||||||
|
|
||||||
std::string filename(pFilename);
|
std::string filename(pFilename);
|
||||||
return pImpl->Exists(filename);
|
return pImpl->Exists(filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is always '/' in a ZIP
|
// This is always '/' in a ZIP
|
||||||
char ZipArchiveIOSystem::getOsSeparator() const {
|
char ZipArchiveIOSystem::getOsSeparator() const {
|
||||||
return '/';
|
return '/';
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only supports Reading
|
// Only supports Reading
|
||||||
IOStream * ZipArchiveIOSystem::Open(const char* pFilename, const char* pMode) {
|
IOStream *ZipArchiveIOSystem::Open(const char *pFilename, const char *pMode) {
|
||||||
ai_assert(pFilename != nullptr);
|
ai_assert(pFilename != nullptr);
|
||||||
|
|
||||||
for (size_t i = 0; pMode[i] != 0; ++i)
|
for (size_t i = 0; pMode[i] != 0; ++i) {
|
||||||
{
|
|
||||||
ai_assert(pMode[i] != 'w');
|
ai_assert(pMode[i] != 'w');
|
||||||
if (pMode[i] == 'w')
|
if (pMode[i] == 'w')
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
@ -507,31 +496,31 @@ namespace Assimp {
|
||||||
|
|
||||||
std::string filename(pFilename);
|
std::string filename(pFilename);
|
||||||
return pImpl->OpenFile(filename);
|
return pImpl->OpenFile(filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ZipArchiveIOSystem::Close(IOStream* pFile) {
|
void ZipArchiveIOSystem::Close(IOStream *pFile) {
|
||||||
delete pFile;
|
delete pFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ZipArchiveIOSystem::isOpen() const {
|
bool ZipArchiveIOSystem::isOpen() const {
|
||||||
return (pImpl->isOpen());
|
return (pImpl->isOpen());
|
||||||
}
|
}
|
||||||
|
|
||||||
void ZipArchiveIOSystem::getFileList(std::vector<std::string>& rFileList) const {
|
void ZipArchiveIOSystem::getFileList(std::vector<std::string> &rFileList) const {
|
||||||
return pImpl->getFileList(rFileList);
|
return pImpl->getFileList(rFileList);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ZipArchiveIOSystem::getFileListExtension(std::vector<std::string>& rFileList, const std::string& extension) const {
|
void ZipArchiveIOSystem::getFileListExtension(std::vector<std::string> &rFileList, const std::string &extension) const {
|
||||||
return pImpl->getFileListExtension(rFileList, extension);
|
return pImpl->getFileListExtension(rFileList, extension);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ZipArchiveIOSystem::isZipArchive(IOSystem* pIOHandler, const char* pFilename) {
|
bool ZipArchiveIOSystem::isZipArchive(IOSystem *pIOHandler, const char *pFilename) {
|
||||||
Implement tmp(pIOHandler, pFilename, "r");
|
Implement tmp(pIOHandler, pFilename, "r");
|
||||||
return tmp.isOpen();
|
return tmp.isOpen();
|
||||||
}
|
|
||||||
|
|
||||||
bool ZipArchiveIOSystem::isZipArchive(IOSystem* pIOHandler, const std::string& rFilename) {
|
|
||||||
return isZipArchive(pIOHandler, rFilename.c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ZipArchiveIOSystem::isZipArchive(IOSystem *pIOHandler, const std::string &rFilename) {
|
||||||
|
return isZipArchive(pIOHandler, rFilename.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Assimp
|
||||||
|
|
|
@ -158,7 +158,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
# pragma warning(disable : 4521 4714 4127)
|
# pragma warning(disable : 4521 4512 4714 4127)
|
||||||
# ifdef ASSIMP_BUILD_DLL_EXPORT
|
# ifdef ASSIMP_BUILD_DLL_EXPORT
|
||||||
# pragma warning (disable : 4251)
|
# pragma warning (disable : 4251)
|
||||||
# endif
|
# endif
|
||||||
|
|
Loading…
Reference in New Issue