diff --git a/AllPurposeAutoSetup/GutsConfigFileManager.cs b/AllPurposeAutoSetup/GutsConfigFileManager.cs index 7ae1ccc..c407b63 100644 --- a/AllPurposeAutoSetup/GutsConfigFileManager.cs +++ b/AllPurposeAutoSetup/GutsConfigFileManager.cs @@ -1,23 +1,11 @@ using System; using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; -using System.Threading; -using System.Diagnostics; -using System.Text.RegularExpressions; -using System.IO; -using System.Security.AccessControl; -using System.Management; -using System.Security.Principal; -using System.Runtime.InteropServices; -using Microsoft.Win32; using System.Drawing; - -using CommonLib.Windows.Forms; +using System.IO; +using System.Windows.Forms; using CommonLib.IO; using CommonLib.Misc; +using CommonLib.Windows.Forms; namespace All_Purpose_Auto_Setup { diff --git a/AllPurposeAutoSetup/GutsSoftwareBuildAssistant.cs b/AllPurposeAutoSetup/GutsSoftwareBuildAssistant.cs index e6390d0..f220a48 100644 --- a/AllPurposeAutoSetup/GutsSoftwareBuildAssistant.cs +++ b/AllPurposeAutoSetup/GutsSoftwareBuildAssistant.cs @@ -1,24 +1,14 @@ using System; using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; -using System.Threading; using System.Diagnostics; -using System.Text.RegularExpressions; -using System.IO; -using System.Security.AccessControl; -using System.Management; -using System.Security.Principal; -using System.Runtime.InteropServices; -using Microsoft.Win32; using System.Drawing; - -using CommonLib.Windows.Forms; +using System.IO; +using System.Text; +using System.Text.RegularExpressions; +using System.Windows.Forms; using CommonLib.IO; using CommonLib.Misc; +using CommonLib.Windows.Forms; namespace All_Purpose_Auto_Setup { @@ -249,7 +239,7 @@ namespace All_Purpose_Auto_Setup } else if (additionalFileMissing.Length > 0) { - ((frmSetupStatusDisplay)m_parentForm).displayMessageBox(MessageBoxCustom.PopUpMsgType.INFO, null, "File \"" + additionalFileMissing + "\" is missing. \n\nProceeding with running pre-build script to create necessary files." , "Info", -1); + ((frmSetupStatusDisplay)m_parentForm).displayMessageBox(MessageBoxCustom.PopUpMsgType.INFO, null, "File \"" + additionalFileMissing + "\" is missing. \n\nProceeding with running pre-build script to create necessary files.", "Info", -1); } else { @@ -283,7 +273,7 @@ namespace All_Purpose_Auto_Setup setupSuccessful = false; } - if ( msg.Length > 0 ) + if (msg.Length > 0) UpdateStatusDisplayAndLogEvent(msg, msg, textPropList); } @@ -536,7 +526,7 @@ namespace All_Purpose_Auto_Setup textProp.textFont = new Font(textProp.textFont, FontStyle.Bold); textPropList.Add(textProp); - if (errMsg.Length > 0 ) + if (errMsg.Length > 0) msg = " - FAILED. " + errMsg; else msg = " - FAILED. " + additionalFileMissing + " not found."; diff --git a/AllPurposeAutoSetup/Important_Files/Examples/Config_Files/config_NGI.ini b/AllPurposeAutoSetup/Important_Files/Examples/Config_Files/config_NGI.ini index c04b92c..e27a050 100644 --- a/AllPurposeAutoSetup/Important_Files/Examples/Config_Files/config_NGI.ini +++ b/AllPurposeAutoSetup/Important_Files/Examples/Config_Files/config_NGI.ini @@ -146,12 +146,22 @@ step = INSTALL_SOFTWARE_PACKAGES,Install_Software ; ; ****************************************************************************************************************************** [Install_Software] -app5_name = Visual Studio 2022 -app5_setup_argument = -p --norestart --noweb --add Microsoft.VisualStudio.Workload.ManagedDesktop;includeRecommended Microsoft.VisualStudio.Workload.NativeDesktop;includeRecommended Microsoft.VisualStudio.Component.VC.ATLMFC Microsoft.VisualStudio.Component.VC.CLI.Support Microsoft.VisualStudio.Workload.VisualStudioExtension;includeRecommended -app5_reg_path = VisualStudio.DTE.17.0 -app5_reg_type = classes_root -app5_setup_file = D:\Windows_Stuff\Visual_Studio_2022.17.9.5\vs_setup.exe -app5_install_process_name = setup +;app5_name = Visual Studio 2022 +;app5_setup_argument = -p --norestart --noweb --add Microsoft.VisualStudio.Workload.ManagedDesktop;includeRecommended Microsoft.VisualStudio.Workload.NativeDesktop;includeRecommended Microsoft.VisualStudio.Component.VC.ATLMFC Microsoft.VisualStudio.Component.VC.CLI.Support Microsoft.VisualStudio.Workload.VisualStudioExtension;includeRecommended +;app5_reg_path = VisualStudio.DTE.17.0 +;app5_reg_type = classes_root +;app5_setup_file = D:\Windows_Stuff\Visual_Studio_2022.17.9.5\vs_setup.exe +;app5_install_process_name = setup + +app6_name = TestStand 2019 +app6_reg_display_name = NI TestStand (32-bit) +app6_reg_type = local_machine +app62_reg_value = 19 +app62_reg_name = DisplayVersion +app62_reg_compare = gte +app6_setup_file = C:\Users\Duc\Desktop\TestStand_2019\Install.exe +app6_spawned_processes_to_ignore = nierserver +app6_reboot_computer_at_completion = true ; ****************************************************************************************************************************** ; THIS SECTION IS OPTIONAL diff --git a/AllPurposeAutoSetup/NetworkAdapterManager.cs b/AllPurposeAutoSetup/NetworkAdapterManager.cs index 89b3618..5f48bef 100644 --- a/AllPurposeAutoSetup/NetworkAdapterManager.cs +++ b/AllPurposeAutoSetup/NetworkAdapterManager.cs @@ -1,25 +1,13 @@ using System; using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; -using System.Threading; -using System.Diagnostics; -using System.Text.RegularExpressions; -using System.IO; -using System.Security.AccessControl; -using System.Management; -using System.Security.Principal; -using System.Runtime.InteropServices; -using Microsoft.Win32; using System.Drawing; - -using CommonLib.Windows.Forms; -using CommonLib.Windows.Misc; -using CommonLib.IO; +using System.Linq; +using System.Management; +using System.Text.RegularExpressions; +using System.Threading; +using System.Windows.Forms; using CommonLib.Misc; +using CommonLib.Windows.Misc; namespace All_Purpose_Auto_Setup { @@ -265,7 +253,7 @@ namespace All_Purpose_Auto_Setup setupSuccessful = NetworkManagement.SetNetworkAdapterIpAddress(networkAdapterConfiguration, networkAdapterIp, networkAdapterSubnetMask, ref errMsg); indentation = Common.getIndentation(1); - msg = "\n" + indentation + "Setting IP=" + networkAdapterIp + " and subnet=" + networkAdapterSubnetMask + " for network adapter at PCI Location " + pciLocation; + msg = "\n" + indentation + "Setting IP=" + networkAdapterIp + " and subnet=" + networkAdapterSubnetMask + " for network adapter at PCI Location " + pciLocation; if (setupSuccessful) { @@ -298,7 +286,7 @@ namespace All_Purpose_Auto_Setup UpdateStatusDisplayAndLogEvent(msg2, msg2, textPropList2); } - if (setupSuccessful && networkAdapterDefaultGateway.Length > 0 ) + if (setupSuccessful && networkAdapterDefaultGateway.Length > 0) { setupSuccessful = NetworkManagement.SetNetworkAdapterDefaultGateway(networkAdapterConfiguration, networkAdapterDefaultGateway, ref errMsg); @@ -540,7 +528,7 @@ namespace All_Purpose_Auto_Setup string[] ips = iniKey.iniValue.Split(','); ips[0] = ips[0].Trim(); - if ( ips.Length > 1) + if (ips.Length > 1) ips[1] = ips[1].Trim(); List ipList = new List(ips); diff --git a/AllPurposeAutoSetup/RunApplicationsManager.cs b/AllPurposeAutoSetup/RunApplicationsManager.cs index 9e60e1a..b239638 100644 --- a/AllPurposeAutoSetup/RunApplicationsManager.cs +++ b/AllPurposeAutoSetup/RunApplicationsManager.cs @@ -1,24 +1,16 @@ using System; using System.Collections.Generic; using System.ComponentModel; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; -using System.Threading; using System.Diagnostics; -using System.Text.RegularExpressions; -using System.IO; -using System.Security.AccessControl; -using System.Management; -using System.Security.Principal; -using System.Runtime.InteropServices; -using Microsoft.Win32; using System.Drawing; - -using CommonLib.Windows.Forms; +using System.IO; +using System.Linq; +using System.Text.RegularExpressions; +using System.Threading; +using System.Windows.Forms; using CommonLib.IO; using CommonLib.Misc; +using CommonLib.Windows.Forms; namespace All_Purpose_Auto_Setup { @@ -194,8 +186,8 @@ namespace All_Purpose_Auto_Setup { Hardware.OpenCdDrive(drive.Name); - tempMsg = "Please insert a disc"; - + tempMsg = "Please insert a disc"; + if (cdLabel.Length > 0) tempMsg += " labeled \"" + cdLabel + "\""; @@ -401,7 +393,7 @@ namespace All_Purpose_Auto_Setup { // since we are receiving everything that's being output to the standard output // we're only interested in the response of the command, and not the command itself - if ( !Regex.IsMatch(e.Data, @"^[a-zA-Z]:[^>]+>.+", RegexOptions.IgnoreCase)) + if (!Regex.IsMatch(e.Data, @"^[a-zA-Z]:[^>]+>.+", RegexOptions.IgnoreCase)) m_consoleAppStatusMessage = e.Data; } } @@ -611,7 +603,7 @@ namespace All_Purpose_Auto_Setup ((frmSetupStatusDisplay)m_parentForm).displayMessageBox(MessageBoxCustom.PopUpMsgType.INFO, null, msg, "Info", -1); - m_parentForm.Invoke((MethodInvoker)(() => + m_parentForm.Invoke((MethodInvoker)(() => { OpenFileDialog openFileDialog1 = new OpenFileDialog(); @@ -786,10 +778,10 @@ namespace All_Purpose_Auto_Setup // if the macro in the argument refers to another key the defines a path if (matchedPathIndex >= 0 && !idToPath.ContainsKey(matches[i].Groups[0].Value)) { - if (PathManip.PathIsFile(entry.Value[matchedPathIndex].iniValue)) - idToPath[matches[i].Groups[0].Value] = Path.GetDirectoryName(Path.GetFullPath(entry.Value[matchedPathIndex].iniValue)); - else - idToPath[matches[i].Groups[0].Value] = Path.GetFullPath(entry.Value[matchedPathIndex].iniValue); + if (PathManip.PathIsFile(entry.Value[matchedPathIndex].iniValue)) + idToPath[matches[i].Groups[0].Value] = Path.GetDirectoryName(Path.GetFullPath(entry.Value[matchedPathIndex].iniValue)); + else + idToPath[matches[i].Groups[0].Value] = Path.GetFullPath(entry.Value[matchedPathIndex].iniValue); } // if the macro in the argument refers to the path defined by primary key app#_path @@ -888,7 +880,7 @@ namespace All_Purpose_Auto_Setup if (setupSuccessful) { if (idToPath.Count > 0) - { + { // goes through each marco in the argument ini key and replace with actual paths foreach (KeyValuePair item in idToPath) { @@ -899,7 +891,7 @@ namespace All_Purpose_Auto_Setup tempOneToManyDict[iniVal][matchedArgumentIndex] = iniVal2; } - } + } } processedEntry = new KeyValuePair, List>>(iniVal, new List>(tempOneToManyDict[iniVal])); diff --git a/AllPurposeAutoSetup/SetupMiscellaneous.cs b/AllPurposeAutoSetup/SetupMiscellaneous.cs index a176965..8a48ffa 100644 --- a/AllPurposeAutoSetup/SetupMiscellaneous.cs +++ b/AllPurposeAutoSetup/SetupMiscellaneous.cs @@ -1,24 +1,11 @@ using System; using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; -using System.Threading; -using System.Diagnostics; -using System.Text.RegularExpressions; -using System.IO; -using System.Security.AccessControl; -using System.Management; -using System.Security.Principal; -using System.Runtime.InteropServices; -using Microsoft.Win32; using System.Drawing; - -using CommonLib.Windows.Forms; +using System.Text.RegularExpressions; +using System.Windows.Forms; using CommonLib.IO; using CommonLib.Misc; -using CommonLib.Windows.Misc; +using CommonLib.Windows.Forms; namespace All_Purpose_Auto_Setup { @@ -407,14 +394,14 @@ namespace All_Purpose_Auto_Setup displayMsg = Regex.Replace(userPrompt["prompt_message"], @"\{newline\}", "\n"); - if ( String.Equals(userPrompt["prompt_message_type"], MessageBoxCustom.PopUpMsgType.YESNO.ToString(), StringComparison.CurrentCultureIgnoreCase)) + if (String.Equals(userPrompt["prompt_message_type"], MessageBoxCustom.PopUpMsgType.YESNO.ToString(), StringComparison.CurrentCultureIgnoreCase)) result = ((frmSetupStatusDisplay)m_parentForm).displayMessageBox(MessageBoxCustom.PopUpMsgType.YESNO, null, displayMsg, "Info", -1); else if (String.Equals(userPrompt["prompt_message_type"], MessageBoxCustom.PopUpMsgType.OKCANCEL.ToString(), StringComparison.CurrentCultureIgnoreCase)) result = ((frmSetupStatusDisplay)m_parentForm).displayMessageBox(MessageBoxCustom.PopUpMsgType.OKCANCEL, null, displayMsg, "Info", -1); else result = ((frmSetupStatusDisplay)m_parentForm).displayMessageBox(MessageBoxCustom.PopUpMsgType.INFO, null, displayMsg, "Info", -1); - if ( Regex.IsMatch(result, @"(yes|ok)", RegexOptions.IgnoreCase)) + if (Regex.IsMatch(result, @"(yes|ok)", RegexOptions.IgnoreCase)) { msg += " - SUCCESS."; diff --git a/AllPurposeAutoSetup/SoftwareInstallManager.cs b/AllPurposeAutoSetup/SoftwareInstallManager.cs index 1adb8a3..b93d465 100644 --- a/AllPurposeAutoSetup/SoftwareInstallManager.cs +++ b/AllPurposeAutoSetup/SoftwareInstallManager.cs @@ -1,1245 +1,1417 @@ using System; using System.Collections.Generic; using System.ComponentModel; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; -using System.Threading; using System.Diagnostics; -using System.Text.RegularExpressions; -using System.IO; -using System.Security.AccessControl; -using System.Management; -using System.Security.Principal; -using System.Runtime.InteropServices; -using Microsoft.Win32; using System.Drawing; - -using CommonLib.Windows.Forms; +using System.IO; +using System.Linq; +using System.Management; +using System.Text.RegularExpressions; +using System.Threading; +using System.Windows.Forms; using CommonLib.IO; using CommonLib.Misc; +using CommonLib.Windows.Forms; using CommonLib.Windows.Misc; -using CommonLib.Runtime.InteropServices; +using Microsoft.Win32; namespace All_Purpose_Auto_Setup { - class SoftwareInstallManager - { + class SoftwareInstallManager + { - // An event that can be raised, allowing other classes to - // subscribe to it and do what they like with the message. - public event Action> UpdateStatusDisplayAndLogEvent; + // An event that can be raised, allowing other classes to + // subscribe to it and do what they like with the message. + public event Action> UpdateStatusDisplayAndLogEvent; - public event Action> UpdateStatusDisplayAtLine; + public event Action> UpdateStatusDisplayAtLine; - public event Action RebootComputer; + public event Action RebootComputer; - public event Action SetupProcessNeedRestartToProceed; + public event Action SetupProcessNeedRestartToProceed; - // event for thread to notify other threads that it has exited - private AutoResetEvent _resetEvent = new AutoResetEvent(false); + // event for thread to notify other threads that it has exited + private AutoResetEvent _resetEvent = new AutoResetEvent(false); - // this dictionary stores application name and its associated setup file and exe file - // it would look like this: - // [ app1_name ] -> List[setup_file exe_file setup_args] - // [ app2_name ] -> List[setup_file setup_args reg_path reg_type ...] - public Dictionary, List>> appNameToInstallerAndExe = new Dictionary, List>>(); + // this dictionary stores application name and its associated setup file and exe file + // it would look like this: + // [ app1_name ] -> List[setup_file exe_file setup_args] + // [ app2_name ] -> List[setup_file setup_args reg_path reg_type ...] + public Dictionary, List>> appNameToInstallerAndExe = new Dictionary, List>>(); - int m_progressLine = 0; + int m_progressLine = 0; - Form m_parentForm; + Form m_parentForm; - public SoftwareInstallManager(Form parentForm) - { - m_parentForm = parentForm; - } + public SoftwareInstallManager(Form parentForm) + { + m_parentForm = parentForm; + } - public bool manageRequiredSoftwarePackages(string sectionName) - { - bool setupSuccessful = true; - string msg, indentation = String.Empty; - string setupFile, exeFile, registryPath, registryDisplayName, registryType, registryName, registryValue, registryCompareOperator, installArgs, - exitCodesToIgnore, installProcessName; - bool promptBeforeInstallation = false, rebootComputerAtCompletionRequested = false, rebootComputerImmediatelyRequested = false; + public bool manageRequiredSoftwarePackages(string sectionName) + { + bool setupSuccessful = true; + string msg, indentation = String.Empty; + string setupFile, exeFile, registryPath, registryDisplayName, registryType, registryName, registryValue, registryCompareOperator, installArgs, + exitCodesToIgnore, spawnedProcessesToIgnore; + bool promptBeforeInstallation = false, rebootComputerAtCompletionRequested = false, rebootComputerImmediatelyRequested = false; - CommonLib.Windows.Forms.TextFormat.TextFontAndColor defaultTextProp = new CommonLib.Windows.Forms.TextFormat.TextFontAndColor(""); - CommonLib.Windows.Forms.TextFormat.TextFontAndColor textProp = new CommonLib.Windows.Forms.TextFormat.TextFontAndColor(""); - List textPropList = new List(); + CommonLib.Windows.Forms.TextFormat.TextFontAndColor defaultTextProp = new CommonLib.Windows.Forms.TextFormat.TextFontAndColor(""); + CommonLib.Windows.Forms.TextFormat.TextFontAndColor textProp = new CommonLib.Windows.Forms.TextFormat.TextFontAndColor(""); + List textPropList = new List(); - // set font to default text and color - textProp.textFont = defaultTextProp.textFont; - textProp.textColor = Common.getSetupStepTitleColor(); - textProp.wordIndex = 0; - textProp.wordCount = 100; - textPropList.Add(textProp); + // set font to default text and color + textProp.textFont = defaultTextProp.textFont; + textProp.textColor = Common.getSetupStepTitleColor(); + textProp.wordIndex = 0; + textProp.wordCount = 100; + textPropList.Add(textProp); - DateTime dat1 = DateTime.Now; - msg = "\n\n<-------------------Date and Time: " + dat1.ToString(@"MM/dd/yyyy hh:mm:ss tt", System.Globalization.CultureInfo.InvariantCulture) + "------------------->"; - UpdateStatusDisplayAndLogEvent(msg, msg, textPropList); + DateTime dat1 = DateTime.Now; + msg = "\n\n<-------------------Date and Time: " + dat1.ToString(@"MM/dd/yyyy hh:mm:ss tt", System.Globalization.CultureInfo.InvariantCulture) + "------------------->"; + UpdateStatusDisplayAndLogEvent(msg, msg, textPropList); - // set font to default text and color - textProp.textFont = defaultTextProp.textFont; - textProp.textColor = Common.getSetupStepTitleColor(); - textProp.wordIndex = 0; - textProp.wordCount = 10; - // set font size - textProp.textFont = new Font(textProp.textFont.Name, 12); - // set font style - textProp.textFont = new Font(textProp.textFont, FontStyle.Bold); - textPropList.Add(textProp); + // set font to default text and color + textProp.textFont = defaultTextProp.textFont; + textProp.textColor = Common.getSetupStepTitleColor(); + textProp.wordIndex = 0; + textProp.wordCount = 10; + // set font size + textProp.textFont = new Font(textProp.textFont.Name, 12); + // set font style + textProp.textFont = new Font(textProp.textFont, FontStyle.Bold); + textPropList.Add(textProp); - msg = "\n-=Installing/checking required software packages=-"; - UpdateStatusDisplayAndLogEvent(msg, msg, textPropList); + msg = "\n-=Installing/checking required software packages=-"; + UpdateStatusDisplayAndLogEvent(msg, msg, textPropList); - appNameToInstallerAndExe.Clear(); + appNameToInstallerAndExe.Clear(); - ConfigFileManager.readOneToManyDictionary(ConfigFileManager.ms_configGeneralInfo.iniFile, - sectionName, @"(app\d+)_name$", @"(app\d+)_.+", appNameToInstallerAndExe); + ConfigFileManager.readOneToManyDictionary(ConfigFileManager.ms_configGeneralInfo.iniFile, + sectionName, @"(app\d+)_name$", @"(app\d+)_.+", appNameToInstallerAndExe); - if (setupSuccessful) + if (setupSuccessful) + { + if (appNameToInstallerAndExe.Count == 0 || + (appNameToInstallerAndExe.Count == 1 && appNameToInstallerAndExe.First().Value.Count == 0)) { - if (appNameToInstallerAndExe.Count == 0 || - (appNameToInstallerAndExe.Count == 1 && appNameToInstallerAndExe.First().Value.Count == 0)) - { - // set font to default text and color - textProp.textFont = defaultTextProp.textFont; - textProp.textColor = Common.getSetupStatusColor(Common.EXECUTION_STATUS.SYSTEM_SKIP); - textProp.wordIndex = 0; - textProp.wordCount = 2; - // set font style - textProp.textFont = new Font(textProp.textFont, FontStyle.Bold); - textPropList.Add(textProp); + // set font to default text and color + textProp.textFont = defaultTextProp.textFont; + textProp.textColor = Common.getSetupStatusColor(Common.EXECUTION_STATUS.SYSTEM_SKIP); + textProp.wordIndex = 0; + textProp.wordCount = 2; + // set font style + textProp.textFont = new Font(textProp.textFont, FontStyle.Bold); + textPropList.Add(textProp); - indentation = Common.getIndentation(1); - msg = "\n" + indentation + "- SKIPPED. Nothing to install/check"; - UpdateStatusDisplayAndLogEvent(msg, msg, textPropList); - } - - KeyValuePair, List>> processedConfigInfo = new KeyValuePair, List>>(); - - // for every app name to be installed/checked - foreach (KeyValuePair, List>> entry in appNameToInstallerAndExe) - { - promptBeforeInstallation = false; - setupFile = ""; - exeFile = ""; - registryPath = ""; - registryDisplayName = ""; - registryType = ""; - registryName = ""; - registryValue = ""; - registryCompareOperator = ""; - installArgs = ""; - exitCodesToIgnore = ""; - installProcessName = ""; - rebootComputerAtCompletionRequested = false; - rebootComputerImmediatelyRequested = false; - - - setupSuccessful = processConfigInfo(entry, ref processedConfigInfo); - - if (!setupSuccessful) - break; - - getInfoUsingExeVerification(processedConfigInfo.Value, ref setupFile, ref exeFile, ref promptBeforeInstallation, ref rebootComputerAtCompletionRequested, ref rebootComputerImmediatelyRequested); - getInfoUsingRegistryVerification(processedConfigInfo.Value, ref registryPath, ref registryDisplayName, ref registryType, ref registryName, ref registryValue, ref registryCompareOperator, ref installArgs, ref exitCodesToIgnore, ref installProcessName); - - if (exeFile.Length > 0) - { - setupSuccessful = checkSoftwareExe(processedConfigInfo.Key.iniValue, setupFile, installArgs, exeFile, exitCodesToIgnore, promptBeforeInstallation, rebootComputerAtCompletionRequested, rebootComputerImmediatelyRequested); - } - else - { - setupSuccessful = checkSoftwareRegistry(processedConfigInfo.Key.iniValue, setupFile, promptBeforeInstallation, installArgs, registryPath, - registryDisplayName, registryType, registryName, registryValue, registryCompareOperator, - exitCodesToIgnore, installProcessName, rebootComputerAtCompletionRequested, rebootComputerImmediatelyRequested); - } - - if (!setupSuccessful || ((frmSetupStatusDisplay)m_parentForm).applicationNeedsToBeRestarted()) - break; - } - } - return setupSuccessful; - } - - // check if software is installed - public bool checkSoftwareExe(string softwareName, string setupFile, string setupArgs, string exeFile, string exitCodesToIgnore, bool promptBeforeInstall, bool rebootComputerAtCompletionRequested, bool rebootComputerImmediatelyRequested) - { - bool setupSuccessful = true; - bool installSuccess = true; - bool installExecuted = false; - string msg1, msg2 = "", indentation = String.Empty; - - CommonLib.Windows.Forms.TextFormat.TextFontAndColor defaultTextProp = new CommonLib.Windows.Forms.TextFormat.TextFontAndColor(""); - CommonLib.Windows.Forms.TextFormat.TextFontAndColor textProp = new CommonLib.Windows.Forms.TextFormat.TextFontAndColor(""); - List textPropList1 = new List(); - List textPropList2 = new List(); - - // set font to default text and color - textProp.textFont = defaultTextProp.textFont; - textProp.textColor = Color.FromArgb(233, 31, 195); - textProp.wordIndex = 3; - textProp.wordCount = 100; - // set font style - textProp.textFont = new Font(textProp.textFont, FontStyle.Bold); - textPropList1.Add(textProp); - - indentation = Common.getIndentation(1); - msg1 = "\n" + indentation + "Checking installation of " + softwareName; - - for (int checkAttempt = 1; checkAttempt <= 2; checkAttempt++) - { - // if software application does not exist - if (!File.Exists(exeFile)) - { - if (checkAttempt == 1 && setupFile.Length > 0) - { - installSuccess = installSoftware(softwareName, setupFile, setupArgs, exitCodesToIgnore, "", promptBeforeInstall); - - installExecuted = true; - - if (!installSuccess) - setupSuccessful = false; - - } - else - { - // set font to default text and color - textProp.textFont = defaultTextProp.textFont; - textProp.textColor = Common.getSetupStatusColor(Common.EXECUTION_STATUS.FAILURE); - textProp.wordIndex = 0; - textProp.wordCount = 2; - // set font style - textProp.textFont = new Font(textProp.textFont, FontStyle.Bold); - textPropList2.Add(textProp); - - msg2 = " - FAILED. Unable to detect presence of file " + exeFile; - setupSuccessful = false; - } - - } - else if (checkAttempt == 2) - { - // set font to default text and color - textProp.textFont = defaultTextProp.textFont; - textProp.textColor = Common.getSetupStatusColor(Common.EXECUTION_STATUS.SUCCESS); - textProp.wordIndex = 0; - textProp.wordCount = 2; - // set font style - textProp.textFont = new Font(textProp.textFont, FontStyle.Bold); - textPropList2.Add(textProp); - - msg2 = " - PASSED"; - } + indentation = Common.getIndentation(1); + msg = "\n" + indentation + "- SKIPPED. Nothing to install/check"; + UpdateStatusDisplayAndLogEvent(msg, msg, textPropList); } - if (installSuccess) + KeyValuePair, List>> processedConfigInfo = new KeyValuePair, List>>(); + + // for every app name to be installed/checked + foreach (KeyValuePair, List>> entry in appNameToInstallerAndExe) { - UpdateStatusDisplayAndLogEvent(msg1, msg1, textPropList1); - UpdateStatusDisplayAndLogEvent(msg2, msg2, textPropList2); + promptBeforeInstallation = false; + setupFile = ""; + exeFile = ""; + registryPath = ""; + registryDisplayName = ""; + registryType = ""; + registryName = ""; + registryValue = ""; + registryCompareOperator = ""; + installArgs = ""; + exitCodesToIgnore = ""; + spawnedProcessesToIgnore = ""; + rebootComputerAtCompletionRequested = false; + rebootComputerImmediatelyRequested = false; - if (installExecuted && rebootComputerAtCompletionRequested) - { - RebootComputer(); - if (rebootComputerImmediatelyRequested) - { - Common.enableAutoRunAfterReboot("Auto_Win_Setup_Task", Application.ExecutablePath); + setupSuccessful = processConfigInfo(entry, ref processedConfigInfo); - // raise event to signal that we need to stop the setup process for changes to take effect - SetupProcessNeedRestartToProceed(); - } - } + if (!setupSuccessful) + break; + + getInfoUsingExeVerification(processedConfigInfo.Value, ref setupFile, ref exeFile, ref promptBeforeInstallation, ref rebootComputerAtCompletionRequested, ref rebootComputerImmediatelyRequested); + getInfoUsingRegistryVerification(processedConfigInfo.Value, ref registryPath, ref registryDisplayName, ref registryType, ref registryName, ref registryValue, ref registryCompareOperator, ref installArgs, ref exitCodesToIgnore, ref spawnedProcessesToIgnore); + + if (exeFile.Length > 0) + { + setupSuccessful = checkSoftwareExe(processedConfigInfo.Key.iniValue, setupFile, installArgs, exeFile, exitCodesToIgnore, promptBeforeInstallation, rebootComputerAtCompletionRequested, rebootComputerImmediatelyRequested); + } + else + { + setupSuccessful = checkSoftwareRegistry(processedConfigInfo.Key.iniValue, setupFile, promptBeforeInstallation, installArgs, registryPath, + registryDisplayName, registryType, registryName, registryValue, registryCompareOperator, + exitCodesToIgnore, spawnedProcessesToIgnore, rebootComputerAtCompletionRequested, rebootComputerImmediatelyRequested); + } + + if (!setupSuccessful || ((frmSetupStatusDisplay)m_parentForm).applicationNeedsToBeRestarted()) + break; } + } + return setupSuccessful; + } - return setupSuccessful; - } + // check if software is installed + public bool checkSoftwareExe(string softwareName, string setupFile, string setupArgs, string exeFile, string exitCodesToIgnore, bool promptBeforeInstall, bool rebootComputerAtCompletionRequested, bool rebootComputerImmediatelyRequested) + { + bool setupSuccessful = true; + bool installSuccess = true; + bool installExecuted = false; + string msg1, msg2 = "", indentation = String.Empty; - public bool installSoftware(string softwareName, string setupFile, string setupArgs, string exitCodesToIgnore, string installProcessName, bool promptBeforeInstall) - { - string msg1 = String.Empty, msg2 = String.Empty, msg3, indentation = String.Empty; - bool setupSuccessful = true; + CommonLib.Windows.Forms.TextFormat.TextFontAndColor defaultTextProp = new CommonLib.Windows.Forms.TextFormat.TextFontAndColor(""); + CommonLib.Windows.Forms.TextFormat.TextFontAndColor textProp = new CommonLib.Windows.Forms.TextFormat.TextFontAndColor(""); + List textPropList1 = new List(); + List textPropList2 = new List(); - CommonLib.Windows.Forms.TextFormat.TextFontAndColor defaultTextProp = new CommonLib.Windows.Forms.TextFormat.TextFontAndColor(""); - CommonLib.Windows.Forms.TextFormat.TextFontAndColor textProp = new CommonLib.Windows.Forms.TextFormat.TextFontAndColor(""); - List textPropList1 = new List(); - List textPropList2 = new List(); - List textPropList3 = new List(); + // set font to default text and color + textProp.textFont = defaultTextProp.textFont; + textProp.textColor = Color.FromArgb(233, 31, 195); + textProp.wordIndex = 3; + textProp.wordCount = 100; + // set font style + textProp.textFont = new Font(textProp.textFont, FontStyle.Bold); + textPropList1.Add(textProp); - // set font to default text and color - textProp.textFont = defaultTextProp.textFont; - textProp.textColor = Color.FromArgb(233, 31, 195); - textProp.wordIndex = 1; - textProp.wordCount = 100; - // set font style - textProp.textFont = new Font(textProp.textFont, FontStyle.Bold); - textPropList1.Add(textProp); + indentation = Common.getIndentation(1); + msg1 = "\n" + indentation + "Checking installation of " + softwareName; - indentation = Common.getIndentation(1); - msg1 = "\n" + indentation + "Installing " + softwareName; - - if (setupFile.Length > 0) + for (int checkAttempt = 1; checkAttempt <= 2; checkAttempt++) + { + // if software application does not exist + if (!File.Exists(exeFile)) { - setupFile = Path.GetFullPath(setupFile); + if (checkAttempt == 1 && setupFile.Length > 0) + { + installSuccess = installSoftware(softwareName, setupFile, setupArgs, exitCodesToIgnore, "", promptBeforeInstall); + + installExecuted = true; + + if (!installSuccess) + setupSuccessful = false; + + } + else + { + // set font to default text and color + textProp.textFont = defaultTextProp.textFont; + textProp.textColor = Common.getSetupStatusColor(Common.EXECUTION_STATUS.FAILURE); + textProp.wordIndex = 0; + textProp.wordCount = 2; + // set font style + textProp.textFont = new Font(textProp.textFont, FontStyle.Bold); + textPropList2.Add(textProp); + + msg2 = " - FAILED. Unable to detect presence of file " + exeFile; + setupSuccessful = false; + } + } - else + else if (checkAttempt == 2) { - // set font to default text and color - textProp.textFont = defaultTextProp.textFont; - textProp.textColor = Common.getSetupStatusColor(Common.EXECUTION_STATUS.FAILURE); - textProp.wordIndex = 0; - textProp.wordCount = 2; - // set font style - textProp.textFont = new Font(textProp.textFont, FontStyle.Bold); - textPropList2.Add(textProp); + // set font to default text and color + textProp.textFont = defaultTextProp.textFont; + textProp.textColor = Common.getSetupStatusColor(Common.EXECUTION_STATUS.SUCCESS); + textProp.wordIndex = 0; + textProp.wordCount = 2; + // set font style + textProp.textFont = new Font(textProp.textFont, FontStyle.Bold); + textPropList2.Add(textProp); - msg2 = " - FAILED. " + softwareName + " is not installed on system. Please install it."; - setupSuccessful = false; - } - - if (setupSuccessful) - { - foreach (var drive in DriveInfo.GetDrives() - .Where(d => d.DriveType == DriveType.CDRom)) - { - if (Regex.IsMatch(setupFile, @"^" + Regex.Escape(drive.Name) + @".+", RegexOptions.IgnoreCase)) - { - while (!drive.IsReady || !File.Exists(setupFile)) - { - Hardware.OpenCdDrive(drive.Name); - - msg3 = ((frmSetupStatusDisplay)m_parentForm).displayMessageBox(MessageBoxCustom.PopUpMsgType.OKCANCEL, null, "Please insert the " + softwareName + " disc into drive " + drive.Name + "\n\n Click OK to proceed", "Info", -1); - - if (String.Equals(msg3, "cancel", StringComparison.OrdinalIgnoreCase)) - { - break; - } - } - - break; - } - } - - if (File.Exists(setupFile)) - { - if (promptBeforeInstall) - msg3 = ((frmSetupStatusDisplay)m_parentForm).displayMessageBox(MessageBoxCustom.PopUpMsgType.YESNO, null, "Required software \"" + softwareName + "\" is not detected in the system.\n\n Would you like to perform the install now?", "Info", -1); - else - msg3 = "yes"; - - if (String.Equals(msg3, "yes", StringComparison.OrdinalIgnoreCase)) - { - - BackgroundWorker bgwInformUserToWait; - - bgwInformUserToWait = new BackgroundWorker(); - bgwInformUserToWait.WorkerSupportsCancellation = true; - bgwInformUserToWait.DoWork += new DoWorkEventHandler(bgwInformUserToWait_DoWork); - bgwInformUserToWait.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bgwInformUserToWait_RunWorkerCompleted); - - frmSetupStatusDisplay displayFrm = (frmSetupStatusDisplay)m_parentForm; - m_progressLine = displayFrm.updateStatusDisplayAndLog("\n ", "", textPropList3); - if (!bgwInformUserToWait.IsBusy) - { - indentation = Common.getIndentation(1); - bgwInformUserToWait.RunWorkerAsync(indentation + "Installing " + softwareName + ". Please wait"); - - } - - try - { - System.Diagnostics.Process process = null; - - // if we have to execute install from a command line - if (Regex.IsMatch(setupFile, @"\.bat$", RegexOptions.IgnoreCase)) - { - ProcessStartInfo ProcStartInfo = new ProcessStartInfo(@"C:\Windows\System32\cmd.exe"); - ProcStartInfo.RedirectStandardOutput = false; - ProcStartInfo.UseShellExecute = false; - ProcStartInfo.CreateNoWindow = true; - ProcStartInfo.RedirectStandardError = true; - process = new System.Diagnostics.Process(); - ProcStartInfo.Arguments = "/c start /wait /d \"" + Path.GetDirectoryName(setupFile) + "\" " + Path.GetFileName(setupFile); - process.StartInfo = ProcStartInfo; - process.Start(); - } - else if (setupArgs.Length > 0 && Regex.IsMatch(setupFile, @"\.exe$", RegexOptions.IgnoreCase)) - { - ProcessStartInfo ProcStartInfo = new ProcessStartInfo(setupFile); - ProcStartInfo.RedirectStandardOutput = false; - ProcStartInfo.UseShellExecute = false; - ProcStartInfo.CreateNoWindow = true; - ProcStartInfo.RedirectStandardError = true; - process = new System.Diagnostics.Process(); - ProcStartInfo.Arguments = setupArgs; - process.StartInfo = ProcStartInfo; - process.Start(); - } - else - { - process = Process.Start(setupFile); - } - - int exitCode = WaitForAllToExit(process); - - process.Close(); - - if (exitCodesToIgnore.Length == 0) - exitCodesToIgnore = ",0,"; - else - exitCodesToIgnore = ",0," + exitCodesToIgnore + ","; - - if (!Regex.IsMatch(exitCodesToIgnore, @",\s*" + exitCode.ToString() + @"\s*,", RegexOptions.IgnoreCase)) - { - throw new Exception(Path.GetFileName(setupFile) + " exited with code: " + exitCode.ToString()); - } - } - catch (Exception e) - { - // set font to default text and color - textProp.textFont = defaultTextProp.textFont; - textProp.textColor = Common.getSetupStatusColor(Common.EXECUTION_STATUS.FAILURE); - textProp.wordIndex = 0; - textProp.wordCount = 2; - // set font style - textProp.textFont = new Font(textProp.textFont, FontStyle.Bold); - textPropList2.Add(textProp); - - msg2 = " - FAILED. Error executing setup file " + setupFile + ". " + e.Message; - - setupSuccessful = false; - } - finally - { - if (!bgwInformUserToWait.CancellationPending && bgwInformUserToWait.IsBusy) - { - bgwInformUserToWait.CancelAsync(); - _resetEvent.WaitOne(); - _resetEvent.Reset(); - } - - displayFrm.removeStatusDisplayLine(m_progressLine, true); - } - } - else - { - // set font to default text and color - textProp.textFont = defaultTextProp.textFont; - textProp.textColor = Common.getSetupStatusColor(Common.EXECUTION_STATUS.FAILURE); - textProp.wordIndex = 0; - textProp.wordCount = 2; - // set font style - textProp.textFont = new Font(textProp.textFont, FontStyle.Bold); - textPropList2.Add(textProp); - - msg2 = " - FAILED. User chooses to not install required software."; - - setupSuccessful = false; - } - } - else - { - // set font to default text and color - textProp.textFont = defaultTextProp.textFont; - textProp.textColor = Common.getSetupStatusColor(Common.EXECUTION_STATUS.FAILURE); - textProp.wordIndex = 0; - textProp.wordCount = 2; - // set font style - textProp.textFont = new Font(textProp.textFont, FontStyle.Bold); - textPropList2.Add(textProp); - - msg2 = " - FAILED. Setup file " + setupFile + " was not found."; - - setupSuccessful = false; - } - } - - if (setupSuccessful) - { - // set font to default text and color - textProp.textFont = defaultTextProp.textFont; - textProp.textColor = Common.getSetupStatusColor(Common.EXECUTION_STATUS.SUCCESS); - textProp.wordIndex = 0; - textProp.wordCount = 2; - // set font style - textProp.textFont = new Font(textProp.textFont, FontStyle.Bold); - textPropList2.Add(textProp); - - msg2 = " - SUCCESS"; + msg2 = " - PASSED"; } + } + if (installSuccess) + { UpdateStatusDisplayAndLogEvent(msg1, msg1, textPropList1); UpdateStatusDisplayAndLogEvent(msg2, msg2, textPropList2); - return setupSuccessful; - } - - private void bgwInformUserToWait_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) - { - // First, handle the case where an exception was thrown. - if (e.Error != null) + if (installExecuted && rebootComputerAtCompletionRequested) { + RebootComputer(); + if (rebootComputerImmediatelyRequested) + { + Common.enableAutoRunAfterReboot("Auto_Win_Setup_Task", Application.ExecutablePath); + + // raise event to signal that we need to stop the setup process for changes to take effect + SetupProcessNeedRestartToProceed(); + } } - else if (e.Cancelled) // user cancelled - { + } - } - else // thread completed on its own - { + return setupSuccessful; + } - } - _resetEvent.Set(); // signal that execution of this thread is done - } + public bool installSoftware(string softwareName, string setupFile, string setupArgs, string exitCodesToIgnore, string spawnedProcessesToIgnore, bool promptBeforeInstall) + { + string msg1 = String.Empty, msg2 = String.Empty, msg3, indentation = String.Empty; + bool setupSuccessful = true; - private int WaitForAllToExit(Process process) - { - int exitCode = -1; + CommonLib.Windows.Forms.TextFormat.TextFontAndColor defaultTextProp = new CommonLib.Windows.Forms.TextFormat.TextFontAndColor(""); + CommonLib.Windows.Forms.TextFormat.TextFontAndColor textProp = new CommonLib.Windows.Forms.TextFormat.TextFontAndColor(""); + List textPropList1 = new List(); + List textPropList2 = new List(); + List textPropList3 = new List(); - // even though this line doesn't appear to do anything, it - // helps in getting the exit code of the child process - // without this line, if we try to get exit code of child process - // exception will be thrown - var sh = process.SafeHandle; + // set font to default text and color + textProp.textFont = defaultTextProp.textFont; + textProp.textColor = Color.FromArgb(233, 31, 195); + textProp.wordIndex = 1; + textProp.wordCount = 100; + // set font style + textProp.textFont = new Font(textProp.textFont, FontStyle.Bold); + textPropList1.Add(textProp); - while (true) - { - ManagementObjectSearcher searcher = new ManagementObjectSearcher( - "SELECT * " + - "FROM Win32_Process " + - "WHERE ParentProcessId=" + process.Id); - ManagementObjectCollection collection = searcher.Get(); - if (collection.Count > 0) - { - foreach (var item in collection) - { - UInt32 childProcessId = (UInt32)item["ProcessId"]; - if ((int)childProcessId != Process.GetCurrentProcess().Id) - { - Process childProcess = null; - try - { - childProcess = Process.GetProcessById((int)childProcessId); - } - catch (Exception) - { - continue; - } - - exitCode = WaitForAllToExit(childProcess); - } - } - } - - if (process.HasExited) - { - if (exitCode == -1) - exitCode = process.ExitCode; - - break; - } - else - Thread.Sleep(500); - } - - return exitCode; - } - - private void bgwInformUserToWait_DoWork(object sender, DoWorkEventArgs e) - { - BackgroundWorker bgw = sender as BackgroundWorker; - - CommonLib.Windows.Forms.TextFormat.TextFontAndColor defaultTextProp = new CommonLib.Windows.Forms.TextFormat.TextFontAndColor(""); - CommonLib.Windows.Forms.TextFormat.TextFontAndColor textProp = new CommonLib.Windows.Forms.TextFormat.TextFontAndColor(""); - List textPropList = new List(); - - string text = (string)e.Argument; - string dots = ""; - - while (true) - { - if (bgw != null && bgw.CancellationPending) - { - if (e != null) - e.Cancel = true; - - break; - } - - if (dots.Length < 3) - dots += "."; - else - dots = "."; - - if (StringManip.GetPhraseWordIndexInText(text, "installing") > -1) - { - // set font to default text and color - textProp.textFont = defaultTextProp.textFont; - textProp.textColor = Color.FromArgb(157, 150, 19); - textProp.wordIndex = StringManip.GetPhraseWordIndexInText(text, "installing"); - textProp.wordCount = 1; - // set font style - textProp.textFont = new Font(textProp.textFont.FontFamily, 13, FontStyle.Bold); - textPropList.Add(textProp); - - // set font to default text and color - textProp.textFont = defaultTextProp.textFont; - textProp.textColor = Color.FromArgb(42, 176, 173); - textProp.wordIndex = StringManip.GetPhraseWordIndexInText(text, "installing") + 1; - textProp.wordCount = StringManip.GetPhraseWordIndexInText(text, "please wait") - textProp.wordIndex; - // set font style - textProp.textFont = new Font(textProp.textFont.FontFamily, 13, FontStyle.Bold); - textPropList.Add(textProp); - - // set font to default text and color - textProp.textFont = defaultTextProp.textFont; - textProp.textColor = Color.FromArgb(157, 150, 19); - textProp.wordIndex = StringManip.GetPhraseWordIndexInText(text, "please wait"); - textProp.wordCount = 10; - // set font style - textProp.textFont = new Font(textProp.textFont.FontFamily, 13, FontStyle.Bold); - textPropList.Add(textProp); - } - else - { - // set font to default text and color - textProp.textFont = defaultTextProp.textFont; - textProp.textColor = Color.FromArgb(17, 75, 237); - textProp.wordIndex = 0; - textProp.wordCount = 100; - // set font style - textProp.textFont = new Font(textProp.textFont.FontFamily, 13, FontStyle.Bold); - textPropList.Add(textProp); - } - - UpdateStatusDisplayAtLine(text + dots, m_progressLine, textPropList); - - Thread.Sleep(500); - } - } - - public bool checkSoftwareRegistry(string softwareName, string setupFile, bool promptBeforeInstall, string setupArgs, string registryPath, string registryDisplayName, string registryType, - string registryName, string registryValue, string registryCompareOperator, - string exitCodesToIgnore, string installProcessName, bool rebootComputerAtCompletionRequested, bool rebootComputerImmediatelyRequested) - { - bool setupSuccessful = true; - bool installSuccessful = true; - bool installExecuted = false; - string msg, indentation = String.Empty, statusMsg = ""; - - CommonLib.Windows.Forms.TextFormat.TextFontAndColor defaultTextProp = new CommonLib.Windows.Forms.TextFormat.TextFontAndColor(""); - CommonLib.Windows.Forms.TextFormat.TextFontAndColor textProp = new CommonLib.Windows.Forms.TextFormat.TextFontAndColor(""); - List textPropList1 = new List(); - List textPropList2 = new List(); + indentation = Common.getIndentation(1); + msg1 = "\n" + indentation + "Installing " + softwareName; + if (setupFile.Length > 0) + { + setupFile = Path.GetFullPath(setupFile); + } + else + { // set font to default text and color textProp.textFont = defaultTextProp.textFont; - textProp.textColor = Color.FromArgb(233, 31, 195); - textProp.wordIndex = 3; - textProp.wordCount = 100; + textProp.textColor = Common.getSetupStatusColor(Common.EXECUTION_STATUS.FAILURE); + textProp.wordIndex = 0; + textProp.wordCount = 2; // set font style textProp.textFont = new Font(textProp.textFont, FontStyle.Bold); - textPropList1.Add(textProp); + textPropList2.Add(textProp); - indentation = Common.getIndentation(1); - msg = "\n" + indentation + "Checking installation of " + softwareName; + msg2 = " - FAILED. " + softwareName + " is not installed on system. Please install it."; + setupSuccessful = false; + } - int maxSoftwareCheckRetries = 15; - int retriesCount = 1; - while (true) + if (setupSuccessful) + { + foreach (var drive in DriveInfo.GetDrives() + .Where(d => d.DriveType == DriveType.CDRom)) { - // if software application does not exist - if (!checkSoftwareRegistrySetting(registryPath, registryDisplayName, registryType, registryName, registryValue, registryCompareOperator, ref statusMsg)) - { - if (retriesCount == 1 && setupFile.Length > 0) - { - installSuccessful = installSoftware(softwareName, setupFile, setupArgs, exitCodesToIgnore, installProcessName, promptBeforeInstall); + if (Regex.IsMatch(setupFile, @"^" + Regex.Escape(drive.Name) + @".+", RegexOptions.IgnoreCase)) + { + while (!drive.IsReady || !File.Exists(setupFile)) + { + Hardware.OpenCdDrive(drive.Name); - installExecuted = true; + msg3 = ((frmSetupStatusDisplay)m_parentForm).displayMessageBox(MessageBoxCustom.PopUpMsgType.OKCANCEL, null, "Please insert the " + softwareName + " disc into drive " + drive.Name + "\n\n Click OK to proceed", "Info", -1); - if (!installSuccessful) - setupSuccessful = false; - - } - - if (!installExecuted || retriesCount == maxSoftwareCheckRetries || !installSuccessful) - { - // set font to default text and color - textProp.textFont = defaultTextProp.textFont; - textProp.textColor = Common.getSetupStatusColor(Common.EXECUTION_STATUS.FAILURE); - textProp.wordIndex = 0; - textProp.wordCount = 2; - // set font style - textProp.textFont = new Font(textProp.textFont, FontStyle.Bold); - textPropList2.Add(textProp); - - setupSuccessful = false; + if (String.Equals(msg3, "cancel", StringComparison.OrdinalIgnoreCase)) + { break; - } + } + } - if (installExecuted && installSuccessful) - { - // wait for all the registry settings to be applied before we check again - Thread.Sleep(1000); - } - } - else - { - // set font to default text and color - textProp.textFont = defaultTextProp.textFont; - textProp.textColor = Common.getSetupStatusColor(Common.EXECUTION_STATUS.SUCCESS); - textProp.wordIndex = 0; - textProp.wordCount = 2; - // set font style - textProp.textFont = new Font(textProp.textFont, FontStyle.Bold); - textPropList2.Add(textProp); - - statusMsg = " - PASSED"; - - break; - } - - retriesCount++; + break; + } } - if (installSuccessful) + if (File.Exists(setupFile)) { - UpdateStatusDisplayAndLogEvent(msg, msg, textPropList1); - UpdateStatusDisplayAndLogEvent(statusMsg, statusMsg, textPropList2); + if (promptBeforeInstall) + msg3 = ((frmSetupStatusDisplay)m_parentForm).displayMessageBox(MessageBoxCustom.PopUpMsgType.YESNO, null, "Required software \"" + softwareName + "\" is not detected in the system.\n\n Would you like to perform the install now?", "Info", -1); + else + msg3 = "yes"; - if (installExecuted && rebootComputerAtCompletionRequested) - { - RebootComputer(); + if (String.Equals(msg3, "yes", StringComparison.OrdinalIgnoreCase)) + { - if (rebootComputerImmediatelyRequested) - { - Common.enableAutoRunAfterReboot("Auto_Win_Setup_Task", Application.ExecutablePath); + BackgroundWorker bgwInformUserToWait; - // raise event to signal that we need to stop the setup process for changes to take effect - SetupProcessNeedRestartToProceed(); - } - } - } + bgwInformUserToWait = new BackgroundWorker(); + bgwInformUserToWait.WorkerSupportsCancellation = true; + bgwInformUserToWait.DoWork += new DoWorkEventHandler(bgwInformUserToWait_DoWork); + bgwInformUserToWait.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bgwInformUserToWait_RunWorkerCompleted); - return setupSuccessful; - } + frmSetupStatusDisplay displayFrm = (frmSetupStatusDisplay)m_parentForm; + m_progressLine = displayFrm.updateStatusDisplayAndLog("\n ", "", textPropList3); + if (!bgwInformUserToWait.IsBusy) + { + indentation = Common.getIndentation(1); + bgwInformUserToWait.RunWorkerAsync(indentation + "Installing " + softwareName + ". Please wait"); - bool checkSoftwareRegistrySetting(string registryPath, string registryDisplayName, string registryType, - string registryName, string registryValue, string registryCompareOperator, ref string statusMsg) - { - bool setupSuccessful = true; - string indentation = String.Empty, actualRegistryValue = ""; - RegistryHive regHive = RegistryHive.LocalMachine; + } - RegistryKey rkSubKey = null; + try + { + System.Diagnostics.Process process = null; - statusMsg = ""; + // if we have to execute install from a command line + if (Regex.IsMatch(setupFile, @"\.bat$", RegexOptions.IgnoreCase)) + { + ProcessStartInfo ProcStartInfo = new ProcessStartInfo(@"C:\Windows\System32\cmd.exe"); + ProcStartInfo.RedirectStandardOutput = false; + ProcStartInfo.UseShellExecute = false; + ProcStartInfo.CreateNoWindow = true; + ProcStartInfo.RedirectStandardError = true; + process = new System.Diagnostics.Process(); + ProcStartInfo.Arguments = "/c start /wait /d \"" + Path.GetDirectoryName(setupFile) + "\" " + Path.GetFileName(setupFile); + process.StartInfo = ProcStartInfo; + process.Start(); + } + else if (setupArgs.Length > 0 && Regex.IsMatch(setupFile, @"\.exe$", RegexOptions.IgnoreCase)) + { + ProcessStartInfo ProcStartInfo = new ProcessStartInfo(setupFile); + ProcStartInfo.RedirectStandardOutput = false; + ProcStartInfo.UseShellExecute = false; + ProcStartInfo.CreateNoWindow = true; + ProcStartInfo.RedirectStandardError = true; + process = new System.Diagnostics.Process(); + ProcStartInfo.Arguments = setupArgs; + process.StartInfo = ProcStartInfo; + process.Start(); + } + else + { + process = Process.Start(setupFile); + } - RegistryKey hklm = null; + int exitCode = WaitForAllToExit(process, spawnedProcessesToIgnore); - if (String.Equals(registryType, "local_machine", StringComparison.OrdinalIgnoreCase)) - { - regHive = RegistryHive.LocalMachine; - } - else if (String.Equals(registryType, "classes_root", StringComparison.OrdinalIgnoreCase)) - { - regHive = RegistryHive.ClassesRoot; - } - else if (String.Equals(registryType, "current_user", StringComparison.OrdinalIgnoreCase)) - { - regHive = RegistryHive.CurrentUser; + process.Close(); + + if (exitCodesToIgnore.Length == 0) + exitCodesToIgnore = ",0,"; + else + exitCodesToIgnore = ",0," + exitCodesToIgnore + ","; + + if (!Regex.IsMatch(exitCodesToIgnore, @",\s*" + exitCode.ToString() + @"\s*,", RegexOptions.IgnoreCase)) + { + throw new Exception(Path.GetFileName(setupFile) + " exited with code: " + exitCode.ToString()); + } + } + catch (Exception e) + { + // set font to default text and color + textProp.textFont = defaultTextProp.textFont; + textProp.textColor = Common.getSetupStatusColor(Common.EXECUTION_STATUS.FAILURE); + textProp.wordIndex = 0; + textProp.wordCount = 2; + // set font style + textProp.textFont = new Font(textProp.textFont, FontStyle.Bold); + textPropList2.Add(textProp); + + msg2 = " - FAILED. Error executing setup file " + setupFile + ". " + e.Message; + + setupSuccessful = false; + } + finally + { + if (!bgwInformUserToWait.CancellationPending && bgwInformUserToWait.IsBusy) + { + bgwInformUserToWait.CancelAsync(); + _resetEvent.WaitOne(); + _resetEvent.Reset(); + } + + displayFrm.removeStatusDisplayLine(m_progressLine, true); + } + } + else + { + // set font to default text and color + textProp.textFont = defaultTextProp.textFont; + textProp.textColor = Common.getSetupStatusColor(Common.EXECUTION_STATUS.FAILURE); + textProp.wordIndex = 0; + textProp.wordCount = 2; + // set font style + textProp.textFont = new Font(textProp.textFont, FontStyle.Bold); + textPropList2.Add(textProp); + + msg2 = " - FAILED. User chooses to not install required software."; + + setupSuccessful = false; + } } else { - statusMsg = " - FAILED. Registry type of \"" + registryType + "\" is invalid"; - setupSuccessful = false; - } + // set font to default text and color + textProp.textFont = defaultTextProp.textFont; + textProp.textColor = Common.getSetupStatusColor(Common.EXECUTION_STATUS.FAILURE); + textProp.wordIndex = 0; + textProp.wordCount = 2; + // set font style + textProp.textFont = new Font(textProp.textFont, FontStyle.Bold); + textPropList2.Add(textProp); - if (setupSuccessful) + msg2 = " - FAILED. Setup file " + setupFile + " was not found."; + + setupSuccessful = false; + } + } + + if (setupSuccessful) + { + // set font to default text and color + textProp.textFont = defaultTextProp.textFont; + textProp.textColor = Common.getSetupStatusColor(Common.EXECUTION_STATUS.SUCCESS); + textProp.wordIndex = 0; + textProp.wordCount = 2; + // set font style + textProp.textFont = new Font(textProp.textFont, FontStyle.Bold); + textPropList2.Add(textProp); + + msg2 = " - SUCCESS"; + } + + UpdateStatusDisplayAndLogEvent(msg1, msg1, textPropList1); + UpdateStatusDisplayAndLogEvent(msg2, msg2, textPropList2); + + return setupSuccessful; + } + + private void bgwInformUserToWait_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) + { + // First, handle the case where an exception was thrown. + if (e.Error != null) + { + + } + else if (e.Cancelled) // user cancelled + { + + } + else // thread completed on its own + { + + } + _resetEvent.Set(); // signal that execution of this thread is done + } + + private int WaitForAllToExit(Process process, string spawnedProcessesToIgnore) + { + int exitCode = -1; + + // even though this line doesn't appear to do anything, it + // helps in getting the exit code of the child process + // without this line, if we try to get exit code of child process + // exception will be thrown + var sh = process.SafeHandle; + + while (true) + { + ManagementObjectSearcher searcher = new ManagementObjectSearcher( + "SELECT * " + + "FROM Win32_Process " + + "WHERE ParentProcessId=" + process.Id); + ManagementObjectCollection collection = searcher.Get(); + if (collection.Count > 0) { - List registryPaths = new List(); - if (registryDisplayName.Length > 0) - { - registryPaths = WindowsRegistry.GetRegistryDynamicUninstallKeys(regHive, registryDisplayName); + foreach (var item in collection) + { + UInt32 childProcessId = (UInt32)item["ProcessId"]; + if ((int)childProcessId != Process.GetCurrentProcess().Id) + { + Process childProcess = null; + try + { + childProcess = Process.GetProcessById((int)childProcessId); + } + catch (Exception) + { + continue; + } - if (registryPaths.Count == 0) - { - statusMsg = " - FAILED. Unable to find any registry key associated with \"" + registryDisplayName + "\""; - setupSuccessful = false; - } - } - else if (registryPath.Length > 0) - { - registryPaths.Add(registryPath); - } + string indentation = Common.getIndentation(1); + ((frmSetupStatusDisplay)m_parentForm).writeToLog($"{indentation}Child process spawned: {childProcess.ProcessName}\r\n"); - hklm = RegistryKey.OpenBaseKey(regHive, RegistryView.Registry64); + string[] processArray = Array.ConvertAll(spawnedProcessesToIgnore.Split(','), p => p.Trim()); - foreach (string regPath in registryPaths) - { - setupSuccessful = true; - - rkSubKey = hklm.OpenSubKey(regPath, false); - - if (rkSubKey != null) - { - if (registryName.Length > 0) - { - List list = new List(rkSubKey.GetValueNames()); - - if (list.FindIndex(x => x.Equals(registryName, StringComparison.OrdinalIgnoreCase)) != -1) - { - actualRegistryValue = rkSubKey.GetValue(registryName).ToString(); - - if (Regex.IsMatch(actualRegistryValue, @"^[\.0-9]+$", RegexOptions.IgnoreCase) && Regex.IsMatch(registryValue, @"^[\.0-9]+$", RegexOptions.IgnoreCase)) - { - if (softwareVersionComparisonSuccessful(registryValue, actualRegistryValue, registryCompareOperator)) - { - statusMsg = " - PASSED"; - } - else - { - statusMsg = " - FAILED. Actual registry value of \"" + actualRegistryValue + "\" is not " + getStringEquivalentOfComparisonOperator(registryCompareOperator) + " the base registry value of \"" + registryValue + "\""; - setupSuccessful = false; - } - } - else if (!String.Equals(actualRegistryValue, registryValue, StringComparison.OrdinalIgnoreCase)) - { - statusMsg = " - FAILED. Actual registry value of \"" + actualRegistryValue + "\" is not " + getStringEquivalentOfComparisonOperator(registryCompareOperator) + " the base registry value of \"" + registryValue + "\""; - setupSuccessful = false; - } - } - else - { - statusMsg = " - FAILED. Unable to find registry key's value name \"" + registryName + "\""; - setupSuccessful = false; - } - } - } - else - { - statusMsg = " - FAILED. Unable to find registry key \"" + registryPath + "\". Either the registry key is wrong or the software is not installed."; - setupSuccessful = false; - } - } + if (!processArray.Contains(childProcess.ProcessName, StringComparer.OrdinalIgnoreCase)) + { + exitCode = WaitForAllToExit(childProcess, spawnedProcessesToIgnore); + } + else + ((frmSetupStatusDisplay)m_parentForm).writeToLog($"{indentation}Ignoring spawned process: {childProcess.ProcessName}\r\n"); + } + } } - if (rkSubKey != null) - rkSubKey.Close(); - - if (hklm != null) - hklm.Close(); - - return setupSuccessful; - } - - static bool softwareVersionComparisonSuccessful(string baseVersion, string actualVersion, string compareOperator) - { - bool compareSuccess = false; - List baseVersionParts = new List(baseVersion.Split('.').ToList()); - List actualVersionParts = new List(actualVersion.Split('.').ToList()); - int actualVal = 0, expectedVal = 0; - - // remove any trailing .0 - for (int i = baseVersionParts.Count - 1; i >= 0; --i) + if (process.HasExited) { - if (i != 0 && Regex.IsMatch(baseVersionParts[i], @"^[0]+$", RegexOptions.IgnoreCase)) - { - baseVersionParts.RemoveAt(i); - } - else - break; - } + if (exitCode == -1) + exitCode = process.ExitCode; - // remove any trailing .0 - for (int i = actualVersionParts.Count - 1; i >= 0; --i) + break; + } + else + Thread.Sleep(500); + } + + return exitCode; + } + + private void bgwInformUserToWait_DoWork(object sender, DoWorkEventArgs e) + { + BackgroundWorker bgw = sender as BackgroundWorker; + + CommonLib.Windows.Forms.TextFormat.TextFontAndColor defaultTextProp = new CommonLib.Windows.Forms.TextFormat.TextFontAndColor(""); + CommonLib.Windows.Forms.TextFormat.TextFontAndColor textProp = new CommonLib.Windows.Forms.TextFormat.TextFontAndColor(""); + List textPropList = new List(); + + string text = (string)e.Argument; + string dots = ""; + + while (true) + { + if (bgw != null && bgw.CancellationPending) { - if (i != 0 && Regex.IsMatch(actualVersionParts[i], @"^[0]+$", RegexOptions.IgnoreCase)) - { - actualVersionParts.RemoveAt(i); - } - else - break; + if (e != null) + e.Cancel = true; + + break; } - if (baseVersionParts.Count == 0) - baseVersionParts.Add("0"); + if (dots.Length < 3) + dots += "."; + else + dots = "."; - if (actualVersionParts.Count == 0) - actualVersionParts.Add("0"); - - if (compareOperator.Length == 0) - compareOperator = "eq"; - - if (String.Equals(compareOperator, "eq", StringComparison.OrdinalIgnoreCase)) + if (StringManip.GetPhraseWordIndexInText(text, "installing") > -1) { - compareSuccess = actualAndBaseVersionsAreEqual(baseVersionParts, actualVersionParts); + // set font to default text and color + textProp.textFont = defaultTextProp.textFont; + textProp.textColor = Color.FromArgb(157, 150, 19); + textProp.wordIndex = StringManip.GetPhraseWordIndexInText(text, "installing"); + textProp.wordCount = 1; + // set font style + textProp.textFont = new Font(textProp.textFont.FontFamily, 13, FontStyle.Bold); + textPropList.Add(textProp); + + // set font to default text and color + textProp.textFont = defaultTextProp.textFont; + textProp.textColor = Color.FromArgb(42, 176, 173); + textProp.wordIndex = StringManip.GetPhraseWordIndexInText(text, "installing") + 1; + textProp.wordCount = StringManip.GetPhraseWordIndexInText(text, "please wait") - textProp.wordIndex; + // set font style + textProp.textFont = new Font(textProp.textFont.FontFamily, 13, FontStyle.Bold); + textPropList.Add(textProp); + + // set font to default text and color + textProp.textFont = defaultTextProp.textFont; + textProp.textColor = Color.FromArgb(157, 150, 19); + textProp.wordIndex = StringManip.GetPhraseWordIndexInText(text, "please wait"); + textProp.wordCount = 10; + // set font style + textProp.textFont = new Font(textProp.textFont.FontFamily, 13, FontStyle.Bold); + textPropList.Add(textProp); } - else if (String.Equals(compareOperator, "ne", StringComparison.OrdinalIgnoreCase)) - { - compareSuccess = !actualAndBaseVersionsAreEqual(baseVersionParts, actualVersionParts); - } - else if (String.Equals(compareOperator, "lte", StringComparison.OrdinalIgnoreCase)) - { - bool isEqual = false; - - for (int i = 0; i < actualVersionParts.Count; i++) - { - if (baseVersionParts.Count >= i + 1) - { - if (Int32.TryParse(actualVersionParts[i], out actualVal) && Int32.TryParse(baseVersionParts[i], out expectedVal)) - { - if (actualVal < expectedVal) - { - isEqual = false; - compareSuccess = true; - break; - } - else if (actualVal > expectedVal) - { - isEqual = false; - break; - } - else if (i == actualVersionParts.Count - 1 && actualVersionParts.Count == baseVersionParts.Count) - { - isEqual = false; - compareSuccess = true; - break; - } - else - isEqual = true; - } - } - } - - if (isEqual && baseVersionParts.Count > actualVersionParts.Count) - compareSuccess = true; - } - else if (String.Equals(compareOperator, "gte", StringComparison.OrdinalIgnoreCase)) - { - for (int i = 0; i < actualVersionParts.Count; i++) - { - if (baseVersionParts.Count >= i + 1) - { - if (Int32.TryParse(actualVersionParts[i], out actualVal) && Int32.TryParse(baseVersionParts[i], out expectedVal)) - { - if (actualVal > expectedVal) - { - compareSuccess = true; - break; - } - else if (actualVal < expectedVal) - break; - else if (i == actualVersionParts.Count - 1 && actualVersionParts.Count == baseVersionParts.Count) - { - compareSuccess = true; - break; - } - } - } - else - { - compareSuccess = true; - break; - } - } - } - else if (String.Equals(compareOperator, "gt", StringComparison.OrdinalIgnoreCase)) - { - for (int i = 0; i < actualVersionParts.Count; i++) - { - if (baseVersionParts.Count >= i + 1) - { - if (Int32.TryParse(actualVersionParts[i], out actualVal) && Int32.TryParse(baseVersionParts[i], out expectedVal)) - { - if (actualVal > expectedVal) - { - compareSuccess = true; - break; - } - } - } - else - { - compareSuccess = true; - break; - } - } - } - else if (String.Equals(compareOperator, "lt", StringComparison.OrdinalIgnoreCase)) - { - compareSuccess = true; - bool isEqual = false; - - for (int i = 0; i < actualVersionParts.Count; i++) - { - if (baseVersionParts.Count >= i + 1) - { - if (Int32.TryParse(actualVersionParts[i], out actualVal) && Int32.TryParse(baseVersionParts[i], out expectedVal)) - { - if (actualVal > expectedVal) - { - isEqual = false; - compareSuccess = false; - break; - } - else if (actualVal < expectedVal) - { - isEqual = false; - break; - } - else - isEqual = true; - } - } - } - - if (isEqual && baseVersionParts.Count == actualVersionParts.Count) - compareSuccess = false; - } - - return compareSuccess; - } - - private static bool actualAndBaseVersionsAreEqual(List baseVersionParts, List actualVersionParts) - { - bool compareSuccess = true; - int actualVal = 0, baseVal = 0; - - if (baseVersionParts.Count != actualVersionParts.Count) - compareSuccess = false; else { - for (int i = 0; i < actualVersionParts.Count; i++) - { - if (baseVersionParts.Count >= i + 1) - { - if (Int32.TryParse(actualVersionParts[i], out actualVal) && Int32.TryParse(baseVersionParts[i], out baseVal)) + // set font to default text and color + textProp.textFont = defaultTextProp.textFont; + textProp.textColor = Color.FromArgb(17, 75, 237); + textProp.wordIndex = 0; + textProp.wordCount = 100; + // set font style + textProp.textFont = new Font(textProp.textFont.FontFamily, 13, FontStyle.Bold); + textPropList.Add(textProp); + } + + UpdateStatusDisplayAtLine(text + dots, m_progressLine, textPropList); + + Thread.Sleep(500); + } + } + + public bool checkSoftwareRegistry(string softwareName, string setupFile, bool promptBeforeInstall, string setupArgs, string registryPath, string registryDisplayName, string registryType, + string registryName, string registryValue, string registryCompareOperator, + string exitCodesToIgnore, string spawnedProcessesToIgnore, bool rebootComputerAtCompletionRequested, bool rebootComputerImmediatelyRequested) + { + bool setupSuccessful = true; + bool installSuccessful = true; + bool installExecuted = false; + string msg, indentation = String.Empty, statusMsg = ""; + + CommonLib.Windows.Forms.TextFormat.TextFontAndColor defaultTextProp = new CommonLib.Windows.Forms.TextFormat.TextFontAndColor(""); + CommonLib.Windows.Forms.TextFormat.TextFontAndColor textProp = new CommonLib.Windows.Forms.TextFormat.TextFontAndColor(""); + List textPropList1 = new List(); + List textPropList2 = new List(); + + // set font to default text and color + textProp.textFont = defaultTextProp.textFont; + textProp.textColor = Color.FromArgb(233, 31, 195); + textProp.wordIndex = 3; + textProp.wordCount = 100; + // set font style + textProp.textFont = new Font(textProp.textFont, FontStyle.Bold); + textPropList1.Add(textProp); + + indentation = Common.getIndentation(1); + msg = "\n" + indentation + "Checking installation of " + softwareName; + + int maxSoftwareCheckRetries = 15; + int retriesCount = 1; + while (true) + { + // if software application does not exist + if (!checkSoftwareRegistrySetting(registryPath, registryDisplayName, registryType, registryName, registryValue, registryCompareOperator, ref statusMsg)) + { + if (retriesCount == 1 && setupFile.Length > 0) + { + installSuccessful = installSoftware(softwareName, setupFile, setupArgs, exitCodesToIgnore, spawnedProcessesToIgnore, promptBeforeInstall); + + installExecuted = true; + + if (!installSuccessful) + setupSuccessful = false; + + } + + if (!installExecuted || retriesCount == maxSoftwareCheckRetries || !installSuccessful) + { + // set font to default text and color + textProp.textFont = defaultTextProp.textFont; + textProp.textColor = Common.getSetupStatusColor(Common.EXECUTION_STATUS.FAILURE); + textProp.wordIndex = 0; + textProp.wordCount = 2; + // set font style + textProp.textFont = new Font(textProp.textFont, FontStyle.Bold); + textPropList2.Add(textProp); + + setupSuccessful = false; + break; + } + + if (installExecuted && installSuccessful) + { + // wait for all the registry settings to be applied before we check again + Thread.Sleep(1000); + } + } + else + { + // set font to default text and color + textProp.textFont = defaultTextProp.textFont; + textProp.textColor = Common.getSetupStatusColor(Common.EXECUTION_STATUS.SUCCESS); + textProp.wordIndex = 0; + textProp.wordCount = 2; + // set font style + textProp.textFont = new Font(textProp.textFont, FontStyle.Bold); + textPropList2.Add(textProp); + + statusMsg = " - PASSED"; + + break; + } + + retriesCount++; + } + + if (installSuccessful) + { + UpdateStatusDisplayAndLogEvent(msg, msg, textPropList1); + UpdateStatusDisplayAndLogEvent(statusMsg, statusMsg, textPropList2); + + if (installExecuted && rebootComputerAtCompletionRequested) + { + RebootComputer(); + + if (rebootComputerImmediatelyRequested) + { + Common.enableAutoRunAfterReboot("Auto_Win_Setup_Task", Application.ExecutablePath); + + // raise event to signal that we need to stop the setup process for changes to take effect + SetupProcessNeedRestartToProceed(); + } + } + } + + return setupSuccessful; + } + + bool checkSoftwareRegistrySetting(string registryPath, string registryDisplayName, string registryType, + string registryName, string registryValue, string registryCompareOperator, ref string statusMsg) + { + bool setupSuccessful = true; + string indentation = String.Empty, actualRegistryValue = ""; + RegistryHive regHive = RegistryHive.LocalMachine; + + RegistryKey rkSubKey = null; + + statusMsg = ""; + + RegistryKey hklm = null; + + if (String.Equals(registryType, "local_machine", StringComparison.OrdinalIgnoreCase)) + { + regHive = RegistryHive.LocalMachine; + } + else if (String.Equals(registryType, "classes_root", StringComparison.OrdinalIgnoreCase)) + { + regHive = RegistryHive.ClassesRoot; + } + else if (String.Equals(registryType, "current_user", StringComparison.OrdinalIgnoreCase)) + { + regHive = RegistryHive.CurrentUser; + } + else + { + statusMsg = " - FAILED. Registry type of \"" + registryType + "\" is invalid"; + setupSuccessful = false; + } + + if (setupSuccessful) + { + List registryPaths = new List(); + if (registryDisplayName.Length > 0) + { + registryPaths = WindowsRegistry.GetRegistryDynamicUninstallKeys(regHive, registryDisplayName); + + if (registryPaths.Count == 0) + { + statusMsg = " - FAILED. Unable to find any registry key associated with \"" + registryDisplayName + "\""; + setupSuccessful = false; + } + } + else if (registryPath.Length > 0) + { + registryPaths.Add(registryPath); + } + + hklm = RegistryKey.OpenBaseKey(regHive, RegistryView.Registry64); + + foreach (string regPath in registryPaths) + { + setupSuccessful = true; + + rkSubKey = hklm.OpenSubKey(regPath, false); + + if (rkSubKey != null) + { + if (registryName.Length > 0) + { + List list = new List(rkSubKey.GetValueNames()); + + if (list.FindIndex(x => x.Equals(registryName, StringComparison.OrdinalIgnoreCase)) != -1) + { + actualRegistryValue = rkSubKey.GetValue(registryName).ToString(); + + if (Regex.IsMatch(actualRegistryValue, @"^[\.0-9]+$", RegexOptions.IgnoreCase) && Regex.IsMatch(registryValue, @"^[\.0-9]+$", RegexOptions.IgnoreCase)) { - if (actualVal != baseVal) - { - compareSuccess = false; - break; - } + if (softwareVersionComparisonSuccessful(registryValue, actualRegistryValue, registryCompareOperator)) + { + statusMsg = " - PASSED"; + } + else + { + statusMsg = " - FAILED. Actual registry value of \"" + actualRegistryValue + "\" is not " + getStringEquivalentOfComparisonOperator(registryCompareOperator) + " the base registry value of \"" + registryValue + "\""; + setupSuccessful = false; + } } - } - } + else if (!String.Equals(actualRegistryValue, registryValue, StringComparison.OrdinalIgnoreCase)) + { + statusMsg = " - FAILED. Actual registry value of \"" + actualRegistryValue + "\" is not " + getStringEquivalentOfComparisonOperator(registryCompareOperator) + " the base registry value of \"" + registryValue + "\""; + setupSuccessful = false; + } + } + else + { + statusMsg = " - FAILED. Unable to find registry key's value name \"" + registryName + "\""; + setupSuccessful = false; + } + } + } + else + { + statusMsg = " - FAILED. Unable to find registry key \"" + registryPath + "\". Either the registry key is wrong or the software is not installed."; + setupSuccessful = false; + } + } + } + + if (rkSubKey != null) + rkSubKey.Close(); + + if (hklm != null) + hklm.Close(); + + return setupSuccessful; + } + + static bool softwareVersionComparisonSuccessful(string baseVersion, string actualVersion, string compareOperator) + { + bool compareSuccess = false; + List baseVersionParts = new List(baseVersion.Split('.').ToList()); + List actualVersionParts = new List(actualVersion.Split('.').ToList()); + int actualVal = 0, expectedVal = 0; + + // remove any trailing .0 + for (int i = baseVersionParts.Count - 1; i >= 0; --i) + { + if (i != 0 && Regex.IsMatch(baseVersionParts[i], @"^[0]+$", RegexOptions.IgnoreCase)) + { + baseVersionParts.RemoveAt(i); + } + else + break; + } + + // remove any trailing .0 + for (int i = actualVersionParts.Count - 1; i >= 0; --i) + { + if (i != 0 && Regex.IsMatch(actualVersionParts[i], @"^[0]+$", RegexOptions.IgnoreCase)) + { + actualVersionParts.RemoveAt(i); + } + else + break; + } + + if (baseVersionParts.Count == 0) + baseVersionParts.Add("0"); + + if (actualVersionParts.Count == 0) + actualVersionParts.Add("0"); + + if (compareOperator.Length == 0) + compareOperator = "eq"; + + if (String.Equals(compareOperator, "eq", StringComparison.OrdinalIgnoreCase)) + { + compareSuccess = actualAndBaseVersionsAreEqual(baseVersionParts, actualVersionParts); + } + else if (String.Equals(compareOperator, "ne", StringComparison.OrdinalIgnoreCase)) + { + compareSuccess = !actualAndBaseVersionsAreEqual(baseVersionParts, actualVersionParts); + } + else if (String.Equals(compareOperator, "lte", StringComparison.OrdinalIgnoreCase)) + { + bool isEqual = false; + + for (int i = 0; i < actualVersionParts.Count; i++) + { + if (baseVersionParts.Count >= i + 1) + { + if (Int32.TryParse(actualVersionParts[i], out actualVal) && Int32.TryParse(baseVersionParts[i], out expectedVal)) + { + if (actualVal < expectedVal) + { + isEqual = false; + compareSuccess = true; + break; + } + else if (actualVal > expectedVal) + { + isEqual = false; + break; + } + else if (i == actualVersionParts.Count - 1 && actualVersionParts.Count == baseVersionParts.Count) + { + isEqual = false; + compareSuccess = true; + break; + } + else + isEqual = true; + } + } } - return compareSuccess; - } + if (isEqual && baseVersionParts.Count > actualVersionParts.Count) + compareSuccess = true; + } + else if (String.Equals(compareOperator, "gte", StringComparison.OrdinalIgnoreCase)) + { + for (int i = 0; i < actualVersionParts.Count; i++) + { + if (baseVersionParts.Count >= i + 1) + { + if (Int32.TryParse(actualVersionParts[i], out actualVal) && Int32.TryParse(baseVersionParts[i], out expectedVal)) + { + if (actualVal > expectedVal) + { + compareSuccess = true; + break; + } + else if (actualVal < expectedVal) + break; + else if (i == actualVersionParts.Count - 1 && actualVersionParts.Count == baseVersionParts.Count) + { + compareSuccess = true; + break; + } + } + } + else + { + compareSuccess = true; + break; + } + } + } + else if (String.Equals(compareOperator, "gt", StringComparison.OrdinalIgnoreCase)) + { + for (int i = 0; i < actualVersionParts.Count; i++) + { + if (baseVersionParts.Count >= i + 1) + { + if (Int32.TryParse(actualVersionParts[i], out actualVal) && Int32.TryParse(baseVersionParts[i], out expectedVal)) + { + if (actualVal > expectedVal) + { + compareSuccess = true; + break; + } + } + } + else + { + compareSuccess = true; + break; + } + } + } + else if (String.Equals(compareOperator, "lt", StringComparison.OrdinalIgnoreCase)) + { + compareSuccess = true; + bool isEqual = false; - public static string getStringEquivalentOfComparisonOperator(string compareOperator) - { - string description = ""; - - if (String.Equals(compareOperator, "eq", StringComparison.OrdinalIgnoreCase)) + for (int i = 0; i < actualVersionParts.Count; i++) { - description = "equal to"; - } - else if (String.Equals(compareOperator, "lte", StringComparison.OrdinalIgnoreCase)) - { - description = "less than or equal to"; - } - else if (String.Equals(compareOperator, "gte", StringComparison.OrdinalIgnoreCase)) - { - description = "greater than or equal to"; - } - else if (String.Equals(compareOperator, "gt", StringComparison.OrdinalIgnoreCase)) - { - description = "greater than"; - } - else if (String.Equals(compareOperator, "lt", StringComparison.OrdinalIgnoreCase)) - { - description = "less than"; - } - else if (String.Equals(compareOperator, "ne", StringComparison.OrdinalIgnoreCase)) - { - description = "not equal to"; ; + if (baseVersionParts.Count >= i + 1) + { + if (Int32.TryParse(actualVersionParts[i], out actualVal) && Int32.TryParse(baseVersionParts[i], out expectedVal)) + { + if (actualVal > expectedVal) + { + isEqual = false; + compareSuccess = false; + break; + } + else if (actualVal < expectedVal) + { + isEqual = false; + break; + } + else + isEqual = true; + } + } } - return description; - } + if (isEqual && baseVersionParts.Count == actualVersionParts.Count) + compareSuccess = false; + } - // get all the necessary info if user choose to verify software by looking for exe name - public void getInfoUsingExeVerification(List> iniKeys, ref string setupFile, ref string exeFile, ref bool promptBeforeInstall, ref bool rebootComputerAtCompletionRequested, ref bool rebootComputerImmediatelyRequested) - { - setupFile = ""; - exeFile = ""; - // for every key specified for the app to be installed/checked - foreach (ConfigFileManager.Ini_KeyValue iniKey in iniKeys) + return compareSuccess; + } + + private static bool actualAndBaseVersionsAreEqual(List baseVersionParts, List actualVersionParts) + { + bool compareSuccess = true; + int actualVal = 0, baseVal = 0; + + if (baseVersionParts.Count != actualVersionParts.Count) + compareSuccess = false; + else + { + for (int i = 0; i < actualVersionParts.Count; i++) { - if (Regex.IsMatch(iniKey.iniKeyName, @"app\d+_setup_file", RegexOptions.IgnoreCase)) - { - setupFile = iniKey.alternateValue; - } - else if (Regex.IsMatch(iniKey.iniKeyName, @"app\d+_exe_file", RegexOptions.IgnoreCase)) - { - exeFile = iniKey.iniValue; - } - else if (Regex.IsMatch(iniKey.iniKeyName, @"app\d+_setup_confirm_prompt", RegexOptions.IgnoreCase)) - { - if (String.Equals(iniKey.iniValue, "yes", StringComparison.OrdinalIgnoreCase)) - promptBeforeInstall = true; - else - promptBeforeInstall = false; - } - else if (Regex.IsMatch(iniKey.iniKeyName, @"app\d+_reboot_computer_at_completion", RegexOptions.IgnoreCase)) - { - if (String.Equals(iniKey.iniValue, "yes", StringComparison.OrdinalIgnoreCase)) - rebootComputerAtCompletionRequested = true; - else - rebootComputerAtCompletionRequested = false; - } - else if (Regex.IsMatch(iniKey.iniKeyName, @"app\d+_reboot_computer_immediately", RegexOptions.IgnoreCase)) - { - if (String.Equals(iniKey.iniValue, "yes", StringComparison.OrdinalIgnoreCase)) - rebootComputerImmediatelyRequested = true; - else - rebootComputerImmediatelyRequested = false; - } + if (baseVersionParts.Count >= i + 1) + { + if (Int32.TryParse(actualVersionParts[i], out actualVal) && Int32.TryParse(baseVersionParts[i], out baseVal)) + { + if (actualVal != baseVal) + { + compareSuccess = false; + break; + } + } + } } - } + } - // get all the necessary info if user choose to verify software by looking at the registry - public void getInfoUsingRegistryVerification(List> iniKeys, ref string registryPath, ref string registryDisplayName, - ref string registryType, ref string registryName, ref string registryValue, ref string registryCompareOperator, ref string installArgs, ref string exitCodesToIgnore, ref string installProcessName) - { - registryPath = ""; - registryDisplayName = ""; - registryType = ""; - registryName = ""; - registryValue = ""; - registryCompareOperator = ""; - installArgs = ""; - exitCodesToIgnore = ""; + return compareSuccess; + } - // for every key specified for the app to be installed/checked - foreach (ConfigFileManager.Ini_KeyValue iniKey in iniKeys) + public static string getStringEquivalentOfComparisonOperator(string compareOperator) + { + string description = ""; + + if (String.Equals(compareOperator, "eq", StringComparison.OrdinalIgnoreCase)) + { + description = "equal to"; + } + else if (String.Equals(compareOperator, "lte", StringComparison.OrdinalIgnoreCase)) + { + description = "less than or equal to"; + } + else if (String.Equals(compareOperator, "gte", StringComparison.OrdinalIgnoreCase)) + { + description = "greater than or equal to"; + } + else if (String.Equals(compareOperator, "gt", StringComparison.OrdinalIgnoreCase)) + { + description = "greater than"; + } + else if (String.Equals(compareOperator, "lt", StringComparison.OrdinalIgnoreCase)) + { + description = "less than"; + } + else if (String.Equals(compareOperator, "ne", StringComparison.OrdinalIgnoreCase)) + { + description = "not equal to"; ; + } + + return description; + } + + // get all the necessary info if user choose to verify software by looking for exe name + public void getInfoUsingExeVerification(List> iniKeys, ref string setupFile, ref string exeFile, ref bool promptBeforeInstall, ref bool rebootComputerAtCompletionRequested, ref bool rebootComputerImmediatelyRequested) + { + setupFile = ""; + exeFile = ""; + // for every key specified for the app to be installed/checked + foreach (ConfigFileManager.Ini_KeyValue iniKey in iniKeys) + { + if (Regex.IsMatch(iniKey.iniKeyName, @"app\d+_setup_file", RegexOptions.IgnoreCase)) { - if (Regex.IsMatch(iniKey.iniKeyName, @"app\d+_reg_path$", RegexOptions.IgnoreCase)) - { - registryPath = iniKey.iniValue; - } - if (Regex.IsMatch(iniKey.iniKeyName, @"app\d+_reg_display_name$", RegexOptions.IgnoreCase)) - { - registryDisplayName = iniKey.iniValue; - } - else if (Regex.IsMatch(iniKey.iniKeyName, @"app\d+_reg_type", RegexOptions.IgnoreCase)) - { - registryType = iniKey.iniValue; - } - else if (Regex.IsMatch(iniKey.iniKeyName, @"app\d+_reg_name", RegexOptions.IgnoreCase)) - { - registryName = iniKey.iniValue; - } - else if (Regex.IsMatch(iniKey.iniKeyName, @"app\d+_reg_value", RegexOptions.IgnoreCase)) - { - registryValue = iniKey.iniValue; - } - else if (Regex.IsMatch(iniKey.iniKeyName, @"app\d+_reg_compare", RegexOptions.IgnoreCase)) - { - registryCompareOperator = iniKey.iniValue; - } - else if (Regex.IsMatch(iniKey.iniKeyName, @"app\d+_setup_argument", RegexOptions.IgnoreCase)) - { - installArgs = iniKey.iniValue; - } - else if (Regex.IsMatch(iniKey.iniKeyName, @"app\d+_exit_codes_to_ignore", RegexOptions.IgnoreCase)) - { - exitCodesToIgnore = iniKey.iniValue; - } - else if (Regex.IsMatch(iniKey.iniKeyName, @"app\d+_install_process_name", RegexOptions.IgnoreCase)) - { - installProcessName = iniKey.iniValue; - } + setupFile = iniKey.alternateValue; } - } - - bool processConfigInfo(KeyValuePair, List>> entry, - ref KeyValuePair, List>> processedEntry) - { - bool setupSuccessful = true; - ConfigFileManager.Ini_KeyValue iniVal = new ConfigFileManager.Ini_KeyValue(""); - ConfigFileManager.Ini_KeyValue iniVal2 = new ConfigFileManager.Ini_KeyValue(""); - string indentation = String.Empty; - string msg = "", msg2 = ""; - Match regExMatch; - - Dictionary, List>> tempOneToManyDict = new Dictionary, List>>(); - List textPropList = new List(); - - bool appVerifiedByCheckingRegistry = false; - bool appVerifiedByCheckingExe = false; - bool appRegistryTypeSpecified = false; - string appId = ""; - string registryKeyType = ""; - - appVerifiedByCheckingRegistry = false; - appVerifiedByCheckingExe = false; - appRegistryTypeSpecified = false; - - Dictionary idToPath = new Dictionary(StringComparer.OrdinalIgnoreCase); - - // for every key specified for the app to be installed - foreach (ConfigFileManager.Ini_KeyValue iniKey in entry.Value) + else if (Regex.IsMatch(iniKey.iniKeyName, @"app\d+_exe_file", RegexOptions.IgnoreCase)) { - regExMatch = Regex.Match(iniKey.iniKeyName, @"(app\d+)_.+$", RegexOptions.IgnoreCase); + exeFile = iniKey.iniValue; + } + else if (Regex.IsMatch(iniKey.iniKeyName, @"app\d+_setup_confirm_prompt", RegexOptions.IgnoreCase)) + { + if (String.Equals(iniKey.iniValue, "yes", StringComparison.OrdinalIgnoreCase)) + promptBeforeInstall = true; + else + promptBeforeInstall = false; + } + else if (Regex.IsMatch(iniKey.iniKeyName, @"app\d+_reboot_computer_at_completion", RegexOptions.IgnoreCase)) + { + if (String.Equals(iniKey.iniValue, "yes", StringComparison.OrdinalIgnoreCase) || String.Equals(iniKey.iniValue, "true", StringComparison.OrdinalIgnoreCase)) + rebootComputerAtCompletionRequested = true; + else + rebootComputerAtCompletionRequested = false; + } + else if (Regex.IsMatch(iniKey.iniKeyName, @"app\d+_reboot_computer_immediately", RegexOptions.IgnoreCase)) + { + if (String.Equals(iniKey.iniValue, "yes", StringComparison.OrdinalIgnoreCase) || String.Equals(iniKey.iniValue, "true", StringComparison.OrdinalIgnoreCase)) + rebootComputerImmediatelyRequested = true; + else + rebootComputerImmediatelyRequested = false; + } + } + } - if (regExMatch.Success) - appId = regExMatch.Groups[1].Value; + // get all the necessary info if user choose to verify software by looking at the registry + public void getInfoUsingRegistryVerification(List> iniKeys, ref string registryPath, ref string registryDisplayName, + ref string registryType, ref string registryName, ref string registryValue, ref string registryCompareOperator, ref string installArgs, ref string exitCodesToIgnore, ref string spawnedProcessesToIgnore) + { + registryPath = ""; + registryDisplayName = ""; + registryType = ""; + registryName = ""; + registryValue = ""; + registryCompareOperator = ""; + installArgs = ""; + exitCodesToIgnore = ""; - // user has specified the verification method - if (Regex.IsMatch(iniKey.iniKeyName, @"app\d+_exe_file", RegexOptions.IgnoreCase)) - { - appVerifiedByCheckingExe = true; - break; - } - else if (Regex.IsMatch(iniKey.iniKeyName, @"(app\d+)_reg_path$", RegexOptions.IgnoreCase) - || Regex.IsMatch(iniKey.iniKeyName, @"(app\d+)_reg_display_name$", RegexOptions.IgnoreCase)) - { - appVerifiedByCheckingRegistry = true; - } - else if (Regex.IsMatch(iniKey.iniKeyName, @"(app\d+)_reg_type$", RegexOptions.IgnoreCase)) - { - regExMatch = Regex.Match(iniKey.iniKeyName, @"(app\d+)_reg_type$", RegexOptions.IgnoreCase); + // for every key specified for the app to be installed/checked + foreach (ConfigFileManager.Ini_KeyValue iniKey in iniKeys) + { + if (Regex.IsMatch(iniKey.iniKeyName, @"app\d+_reg_path$", RegexOptions.IgnoreCase)) + { + registryPath = iniKey.iniValue; + } + if (Regex.IsMatch(iniKey.iniKeyName, @"app\d+_reg_display_name$", RegexOptions.IgnoreCase)) + { + registryDisplayName = iniKey.iniValue; + } + else if (Regex.IsMatch(iniKey.iniKeyName, @"app\d+_reg_type", RegexOptions.IgnoreCase)) + { + registryType = iniKey.iniValue; + } + else if (Regex.IsMatch(iniKey.iniKeyName, @"app\d+_reg_name", RegexOptions.IgnoreCase)) + { + registryName = iniKey.iniValue; + } + else if (Regex.IsMatch(iniKey.iniKeyName, @"app\d+_reg_value", RegexOptions.IgnoreCase)) + { + registryValue = iniKey.iniValue; + } + else if (Regex.IsMatch(iniKey.iniKeyName, @"app\d+_reg_compare", RegexOptions.IgnoreCase)) + { + registryCompareOperator = iniKey.iniValue; + } + else if (Regex.IsMatch(iniKey.iniKeyName, @"app\d+_setup_argument", RegexOptions.IgnoreCase)) + { + installArgs = iniKey.iniValue; + } + else if (Regex.IsMatch(iniKey.iniKeyName, @"app\d+_exit_codes_to_ignore", RegexOptions.IgnoreCase)) + { + exitCodesToIgnore = iniKey.iniValue; + } + else if (Regex.IsMatch(iniKey.iniKeyName, @"app\d+_spawned_processes_to_ignore", RegexOptions.IgnoreCase)) + { + spawnedProcessesToIgnore = iniKey.iniValue; + } + } + } - registryKeyType = regExMatch.Groups[1].Value; - appRegistryTypeSpecified = true; + bool processConfigInfo(KeyValuePair, List>> entry, + ref KeyValuePair, List>> processedEntry) + { + bool setupSuccessful = true; + ConfigFileManager.Ini_KeyValue iniVal = new ConfigFileManager.Ini_KeyValue(""); + ConfigFileManager.Ini_KeyValue iniVal2 = new ConfigFileManager.Ini_KeyValue(""); + string indentation = String.Empty; + string msg = "", msg2 = ""; + Match regExMatch; - if (!WindowsRegistryManager.registryTypeIsValid(iniKey.iniValue)) - { + Dictionary, List>> tempOneToManyDict = new Dictionary, List>>(); + List textPropList = new List(); + + bool appVerifiedByCheckingRegistry = false; + bool appVerifiedByCheckingExe = false; + bool appRegistryTypeSpecified = false; + string appId = ""; + string registryKeyType = ""; + + appVerifiedByCheckingRegistry = false; + appVerifiedByCheckingExe = false; + appRegistryTypeSpecified = false; + + Dictionary idToPath = new Dictionary(StringComparer.OrdinalIgnoreCase); + + // for every key specified for the app to be installed + foreach (ConfigFileManager.Ini_KeyValue iniKey in entry.Value) + { + regExMatch = Regex.Match(iniKey.iniKeyName, @"(app\d+)_.+$", RegexOptions.IgnoreCase); + + if (regExMatch.Success) + appId = regExMatch.Groups[1].Value; + + // user has specified the verification method + if (Regex.IsMatch(iniKey.iniKeyName, @"app\d+_exe_file", RegexOptions.IgnoreCase)) + { + appVerifiedByCheckingExe = true; + break; + } + else if (Regex.IsMatch(iniKey.iniKeyName, @"(app\d+)_reg_path$", RegexOptions.IgnoreCase) + || Regex.IsMatch(iniKey.iniKeyName, @"(app\d+)_reg_display_name$", RegexOptions.IgnoreCase)) + { + appVerifiedByCheckingRegistry = true; + } + else if (Regex.IsMatch(iniKey.iniKeyName, @"(app\d+)_reg_type$", RegexOptions.IgnoreCase)) + { + regExMatch = Regex.Match(iniKey.iniKeyName, @"(app\d+)_reg_type$", RegexOptions.IgnoreCase); + + registryKeyType = regExMatch.Groups[1].Value; + appRegistryTypeSpecified = true; + + if (!WindowsRegistryManager.registryTypeIsValid(iniKey.iniValue)) + { + indentation = Common.getIndentation(1); + msg = "\n" + indentation + "- FAILED. " + + "\n" + indentation + "File: " + ConfigFileManager.ms_configGeneralInfo.pathAndNameOfConfigFile + + "\n" + indentation + "Section: " + iniKey.iniSectionName + + "\n" + indentation + "Key: " + iniKey.iniKeyName + + "\n" + indentation + "Value: " + iniKey.iniValue + + "\n" + indentation + "Error Description: The value is invalid the INI file."; + + Common.formatConfigIniFailureMessage(msg, textPropList); + + UpdateStatusDisplayAndLogEvent(msg, msg, textPropList); + + setupSuccessful = false; + + break; + } + } + else if (Regex.IsMatch(iniKey.iniKeyName, @"app\d+_reg_compare", RegexOptions.IgnoreCase)) + { + string description = SoftwareInstallManager.getStringEquivalentOfComparisonOperator(iniKey.iniValue); + + if (description.Length == 0) + { + indentation = Common.getIndentation(1); + msg = "\n" + indentation + "- FAILED. " + + "\n" + indentation + "File: " + ConfigFileManager.ms_configGeneralInfo.pathAndNameOfConfigFile + + "\n" + indentation + "Section: " + iniKey.iniSectionName + + "\n" + indentation + "Key: " + iniKey.iniKeyName + + "\n" + indentation + "Value: " + iniKey.iniValue + + "\n" + indentation + "Error Description: The value is invalid the INI file."; + + Common.formatConfigIniFailureMessage(msg, textPropList); + + UpdateStatusDisplayAndLogEvent(msg, msg, textPropList); + + setupSuccessful = false; + + break; + } + } + else if (Regex.IsMatch(iniKey.iniKeyName, @"app\d+_setup_file", RegexOptions.IgnoreCase) && iniKey.iniValue.Length > 0) + { + iniVal = iniKey; + + if (!Common.pathContainsMacro(iniKey.iniValue)) + { + iniVal.alternateValue = Path.GetFullPath(iniKey.iniValue); + + // check only relative path + if (!Path.IsPathRooted(iniKey.iniValue) && (!File.Exists(iniVal.alternateValue))) + { + indentation = Common.getIndentation(1); + msg = "\n" + indentation + "- FAILED. " + + "\n" + indentation + "File: " + ConfigFileManager.ms_configGeneralInfo.pathAndNameOfConfigFile + + "\n" + indentation + "Section: " + iniKey.iniSectionName + + "\n" + indentation + "Key: " + iniKey.iniKeyName + + "\n" + indentation + "Value: " + iniKey.iniValue + + "\n" + indentation + "Error Description: The path defined in the value above is invalid. Translated path " + iniVal.alternateValue; + + Common.formatConfigIniFailureMessage(msg, textPropList); + + UpdateStatusDisplayAndLogEvent(msg, msg, textPropList); + + setupSuccessful = false; + + break; + } + } + else // the path specified contains macros, we have to resolve macros + { + iniVal.alternateValue = Common.resolveMacroPath(iniKey.iniValue); + + if (Common.pathContainsCdDriveMacro(iniKey.iniValue)) + { + if (iniVal.alternateValue.Length == 0) + { + setupSuccessful = false; + msg2 = PathManip.enumWindowsDesignatedPaths.CD_DRIVE.ToString() + " macro was defined. But no CD drive is found in the system"; + } + //else + //{ + // setupSuccessful = Common.validatePathInCdDrive(iniVal.alternateValue, m_parentForm); + // msg2 = "\"" + iniVal.alternateValue + "\" does not exist. Please insert a CD with that path"; + //} + + if (!setupSuccessful) + { indentation = Common.getIndentation(1); msg = "\n" + indentation + "- FAILED. " + "\n" + indentation + "File: " + ConfigFileManager.ms_configGeneralInfo.pathAndNameOfConfigFile + "\n" + indentation + "Section: " + iniKey.iniSectionName + "\n" + indentation + "Key: " + iniKey.iniKeyName + "\n" + indentation + "Value: " + iniKey.iniValue - + "\n" + indentation + "Error Description: The value is invalid the INI file."; + + "\n" + indentation + "Error Description: " + msg2; Common.formatConfigIniFailureMessage(msg, textPropList); UpdateStatusDisplayAndLogEvent(msg, msg, textPropList); + } + } + } + } + else if (Regex.IsMatch(iniKey.iniKeyName, @"(app\d+)_setup_argument$", RegexOptions.IgnoreCase)) + { + MatchCollection matches = Regex.Matches(iniKey.iniValue, @"\{([^\{\}]+)\}", RegexOptions.IgnoreCase); - setupSuccessful = false; + if (matches.Count > 0) + { + // each match can have multiple parts i.e. $1 $2...$n + for (int i = 0; i < matches.Count; i++) + { + // matches[i].Groups[0].Value is the actual macro itself, i.e. {keyname} + // matches[i].Groups[1].Value is the string inside curly brackets, i.e. keyname + string pattern = Regex.Escape(matches[i].Groups[1].Value); - break; - } - } - else if (Regex.IsMatch(iniKey.iniKeyName, @"app\d+_reg_compare", RegexOptions.IgnoreCase)) - { - string description = SoftwareInstallManager.getStringEquivalentOfComparisonOperator(iniKey.iniValue); + // looking for a key that defines the actual path to be used in the argument + int matchedPathIndex = entry.Value.FindIndex(x => Regex.IsMatch(x.iniKeyName, pattern, RegexOptions.IgnoreCase)); - if (description.Length == 0) - { + // if the macro in the argument refers to another key the defines a path + if (matchedPathIndex >= 0 && !idToPath.ContainsKey(matches[i].Groups[0].Value)) + { + string resolvedPath = Common.resolveMacroPath(entry.Value[matchedPathIndex].iniValue); + + if (Common.pathContainsCdDriveMacro(entry.Value[matchedPathIndex].iniValue)) + { + if (resolvedPath.Length == 0) + { + setupSuccessful = false; + msg2 = matches[i].Groups[1].Value + " macro was defined. But no CD drive is found in the system"; + } + else + { + setupSuccessful = Common.validatePathInCdDrive(resolvedPath, m_parentForm); + msg2 = "\"" + resolvedPath + "\" does not exist. Please insert a CD with that path"; + } + + if (!setupSuccessful) + { + indentation = Common.getIndentation(1); + msg = "\n" + indentation + "- FAILED. " + + "\n" + indentation + "File: " + ConfigFileManager.ms_configGeneralInfo.pathAndNameOfConfigFile + + "\n" + indentation + "Section: " + iniKey.iniSectionName + + "\n" + indentation + "Key: " + iniKey.iniKeyName + + "\n" + indentation + "Value: " + iniKey.iniValue + + "\n" + indentation + "Error Description: " + msg2; + + Common.formatConfigIniFailureMessage(msg, textPropList); + + UpdateStatusDisplayAndLogEvent(msg, msg, textPropList); + } + } + + if (PathManip.PathIsFile(resolvedPath)) + idToPath[matches[i].Groups[0].Value] = Path.GetDirectoryName(Path.GetFullPath(resolvedPath)); + else + idToPath[matches[i].Groups[0].Value] = Path.GetFullPath(resolvedPath); + } + // if the macro refers to user's desktop, temp folder, cd drive + else if (Common.pathContainsMacro(matches[i].Groups[0].Value) && !idToPath.ContainsKey(matches[i].Groups[0].Value)) + { + string resolvedPath = Common.resolveMacroPath(matches[i].Groups[0].Value); + + if (Common.pathContainsCdDriveMacro(matches[i].Groups[0].Value)) + { + if (resolvedPath.Length == 0) + { + setupSuccessful = false; + msg2 = matches[i].Groups[1].Value + " macro was defined. But no CD drive is found in the system"; + } + + if (!setupSuccessful) + { + indentation = Common.getIndentation(1); + msg = "\n" + indentation + "- FAILED. " + + "\n" + indentation + "File: " + ConfigFileManager.ms_configGeneralInfo.pathAndNameOfConfigFile + + "\n" + indentation + "Section: " + iniKey.iniSectionName + + "\n" + indentation + "Key: " + iniKey.iniKeyName + + "\n" + indentation + "Value: " + iniKey.iniValue + + "\n" + indentation + "Error Description: " + msg2; + + Common.formatConfigIniFailureMessage(msg, textPropList); + + UpdateStatusDisplayAndLogEvent(msg, msg, textPropList); + } + } + + idToPath[matches[i].Groups[0].Value] = resolvedPath; + } + else + { indentation = Common.getIndentation(1); msg = "\n" + indentation + "- FAILED. " + "\n" + indentation + "File: " + ConfigFileManager.ms_configGeneralInfo.pathAndNameOfConfigFile + "\n" + indentation + "Section: " + iniKey.iniSectionName + "\n" + indentation + "Key: " + iniKey.iniKeyName + "\n" + indentation + "Value: " + iniKey.iniValue - + "\n" + indentation + "Error Description: The value is invalid the INI file."; + + "\n" + indentation + "Error Description: The value above specifies a variable \"" + matches[i].Groups[0].Value + "\" in the argument." + + " Key \"" + iniKey.iniKeyName + "_" + matches[i].Groups[1].Value + + "\" must be defined to specify the actual path for variable \"" + matches[i].Groups[0].Value + "\""; Common.formatConfigIniFailureMessage(msg, textPropList); @@ -1248,266 +1420,97 @@ namespace All_Purpose_Auto_Setup setupSuccessful = false; break; - } - } - else if (Regex.IsMatch(iniKey.iniKeyName, @"app\d+_setup_file", RegexOptions.IgnoreCase) && iniKey.iniValue.Length > 0) - { - iniVal = iniKey; + } + } + } - if (!Common.pathContainsMacro(iniKey.iniValue)) - { - iniVal.alternateValue = Path.GetFullPath(iniKey.iniValue); - - // check only relative path - if (!Path.IsPathRooted(iniKey.iniValue) && (!File.Exists(iniVal.alternateValue))) - { - indentation = Common.getIndentation(1); - msg = "\n" + indentation + "- FAILED. " - + "\n" + indentation + "File: " + ConfigFileManager.ms_configGeneralInfo.pathAndNameOfConfigFile - + "\n" + indentation + "Section: " + iniKey.iniSectionName - + "\n" + indentation + "Key: " + iniKey.iniKeyName - + "\n" + indentation + "Value: " + iniKey.iniValue - + "\n" + indentation + "Error Description: The path defined in the value above is invalid. Translated path " + iniVal.alternateValue; - - Common.formatConfigIniFailureMessage(msg, textPropList); - - UpdateStatusDisplayAndLogEvent(msg, msg, textPropList); - - setupSuccessful = false; - - break; - } - } - else // the path specified contains macros, we have to resolve macros - { - iniVal.alternateValue = Common.resolveMacroPath(iniKey.iniValue); - - if (Common.pathContainsCdDriveMacro(iniKey.iniValue)) - { - if (iniVal.alternateValue.Length == 0) - { - setupSuccessful = false; - msg2 = PathManip.enumWindowsDesignatedPaths.CD_DRIVE.ToString() + " macro was defined. But no CD drive is found in the system"; - } - //else - //{ - // setupSuccessful = Common.validatePathInCdDrive(iniVal.alternateValue, m_parentForm); - // msg2 = "\"" + iniVal.alternateValue + "\" does not exist. Please insert a CD with that path"; - //} - - if (!setupSuccessful) - { - indentation = Common.getIndentation(1); - msg = "\n" + indentation + "- FAILED. " - + "\n" + indentation + "File: " + ConfigFileManager.ms_configGeneralInfo.pathAndNameOfConfigFile - + "\n" + indentation + "Section: " + iniKey.iniSectionName - + "\n" + indentation + "Key: " + iniKey.iniKeyName - + "\n" + indentation + "Value: " + iniKey.iniValue - + "\n" + indentation + "Error Description: " + msg2; - - Common.formatConfigIniFailureMessage(msg, textPropList); - - UpdateStatusDisplayAndLogEvent(msg, msg, textPropList); - } - } - } - } - else if (Regex.IsMatch(iniKey.iniKeyName, @"(app\d+)_setup_argument$", RegexOptions.IgnoreCase)) - { - MatchCollection matches = Regex.Matches(iniKey.iniValue, @"\{([^\{\}]+)\}", RegexOptions.IgnoreCase); - - if (matches.Count > 0) - { - // each match can have multiple parts i.e. $1 $2...$n - for (int i = 0; i < matches.Count; i++) - { - // matches[i].Groups[0].Value is the actual macro itself, i.e. {keyname} - // matches[i].Groups[1].Value is the string inside curly brackets, i.e. keyname - string pattern = Regex.Escape(matches[i].Groups[1].Value); - - // looking for a key that defines the actual path to be used in the argument - int matchedPathIndex = entry.Value.FindIndex(x => Regex.IsMatch(x.iniKeyName, pattern, RegexOptions.IgnoreCase)); - - // if the macro in the argument refers to another key the defines a path - if (matchedPathIndex >= 0 && !idToPath.ContainsKey(matches[i].Groups[0].Value)) - { - string resolvedPath = Common.resolveMacroPath(entry.Value[matchedPathIndex].iniValue); - - if (Common.pathContainsCdDriveMacro(entry.Value[matchedPathIndex].iniValue)) - { - if (resolvedPath.Length == 0) - { - setupSuccessful = false; - msg2 = matches[i].Groups[1].Value + " macro was defined. But no CD drive is found in the system"; - } - else - { - setupSuccessful = Common.validatePathInCdDrive(resolvedPath, m_parentForm); - msg2 = "\"" + resolvedPath + "\" does not exist. Please insert a CD with that path"; - } - - if (!setupSuccessful) - { - indentation = Common.getIndentation(1); - msg = "\n" + indentation + "- FAILED. " - + "\n" + indentation + "File: " + ConfigFileManager.ms_configGeneralInfo.pathAndNameOfConfigFile - + "\n" + indentation + "Section: " + iniKey.iniSectionName - + "\n" + indentation + "Key: " + iniKey.iniKeyName - + "\n" + indentation + "Value: " + iniKey.iniValue - + "\n" + indentation + "Error Description: " + msg2; - - Common.formatConfigIniFailureMessage(msg, textPropList); - - UpdateStatusDisplayAndLogEvent(msg, msg, textPropList); - } - } - - if (PathManip.PathIsFile(resolvedPath)) - idToPath[matches[i].Groups[0].Value] = Path.GetDirectoryName(Path.GetFullPath(resolvedPath)); - else - idToPath[matches[i].Groups[0].Value] = Path.GetFullPath(resolvedPath); - } - // if the macro refers to user's desktop, temp folder, cd drive - else if (Common.pathContainsMacro(matches[i].Groups[0].Value) && !idToPath.ContainsKey(matches[i].Groups[0].Value)) - { - string resolvedPath = Common.resolveMacroPath(matches[i].Groups[0].Value); - - if (Common.pathContainsCdDriveMacro(matches[i].Groups[0].Value)) - { - if (resolvedPath.Length == 0) - { - setupSuccessful = false; - msg2 = matches[i].Groups[1].Value + " macro was defined. But no CD drive is found in the system"; - } - - if (!setupSuccessful) - { - indentation = Common.getIndentation(1); - msg = "\n" + indentation + "- FAILED. " - + "\n" + indentation + "File: " + ConfigFileManager.ms_configGeneralInfo.pathAndNameOfConfigFile - + "\n" + indentation + "Section: " + iniKey.iniSectionName - + "\n" + indentation + "Key: " + iniKey.iniKeyName - + "\n" + indentation + "Value: " + iniKey.iniValue - + "\n" + indentation + "Error Description: " + msg2; - - Common.formatConfigIniFailureMessage(msg, textPropList); - - UpdateStatusDisplayAndLogEvent(msg, msg, textPropList); - } - } - - idToPath[matches[i].Groups[0].Value] = resolvedPath; - } - else - { - indentation = Common.getIndentation(1); - msg = "\n" + indentation + "- FAILED. " - + "\n" + indentation + "File: " + ConfigFileManager.ms_configGeneralInfo.pathAndNameOfConfigFile - + "\n" + indentation + "Section: " + iniKey.iniSectionName - + "\n" + indentation + "Key: " + iniKey.iniKeyName - + "\n" + indentation + "Value: " + iniKey.iniValue - + "\n" + indentation + "Error Description: The value above specifies a variable \"" + matches[i].Groups[0].Value + "\" in the argument." - + " Key \"" + iniKey.iniKeyName + "_" + matches[i].Groups[1].Value - + "\" must be defined to specify the actual path for variable \"" + matches[i].Groups[0].Value + "\""; - - Common.formatConfigIniFailureMessage(msg, textPropList); - - UpdateStatusDisplayAndLogEvent(msg, msg, textPropList); - - setupSuccessful = false; - - break; - } - } - } - - if (!setupSuccessful) - break; - } + if (!setupSuccessful) + break; } + } - if (setupSuccessful) + if (setupSuccessful) + { + + if (appVerifiedByCheckingExe) { - - if (appVerifiedByCheckingExe) - { - tempOneToManyDict[entry.Key] = new List>(entry.Value); - } - else if (appVerifiedByCheckingRegistry) - { - if (!appRegistryTypeSpecified) - { - indentation = Common.getIndentation(1); - msg = "\n" + indentation + "- FAILED. " - + "\n" + indentation + "File: " + ConfigFileManager.ms_configGeneralInfo.pathAndNameOfConfigFile - + "\n" + indentation + "Section: " + entry.Key.iniSectionName - + "\n" + indentation + "Error Description: The key name " + appId + "_reg_type is missing in the above section in the INI file."; - - Common.formatConfigIniFailureMessage(msg, textPropList); - - UpdateStatusDisplayAndLogEvent(msg, msg, textPropList); - - setupSuccessful = false; - - } - - if (setupSuccessful) - { - tempOneToManyDict[entry.Key] = new List>(entry.Value); - } - } - else - { - indentation = Common.getIndentation(1); - msg = "\n" + indentation + "- FAILED. " - + "\n" + indentation + "File: " + ConfigFileManager.ms_configGeneralInfo.pathAndNameOfConfigFile - + "\n" + indentation + "Section: " + entry.Key.iniSectionName - + "\n" + indentation + "Error Description: One of the following 3 key names must be defined: " + appId + "_exe_file, " + appId + "_reg_path, " + appId + "_reg_display_name, "; - - Common.formatConfigIniFailureMessage(msg, textPropList); - - UpdateStatusDisplayAndLogEvent(msg, msg, textPropList); - - setupSuccessful = false; - } + tempOneToManyDict[entry.Key] = new List>(entry.Value); } - - if (setupSuccessful) + else if (appVerifiedByCheckingRegistry) { - int matchedArgumentIndex = -1; + if (!appRegistryTypeSpecified) + { + indentation = Common.getIndentation(1); + msg = "\n" + indentation + "- FAILED. " + + "\n" + indentation + "File: " + ConfigFileManager.ms_configGeneralInfo.pathAndNameOfConfigFile + + "\n" + indentation + "Section: " + entry.Key.iniSectionName + + "\n" + indentation + "Error Description: The key name " + appId + "_reg_type is missing in the above section in the INI file."; - matchedArgumentIndex = tempOneToManyDict[entry.Key].FindIndex(x => Regex.IsMatch(x.iniKeyName, @"app\d+_setup_file$", RegexOptions.IgnoreCase)); + Common.formatConfigIniFailureMessage(msg, textPropList); - if (matchedArgumentIndex >= 0) - { - tempOneToManyDict[entry.Key][matchedArgumentIndex] = iniVal; - } + UpdateStatusDisplayAndLogEvent(msg, msg, textPropList); - if (idToPath.Count > 0) - { - matchedArgumentIndex = -1; - foreach (KeyValuePair item in idToPath) - { - if (matchedArgumentIndex < 0) - { - matchedArgumentIndex = tempOneToManyDict[entry.Key].FindIndex(x => Regex.IsMatch(x.iniKeyName, @"app\d+_setup_argument$", RegexOptions.IgnoreCase)); - iniVal2 = tempOneToManyDict[entry.Key][matchedArgumentIndex]; - } + setupSuccessful = false; - if (matchedArgumentIndex >= 0) - { - iniVal2.iniValue = Regex.Replace(iniVal2.iniValue, Regex.Escape(item.Key), item.Value, RegexOptions.IgnoreCase); - } - } + } - if (matchedArgumentIndex >= 0) - tempOneToManyDict[entry.Key][matchedArgumentIndex] = iniVal2; - } + if (setupSuccessful) + { + tempOneToManyDict[entry.Key] = new List>(entry.Value); + } + } + else + { + indentation = Common.getIndentation(1); + msg = "\n" + indentation + "- FAILED. " + + "\n" + indentation + "File: " + ConfigFileManager.ms_configGeneralInfo.pathAndNameOfConfigFile + + "\n" + indentation + "Section: " + entry.Key.iniSectionName + + "\n" + indentation + "Error Description: One of the following 3 key names must be defined: " + appId + "_exe_file, " + appId + "_reg_path, " + appId + "_reg_display_name, "; - processedEntry = new KeyValuePair, List>>(entry.Key, new List>(tempOneToManyDict[entry.Key])); + Common.formatConfigIniFailureMessage(msg, textPropList); + + UpdateStatusDisplayAndLogEvent(msg, msg, textPropList); + + setupSuccessful = false; + } + } + + if (setupSuccessful) + { + int matchedArgumentIndex = -1; + + matchedArgumentIndex = tempOneToManyDict[entry.Key].FindIndex(x => Regex.IsMatch(x.iniKeyName, @"app\d+_setup_file$", RegexOptions.IgnoreCase)); + + if (matchedArgumentIndex >= 0) + { + tempOneToManyDict[entry.Key][matchedArgumentIndex] = iniVal; } - return setupSuccessful; - } - } + if (idToPath.Count > 0) + { + matchedArgumentIndex = -1; + foreach (KeyValuePair item in idToPath) + { + if (matchedArgumentIndex < 0) + { + matchedArgumentIndex = tempOneToManyDict[entry.Key].FindIndex(x => Regex.IsMatch(x.iniKeyName, @"app\d+_setup_argument$", RegexOptions.IgnoreCase)); + iniVal2 = tempOneToManyDict[entry.Key][matchedArgumentIndex]; + } + + if (matchedArgumentIndex >= 0) + { + iniVal2.iniValue = Regex.Replace(iniVal2.iniValue, Regex.Escape(item.Key), item.Value, RegexOptions.IgnoreCase); + } + } + + if (matchedArgumentIndex >= 0) + tempOneToManyDict[entry.Key][matchedArgumentIndex] = iniVal2; + } + + processedEntry = new KeyValuePair, List>>(entry.Key, new List>(tempOneToManyDict[entry.Key])); + } + + return setupSuccessful; + } + } } diff --git a/AllPurposeAutoSetup/WindowFeaturesManager.cs b/AllPurposeAutoSetup/WindowFeaturesManager.cs index ae93b17..933ad89 100644 --- a/AllPurposeAutoSetup/WindowFeaturesManager.cs +++ b/AllPurposeAutoSetup/WindowFeaturesManager.cs @@ -1,23 +1,12 @@ using System; using System.Collections.Generic; using System.ComponentModel; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; -using System.Threading; using System.Diagnostics; -using System.Text.RegularExpressions; -using System.IO; -using System.Security.AccessControl; -using System.Management; -using System.Security.Principal; -using System.Runtime.InteropServices; -using Microsoft.Win32; using System.Drawing; - -using CommonLib.Windows.Forms; -using CommonLib.IO; +using System.IO; +using System.Text.RegularExpressions; +using System.Threading; +using System.Windows.Forms; using CommonLib.Misc; namespace All_Purpose_Auto_Setup @@ -349,7 +338,7 @@ namespace All_Purpose_Auto_Setup // First, handle the case where an exception was thrown. if (e.Error != null) { - + } else if (e.Cancelled) // user cancelled { @@ -433,7 +422,7 @@ namespace All_Purpose_Auto_Setup Thread.Sleep(500); } - } + } void cmd_WindowFeature_DataReceived(object sender, DataReceivedEventArgs e) { diff --git a/AllPurposeAutoSetup/WindowsRegistryManager.cs b/AllPurposeAutoSetup/WindowsRegistryManager.cs index a41478e..aa848e3 100644 --- a/AllPurposeAutoSetup/WindowsRegistryManager.cs +++ b/AllPurposeAutoSetup/WindowsRegistryManager.cs @@ -1,24 +1,11 @@ using System; using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; -using System.Threading; -using System.Diagnostics; -using System.Text.RegularExpressions; -using System.IO; -using System.Security.AccessControl; -using System.Management; -using System.Security.Principal; -using System.Runtime.InteropServices; -using Microsoft.Win32; using System.Drawing; - -using CommonLib.Windows.Forms; -using CommonLib.IO; +using System.Text.RegularExpressions; +using System.Windows.Forms; using CommonLib.Misc; using CommonLib.Windows.Misc; +using Microsoft.Win32; namespace All_Purpose_Auto_Setup { @@ -149,9 +136,9 @@ namespace All_Purpose_Auto_Setup if (String.Equals(registryAction, "delete", StringComparison.OrdinalIgnoreCase)) { - setupSuccessful = WindowsRegistry.DeleteRegistryValueName(registryPath, getRegistryHive(registryType), entry.Key, ref errMsg); + setupSuccessful = WindowsRegistry.DeleteRegistryValueName(registryPath, getRegistryHive(registryType), entry.Key, ref errMsg); - msg1 = "\n" + indentation + "Deleting value name " + entry.Key + " in " + registryPath; + msg1 = "\n" + indentation + "Deleting value name " + entry.Key + " in " + registryPath; } else // add to registry { @@ -207,7 +194,7 @@ namespace All_Purpose_Auto_Setup } } - if ( msg1.Length > 0 ) + if (msg1.Length > 0) { // set font to default text and color @@ -270,7 +257,7 @@ namespace All_Purpose_Auto_Setup UpdateStatusDisplayAndLogEvent(msg1, msg1, textPropList1); UpdateStatusDisplayAndLogEvent(msg2, msg2, textPropList2); - + } if (!setupSuccessful) @@ -370,7 +357,7 @@ namespace All_Purpose_Auto_Setup } public void getRegistryInfo(List> iniKeys, ref string action, - ref string registryType, Dictionary nameValuePairs) + ref string registryType, Dictionary nameValuePairs) { Match regExMatch; registryType = ""; @@ -448,9 +435,9 @@ namespace All_Purpose_Auto_Setup RegistryHive regHive = RegistryHive.LocalMachine; if (String.Equals(regType, "local_machine", StringComparison.OrdinalIgnoreCase)) - regHive = RegistryHive.LocalMachine; + regHive = RegistryHive.LocalMachine; else if (String.Equals(regType, "classes_root", StringComparison.OrdinalIgnoreCase)) - regHive = RegistryHive.ClassesRoot; + regHive = RegistryHive.ClassesRoot; else if (String.Equals(regType, "current_user", StringComparison.OrdinalIgnoreCase)) regHive = RegistryHive.CurrentUser; else @@ -535,7 +522,7 @@ namespace All_Purpose_Auto_Setup regExMatch = Regex.Match(iniKey.iniValue, @"\[\s*name\s*:\s*(.*[^\s])\s*,\s*value\s*:\s*(.*[^\s])\s*,\s*type\s*:\s*(.*[a-zA-Z])\s*\]", RegexOptions.IgnoreCase); // match multi value - if ( !regExMatch.Success ) + if (!regExMatch.Success) regExMatch = Regex.Match(iniKey.iniValue, @"\[\s*name\s*:\s*(.*[^\s])\s*,\s*:\s*value\s*:\s*(.*[^\s])\s*,\s*type\s*:\s*(.*[a-zA-Z])\s*\]", RegexOptions.IgnoreCase); } diff --git a/AllPurposeAutoSetup/WindowsShortcutManager.cs b/AllPurposeAutoSetup/WindowsShortcutManager.cs index 29ffff7..968aa36 100644 --- a/AllPurposeAutoSetup/WindowsShortcutManager.cs +++ b/AllPurposeAutoSetup/WindowsShortcutManager.cs @@ -1,23 +1,12 @@ using System; using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; -using System.Threading; -using System.Diagnostics; -using System.Text.RegularExpressions; -using System.IO; -using System.Security.AccessControl; -using System.Management; -using System.Security.Principal; -using System.Runtime.InteropServices; -using Microsoft.Win32; using System.Drawing; - -using CommonLib.Windows.Forms; +using System.IO; +using System.Text.RegularExpressions; +using System.Windows.Forms; using CommonLib.IO; using CommonLib.Misc; +using CommonLib.Windows.Forms; using CommonLib.Windows.Misc; namespace All_Purpose_Auto_Setup @@ -154,7 +143,7 @@ namespace All_Purpose_Auto_Setup statusGiven = true; } } - + if (!statusGiven && File.Exists(shortcutPath)) { msg2 = ((frmSetupStatusDisplay)m_parentForm).displayMessageBox(MessageBoxCustom.PopUpMsgType.YESNO, null, "Shortcut \"" + Path.GetFileName(shortcutPath) + "\" already exists.\n\nDo you wish to overwrite it?", "Warning!!!", -1); @@ -276,7 +265,7 @@ namespace All_Purpose_Auto_Setup public string getShortcutTargetPath(List> iniKeys) { string targetPath = ""; - + foreach (ConfigFileManager.Ini_KeyValue iniKey in iniKeys) { if (Regex.IsMatch(iniKey.iniKeyName, @"shortcut\d+_target_path", RegexOptions.IgnoreCase)) @@ -292,7 +281,7 @@ namespace All_Purpose_Auto_Setup public string getShortcutArguments(List> iniKeys) { string args = ""; - + foreach (ConfigFileManager.Ini_KeyValue iniKey in iniKeys) { if (Regex.IsMatch(iniKey.iniKeyName, @"shortcut\d+_arguments", RegexOptions.IgnoreCase)) diff --git a/AllPurposeAutoSetup/frmAbout.cs b/AllPurposeAutoSetup/frmAbout.cs index fa8dad9..db6ccbb 100644 --- a/AllPurposeAutoSetup/frmAbout.cs +++ b/AllPurposeAutoSetup/frmAbout.cs @@ -1,15 +1,6 @@ using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; -using System.Reflection; using System.IO; - +using System.Reflection; using CommonLib.Windows.Forms; namespace All_Purpose_Auto_Setup diff --git a/AllPurposeAutoSetup/frmMain.cs b/AllPurposeAutoSetup/frmMain.cs index d2f984c..88afacd 100644 --- a/AllPurposeAutoSetup/frmMain.cs +++ b/AllPurposeAutoSetup/frmMain.cs @@ -1,21 +1,13 @@ using System; using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; using System.Diagnostics; using System.IO; -using System.Text.RegularExpressions; -using System.Threading; +using System.Linq; using System.Reflection; - -using CommonLib.Windows.Forms; +using System.Text.RegularExpressions; +using System.Windows.Forms; using CommonLib.IO; -using CommonLib.Misc; +using CommonLib.Windows.Forms; using CommonLib.Windows.Misc; namespace All_Purpose_Auto_Setup @@ -164,9 +156,9 @@ namespace All_Purpose_Auto_Setup if (args.Count() > 1) { - pathAndNameOfConfigFile = args[1]; - if (!PathManip.IsAbsolutePath(pathAndNameOfConfigFile)) - pathAndNameOfConfigFile = Path.GetFullPath(Path.Combine(Application.StartupPath, pathAndNameOfConfigFile)); + pathAndNameOfConfigFile = args[1]; + if (!PathManip.IsAbsolutePath(pathAndNameOfConfigFile)) + pathAndNameOfConfigFile = Path.GetFullPath(Path.Combine(Application.StartupPath, pathAndNameOfConfigFile)); } else if (Properties.Settings.Default["ConfigFile"].ToString().Length > 0) { diff --git a/AllPurposeAutoSetup/frmSetupStatusDisplay.cs b/AllPurposeAutoSetup/frmSetupStatusDisplay.cs index ba8ec58..17fd543 100644 --- a/AllPurposeAutoSetup/frmSetupStatusDisplay.cs +++ b/AllPurposeAutoSetup/frmSetupStatusDisplay.cs @@ -1,25 +1,14 @@ using System; using System.Collections.Generic; using System.ComponentModel; -using System.Data; using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; -using System.Threading; -using System.Diagnostics; -using System.Text.RegularExpressions; using System.IO; -using System.Security.AccessControl; -using System.Management; -using System.Security.Principal; -using System.Runtime.InteropServices; -using Microsoft.Win32; - -using CommonLib.Windows.Forms; +using System.Text.RegularExpressions; +using System.Threading; +using System.Windows.Forms; using CommonLib.IO; using CommonLib.Misc; +using CommonLib.Windows.Forms; using CommonLib.Windows.Misc; namespace All_Purpose_Auto_Setup @@ -90,7 +79,7 @@ namespace All_Purpose_Auto_Setup // process the configuration file configFileMgr = new ConfigFileManager(this, pathAndNameOfConfigFile); - pathAndNameOfSetupLog = Path.Combine(Application.StartupPath,pathAndNameOfSetupLog); + pathAndNameOfSetupLog = Path.Combine(Application.StartupPath, pathAndNameOfSetupLog); pathAndNameOfSetupLog = FileManip.GenerateUniqueFileName(Path.GetDirectoryName(pathAndNameOfSetupLog), Path.GetFileNameWithoutExtension(pathAndNameOfSetupLog), Path.GetExtension(pathAndNameOfSetupLog)); @@ -148,6 +137,7 @@ namespace All_Purpose_Auto_Setup str = Regex.Replace(str, @"\n", "\r\n", RegexOptions.IgnoreCase); swSetupLog.Write(str); + swSetupLog.Flush(); } } @@ -164,6 +154,7 @@ namespace All_Purpose_Auto_Setup str = Regex.Replace(str, @"\n", "\r\n", RegexOptions.IgnoreCase); swSetupLog.Write(str); + swSetupLog.Flush(); } return FormControlsManipThreadSafe.getRichTextBoxLastLineIndex(statusRtxtbox); @@ -177,6 +168,7 @@ namespace All_Purpose_Auto_Setup str = Regex.Replace(str, @"\n", "\r\n", RegexOptions.IgnoreCase); swSetupLog.Write(str); + swSetupLog.Flush(); } } @@ -327,7 +319,7 @@ namespace All_Purpose_Auto_Setup currentSetupStep < (int)Properties.Settings.Default["CurrentSetupStep"]) continue; - if ( getActualSetupStep(entry[0], ref actualSetupstep) ) + if (getActualSetupStep(entry[0], ref actualSetupstep)) { setupSuccessful = setupStepCalls[actualSetupstep].Invoke(entry[1]); @@ -542,7 +534,7 @@ namespace All_Purpose_Auto_Setup indentation = Common.getIndentation(1); msg = "\n" + indentation + "- FAILED. " + "\n" + indentation + "File: " + ConfigFileManager.ms_configGeneralInfo.pathAndNameOfConfigFile - + "\n" + indentation + "Error Description: The section " + SectionName.Setup_Step_Manager + " doesn't exist or have no entries."; + + "\n" + indentation + "Error Description: The section " + SectionName.Setup_Step_Manager + " doesn't exist or have no entries."; Common.formatConfigIniFailureMessage(msg, textPropList); @@ -645,7 +637,7 @@ namespace All_Purpose_Auto_Setup List textPropList = new List(); string msg; - + if (ConfigFileManager.ms_configGeneralInfo.programName.iniValue.Length > 0) { // set font to default text and color diff --git a/AllPurposeAutoSetup/frmUserInput.cs b/AllPurposeAutoSetup/frmUserInput.cs index 502e4b1..52d34a3 100644 --- a/AllPurposeAutoSetup/frmUserInput.cs +++ b/AllPurposeAutoSetup/frmUserInput.cs @@ -1,15 +1,7 @@ using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using System.Windows.Forms; -using System.Threading; -using CommonLib.Windows.Forms; +using CommonLib.Windows.Forms; namespace All_Purpose_Auto_Setup {