//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
        //Upload byte[] to imgur and give user a response
        private async Task UploadImageToImgur(byte[] cimg, string WindowName)
        {
            string link = await UploadImgur(cimg, WindowName);

            if (link.StartsWith("http://"))
            {
                Clipboard.SetText(link);
                PlayBlop();

                //Catch internal toast exceptions & process start exception
                try {
                    if (FileIO.OpenAfterUpload)
                    {
                        Process.Start(link);
                    }

                    await SuccessToast.ShowAsync(Properties.strings.linkclipboard,
                                                 TimeSpan.FromSeconds(5));
                } catch { }
            }
            else
            {
                //Catch internal toast exceptions
                try {
                    await ErrorToast.ShowAsync(string.Format(Properties.strings.uploadingError, link),
                                               TimeSpan.FromSeconds(5));
                } catch { }
            }
        }
示例#3
0
        private async void InstantUpload(string path)
        {
            await Task.Delay(550);

            string lpath = path.ToLower();

            if (lpath.EndsWith(".jpeg") ||
                lpath.EndsWith(".jpg") ||
                lpath.EndsWith(".png") ||
                lpath.EndsWith(".gif") ||
                lpath.EndsWith(".apng") ||
                lpath.EndsWith(".tiff") ||
                lpath.EndsWith(".xcf") ||
                lpath.EndsWith(".pdf"))
            {
                byte[] byteImg = File.ReadAllBytes(path);

                string KB = $"{(byteImg.Length / 1024d):0.#}";
                SuccessToast.Show(string.Format(Properties.strings.uploading, KB), TimeSpan.FromDays(10));

                await UploadImageToImgur(byteImg, "");
            }
            else
            {
                await ErrorToast.ShowAsync(Properties.strings.errorFileType, TimeSpan.FromSeconds(5));
            }
            DelayedClose(0);
        }
示例#4
0
 //Copy the Byte[] to the Clipboard
 private void CopyImageToClipboard(byte[] cimg)
 {
     CopyClipboard(cimg);
     SuccessToast.Show(Properties.strings.imgclipboard,
                       TimeSpan.FromSeconds(3.5));
 }
示例#5
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();
            }
        }