示例#1
0
        private async void StartWithArguments()
        {
            CommandlineArgs args = CommandLineHelper.GetCommandlineArguments();

            switch (args.Argument)
            {
            case CommandLineHelper.Argument.Autostart:
                //Tray with Hotkeys
                await StartTray.Initialize(this);

                break;

            case CommandLineHelper.Argument.Gif:
                //GIF Recording Capture
                using (GifWindow window = new GifWindow())
                    window.ShowDialog();
                break;

            case CommandLineHelper.Argument.Snipe:
                //Normal Image Capture
                using (ScreenshotWindow window = new ScreenshotWindow())
                    window.ShowDialog();
                break;

            case CommandLineHelper.Argument.Upload:
                //Context Menu Instant Upload
                if (args.UploadFiles.Count > 1)
                {
                    //1 or more files
                    //TODO: Implement "%1" more than 1
                    await StartUpload.UploadMultiple(args.UploadFiles);
                }
                else if (args.UploadFiles.Count == 1)
                {
                    //1 File
                    await StartUpload.UploadSingle(args.UploadFiles[0]);
                }
                else
                {
                    //No Image File detected
                    await Statics.ShowNotificationAsync(Properties.strings.notAnImage, NotificationWindow.NotificationType.Error);
                }
                break;
            }

            //Wait for every Notification to close
            if (NotificationWindow.IsShown)
            {
                await Task.Delay(NotificationWindow.ShowDuration);
            }

            Application.Current.Shutdown();
        }
示例#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();
            }
        }
示例#3
0
        //Open Image Capture Window
        private async Task CaptureImage()
        {
            using (ScreenshotWindow window = new ScreenshotWindow(FileIO.AllMonitors)) {
                window.ShowDialog();

                if (window.DialogResult == true)
                {
                    //10 MB = 10.485.760 Bytes      => Imgur's max. File Size
                    if (window.CroppedImage.Length >= 10485760)
                    {
                        Notification = new Notification(strings.imgTooBig, Notification.NotificationType.Error, true,
                                                        ActionTroubleshoot);
                        await Notification.ShowAsync();

                        //await ErrorToast.ShowAsync(strings.imgToBig, TimeSpan.FromSeconds(3));
                        return;
                    }

                    try {
                        bool imgurAfterSnipe = FileIO.ImgurAfterSnipe;

                        //Config: Save Image locally?
                        if (FileIO.SaveImages)
                        {
                            try {
                                //Save File with unique name
                                long   time      = DateTime.Now.ToFileTimeUtc();
                                string extension = "." + FileIO.ImageFormat.ToString().ToLower();
                                string filename  = _dir + $"\\Snipe_{time}{extension}";
                                File.WriteAllBytes(filename, window.CroppedImage);

                                if (FileIO.OpenAfterUpload)
                                {
                                    //If name contains Spaces, Arguments get seperated by the Space
                                    if (filename.Contains(" "))
                                    {
                                        //Open Image itself
                                        Process.Start(filename);
                                    }
                                    else
                                    {
                                        //Open Explorer and Highlight Image
                                        Process.Start("explorer.exe", $"/select,\"{filename}\"");
                                    }
                                }
                            } catch {
                                // ignored
                            }
                        }

                        //Config: Upload Image to Imgur or Copy to Clipboard?
                        if (imgurAfterSnipe)
                        {
                            string kb = $"{window.CroppedImage.Length / 1024d:0.#}";
                            Notification = new Notification(string.Format(strings.uploading, kb),
                                                            Notification.NotificationType.Progress, false, null);
                            Notification.Show();
                            //SuccessToast.Show(string.Format(strings.uploading, kb), TimeSpan.FromDays(10));

                            string link = await _imgur.Upload(window.CroppedImage, window.HwndName);
                            await HandleLink(link);

                            Notification.Close();
                        }
                        else
                        {
                            CopyClipboard(window.CroppedImage);

                            Notification = new Notification(strings.imgclipboard, Notification.NotificationType.Success,
                                                            true, null);
                            await Notification.ShowAsync();

                            //await SuccessToast.ShowAsync(strings.imgclipboard, TimeSpan.FromSeconds(3));
                        }
                    } catch (Exception ex) {
                        Notification = new Notification(strings.errorMsg, Notification.NotificationType.Error, true,
                                                        ActionTroubleshoot);
                        await Notification.ShowAsync();

                        MessageBox.Show(string.Format(strings.otherErrorMsg, ex.Message),
                                        strings.errorMsg);
                        //ErrorToast.Show(string.Format(strings.otherErrorMsg, ex),
                        //    TimeSpan.FromSeconds(3.5));
                    }
                }
                else
                {
                    if (window.Error)
                    {
                        Notification = new Notification(strings.uploadingErrorGif, Notification.NotificationType.Error,
                                                        true,
                                                        ActionTroubleshoot);
                        await Notification.ShowAsync();
                    }
                }
            }

            Notification = null;
            GC.Collect();
        }