#include #include #include #include #include "creator_thread.h" extern "C" { #include "uniso.h" } static void progress_cb(size_t current, size_t total, const char *filename, void *user_data) { static size_t unpacked_bytes = 0; static size_t total_bytes = 0; Dialog *d = (Dialog *)user_data; if (current != unpacked_bytes || total != total_bytes) { unpacked_bytes = current; total_bytes = total; wxMutexGuiEnter(); d->SetProgress(current, total, filename); wxMutexGuiLeave(); } } CreatorThread::CreatorThread(Dialog *d, const wxString &iso, const wxString &target) : wxThread() { m_dialog = d; m_source = new wxFileName(iso); m_target = new wxFileName(target, wxEmptyString); m_current_file = NULL; m_total_bytes = 0; m_unpacked_bytes = 0; } CreatorThread::~CreatorThread() { delete m_source; delete m_target; m_dialog = NULL; } void CreatorThread::OnExit() { } wxThread::ExitCode CreatorThread::Entry() { int fd; /* extract contents to .new/ dir on target device */ wxFileName newdir(*m_target); newdir.AppendDir(wxT(".new")); newdir.Mkdir(0755, wxPATH_MKDIR_FULL); newdir.SetCwd(); fd = open(m_source->GetFullPath().char_str(), O_RDONLY); if (fd >= 0) uniso(fd, &progress_cb, m_dialog); close(fd); /* move existing to old */ wxFileName olddir(*m_target); olddir.AppendDir(wxT(".old")); olddir.Mkdir(0755, wxPATH_MKDIR_FULL); wxFileName target(*m_target); return NULL; }