Add function to retrieve CBT status

This commit is contained in:
Martin 2016-06-17 19:35:16 +02:00
parent b916fa8918
commit 107c8474ce
2 changed files with 103 additions and 0 deletions

81
CbtStatus.cpp Normal file
View File

@ -0,0 +1,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("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);
}
}
}

22
CbtStatus.h Normal file
View File

@ -0,0 +1,22 @@
#pragma once
#include "gui/GUI.h"
#include <wx/process.h>
#include <wx/timer.h>
class CbtStatus : public GUICbtStatus, wxTimer, wxProcess
{
public:
CbtStatus(wxWindow* parent);
~CbtStatus();
protected:
virtual void OnExitClick(wxCommandEvent& event);
virtual void Notify(void);
virtual void OnTerminate(int pid, int status);
void addStream(wxInputStream* input_stream);
bool first_val;
};