-
Notifications
You must be signed in to change notification settings - Fork 42
/
CbtStatus.cpp
81 lines (66 loc) · 1.44 KB
/
CbtStatus.cpp
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
73
74
75
76
77
78
79
80
81
#include "CbtStatus.h"
#include <wx/process.h>
extern wxString res_path;
extern wxString ico_ext;
extern wxBitmapType ico_type;
CbtStatus::CbtStatus(wxWindow* parent)
: GUICbtStatus(parent), wxProcess(wxPROCESS_REDIRECT), first_val(true)
{
SetIcon(wxIcon(res_path + wxT("backup-ok.") + ico_ext, ico_type));
long pid = wxExecute(wxT("\"") + res_path + wxT("urbctctl.exe\" status all"), wxEXEC_ASYNC, this);
if (pid != 0)
{
Redirect();
CloseOutput();
}
Start(100);
m_textCtrl3->SetValue("Retrieving CBT status...");
Show(true);
}
CbtStatus::~CbtStatus()
{
Stop();
}
void CbtStatus::OnExitClick(wxCommandEvent & event)
{
Stop();
Close();
}
void CbtStatus::Notify(void)
{
if (first_val)
{
first_val = false;
m_textCtrl3->SetValue("");
}
addStream(GetInputStream());
addStream(GetErrorStream());
if ((GetErrorStream() == NULL || GetErrorStream()->Eof())
&& (GetInputStream()==NULL || GetInputStream()->Eof()) )
{
Stop();
}
}
void CbtStatus::OnTerminate(int pid, int status)
{
Notify();
Stop();
}
void CbtStatus::addStream(wxInputStream * input_stream)
{
if (input_stream == NULL)
{
return;
}
while (input_stream->CanRead())
{
char buffer[1024];
input_stream->Read(buffer, 1024);
size_t read = input_stream->LastRead();
if (read > 0)
{
wxString read_str = wxString::FromUTF8(buffer, read);
m_textCtrl3->AppendText(read_str);
}
}
}