private async void ButtonUpgrade_OnClick(object sender, RoutedEventArgs e) { #if (!SQUIRREL) if (_inProgress) { TabControl.SelectedIndex = 1; return; } _inProgress = true; if (File.Exists(InstallerFile)) { try { File.Delete(InstallerFile); } catch (Exception) { _inProgress = false; ErrorManager.AddError("Installer file already exists.", $"Please delete '{InstallerFile}' and try again."); return; } } TabControl.SelectedIndex = 1; LabelHeader.Content = "Downloading..."; try { using (var wc = new WebClient()) { var release = await GitHub.CheckForUpdate("HearthSim", "HDT-Releases", new Version(0, 0)); var installer = release?.Assets?.FirstOrDefault(x => x.Name == "HDT-Installer.exe"); if (installer != null) { wc.DownloadProgressChanged += (o, args) => Progress = args.ProgressPercentage; await wc.DownloadFileTaskAsync(installer.Url, InstallerFile); } ButtonRestart.IsEnabled = true; ButtonBack.Visibility = Visibility.Collapsed; LabelHeader.Content = "Download complete"; } } catch (Exception ex) { _inProgress = false; Log.Error(ex); ErrorManager.AddError("Could not download new installer.", "Please manually download it from 'https://hsdecktracker.net/download'."); if (File.Exists(InstallerFile)) { try { File.Delete(InstallerFile); } catch (Exception ex1) { Log.Error(ex1); } } } #endif }
private static async Task <GitHub.Release> GetLatestRelease(bool beta) { var currentVersion = Helper.GetCurrentVersion(); if (currentVersion == null) { return(null); } return(await GitHub.CheckForUpdate("HearthSim", "Hearthstone-Deck-Tracker", currentVersion, beta)); }
public static async Task <bool> CheckAutoUpdate(Version currentVersion) { Log.Debug("Checking for new DeckPredictor version, current version: " + currentVersion); var release = await GitHub.CheckForUpdate(GitHubUser, GitHubRepo, currentVersion, true); if (release == null) { Log.Debug("DeckPredictor is up-to-date."); return(false); } if (!Directory.Exists(TempDirectory)) { Log.Debug("Creating temp directory: " + TempDirectory); Directory.CreateDirectory(TempDirectory); } try { Log.Info("Downloading new DeckPredictor Version: " + release.Tag); var path = await GitHub.DownloadRelease(release, TempDirectory); if (path == null) { Log.Error("Download failed, check hdt log for error."); return(false); } Log.Info("Downloaded to: " + path); var zipFile = Path.Combine(TempDirectory, release.Assets[0].Name); Log.Info("Extracting " + zipFile + "..."); ZipFile.ExtractToDirectory(zipFile, TempDirectory); Log.Info("Copying over new DeckPredictor..."); Log.Debug("From: " + TempPluginDirectory + " To: " + DeckPredictorPlugin.PluginDirectory); CopyFiles(TempPluginDirectory, DeckPredictorPlugin.PluginDirectory); } catch (Exception e) { Log.Error("Exception while installing update: " + e); return(false); } finally { // Delete temp directory if (Directory.Exists(TempDirectory)) { Directory.Delete(TempDirectory, true); } } return(true); }