using System; using System.Collections.Generic; using System.Linq; using System.Windows.Forms; using System.IO; using System.Xml; using System.Diagnostics; namespace Cyberpipe { static class Program { /// <summary> /// The main entry point for the application. /// </summary> [STAThread] static void Main() { string localConfigPath = Application.StartupPath + "/Config.xml"; //获取程序及版本信息 string currentVersionCode = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString(); //获取文件版本信息 FileVersionInfo myFileVersion = FileVersionInfo.GetVersionInfo(System.Windows.Forms.Application.ExecutablePath); string str = myFileVersion.FileVersion; string configUrl = getProgramUrl(localConfigPath, "configurl"); if (configUrl != "") { String newVersionCode = getVersionCode(configUrl, currentVersionCode); if (newVersionCode != currentVersionCode) { if (MessageBox.Show("检测到新版本,是否立即更新?", "智慧管网太湖新城规划分析系统", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { string programUrl = getProgramUrl(localConfigPath, "programurl"); if (programUrl != "") { FrmDownloadProgress frmdownload = FrmDownloadProgress.getForm(programUrl); return; } } else { } } } Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); FrmLogin frm = new FrmLogin(); if (frm.ShowDialog() == DialogResult.OK) { Application.Run(new MainFrm()); } } //获取新版本程序的路径 private static string getProgramUrl(string fileName, string nodeName) { string url = ""; try { XmlTextReader xmlReader = new XmlTextReader(fileName); while (xmlReader.Read()) { if (xmlReader.Name == nodeName) { url = xmlReader.ReadElementContentAsString(); break; } } xmlReader.Close(); } catch (Exception e) { url = ""; } return url; } //获取版本号 private static string getVersionCode(string fileName, string currentVersionCode) { string versionCode=""; try { XmlTextReader xmlReader = new XmlTextReader(fileName); while (xmlReader.Read()) { if (xmlReader.Name == "versioncode") { versionCode = xmlReader.ReadElementContentAsString(); break; } } xmlReader.Close(); } catch (Exception e) { versionCode = currentVersionCode; return versionCode; } return versionCode; } } }