как создавать архивы? Topic is solved

Это русская секция форума wxWidjets. В этой секции вы можете обсуждать любые вопросы, связанные с wxWidgets на вашем родном языке.
Post Reply
SmileGobo
Earned some good credits
Earned some good credits
Posts: 111
Joined: Wed Jul 30, 2008 8:01 am
Location: Russia/MO
Contact:

как создавать архивы?

Post by SmileGobo »

Ковыряюсь в документации продолжительное время. Из примера не очень ясно как работать с файлами различных типов. Толи открывать и читать побайтно(как это сделать средствами виджетс не очень понятно), толи еще как то. Буду признателен за хороший пример с комментариями упаковки распаковки файлов в zip.
win xp sp2; CodeBlocks/mingw/wxWidgets 2.8.9/wxFormBuilder
web-программирование:PHP,js/Ajax
borr_1
Super wx Problem Solver
Super wx Problem Solver
Posts: 362
Joined: Wed Mar 07, 2007 8:10 am
Location: Russia, Shakhty

Post by borr_1 »

А что справка не помогла?
Creating an archive
Archive formats such as zip

Call PutNextEntry() to create each new entry in the archive, then write the entry's data. Another call to PutNextEntry() closes the current entry and begins the next.

For example:
wxFFileOutputStream out(_T("test.zip"));
wxZipOutputStream zip(out);
wxTextOutputStream txt(zip);
wxString sep(wxFileName::GetPathSeparator());

zip.PutNextEntry(_T("entry1.txt"));
txt << _T("Some text for entry1.txt\n");

zip.PutNextEntry(_T("subdir") + sep + _T("entry2.txt"));
txt << _T("Some text for subdir/entry2.txt\n");
GetNextEntry() returns a pointer to entry object containing the meta-data for the next entry in the archive (and gives away ownership). Reading from the input stream then returns the entry's data. Eof() becomes true after an attempt has been made to read past the end of the entry's data.

When there are no more entries, GetNextEntry() returns NULL and sets Eof().

auto_ptr<wxZipEntry> entry;

wxFFileInputStream in(_T("test.zip"));
wxZipInputStream zip(in);

while (entry.reset(zip.GetNextEntry()), entry.get() != NULL)
{
// access meta-data
wxString name = entry->GetName();
// read 'zip' to access the entry's data
}
include <wx/zipstrm.h> и <wx/fs_mem.h> для фс не забудь.
SmileGobo
Earned some good credits
Earned some good credits
Posts: 111
Joined: Wed Jul 30, 2008 8:01 am
Location: Russia/MO
Contact:

Post by SmileGobo »

Да именно с этими примерами я и не разобрался и нигде кроме них ничего нету. ](*,)
Как допустим связать zip поток с ,бинарным?

Вот пока что получилось:

Code: Select all

void tst_arhive(wxString fname){
    wxFileInputStream in(fname);
    wxFileName file1(fname);
    if (!in.IsOk()) wxMessageBox("file bad");
    wxFileOutputStream out(_T("test.zip"));
    wxZipOutputStream zip(out);
    //wxMessageBox(file1.GetName()+wxString(".")+file1.GetExt());
    zip.PutNextEntry(file1.GetName()+wxString(".")+file1.GetExt());
    static unsigned char buf[1024];
    size_t byteLeft =in.GetSize();
    buf=in.Read((void*) buf,1024);
    zip.Write((const void*) buf,1024);
}
Но в файлы пишутся нули :?
win xp sp2; CodeBlocks/mingw/wxWidgets 2.8.9/wxFormBuilder
web-программирование:PHP,js/Ajax
borr_1
Super wx Problem Solver
Super wx Problem Solver
Posts: 362
Joined: Wed Mar 07, 2007 8:10 am
Location: Russia, Shakhty

Post by borr_1 »

ЭЭЭЭ а по этому форуму поиск что дал я только набрал wxZipOutputStream и получил кучу ссылок фот хотя бы верхняя там много хороших примеров http://forums.wxwidgets.org/viewtopic.p ... tputstream
Смотри ответ помеченный как answer
SmileGobo
Earned some good credits
Earned some good credits
Posts: 111
Joined: Wed Jul 30, 2008 8:01 am
Location: Russia/MO
Contact:

Post by SmileGobo »

Спасибо что-то вытанцовывается. Возможно стоит выложить потом то что у меня получится.
win xp sp2; CodeBlocks/mingw/wxWidgets 2.8.9/wxFormBuilder
web-программирование:PHP,js/Ajax
Post Reply