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 { static string ent = "C:\\EMSCyberPipe"; /// <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.GetVersionInfo(Application.ExecutablePath); Utility.SysInfoConfig(); string configUrl = getProgramUrl(localConfigPath, "configurl"); if (configUrl != "") { String newVersionCode = getVersionCode(configUrl, currentVersionCode); if (newVersionCode != currentVersionCode) { if (MessageBox.Show("检测到新版本,是否立即更新?", "智慧管网太湖新城电子标识系统", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { remoteUpDate(); string programUrl = getProgramUrl(localConfigPath, "programurl"); if (programUrl != "") { //FrmDownloadProgress frmdownload = FrmDownloadProgress.getForm(programUrl); Process.Start(ent + "/UpDateProgress.exe").WaitForExit(); return; } } else { /* System.Diagnostics.Process[] proc = System.Diagnostics.Process.GetProcessesByName("UpDateProgress"); //关闭原有应用程序的所有进程 foreach (System.Diagnostics.Process pro in proc) { pro.Kill(); } * */ } } } Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); FrmLogin frm = new FrmLogin(); if (frm.ShowDialog() == DialogResult.OK) { if (Utility.userRole != null) { Application.Run(new MainFrm()); } else { MessageBox.Show("该用户没有分配任何角色!"); return; } } } private static void remoteUpDate() { if (!File.Exists(ent)) { Directory.CreateDirectory(ent); } string filePath_exe = ent + "\\UpDateProgress.exe"; string filePath_exeConfig = ent + "\\UpDateProgress.exe.config"; string filePath_exePdb = ent + "\\UpDateProgress.pdb"; string filePath_config = ent + "\\Config.xml"; string localPath_exe = Application.StartupPath + "\\UpDateProgress.exe"; string localPath_exeConfig = Application.StartupPath + "\\UpDateProgress.exe.config"; string localPath_exePdb = Application.StartupPath + "\\UpDateProgress.pdb"; string localPath_config = Application.StartupPath + "\\Config.xml"; //TODO LIST:判断文件是否存在,存在就删除 //delOldVersion(filePath_exe); File.Copy(localPath_exe, filePath_exe, true); File.Copy(localPath_exeConfig, filePath_exeConfig, true); File.Copy(localPath_exePdb, filePath_exePdb, true); File.Copy(localPath_config, filePath_config, true); } private static void createFolder(String folerName) { if (!Directory.Exists(folerName)) { Directory.CreateDirectory(folerName); } } private static void delOldVersion(String fileName) { if (System.IO.File.Exists(fileName)) { File.Delete(fileName); } } //获取新版本程序的路径 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; } } }