//Save Changes Button
        private async void Save(object s, RoutedEventArgs e)
        {
            try {
                Cursor = Cursors.Wait;

                ConfigHelper.Save();

                //Restart for applied changes
                InstallerHelper.KillImgurSniper(false);
                //If not Tray Service, do not start
                if (ConfigHelper.RunOnBoot)
                {
                    try {
                        InstallerHelper.StartImgurSniper();
                    } catch {
                        await ErrorToast.ShowAsync(str.trayServiceNotRunning, TimeSpan.FromSeconds(3));
                    }
                }

                SuccessToast.Show(str.applied, TimeSpan.FromSeconds(2));

                BtnSave.IsEnabled = false;
            } catch {
                ErrorToast.Show(str.couldNotApply, TimeSpan.FromSeconds(3));
            }
            Cursor = Cursors.Arrow;
        }
예제 #2
0
        //Make Screenshot, Let user Crop, Upload Picture and Copy Link to Clipboard
        private async void Crop(bool CloseOnFinish, bool FocusNewWindow)
        {
            this.Visibility = Visibility.Visible;
            this.BringIntoView();
            this.Topmost = true;

            ScreenshotWindow window = new ScreenshotWindow(FileIO.AllMonitors, FocusNewWindow);

            window.ShowDialog();

            if (window.DialogResult == true)
            {
                byte[] cimg = window.CroppedImage;

                if (cimg.Length >= 10240000 && !FileIO.TokenExists)
                {
                    await ErrorToast.ShowAsync(Properties.strings.imgToBig, TimeSpan.FromSeconds(3));

                    return;
                }

                try {
                    //Config: Save Image locally?
                    if (Properties.Settings.Default.SaveImages)
                    {
                        long   time      = DateTime.Now.ToFileTimeUtc();
                        string extension = FileIO.UsePNG ? ".png" : ".jpeg";
                        File.WriteAllBytes(_dir + $"\\Snipe_{time}{extension}", cimg);
                    }

                    //Config: Upload Image to Imgur or Copy to Clipboard?
                    if (Properties.Settings.Default.ImgurAfterSnipe)
                    {
                        string KB = $"{(cimg.Length / 1024d):0.#}";
                        SuccessToast.Show(string.Format(Properties.strings.uploading, KB), TimeSpan.FromDays(10));

                        await UploadImageToImgur(cimg, window.HwndName);
                    }
                    else
                    {
                        CopyImageToClipboard(cimg);

                        SuccessToast.Show(Properties.strings.imgclipboard, TimeSpan.FromDays(10));
                    }
                } catch (Exception ex) {
                    File.Delete(FileIO._config);

                    ErrorToast.Show(string.Format(Properties.strings.otherErrorMsg, ex),
                                    TimeSpan.FromSeconds(3.5));
                }
            }

            try {
                if (CloseOnFinish)
                {
                    DelayedClose(0);
                }
                else
                {
                    this.Visibility = Visibility.Hidden;
                }
            } catch {
                System.Windows.Application.Current.Shutdown();
            }
        }