Rev 67 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
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.Diagnostics;using System.Threading;namespace SWAT_USB_App{public partial class Software_Form : Form{private static List<string> subGroups = new List<string>();private static List<Process> toInstall = new List<Process>();private static List<CheckBox> formCheckBoxes = new List<CheckBox>();private static List<RadioButton> formRadioButton = new List<RadioButton>();public Software_Form(){// Draws the form with a checkbox for each software specified in the text fileInitializeComponent();try{Debug.appendText("Software form initializing");// Clears all listssubGroups.Clear();toInstall.Clear();formCheckBoxes.Clear();formRadioButton.Clear();// Location placeholderint nextXLocation = 6, nextYLocation = 19;// Extracts all groups from ApplicationsListfor (int i = 0; i < SettingsParser.ApplicationsList.Count(); i++)if (SettingsParser.ApplicationsList[i].Group != null){// Check if group exists alreadybool groupExist = false;for (int j = 0; j < subGroups.Count(); j++)if (SettingsParser.ApplicationsList[i].Group == subGroups[j]){groupExist = true;break;}if (!groupExist)subGroups.Add(SettingsParser.ApplicationsList[i].Group);}// Updates the groupbox size to hold all the checkboxes and subgroupsthis.groupBox_SoftwareList.Size = new Size(SettingsParser.softwareFormWidth - 30, 19 + SettingsParser.ApplicationsList.Count() * 23 + (subGroups.Count() * 25));// Updates the window size to hold all elementsthis.Size = new Size(SettingsParser.softwareFormWidth, 101 + SettingsParser.ApplicationsList.Count() * 23 + (subGroups.Count() * 25));// Adds a checkbox for each software item that is ungrouped, adds checkbox to list formCheckBoxesfor (int i = 0; i < SettingsParser.ApplicationsList.Count(); i++){if (SettingsParser.ApplicationsList[i].Group == null){// Creates a new checkboxCheckBox chkBox = new CheckBox();chkBox.Name = "chk_" + SettingsParser.ApplicationsList[i].Name;chkBox.AutoSize = true;chkBox.Text = SettingsParser.ApplicationsList[i].Name;if (SettingsParser.ApplicationsList[i].Default)chkBox.Checked = true;chkBox.Location = new Point(nextXLocation, nextYLocation);// Increments the location placeholder for the next elementnextYLocation += 23;// Adds the checkbox to the parent groupboxthis.groupBox_SoftwareList.Controls.Add(chkBox);// Adds the checkbox to formCheckBoxes listformCheckBoxes.Add(chkBox);}}// Adds a groupbox for each entry specified in subGroups as well as any applications under the groupfor (int i = 0; i < subGroups.Count(); i++){// Sets the internal location coordinates for the next elementint subNextXLocation = 6;int subNextYLocation = 19;// Creates a new groupboxGroupBox grpBox = new GroupBox();grpBox.Name = "grp_" + subGroups[i];grpBox.Text = subGroups[i];// Finds the number of applications under the groupint numberOfSubentries = 0;for (int j = 0; j < SettingsParser.ApplicationsList.Count(); j++)if (SettingsParser.ApplicationsList[j].Group == subGroups[i]){// If the group matches, creates a new radiobuttonnumberOfSubentries++;RadioButton rdoBtn = new RadioButton();rdoBtn.Name = "rdo_" + SettingsParser.ApplicationsList[j].Name;rdoBtn.AutoSize = true;rdoBtn.Text = SettingsParser.ApplicationsList[j].Name;if (SettingsParser.ApplicationsList[j].Default)rdoBtn.Checked = true;rdoBtn.Location = new Point(subNextXLocation, subNextYLocation);// Increments the location placeholder for the next elementsubNextYLocation += 23;// Adds the radiobutton to the parent groupboxgrpBox.Controls.Add(rdoBtn);// Adds the radiobutton to formRadioButton listformRadioButton.Add(rdoBtn);}grpBox.Size = new Size(SettingsParser.softwareFormWidth - 42, 19 + numberOfSubentries * 23);grpBox.Location = new Point(nextXLocation, nextYLocation);nextYLocation += 25 + numberOfSubentries * 23;// Adds the created groupbox to the parent groupboxthis.groupBox_SoftwareList.Controls.Add(grpBox);}}catch (Exception ex){Debug.appendText("Exception Thrown: " + ex.ToString());MessageBox.Show(ex.ToString());}}private void updateToInstallList(){try{Debug.appendText("Updating list of processes to run from list of software checked");// Updates list toInstall with processes for each software checked in formCheckBoxesfor (int i = 0; i < formCheckBoxes.Count(); i++){if (formCheckBoxes[i].Checked){string[] temp = null;// Pulls the setup locationsfor (int j = 0; j < SettingsParser.ApplicationsList.Count(); j++)if (SettingsParser.ApplicationsList[j].Name == formCheckBoxes[i].Text){temp = SettingsParser.ApplicationsList[j].SetupFileLocation;break;}for (int j = 0; j < temp.Count(); j += 2){Process proc = new Process();proc.StartInfo.FileName = Initialization.pathToSWATDrive + temp[j];proc.StartInfo.Arguments = temp[j + 1];toInstall.Add(proc);}}}// Updates list toInstall with processes for each software checked in formRadioButtonfor (int i = 0; i < formRadioButton.Count(); i++){if (formRadioButton[i].Checked){string[] temp = null;// Pulls the setup locationsfor (int j = 0; j < SettingsParser.ApplicationsList.Count(); j++)if (SettingsParser.ApplicationsList[j].Name == formRadioButton[i].Text){temp = SettingsParser.ApplicationsList[j].SetupFileLocation;break;}for (int j = 0; j < temp.Count(); j += 2){Process proc = new Process();proc.StartInfo.FileName = Initialization.pathToSWATDrive + temp[j];proc.StartInfo.Arguments = temp[j + 1];toInstall.Add(proc);}}}}catch (Exception e){Debug.appendText("Exception Thrown: " + e.ToString());MessageBox.Show(e.ToString());}}private void startSoftwareInstaller(List<Process> toInstall, int ID){Debug.appendText("Starting to install softwares from list of processes");try{this.WindowState = FormWindowState.Minimized;// Goes through list toInstall and runs each process after the previous one endsint tempID = ID;if (tempID < toInstall.Count){Debug.appendText("Running setup " + toInstall[ID].StartInfo.FileName + " with arguments " + toInstall[ID].StartInfo.Arguments);toInstall[ID].Start();while (!toInstall[ID].HasExited){// Waits for installer to finish before starting the next oneThread.Sleep(3000);}if (toInstall[ID].HasExited){Debug.appendText("Setup is detected as finished, running next setup");tempID++;startSoftwareInstaller(toInstall, tempID);}}this.WindowState = FormWindowState.Normal;}catch (Exception e){Debug.appendText("Exception Thrown: " + e.ToString());MessageBox.Show(e.ToString());}}private void btn_Ok_Click(object sender, EventArgs e){updateToInstallList();startSoftwareInstaller(toInstall, 0);this.Close();}private void btn_Cancel_Click(object sender, EventArgs e){Debug.appendText("Closing software form");this.Close();}private void btn_Reset_Click(object sender, EventArgs e){for (int i = 0; i < formCheckBoxes.Count(); i++)formCheckBoxes[i].Checked = false;for (int i = 0; i < formRadioButton.Count(); i++)formRadioButton[i].Checked = false;}}}