private async void firmwareUpdater_Load(object sender, EventArgs e) { ipaddressText.Text = _ipaddress; infoText.Text = ""; string firmwarePath = Path.GetTempPath() + $"firmware_{_version}.bin"; githubUpdater updater = new githubUpdater("limiteddata", "ESPRGB-8266", Path.GetTempPath()); infoText.Text += $"Downloading firmware version {_version}.\n"; var download = await updater.downloadVersion(_version); if (download) { infoText.Text += "Finished downloading firmware \n"; infoText.Text += "Unziping the archive\n"; if (File.Exists(firmwarePath)) { File.Delete(firmwarePath); } ZipFile.ExtractToDirectory(updater.updateArchiveFileName, Path.GetTempPath()); progress.Value = 0; ESPOTA ota = new ESPOTA(_ipaddress, firmwarePath); progress.Maximum = ota.content_size; ota.progressEvent += (senderx, ex) => { progress.Value = ex; progress.Refresh(); }; ota.messageEvent += (senderx, ex) => { infoText.Text += ex + "\n"; infoText.Refresh(); }; if (ota.Update()) { exceptions msg = new exceptions(0, "ESPRGB-FirmwareUpdate", "Firmware updated successfully!"); msg.StartPosition = FormStartPosition.CenterParent; msg.ShowDialog(); } else { exceptions msg = new exceptions(0, "ESPRGB-FirmwareUpdate", "Failed to upload the firmware!"); msg.StartPosition = FormStartPosition.CenterParent; msg.ShowDialog(); } File.Delete(updater.updateArchiveFileName); File.Delete(Path.GetTempPath() + $"firmware_{_version}.bin"); this.Close(); } else { this.Close(); } }
public void checkForUpdates() { try { if (CheckInternetConnection()) { Console.WriteLine("Internet connection available"); Thread updateChecker = new Thread(() => { githubUpdater updater = new githubUpdater("limiteddata", "ESPRGB-Client", Path.GetTempPath()); Task <bool> newUpdate = updater.checkForUpdates(curVersion); if (newUpdate.Result) { exceptions updateMessage = new exceptions(1, "ESPRGB-Update", "Version " + updater.latestVersion.ToString() + " is available.\n Do you want to update?"); updateMessage.StartPosition = FormStartPosition.CenterParent; updateMessage.ShowDialog(); if (updateMessage.DialogResult == DialogResult.Yes) { Task <bool> download = updater.downloadNewVersionFromExtension("msi"); if (download.Result) { exceptions msg = new exceptions(0, "ESPRGB-Update", "Finished downloading. Continue installing the new version"); msg.StartPosition = FormStartPosition.CenterParent; msg.ShowDialog(); if (msg.DialogResult == DialogResult.OK) { if (updater.Install()) { this.Invoke((MethodInvoker) delegate { Application.Exit(); }); } } } } } }); updateChecker.Start(); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); throw; } }