public HttpResponseMessage Upgrade(string appid) { try { var app = _apps.Where(a => a.appid == appid).FirstOrDefault(); if (app == null) { return(new HttpResponseMessage(HttpStatusCode.NoContent)); } var zipFile = string.Format(_zipFileTemp, appid); if (!File.Exists(zipFile)) { _logger.LogInfo(string.Format("正在制作升级包...")); ZipCompresser.Compress(zipFile, string.Format(HostContext.RootPath + "Clients/{0}/Upgrade", appid)); _logger.LogInfo(string.Format("升级包制作完毕")); } else { _logger.LogInfo(string.Format("升级包已存在,将直接下载")); } HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK); FileStream fs = new FileStream(zipFile, FileMode.Open); response.Content = new StreamContent(fs); response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream"); response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment") { FileName = new FileInfo(zipFile).Name }; return(response); } catch (Exception ex) { return(new HttpResponseMessage(HttpStatusCode.NoContent)); } }
private async Task UnZipAndProcess() { Notify("开始解压升级包upgrade.zip..."); ZipCompresser.Decompress(zipFile, tempPath); Notify("升级包upgrade.zip解压完毕"); //1、获取更新配置文件 var upgradeConf = tempPath + "/files.json"; if (!File.Exists(upgradeConf)) { Notify("未找到升级配置文件,升级包不完整!"); return; } var confStr = File.ReadAllText(upgradeConf); var confs = JsonConvert.DeserializeObject <IList <UpgradeConf> >(confStr); var progress = 0; for (var idx = 0; idx < confs.Count; idx++) { var conf = confs[idx]; var from = conf.path.Replace("~", tempPath); var to = conf.path.Replace("~", ClientContext.TargetAppPath); _logger.LogInfo(string.Format("开始\t——\t{0}", conf.ToString())); if (conf.type == ItemType.file) { HandleFile(from, to, conf); } else { HandleFolder(to, conf); } progress = Convert.ToInt32(((idx + 1) * 1.0 / confs.Count * 100)); progressBar.Value = progress; Notify(string.Format("正在应用更新:{0},{1}", (progress + "/%"), conf.path), false); _logger.LogInfo(string.Format("结束\t——\t{0}", conf.ToString())); } Notify("更新完毕!将在5s后重新启动主程序。"); //更新客户端版本信息 _logger.LogInfo("修改主程序版本信息,最新版本:" + ClientContext.NewestVersion); AppSettingUtils.Update("version", ClientContext.NewestVersion); linkRetry.IsEnabled = true; _cntTimer.Start(); SetSecondCount(5); await Task.Delay(5000); this.DialogResult = true; this.Close(); }