1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
#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, 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;
}
|