private void lnkSetting_Click(object sender, EventArgs e) { string strIpAddress = string.Empty; string port = "80"; try { AutoUpdateService.AutoUpdateSoapClient sc = new AutoUpdateSoapClient(); string servicePath = sc.Endpoint.Address.ToString(); string strIpAndPort = servicePath.Substring(0, servicePath.LastIndexOf('/')).Substring(7); string[] strArr = strIpAndPort.Split(':'); strIpAddress = strArr[0]; if (strArr.Length > 1) { port = strArr[1]; } } catch (Exception ex) { MessageBox.Show(ex.Message, "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } new SettingForm(strIpAddress, port).ShowDialog(); }
/// <summary> /// 通过webservice获取服务器上的文件信息,检测本地,返回待更新文件列表 /// </summary> /// <param name="updatePath">待更新文件的地址</param> /// <returns></returns> public List <string> CheckFilesForUpdate(out string updatePath, out string strMsg) { strMsg = string.Empty; updatePath = string.Empty; try { AutoUpdateService.AutoUpdateSoapClient sc = new AutoUpdateSoapClient(); AutoUpdateService.UpdateFileInfo[] list = sc.GetAllUpdateFileInfo(); if (list.Length == 0) { return(null); } Dictionary <string, string> dic = new Dictionary <string, string>(); foreach (AutoUpdateService.UpdateFileInfo u in list) { dic.Add(u.Name, u.Version); } string servicePath = sc.Endpoint.Address.ToString(); updatePath = servicePath.Substring(0, servicePath.LastIndexOf('/')) + "/Update"; //updatePath = Path.Combine(servicePath.Substring(0, servicePath.LastIndexOf('/')), "Update"); if (dic.Count == 0 || updatePath.Length == 0) {//无更新 return(null); } List <string> updateFiles = null; string locaDirlPath = AppDomain.CurrentDomain.BaseDirectory; string localFilePath = string.Empty; updateFiles = new List <string>(); FileVersionInfo fvi = null; foreach (var temp in dic) { localFilePath = Path.Combine(locaDirlPath, temp.Key); if (string.IsNullOrEmpty(temp.Value) || !File.Exists(localFilePath)) { string strUrl = updatePath + "/" + temp.Key.Trim(); WebRequest webReq = WebRequest.Create(strUrl); WebResponse webRes = webReq.GetResponse(); long totalBytes = webRes.ContentLength; //从WEB响应得到总字节数 if (File.Exists(localFilePath)) { FileInfo fileInfo = new FileInfo(localFilePath); if (totalBytes == fileInfo.Length) { webRes.Close(); continue; } else { webRes.Close(); updateFiles.Add(temp.Key); } } else { webRes.Close(); updateFiles.Add(temp.Key); } } else { fvi = FileVersionInfo.GetVersionInfo(localFilePath); if (string.Compare(temp.Value, fvi.FileVersion, false) == 0) { continue; } else { updateFiles.Add(temp.Key); } } } if (updateFiles.Count == 0) {//无更新 return(null); } return(updateFiles); } catch (Exception ex) { strMsg = "检测更新失败,原因:" + ex.Message; return(null); } }