public MainWindow() { InitializeComponent(); UpdateCore.version(ver); if (!UpdateCore.verchk) { UpdateForm frm = new UpdateForm(); Hide(); frm.Show(); } else { changefilename(); CuttingEdge.Osuroot(); FormCuttingEdge frm2 = new FormCuttingEdge(); Hide(); frm2.Show(); } }
private void Form1_Load(object sender, EventArgs e) { try { UpdateCore.version(ver); if (UpdateCore.verchk == "1") { if (GetServerIP == "404 page not found") { ServerIP = GetServerIP; GetServer(); } if (GetServerIP != "404 page not found") { ServerIP = "34.85.96.178"; GetServer(); } } if (UpdateCore.verchk == "0") { UpdateForm frm = new UpdateForm(); Hide(); ShowInTaskbar = false; frm.Show(); } } catch (Exception ex) { LogCore.Log(ex); MessageBox.Show("Error! \r\rPlease Send Discrod Nerina#4444 the Switcher Logs", "Novah", MessageBoxButtons.OK, MessageBoxIcon.Error); string filepath = Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData) + "\\novahlog.txt"; Process.Start(filepath); Environment.Exit(0); } }
private void btn_update_Click(object sender, EventArgs e2) { if (isdown) { return; } if (SystemSettings.UpdateInfo != null && btn_update.IsActive) { UpdateInfo updateInfo = SystemSettings.UpdateInfo; if (updateInfo.files.Count > 0) { isdown = true; //btn_update.Enabled = false; label_updateInfo.Visible = false; metroLoading.Visible = metroLoading.State = true; btn_update.Width = 160; bool isok = false; string updatebasePath = Program.UpdatePath + updateInfo.verson + "\\"; string updatePath = updatebasePath + updateInfo.files[0].name; Action _action = () => { if (File.Exists(updatePath)) { isok = true; } else { btn_update.Invoke(new Action(() => { btn_update.Enabled = false; btn_update.Text = "正在下载"; })); Helper.DownCore core = new Helper.DownCore(); core.MaxValueChange += (s, e) => { metroLoading.MaxValue = e; }; core.ValueChange += (s, e) => { metroLoading.Value = e; }; core.SpeedChange += (s, e) => { btn_update.Invoke(new Action(() => { btn_update.Text = "正在下载 " + e.CountSize(); })); }; string InitErr; if (core.DownInit(updateInfo.files[0].url, updateInfo.files[0].name, out InitErr)) { string Err; if (core.DownUrl(updatePath, updatebasePath + "temp\\", out Err)) { isok = true; //btn_update.Invoke(new Action(() => //{ // btn_update.MaxValue = btn_update.Value = 0; // btn_update.Text = "点击安装"; // //label1.Text = verson; //})); } else { //下载失败 btn_update.Invoke(new Action(() => { btn_update.IsActive = false; btn_update.State = false; btn_update.ForeColor = Color.Red; btn_update.Text = Err; })); System.Threading.Thread.Sleep(2000); btn_update.Invoke(new Action(() => { btn_update.ForeColor = this.ForeColor; btn_update.Text = "检查更新"; btn_update.Enabled = true; })); } } else { btn_update.Invoke(new Action(() => { btn_update.IsActive = false; btn_update.State = false; btn_update.ForeColor = Color.Red; btn_update.Text = InitErr; })); System.Threading.Thread.Sleep(2000); btn_update.Invoke(new Action(() => { btn_update.ForeColor = this.ForeColor; btn_update.Text = "检查更新"; btn_update.Enabled = true; })); } } }; _task.ContinueWhenAll(new Task[] { _task.StartNew(_action) }, (action => { if (isok) { if (updatePath.EndsWith(".exe")) { AdminAppMainUpdate adminAppMainUpdate = new AdminAppMainUpdate(updatebasePath, new List <string> { "TPlayer.exe" }); btn_update.Invoke(new Action(() => { btn_update.BackColorActive = btn_update.BackColorActive2 = Color.DodgerBlue; btn_update.Text = "等待升级"; })); if (adminAppMainUpdate.OpenAssistExe("Update")) { btn_update.Invoke(new Action(() => { Environment.Exit(0); })); return; } else { btn_update.Invoke(new Action(() => { btn_update.IsActive = false; btn_update.ForeColor = Color.Red; btn_update.Text = "启动更新程序失败"; })); System.Threading.Thread.Sleep(2000); btn_update.Invoke(new Action(() => { btn_update.ForeColor = this.ForeColor; btn_update.Text = "检查更新"; })); } Directory.Delete(updatebasePath, true); } else { string err; List <string> files = Compression.DecompressionList(updatePath, updatebasePath, out err); if (files != null && files.Count > 0) { AdminAppMainUpdate adminAppMainUpdate = new AdminAppMainUpdate(updatebasePath, files); btn_update.Invoke(new Action(() => { btn_update.ForeColor = Color.DodgerBlue; btn_update.Text = "等待升级"; })); if (adminAppMainUpdate.OpenAssistExe("Update")) { btn_update.Invoke(new Action(() => { Environment.Exit(0); })); return; } else { btn_update.Invoke(new Action(() => { btn_update.State = false; btn_update.ForeColor = Color.Red; btn_update.Text = "启动更新程序失败"; })); System.Threading.Thread.Sleep(2000); btn_update.Invoke(new Action(() => { btn_update.ForeColor = this.ForeColor; btn_update.Text = "检查更新"; })); } Directory.Delete(updatebasePath, true); } else { File.Delete(updatePath); btn_update.Invoke(new Action(() => { btn_update.State = false; btn_update.ForeColor = Color.Red; btn_update.Text = "文件已损坏"; })); System.Threading.Thread.Sleep(2000); btn_update.Invoke(new Action(() => { btn_update.ForeColor = this.ForeColor; btn_update.Text = "检查更新"; })); } } } this.Invoke(new Action(() => { btn_update.Width = 114; metroLoading.Visible = metroLoading.State = false; btn_update.Enabled = true; })); isdown = false; })); } else { SystemSettings.UpdateInfo = null; metroLoading.State = false; metroLoading.Visible = false; label_updateInfo.Visible = btn_update.Visible = true; UpdateInfo(); btn_update_Click(sender, e2); } } else { label_NewVersion.Text = "正在检查更新"; label_updateInfo.Visible = btn_info.Visible = btn_update.Visible = false; metroLoading.Visible = true; metroLoading.State = true; SystemSettings.UpdateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm"); bool htmlErr = false; Action _action = () => { Version verson = new Version(Application.ProductVersion); UpdateInfo updateInfo; if (UpdateCore.Update(verson, out updateInfo, out htmlErr, SystemSettings.UpdatePie)) { SystemSettings.UpdateInfo = updateInfo; //this.BeginInvoke(new Action(() => //{ // Frm.Update update = new Frm.Update(this, verson.ToString(), updateInfo); // update.Show(); //})); //Debug.WriteLine(Newtonsoft.Json.JsonConvert.SerializeObject(updateInfo)); } else { SystemSettings.UpdateInfo = null; } }; _task.ContinueWhenAll(new Task[] { _task.StartNew(_action) }, (action => { this.Invoke(new Action(() => { metroLoading.State = false; metroLoading.Visible = false; label_updateInfo.Visible = btn_update.Visible = true; UpdateInfo(htmlErr); })); })); } }