forked from n00b87/RCBasic-Studio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrcbasic_editrc_distProcess_dialog.cpp
executable file
·125 lines (95 loc) · 3.12 KB
/
rcbasic_editrc_distProcess_dialog.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#include "rcbasic_editrc_distProcess_dialog.h"
#include <wx/txtstrm.h>
#include <wx/msgdlg.h>
rcbasic_editrc_distProcess_dialog::rcbasic_editrc_distProcess_dialog( wxWindow* parent, wxString dist_cmd, int num_targets )
:
rc_distProcess_dialog( parent )
{
isRunning = false;
dist_pid = -1;
dist_process = NULL;
dist_process = new wxProcess(this);
if(!dist_process)
Close();
dist_process->Redirect();
dist_process->Connect( wxEVT_END_PROCESS, wxProcessEventHandler( rcbasic_editrc_distProcess_dialog::onDistProcessTerminate ), NULL, this );
wxString pkg_home;
wxGetEnv(_("RC_PKG_HOME"), &pkg_home);
wxSetWorkingDirectory(pkg_home);
wxString p;
wxGetEnv(_("PATH"), &p);
//wxPuts(_("PATH: ") + p );
//wxPuts(_("\nCMD: ")+dist_cmd+_("\n\n"));
dist_pid = wxExecute(dist_cmd, wxEXEC_ASYNC, dist_process, NULL);
if(dist_pid < 0)
{
if(dist_process)
delete dist_process;
dist_process = NULL;
return;
}
isRunning = true;
target_count = num_targets;
//wxPrintf(_("Num Targets: %d\n"), target_count);
m_status_gauge->SetRange(target_count);
current_count = 0;
}
void rcbasic_editrc_distProcess_dialog::onDistProcessUpdateUI( wxUpdateUIEvent& event )
{
// TODO: Implement onDistProcessUpdateUI
if(!isRunning)
return;
wxTextInputStream dist_stream(*dist_process->GetInputStream());
while(dist_process->IsInputAvailable())
{
wxString console_line = dist_stream.ReadLine();
if(console_line.find(_("RCBASIC PACKAGE SUCCESS:")) != wxString::npos)
{
//wxPuts(_("\n\n####FOUND IT#####\n\n"));
current_count++;
m_status_gauge->SetValue(current_count);
//wxPrintf(_("Current Value = %d out of %d\n"), m_status_gauge->GetValue(), m_status_gauge->GetRange());
}
m_consoleLog_textCtrl->AppendText(console_line + _("\n"));
}
}
void rcbasic_editrc_distProcess_dialog::onCancelButtonClick( wxCommandEvent& event )
{
// TODO: Implement onCancelButtonClick
if(!isRunning)
Close();
isRunning = false;
dist_process->CloseOutput();
wxExecute(_("taskkill /F /IM rcbasic_studio_run.exe"), wxEXEC_SYNC);
wxKill(dist_pid);
if(dist_process)
delete dist_process;
dist_process = NULL;
Close();
}
void rcbasic_editrc_distProcess_dialog::onCloseButtonClick( wxCommandEvent& event )
{
// TODO: Implement onCloseButtonClick
Close();
}
void rcbasic_editrc_distProcess_dialog::onDistProcessTerminate( wxProcessEvent& event )
{
isRunning = false;
dist_process->CloseOutput();
wxTextInputStream dist_stream(*dist_process->GetInputStream());
while(dist_process->IsInputAvailable())
{
wxString console_line = dist_stream.ReadLine();
m_consoleLog_textCtrl->AppendText(console_line + _("\n"));
}
if(m_status_gauge->GetValue() < m_status_gauge->GetRange())
{
wxMessageBox(_("ERROR: Did not successfully build app for all selected platforms."));
}
wxKill(dist_pid);
if(dist_process)
delete dist_process;
dist_process = NULL;
m_cancel_button->Hide();
m_close_button->Enable();
}