internal void CheckVersion(bool IsStartUp, bool IsManually) { try { if (IsStartUp) Thread.Sleep(7000); WebClientHelper webclientHelper = new WebClientHelper(); ProxyInfo proxyinfo = ConfigCtrl.GetProxy(); webclientHelper.SetProxy(proxyinfo.Server, proxyinfo.Port, proxyinfo.UserName, proxyinfo.Password); if (proxyinfo.Enable) webclientHelper.EnableProxy(); Stream updatestream = null; try { // Download the update info file to the memory, updatestream = webclientHelper.OpenRead(REMOTE_URI + UPDATE_FILE); } catch (Exception ex) { LogHelper.Write("Download update.xml", REMOTE_URI + UPDATE_FILE, ex, LogSeverity.Error); return; } if (updatestream == null) { LogHelper.Write("Download update.xml", REMOTE_URI + UPDATE_FILE, LogSeverity.Error); return; } // read and close the stream using (System.IO.StreamReader streamReader = new System.IO.StreamReader(updatestream, System.Text.Encoding.GetEncoding("GB2312"))) { string updateInfo = streamReader.ReadToEnd(); // if something was read if (!string.IsNullOrEmpty(updateInfo)) { //LogHelper.Write("Johnny.Kaixin.WinUI.AutoUpdate.CheckVersion.updateInfo:", updateInfo, LogSeverity.Info); string newVersion = StringHelper.GetMid(updateInfo, "<Version Num = \"", "\"/>"); if (String.IsNullOrEmpty(newVersion)) { LogHelper.Write("Get Version", "newVersion is null", LogSeverity.Info); return; } if (CompareVersions(Assembly.GetExecutingAssembly().GetName().Version.ToString(), newVersion)) { // Download the auto update program to the application // path, so you always have the last version runing if (webclientHelper.DownloadFile(REMOTE_URI + "AutoUpdate.exe", Application.StartupPath + "\\AutoUpdate.exe")) { if (NewVersionFound != null) NewVersionFound(newVersion, Application.StartupPath + "\\AutoUpdate.exe", DataConvert.GetEncodeData(updateInfo)); } else { LogHelper.Write("Download AutoUpdate.exe failed", REMOTE_URI + "AutoUpdate.exe", LogSeverity.Error); return; } } else if (IsManually) { if (LatestVersionConfirmed != null) LatestVersionConfirmed(Assembly.GetExecutingAssembly().GetName().Version.ToString()); } } } } catch (Exception ex) { LogHelper.Write("AutoUpdate.CheckVersion", ex, LogSeverity.Error); } }
public UpdateMasterData() { _webclientHelper = new WebClientHelper(); }