Ask() public static method

Shows a Yes/No dialog.
public static Ask ( string title, string instruction, string observation, Icons icon = Icons.Error ) : bool
title string The title of the window.
instruction string The main instruction.
observation string A complementar observation.
icon Icons The image of the dialog.
return bool
Exemplo n.º 1
0
        private void Delete(History history)
        {
            if (!Dialog.Ask(Title, LocalizationHelper.Get("S.Options.Upload.History.Delete.Instruction"), LocalizationHelper.Get("S.Options.Upload.History.Delete.Message")))
            {
                return;
            }

            CurrentPreset?.History.Remove(history);
            DataGrid.ItemsSource   = null;
            DataGrid.ItemsSource   = CurrentPreset?.History;
            DataGrid.SelectedIndex = 0;
        }
Exemplo n.º 2
0
        private void Update_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            var download = new DownloadDialog
            {
                Element = _newRelease,
                Owner   = this
            };

            var result = download.ShowDialog();

            if (result.HasValue && result.Value)
            {
                if (Dialog.Ask("Screen To Gif", FindResource("Update.CloseThis").ToString(), FindResource("Update.CloseThis.Detail").ToString()))
                {
                    Environment.Exit(25);
                }
            }
        }
Exemplo n.º 3
0
        private void Update_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            var download = new DownloadDialog
            {
                Element = _newRelease,
                Owner   = this
            };

            var result = download.ShowDialog();

            if (result.HasValue && result.Value)
            {
                if (Dialog.Ask("Screen To Gif", "Do you want to close this app?", "This is the old release, you downloaded the new version already."))
                {
                    Environment.Exit(25);
                }
            }
        }
Exemplo n.º 4
0
        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"), 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;
        }
Exemplo n.º 5
0
        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;
        }