83 lines
2.0 KiB
C++
83 lines
2.0 KiB
C++
#include "IZipFileContentProvider.h"
|
|
namespace LifeCore
|
|
{
|
|
static const String zipPathSplitter(_text("/"));
|
|
|
|
IZipFileContentProvider::IZipFileContentProvider(const String& zipFile)
|
|
{
|
|
IZipFolder* folder = new IZipFolder();
|
|
g_rootFolder = zipFile;
|
|
folder->Provider = this;
|
|
folder->Name = GetFileNameWithoutExtention(zipFile);
|
|
|
|
folder->EntryName = _text("");
|
|
|
|
g_fs = new IFileSystem(folder);
|
|
|
|
g_sourceFile = unzOpen(zipFile.c_str());
|
|
|
|
unzGetGlobalInfo(g_sourceFile,&globalInfo);
|
|
g_fs->GetRootFolder();
|
|
BuildTree();
|
|
unzClose(g_sourceFile);
|
|
}
|
|
|
|
void IZipFileContentProvider::BuildTree()
|
|
{
|
|
unzGoToFirstFile(g_sourceFile);
|
|
|
|
for (unsigned int i = 0; i < globalInfo.number_entry; i++)
|
|
{
|
|
tchar fileName[256+1] = {0};
|
|
unz_file_info fileInfo;
|
|
|
|
unzGetCurrentFileInfo(g_sourceFile,&fileInfo,fileName,256,NULL,0,NULL, 0);
|
|
|
|
if (fileInfo.size_filename >0 && fileName[fileInfo.size_filename-1] == '/')
|
|
{
|
|
/* string path = entry.Name;
|
|
path = path.Replace('/', '\\');
|
|
IZipFolder folder = BuildDirectory(path);*/
|
|
}
|
|
else//is file
|
|
{
|
|
String sd = String(fileName);
|
|
String p = GetZipPathWithoutFilename(sd);
|
|
IZipFolder* folder;
|
|
g_fs->GetFolder(p, (IFolder**)&folder);
|
|
|
|
IZipFile* file = new IZipFile();
|
|
file->FileName = GetFileName(sd, zipPathSplitter);
|
|
file->Provider = this;
|
|
file->Size = fileInfo.uncompressed_size;
|
|
file->EntryName = sd;
|
|
folder->AddFile(file);
|
|
}
|
|
unzCloseCurrentFile(g_sourceFile);
|
|
unzGoToNextFile(g_sourceFile);
|
|
}
|
|
|
|
//print folder tree
|
|
String tab(_text("\t"));
|
|
int cnt = g_fs->GetRootFolder()->folderCount;
|
|
for(int i = 0; i < cnt; i++)
|
|
{
|
|
IFolder* fld = g_fs->GetRootFolder()->GetFolder(i);
|
|
PRINT(_text("%s\n"), fld->Name.c_str());
|
|
PRINT(_text("Files count: %i\n"), fld->fileCount);
|
|
}
|
|
}
|
|
|
|
String IZipFileContentProvider::GetZipPathWithoutFilename(const String& path)
|
|
{
|
|
int offset = path.find_last_of(_text("/"));
|
|
if(offset>=0)
|
|
{
|
|
return path.substr(0, offset);
|
|
}
|
|
else
|
|
{
|
|
return _text("/");
|
|
}
|
|
}
|
|
} |