2
Copyright (c) 2009 NetAllied Systems GmbH
4
This file is part of G3DWarehouseBrowser.
6
Licensed under the MIT Open Source License,
7
for details please see LICENSE file or the website
8
http://www.opensource.org/licenses/mit-license.php
11
#include "G3DStableHeaders.h"
12
#include "G3DFileUnzipper.h"
17
#include "zzip/zzip.h"
19
#include "COLLADABUStringUtils.h"
26
const char IMAGES_DIRECTORY[] = "images";
27
const char MODEL_PATH[] = "models/model.dae";
28
const char WAREHOUSE_MODEL_PATH[] = "models/warehouse_model.dae";
29
const char MODEL_DIR[] = "models";
31
const String SLASH("/");
32
const String BACKSLASH("\\");
36
String unzipFile_( ZZIP_DIR * dir, const ZZIP_DIRENT& d, const String& extractPath, String& errorString )
38
ZZIP_FILE* input = zzip_file_open (dir, d.d_name, O_RDONLY);
41
errorString = zzip_strerror_of(dir);
44
String filePath(d.d_name);
45
COLLADABU::StringUtils::stringFindAndReplace(filePath, SLASH, BACKSLASH);
46
String extractedFilePath = extractPath + filePath;
48
errno_t error = fopen_s( &outFile, extractedFilePath.c_str(), "wb" );
51
errorString = String("Could not open output file") + d.d_name;
53
zzip_file_close (input);
58
char buf[17]; zzip_ssize_t n;
59
/* read chunks of 16 bytes into buf */
60
while (0 < (n = zzip_read (input, buf, 16)))
62
fwrite (buf, 1, n, outFile);
69
zzip_file_close (input);
71
return extractedFilePath;
76
//--------------------------------------------------------------------
77
FileUnzipper::FileUnzipper( const String& zipFile, const String& extractPath )
79
mSucceeded = unzipFile(zipFile, extractPath);
82
//--------------------------------------------------------------------
83
FileUnzipper::~FileUnzipper()
87
//--------------------------------------------------------------------
88
bool FileUnzipper::unzipFile( const String& zipFile, const String& extractPath )
95
dir = zzip_dir_open(zipFile.c_str(), &error);
98
mLastErrorString = zzip_strerror(error);
102
/* read each dir entry and show one line of info per file */
103
while (zzip_dir_read (dir, &d))
106
if ( (strcmp(d.d_name, MODEL_PATH) == 0) || (strcmp(d.d_name, WAREHOUSE_MODEL_PATH) == 0) )
108
_mkdir( (extractPath+MODEL_DIR).c_str() );
109
mDAEFilePath = unzipFile_(dir, d, extractPath, mLastErrorString);
114
String filePath(d.d_name);
115
size_t separatorPos = filePath.find_first_of('/');
116
String filePathDir(filePath, 0, separatorPos);
118
if ( filePathDir == IMAGES_DIRECTORY )
120
_mkdir( (extractPath+IMAGES_DIRECTORY).c_str() );
121
unzipFile_(dir, d, extractPath, mLastErrorString);
130
bool FileUnzipper::unzipDirectory( ZZIP_DIR * dir, ZZIP_DIRENT d, const String& extractPath )
b'\\ No newline at end of file'