public TargetInformation(string fileName, string path, string deleteButtonVisible = "Visible", string updateMethodEnable = "True", string updateMethod = "新增") { this.fileName = fileName; this.path = path; this.md5 = Md5Creator.createMd5(this.path); this.deleteButtonVisible = deleteButtonVisible; this.updateMethodEnable = updateMethodEnable; this.updateMethod = updateMethod; }
public bool update() { // 更新软件 List <TargetInformation> remoteConfig = new List <TargetInformation>(); List <TargetInformation> currentConfig = new List <TargetInformation>(); ConfigManager.AnalysisXml(currentRemoteConfig, remoteConfig, false); ConfigManager.AnalysisXml(currentConfigFile, currentConfig, false); WebClient client = new WebClient(); foreach (TargetInformation file in remoteConfig) { if (file.FileName == appName) { if (file.Md5 != Md5Creator.createMd5(appName) && (file.UpdateMethod == "替换" || file.UpdateMethod == "新增")) { isNeedToClose = true; updateFileName = file.FileName; } continue; } if (file.UpdateMethod == "新增" || file.UpdateMethod == "替换") { if (File.Exists(System.IO.Path.GetDirectoryName(currentConfigFile) + file.FileName)) { foreach (TargetInformation config in currentConfig) { if (config.FileName == file.FileName) { config.Md5 = file.Md5; config.UpdateMethod = file.UpdateMethod; break; } } } else { currentConfig.Add(file); } client.DownloadFile(url + "/" + file.FileName, System.IO.Path.GetDirectoryName(currentConfigFile) + file.FileName); } else if (file.UpdateMethod == "删除") { foreach (TargetInformation cf in currentConfig) { if (file.Md5 == cf.Md5 && file.FileName == cf.FileName && file.FileName != appName) { FileInfo ff = new FileInfo(cf.Path); currentConfig.Remove(cf); ff.Delete(); } } } else if (file.UpdateMethod == "覆盖后重启") { if (file.Md5 != Md5Creator.createMd5(appName)) { isNeedToClose = true; updateFileName = file.FileName; } } } ThreadHelper arg = new ThreadHelper { c = currentConfig }; Thread t = new Thread(new ParameterizedThreadStart(updateConfig)); t.Start(arg); return(isNeedToClose); }