public static async Task FinishGif(Stream stream, string hwndName) { try { //Set Stream Position to beginning stream.Position = 0; bool wasSaved = false; Action clickAction = null; //Config: Save GIF locally? if (ConfigHelper.SaveImages) { try { //Save File with unique name long time = DateTime.Now.ToFileTimeUtc(); string filename = Path.Combine(ConfigHelper.SaveImagesPath, $"Snipe_{time}.gif"); using (FileStream fstream = new FileStream(filename, FileMode.OpenOrCreate, FileAccess.Write)) { await stream.CopyToAsync(fstream); } wasSaved = true; clickAction = () => { Process.Start(filename); }; if (ConfigHelper.OpenFileAfterSnap) { //Open Explorer and Highlight Image Process.Start("explorer.exe", $"/select, \"{filename}\""); } } catch { // could not start process } } //Config: Upload GIF to Imgur or Copy to Clipboard? switch (ConfigHelper.AfterSnipeAction) { case AfterSnipe.CopyClipboard: //Copy Binary GIF to Clipboard //TODO: Remove? GIFs cant be copied to clipboard await ClipboardHelper.CopyImage(stream, wasSaved, true); break; case AfterSnipe.DoNothing: //Do nothing (just save file e.g.) if (wasSaved) { await ShowNotificationAsync(strings.savedToFile, NotificationType.Success, clickAction); } break; case AfterSnipe.UploadImgur: //Upload image to imgur and copy link string link = await UploadImgur(stream, hwndName, true); await ClipboardHelper.CopyLink(link, wasSaved); break; } } catch (Exception ex) { await ShowNotificationAsync(strings.errorMsg, NotificationType.Error, ActionTroubleshoot); Helpers.WriteError(ex); } }
public static async Task FinishScreenshot(Stream stream, string hwndName) { try { //Set Stream Position to beginning stream.Position = 0; bool wasSaved = false; //Config: Save Image locally? if (ConfigHelper.SaveImages) { try { //Save File with unique name long time = DateTime.Now.ToFileTimeUtc(); string extension = "." + ConfigHelper.ImageFormat.ToString().ToLower(); string filename = Path.Combine(ConfigHelper.SaveImagesPath, $"Snipe_{time}{extension}"); using (FileStream fstream = new FileStream(filename, FileMode.OpenOrCreate, FileAccess.Write)) { await stream.CopyToAsync(fstream); } wasSaved = true; if (ConfigHelper.OpenFileAfterSnap) { //Open Explorer and Highlight Image Process.Start("explorer.exe", $"/select, \"{filename}\""); } } catch { // could not start process } } //Config: Upload Image to Imgur or Copy to Clipboard? switch (ConfigHelper.AfterSnipeAction) { case AfterSnipe.CopyClipboard: //Copy Binary Image to Clipboard await ClipboardHelper.CopyImage(stream, wasSaved, false); break; case AfterSnipe.DoNothing: //Do nothing (just save file e.g.) if (wasSaved) { await ShowNotificationAsync(strings.savedToFile, NotificationType.Success); } break; case AfterSnipe.UploadImgur: //Upload image to imgur and copy link string link = await UploadImgur(stream, hwndName, false); await ClipboardHelper.CopyLink(link, wasSaved); break; } } catch (Exception ex) { await ShowNotificationAsync(strings.errorMsg, NotificationType.Error, ActionTroubleshoot); MessageBox.Show(string.Format(strings.otherErrorMsg, ex.Message), strings.errorMsg); } }