public AutoUpdateStarter(frmWait _frmWait) { WaitForm = _frmWait; string stConfigFileName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); stConfigFileName = Path.Combine(stConfigFileName, Path.GetFileNameWithoutExtension(Assembly.GetExecutingAssembly().Location)); stConfigFileName += @".exe.config"; AutoUpdateStarterConfig config = AutoUpdateStarterConfig.Load(stConfigFileName); this.executablePath = config.ApplicationExePath; this.isDeleteTemp = config.DeleteTemp; this.updatePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + Path.DirectorySeparatorChar + "update" + Path.DirectorySeparatorChar; StartProcessAndWait(); }
/// <summary> /// Load: Returns a AutoUpdateStarterConfig object based on the xml file specified by filepath parameter /// </summary> /// <param name="filePath"></param> /// <returns></returns> public static AutoUpdateStarterConfig Load(string filePath) { AutoUpdateStarterConfig config = new AutoUpdateStarterConfig(); config.configFilePath = filePath; try { //Load the xml config file XmlDocument XmlDoc = new XmlDocument(); try { XmlDoc.Load(filePath); } catch (Exception e) { Debug.WriteLine("Unable to load the AutoUpdateStarter config file at: " + filePath); Debug.WriteLine("Error Message: " + e.Message); } //Parse out the XML Nodes XmlNode pathNode = XmlDoc.SelectSingleNode(@"//ApplicationFolderName"); config.ApplicationFolderName = pathNode.InnerText; XmlNode exeNode = XmlDoc.SelectSingleNode(@"//ApplicationExeName"); config.ApplicationExeName = exeNode.InnerText; XmlNode tempNode = XmlDoc.SelectSingleNode(@"//DeleteTemp"); config.DeleteTemp = (tempNode.InnerText.ToUpper() == "NO") ? false : true; return config; } catch (Exception e) { Debug.WriteLine("Failed to read the AutoUpdateStarter config file at: " + filePath); Debug.WriteLine("Make sure that the config file is present and has a valid format"); throw e; } }//Load(string filePath)