private new void Update() { //下载更新软件 var url = XmlHelp.GetInnerTextByPath("Config:WebUrl") + updateSoft; var fileName = Path.GetFileName(updateSoft); var b = HtmlHelp.DownFile(url, fileName); if (!b) { MessageBox.Show("下载更新文件失败!"); } else { var aPath = Application.StartupPath + "/"; var updateFileName = XmlHelp.GetInnerTextByPath("Config:UpdateFileName"); if (File.Exists(updateFileName)) { File.Delete(updateFileName); } ZipHelp.ExtractToDirectory(fileName, aPath); File.Delete(fileName); //启动更新程序 Process.Start(updateFileName); //关闭主进程 var proc = Process.GetProcessesByName(XmlHelp.GetInnerTextByPath("Config:MainProcess").Replace(".exe", "")); foreach (var p in proc) { p.Kill(); } } }
/// <summary> /// 解压文件 /// </summary> /// <param name="objParame"></param> public void UnZipFile(object objParame) { var parame = (Dictionary <string, string>)objParame; var savePath = parame["SavePath"].Replace("\\", "/").Replace("//", "/"); var fileUrl = parame["FileUrl"].Replace("\\", "/").Replace("//", "/"); var fileName = parame["FileName"].Replace("\\", "/").Replace("//", "/"); var delay = parame["Delay"]; //将文件解压 var zipDir = savePath + "/" + Path.GetFileNameWithoutExtension(fileUrl); try { ZipHelp.ExtractToDirectory(fileName, zipDir); //将文件解压后的文件夹中的图片转为GIF var fs = Directory.GetFiles(zipDir); GifHelp.ImageToGif(fs, zipDir + ".gif", int.Parse(delay)); } catch (Exception ex) { AddErrorMsg(string.Format("解压文件{0}失败!\r\n{1}\r\n", fileName, ex.Message)); HtmlHelp.SaveStringToTxt(ex.StackTrace + "\r\n", "Error.txt"); } finally { mut.DisposeUnZipThread(); } }
private void UpdateSoft() { try { var url = XmlHelp.GetInnerTextByPath("Config:UpdateUrl"); var json = HtmlHelp.Get(url); var result = JsonHelp.DeserializeObject <ResultEntity>(json); if (result.Code == "1") { var url2 = XmlHelp.GetInnerTextByPath("Config:WebUrl"); var zip = Path.GetFileName(result.FileName); var b = HtmlHelp.DownFile(url2 + result.FileName, zip, progressBar1); if (!b) { throw new Exception(); } //解压下载的文件 var aPath = Application.StartupPath + "/"; ZipHelp.ExtractToDirectory(zip, aPath + "NewPixiv"); //删除下载的压缩文件 File.Delete(aPath + zip); //替换文件 ReplaceFile(aPath, aPath + "NewPixiv"); //删除解压后的文件 Directory.Delete(aPath + "NewPixiv", true); //重新启动主程序 var mainPreocess = XmlHelp.GetInnerTextByPath("Config:MainProcess"); Process.Start(mainPreocess); } else { MessageBox.Show(result.Message); } } catch (Exception e) { MessageBox.Show("更新文件失败!"); } }