-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCompileForm.cs
150 lines (136 loc) · 4.7 KB
/
CompileForm.cs
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace PyinstallerHelper
{
public partial class CompileForm : Form
{
public string ToBuild;
public string tempdir;
public bool abort = false;
private bool running = false;
public Stream ns = Stream.Null;
private StreamReader nsr;
private StreamWriter nsw;
private string ToPut = "";
public CompileForm()
{
nsr = new StreamReader(ns);
nsw = new StreamWriter(ns);
InitializeComponent();
}
private void CompileForm_Load(object sender, EventArgs e)
{
richTextBox1.Text = ToBuild;
this.MaximizeBox = false;//Messes up UI
button2.Enabled = false;
progressBar1.Maximum = 100;
progressBar1.Step = 1;
running = true;
this.Text = "Compiling...";
//TODO Compile code
ToBuild = richTextBox1.Text;//Load any changes the user has made
var ts = new ThreadStart(() => DoTheDeed(tempdir));
ts += UIMarkEndInstall;
Thread t = new Thread(ts);
t.Start();
}
private void button1_Click(object sender, EventArgs e)
{
if (running)
{
abort = true;
}
else
{
this.Close();
}
}
private void OnInputRecv(object sender, DataReceivedEventArgs e)
{
this.Invoke((MethodInvoker)delegate {
// Running on the UI thread
richTextBox1.Text += "\n"+e.Data;
progressBar1.PerformStep();
});
}
private void DoTheDeed(string tempdir)
{
Process p = new Process();
var slp = CLISplit.SplitCommandLine(ToBuild).ToList();
p.StartInfo.FileName = RuntimeConfiguration.c.PyinstallerPath;
p.StartInfo.Arguments = String.Join(" ",slp.GetRange(1,slp.Count-1));
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = true;
p.OutputDataReceived += OnInputRecv;
p.ErrorDataReceived += OnInputRecv;
try
{
p.Start();
} catch
{
MessageBox.Show("You do not appear to have pyinstaller installed. Please go to Options -> Pyinstaller to fix this.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
p.BeginOutputReadLine();
p.BeginErrorReadLine();
while (!p.HasExited)
{
if (abort)
{
p.Kill();
MessageBox.Show("Compilation aborted", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
break;
}
}
this.Invoke((MethodInvoker)delegate {
// Running on the UI thread
progressBar1.Value = progressBar1.Maximum;
});
var ec = p.ExitCode;
if (ec != 0)
{
MessageBox.Show("Error compiling: Please check log", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
} else
{
if (RuntimeConfiguration.AutomatedBuild)
{
this.Close();
}
MessageBox.Show("Completed successfully!","Report",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
}
private void button2_Click(object sender, EventArgs e)
{
this.Close();
}
private void UIMarkEndInstall()
{
this.Invoke((MethodInvoker)delegate {
// Running on the UI thread
File.WriteAllText(tempdir + "\\compile.log", richTextBox1.Text);
Text = "Finished";
progressBar1.Style = ProgressBarStyle.Continuous;
running = false;
button2.Enabled = true;
});
}
private void richTextBox1_TextChanged(object sender, EventArgs e)
{
richTextBox1.SelectionStart = richTextBox1.Text.Length;
richTextBox1.ScrollToCaret();
}
}
}