summaryrefslogtreecommitdiffstats
path: root/creator_thread.cpp
diff options
context:
space:
mode:
authorNatanael Copa <ncopa@alpinelinux.org>2012-07-18 22:11:55 +0200
committerNatanael Copa <ncopa@alpinelinux.org>2012-07-18 22:13:33 +0200
commit711f6fb1caa0861d1b3504d53c7f44c0582cbc97 (patch)
treeba04843a2c5683b8c60544ca3bc6d0bbdeed5598 /creator_thread.cpp
parent5384d95c28298710fee6728bb83614a130469716 (diff)
downloadalpine-usb-creator-711f6fb1caa0861d1b3504d53c7f44c0582cbc97.tar.bz2
alpine-usb-creator-711f6fb1caa0861d1b3504d53c7f44c0582cbc97.tar.xz
Extract iso with libuniso
Diffstat (limited to 'creator_thread.cpp')
-rw-r--r--creator_thread.cpp54
1 files changed, 44 insertions, 10 deletions
diff --git a/creator_thread.cpp b/creator_thread.cpp
index f5ab6b2..9b79beb 100644
--- a/creator_thread.cpp
+++ b/creator_thread.cpp
@@ -1,13 +1,39 @@
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
#include <wx/msgdlg.h>
#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, NULL);
+ 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()
@@ -23,16 +49,24 @@ void CreatorThread::OnExit()
wxThread::ExitCode CreatorThread::Entry()
{
- int i;
- wxFileName tmpdir(*m_target);
- tmpdir.AppendDir(wxT(".new"));
- tmpdir.Mkdir(0755, wxPATH_MKDIR_FULL);
- for (i = 0; i<=100; i++) {
- wxMutexGuiEnter();
- m_dialog->SetProgress(i);
- wxMutexGuiLeave();
- wxMilliSleep(100);
- }
+ 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;
}