private async void DownloadButton_Click(object sender, RoutedEventArgs e) { StatusBand.Hide(); if (EncodingManager.Encodings.Any(a => a.Status == Status.Processing)) { StatusBand.Warning(LocalizationHelper.Get("S.Updater.Warning.Encoding")); return; } DownloadButton.IsEnabled = false; StatusBand.Info(LocalizationHelper.Get("S.Updater.Downloading")); //If it's still downloading, wait for it to finish. if (Global.UpdateAvailable.IsDownloading) { Global.UpdateAvailable.TaskCompletionSource = new TaskCompletionSource <bool>(); await Global.UpdateAvailable.TaskCompletionSource.Task; if (!IsLoaded) { return; } } //If update already downloaded, simply close this window. The installation will happen afterwards. if (File.Exists(Global.UpdateAvailable.ActivePath)) { GC.Collect(); DialogResult = true; return; } //When the update was not queried from Github, the download must be done by browser. if (!Global.UpdateAvailable.IsFromGithub) { try { Process.Start(Global.UpdateAvailable.ActiveDownloadUrl); } catch (Exception ex) { LogWriter.Log(ex, "Impossible to open the browser to download the update.", Global.UpdateAvailable?.ActiveDownloadUrl); } GC.Collect(); DialogResult = true; return; } DownloadProgressBar.Visibility = Visibility.Visible; RunAfterwardsCheckBox.Visibility = Visibility.Collapsed; var result = await Task.Run(async() => await App.MainViewModel.DownloadUpdate()); //If cancelled. if (!IsLoaded) { return; } if (!result) { DownloadButton.IsEnabled = true; DownloadProgressBar.Visibility = Visibility.Hidden; StatusBand.Error(LocalizationHelper.Get("S.Updater.Warning.Download")); return; } //If the update was downloaded successfully, close this window to run. if (File.Exists(Global.UpdateAvailable.ActivePath)) { GC.Collect(); StatusBand.Hide(); DialogResult = true; return; } StatusBand.Error(LocalizationHelper.Get("S.Updater.Warning.Download")); }
private async void Add_Executed(object sender, ExecutedRoutedEventArgs e) { var ofd = new OpenFileDialog { AddExtension = true, CheckFileExists = true, Title = LocalizationHelper.Get("S.Localization.OpenResource"), Filter = LocalizationHelper.Get("S.Localization.File.Resource") + " (*.xaml)|*.xaml;" }; var result = ofd.ShowDialog(); if (!result.HasValue || !result.Value) { return; } #region Validations var position = ofd.FileName.IndexOf("StringResources", StringComparison.InvariantCulture); var subs = position > -1 ? ofd.FileName.Substring(position) : ""; var pieces = subs.Split(new[] { '.' }, StringSplitOptions.RemoveEmptyEntries); //Wrong filename format. if (position < 0 || pieces.Length != 3) { Dialog.Ok(Title, LocalizationHelper.Get("S.Localization.Warning.Name"), LocalizationHelper.Get("S.Localization.Warning.Name.Info")); StatusBand.Hide(); return; } //Repeated language code. if (Application.Current.Resources.MergedDictionaries.Any(x => x.Source != null && x.Source.OriginalString.Contains(subs))) { Dialog.Ok(Title, LocalizationHelper.Get("S.Localization.Warning.Repeated"), LocalizationHelper.Get("S.Localization.Warning.Repeated.Info")); StatusBand.Hide(); return; } try { var properCulture = await Task.Factory.StartNew(() => CheckSupportedCulture(pieces[1])); if (properCulture != pieces[1]) { Dialog.Ok(Title, LocalizationHelper.Get("S.Localization.Warning.Redundant"), LocalizationHelper.GetWithFormat("S.Localization.Warning.Redundant.Info", "The \"{0}\" code is redundant. Try using \"{1}\" instead.", pieces[1], properCulture)); StatusBand.Hide(); return; } } catch (CultureNotFoundException cn) { LogWriter.Log(cn, "Impossible to validade the resource name, culture not found"); Dialog.Ok(Title, LocalizationHelper.Get("S.Localization.Warning.Unknown"), LocalizationHelper.GetWithFormat("S.Localization.Warning.Unknown.Info", "The \"{0}\" and its family were not recognized as valid language codes.", pieces[1])); StatusBand.Hide(); return; } catch (Exception ex) { LogWriter.Log(ex, "Impossible to validade the resource name"); Dialog.Ok(Title, LocalizationHelper.Get("S.Localization.Warning.NotPossible"), ex.Message); StatusBand.Hide(); return; } #endregion StatusBand.Info(LocalizationHelper.Get("S.Localization.Importing")); try { var fileName = ofd.FileName; await Task.Factory.StartNew(() => LocalizationHelper.ImportStringResource(fileName)); } catch (Exception ex) { LogWriter.Log(ex, "Impossible to import the resource"); Dialog.Ok(Title, LocalizationHelper.Get("S.Localization.Warning.NotPossible"), ex.Message); StatusBand.Hide(); return; } var resourceDictionary = Application.Current.Resources.MergedDictionaries.LastOrDefault(); var imageItem = new ExtendedListBoxItem { Content = resourceDictionary?.Source.OriginalString ?? "...", Icon = FindResource("Vector.Translate") as Brush, Author = LocalizationHelper.GetWithFormat("S.Localization.Recognized", "Recognized as {0}", pieces[1]), Index = Application.Current.Resources.MergedDictionaries.Count - 1, ShowMarkOnSelection = false }; StatusBand.Hide(); ResourceListBox.Items.Add(imageItem); ResourceListBox.ScrollIntoView(imageItem); UpdateIndexes(); CommandManager.InvalidateRequerySuggested(); }
private async void Localization_Loaded(object sender, RoutedEventArgs e) { AddButton.IsEnabled = false; SaveButton.IsEnabled = false; RemoveButton.IsEnabled = false; DownButton.IsEnabled = false; UpButton.IsEnabled = false; OkButton.IsEnabled = false; var actualIndex = 0; foreach (var resourceDictionary in Application.Current.Resources.MergedDictionaries) { //If it's not a localization resource, ignore it. if (resourceDictionary.Source?.OriginalString.Contains("StringResources") != true) { actualIndex++; continue; } var imageItem = new ExtendedListBoxItem { Content = resourceDictionary.Source.OriginalString, Icon = FindResource("Vector.Translate") as Brush, Index = actualIndex++, ShowMarkOnSelection = false }; #region Language code var pieces = resourceDictionary.Source.OriginalString.Split(new[] { '.' }, StringSplitOptions.RemoveEmptyEntries); if (pieces.Length == 3 || pieces.Length == 4) { imageItem.Author = LocalizationHelper.GetWithFormat("S.Localization.Recognized", "Recognized as {0}", pieces[1]); } else { imageItem.Author = LocalizationHelper.Get("S.Localization.NotRecognized"); } #endregion ResourceListBox.Items.Add(imageItem); } //Selects the last item on the list. ResourceListBox.SelectedItem = ResourceListBox.Items.Cast <ExtendedListBoxItem>().LastOrDefault(w => w.IsEnabled); if (ResourceListBox.SelectedItem != null) { ResourceListBox.ScrollIntoView(ResourceListBox.SelectedItem); } StatusBand.Info(LocalizationHelper.Get("S.Localization.GettingCodes")); _cultures = await GetProperCulturesAsync(); AddButton.IsEnabled = true; SaveButton.IsEnabled = true; RemoveButton.IsEnabled = true; DownButton.IsEnabled = true; UpButton.IsEnabled = true; OkButton.IsEnabled = true; StatusBand.Hide(); SizeToContent = SizeToContent.Width; MaxHeight = double.PositiveInfinity; CommandManager.InvalidateRequerySuggested(); }
private void Window_Loaded(object sender, RoutedEventArgs e) { #region Adjust to file type switch (Current.Type) { case ExportFormats.Gif: EncoderScreenToGifItem.IsEnabled = true; EncoderFfmpegItem.IsEnabled = true; EncoderGifskiItem.IsEnabled = Environment.Is64BitProcess; EncoderSystemItem.IsEnabled = true; EncoderKGySoftItem.IsEnabled = true; break; case ExportFormats.Apng: EncoderScreenToGifItem.IsEnabled = true; EncoderFfmpegItem.IsEnabled = true; EncoderGifskiItem.IsEnabled = false; EncoderSystemItem.IsEnabled = false; EncoderKGySoftItem.IsEnabled = false; break; case ExportFormats.Webp: case ExportFormats.Bpg: case ExportFormats.Avi: case ExportFormats.Mkv: case ExportFormats.Mov: case ExportFormats.Mp4: case ExportFormats.Webm: EncoderScreenToGifItem.IsEnabled = false; EncoderFfmpegItem.IsEnabled = true; EncoderGifskiItem.IsEnabled = false; EncoderSystemItem.IsEnabled = false; EncoderKGySoftItem.IsEnabled = false; break; case ExportFormats.Jpeg: case ExportFormats.Png: case ExportFormats.Bmp: case ExportFormats.Stg: case ExportFormats.Psd: EncoderScreenToGifItem.IsEnabled = true; EncoderFfmpegItem.IsEnabled = false; EncoderGifskiItem.IsEnabled = false; EncoderSystemItem.IsEnabled = false; EncoderKGySoftItem.IsEnabled = false; break; } #endregion TitleTextBox.Focus(); ExtensionTextBlock.Text = Current.Type.ToString(); EncoderComboBox.SelectedValue = Current.Encoder; if (IsNew) { AutoSaveCheckBox.IsChecked = true; return; } //Edit. IconBorder.Background = TryFindResource("Vector.Pen") as Brush; ModeTextBlock.Text = LocalizationHelper.Get("S.Edit"); EncoderComboBox.IsEnabled = false; TitleTextBox.Text = Current.Title ?? ""; DescriptionTextBox.Text = Current.Description ?? ""; AutoSaveCheckBox.IsChecked = Current.HasAutoSave; SaveInfoTextBlock.SetResourceReference(TextBlock.TextProperty, "S.Preset.Info." + (AutoSaveCheckBox.IsChecked == true ? "Automatic" : "Manual")); //If it's a default preset, just let the user edit the "auto save" feature. if (string.IsNullOrWhiteSpace(Current.TitleKey)) { return; } TitleTextBox.IsEnabled = false; DescriptionTextBox.IsEnabled = false; AutoSaveCheckBox.Focus(); StatusBand.Info(LocalizationHelper.Get("S.Preset.Warning.Readonly")); }
private void SendButton_Click(object sender, RoutedEventArgs e) { StatusBand.Hide(); #region Validation if (TitleTextBox.Text.Length == 0) { StatusBand.Warning(FindResource("S.Feedback.Warning.Title") as string); TitleTextBox.Focus(); return; } if (MessageTextBox.Text.Length == 0) { StatusBand.Warning(FindResource("S.Feedback.Warning.Message") as string); MessageTextBox.Focus(); return; } if (string.IsNullOrWhiteSpace(Secret.Password)) { Dialog.Ok("Feedback", "You are probably running from the source code", "Please, don't try to log into the account of the e-mail sender. " + "Everytime someone does that, the e-mail gets locked and this feature (the feedback) stops working.", Dialog.Icons.Warning); return; } #endregion #region UI StatusBand.Info(FindResource("S.Feedback.Sending").ToString()); Cursor = Cursors.AppStarting; MainGrid.IsEnabled = false; MainGrid.UpdateLayout(); #endregion //Please, don't try to log with this e-mail and password. :/ //Everytime someone does this, I have to change the password and the Feedback feature stops working until I update the app. var passList = Secret.Password.Split('|'); var smtp = new SmtpClient { Timeout = 5 * 60 * 1000, //Minutes, seconds, miliseconds Port = Secret.Port, Host = Secret.Host, EnableSsl = true, UseDefaultCredentials = true, Credentials = new NetworkCredential(Secret.Email, passList[_current]) }; //Please, don't try to log with this e-mail and password. :/ //Everytime someone does this, I have to change the password and the Feedback feature stops working until I update the app. var mail = new MailMessage { From = new MailAddress("*****@*****.**"), Subject = "ScreenToGif - Feedback", IsBodyHtml = true }; mail.To.Add("*****@*****.**"); #region Text var sb = new StringBuilder(); sb.Append("<html xmlns:msxsl=\"urn:schemas-microsoft-com:xslt\">"); sb.Append("<head><meta content=\"en-us\" http-equiv=\"Content-Language\" />" + "<meta content=\"text/html; charset=utf-16\" http-equiv=\"Content-Type\" />" + "<title>Screen To Gif - Feedback</title>" + "</head>"); sb.AppendFormat("<style>{0}</style>", Util.Other.GetTextResource("ScreenToGif.Resources.Style.css")); sb.Append("<body>"); sb.AppendFormat("<h1>{0}</h1>", TitleTextBox.Text); sb.Append("<div id=\"content\"><div>"); sb.Append("<h2>Overview</h2>"); sb.Append("<div id=\"overview\"><table><tr>"); sb.Append("<th _locid=\"UserTableHeader\">User</th>"); if (MailTextBox.Text.Length > 0) { sb.Append("<th _locid=\"FromTableHeader\">Mail</th>"); } sb.Append("<th _locid=\"VersionTableHeader\">Version</th>"); sb.Append("<th _locid=\"WindowsTableHeader\">Windows</th>"); sb.Append("<th _locid=\"BitsTableHeader\">Instruction Size</th>"); sb.Append("<th _locid=\"MemoryTableHeader\">Working Memory</th>"); sb.Append("<th _locid=\"IssueTableHeader\">Issue?</th>"); sb.Append("<th _locid=\"SuggestionTableHeader\">Suggestion?</th></tr>"); sb.AppendFormat("<tr><td class=\"textcentered\">{0}</td>", Environment.UserName); if (MailTextBox.Text.Length > 0) { sb.AppendFormat("<td class=\"textcentered\">{0}</td>", MailTextBox.Text); } sb.AppendFormat("<td class=\"textcentered\">{0}</td>", Assembly.GetExecutingAssembly().GetName().Version.ToString(4)); sb.AppendFormat("<td class=\"textcentered\">{0}</td>", Environment.OSVersion.Version); sb.AppendFormat("<td class=\"textcentered\">{0}</td>", Environment.Is64BitOperatingSystem ? "64 bits" : "32 Bits"); sb.AppendFormat("<td class=\"textcentered\">{0}</td>", Humanizer.BytesToString(Environment.WorkingSet)); sb.AppendFormat("<td class=\"textcentered\">{0}</td>", IssueCheckBox.IsChecked.Value ? "Yes" : "No"); sb.AppendFormat("<td class=\"textcentered\">{0}</td></tr></table></div></div>", SuggestionCheckBox.IsChecked.Value ? "Yes" : "No"); sb.Append("<h2>Details</h2><div><div><table>"); sb.Append("<tr id=\"ProjectNameHeaderRow\"><th class=\"messageCell\" _locid=\"MessageTableHeader\">Message</th></tr>"); sb.Append("<tr name=\"MessageRowClassProjectName\">"); sb.AppendFormat("<td class=\"messageCell\">{0}</td></tr></table>", MessageTextBox.Text); sb.Append("</div></div></div></body></html>"); #endregion mail.Body = sb.ToString(); foreach (AttachmentListBoxItem attachment in AttachmentListBox.Items) { mail.Attachments.Add(new Attachment(attachment.Attachment)); } smtp.SendCompleted += Smtp_OnSendCompleted; smtp.SendMailAsync(mail); }
private async void DownloadButton_Click(object sender, RoutedEventArgs e) { #region Save as var save = new Microsoft.Win32.SaveFileDialog { FileName = "ScreenToGif" + (IsInstaller ? " Setup " + Element.XPathSelectElement("tag_name").Value : ""), DefaultExt = IsInstaller ? ".msi" : ".exe", Filter = IsInstaller ? "ScreenToGif setup (.msi)|*.msi" : "ScreenToGif executable (.exe)|*.exe" }; var result = save.ShowDialog(); if (!result.HasValue || !result.Value) { return; } if (save.FileName == Assembly.GetExecutingAssembly().Location) { Dialog.Ok(Title, this.TextResource("Update.Filename.Warning"), this.TextResource("Update.Filename.Warning2"), Dialog.Icons.Warning); return; } #endregion DownloadButton.IsEnabled = false; StatusBand.Info("Downloading..."); DownloadProgressBar.Visibility = Visibility.Visible; var tempFilename = !IsInstaller?save.FileName.Replace(".exe", DateTime.Now.ToString(" hh-mm-ss fff") + ".zip") : save.FileName; #region Download try { using (var webClient = new WebClient()) { webClient.Credentials = CredentialCache.DefaultNetworkCredentials; webClient.Proxy = WebHelper.GetProxy(); await webClient.DownloadFileTaskAsync(new Uri((IsInstaller ? Element.XPathSelectElement("assets").LastNode : Element.XPathSelectElement("assets").FirstNode).XPathSelectElement("browser_download_url").Value), tempFilename); } } catch (Exception ex) { LogWriter.Log(ex, "Download updates"); DownloadButton.IsEnabled = true; DownloadProgressBar.Visibility = Visibility.Hidden; Dialog.Ok("Update", "Error while downloading", ex.Message); return; } #endregion //If cancelled. if (!IsLoaded) { return; } #region Installer if (IsInstaller) { if (!Dialog.Ask(Title, this.TextResource("Update.Install.Header"), this.TextResource("Update.Install.Description"))) { return; } try { Process.Start(tempFilename); } catch (Exception ex) { LogWriter.Log(ex, "Starting the installer"); Dialog.Ok(Title, "Error while starting the installer", ex.Message); return; } Environment.Exit(25); } #endregion #region Unzip try { //Deletes if already exists. if (File.Exists(save.FileName)) { File.Delete(save.FileName); } //Unzips the only file. using (var zipArchive = ZipFile.Open(tempFilename, ZipArchiveMode.Read)) zipArchive.Entries.First(x => x.Name.EndsWith(".exe")).ExtractToFile(save.FileName); } catch (Exception ex) { LogWriter.Log(ex, "Unziping update"); DownloadButton.IsEnabled = true; DownloadProgressBar.Visibility = Visibility.Hidden; Dialog.Ok("Update", "Error while unzipping", ex.Message); return; } #endregion #region Delete temporary zip and run try { File.Delete(tempFilename); Process.Start(save.FileName); } catch (Exception ex) { LogWriter.Log(ex, "Finishing update"); DownloadButton.IsEnabled = true; DownloadProgressBar.Visibility = Visibility.Hidden; Dialog.Ok(Title, "Error while finishing the update", ex.Message); return; } #endregion GC.Collect(); DialogResult = true; }
private async void Localization_OnLoaded(object sender, RoutedEventArgs e) { StatusBand.Info("Getting resources..."); AddButton.IsEnabled = false; SaveButton.IsEnabled = false; RemoveButton.IsEnabled = false; DownButton.IsEnabled = false; UpButton.IsEnabled = false; OkButton.IsEnabled = false; foreach (var resourceDictionary in Application.Current.Resources.MergedDictionaries) { var imageItem = new ImageListBoxItem { Tag = resourceDictionary.Source?.OriginalString ?? "Settings", Content = resourceDictionary.Source?.OriginalString ?? "Settings" }; if (resourceDictionary.Source == null) { imageItem.IsEnabled = false; imageItem.Image = FindResource("Vector.No") as Canvas; imageItem.Author = "This is a settings dictionary."; } else if (resourceDictionary.Source.OriginalString.Contains("StringResources")) { imageItem.Image = FindResource("Vector.Translate") as Canvas; #region Name //var subs = resourceDictionary.Source.OriginalString.Substring(resourceDictionary.Source.OriginalString.IndexOf("StringResources")); var pieces = resourceDictionary.Source.OriginalString.Split(new[] { '.' }, StringSplitOptions.RemoveEmptyEntries); if (pieces.Length == 3 || pieces.Length == 4) { imageItem.Author = "Recognized as " + pieces[1]; } else { imageItem.Author = "Not recognized"; } #endregion } else { imageItem.IsEnabled = false; imageItem.Image = FindResource("Vector.No") as Canvas; imageItem.Author = "This is a style dictionary."; } ResourceListBox.Items.Add(imageItem); } ResourceListBox.SelectedIndex = ResourceListBox.Items.Count - 1; ResourceListBox.ScrollIntoView(ResourceListBox.SelectedItem); SaveButton.IsEnabled = true; RemoveButton.IsEnabled = true; DownButton.IsEnabled = true; UpButton.IsEnabled = true; OkButton.IsEnabled = true; StatusBand.Info("Getting language codes..."); _cultures = await GetProperCulturesAsync(); StatusBand.Hide(); AddButton.IsEnabled = true; SizeToContent = SizeToContent.Width; MaxHeight = double.PositiveInfinity; CommandManager.InvalidateRequerySuggested(); }
private async void Add_Executed(object sender, ExecutedRoutedEventArgs e) { var ofd = new OpenFileDialog { AddExtension = true, CheckFileExists = true, Title = "Open a Resource Dictionary", Filter = "Resource Dictionay (*.xaml)|*.xaml;" }; var result = ofd.ShowDialog(); if (!result.HasValue || !result.Value) { return; } StatusBand.Info("Validating resource name..."); #region Validation if (!ofd.FileName.Contains("StringResources")) { Dialog.Ok("Action Denied", "The name of file does not follow a valid pattern.", "Try renaming like (without the []): StringResources.[Language Code].xaml"); StatusBand.Hide(); return; } var subs = ofd.FileName.Substring(ofd.FileName.IndexOf("StringResources")); if (Application.Current.Resources.MergedDictionaries.Any(x => x.Source != null && x.Source.OriginalString.Contains(subs))) { Dialog.Ok("Action Denied", "You can't add a resource with the same name.", "Try renaming like: StringResources.[Language Code].xaml"); StatusBand.Hide(); return; } var pieces = subs.Split(new[] { '.' }, StringSplitOptions.RemoveEmptyEntries); if (pieces.Length != 3) { Dialog.Ok("Action Denied", "Filename with wrong format.", "Try renaming like: StringResources.[Language Code].xaml"); StatusBand.Hide(); return; } var cultureName = pieces[1]; string properCulture; try { properCulture = await Task.Factory.StartNew(() => CheckSupportedCulture(cultureName)); } catch (CultureNotFoundException) { Dialog.Ok("Action Denied", "Unknown Language.", $"The \"{cultureName}\" and its family were not recognized as a valid language codes."); StatusBand.Hide(); return; } catch (Exception ex) { Dialog.Ok("Action Denied", "Error checking culture.", ex.Message); StatusBand.Hide(); return; } if (properCulture != cultureName) { Dialog.Ok("Action Denied", "Redundant Language Code.", $"The \"{cultureName}\" code is redundant. Try using \'{properCulture}\" instead"); StatusBand.Hide(); return; } #endregion StatusBand.Info("Importing resource..."); var fileName = ofd.FileName; try { await Task.Factory.StartNew(() => LocalizationHelper.ImportStringResource(fileName)); } catch (Exception ex) { Dialog.Ok("Localization", "Localization - Importing Xaml Resource", ex.Message); StatusBand.Hide(); await Task.Factory.StartNew(GC.Collect); return; } var resourceDictionary = Application.Current.Resources.MergedDictionaries.LastOrDefault(); var imageItem = new ImageListBoxItem { Tag = resourceDictionary?.Source.OriginalString ?? "Unknown", Content = resourceDictionary?.Source.OriginalString ?? "Unknown", Image = FindResource("Vector.Translate") as Canvas, Author = "Recognized as " + pieces[1] }; StatusBand.Hide(); ResourceListBox.Items.Add(imageItem); ResourceListBox.ScrollIntoView(imageItem); CommandManager.InvalidateRequerySuggested(); }
private async void DownloadButton_Click(object sender, RoutedEventArgs e) { #region Save as var save = new Microsoft.Win32.SaveFileDialog { FileName = "ScreenToGif " + Global.UpdateModel.Version + (IsInstaller ? " Setup" : ""), DefaultExt = IsInstaller ? ".msi" : ".exe", Filter = IsInstaller ? "ScreenToGif setup|*.msi" : "ScreenToGif executable|*.exe" }; var result = save.ShowDialog(); if (!result.HasValue || !result.Value) { return; } if (save.FileName == Assembly.GetExecutingAssembly().Location) { Dialog.Ok(Title, LocalizationHelper.Get("Update.Filename.Warning"), LocalizationHelper.Get("Update.Filename.Warning2"), Icons.Warning); return; } #endregion //After downloading, remove the notification and set the global variable to null; DownloadButton.IsEnabled = false; StatusBand.Info("Downloading..."); DownloadProgressBar.Visibility = Visibility.Visible; var tempFilename = !IsInstaller?save.FileName.Replace(".exe", DateTime.Now.ToString(" hh-mm-ss fff") + ".zip") : save.FileName; #region Download try { using (var webClient = new WebClient()) { webClient.Credentials = CredentialCache.DefaultNetworkCredentials; webClient.Proxy = WebHelper.GetProxy(); await webClient.DownloadFileTaskAsync(new Uri(IsInstaller ? Global.UpdateModel.InstallerDownloadUrl : Global.UpdateModel.PortableDownloadUrl), tempFilename); } } catch (Exception ex) { LogWriter.Log(ex, "Download updates"); DownloadButton.IsEnabled = true; DownloadProgressBar.Visibility = Visibility.Hidden; StatusBand.Hide(); Dialog.Ok("Update", "Error while downloading", ex.Message); return; } #endregion //If cancelled. if (!IsLoaded) { StatusBand.Hide(); return; } #region Installer if (IsInstaller) { if (!Dialog.Ask(Title, LocalizationHelper.Get("Update.Install.Header"), LocalizationHelper.Get("Update.Install.Description"))) { return; } try { Process.Start(tempFilename); } catch (Exception ex) { LogWriter.Log(ex, "Starting the installer"); StatusBand.Hide(); Dialog.Ok(Title, "Error while starting the installer", ex.Message); return; } Global.UpdateModel = null; Environment.Exit(25); } #endregion #region Unzip try { //Unzips the only file. using (var zipArchive = ZipFile.Open(tempFilename, ZipArchiveMode.Read)) zipArchive.Entries.First(x => x.Name.EndsWith(".exe")).ExtractToFile(save.FileName, true); } catch (Exception ex) { LogWriter.Log(ex, "Unziping update"); DownloadButton.IsEnabled = true; DownloadProgressBar.Visibility = Visibility.Hidden; StatusBand.Hide(); Dialog.Ok("Update", "Error while unzipping", ex.Message); return; } #endregion Global.UpdateModel = null; #region Delete temporary zip and run try { File.Delete(tempFilename); Process.Start(save.FileName); } catch (Exception ex) { LogWriter.Log(ex, "Finishing update"); DownloadButton.IsEnabled = true; DownloadProgressBar.Visibility = Visibility.Hidden; StatusBand.Hide(); Dialog.Ok(Title, "Error while finishing the update", ex.Message); return; } #endregion GC.Collect(); DialogResult = true; }
private async void DownloadButton_Click(object sender, RoutedEventArgs e) { #region Save as var save = new Microsoft.Win32.SaveFileDialog { FileName = "ScreenToGif", // + Element.XPathSelectElement("tag_name").Value, DefaultExt = ".exe", Filter = "ScreenToGif executable (.exe)|*.exe" }; var result = save.ShowDialog(); if (!result.HasValue || !result.Value) { return; } #endregion DownloadButton.IsEnabled = false; StatusBand.Info("Downloading..."); DownloadProgressBar.Visibility = Visibility.Visible; var tempFilename = save.FileName.Replace(".exe", DateTime.Now.ToString(" hh-mm-ss fff") + ".zip"); #region Download try { using (var webClient = new WebClient()) { webClient.Credentials = CredentialCache.DefaultNetworkCredentials; await webClient.DownloadFileTaskAsync(new Uri(Element.XPathSelectElement("assets").FirstNode.XPathSelectElement("browser_download_url").Value), tempFilename); } } catch (Exception ex) { LogWriter.Log(ex, "Download updates"); DownloadButton.IsEnabled = true; DownloadProgressBar.Visibility = Visibility.Hidden; Dialog.Ok("Update", "Error while downloading", ex.Message); return; } #endregion //If cancelled. if (!IsLoaded) { return; } #region Unzip try { //Deletes if already exists. if (File.Exists(save.FileName)) { File.Delete(save.FileName); } //Unzips the only file. using (var zipArchive = ZipFile.Open(tempFilename, ZipArchiveMode.Read)) { zipArchive.Entries.First(x => x.Name.EndsWith(".exe")).ExtractToFile(save.FileName); } } catch (Exception ex) { LogWriter.Log(ex, "Unziping update"); DownloadButton.IsEnabled = true; DownloadProgressBar.Visibility = Visibility.Hidden; Dialog.Ok("Update", "Error while unzipping", ex.Message); return; } #endregion //If cancelled. if (!IsLoaded) { return; } #region Delete temporary zip and run try { File.Delete(tempFilename); Process.Start(save.FileName); } catch (Exception ex) { LogWriter.Log(ex, "Finishing update"); DownloadButton.IsEnabled = true; DownloadProgressBar.Visibility = Visibility.Hidden; Dialog.Ok("Update", "Error while finishing the update", ex.Message); return; } #endregion DialogResult = true; }