Ejemplo n.º 1
0
 /// <summary>
 /// 在异步下载结束时触发该事件
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 void downclient_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
 {
     try
     {
         if (e.Error != null)
         {
             Util.WritePrivateProfileString(System.Reflection.MethodInfo.GetCurrentMethod().Name, "下载错误", e.Error.ToString(), "errlog.ini");
             MessageBox.Show(this, "在进行远程更新时,发生错误", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
         else
         {
             Util.KillProcess();//关闭主进程
             //验证哈希值
             if (Util.IsHash(Util.GetHash(Util.GetDictiory() + "\\down.zip"), FileWork.GetDownHash()))
             {
                 //删除无用压缩文件
                 File.Delete(Util.GetDictiory() + "\\down.zip");
                 //删除无用版本文件
                 File.Delete(Util.GetDictiory() + "\\ServerUpdateFiles.xml");
                 MessageBox.Show(this, "远程服务器更新包已发生变化,无法更新", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                 Util.WritePrivateProfileString("注入提示", "下载错误",
                                                "远程服务器中的更新包在制作和下载时间段中数据包发生变化,为了安全期间不给予下载!", "errlog.ini");
                 this.Close();
             }
             else
             {
                 //解压压缩包文件
                 ReduceToUnReduceFile.unZipFile(Util.GetDictiory() + "\\down.zip", Util.GetDictiory());
                 //删除压缩包文件
                 File.Delete(Util.GetDictiory() + "\\down.zip");
                 //检查文件夹层次结构
                 FileWork.LookFiles(Util.GetDictiory() + "\\down", Util.GetDictiory());
                 //订阅复制文件事件
                 FileWork.CopyFileEvent += new FileWork.CopyFileDelegate(FileWork_CopyFileEvent);
                 //递归复制文件
                 FileWork.CopyFiles(Util.GetDictiory() + "\\down", Util.GetDictiory());
                 //删除临时文件夹
                 FileWork.DeleteFiles(Util.GetDictiory() + "\\down");
                 //更新本地版本号信息
                 Util.UpdateLocalXml();
                 File.Delete(Util.GetDictiory() + "\\ServerUpdateFiles.xml");
                 MessageBox.Show(this, "升级成功!", "信息提示");
                 Util.StartProcess();
                 isupdate = true;
             }
         }
     }
     catch (Exception err)
     {
         Util.WritePrivateProfileString("注入提示", "下载错误", err.ToString(), "errlog.ini");
     }
     finally { downclient.Dispose(); }
     Application.Exit();
 }
Ejemplo n.º 2
0
 private void Bt_execution_Click(object sender, EventArgs e)
 {
     if (Tb_path.Text.Length > 0)
     {
         try
         {
             progressBar1.Visible = true;
             //制作升级包
             progressBar1.Value += 10;
             ReduceToUnReduceFile.ZipFilenew(Tb_path.Text, Tb_path.Text.Substring(0, Tb_path.Text.LastIndexOf("\\")) + "\\down.zip");
             //制作升级文件信息
             progressBar1.Value += 10;
             string      dostring = "<?xml version='1.0' encoding='UTF-8'?><RootServer><Version no='' remark='服务器端版本号'></Version><ServerDownUrl url='' remark='升级地址'></ServerDownUrl><FileZip filename='' hash='' remark='服务器端升级压缩包名称及哈希值'></FileZip></RootServer>";
             XmlDocument document = new XmlDocument();
             document.LoadXml(dostring);
             progressBar1.Value += 10;
             document.DocumentElement.ChildNodes[0].Attributes["no"].Value = Tb_version.Text;
             progressBar1.Value += 10;
             document.DocumentElement.ChildNodes[1].Attributes["url"].Value = Tb_webpath.Text;
             progressBar1.Value += 10;
             document.DocumentElement.ChildNodes[2].Attributes["filename"].Value = "down.zip";
             progressBar1.Value += 10;
             string hashfilepath = Tb_path.Text.Substring(0, Tb_path.Text.LastIndexOf("\\")) + "\\down.zip";
             progressBar1.Value += 10;
             document.DocumentElement.ChildNodes[2].Attributes["hash"].Value = new Hash().GetHash(hashfilepath);
             progressBar1.Value += 10;
             progressBar1.Value += 10;
             document.Save(Tb_path.Text.Substring(0, Tb_path.Text.LastIndexOf("\\")) + "\\ServerUpdateFiles.xml");
             progressBar1.Value += 10;
             Properties.Settings.Default.ServicePath = Tb_webpath.Text;
             Properties.Settings.Default.AppVersion  = Tb_version.Text;
             Properties.Settings.Default.Save();
             MessageBox.Show("制作成功!");
             this.Close();
         }
         catch (Exception err) { MessageBox.Show("不能指定空文件夹"); }
     }
 }