private void Core_MaxValueChange(Helper.DownCore core, double e) { if (core.Tag != null) { lock (core.Tag) { Frm.Downitem item = core.Tag as Frm.Downitem; if (item != null) { item.prog.MaxValue = e; } } } }
private void Core_SpeedChange(Helper.DownCore core, double e) { if (core.Tag != null) { lock (core.Tag) { Frm.Downitem item = core.Tag as Frm.Downitem; if (item != null) { item.Invoke(new Action(() => { item.size.Text = core.Value.CountSize() + "/" + core.MaxValue.CountSize() + " " + e.CountSize() + " /s"; })); } } } }
private void Core_TimeChange(Helper.DownCore core, string e) { if (core.Tag != null) { lock (core.Tag) { Frm.Downitem item = core.Tag as Frm.Downitem; if (item != null) { item.Invoke(new Action(() => { item.time.Text = "预计还需 " + e; })); } } } }
private void Core_StateChange(Helper.DownCore core, Helper.DownCore.DownState e) { if (core.Tag != null) { lock (core.Tag) { Frm.Downitem item = core.Tag as Frm.Downitem; if (item != null) { switch (e) { case Helper.DownCore.DownState.Complete: item.Invoke(new Action(() => { item.state.ForeColor = Color.FromArgb(80, 227, 194); item.state.Text = "下载完成"; item.time.Text = null; item.size.Text = core.MaxValue.CountSize(); item.link_retry.Visible = item.link_del.Visible = false; item.link_open.Visible = true; })); break; case Helper.DownCore.DownState.Downloading: item.Invoke(new Action(() => { item.state.ForeColor = Color.Black; item.state.Text = "下载中"; item.link_retry.Visible = item.link_open.Visible = false; item.link_del.Visible = true; })); break; case Helper.DownCore.DownState.Fail: item.Invoke(new Action(() => { item.state.ForeColor = Color.FromArgb(235, 17, 35); item.state.Text = "下载失败"; item.time.Text = item.size.Text = null; item.link_open.Visible = false; item.link_retry.Visible = item.link_del.Visible = true; })); break; case Helper.DownCore.DownState.Ready: item.Invoke(new Action(() => { item.state.ForeColor = Color.DimGray; item.state.Text = "准备中"; item.link_del.Visible = item.link_retry.Visible = item.link_open.Visible = false; })); break; case Helper.DownCore.DownState.Stop: item.Invoke(new Action(() => { item.state.ForeColor = Color.OrangeRed; item.state.Text = "已停止"; item.time.Text = null; item.link_retry.Visible = item.link_open.Visible = false; item.link_del.Visible = true; })); break; } } } } }
protected override void OnLoad(EventArgs e1) { base.OnLoad(e1); string codecsPath = Program.TempPath + "codecs.zip"; Program.TempPath.CreateDirectory(true); Action _action = () => { Helper.DownCore core = new Helper.DownCore(); core.MaxValueChange += (s, e) => { tProgressBar1.Invoke(new Action(() => { tProgressBar1.Maximum = (int)e; })); }; core.ValueChange += (s, e) => { tProgressBar1.Invoke(new Action(() => { try { tProgressBar1.Value = (int)e; } catch { } })); }; core.SpeedChange += (s, e) => { label2.Invoke(new Action(() => { label2.Text = e.CountSize() + " /s"; })); }; string InitErr; if (core.DownInit("http://aplayer.open.xunlei.com/codecs.zip", "codecs.zip", out InitErr)) { string Err; if (core.DownUrl(codecsPath, Program.TempPath + "codecs\\", out Err)) { isok = true; if (File.Exists(codecsPath)) { this.Invoke(new Action(() => { label2.Text = "下载完毕,正在安装"; })); Directory.Delete(Program.CodecsPath, true); string err; if (Compression.Decompression(codecsPath, Program.CodecsPath, out err)) { this.Invoke(new Action(() => { label1.Text = "修复解码器成功"; label2.Text = "完成"; })); } else { this.Invoke(new Action(() => { tProgressBar1.State = TSkin.ProgressBarState.Error; tProgressBar1.Maximum = tProgressBar1.Value = 1; label1.Text = "修复解码器失败"; label2.Text = "原因:" + err; })); } try { if (File.Exists(codecsPath)) { File.Delete(codecsPath); } } catch { } } } else { //下载失败 try { if (File.Exists(codecsPath)) { File.Delete(codecsPath); } } catch { } this.Invoke(new Action(() => { tProgressBar1.State = TSkin.ProgressBarState.Error; tProgressBar1.Maximum = tProgressBar1.Value = 1; label1.Text = "修复解码器失败"; label2.Text = "原因:" + Err; })); } } else { try { if (File.Exists(codecsPath)) { File.Delete(codecsPath); } } catch { } this.Invoke(new Action(() => { tProgressBar1.State = TSkin.ProgressBarState.Error; tProgressBar1.Maximum = tProgressBar1.Value = 1; label1.Text = "修复解码器失败"; label2.Text = "原因:" + InitErr; })); } }; _task.ContinueWhenAll(new Task[] { _task.StartNew(_action) }, (action => { btn_close.Invoke(new Action(() => { btn_close.Enabled = true; })); })); }