public static void Show(int duration, Size size, string imagePath, string url) { if (duration > 0 && !size.IsEmpty && !string.IsNullOrEmpty(imagePath) && Helpers.IsImageFile(imagePath) && File.Exists(imagePath)) { Image img = ImageHelpers.LoadImage(imagePath); NotificationForm form = new NotificationForm(duration, size, img, url); NativeMethods.ShowWindow(form.Handle, (int)WindowShowStyle.ShowNoActivate); NativeMethods.SetWindowPos(form.Handle, (IntPtr)SpecialWindowHandles.HWND_TOPMOST, 0, 0, 0, 0, SetWindowPosFlags.SWP_NOMOVE | SetWindowPosFlags.SWP_NOSIZE | SetWindowPosFlags.SWP_NOACTIVATE); } }
public static void Show(int duration, ContentAlignment placement, Size size, NotificationFormConfig config) { if (duration > 0 && size.Width > 0 && size.Height > 0) { config.Image = ImageHelpers.LoadImage(config.FilePath); if (config.Image != null || !string.IsNullOrEmpty(config.Text)) { NotificationForm form = new NotificationForm(duration, placement, size, config); NativeMethods.ShowWindow(form.Handle, (int)WindowShowStyle.ShowNoActivate); NativeMethods.SetWindowPos(form.Handle, (IntPtr)SpecialWindowHandles.HWND_TOPMOST, 0, 0, 0, 0, SetWindowPosFlags.SWP_NOMOVE | SetWindowPosFlags.SWP_NOSIZE | SetWindowPosFlags.SWP_NOACTIVATE); } } }
public static void Show(int duration, ContentAlignment placement, Size size, NotificationFormConfig config) { if (size.Width > 0 && size.Height > 0) { config.Image = ImageHelpers.LoadImage(config.FilePath); if (config.Image != null || !string.IsNullOrEmpty(config.Text)) { NotificationForm form = new NotificationForm(duration, placement, size, config); NativeMethods.ShowWindow(form.Handle, (int)WindowShowStyle.ShowNoActivate); } } }
private static void task_UploadCompleted(UploadTask task) { try { if (ListViewControl != null && task != null) { if (task.RequestSettingUpdate) { Program.MainForm.UpdateMainFormSettings(); } TaskInfo info = task.Info; if (info != null && info.Result != null) { ListViewItem lvi = FindListViewItem(task); if (info.Result.IsError) { string errors = string.Join("\r\n\r\n", info.Result.Errors.ToArray()); DebugHelper.WriteLine("Task failed. Filename: {0}, Errors:\r\n{1}", info.FileName, errors); if (lvi != null) { lvi.SubItems[1].Text = Resources.TaskManager_task_UploadCompleted_Error; lvi.SubItems[6].Text = string.Empty; lvi.ImageIndex = 1; } if (!info.TaskSettings.AdvancedSettings.DisableNotifications) { if (task.Info.TaskSettings.GeneralSettings.PlaySoundAfterUpload) { Helpers.PlaySoundAsync(Resources.ErrorSound); } if (info.TaskSettings.GeneralSettings.PopUpNotification != PopUpNotificationType.None && Program.MainForm.niTray.Visible) { Program.MainForm.niTray.ShowBalloonTip(5000, "ShareX - " + Resources.TaskManager_task_UploadCompleted_Error, errors, ToolTipIcon.Error); } } } else { DebugHelper.WriteLine("Task completed. Filename: {0}, URL: {1}, Duration: {2} ms", info.FileName, info.Result.ToString(), (int)info.UploadDuration.TotalMilliseconds); string result = info.Result.ToString(); if (string.IsNullOrEmpty(result) && !string.IsNullOrEmpty(info.FilePath)) { result = info.FilePath; } if (lvi != null) { lvi.Text = info.FileName; lvi.SubItems[1].Text = info.Status; lvi.ImageIndex = 2; if (!string.IsNullOrEmpty(result)) { lvi.SubItems[6].Text = result; } } if (!task.StopRequested && !string.IsNullOrEmpty(result)) { if (task.Info.TaskSettings.GeneralSettings.SaveHistory) { HistoryManager.AddHistoryItemAsync(Program.HistoryFilePath, info.GetHistoryItem()); } if (!info.TaskSettings.AdvancedSettings.DisableNotifications && info.Job != TaskJob.ShareURL) { if (task.Info.TaskSettings.GeneralSettings.PlaySoundAfterUpload) { Helpers.PlaySoundAsync(Resources.TaskCompletedSound); } if (!string.IsNullOrEmpty(info.TaskSettings.AdvancedSettings.BalloonTipContentFormat)) { result = new UploadInfoParser().Parse(info, info.TaskSettings.AdvancedSettings.BalloonTipContentFormat); } if (!string.IsNullOrEmpty(result)) { switch (info.TaskSettings.GeneralSettings.PopUpNotification) { case PopUpNotificationType.BalloonTip: if (Program.MainForm.niTray.Visible) { Program.MainForm.niTray.Tag = result; Program.MainForm.niTray.ShowBalloonTip(5000, "ShareX - " + Resources.TaskManager_task_UploadCompleted_ShareX___Task_completed, result, ToolTipIcon.Info); } break; case PopUpNotificationType.ToastNotification: NotificationFormConfig toastConfig = new NotificationFormConfig() { Action = info.TaskSettings.AdvancedSettings.ToastWindowClickAction, FilePath = info.FilePath, Text = "ShareX - " + Resources.TaskManager_task_UploadCompleted_ShareX___Task_completed + "\r\n" + result, URL = result }; NotificationForm.Show((int)(info.TaskSettings.AdvancedSettings.ToastWindowDuration * 1000), info.TaskSettings.AdvancedSettings.ToastWindowPlacement, info.TaskSettings.AdvancedSettings.ToastWindowSize, toastConfig); break; } } if (info.TaskSettings.GeneralSettings.ShowAfterUploadForm) { AfterUploadForm dlg = new AfterUploadForm(info); NativeMethods.ShowWindow(dlg.Handle, (int)WindowShowStyle.ShowNoActivate); } } } } if (lvi != null) { lvi.EnsureVisible(); } } } } finally { if (!IsBusy && Program.CLI.IsCommandExist("AutoClose")) { Application.Exit(); } else { StartTasks(); UpdateProgressUI(); } } }
public static void Show(int duration, ContentAlignment placement, Size size, string imagePath, string text, string url) { if (duration > 0 && !size.IsEmpty) { Image img = ImageHelpers.LoadImage(imagePath); if (img != null || !string.IsNullOrEmpty(text)) { NotificationForm form = new NotificationForm(duration, placement, size, img, text, url); NativeMethods.ShowWindow(form.Handle, (int)WindowShowStyle.ShowNoActivate); NativeMethods.SetWindowPos(form.Handle, (IntPtr)SpecialWindowHandles.HWND_TOPMOST, 0, 0, 0, 0, SetWindowPosFlags.SWP_NOMOVE | SetWindowPosFlags.SWP_NOSIZE | SetWindowPosFlags.SWP_NOACTIVATE); } } }
private static void Task_TaskCompleted(WorkerTask task) { try { task.KeepImage = false; if (task != null) { if (task.RequestSettingUpdate) { Program.MainForm.UpdateCheckStates(); } TaskInfo info = task.Info; if (info != null && info.Result != null) { TaskThumbnailPanel panel = TaskThumbnailView.FindPanel(task); if (panel != null) { panel.UpdateStatus(); panel.ProgressVisible = false; } ListViewItem lvi = TaskListView.FindItem(task); if (task.Status == TaskStatus.Stopped) { DebugHelper.WriteLine($"Task stopped. Filename: {info.FileName}"); if (lvi != null) { lvi.Text = info.FileName; lvi.SubItems[1].Text = info.Status; lvi.ImageIndex = 2; } } else if (task.Status == TaskStatus.Failed) { string errors = string.Join("\r\n\r\n", info.Result.Errors.ToArray()); DebugHelper.WriteLine($"Task failed. Filename: {info.FileName}, Errors:\r\n{errors}"); if (lvi != null) { lvi.SubItems[1].Text = info.Status; lvi.SubItems[6].Text = ""; lvi.ImageIndex = 1; } if (!info.TaskSettings.AdvancedSettings.DisableNotifications) { if (info.TaskSettings.GeneralSettings.PlaySoundAfterUpload) { TaskHelpers.PlayErrorSound(info.TaskSettings); } if (info.TaskSettings.GeneralSettings.PopUpNotification != PopUpNotificationType.None && !string.IsNullOrEmpty(errors) && (!info.TaskSettings.AdvancedSettings.DisableNotificationsOnFullscreen || !CaptureHelpers.IsActiveWindowFullscreen())) { TaskHelpers.ShowBalloonTip(errors, ToolTipIcon.Error, 5000, "ShareX - " + Resources.TaskManager_task_UploadCompleted_Error); } } } else { DebugHelper.WriteLine($"Task completed. Filename: {info.FileName}, Duration: {(long)info.TaskDuration.TotalMilliseconds} ms"); string result = info.Result.ToString(); if (string.IsNullOrEmpty(result) && !string.IsNullOrEmpty(info.FilePath)) { result = info.FilePath; } if (lvi != null) { lvi.Text = info.FileName; lvi.SubItems[1].Text = info.Status; lvi.ImageIndex = 2; if (!string.IsNullOrEmpty(result)) { lvi.SubItems[6].Text = result; } } if (!task.StopRequested && !string.IsNullOrEmpty(result)) { if (Program.Settings.HistorySaveTasks && (!Program.Settings.HistoryCheckURL || (!string.IsNullOrEmpty(info.Result.URL) || !string.IsNullOrEmpty(info.Result.ShortenedURL)))) { HistoryItem historyItem = info.GetHistoryItem(); AppendHistoryItemAsync(historyItem); } RecentManager.Add(task); if (!info.TaskSettings.AdvancedSettings.DisableNotifications && info.Job != TaskJob.ShareURL) { if (info.TaskSettings.GeneralSettings.PlaySoundAfterUpload) { TaskHelpers.PlayTaskCompleteSound(info.TaskSettings); } if (!string.IsNullOrEmpty(info.TaskSettings.AdvancedSettings.BalloonTipContentFormat)) { result = new UploadInfoParser().Parse(info, info.TaskSettings.AdvancedSettings.BalloonTipContentFormat); } if (!string.IsNullOrEmpty(result) && (!info.TaskSettings.AdvancedSettings.DisableNotificationsOnFullscreen || !CaptureHelpers.IsActiveWindowFullscreen())) { switch (info.TaskSettings.GeneralSettings.PopUpNotification) { case PopUpNotificationType.BalloonTip: BalloonTipAction action = new BalloonTipAction() { ClickAction = BalloonTipClickAction.OpenURL, Text = result }; TaskHelpers.ShowBalloonTip(result, ToolTipIcon.Info, 5000, "ShareX - " + Resources.TaskManager_task_UploadCompleted_ShareX___Task_completed, action); break; case PopUpNotificationType.ToastNotification: task.KeepImage = true; NotificationFormConfig toastConfig = new NotificationFormConfig() { LeftClickAction = info.TaskSettings.AdvancedSettings.ToastWindowClickAction, RightClickAction = info.TaskSettings.AdvancedSettings.ToastWindowRightClickAction, MiddleClickAction = info.TaskSettings.AdvancedSettings.ToastWindowMiddleClickAction, FilePath = info.FilePath, Image = task.Image, Text = "ShareX - " + Resources.TaskManager_task_UploadCompleted_ShareX___Task_completed + "\r\n" + result, URL = result }; NotificationForm.Show((int)(info.TaskSettings.AdvancedSettings.ToastWindowDuration * 1000), (int)(info.TaskSettings.AdvancedSettings.ToastWindowFadeDuration * 1000), info.TaskSettings.AdvancedSettings.ToastWindowPlacement, info.TaskSettings.AdvancedSettings.ToastWindowSize, toastConfig); break; } if (info.TaskSettings.AfterUploadJob.HasFlag(AfterUploadTasks.ShowAfterUploadWindow) && info.IsUploadJob) { AfterUploadForm dlg = new AfterUploadForm(info); NativeMethods.ShowWindow(dlg.Handle, (int)WindowShowStyle.ShowNoActivate); } } } } } if (lvi != null) { lvi.EnsureVisible(); if (Program.Settings.AutoSelectLastCompletedTask) { TaskListView.ListViewControl.SelectSingle(lvi); } } } } } finally { if (!IsBusy && Program.CLI.IsCommandExist("AutoClose")) { Application.Exit(); } else { StartTasks(); UpdateProgressUI(); if (Program.Settings.SaveSettingsAfterTaskCompleted && !IsBusy) { SettingManager.SaveAllSettingsAsync(); } } } }
private static void StartRecording(ScreenRecordOutput outputType, TaskSettings taskSettings, ScreenRecordStartMethod startMethod = ScreenRecordStartMethod.Region) { if (outputType == ScreenRecordOutput.GIF) { taskSettings.CaptureSettings.FFmpegOptions.VideoCodec = FFmpegVideoCodec.gif; } if (taskSettings.CaptureSettings.FFmpegOptions.IsAnimatedImage) { taskSettings.CaptureSettings.ScreenRecordTwoPassEncoding = true; } int fps; if (taskSettings.CaptureSettings.FFmpegOptions.VideoCodec == FFmpegVideoCodec.gif) { fps = taskSettings.CaptureSettings.GIFFPS; } else { fps = taskSettings.CaptureSettings.ScreenRecordFPS; } DebugHelper.WriteLine("Starting screen recording. Video encoder: \"{0}\", Audio encoder: \"{1}\", FPS: {2}", taskSettings.CaptureSettings.FFmpegOptions.VideoCodec.GetDescription(), taskSettings.CaptureSettings.FFmpegOptions.AudioCodec.GetDescription(), fps); if (!TaskHelpers.CheckFFmpeg(taskSettings)) { return; } if (!taskSettings.CaptureSettings.FFmpegOptions.IsSourceSelected) { MessageBox.Show(Resources.FFmpeg_FFmpeg_video_and_audio_source_both_can_t_be__None__, "ShareX - " + Resources.FFmpeg_FFmpeg_error, MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (taskSettings.GeneralSettings.ToastWindowAutoHide) { NotificationForm.CloseActiveForm(); } Rectangle captureRectangle = Rectangle.Empty; TaskMetadata metadata = new TaskMetadata(); switch (startMethod) { case ScreenRecordStartMethod.Region: if (taskSettings.CaptureSettings.ScreenRecordTransparentRegion) { RegionCaptureTasks.GetRectangleRegionTransparent(out captureRectangle); } else { RegionCaptureTasks.GetRectangleRegion(out captureRectangle, out WindowInfo windowInfo, taskSettings.CaptureSettings.SurfaceOptions); metadata.UpdateInfo(windowInfo); } break; case ScreenRecordStartMethod.ActiveWindow: if (taskSettings.CaptureSettings.CaptureClientArea) { captureRectangle = CaptureHelpers.GetActiveWindowClientRectangle(); } else { captureRectangle = CaptureHelpers.GetActiveWindowRectangle(); } break; case ScreenRecordStartMethod.CustomRegion: captureRectangle = taskSettings.CaptureSettings.CaptureCustomRegion; break; case ScreenRecordStartMethod.LastRegion: captureRectangle = Program.Settings.ScreenRecordRegion; break; } Rectangle screenRectangle = CaptureHelpers.GetScreenBounds(); captureRectangle = Rectangle.Intersect(captureRectangle, screenRectangle); if (taskSettings.CaptureSettings.FFmpegOptions.IsEvenSizeRequired) { captureRectangle = CaptureHelpers.EvenRectangleSize(captureRectangle); } if (IsRecording || !captureRectangle.IsValid() || screenRecorder != null) { return; } Program.Settings.ScreenRecordRegion = captureRectangle; IsRecording = true; string path = ""; bool abortRequested = false; float duration = taskSettings.CaptureSettings.ScreenRecordFixedDuration ? taskSettings.CaptureSettings.ScreenRecordDuration : 0; recordForm = new ScreenRecordForm(captureRectangle) { ActivateWindow = startMethod == ScreenRecordStartMethod.Region, Duration = duration, AskConfirmationOnAbort = taskSettings.CaptureSettings.ScreenRecordAskConfirmationOnAbort }; recordForm.StopRequested += StopRecording; recordForm.Show(); Task.Run(() => { try { string extension; if (taskSettings.CaptureSettings.ScreenRecordTwoPassEncoding) { extension = "mp4"; } else { extension = taskSettings.CaptureSettings.FFmpegOptions.Extension; } string screenshotsFolder = TaskHelpers.GetScreenshotsFolder(taskSettings, metadata); string fileName = TaskHelpers.GetFileName(taskSettings, extension, metadata); path = TaskHelpers.HandleExistsFile(screenshotsFolder, fileName, taskSettings); if (string.IsNullOrEmpty(path)) { abortRequested = true; } if (!abortRequested) { recordForm.ChangeState(ScreenRecordState.BeforeStart); if (taskSettings.CaptureSettings.ScreenRecordAutoStart) { int delay = (int)(taskSettings.CaptureSettings.ScreenRecordStartDelay * 1000); if (delay > 0) { recordForm.InvokeSafe(() => recordForm.StartCountdown(delay)); recordForm.RecordResetEvent.WaitOne(delay); } } else { recordForm.RecordResetEvent.WaitOne(); } if (recordForm.IsAbortRequested) { abortRequested = true; } if (!abortRequested) { ScreenRecordingOptions options = new ScreenRecordingOptions() { IsRecording = true, IsLossless = taskSettings.CaptureSettings.ScreenRecordTwoPassEncoding, FFmpeg = taskSettings.CaptureSettings.FFmpegOptions, FPS = fps, Duration = duration, OutputPath = path, CaptureArea = captureRectangle, DrawCursor = taskSettings.CaptureSettings.ScreenRecordShowCursor }; Screenshot screenshot = TaskHelpers.GetScreenshot(taskSettings); screenshot.CaptureCursor = taskSettings.CaptureSettings.ScreenRecordShowCursor; screenRecorder = new ScreenRecorder(ScreenRecordOutput.FFmpeg, options, screenshot, captureRectangle); screenRecorder.RecordingStarted += ScreenRecorder_RecordingStarted; screenRecorder.EncodingProgressChanged += ScreenRecorder_EncodingProgressChanged; recordForm.ChangeState(ScreenRecordState.AfterStart); screenRecorder.StartRecording(); if (recordForm.IsAbortRequested) { abortRequested = true; } } } } catch (Exception e) { DebugHelper.WriteException(e); } if (taskSettings.CaptureSettings.ScreenRecordTwoPassEncoding && !abortRequested && screenRecorder != null && File.Exists(path)) { recordForm.ChangeState(ScreenRecordState.Encoding); path = ProcessTwoPassEncoding(path, metadata, taskSettings); } if (recordForm != null) { recordForm.InvokeSafe(() => { recordForm.Close(); recordForm.Dispose(); recordForm = null; }); } if (screenRecorder != null) { screenRecorder.Dispose(); screenRecorder = null; if (abortRequested && !string.IsNullOrEmpty(path) && File.Exists(path)) { File.Delete(path); } } }).ContinueInCurrentContext(() => { if (!abortRequested && !string.IsNullOrEmpty(path) && File.Exists(path) && TaskHelpers.ShowAfterCaptureForm(taskSettings, out string customFileName, null, path)) { if (!string.IsNullOrEmpty(customFileName)) { string currentFileName = Path.GetFileNameWithoutExtension(path); string ext = Path.GetExtension(path); if (!currentFileName.Equals(customFileName, StringComparison.InvariantCultureIgnoreCase)) { path = Helpers.RenameFile(path, customFileName + ext); } } WorkerTask task = WorkerTask.CreateFileJobTask(path, metadata, taskSettings, customFileName); TaskManager.Start(task); } abortRequested = false; IsRecording = false; }); }
private static void task_UploadCompleted(UploadTask task) { try { if (ListViewControl != null && task != null) { if (task.RequestSettingUpdate) { Program.MainForm.UpdateMainFormSettings(); } TaskInfo info = task.Info; if (info != null && info.Result != null) { ListViewItem lvi = FindListViewItem(task); if (info.Result.IsError) { string errors = string.Join("\r\n\r\n", info.Result.Errors.ToArray()); DebugHelper.WriteLine("Task failed. Filename: {0}, Errors:\r\n{1}", info.FileName, errors); if (lvi != null) { lvi.SubItems[1].Text = "Error"; lvi.SubItems[8].Text = string.Empty; lvi.ImageIndex = 1; } if (task.Info.TaskSettings.GeneralSettings.PlaySoundAfterUpload) { SystemSounds.Asterisk.Play(); } } else { DebugHelper.WriteLine("Task completed. Filename: {0}, URL: {1}, Duration: {2} ms", info.FileName, info.Result.ToString(), (int)info.UploadDuration.TotalMilliseconds); string result = info.Result.ToString(); if (string.IsNullOrEmpty(result) && !string.IsNullOrEmpty(info.FilePath)) { result = info.FilePath; } if (lvi != null) { lvi.Text = info.FileName; lvi.SubItems[1].Text = info.Status; lvi.ImageIndex = 2; if (!string.IsNullOrEmpty(result)) { lvi.SubItems[8].Text = result; } } if (!task.IsStopped && !string.IsNullOrEmpty(result)) { if (task.Info.TaskSettings.GeneralSettings.SaveHistory) { HistoryManager.AddHistoryItemAsync(Program.HistoryFilePath, info.GetHistoryItem()); } if (!info.TaskSettings.AdvancedSettings.DisableNotifications) { if (task.Info.TaskSettings.GeneralSettings.PlaySoundAfterUpload) { SystemSounds.Exclamation.Play(); } string balloonTipText = result; if (!string.IsNullOrEmpty(info.TaskSettings.AdvancedSettings.BalloonTipContentFormat)) { balloonTipText = new UploadInfoParser().Parse(info, info.TaskSettings.AdvancedSettings.BalloonTipContentFormat); } if (!string.IsNullOrEmpty(balloonTipText)) { if (task.Info.TaskSettings.GeneralSettings.TrayBalloonTipAfterUpload && Program.MainForm.niTray.Visible) { Program.MainForm.niTray.Tag = result; Program.MainForm.niTray.ShowBalloonTip(5000, "ShareX - Task completed", balloonTipText, ToolTipIcon.Info); } if (task.Info.TaskSettings.GeneralSettings.ShowToastWindowAfterTask) { NotificationForm.Show((int)(task.Info.TaskSettings.AdvancedSettings.ToastWindowDuration * 1000), task.Info.TaskSettings.AdvancedSettings.ToastWindowSize, info.FilePath, result); } } if (info.TaskSettings.GeneralSettings.ShowAfterUploadForm) { AfterUploadForm dlg = new AfterUploadForm(info); NativeMethods.ShowWindow(dlg.Handle, (int)WindowShowStyle.ShowNoActivate); } } } } if (lvi != null) { lvi.EnsureVisible(); } } } } finally { StartTasks(); UpdateProgressUI(); } }