private async void Window_Loaded(object sender, RoutedEventArgs e) { #region Validation if (Global.UpdateAvailable == null) { WhatsNewParagraph.Inlines.Add("Something wrong happened. No update was found."); return; } if (Global.UpdateAvailable.MustDownloadManually) { StatusBand.Warning(LocalizationHelper.Get("S.Updater.NoNewRelease.Info")); } #endregion try { //Detect if this is portable or installed. Download the proper file. IsChocolatey = AppDomain.CurrentDomain.BaseDirectory.EndsWith(@"Chocolatey\lib\screentogif\content\"); IsInstaller = Directory.EnumerateFiles(AppDomain.CurrentDomain.BaseDirectory).Any(x => x.ToLowerInvariant().EndsWith("screentogif.visualelementsmanifest.xml")); VersionRun.Text = $"{LocalizationHelper.Get("S.Updater.Version")} {Global.UpdateAvailable.Version}"; SizeRun.Text = !UserSettings.All.PortableUpdate ? (Global.UpdateAvailable.InstallerSize > 0 ? Humanizer.BytesToString(Global.UpdateAvailable.InstallerSize) : "") : (Global.UpdateAvailable.PortableSize > 0 ? Humanizer.BytesToString(Global.UpdateAvailable.PortableSize) : ""); TypeRun.Text = IsInstaller ? LocalizationHelper.Get("S.Updater.Installer") : LocalizationHelper.Get("S.Updater.Portable"); //Details. if (Global.UpdateAvailable.IsFromGithub) { //From Github, the description is available. var splited = Global.UpdateAvailable.Description.Split(new[] { '#' }, StringSplitOptions.RemoveEmptyEntries); WhatsNewParagraph.Inlines.Add(splited[0].Replace(" What's new?\r\n\r\n", "")); FixesParagraph.Inlines.Add(splited.Length > 1 ? splited[1].Replace(" Bug fixes:\r\n\r\n", "").Replace(" Fixed:\r\n\r\n", "") : "Aparently nothing."); } else { //If the release detail was obtained by querying Fosshub, no release note is available. MainFlowDocument.Blocks.Remove(WhatsNewParagraphTitle); MainFlowDocument.Blocks.Remove(FixesParagraphTitle); MainFlowDocument.Blocks.Remove(FixesParagraph); var run = new Run(); run.SetResourceReference(Run.TextProperty, "S.Updater.Info.NewVersionAvailable"); WhatsNewParagraph.Inlines.Add(run); } DocumentViewer.UpdateLayout(); //If set to force the download the portable version of the app, check if it was downloaded. if (UserSettings.All.PortableUpdate) { //If the update was already downloaded. if (File.Exists(Global.UpdateAvailable.PortablePath)) { //If it's still downloading, wait for it to finish before displaying "Open". if (Global.UpdateAvailable.IsDownloading) { Global.UpdateAvailable.TaskCompletionSource = new TaskCompletionSource <bool>(); await Global.UpdateAvailable.TaskCompletionSource.Task; if (!IsLoaded) { return; } } DownloadButton.SetResourceReference(ExtendedButton.TextProperty, "S.Updater.InstallManually"); } return; } //If set to download automatically, check if the installer was downloaded. if (UserSettings.All.InstallUpdates) { //If the update was already downloaded. if (File.Exists(Global.UpdateAvailable.InstallerPath)) { //If it's still downloading, wait for it to finish before displaying "Install". if (Global.UpdateAvailable.IsDownloading) { Global.UpdateAvailable.TaskCompletionSource = new TaskCompletionSource <bool>(); await Global.UpdateAvailable.TaskCompletionSource.Task; if (!IsLoaded) { return; } } DownloadButton.SetResourceReference(ExtendedButton.TextProperty, "S.Updater.Install"); //When the update was prompted manually, the user can set the installer to run the app afterwards. if (WasPromptedManually) { RunAfterwardsCheckBox.Visibility = Visibility.Visible; RunAfterwardsCheckBox.IsChecked = true; } } } } catch (Exception ex) { LogWriter.Log(ex, "Impossible to load the download details"); StatusBand.Error(LocalizationHelper.Get("S.Updater.Warning.Show")); } finally { Height = ActualHeight; SizeToContent = SizeToContent.Width; Width = ActualWidth; SizeToContent = SizeToContent.Manual; MaxHeight = double.PositiveInfinity; MaxWidth = double.PositiveInfinity; CenterOnScreen(); } }
private void Window_Loaded(object sender, RoutedEventArgs e) { #region Validation if (Global.UpdateAvailable == null) { WhatsNewParagraph.Inlines.Add("Something wrong happened. No update was found."); return; } #endregion try { //Detect if this is portable or installed. Download the proper file. IsChocolatey = AppDomain.CurrentDomain.BaseDirectory.EndsWith(@"Chocolatey\lib\screentogif\content\"); IsInstaller = Directory.EnumerateFiles(AppDomain.CurrentDomain.BaseDirectory).Any(x => x.ToLowerInvariant().EndsWith("screentogif.visualelementsmanifest.xml")); VersionRun.Text = $"{LocalizationHelper.Get("S.Updater.Version")} {Global.UpdateAvailable.Version}"; SizeRun.Text = Global.UpdateAvailable.InstallerSize > 0 ? Humanizer.BytesToString(IsInstaller ? Global.UpdateAvailable.InstallerSize : Global.UpdateAvailable.PortableSize) : ""; TypeRun.Text = IsInstaller ? LocalizationHelper.Get("S.Updater.Installer") : LocalizationHelper.Get("S.Updater.Portable"); //If set to download automatically, check if the installer was downloaded. if (UserSettings.All.InstallUpdates) { //If the update was already downloaded. if (File.Exists(Global.UpdateAvailable.InstallerPath)) { DownloadButton.SetResourceReference(ImageButton.TextProperty, "S.Updater.Install"); //When the update was prompted manually, the user can set the installer to run the app afterwards. if (WasPromptedManually) { RunAfterwardsCheckBox.Visibility = Visibility.Visible; RunAfterwardsCheckBox.IsChecked = true; } } } //Details. if (Global.UpdateAvailable.IsFromGithub) { //From Github, the description is available. var splited = Global.UpdateAvailable.Description.Split(new[] { '#' }, StringSplitOptions.RemoveEmptyEntries); WhatsNewParagraph.Inlines.Add(splited[0].Replace(" What's new?\r\n\r\n", "")); FixesParagraph.Inlines.Add(splited.Length > 1 ? splited[1].Replace(" Bug fixes:\r\n\r\n", "").Replace(" Fixed:\r\n\r\n", "") : "Aparently nothing."); } else { //If the release detail was obtained by querying Fosshub, no release note is available. MainFlowDocument.Blocks.Remove(WhatsNewParagraphTitle); MainFlowDocument.Blocks.Remove(FixesParagraphTitle); MainFlowDocument.Blocks.Remove(FixesParagraph); var run = new Run(); run.SetResourceReference(Run.TextProperty, "S.Updater.Info.NewVersionAvailable"); WhatsNewParagraph.Inlines.Add(run); } } catch (Exception ex) { LogWriter.Log(ex, "Impossible to load the download details"); StatusBand.Error(LocalizationHelper.Get("S.Updater.Warning.Show")); } }