private void FrmUpdate_Load(object sender, System.EventArgs e) { panel2.Visible = false; btnFinish.Visible = false; string localXmlFile = Application.StartupPath + "\\UpdateList.xml"; string serverXmlFile = string.Empty; try { //从本地读取更新配置文件信息 updaterXmlFiles = new XmlFiles(localXmlFile); } catch { MessageBox.Show("配置文件出错!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); this.Close(); return; } //获取服务器地址 updateUrl = updaterXmlFiles.GetNodeValue("//Url"); AppUpdater appUpdater = new AppUpdater(); appUpdater.UpdaterUrl = updateUrl + "/UpdateList.xml"; //与服务器连接,下载更新配置文件 try { tempUpdatePath = Environment.GetEnvironmentVariable("Temp") + "\\" + "_" + updaterXmlFiles.FindNode("//Application").Attributes["applicationId"].Value + "_" + "y" + "_" + "x" + "_" + "m" + "_" + "\\"; appUpdater.DownAutoUpdateFile(tempUpdatePath); } catch { MessageBox.Show("与服务器连接失败,操作超时!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); return; } //获取更新文件列表 Hashtable htUpdateFile = new Hashtable(); serverXmlFile = tempUpdatePath + "\\UpdateList.xml"; if (!File.Exists(serverXmlFile)) { return; } availableUpdate = appUpdater.CheckForUpdate(serverXmlFile, localXmlFile, out htUpdateFile); if (availableUpdate > 0) { for (int i = 0; i < htUpdateFile.Count; i++) { string [] fileArray = (string [])htUpdateFile[i]; lvUpdateList.Items.Add(new ListViewItem(fileArray)); } } // else // btnNext.Enabled = false; }
private void CheckWrok() { string strXmlPath = Application.StartupPath + "\\UpdateList.xml", serverXmlFile = string.Empty; try { m_UpdaterXmlFiles = new XmlFiles(strXmlPath); } catch (Exception exc) { MessageBox.Show("读取配置文件出错!" + exc.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); this.Close(); } m_Url = m_UpdaterXmlFiles.GetNodeValue("//Url"); AppUpdater appUpdater = new AppUpdater(); appUpdater.UpdaterUrl = m_Url + "/UpdateList.xml"; try { m_TempPath = Environment.GetEnvironmentVariable("Temp") + "\\" + "_" + m_UpdaterXmlFiles.FindNode("//Application").Attributes["applicationId"].Value + "_" + "l" + "_" + "i" + "_" + "s" + "_"; appUpdater.DownAutoUpdateFile(m_TempPath); } catch (Exception exc) { MessageBox.Show("与服务器连接失败,操作超时!" + exc.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); } //获取更新文件列表 Hashtable htUpdateFile = new Hashtable(); serverXmlFile = m_TempPath + "\\UpdateList.xml"; if (!File.Exists(serverXmlFile)) { return; } m_UpdateCount = appUpdater.CheckForUpdate(serverXmlFile, strXmlPath, out htUpdateFile); if (m_UpdateCount > 0) { label1.Text = "以下是需要更新的文件列表:"; btnNext.Enabled = true; for (int i = 0; i < htUpdateFile.Count; i++) { string[] fileArray = (string[])htUpdateFile[i]; lvUpdateList.Items.Add(new ListViewItem(fileArray)); } } else { label1.Text = "未发现需要更新的文件!"; MessageBox.Show("当前为最新版本!"); this.Close(); Application.ExitThread(); Application.Exit(); } }
private void Dispose(bool disposing) { if (!this.disposed) { if (disposing) { this.component.Dispose(); } AppUpdater.CloseHandle(this.handle); this.handle = IntPtr.Zero; } this.disposed = true; }
private void backgroundWorker2_DoWork(object sender, DoWorkEventArgs e) { string localXmlFile = Application.StartupPath + "\\UpdateList.xml"; string serverXmlFile = string.Empty; try { //从本地读取更新配置文件信息 updaterXmlFiles = new XmlFiles(localXmlFile); } catch (Exception ee) { MessageBox.Show("配置文件出错!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); this.Close(); return; } //获取服务器地址 updateUrl = updaterXmlFiles.GetNodeValue("//Url"); AppUpdater appUpdater = new AppUpdater(); appUpdater.UpdaterUrl = updateUrl + "/UpdateList.xml"; //与服务器连接,下载更新配置文件 try { tempUpdatePath = Environment.GetEnvironmentVariable("Temp") + "\\" + "_" + updaterXmlFiles.FindNode("//Application").Attributes["applicationId"].Value + "_" + "y" + "_" + "x" + "_" + "m" + "_" + "\\"; appUpdater.DownAutoUpdateFile(tempUpdatePath); } catch { MessageBox.Show("与服务器连接失败,操作超时!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); return; } //获取更新文件列表 htUpdateFile = new Hashtable(); serverXmlFile = tempUpdatePath + "\\UpdateList.xml"; if (!File.Exists(serverXmlFile)) { MessageBox.Show("更新地址错误"); Application.Exit(); return; } availableUpdate = appUpdater.CheckForUpdate(serverXmlFile, localXmlFile, out htUpdateFile); }
private void FrmUpdate_Load(object sender, EventArgs e) { this.panel2.Visible = false; this.btnFinish.Visible = false; string text = AppDomain.CurrentDomain.BaseDirectory + @"UpdateList.xml"; string text2 = string.Empty; try { this.updaterXmlFiles = new XmlFiles(text); } catch { MessageBox.Show("配置文件出错!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Hand); base.Close(); return; } this.updateUrl = string.Format(this.updaterXmlFiles.GetNodeValue("//Url"), _IP); AppUpdater appUpdater = new AppUpdater(); appUpdater.UpdaterUrl = this.updateUrl + "UpdateList.xml"; try { this.tempUpdatePath = Environment.GetEnvironmentVariable("Temp") + "\\_" + this.updaterXmlFiles.FindNode("//Application").Attributes["applicationId"].Value + "_y_x_m_\\"; appUpdater.DownAutoUpdateFile(this.tempUpdatePath); } catch { MessageBox.Show("与服务器连接失败,操作超时!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); base.Close(); return; } Hashtable hashtable = new Hashtable(); text2 = this.tempUpdatePath + "UpdateList.xml"; if (File.Exists(text2)) { this.availableUpdate = appUpdater.CheckForUpdate(text2, text, out hashtable); if (this.availableUpdate > 0) { for (int i = 0; i < hashtable.Count; i++) { string[] items = (string[])hashtable[i]; this.lvUpdateList.Items.Add(new ListViewItem(items)); } } } }
public int CheckUpdate() { string localXmlFile = Application.StartupPath + "\\UpdateList.xml"; string serverXmlFile = string.Empty; try { //从本地读取更新配置文件信息 updaterXmlFiles = new XmlFiles(localXmlFile); } catch { //MessageBox.Show("配置文件出错!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); return(-1); } //获取服务器地址 updateUrl = updaterXmlFiles.GetNodeValue("//Url"); AppUpdater appUpdater = new AppUpdater(); appUpdater.UpdaterUrl = updateUrl + "/UpdateList.xml"; //与服务器连接,下载更新配置文件 try { tempUpdatePath = Environment.GetEnvironmentVariable("Temp") + "\\" + "_" + updaterXmlFiles.FindNode("//Application").Attributes["applicationId"].Value + "_" + "y" + "_" + "x" + "_" + "m" + "_" + "\\"; appUpdater.DownAutoUpdateFile(tempUpdatePath); } catch { //MessageBox.Show("与服务器连接失败,操作超时!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return(-2); } //获取更新文件列表 Hashtable htUpdateFile = new Hashtable(); serverXmlFile = tempUpdatePath + "\\UpdateList.xml"; if (!File.Exists(serverXmlFile)) { return(-3); } availableUpdate = appUpdater.CheckForUpdate(serverXmlFile, localXmlFile, out htUpdateFile); return(availableUpdate); }
/// <summary> /// 返回下载更新文件的临时目录 /// </summary> public bool DownAutoUpdateFile(string downpath) { bool result = false; if (!System.IO.Directory.Exists(downpath)) { System.IO.Directory.CreateDirectory(downpath); } string serverXmlFile = downpath + @"UpdateList.xml"; WebRequest req = null; WebResponse res = null; try { TempLog.Debug("下载更新配置文件UpdateList.xml,创建WebRequest"); req = AppUpdater.Create(this.UpdaterUrl); TempLog.Debug("下载更新配置文件UpdateList.xml,完成WebRequest"); res = req.GetResponse(); TempLog.Debug("下载更新配置文件UpdateList.xml,完成WebRequest获取GetResponse"); if (res.ContentLength > 0) { WebClient wClient = AppUpdater.CreateClient(); TempLog.Debug("下载更新配置文件UpdateList.xml,开始下载"); wClient.DownloadFile(this.UpdaterUrl, serverXmlFile); TempLog.Debug("下载更新配置文件UpdateList.xml,完成下载"); result = true; } } catch (Exception ex) { throw ex; } finally { if (res != null) { res.Close(); req.Abort(); } } return(result); }
private void update_Tick(object sender, EventArgs e) { timer.Stop(); timer.Dispose(); if (!IsConnectInternet()) { label1.Visible = true; label7.Text = "无法连接到互联网!"; MessageBox.Show(this, "无法连接到互联网,请检查网络!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } string localXmlFile = Application.StartupPath + "\\UpdateList.xml"; string serverXmlFile = string.Empty; try { //从本地读取更新配置文件信息 updaterXmlFiles = new XmlFiles(localXmlFile); } catch { MessageBox.Show(this, "读取配置文件出错,请联系管理员!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); this.Close(); return; } //获取服务器地址 updateUrl = updaterXmlFiles.GetNodeValue("//Url"); AppUpdater appUpdater = new AppUpdater(); appUpdater.UpdaterUrl = updateUrl + "/UpdateList.xml"; //与服务器连接,下载更新配置文件 try { tempUpdatePath = Environment.GetEnvironmentVariable("Temp") + "\\" + "_" + updaterXmlFiles.FindNode("//Application").Attributes["applicationId"].Value + "_" + "y" + "_" + "x" + "_" + "m" + "_" + "\\"; appUpdater.DownAutoUpdateFile(tempUpdatePath); } catch { MessageBox.Show(this, "与服务器连接失败,请求超时!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); this.Close(); return; } //获取更新文件列表 Hashtable htUpdateFile = new Hashtable(); serverXmlFile = tempUpdatePath + "\\UpdateList.xml"; if (!File.Exists(serverXmlFile)) { label1.Visible = true; label7.Text = "当前版本已经是最新版本!"; label7.Visible = true; MessageBox.Show(this, "当前版本已经是最新版本!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); return; } availableUpdate = appUpdater.CheckForUpdate(serverXmlFile, localXmlFile, out htUpdateFile); if (availableUpdate > 0) { //获取更新内容说明 this.txt_updateNotes.Visible = true; this.panel_updateNotes.Visible = true; this.btn_showUpdateNotes.Enabled = true; this.btn_showUpdateNotes.Text = "查看更新列表(&S)"; string[] updateNotes = appUpdater.GetUpdateNotes(serverXmlFile); if (updateNotes != null) { foreach (string note in updateNotes) { this.txt_updateNotes.AppendText(note + "\r\n"); } } else { this.txt_updateNotes.AppendText("暂时没有版本更新说明!"); } for (int i = 0; i < htUpdateFile.Count; i++) { string[] fileArray = (string[])htUpdateFile[i]; lvUpdateList.Items.Add(new ListViewItem(fileArray)); } label1.Visible = true; label1.Text = "发现新版本"; lvUpdateList.Visible = true; lbState.Visible = true; pbDownFile.Visible = true; label7.Visible = false; btnNext.Enabled = true; } else { label1.Visible = true; label7.Text = "当前版本已经是最新版本!"; label7.Visible = true; MessageBox.Show(this, "当前版本已经是最新版本!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); } }
private void CheckWrok() { string strXmlPath = Application.StartupPath + "\\UpdateList.xml", serverXmlFile = string.Empty; try { m_UpdaterXmlFiles = new XmlFiles(strXmlPath); } catch (Exception exc) { MessageBox.Show("��ȡ�����ļ�����!" + exc.Message, "����", MessageBoxButtons.OK, MessageBoxIcon.Error); this.Close(); } m_Url = m_UpdaterXmlFiles.GetNodeValue("//Url"); AppUpdater appUpdater = new AppUpdater(); appUpdater.UpdaterUrl = m_Url + "/UpdateList.xml"; try { m_TempPath = Environment.GetEnvironmentVariable("Temp") + "\\" + "_" + m_UpdaterXmlFiles.FindNode("//Application").Attributes["applicationId"].Value + "_" + "l" + "_" + "i" + "_" + "s" + "_"; appUpdater.DownAutoUpdateFile(m_TempPath); } catch (Exception exc) { MessageBox.Show("�����������ʧ��,������ʱ!" + exc.Message, "��ʾ", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); } //��ȡ�����ļ��б� Hashtable htUpdateFile = new Hashtable(); serverXmlFile = m_TempPath + "\\UpdateList.xml"; if (!File.Exists(serverXmlFile)) return; m_UpdateCount = appUpdater.CheckForUpdate(serverXmlFile, strXmlPath, out htUpdateFile); if (m_UpdateCount > 0) { label1.Text = "��������Ҫ���µ��ļ��б��"; btnNext.Enabled = true; for (int i = 0; i < htUpdateFile.Count; i++) { string[] fileArray = (string[])htUpdateFile[i]; lvUpdateList.Items.Add(new ListViewItem(fileArray)); } } else { label1.Text = "δ������Ҫ���µ��ļ���"; MessageBox.Show("��ǰΪ���°汾��"); this.Close(); Application.ExitThread(); Application.Exit(); } }
private void FrmUpdate_Load(object sender, System.EventArgs e) { string currentDirectory = Environment.CurrentDirectory; if (!AppConst.GetConfig()) { MessageBox.Show("配置文件读取失败!请确定配置文件放在" + currentDirectory + "该目录下"); return; } panel2.Visible = false; btnFinish.Visible = false; string localXmlFile = currentDirectory + "\\UpdateList.xml"; string serverXmlFile = string.Empty; try { //从本地读取更新配置文件信息 updaterXmlFiles = new XmlFiles(localXmlFile); } catch { MessageBox.Show("配置文件出错!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); this.Close(); return; } //获取服务器地址 updateUrl = updaterXmlFiles.GetNodeValue("//Url"); AppUpdater appUpdater = new AppUpdater(); appUpdater.UpdaterUrl = updateUrl + "/UpdateList.xml" + url_postfix; //与服务器连接,下载更新配置文件 try { //临时更新文件目录 tempUpdatePath = currentDirectory + "\\" + AppConst.TempFilePath; appUpdater.DownAutoUpdateFile(tempUpdatePath); } catch { MessageBox.Show("与服务器连接失败,操作超时!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); return; } //获取更新文件列表 htUpdateFile = new Hashtable(); serverXmlFile = tempUpdatePath + "\\UpdateList.xml"; if (!File.Exists(serverXmlFile)) { return; } availableUpdate = appUpdater.CheckForUpdate(serverXmlFile, localXmlFile, out htUpdateFile); if (availableUpdate > 0) { for (int i = 0; i < htUpdateFile.Count; i++) { string [] fileArray = (string [])htUpdateFile[i]; lvUpdateList.Items.Add(new ListViewItem(fileArray)); } } }
//�Ա�XML�ļ�����Ƿ���������Ŀ private void XMLCheckUpdate() { label1.Text = "���ڼ����£����Ժ�..."; string localXmlFile = Application.StartupPath + "\\Update\\UpdateList.xml"; string serverXmlFile = string.Empty; try { //�ӱ��ض�ȡ���������ļ���Ϣ updaterXmlFiles = new XmlFiles(localXmlFile); } catch { MessageBox.Show("���������ļ�����!", "����", MessageBoxButtons.OK, MessageBoxIcon.Error); this.Close(); return; } //��ȡ��������ַ updateUrl = updaterXmlFiles.GetNodeValue("//Url"); AppUpdater appUpdater = new AppUpdater(); appUpdater.UpdaterUrl = updateUrl + "/UpdateList.xml"; appUpdater.UpdaterUrl1 = updateUrl + "/Update.xml"; //�����������,���ظ��������ļ� try { tempUpdatePath = Environment.GetEnvironmentVariable("Temp") + "\\" + "_" + updaterXmlFiles.FindNode("//Application").Attributes["applicationId"].Value + "_" + "y" + "_" + "x" + "_" + "m" + "_" + "\\";//�������ļ���ʱ�ļ�����·�� tempUpdatePath1 = Environment.GetEnvironmentVariable("Temp") + "\\" + "_" + updaterXmlFiles.FindNode("//Application").Attributes["applicationId"].Value + "_" + "y" + "_" + "x" + "_" + "m" + "_" + "\\" + "ISoft\\Update\\";//�����ļ���ʱ�ļ�·�� appUpdater.DownAutoUpdateFile(tempUpdatePath1); } catch { MessageBox.Show("�����������ʧ��,������ʱ!", "��ʾ", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); return; } //��ȡ�����ļ��б� Hashtable htUpdateFile = new Hashtable(); serverXmlFile = tempUpdatePath1 + "\\UpdateList.xml"; if (!File.Exists(serverXmlFile)) { return; } availableUpdate = appUpdater.CheckForUpdate(serverXmlFile, localXmlFile, out htUpdateFile); if (availableUpdate > 0) { for (int i = 0; i < htUpdateFile.Count; i++) { string[] fileArray = (string[])htUpdateFile[i]; lvUpdateList1.Items.Add(new ListViewItem(fileArray[0])); if (fileArray[0] == "ISoft\\ISoft.exe") { fileArray[0] = "������"; lvUpdateList.Items.Add(new ListViewItem(fileArray)); continue; } if (fileArray[0] == "ISoft\\Update\\AutoUpdate.exe") { fileArray[0] = "�Զ����³���"; lvUpdateList.Items.Add(new ListViewItem(fileArray)); continue; } if (fileArray[0] == "ISoft\\AdvancedFunctions\\HotTools\\FileDestrory\\FileDestory.exe") { fileArray[0] = "�ļ������"; lvUpdateList.Items.Add(new ListViewItem(fileArray)); continue; } if (fileArray[0] == "ISoft\\AdvancedFunctions\\HotTools\\Individuation\\Individuation.exe") { fileArray[0] = "���Ի�"; lvUpdateList.Items.Add(new ListViewItem(fileArray)); continue; } if (fileArray[0] == "ISoft\\AdvancedFunctions\\HotTools\\RubbishCleaner\\RubbishCleaner.exe") { fileArray[0] = "��������"; lvUpdateList.Items.Add(new ListViewItem(fileArray)); continue; } if (fileArray[0] == "ISoft\\AdvancedFunctions\\SysOptimizedTools\\OSSpeed\\OSSpeed.exe") { fileArray[0] = "ϵͳ����"; lvUpdateList.Items.Add(new ListViewItem(fileArray)); continue; } if (fileArray[0] == "ISoft\\AdvancedFunctions\\SysOptimizedTools\\ScanLargeFile\\ScanLargeFile.exe") { fileArray[0] = "���ļ�ɨ��"; lvUpdateList.Items.Add(new ListViewItem(fileArray)); continue; } if (fileArray[0] == "ISoft\\AdvancedFunctions\\SysTools\\DefaultSet\\DefaultSet.exe") { fileArray[0] = "Ĭ���������"; lvUpdateList.Items.Add(new ListViewItem(fileArray)); continue; } if (fileArray[0] == "ISoft\\AdvancedFunctions\\SysTools\\ReadText\\ReadText.exe") { fileArray[0] = "�����ʶ���"; lvUpdateList.Items.Add(new ListViewItem(fileArray)); continue; } if (fileArray[0] == "ISoft\\AdvancedFunctions\\SysTools\\FileMonitor\\FileMonitor.exe") { fileArray[0] = "���̼���"; lvUpdateList.Items.Add(new ListViewItem(fileArray)); continue; } if (fileArray[0] == "ISoft\\AdvancedFunctions\\SysTools\\TimeSyn\\TimeSyn.exe") { fileArray[0] = "ʱ��ͬ������"; lvUpdateList.Items.Add(new ListViewItem(fileArray)); continue; } if (fileArray[0] == "ISoft\\AdvancedFunctions\\OtherTools\\VideoRec\\VideoRec.exe") { fileArray[0] = "��Ƶ¼����"; lvUpdateList.Items.Add(new ListViewItem(fileArray)); continue; } if (fileArray[0] == "ISoft\\AdvancedFunctions\\OtherTools\\FileSplitAndJion\\FileSplitAndJion.exe") { fileArray[0] = "�ļ��ָ���ϲ�"; lvUpdateList.Items.Add(new ListViewItem(fileArray)); continue; } if (fileArray[0] == "ISoft\\AdvancedFunctions\\OtherTools\\CompTxt\\CompTxt.exe") { fileArray[0] = "�ļ����ݱȽ���"; lvUpdateList.Items.Add(new ListViewItem(fileArray)); continue; } if (fileArray[0] == "ISoft\\AdvancedFunctions\\OtherTools\\ThunderEncodeDecode\\ThunderEncodeDecode.exe") { fileArray[0] = "Ѹ��ַ������"; lvUpdateList.Items.Add(new ListViewItem(fileArray)); continue; } } } if (availableUpdate == 0) { InvalidateControl1(); } else { label1.Text = "����Ϊ�����ļ��б����������һ������ʼ����"; btnNext.Visible = true; } }
private void DownUpdateFile() { mainAppExe = updaterXmlFiles.GetNodeValue("//EntryPoint"); Process [] allProcess = Process.GetProcesses(); foreach (Process p in allProcess) { if (p.ProcessName.ToLower() + ".exe" == mainAppExe.ToLower()) { for (int i = 0; i < p.Threads.Count; i++) { p.Threads[i].Dispose(); } p.Kill(); isRun = true; } } bool isFinish = false; WebClient wcClient = AppUpdater.CreateClient(); WebResponse webRes = null; WebRequest webReq = null; for (int i = 0; i < this.lvUpdateList.Items.Count; i++) { string UpdateFile = lvUpdateList.Items[i].Text.Trim(); //string UpdateFile = WindowFormDelegate.GetListViewText(lvUpdateList, i); string updateFileUrl = updateUrl + UpdateFile; long fileLength = 0; WindowFormDelegate.SetMainThreadHint(lbFileListHint, string.Format("共{0}个文件待更新,准备更新第{1}个文件中", lvUpdateList.Items.Count.ToString(), (i + 1).ToString())); try { TempLog.Debug(string.Format("下载更新文件{0},创建WebRequest", updateFileUrl)); webReq = AppUpdater.Create(updateFileUrl); TempLog.Debug("完成创建WebRequest"); TempLog.Debug("下载更新文件,准备获取WebResponse"); webRes = webReq.GetResponse(); TempLog.Debug("下载更新文件,完成获取WebResponse"); fileLength = webRes.ContentLength; WindowFormDelegate.SetMainThreadHint(this.lbState, "正在下载更新文件,请稍后..."); //lbState.Text = "正在下载更新文件,请稍后..."; pbDownFile.Value = 0; pbDownFile.Maximum = (int)fileLength; TempLog.Debug("下载更新文件,获取GetResponseStream"); Stream srm = webRes.GetResponseStream(); TempLog.Debug("下载更新文件,完成获取GetResponseStream"); StreamReader srmReader = new StreamReader(srm); byte[] bufferbyte = new byte[fileLength]; int allByte = (int)bufferbyte.Length; int startByte = 0; while (fileLength > 0) { Application.DoEvents(); int downByte = srm.Read(bufferbyte, startByte, allByte); if (downByte == 0) { break; } ; startByte += downByte; allByte -= downByte; pbDownFile.Value += downByte; float part = (float)startByte / 1024; float total = (float)bufferbyte.Length / 1024; int percent = Convert.ToInt32((part / total) * 100); this.lvUpdateList.Items[i].SubItems[2].Text = percent.ToString() + "%"; } string tempPath = tempUpdatePath + UpdateFile; CreateDirtory(tempPath); FileStream fs = new FileStream(tempPath, FileMode.OpenOrCreate, FileAccess.Write); fs.Write(bufferbyte, 0, bufferbyte.Length); srm.Close(); srmReader.Close(); fs.Close(); } catch (WebException ex) { //MessageBox.Show("更新文件下载失败!" + ex.Message.ToString(), "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); // isFinish = false; // continue; Console.WriteLine("下载异常:" + ex.ToString()); } finally { if (webRes != null) { webRes.Close(); webReq.Abort(); } } if (i == this.lvUpdateList.Items.Count - 1) { isFinish = true; //this.btnFinish_Click(null, null); } } InvalidateControl(); if (isFinish) { this.CopyFileThread(); } //btnFinish_Click(null, null); else { this.StartMainApplication(); } }
private void FrmUpdate_Load(object sender, System.EventArgs e) { panel2.Visible = false; btnFinish.Visible = false; string localXmlFile = Application.StartupPath + "\\UpdateList.xml"; string serverXmlFile = string.Empty; try { //从本地读取更新配置文件信息 TempLog.Debug("准备加载启动路径下的UpdateList.xml更新文件!"); updaterXmlFiles = new XmlFiles(localXmlFile); mainAppExe = updaterXmlFiles.GetNodeValue("//EntryPoint"); TempLog.Debug("加载启动路径下的UpdateList.xml更新文件并读取更新完需执行的exe文件名完毕!"); } catch (Exception ex) { TempLog.Info("加载UpdateList.xml出现异常:" + ex); //MessageBox.Show("配置文件出错!","错误",MessageBoxButtons.OK,MessageBoxIcon.Error); this.StartMainApplication(); return; } //获取服务器地址 updateUrl = updaterXmlFiles.GetNodeValue("//Url"); AppUpdater appUpdater = new AppUpdater(); appUpdater.UpdaterUrl = updateUrl + "UpdateList.xml"; //与服务器连接,下载更新配置文件 try { TempLog.Debug("准备下载更新配置文件列表UpdateList.xml"); tempUpdatePath = Environment.GetEnvironmentVariable("Temp") + "\\" + "_" + updaterXmlFiles.FindNode("//Application").Attributes["applicationId"].Value + "_" + "y" + "_" + "x" + "_" + "m" + "_" + "\\"; appUpdater.DownAutoUpdateFile(tempUpdatePath); TempLog.Debug("完成下载更新配置文件列表UpdateList.xml"); } catch (Exception ex) { TempLog.Info("下载更新配置文件列表UpdateList.xml出现异常:" + ex); //MessageBox.Show("与服务器连接失败,操作超时!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information); this.StartMainApplication(); return; } //获取更新文件列表 Hashtable htUpdateFile = new Hashtable(); serverXmlFile = tempUpdatePath + "\\UpdateList.xml"; if (!File.Exists(serverXmlFile)) { return; } availableUpdate = appUpdater.CheckForUpdate(serverXmlFile, localXmlFile, out htUpdateFile); if (availableUpdate > 0) { for (int i = 0; i < htUpdateFile.Count; i++) { string [] fileArray = (string [])htUpdateFile[i]; lvUpdateList.Items.Add(new ListViewItem(fileArray)); } } this.lbFileListHint.Text = string.Format("共{0}个文件待更新,准备更新中{1}", lvUpdateList.Items.Count.ToString(), string.Empty); btnNext_Click(null, null); // else // btnNext.Enabled = false; }
private void FrmUpdate_Load(object sender, System.EventArgs e) { // if (!CheckInetConnection()) // { // MessageBox.Show("无网络连接!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); // this.Close(); // return; // } //foreach (Process my in System.Diagnostics.Process.GetProcesses()) //{ // if (my.ProcessName == "FairiesCoolerCash") // { // my.Kill(); // } //} panel2.Visible = false; btnFinish.Visible = false; string localXmlFile = Application.StartupPath + "\\UpdateList.xml"; string serverXmlFile = string.Empty; try { //从本地读取更新配置文件信息 updaterXmlFiles = new XmlFiles(localXmlFile ); } catch { MessageBox.Show("配置文件出错!","错误",MessageBoxButtons.OK,MessageBoxIcon.Error); this.Close(); return; } //获取服务器地址 updateUrl = updaterXmlFiles.GetNodeValue("//Url"); description = updaterXmlFiles.GetNodeValue("//Description"); this.Text = description; AppUpdater appUpdater = new AppUpdater(); appUpdater.UpdaterUrl = updateUrl + "/UpdateList.xml"; //与服务器连接,下载更新配置文件 try { tempUpdatePath = Application.StartupPath + "\\AutoUpdateFiles" + "\\" + "_" + updaterXmlFiles.FindNode("//Application").Attributes["applicationId"].Value + "_" + "y" + "_" + "x" + "_" + "m" + "_" + "\\"; appUpdater.DownAutoUpdateFile(tempUpdatePath); } catch { MessageBox.Show("与服务器连接失败,操作超时!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information); this.Close(); return; } //获取更新文件列表 Hashtable htUpdateFile = new Hashtable(); serverXmlFile = tempUpdatePath + "\\UpdateList.xml"; if(!File.Exists(serverXmlFile)) { return; } availableUpdate = appUpdater.CheckForUpdate(serverXmlFile,localXmlFile,out htUpdateFile); if (availableUpdate > 0) { for(int i=0;i<htUpdateFile.Count;i++) { string [] fileArray =(string []) htUpdateFile[i]; lvUpdateList.Items.Add(new ListViewItem(fileArray)); } } // else // btnNext.Enabled = false; }
private bool CheckHasNewVersion() { string xmlFile = Environment.CurrentDirectory + @"\UpdateList.xml"; string path = string.Empty; try { this.updaterXmlFiles = new XmlFiles(xmlFile); } catch { MessageBox.Show("配置文件出错!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Hand); return false; } this.updateUrl = this.updaterXmlFiles.GetNodeValue("//Url"); AppUpdater updater = new AppUpdater(); try { this.tempUpdatePath = string.Format(@"{0}\{1}_{2}", Environment.GetEnvironmentVariable("Temp"), this.updaterXmlFiles.FindNode("//Application").Attributes["applicationId"].Value, DateTime.Now.ToString("yyyyMMddHHmmss")); updater.DownAutoUpdateFile(this.tempUpdatePath, string.Empty, this.updateUrl); } catch { MessageBox.Show("与服务器连接失败,操作超时!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); return false; } path = this.tempUpdatePath + @"\UpdateList.xml"; if (!System.IO.File.Exists(path)) { return false; } return (updater.CheckForUpdate(this.tempUpdatePath, path, xmlFile, out this.updateFileUrls) > 0); }
private void FrmUpdate_Load(object sender, System.EventArgs e) { string localXmlFile = Application.StartupPath + "\\Version.xml"; string serverXmlFile = string.Empty; try { //从本地读取更新配置文件信息 updaterXmlFiles = new XmlFiles(localXmlFile); } catch { //MessageBox.Show("配置文件出错!","错误",MessageBoxButtons.OK,MessageBoxIcon.Error); WriteLog("配置文件出错"); this.Close(); return; } //获取服务器地址 updateUrl = updaterXmlFiles.GetNodeValue("//Url"); AppUpdater appUpdater = new AppUpdater(); appUpdater.UpdaterUrl = updateUrl + "Version.xml"; //WriteLog(appUpdater.UpdaterUrl); //与服务器连接,下载更新配置文件 try { tempUpdatePath = Environment.GetEnvironmentVariable("Temp") + "\\" + "_" + updaterXmlFiles.FindNode("//Application").Attributes["applicationId"].Value + "_" + "u" + "_" + "p" + "_" + "\\"; deleteDirectory(tempUpdatePath);//删除临时目录 appUpdater.DownAutoUpdateFile(tempUpdatePath); } catch { //MessageBox.Show("与服务器连接失败,操作超时!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information); WriteLog("与服务器连接失败,操作超时!"); this.Close(); return; } //获取更新文件列表 serverXmlFile = tempUpdatePath + "Version.xml"; if (!File.Exists(serverXmlFile)) { this.Close(); return; } availableUpdate = appUpdater.CheckForUpdate(serverXmlFile, localXmlFile, out htUpdateFile); if (availableUpdate > 0) { if (DialogResult.OK == MessageBox.Show("发现新版本! 要更新吗?", mainAppName, MessageBoxButtons.OKCancel, MessageBoxIcon.Question)) { for (int i = 0; i < htUpdateFile.Count; i++) { string[] fileArray = (string[])htUpdateFile[i]; lvUpdateList.Items.Add(new ListViewItem(fileArray)); } //this.btnNext_Click(sender, e); } else { this.Close();//do not need to open the window } } else { this.Close(); } }
//对比XML文件检查是否有升级条目 private void XMLCheckUpdate() { label1.Text = "正在检查更新,请稍候..."; string localXmlFile = Application.StartupPath + "\\Update\\UpdateList.xml"; string serverXmlFile = string.Empty; try { //从本地读取更新配置文件信息 updaterXmlFiles = new XmlFiles(localXmlFile); } catch { MessageBox.Show("本地配置文件出错!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); this.Close(); return; } //获取服务器地址 updateUrl = updaterXmlFiles.GetNodeValue("//Url"); AppUpdater appUpdater = new AppUpdater(); appUpdater.UpdaterUrl = updateUrl + "/UpdateList.xml"; appUpdater.UpdaterUrl1 = updateUrl + "/Update.xml"; //与服务器连接,下载更新配置文件 try { tempUpdatePath = Environment.GetEnvironmentVariable("Temp") + "\\" + "_" + updaterXmlFiles.FindNode("//Application").Attributes["applicationId"].Value + "_" + "y" + "_" + "x" + "_" + "m" + "_" + "\\"; //非配置文件临时文件顶级路径 tempUpdatePath1 = Environment.GetEnvironmentVariable("Temp") + "\\" + "_" + updaterXmlFiles.FindNode("//Application").Attributes["applicationId"].Value + "_" + "y" + "_" + "x" + "_" + "m" + "_" + "\\" + "ISoft\\Update\\"; //配置文件临时文件路径 appUpdater.DownAutoUpdateFile(tempUpdatePath1); } catch { MessageBox.Show("与服务器连接失败,操作超时!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); return; } //获取更新文件列表 Hashtable htUpdateFile = new Hashtable(); serverXmlFile = tempUpdatePath1 + "\\UpdateList.xml"; if (!File.Exists(serverXmlFile)) { return; } availableUpdate = appUpdater.CheckForUpdate(serverXmlFile, localXmlFile, out htUpdateFile); if (availableUpdate > 0) { for (int i = 0; i < htUpdateFile.Count; i++) { string[] fileArray = (string[])htUpdateFile[i]; lvUpdateList1.Items.Add(new ListViewItem(fileArray[0])); if (fileArray[0] == "ISoft\\ISoft.exe") { fileArray[0] = "主程序"; lvUpdateList.Items.Add(new ListViewItem(fileArray)); continue; } if (fileArray[0] == "ISoft\\Update\\AutoUpdate.exe") { fileArray[0] = "自动更新程序"; lvUpdateList.Items.Add(new ListViewItem(fileArray)); continue; } if (fileArray[0] == "ISoft\\AdvancedFunctions\\HotTools\\FileDestrory\\FileDestory.exe") { fileArray[0] = "文件粉碎机"; lvUpdateList.Items.Add(new ListViewItem(fileArray)); continue; } if (fileArray[0] == "ISoft\\AdvancedFunctions\\HotTools\\Individuation\\Individuation.exe") { fileArray[0] = "个性化"; lvUpdateList.Items.Add(new ListViewItem(fileArray)); continue; } if (fileArray[0] == "ISoft\\AdvancedFunctions\\HotTools\\RubbishCleaner\\RubbishCleaner.exe") { fileArray[0] = "垃圾清理"; lvUpdateList.Items.Add(new ListViewItem(fileArray)); continue; } if (fileArray[0] == "ISoft\\AdvancedFunctions\\SysOptimizedTools\\OSSpeed\\OSSpeed.exe") { fileArray[0] = "系统加速"; lvUpdateList.Items.Add(new ListViewItem(fileArray)); continue; } if (fileArray[0] == "ISoft\\AdvancedFunctions\\SysOptimizedTools\\ScanLargeFile\\ScanLargeFile.exe") { fileArray[0] = "大文件扫描"; lvUpdateList.Items.Add(new ListViewItem(fileArray)); continue; } if (fileArray[0] == "ISoft\\AdvancedFunctions\\SysTools\\DefaultSet\\DefaultSet.exe") { fileArray[0] = "默认软件设置"; lvUpdateList.Items.Add(new ListViewItem(fileArray)); continue; } if (fileArray[0] == "ISoft\\AdvancedFunctions\\SysTools\\ReadText\\ReadText.exe") { fileArray[0] = "语音朗读机"; lvUpdateList.Items.Add(new ListViewItem(fileArray)); continue; } if (fileArray[0] == "ISoft\\AdvancedFunctions\\SysTools\\FileMonitor\\FileMonitor.exe") { fileArray[0] = "磁盘监视"; lvUpdateList.Items.Add(new ListViewItem(fileArray)); continue; } if (fileArray[0] == "ISoft\\AdvancedFunctions\\SysTools\\TimeSyn\\TimeSyn.exe") { fileArray[0] = "时间同步助手"; lvUpdateList.Items.Add(new ListViewItem(fileArray)); continue; } if (fileArray[0] == "ISoft\\AdvancedFunctions\\OtherTools\\VideoRec\\VideoRec.exe") { fileArray[0] = "视频录制器"; lvUpdateList.Items.Add(new ListViewItem(fileArray)); continue; } if (fileArray[0] == "ISoft\\AdvancedFunctions\\OtherTools\\FileSplitAndJion\\FileSplitAndJion.exe") { fileArray[0] = "文件分割与合并"; lvUpdateList.Items.Add(new ListViewItem(fileArray)); continue; } if (fileArray[0] == "ISoft\\AdvancedFunctions\\OtherTools\\CompTxt\\CompTxt.exe") { fileArray[0] = "文件内容比较器"; lvUpdateList.Items.Add(new ListViewItem(fileArray)); continue; } if (fileArray[0] == "ISoft\\AdvancedFunctions\\OtherTools\\ThunderEncodeDecode\\ThunderEncodeDecode.exe") { fileArray[0] = "迅雷地址解码器"; lvUpdateList.Items.Add(new ListViewItem(fileArray)); continue; } } } if (availableUpdate == 0) { InvalidateControl1(); } else { label1.Text = "以下为更新文件列表,请点击“下一步”开始更新"; btnNext.Visible = true; } }
private void FrmUpdate_Load(object sender, System.EventArgs e) { panel2.Visible = false; btnFinish.Visible = false; string localXmlFile = Application.StartupPath + "\\UpdateList.xml"; string serverXmlFile = string.Empty; try { //从本地读取更新配置文件信息 updaterXmlFiles = new XmlFiles(localXmlFile ); } catch { MessageBox.Show("配置文件出错!","错误",MessageBoxButtons.OK,MessageBoxIcon.Error); this.Close(); return; } //获取服务器地址 updateUrl = updaterXmlFiles.GetNodeValue("//Url"); AppUpdater appUpdater = new AppUpdater(); appUpdater.UpdaterUrl = updateUrl + "/UpdateList.xml"; //与服务器连接,下载更新配置文件 try { tempUpdatePath = Environment.GetEnvironmentVariable("Temp") + "\\"+ "_"+ updaterXmlFiles.FindNode("//Application").Attributes["applicationId"].Value+"_"+"y"+"_"+"x"+"_"+"m"+"_"+"\\"; appUpdater.DownAutoUpdateFile(tempUpdatePath); } catch { MessageBox.Show("与服务器连接失败,操作超时!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information); this.Close(); return; } //获取更新文件列表 Hashtable htUpdateFile = new Hashtable(); serverXmlFile = tempUpdatePath + "\\UpdateList.xml"; if(!File.Exists(serverXmlFile)) { return; } availableUpdate = appUpdater.CheckForUpdate(serverXmlFile,localXmlFile,out htUpdateFile); if (availableUpdate > 0) { for(int i=0;i<htUpdateFile.Count;i++) { string [] fileArray =(string []) htUpdateFile[i]; lvUpdateList.Items.Add(new ListViewItem(fileArray)); } } // else // btnNext.Enabled = false; }