wxZip 사용

C++ 2012. 7. 24. 09:29



다 좋은데.. 스펙을 충실히 따라서 2GB인지 4GB인지 이상된 .zip 파일을 못풀어줌.

zlib + minizip 은 대용량 가능 (http://www.winimage.com/zLibDll/minizip.html).



// 압축 풀기

void uncompress(const wxString& zip_path) {

wxFileInputStream in(zip_path);

if (!in) {

//Error("can't open stream : " + zip_path.ToStdString());

return;

}


wxZipInputStream zip(in);


unique_ptr<wxZipEntry> entry;

while (entry.reset(zip.GetNextEntry()), entry.get() != NULL) {


wxString file_path = wxFileName(zip_path).GetPath(wxPATH_GET_SEPARATOR) + entry->GetName();

if (entry->IsDir()) {

wxFileName::Mkdir(file_path, entry->GetMode(), wxPATH_MKDIR_FULL);

continue;

}


zip.OpenEntry(*entry);

if (!zip.CanRead()) {

//Error("can't read zip entry : " + entry->GetInternalName().ToStdString());

continue;

}

wxFile file(file_path, wxFile::write);

if (!file.IsOpened()) {

//Error("can't open file(write mode) : " + file_path.ToStdString());

continue;

}


while (!zip.Eof()) {


vector<BYTE> buffer(8192, 0x00);

zip.Read(&buffer.at(0), buffer.size());

size_t bytes = zip.LastRead();


if (bytes > 0) {

file.Write(&buffer.at(0), bytes);

}

}

}

}


// 압축해재시 크기

UINT64 uncompressedSize(vector<wxString>& files) {

UINT64 size = 0;

wxFileInputStream in(*it);

if (!in) {

//Error("can't open file : " + it->ToStdString());

continue;

}


wxZipInputStream zip(in);

unique_ptr<wxZipEntry> entry;

wxZipEntry* ent = zip.GetNextEntry();

while (entry.reset(zip.GetNextEntry()), entry.get() != NULL) {

size += entry->GetSize();

}

return size;

}

'C++' 카테고리의 다른 글

wxWidgets 컴파일  (0) 2012.07.24
윈도우 폴더 관련  (0) 2012.07.24
wxWidgets tray icon (wxTaskBarIcon)  (0) 2012.07.24
taskbar gage (windows7 이상)  (0) 2012.07.24
wxRichTextCtrl 사용방법  (0) 2012.07.14
wxColour #FF000000 - 알파 인식여부 확인  (0) 2012.07.11
wxRegEx 사용하여 특정 문자 치환  (0) 2012.07.11
std::regex  (0) 2012.07.05