Example #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();
        }
Example #2
0
        //Open GIF Capture Window
        private async Task CaptureGif()
        {
            using (GifWindow window = new GifWindow(FileIO.AllMonitors)) {
                window.ShowDialog();

                if (window.DialogResult == true)
                {
                    //10 MB = 10.485.760 Bytes      => Imgur's max. File Size
                    if (window.CroppedGif.Length >= 10485760)
                    {
                        Notification = new Notification(strings.imgTooBigGif, 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 filename = _dir + $"\\Snipe_{time}.gif";
                                File.WriteAllBytes(filename, window.CroppedGif);

                                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.CroppedGif.Length / 1024d:0.#}";
                            Notification = new Notification(string.Format(strings.uploadingGif, kb),
                                                            Notification.NotificationType.Progress, false, null);
                            Notification.Show();
                            //SuccessToast.Show(string.Format(strings.uploading, kb), TimeSpan.FromDays(10));

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

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

                            Notification = new Notification(strings.imgclipboardGif,
                                                            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();
        }