Source

BlueGo / BlueGo / FormMain.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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.IO;
using System.IO.Compression;
using System.Diagnostics;
using System.Threading;
using System.Reflection;
using BlueGo.GUI;
using System.Net.Mail;
using System.Management;
using System.Xml.Linq;
using System.Xml;
using Microsoft.Win32;
using System.Runtime.InteropServices;

namespace BlueGo
{
    public partial class FormMain : Form
    {    
        string Qt4_8_3DownloadURL = @"http://releases.qt-project.org/qt4/source/qt-everywhere-opensource-src-4.8.3.zip";
        string Qt4_8_3ZipFilename = "qt-everywhere-opensource-src-4.8.3.zip";

        string jomURL = @"ftp://ftp.qt.nokia.com/jom/jom108.zip";

        int coreCount = 0;





    

        // perl strawbery

        public FormMain()
        {
            InitializeComponent();

            
            foreach (var item in new System.Management.ManagementObjectSearcher("Select * from Win32_Processor").Get())
            {
                coreCount += int.Parse(item["NumberOfCores"].ToString());
            }
        }

        void sendMail()
        {
            if (!BlueGo.GUI.PreferencesManager.Instance.SendReportEmail)
                return;

            string strVon = PreferencesManager.Instance.User;
            string strAn = PreferencesManager.Instance.Subscriber;
            string strSmtpServer = PreferencesManager.Instance.SmtpServer;
            string strUser = PreferencesManager.Instance.User;
            string strPasswort = PreferencesManager.Instance.Password;

            string host = strSmtpServer;
            int port = int.Parse(PreferencesManager.Instance.Port);

            SmtpClient client = new SmtpClient(host, port);

            System.Net.NetworkCredential nc = new System.Net.NetworkCredential(strUser, strPasswort);
            client.Credentials = nc;

            client.EnableSsl = true;
            
            MailMessage mail = new MailMessage();
            MailAddress from = new MailAddress(strVon);
            mail.To.Add(strAn);
            mail.From = from;
            mail.Subject = "BUWDeployment";

            mail.Body = "Hello it´s me the BUWDeployer";

            // collect some info for mail
            string ComputerName = System.Windows.Forms.SystemInformation.ComputerName.ToString();
            IPHostEntry Host = Dns.GetHostEntry(Dns.GetHostName());

            mail.Body += "\n";
            mail.Body += "Computer Name: " + ComputerName;

            foreach (IPAddress ipaddress in Host.AddressList)
            {
                mail.Body += "\n";
                mail.Body += "IP           : " + ipaddress.ToString();   
            }

            mail.Body += "\n";
            mail.Body += "ProcessorCount: " + Environment.ProcessorCount;
            mail.Body += "\n";
            mail.Body += "Is64BitOperatingSystem: " + Environment.Is64BitOperatingSystem;
            mail.Body += "\n";
            mail.Body += "OSVersion: " + Environment.OSVersion;
            mail.Body += "\n";
            mail.Body += "UserName: " + Environment.UserName;
            mail.Body += "Cpu Caption: " + WMI_ProcessorInformation.WMI_Processor_Information.GetCpuCaption();
            mail.Body += "\n";
            mail.Body += "Cpu Cores: " + WMI_ProcessorInformation.WMI_Processor_Information.GetCpuCores();
            mail.Body += "\n";
            mail.Body += "Cpu Id: " + WMI_ProcessorInformation.WMI_Processor_Information.GetCpuId();
            mail.Body += "\n";
            mail.Body += "Cpu Socket Designation" + WMI_ProcessorInformation.WMI_Processor_Information.GetCpuSocketDesignation();
            mail.Body += "\n";
            mail.Body += "Cpu's current operating voltage: " + WMI_ProcessorInformation.WMI_Processor_Information.GetCpuVoltage();
            mail.Body += "\n";
            mail.Body += "Cpu's Manufacturer: " + WMI_ProcessorInformation.WMI_Processor_Information.GetCpuManufacturer();
            mail.Body += "\n";
            mail.Body += "Cpu Number of logical processors: " + WMI_ProcessorInformation.WMI_Processor_Information.GetCpuNumberOfLogicalProcessors();
            mail.Body += "\n";
            mail.Body += "Cpu's Data width (32 or 64bit): " + WMI_ProcessorInformation.WMI_Processor_Information.GetCpuDataWidth();
            mail.Body += "\n";
            mail.Body += "Cpu speed is (in mega-hertz): " + WMI_ProcessorInformation.WMI_Processor_Information.GetCpuClockSpeed();
            mail.Body += "\n";

            ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_DisplayConfiguration");

            string graphicsCard = string.Empty;
            foreach (ManagementObject mo in searcher.Get())
            {
                foreach (PropertyData property in mo.Properties)
                {
                    if (property.Name == "Description")
                    {
                        graphicsCard = property.Value.ToString();

                        mail.Body += "\n";
                        mail.Body += "graphicsCard: " + graphicsCard;
                    }
                }
            }


            try
            {
                client.Send(mail);
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }

        void sendMail(string Text)
        {
            string strVon = PreferencesManager.Instance.User;
            string strAn = PreferencesManager.Instance.Subscriber;
            string strSmtpServer = PreferencesManager.Instance.SmtpServer;
            string strUser = PreferencesManager.Instance.User;
            string strPasswort = PreferencesManager.Instance.Password;

            string host = strSmtpServer;
            int port = int.Parse(PreferencesManager.Instance.Port);


            SmtpClient client = new SmtpClient(host, port);

            System.Net.NetworkCredential nc = new System.Net.NetworkCredential(strUser, strPasswort);
            client.Credentials = nc;

            client.EnableSsl = true;

            MailMessage mail = new MailMessage();
            MailAddress from = new MailAddress(strVon);
            mail.To.Add(strAn);
            mail.From = from;
            mail.Subject = "BUWDeployment";

            mail.Body = Text;

            string ComputerName = System.Windows.Forms.SystemInformation.ComputerName.ToString();
            mail.Body += "\n";
            mail.Body += "Computer Name: " + ComputerName;

            try
            {
                client.Send(mail);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }

        void DownloadAndBuildQT4_8_3_x64()
        {
            string destinationFolder = DetermineDestinationFolder();

            if (!Directory.Exists(destinationFolder))
            {
                Directory.CreateDirectory(destinationFolder);
            }
            message("downloading QT");

            string thirdpartyDirectoryPath = PreferencesManager.Instance.ThirdPartyDownloadFolder;

            // Download Qt
            DownloadHelper.DownloadFileFromURL(Qt4_8_3DownloadURL, destinationFolder + Qt4_8_3ZipFilename);

            message("extracting QT");

            // Extract Qt
            SevenZip.Decompress(destinationFolder + Qt4_8_3ZipFilename, destinationFolder);

            eCompiler compilerType = DetermineSelectedCompiler();
            if(compilerType == eCompiler.VS2012)
            {
                // patch Qt 4.8.3
                message("patching Qt 4.8.3");

                System.Reflection.Assembly a = System.Reflection.Assembly.GetEntryAssembly();
                string baseDir = System.IO.Path.GetDirectoryName(a.Location);
                string qmakeConfigPath = baseDir + @"\qt4.8.3vs2012patch\qmake.conf";
                
                if (!File.Exists(qmakeConfigPath))
                    throw new Exception("File " + qmakeConfigPath + " does not exist");

                File.Copy(
                    qmakeConfigPath,
                    destinationFolder + @"qt-everywhere-opensource-src-4.8.3\mkspecs\win32-msvc2010\qmake.conf", true);

                File.Copy(
                  @"qt4.8.3vs2012patch\HashSet.h",
                  destinationFolder + @"qt-everywhere-opensource-src-4.8.3\src\3rdparty\webkit\Source\JavaScriptCore\wtf\HashSet.h", true);
            }

            message("configure qt");

            configureQT_4_8_3();
            
            message("building qt");

            buildQT4_8_3();

            message("Finished buidling qt  - - - DONE");

            UnlockQtBuildButton();
        }

        string DetermineDestinationFolder()
        {
            string destinationFolder = PreferencesManager.Instance.ThirdPartyDownloadFolder + "/vs2010/x64/";

            eCompiler compilerType = DetermineSelectedCompiler();
            if (compilerType == eCompiler.VS2012)
            {
                destinationFolder = PreferencesManager.Instance.ThirdPartyDownloadFolder + "/vs2012/x64/";
            }
            else if (compilerType == eCompiler.VS2010)
            {
                destinationFolder = PreferencesManager.Instance.ThirdPartyDownloadFolder + "/vs2010/x64/";
            }
            else
                throw new Exception("Invalid compiler");

            return destinationFolder;
        }

        void message(string msg)
        {
            SetWindowTitleStatusInfo(msg);
            
            if(BlueGo.GUI.PreferencesManager.Instance.SendReportEmail)
                sendMail(msg);

            this.Invoke((MethodInvoker)delegate
            {
                listBoxLogOutput.Items.Add(msg);
                //listBox1.EnsureVisible(listBox1.Items.Count - 1);
            });
        }

        private void readStandardOutput(Process p)
        {
            using (StreamReader sr = p.StandardOutput)
            {
                while (sr.BaseStream.CanRead)
                {
                    string test = sr.ReadLine();

                    if (test == null)
                        break;

                    this.Invoke((MethodInvoker)delegate
                    {
                        listBoxLogOutput.Items.Add(test);
                    });
                }
            }
        }

        private void readStandardError(Process p)
        {
            using (StreamReader sr = p.StandardError)
            {
                while (sr.BaseStream.CanRead)
                {
                    string test = sr.ReadLine();

                    if (test == null)
                        break;

                    this.Invoke((MethodInvoker)delegate
                    {
                        listBoxLogOutput.Items.Add(test);
                    });
                }
            }
        }


        private void Form1_Resize(object sender, EventArgs e)
        {
            if (this.WindowState == FormWindowState.Minimized)
            {
                //this.notifyIcon1.ContextMenu = contextMenuStrip1;
                this.ShowInTaskbar = false;
                this.WindowState = FormWindowState.Minimized;
                this.notifyIconBlueDeployment.Visible = true;
            }
        }

        private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            this.ShowInTaskbar = true;
            this.notifyIconBlueDeployment.Visible = false;
            this.WindowState = FormWindowState.Normal;
        }

        private void preferencesToolStripMenuItem_Click(object sender, EventArgs e)
        {
            m_FormPreferences.Clean();
            m_FormPreferences.ShowDialog();
        }

        private void configureQT_4_8_3()
        {
            string destinationFolder = PreferencesManager.Instance.ThirdPartyDownloadFolder + "/vs2010/x64/";
            eCompiler compiler = DetermineSelectedCompiler();
            if (compiler == eCompiler.VS2012)
                destinationFolder = PreferencesManager.Instance.ThirdPartyDownloadFolder + "/vs2012/x64/";
            if (compiler == eCompiler.VS2010)
                destinationFolder = PreferencesManager.Instance.ThirdPartyDownloadFolder + "/vs2010/x64/";

            Process p = new Process();
            ProcessStartInfo info = info = new ProcessStartInfo("cmd.exe", @"%comspec% /k """ + Compiler.GetCompilerPath(compiler) + @"\VC\vcvarsall.bat"" amd64");

            info.RedirectStandardInput = true;
            info.UseShellExecute = false;
            info.RedirectStandardOutput = true;
            info.RedirectStandardError = true;

            p.StartInfo = info;
            p.Start();
            
            using (StreamWriter sw = p.StandardInput)
            {
                if (sw.BaseStream.CanWrite)
                {
                    sw.WriteLine("cd " + destinationFolder + "qt-everywhere-opensource-src-4.8.3");
                    sw.WriteLine("configure -mp -opensource -nomake demos -nomake examples -platform win32-msvc2010");
                    sw.WriteLine("y");

                   // sw.WriteLine(@"jom && jom clean");
                }
            }
            
            readStandardOutput(p);
            readStandardError(p);

            p.WaitForExit();
            p.Close();
        }

        private void buildQT4_8_3()
        {
            string destinationFolder = DetermineDestinationFolder();
            eCompiler compiler = DetermineSelectedCompiler();
       
            Process p = new Process();
            ProcessStartInfo info = null;
            Compiler.GetCompilerPath(compiler);

            info = new ProcessStartInfo("cmd.exe", @"%comspec% /k """ + Compiler.GetCompilerPath(compiler) + @"\VC\vcvarsall.bat"" amd64");

            info.RedirectStandardInput = true;
            info.UseShellExecute = false;
            info.RedirectStandardOutput = true;
            info.RedirectStandardError = false;

            p.StartInfo = info;
            p.Start();
            
            using (StreamWriter sw = p.StandardInput)
            {
                if (sw.BaseStream.CanWrite)
                {
                    sw.WriteLine("cd " + destinationFolder + "qt-everywhere-opensource-src-4.8.3");
                    sw.WriteLine(@"nmake");
                }
            }
            
            readStandardOutput(p);

            p.WaitForExit();
            p.Close();
        }

        BlueGo.GUI.FormPrefernces m_FormPreferences = new BlueGo.GUI.FormPrefernces();
 
        List<BlueGo.Data.ApplicationInfo> appInfoList = new List<BlueGo.Data.ApplicationInfo>();

        private void CheckForUpdates()
        {
            try
            {
                WebClient client = new WebClient();
                Stream data = client.OpenRead("http://www.vertexwahn.de/bluego.xml");
                StreamReader reader = new StreamReader(data);
                XmlTextReader xmlReader = new XmlTextReader(reader);
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.Load(xmlReader);

                XmlNode xmlInfo = xmlDoc.SelectSingleNode("BlueGo/Info");
                string strVersion = xmlInfo.Attributes["Version"].InnerText;
                string strDownloadLink = xmlInfo.Attributes["DownloadLink"].InnerText;

                if (strVersion != "0.0.7")
                {
                    //MessageBox.Show("A new version of BlueGo is available (BlueGo " + strVersion + "). It can be downloaded from " + strDownloadLink, "BlueGo");
                    FormUpdate formUpdate = new FormUpdate();
                    formUpdate.Clean(strVersion, strDownloadLink);
                    formUpdate.ShowDialog();
                }

                reader.Close();
                data.Close();
                reader.Close();
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }

        private void FormMain_Load(object sender, EventArgs e)
        {
            CheckForUpdates();

            // Fill gui elements
            List<BoostInfo> boostInfoList = BoostInfo.CreateBoostInfoList();
            boostInfoList.Reverse();
            foreach(BoostInfo bi in boostInfoList)
            {
                comboBoxbBoostVersion.Items.Add(BoostInfo.BoostVersionToString(bi.Version));
            }

            if (comboBoxbBoostVersion.Items.Count > 0)
                comboBoxbBoostVersion.SelectedIndex = 0;

            if (comboBoxPlatform.Items.Count > 0)
                comboBoxPlatform.SelectedIndex = 0;

            if (comboBoxCompiler.Items.Count > 0)
                comboBoxCompiler.SelectedIndex = 0;

            if (comboBoxQtVersion.Items.Count > 0)
                comboBoxQtVersion.SelectedIndex = 0;

            appInfoList = BlueGo.Data.ApplicationInfo.Load("applications.xml");

            foreach (BlueGo.Data.ApplicationInfo ai in appInfoList)
            {
                checkedListBoxApplications.Items.Add(ai.Name);
            }
        }

        private void buttonDonloadApplications_Click(object sender, EventArgs e)
        {
            buttonDonloadApplications.Enabled = false;

            if (!Directory.Exists(PreferencesManager.Instance.ApplicationDownloadFolder))
            {
                Directory.CreateDirectory(PreferencesManager.Instance.ApplicationDownloadFolder);
            }

            for(int i = 0; i < checkedListBoxApplications.Items.Count; i++)
            {
                if( checkedListBoxApplications.GetItemChecked(i) )
                {
                    // Download boost
                    DownloadHelper.DownloadFileFromURL(appInfoList[i].DownloadUrl, PreferencesManager.Instance.ApplicationDownloadFolder + "\\" + appInfoList[i].Filename);
                }
            }
            
            buttonDonloadApplications.Enabled = true;
        }

        private void exitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
        {
            MessageBox.Show("BlueGo by Vertexwahn", "BlueGo");
        }

        static void GetInstalled()
        {
            string uninstallKey = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";
            using (RegistryKey rk = Registry.LocalMachine.OpenSubKey(uninstallKey))
            {
                foreach (string skName in rk.GetSubKeyNames())
                {
                    using (RegistryKey sk = rk.OpenSubKey(skName))
                    {
                        Console.WriteLine(sk.GetValue("DisplayName"));
                    }
                }
            }
        }

        private void buttonQT_Click(object sender, EventArgs e)
        {
            eCompiler compiler = DetermineSelectedCompiler();

            if (!Compiler.IsPresent(compiler))
            {
                ReportCompilerNotPresent(compiler);
                return; // Compiler not present we can not do anything useful
            }
            
            // prevent that user double clicks the qt build button
            buttonBuildQT.Enabled = false;

            // check if perl is available
            if( !System.IO.Directory.Exists(@"C:\strawberry\perl") )
            {
                if (MessageBox.Show("Warning: Perl must be installed in order to build qt. Do you want to continue? (You can use http://strawberryperl.com/) ", 
                    "Warning", 
                    MessageBoxButtons.OKCancel) != DialogResult.OK)
                {
                    buttonBuildQT.Enabled = true;
                    return;
                }

            }
                    
            Thread t = new Thread(new ThreadStart(DownloadAndBuildQT4_8_3_x64));
            t.Start(); 
        }

        private eBoostVersion DetermineSelectedBoostVersion()
        {
            string text = "";
            this.Invoke((MethodInvoker)delegate()
            {
                text = comboBoxbBoostVersion.Text;
            });


            foreach (BoostInfo bi in BoostInfo.CreateBoostInfoList())
            {
                if (BoostInfo.BoostVersionToString(bi.Version) == text)
                    return bi.Version;
            }

            throw new Exception("Unknown Boost Version.");
        }

        eCompiler DetermineSelectedCompiler()
        {
            string text = "";
            this.Invoke((MethodInvoker)delegate()
            {
                text = comboBoxCompiler.Text;
            });

            if (text == "Microsoft Visual Studio 2010")
            {
                return eCompiler.VS2010;
            }

            if (text == "Microsoft Visual Studio 2012")
            {
                return eCompiler.VS2012;
            }

            throw new Exception("Invalid compiler selected");
            //return eCompiler.Unknown;
        }

        void ReportCompilerNotPresent(eCompiler compiler)
        {
            MessageBox.Show("Error: Selected Compiler is not present.", "BlueGo",
                MessageBoxButtons.OK, MessageBoxIcon.Error);
        }

        private void buttonBoostBuild_Click(object sender, EventArgs e)
        { 
            eCompiler compiler = DetermineSelectedCompiler();

            if (!Compiler.IsPresent(compiler))
            {
                ReportCompilerNotPresent(compiler);
                return; // Compiler not present we can not do anything useful
            }

            // Lock GUI
            buttonBoostBuild.Enabled = false;

            /*
            Thread t = new Thread(new ThreadStart(DownloadAndBuildBoost_x64));
            t.Start();
            */

            boostBuildProcessDescripton bbpd = new boostBuildProcessDescripton();
            bbpd.boostVersion = DetermineSelectedBoostVersion();
            bbpd.compilerType = compiler;
            bbpd.coreCount = coreCount;
            bbpd.destinationFolder = DetermineDestinationFolder();
            BoostBuildProcess boostBuildProcess = new BoostBuildProcess(bbpd);

            boostBuildProcess.Message += new MessageEventHandler(boostBuildProcess_Message);
            boostBuildProcess.StandardOutputMessage += new StandardOutputMessageEventHandler(boostBuildProcess_StandardOutputMessage);
            boostBuildProcess.StandardErrorMessage += new StandardErrorMessageEventHandler(boostBuildProcess_StandardErrorMessage);
            boostBuildProcess.Finished += new FinishedEventHandler(boostBuildProcess_Finished);

            Thread workerThread = new Thread(boostBuildProcess.DownloadAndBuildBoost_x64);
            workerThread.Start();
        }

        void boostBuildProcess_StandardErrorMessage(object sender, string message)
        {
            this.Invoke((MethodInvoker)delegate
            {
                listBoxLogOutput.Items.Add(message);
                //listBox1.EnsureVisible(listBox1.Items.Count - 1);
            });
        }

        void boostBuildProcess_StandardOutputMessage(object sender, string message)
        {
            this.Invoke((MethodInvoker)delegate
            {
                listBoxLogOutput.Items.Add(message);
                //listBox1.EnsureVisible(listBox1.Items.Count - 1);
            });
        }

        void boostBuildProcess_Finished(object sender)
        {
            UnlockBoostBuildButton();
        }

        void boostBuildProcess_Message(object sender, string message)
        {
            this.message(message);
        }

        private static void CheckDestinationFolder(string destinationFolder)
        {
            if (!System.IO.File.Exists(destinationFolder))
            {
                throw new Exception("Destination folder does not exist " + destinationFolder);
            }
        }

        private void SetWindowTitleStatusInfo(String statusInfo)
        {
            string windowTitle = "BlueGo (0.0.7) [" + statusInfo + "]";
        
            this.Invoke((MethodInvoker)delegate()
            {
                this.Text = windowTitle;
            });
        }

        private void UnlockBoostBuildButton()
        {
            this.Invoke((MethodInvoker)delegate()
            {
                this.buttonBoostBuild.Enabled = true;
            });
        }

        private void UnlockQtBuildButton()
        {
            this.Invoke((MethodInvoker)delegate()
            {
                buttonBuildQT.Enabled = false;
            });
        }

        private void buttonCMakeBrowseSource_Click(object sender, EventArgs e)
        {
            System.Windows.Forms.FolderBrowserDialog objDialog = new FolderBrowserDialog();
            objDialog.Description = "Select the source folder";
            objDialog.SelectedPath = @"C:\";       
            DialogResult objResult = objDialog.ShowDialog(this);
            if (objResult == DialogResult.OK)
            {
                textBoxCMakeSource.Text = objDialog.SelectedPath;
            }               
        }

        private void buttonCMakeBrowseBuild_Click(object sender, EventArgs e)
        {
            System.Windows.Forms.FolderBrowserDialog objDialog = new FolderBrowserDialog();
            objDialog.Description = "Select the build folder";
            objDialog.SelectedPath = @"C:\";      
            DialogResult objResult = objDialog.ShowDialog(this);
            if (objResult == DialogResult.OK)
            {
                textBoxCMakeBinariesFolder.Text = objDialog.SelectedPath;
            }         
        }

        private void buttonCMakeGo_Click(object sender, EventArgs e)
        {
            MessageBox.Show("This will create a batch (BlueGo.bat) in your source folder which can be used to run CMake.");

            // Open CMakeLists.txt
            string filename = textBoxCMakeSource.Text + @"\CMakeLists.txt";
            StreamReader sr;
            sr = File.OpenText(filename);


            List<Package> packages = new List<Package>();

            // find out which packages are needed
            string s = sr.ReadLine();
            
            while (s != null)
            {
                if (s.Contains("find_package"))
                {
                    listBoxLogOutput.Items.Add(s);

                    if (s.Contains("DirectX"))
                    {
                        listBoxLogOutput.Items.Add("DirectX needed!");

                        packages.Add(new Package("DirectX"));
                    }
                    if (s.Contains("VLD"))
                    {
                        listBoxLogOutput.Items.Add("VLD needed!");

                        packages.Add(new Package("VLD"));
                    }
                    if (s.Contains("OptiX"))
                    {
                        listBoxLogOutput.Items.Add("OptiX needed!");

                        packages.Add(new Package("OptiX"));
                    }
                    if (s.Contains("CUDA"))
                    {
                        listBoxLogOutput.Items.Add("CUDA needed!");
                        packages.Add(new Package("CUDA"));
                    }
                    if (s.Contains("Qt4"))
                    {
                        listBoxLogOutput.Items.Add("Qt4 needed!");
                        packages.Add(new Package("Qt4"));
                    }
                    if (s.Contains("Boost"))
                    {
                        listBoxLogOutput.Items.Add("Boost needed!");
                        packages.Add(new Package("Boost"));
                    }
                }
                
                s = sr.ReadLine();
            }

            string batchFile = "";

            batchFile += "cd " + textBoxCMakeBinariesFolder.Text + Environment.NewLine;
            batchFile += "\"C:\\Program Files (x86)\\CMake 2.8\\bin\\cmake\"" + " " +
                         "-G\"Visual Studio 10 Win64\"" + " " +
                         "-H\"" + textBoxCMakeSource.Text + "\" " +
                         "-B\"" + textBoxCMakeBinariesFolder.Text + "\" " + 
                         "-DQT_QMAKE_EXECUTABLE=\"C:\\thirdparty\\qt-everywhere-opensource-src-4.8.3\\bin\\qmake.exe" + " " +
                         "-DBOOST_ROOT=\"C:\\thirdparty\\vs2010\\x64\\boost_1_52_0" + " " +
                         "-DVLD_ROOT_DIR=\"C:\\Program Files (x86)\\Visual Leak Detector\"" + " " +
                         Environment.NewLine;
            batchFile += "cd " + textBoxCMakeSource.Text + Environment.NewLine;

            using (StreamWriter outfile = new StreamWriter(textBoxCMakeSource.Text + @"\BlueGo.bat"))
            {
                outfile.Write(batchFile);
            }
        }
    }
}