|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.ComponentModel; |
| 4 | +using System.Data; |
| 5 | +using System.Diagnostics; |
| 6 | +using System.Drawing; |
| 7 | +using System.IO; |
| 8 | +using System.Linq; |
| 9 | +using System.Text; |
| 10 | +using System.Threading; |
| 11 | +using System.Threading.Tasks; |
| 12 | +using System.Windows.Forms; |
| 13 | + |
| 14 | +namespace PyinstallerHelper |
| 15 | +{ |
| 16 | + public partial class CompileForm : Form |
| 17 | + { |
| 18 | + public string ToBuild; |
| 19 | + public string tempdir; |
| 20 | + public bool abort = false; |
| 21 | + private bool running = false; |
| 22 | + public Stream ns = Stream.Null; |
| 23 | + private StreamReader nsr; |
| 24 | + private StreamWriter nsw; |
| 25 | + private string ToPut = ""; |
| 26 | + public CompileForm() |
| 27 | + { |
| 28 | + nsr = new StreamReader(ns); |
| 29 | + nsw = new StreamWriter(ns); |
| 30 | + InitializeComponent(); |
| 31 | + } |
| 32 | + |
| 33 | + private void CompileForm_Load(object sender, EventArgs e) |
| 34 | + { |
| 35 | + richTextBox1.Text = ToBuild; |
| 36 | + this.MaximizeBox = false;//Messes up UI |
| 37 | + } |
| 38 | + |
| 39 | + private void button1_Click(object sender, EventArgs e) |
| 40 | + { |
| 41 | + if (running) |
| 42 | + { |
| 43 | + abort = true; |
| 44 | + } |
| 45 | + else |
| 46 | + { |
| 47 | + this.Close(); |
| 48 | + } |
| 49 | + } |
| 50 | + private void DoTheDeed(string tempdir) |
| 51 | + { |
| 52 | + Process p = new Process(); |
| 53 | + var slp = CLISplit.SplitCommandLine(ToBuild).ToList(); |
| 54 | + p.StartInfo.FileName = "powershell.exe"; |
| 55 | + p.StartInfo.Arguments = ToBuild+$" | tee {tempdir}\\compile.log"; |
| 56 | + p.StartInfo.UseShellExecute = false; |
| 57 | + if (!checkBox1.Checked) |
| 58 | + { |
| 59 | + p.StartInfo.CreateNoWindow = true; |
| 60 | + } else |
| 61 | + { |
| 62 | + p.StartInfo.CreateNoWindow = false; |
| 63 | + } |
| 64 | + p.Start(); |
| 65 | + p.WaitForExit(); |
| 66 | + var ec = p.ExitCode; |
| 67 | + if (ec != 0) |
| 68 | + { |
| 69 | + MessageBox.Show("Error compiling: Please check log", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); |
| 70 | + } else |
| 71 | + { |
| 72 | + MessageBox.Show("Completed successfully!"); |
| 73 | + } |
| 74 | + } |
| 75 | + |
| 76 | + |
| 77 | + private void button2_Click(object sender, EventArgs e) |
| 78 | + { |
| 79 | + button2.Enabled = false; |
| 80 | + progressBar1.Style = ProgressBarStyle.Marquee; |
| 81 | + running = true; |
| 82 | + this.Text = "Compiling..."; |
| 83 | + //TODO Compile code |
| 84 | + ToBuild = richTextBox1.Text;//Load any changes the user has made |
| 85 | + var ts = new ThreadStart(() => DoTheDeed(tempdir)); |
| 86 | + ts += UIMarkEndInstall; |
| 87 | + Thread t = new Thread(ts) ; |
| 88 | + |
| 89 | + t.Start(); |
| 90 | + |
| 91 | + |
| 92 | + } |
| 93 | + private void UIMarkEndInstall() |
| 94 | + { |
| 95 | + this.Invoke((MethodInvoker)delegate { |
| 96 | + // Running on the UI thread |
| 97 | + Text = "Finished"; |
| 98 | + progressBar1.Style = ProgressBarStyle.Continuous; |
| 99 | + running = false; |
| 100 | + button2.Enabled = true; |
| 101 | + }); |
| 102 | + |
| 103 | + } |
| 104 | + |
| 105 | + private void richTextBox1_TextChanged(object sender, EventArgs e) |
| 106 | + { |
| 107 | + |
| 108 | + } |
| 109 | + } |
| 110 | +} |
0 commit comments