/// <summary> /// 解压缩 /// </summary> /// <param name="context"></param> private void UnZip(HttpContext context) { string unZipDir = context.Server.MapPath(context.Request["value1"]); string[] zipFiles = context.Request["value2"].Split('|'); foreach (string item in zipFiles) { ZipClass.UnZip(context.Server.MapPath(item), unZipDir, ""); } context.Response.Write("OK"); }
private void bntdonwload_Click(object sender, EventArgs e) { string cof = File.ReadAllText(System.IO.Path.Combine(Win.WinInput.Input.ProDitPath, "load.config"), Encoding.UTF8); List <UpdateDictEnt> pl = new List <UpdateDictEnt>(); if (!string.IsNullOrEmpty(cof)) { pl = ApiClient.JsonToObj <List <UpdateDictEnt> >(cof); } List <UpdateDictEnt> dpl = new List <UpdateDictEnt>(); for (int i = 0; i < this.lisload.Items.Count; i++) { if (this.lisload.Items[i].Checked) { var down = pl.Find(f => f.Dictid == this.lisload.Items[i].Tag.ToString()); if (down != null) { dpl.Add(down); } } } if (dpl.Count == 0) { MessageBox.Show("请选择要下载或更新的词库!"); return; } if (dpl.Count > 3) { MessageBox.Show("同时下载的词库不能超过3个!"); return; } System.Threading.Tasks.Task task = new System.Threading.Tasks.Task(() => { this.bntdonwload.Enabled = false; this.lbdinfo.Visible = true; try { foreach (var d in dpl) { try { var data = ApiClient.GetProDict(Win.WinInput.ApiUrl, d.Dictid);//获取下载地址 if (data.DictList.Count == 0) { continue; } WebClient client = new WebClient(); string filename = System.IO.Path.Combine(Win.WinInput.Input.AppPath, DateTime.Now.Ticks.ToString() + ".zip"); client.DownloadFile(data.DictList[0].UpdateUrl[0], filename); Thread.Sleep(100); if (File.Exists(filename)) { //下载完成解压 ZipClass.UnZip(filename, System.IO.Path.Combine(Win.WinInput.Input.AppPath, "prodict"), string.Empty); d.UpdateFalg = 0; d.DictVersion = data.DictList[0].DictVersion; Thread.Sleep(200); File.Delete(filename);//解压完成,删除下载的文件 } } catch (Exception ex) { string ss = ex.Message; } } File.WriteAllText(System.IO.Path.Combine(Win.WinInput.Input.ProDitPath, "load.config"), ApiClient.ToJson(pl), Encoding.UTF8); ProDictFrm_Load(null, null); } catch { } this.lbdinfo.Visible = false; this.bntdonwload.Enabled = true; return; }); task.Start(); }