public void CaptureScreenshot(CaptureType captureType, TaskSettings taskSettings = null, bool autoHideForm = true) { if (taskSettings == null) taskSettings = TaskSettings.GetDefaultTaskSettings(); switch (captureType) { case CaptureType.Screen: DoCapture(Screenshot.CaptureFullscreen, CaptureType.Screen, taskSettings, autoHideForm); break; case CaptureType.ActiveWindow: CaptureActiveWindow(taskSettings, autoHideForm); break; case CaptureType.ActiveMonitor: DoCapture(Screenshot.CaptureActiveMonitor, CaptureType.ActiveMonitor, taskSettings, autoHideForm); break; case CaptureType.Rectangle: case CaptureType.RectangleWindow: case CaptureType.RoundedRectangle: case CaptureType.Ellipse: case CaptureType.Triangle: case CaptureType.Diamond: case CaptureType.Polygon: case CaptureType.Freehand: CaptureRegion(captureType, taskSettings, autoHideForm); break; case CaptureType.LastRegion: CaptureLastRegion(taskSettings, autoHideForm); break; } }
public HotkeySettings(HotkeyType job, Keys hotkey = Keys.None) : this() { TaskSettings = TaskSettings.GetDefaultTaskSettings(); TaskSettings.Job = job; HotkeyInfo = new HotkeyInfo(hotkey); }
public static void CaptureScreenshot(CaptureType captureType, TaskSettings taskSettings = null, bool autoHideForm = true) { if (taskSettings == null) taskSettings = TaskSettings.GetDefaultTaskSettings(); switch (captureType) { case CaptureType.Fullscreen: DoCapture(TaskHelpers.GetScreenshot(taskSettings).CaptureFullscreen, CaptureType.Fullscreen, taskSettings, autoHideForm); break; case CaptureType.ActiveWindow: CaptureActiveWindow(taskSettings, autoHideForm); break; case CaptureType.ActiveMonitor: DoCapture(TaskHelpers.GetScreenshot(taskSettings).CaptureActiveMonitor, CaptureType.ActiveMonitor, taskSettings, autoHideForm); break; case CaptureType.Region: CaptureRegion(taskSettings, autoHideForm); break; case CaptureType.CustomRegion: CaptureCustomRegion(taskSettings, autoHideForm); break; case CaptureType.LastRegion: CaptureLastRegion(taskSettings, autoHideForm); break; } }
public static void ClipboardUpload(TaskSettings taskSettings = null) { if (taskSettings == null) taskSettings = TaskSettings.GetDefaultTaskSettings(); if (Clipboard.ContainsImage()) { Image img = Clipboard.GetImage(); if (!taskSettings.AdvancedSettings.ProcessImagesDuringClipboardUpload) { taskSettings.AfterCaptureJob = AfterCaptureTasks.UploadImageToHost; } RunImageTask(img, taskSettings); } else if (Clipboard.ContainsFileDropList()) { string[] files = Clipboard.GetFileDropList().Cast<string>().ToArray(); UploadFile(files, taskSettings); } else if (Clipboard.ContainsText()) { string text = Clipboard.GetText(); if (taskSettings.UploadSettings.ClipboardUploadAutoDetectURL && Helpers.IsValidURLRegex(text)) { ShortenURL(text.Trim(), taskSettings); } else { UploadText(text, taskSettings); } } }
public ScreenColorPicker(TaskSettings taskSettings) { if (taskSettings != null) { surfaceOptions = taskSettings.CaptureSettings.SurfaceOptions; } else { surfaceOptions = new SurfaceOptions(); } InitializeComponent(); colorPicker.DrawCrosshair = true; colorTimer.Tick += colorTimer_Tick; UpdateControls(true); foreach (Control control in Controls) { if (control is NumericUpDown || control is TextBox) { control.DoubleClick += CopyToClipboard; } } }
public override void Capture(CaptureType captureType, TaskSettings taskSettings, bool autoHideForm = true) { DoCapture(() => { Image img; string activeWindowTitle = NativeMethods.GetForegroundWindowText(); string activeProcessName = null; using (Process process = NativeMethods.GetForegroundWindowProcess()) { if (process != null) { activeProcessName = process.ProcessName; } } if (taskSettings.CaptureSettings.CaptureTransparent && !taskSettings.CaptureSettings.CaptureClientArea) { img = Screenshot.CaptureActiveWindowTransparent(); } else { img = Screenshot.CaptureActiveWindow(); } img.Tag = new ImageTag { ActiveWindowTitle = activeWindowTitle, ActiveProcessName = activeProcessName }; return img; }, CaptureType.ActiveWindow, taskSettings, autoHideForm); }
private static Image ResizeImage(TaskSettings taskSettings, Image img, ImageScaleType scaleType) { float width = 0, height = 0; switch (scaleType) { case ImageScaleType.Percentage: width = img.Width * (taskSettings.ImageSettings.ImageScalePercentageWidth / 100f); height = img.Height * (taskSettings.ImageSettings.ImageScalePercentageHeight / 100f); break; case ImageScaleType.Width: width = taskSettings.ImageSettings.ImageScaleToWidth; height = taskSettings.ImageSettings.ImageKeepAspectRatio ? img.Height * (width / img.Width) : img.Height; break; case ImageScaleType.Height: height = taskSettings.ImageSettings.ImageScaleToHeight; width = taskSettings.ImageSettings.ImageKeepAspectRatio ? img.Width * (height / img.Height) : img.Width; break; case ImageScaleType.Specific: width = taskSettings.ImageSettings.ImageScaleSpecificWidth; height = taskSettings.ImageSettings.ImageScaleSpecificHeight; break; } if (width > 0 && height > 0) { return CaptureHelpers.ResizeImage(img, (int)width, (int)height, taskSettings.ImageSettings.ImageUseSmoothScaling); } return img; }
public static ImageData PrepareImage(Image img, TaskSettings taskSettings) { ImageData imageData = new ImageData(); imageData.ImageFormat = taskSettings.ImageSettings.ImageFormat; if (taskSettings.ImageSettings.ImageFormat == EImageFormat.JPEG) { img = ImageHelpers.FillBackground(img, Color.White); } imageData.ImageStream = SaveImage(img, taskSettings.ImageSettings.ImageFormat, taskSettings); int sizeLimit = taskSettings.ImageSettings.ImageSizeLimit * 1000; if (taskSettings.ImageSettings.ImageFormat != taskSettings.ImageSettings.ImageFormat2 && sizeLimit > 0 && imageData.ImageStream.Length > sizeLimit) { if (taskSettings.ImageSettings.ImageFormat2 == EImageFormat.JPEG) { img = ImageHelpers.FillBackground(img, Color.White); } imageData.ImageStream = SaveImage(img, taskSettings.ImageSettings.ImageFormat2, taskSettings); imageData.ImageFormat = taskSettings.ImageSettings.ImageFormat2; } return imageData; }
public HotkeySettings(HotkeyType job, Keys hotkey = Keys.None) : this() { TaskSettings = TaskSettings.GetDefaultTaskSettings(); TaskSettings.Job = job; TaskSettings.Description = job.GetDescription(); HotkeyInfo = new HotkeyInfo { Hotkey = hotkey }; }
private void SelectRegion(TaskSettings taskSettings) { Rectangle rect; if (TaskHelper.SelectRegion(taskSettings, out rect) && !rect.IsEmpty) { CaptureRectangle = Helpers.EvenRectangleSize(rect); } }
public static UploadTask CreateDataUploaderTask(EDataType dataType, Stream stream, string fileName, TaskSettings taskSettings) { UploadTask task = new UploadTask(taskSettings); task.Info.Job = TaskJob.DataUpload; task.Info.DataType = dataType; task.Info.FileName = fileName; task.Data = stream; return task; }
public static void ClipboardUpload(TaskSettings taskSettings = null) { if (taskSettings == null) taskSettings = TaskSettings.GetDefaultTaskSettings(); if (Clipboard.ContainsImage()) { Image img = Clipboard.GetImage(); if (img != null) { if (!taskSettings.AdvancedSettings.ProcessImagesDuringClipboardUpload) { taskSettings.AfterCaptureJob = AfterCaptureTasks.UploadImageToHost; } RunImageTask(img, taskSettings); } } else if (Clipboard.ContainsFileDropList()) { string[] files = Clipboard.GetFileDropList().Cast<string>().ToArray(); UploadFile(files, taskSettings); } else if (Clipboard.ContainsText()) { string text = Clipboard.GetText(); if (!string.IsNullOrEmpty(text)) { string url = text.Trim(); if (URLHelpers.IsValidURLRegex(url)) { if (taskSettings.UploadSettings.ClipboardUploadURLContents) { DownloadAndUploadFile(url, taskSettings); return; } if (taskSettings.UploadSettings.ClipboardUploadShortenURL) { ShortenURL(url, taskSettings); return; } if (taskSettings.UploadSettings.ClipboardUploadShareURL) { ShareURL(url, taskSettings); return; } } UploadText(text, taskSettings, true); } } }
public override void Capture(CaptureType captureType, TaskSettings taskSettings, bool autoHideForm = true) { DoCapture(() => { Rectangle regionBounds = taskSettings.CaptureSettings.CaptureCustomRegion; Image img = Screenshot.CaptureRectangle(regionBounds); return img; }, CaptureType.CustomRegion, taskSettings, autoHideForm); }
public AfterCaptureForm(string filePath, TaskSettings taskSettings) : this(taskSettings) { if (Helpers.IsImageFile(filePath)) { pbImage.LoadImageFromFileAsync(filePath); } FileName = Path.GetFileNameWithoutExtension(filePath); txtFileName.Text = FileName; }
public TaskInfo(TaskSettings taskSettings) { if (taskSettings == null) { taskSettings = TaskSettings.GetDefaultTaskSettings(); } TaskSettings = taskSettings; Result = new UploadResult(); }
public AfterCaptureForm(Image img, TaskSettings taskSettings) : this(taskSettings) { if (img != null) { pbImage.LoadImage(img); btnCopy.Enabled = true; } FileName = TaskHelpers.GetFilename(TaskSettings, null, img); txtFileName.Text = FileName; }
public static DropForm GetInstance(int size, int offset, ContentAlignment alignment, int opacity, int hoverOpacity, TaskSettings taskSettings = null) { if (instance == null || instance.IsDisposed) { instance = new DropForm(size, offset, alignment, opacity, hoverOpacity); } instance.taskSettings = taskSettings; return instance; }
public static void StartStopRecording(ScreenRecordOutput outputType, ScreenRecordStartMethod startMethod, TaskSettings taskSettings) { if (IsRecording) { if (recordForm != null && !recordForm.IsDisposed) { recordForm.StartStopRecording(); } } else { StartRecording(outputType, taskSettings, startMethod); } }
public static void AddDefaultExternalPrograms(TaskSettings taskSettings) { if (taskSettings.ExternalPrograms == null) { taskSettings.ExternalPrograms = new List<ExternalProgram>(); } AddExternalProgramFromRegistry(taskSettings, "Paint", "mspaint.exe"); AddExternalProgramFromRegistry(taskSettings, "Paint.NET", "PaintDotNet.exe"); AddExternalProgramFromRegistry(taskSettings, "Adobe Photoshop", "Photoshop.exe"); AddExternalProgramFromRegistry(taskSettings, "IrfanView", "i_view32.exe"); AddExternalProgramFromRegistry(taskSettings, "XnView", "xnview.exe"); AddExternalProgramFromFile(taskSettings, "OptiPNG", "optipng.exe"); }
public static void UploadFile(string[] files, TaskSettings taskSettings = null) { if (taskSettings == null) taskSettings = TaskSettings.GetDefaultTaskSettings(); if (files != null && files.Length > 0) { if (files.Length <= 10 || IsUploadConfirmed(files.Length)) { foreach (string file in files) { UploadFile(file, taskSettings); } } } }
public AfterCaptureForm(Image img, TaskSettings taskSettings) { InitializeComponent(); Icon = ShareXResources.Icon; ImageList imageList = new ImageList { ColorDepth = ColorDepth.Depth32Bit }; imageList.Images.Add(Resources.checkbox_uncheck); imageList.Images.Add(Resources.checkbox_check); lvAfterCaptureTasks.SmallImageList = imageList; ucBeforeUpload.InitCapture(taskSettings); AfterCaptureTasks = taskSettings.AfterCaptureJob; AddAfterCaptureItems(AfterCaptureTasks); pbImage.LoadImage(img); }
private AfterCaptureForm(TaskSettings taskSettings) { TaskSettings = taskSettings; InitializeComponent(); Icon = ShareXResources.Icon; ImageList imageList = new ImageList { ColorDepth = ColorDepth.Depth32Bit }; imageList.Images.Add(Resources.checkbox_uncheck); imageList.Images.Add(Resources.checkbox_check); lvAfterCaptureTasks.SmallImageList = imageList; lvAfterUploadTasks.SmallImageList = imageList; ucBeforeUpload.InitCapture(TaskSettings); AddAfterCaptureItems(TaskSettings.AfterCaptureJob); AddAfterUploadItems(TaskSettings.AfterUploadJob); }
public static void UploadFile(string filePath, TaskSettings taskSettings = null) { if (taskSettings == null) taskSettings = TaskSettings.GetDefaultTaskSettings(); if (!string.IsNullOrEmpty(filePath)) { if (File.Exists(filePath)) { UploadTask task = UploadTask.CreateFileUploaderTask(filePath, taskSettings); TaskManager.Start(task); } else if (Directory.Exists(filePath)) { string[] files = Directory.GetFiles(filePath, "*.*", SearchOption.AllDirectories); UploadFile(files, taskSettings); } } }
public static Image AddImageEffects(Image img, TaskSettings taskSettings) { if (taskSettings.ImageSettings.ShowImageEffectsWindowAfterCapture) { using (ImageEffectsForm imageEffectsForm = new ImageEffectsForm(img, taskSettings.ImageSettings.ImageEffects)) { if (imageEffectsForm.ShowDialog() == DialogResult.OK) { taskSettings.ImageSettings.ImageEffects = imageEffectsForm.Effects; } } } using (img) { return ImageEffectManager.ApplyEffects(img, taskSettings.ImageSettings.ImageEffects); } }
private void ActiveWindowRegion(TaskSettings taskSettings) { IntPtr handle = NativeMethods.GetForegroundWindow(); if (handle.ToInt32() > 0) { if (taskSettings.CaptureSettings.CaptureClientArea) { captureRectangle = NativeMethods.GetClientRect(handle); } else { captureRectangle = CaptureHelpers.GetWindowRectangle(handle); } } else { SelectRegion(); } }
public static void ClipboardUploadMainWindow(TaskSettings taskSettings = null) { if (taskSettings == null) taskSettings = TaskSettings.GetDefaultTaskSettings(); if (Program.Settings.ShowClipboardContentViewer) { using (ClipboardContentViewer ccv = new ClipboardContentViewer(true)) { if (ccv.ShowDialog() == DialogResult.OK && !ccv.IsClipboardEmpty) { ClipboardUpload(taskSettings); } Program.Settings.ShowClipboardContentViewer = !ccv.DontShowThisWindow; } } else { ClipboardUpload(taskSettings); } }
public static void DoCapture(ScreenCaptureDelegate capture, CaptureType captureType, TaskSettings taskSettings = null, bool autoHideForm = true) { if (taskSettings == null) taskSettings = TaskSettings.GetDefaultTaskSettings(); if (taskSettings.CaptureSettings.IsDelayScreenshot && taskSettings.CaptureSettings.DelayScreenshot > 0) { TaskEx.Run(() => { int sleep = (int)(taskSettings.CaptureSettings.DelayScreenshot * 1000); Thread.Sleep(sleep); }, () => { DoCaptureWork(capture, captureType, taskSettings, autoHideForm); }); } else { DoCaptureWork(capture, captureType, taskSettings, autoHideForm); } }
public static string CreateThumbnail(Image img, string folder, string filename, TaskSettings taskSettings) { if ((taskSettings.ImageSettings.ThumbnailWidth > 0 || taskSettings.ImageSettings.ThumbnailHeight > 0) && (!taskSettings.ImageSettings.ThumbnailCheckSize || (img.Width > taskSettings.ImageSettings.ThumbnailWidth && img.Height > taskSettings.ImageSettings.ThumbnailHeight))) { string thumbnailFileName = Path.GetFileNameWithoutExtension(filename) + taskSettings.ImageSettings.ThumbnailName + ".jpg"; string thumbnailFilePath = CheckFilePath(folder, thumbnailFileName, taskSettings); if (!string.IsNullOrEmpty(thumbnailFilePath)) { Image thumbImage = null; try { thumbImage = (Image)img.Clone(); thumbImage = new Resize { Width = taskSettings.ImageSettings.ThumbnailWidth, Height = taskSettings.ImageSettings.ThumbnailHeight }.Apply(thumbImage); thumbImage = ImageHelpers.FillBackground(thumbImage, Color.White); thumbImage.SaveJPG(thumbnailFilePath, 90); return thumbnailFilePath; } catch (Exception e) { DebugHelper.WriteException(e); } finally { if (thumbImage != null) { thumbImage.Dispose(); } } } } return null; }
protected void AfterCapture(Image img, CaptureType captureType, TaskSettings taskSettings) { if (img != null) { if (taskSettings.GeneralSettings.PlaySoundAfterCapture) { TaskHelpers.PlayCaptureSound(taskSettings); } if (taskSettings.ImageSettings.ImageEffectOnlyRegionCapture && !IsRegionCapture(captureType)) { taskSettings.AfterCaptureJob = taskSettings.AfterCaptureJob.Remove(AfterCaptureTasks.AddImageEffects); } string customFileName; if (TaskHelpers.ShowAfterCaptureForm(taskSettings, out customFileName, img)) { UploadManager.RunImageTask(img, taskSettings, customFileName); } } }
private void btnRegion_Click(object sender, EventArgs e) { TaskSettings taskSettings = TaskSettings.GetDefaultTaskSettings(); SelectRegion(taskSettings); }
private void SetDefaultSettings() { if (Program.DefaultTaskSettings != null) { TaskSettings defaultTaskSettings = Program.DefaultTaskSettings.Copy(); if (UseDefaultAfterCaptureJob) { AfterCaptureJob = defaultTaskSettings.AfterCaptureJob; } if (UseDefaultAfterUploadJob) { AfterUploadJob = defaultTaskSettings.AfterUploadJob; } if (UseDefaultDestinations) { ImageDestination = defaultTaskSettings.ImageDestination; ImageFileDestination = defaultTaskSettings.ImageFileDestination; TextDestination = defaultTaskSettings.TextDestination; TextFileDestination = defaultTaskSettings.TextFileDestination; FileDestination = defaultTaskSettings.FileDestination; URLShortenerDestination = defaultTaskSettings.URLShortenerDestination; URLSharingServiceDestination = defaultTaskSettings.URLSharingServiceDestination; } if (UseDefaultGeneralSettings) { GeneralSettings = defaultTaskSettings.GeneralSettings; } if (UseDefaultImageSettings) { ImageSettings = defaultTaskSettings.ImageSettings; } if (UseDefaultCaptureSettings) { CaptureSettings = defaultTaskSettings.CaptureSettings; } if (UseDefaultUploadSettings) { UploadSettings = defaultTaskSettings.UploadSettings; } if (UseDefaultActions) { ExternalPrograms = defaultTaskSettings.ExternalPrograms; } if (UseDefaultToolsSettings) { ToolsSettings = defaultTaskSettings.ToolsSettings; } if (UseDefaultAdvancedSettings) { AdvancedSettings = defaultTaskSettings.AdvancedSettings; } } }
public void StartRecording(TaskSettings taskSettings) { if (taskSettings.CaptureSettings.RunScreencastCLI) { if (!Program.Settings.VideoEncoders.IsValidIndex(taskSettings.CaptureSettings.VideoEncoderSelected)) { MessageBox.Show(Resources.ScreenRecordForm_StartRecording_There_is_no_valid_CLI_video_encoder_selected_, "ShareX", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (!Program.Settings.VideoEncoders[taskSettings.CaptureSettings.VideoEncoderSelected].IsValid()) { MessageBox.Show(Resources.ScreenRecordForm_StartRecording_CLI_video_encoder_file_does_not_exist__ + Program.Settings.VideoEncoders[taskSettings.CaptureSettings.VideoEncoderSelected].Path, "ShareX", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } } if (taskSettings.CaptureSettings.ScreenRecordOutput == ScreenRecordOutput.FFmpeg) { if (!File.Exists(taskSettings.CaptureSettings.FFmpegOptions.CLIPath)) { string ffmpegText = string.IsNullOrEmpty(taskSettings.CaptureSettings.FFmpegOptions.CLIPath) ? "ffmpeg.exe" : taskSettings.CaptureSettings.FFmpegOptions.CLIPath; if (MessageBox.Show(string.Format(Resources.ScreenRecordForm_StartRecording_does_not_exist, ffmpegText), "ShareX - " + Resources.ScreenRecordForm_StartRecording_Missing + " ffmpeg.exe", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes) { if (FFmpegHelper.DownloadFFmpeg(false, DownloaderForm_InstallRequested) == DialogResult.OK) { Program.DefaultTaskSettings.CaptureSettings.FFmpegOptions.CLIPath = taskSettings.TaskSettingsReference.CaptureSettings.FFmpegOptions.CLIPath = taskSettings.CaptureSettings.FFmpegOptions.CLIPath = Path.Combine(Program.ToolsFolder, "ffmpeg.exe"); } } else { return; } } if (!taskSettings.CaptureSettings.FFmpegOptions.IsSourceSelected) { MessageBox.Show(Resources.ScreenRecordForm_StartRecording_FFmpeg_video_and_audio_source_both_can_t_be__None__, "ShareX - " + Resources.ScreenRecordForm_StartRecording_FFmpeg_error, MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } } Rectangle captureRectangle; TaskHelpers.SelectRegion(out captureRectangle); captureRectangle = CaptureHelpers.EvenRectangleSize(captureRectangle); if (IsRecording || !captureRectangle.IsValid() || screenRecorder != null) { return; } IsRecording = true; Screenshot.CaptureCursor = taskSettings.CaptureSettings.ShowCursor; TrayIcon.Text = "ShareX - " + Resources.ScreenRecordForm_StartRecording_Waiting___; TrayIcon.Icon = Resources.control_record_yellow.ToIcon(); TrayIcon.Visible = true; string path = ""; float duration = taskSettings.CaptureSettings.ScreenRecordFixedDuration ? taskSettings.CaptureSettings.ScreenRecordDuration : 0; regionForm = ScreenRegionForm.Show(captureRectangle, StopRecording, duration); regionForm.RecordResetEvent = new ManualResetEvent(false); TaskEx.Run(() => { try { if (taskSettings.CaptureSettings.ScreenRecordAutoDisableAero) { dwmManager = new DWMManager(); dwmManager.AutoDisable(); } if (taskSettings.CaptureSettings.ScreenRecordOutput == ScreenRecordOutput.AVI) { path = Path.Combine(taskSettings.CaptureFolder, TaskHelpers.GetFilename(taskSettings, "avi")); } else if (taskSettings.CaptureSettings.ScreenRecordOutput == ScreenRecordOutput.FFmpeg) { path = Path.Combine(taskSettings.CaptureFolder, TaskHelpers.GetFilename(taskSettings, taskSettings.CaptureSettings.FFmpegOptions.Extension)); } else { path = Program.ScreenRecorderCacheFilePath; } ScreencastOptions options = new ScreencastOptions() { FFmpeg = taskSettings.CaptureSettings.FFmpegOptions, AVI = taskSettings.CaptureSettings.AVIOptions, ScreenRecordFPS = taskSettings.CaptureSettings.ScreenRecordFPS, GIFFPS = taskSettings.CaptureSettings.GIFFPS, Duration = duration, OutputPath = path, CaptureArea = captureRectangle, DrawCursor = taskSettings.CaptureSettings.ShowCursor }; screenRecorder = new ScreenRecorder(options, captureRectangle, taskSettings.CaptureSettings.ScreenRecordOutput); if (regionForm != null && regionForm.RecordResetEvent != null) { TrayIcon.Text = "ShareX - " + Resources.ScreenRecordForm_StartRecording_Click_tray_icon_to_start_recording_; if (taskSettings.CaptureSettings.ScreenRecordAutoStart) { int delay = (int)(taskSettings.CaptureSettings.ScreenRecordStartDelay * 1000); if (delay > 0) { regionForm.RecordResetEvent.WaitOne(delay); } } else { regionForm.RecordResetEvent.WaitOne(); } if (regionForm.AbortRequested) { abortRequested = true; } } if (!abortRequested) { TrayIcon.Text = "ShareX - " + Resources.ScreenRecordForm_StartRecording_Click_tray_icon_to_stop_recording_; TrayIcon.Icon = Resources.control_record.ToIcon(); if (regionForm != null) { this.InvokeSafe(() => regionForm.StartTimer()); } screenRecorder.StartRecording(); if (regionForm != null && regionForm.AbortRequested) { abortRequested = true; } } } finally { if (dwmManager != null) { dwmManager.Dispose(); dwmManager = null; } if (regionForm != null) { if (regionForm.RecordResetEvent != null) { regionForm.RecordResetEvent.Dispose(); } this.InvokeSafe(() => regionForm.Close()); regionForm = null; } } try { if (!abortRequested && screenRecorder != null) { TrayIcon.Text = "ShareX - " + Resources.ScreenRecordForm_StartRecording_Encoding___; TrayIcon.Icon = Resources.camcorder_pencil.ToIcon(); string sourceFilePath = path; if (taskSettings.CaptureSettings.ScreenRecordOutput == ScreenRecordOutput.GIF) { if (taskSettings.CaptureSettings.RunScreencastCLI) { sourceFilePath = Path.ChangeExtension(Program.ScreenRecorderCacheFilePath, "gif"); } else { sourceFilePath = path = Path.Combine(taskSettings.CaptureFolder, TaskHelpers.GetFilename(taskSettings, "gif")); } screenRecorder.SaveAsGIF(sourceFilePath, taskSettings.ImageSettings.ImageGIFQuality); } if (taskSettings.CaptureSettings.RunScreencastCLI) { VideoEncoder encoder = Program.Settings.VideoEncoders[taskSettings.CaptureSettings.VideoEncoderSelected]; path = Path.Combine(taskSettings.CaptureFolder, TaskHelpers.GetFilename(taskSettings, encoder.OutputExtension)); screenRecorder.EncodeUsingCommandLine(encoder, sourceFilePath, path); } } } finally { if (screenRecorder != null) { if (taskSettings.CaptureSettings.RunScreencastCLI && !string.IsNullOrEmpty(screenRecorder.CachePath) && File.Exists(screenRecorder.CachePath)) { File.Delete(screenRecorder.CachePath); } screenRecorder.Dispose(); screenRecorder = null; if (abortRequested && !string.IsNullOrEmpty(path) && File.Exists(path)) { File.Delete(path); } } } }, () => { if (TrayIcon.Visible) { TrayIcon.Visible = false; } if (!abortRequested && !string.IsNullOrEmpty(path) && File.Exists(path) && TaskHelpers.ShowAfterCaptureForm(taskSettings)) { UploadTask task = UploadTask.CreateFileJobTask(path, taskSettings); TaskManager.Start(task); } abortRequested = false; IsRecording = false; }); }
public static void DoScreenRecordingGIF() { TaskSettings taskSettings = TaskSettings.GetDefaultTaskSettings(); StartScreenRecording(ScreenRecordOutput.GIF, taskSettings); }
private static void ProcessClipboardContentViewerDialog(ClipboardContentViewer ccv, TaskSettings taskSettings = null) { if (taskSettings == null) { taskSettings = TaskSettings.GetDefaultTaskSettings(); } if (ccv.ShowDialog() == DialogResult.OK && ccv.IsClipboardContentValid) { if (ccv.ClipboardContentType != EClipboardContentType.Default) { ClipboardUploadCached(ccv, taskSettings); } else { ClipboardUpload(taskSettings); } } else if (ccv.ClipboardContentType == EClipboardContentType.Image) { ((Image)ccv.ClipboardContent).Dispose(); } }
public static void UploadImage(Bitmap bmp, ImageDestination imageDestination, FileDestination imageFileDestination, TaskSettings taskSettings = null) { if (bmp != null) { if (taskSettings == null) { taskSettings = TaskSettings.GetDefaultTaskSettings(); } if (taskSettings.IsSafeTaskSettings) { taskSettings.UseDefaultAfterCaptureJob = false; taskSettings.AfterCaptureJob = AfterCaptureTasks.UploadImageToHost; taskSettings.UseDefaultDestinations = false; taskSettings.ImageDestination = imageDestination; taskSettings.ImageFileDestination = imageFileDestination; } RunImageTask(bmp, taskSettings); } }
private static string ProcessTwoPassEncoding(string input, TaskMetadata metadata, TaskSettings taskSettings, bool deleteInputFile = true) { string screenshotsFolder = TaskHelpers.GetScreenshotsFolder(taskSettings, metadata); string fileName = TaskHelpers.GetFileName(taskSettings, taskSettings.CaptureSettings.FFmpegOptions.Extension, metadata); string output = Path.Combine(screenshotsFolder, fileName); try { if (taskSettings.CaptureSettings.FFmpegOptions.VideoCodec == FFmpegVideoCodec.gif) { screenRecorder.FFmpegEncodeAsGIF(input, output); } else { screenRecorder.FFmpegEncodeVideo(input, output); } } finally { if (deleteInputFile && !input.Equals(output, StringComparison.InvariantCultureIgnoreCase) && File.Exists(input)) { File.Delete(input); } } return(output); }
private void DoCaptureWork(ScreenCaptureDelegate capture, CaptureType captureType, TaskSettings taskSettings, bool autoHideForm = true) { if (autoHideForm) { Hide(); Thread.Sleep(250); } Image img = null; try { Screenshot.CaptureCursor = taskSettings.CaptureSettings.ShowCursor; Screenshot.CaptureShadow = taskSettings.CaptureSettings.CaptureShadow; Screenshot.ShadowOffset = taskSettings.CaptureSettings.CaptureShadowOffset; Screenshot.CaptureClientArea = taskSettings.CaptureSettings.CaptureClientArea; Screenshot.AutoHideTaskbar = taskSettings.CaptureSettings.CaptureAutoHideTaskbar; img = capture(); } catch (Exception ex) { DebugHelper.WriteException(ex); } finally { if (autoHideForm) { this.ShowActivate(); } AfterCapture(img, captureType, taskSettings); } }
private void DoCapture(ScreenCaptureDelegate capture, CaptureType captureType, TaskSettings taskSettings = null, bool autoHideForm = true) { if (taskSettings == null) { taskSettings = TaskSettings.GetDefaultTaskSettings(); } if (taskSettings.CaptureSettings.IsDelayScreenshot && taskSettings.CaptureSettings.DelayScreenshot > 0) { TaskEx.Run(() => { int sleep = (int)(taskSettings.CaptureSettings.DelayScreenshot * 1000); Thread.Sleep(sleep); }, () => { DoCaptureWork(capture, captureType, taskSettings, autoHideForm); }); } else { DoCaptureWork(capture, captureType, taskSettings, autoHideForm); } }
public static void OpenDropWindow(TaskSettings taskSettings = null) { DropForm.GetInstance(Program.Settings.DropSize, Program.Settings.DropOffset, Program.Settings.DropAlignment, Program.Settings.DropOpacity, Program.Settings.DropHoverOpacity, taskSettings).ForceActivate(); }
public static void StartScreenRecording(ScreenRecordOutput outputType, ScreenRecordStartMethod startMethod, TaskSettings taskSettings = null) { if (taskSettings == null) { taskSettings = TaskSettings.GetDefaultTaskSettings(); } ScreenRecordManager.StartStopRecording(outputType, startMethod, taskSettings); }
public static MemoryStream SaveImage(Image img, EImageFormat imageFormat, TaskSettings taskSettings) { return(SaveImage(img, imageFormat, taskSettings.ImageSettings.ImageJPEGQuality, taskSettings.ImageSettings.ImageGIFQuality)); }
private void CaptureRegion(CaptureType captureType, TaskSettings taskSettings, bool autoHideForm = true) { Surface surface; switch (captureType) { default: case CaptureType.Rectangle: surface = new RectangleRegion(); break; case CaptureType.RectangleWindow: RectangleRegion rectangleRegion = new RectangleRegion(); rectangleRegion.AreaManager.WindowCaptureMode = true; surface = rectangleRegion; break; case CaptureType.RoundedRectangle: surface = new RoundedRectangleRegion(); break; case CaptureType.Ellipse: surface = new EllipseRegion(); break; case CaptureType.Triangle: surface = new TriangleRegion(); break; case CaptureType.Diamond: surface = new DiamondRegion(); break; case CaptureType.Polygon: surface = new PolygonRegion(); break; case CaptureType.Freehand: surface = new FreeHandRegion(); break; } DoCapture(() => { Image img = null; Image screenshot = Screenshot.CaptureFullscreen(); try { surface.Config = taskSettings.CaptureSettings.SurfaceOptions; surface.SurfaceImage = screenshot; surface.Prepare(); surface.ShowDialog(); if (surface.Result == SurfaceResult.Region) { img = surface.GetRegionImage(); screenshot.Dispose(); } else if (surface.Result == SurfaceResult.Fullscreen) { img = screenshot; } if (img != null) { isLightCapture = false; } } finally { surface.Dispose(); } return(img); }, captureType, taskSettings, autoHideForm); }
private static void StartRecording(ScreenRecordOutput outputType, TaskSettings taskSettings, ScreenRecordStartMethod startMethod = ScreenRecordStartMethod.Region) { if (outputType == ScreenRecordOutput.FFmpeg && taskSettings.CaptureSettings.FFmpegOptions.VideoCodec == FFmpegVideoCodec.gif) { outputType = ScreenRecordOutput.GIF; } if (outputType == ScreenRecordOutput.FFmpeg) { DebugHelper.WriteLine("Starting screen recording. Video encoder: \"{0}\", Audio encoder: \"{1}\", FPS: {2}", taskSettings.CaptureSettings.FFmpegOptions.VideoCodec.GetDescription(), taskSettings.CaptureSettings.FFmpegOptions.AudioCodec.GetDescription(), taskSettings.CaptureSettings.ScreenRecordFPS); } else { DebugHelper.WriteLine("Starting screen recording. FPS: {0}", taskSettings.CaptureSettings.GIFFPS); } if (taskSettings.CaptureSettings.RunScreencastCLI) { if (!Program.Settings.VideoEncoders.IsValidIndex(taskSettings.CaptureSettings.VideoEncoderSelected)) { MessageBox.Show(Resources.ScreenRecordForm_StartRecording_There_is_no_valid_CLI_video_encoder_selected_, "ShareX", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (!Program.Settings.VideoEncoders[taskSettings.CaptureSettings.VideoEncoderSelected].IsValid()) { MessageBox.Show(Resources.ScreenRecordForm_StartRecording_CLI_video_encoder_file_does_not_exist__ + Program.Settings.VideoEncoders[taskSettings.CaptureSettings.VideoEncoderSelected].Path, "ShareX", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } } if (outputType == ScreenRecordOutput.GIF) { taskSettings.CaptureSettings.FFmpegOptions.VideoCodec = FFmpegVideoCodec.gif; taskSettings.CaptureSettings.FFmpegOptions.UseCustomCommands = false; } if (!TaskHelpers.CheckFFmpeg(taskSettings)) { return; } if (!taskSettings.CaptureSettings.FFmpegOptions.IsSourceSelected) { MessageBox.Show(Resources.ScreenRecordForm_StartRecording_FFmpeg_video_and_audio_source_both_can_t_be__None__, "ShareX - " + Resources.ScreenRecordForm_StartRecording_FFmpeg_error, MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } Rectangle captureRectangle = Rectangle.Empty; switch (startMethod) { case ScreenRecordStartMethod.Region: RegionCaptureTasks.GetRectangleRegion(out captureRectangle, taskSettings.CaptureSettings.SurfaceOptions); 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; } 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, startMethod == ScreenRecordStartMethod.Region, duration); recordForm.StopRequested += StopRecording; recordForm.Show(); TaskEx.Run(() => { try { string filename = TaskHelpers.GetFilename(taskSettings, taskSettings.CaptureSettings.FFmpegOptions.Extension); path = TaskHelpers.CheckFilePath(taskSettings.CaptureFolder, 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.AbortRequested) { abortRequested = true; } if (!abortRequested) { ScreencastOptions options = new ScreencastOptions() { FFmpeg = taskSettings.CaptureSettings.FFmpegOptions, ScreenRecordFPS = taskSettings.CaptureSettings.ScreenRecordFPS, GIFFPS = taskSettings.CaptureSettings.GIFFPS, 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 += () => recordForm.ChangeState(ScreenRecordState.AfterRecordingStart); recordForm.ChangeState(ScreenRecordState.AfterStart); screenRecorder.StartRecording(); if (recordForm.AbortRequested) { abortRequested = true; } } } } catch (Exception e) { DebugHelper.WriteException(e); } try { if (!abortRequested && screenRecorder != null && File.Exists(path)) { recordForm.ChangeState(ScreenRecordState.AfterStop); string sourceFilePath = path; if (outputType == ScreenRecordOutput.GIF) { path = Path.Combine(taskSettings.CaptureFolder, TaskHelpers.GetFilename(taskSettings, "gif")); screenRecorder.FFmpegEncodeAsGIF(sourceFilePath, path); } if (taskSettings.CaptureSettings.RunScreencastCLI) { VideoEncoder encoder = Program.Settings.VideoEncoders[taskSettings.CaptureSettings.VideoEncoderSelected]; path = Path.Combine(taskSettings.CaptureFolder, TaskHelpers.GetFilename(taskSettings, encoder.OutputExtension)); screenRecorder.EncodeUsingCommandLine(encoder, sourceFilePath, path); } } } finally { if (recordForm != null) { recordForm.InvokeSafe(() => { recordForm.Close(); recordForm.Dispose(); recordForm = null; }); } if (screenRecorder != null) { if ((outputType == ScreenRecordOutput.GIF || taskSettings.CaptureSettings.RunScreencastCLI) && !string.IsNullOrEmpty(screenRecorder.CachePath) && File.Exists(screenRecorder.CachePath)) { File.Delete(screenRecorder.CachePath); } screenRecorder.Dispose(); screenRecorder = null; if (abortRequested && !string.IsNullOrEmpty(path) && File.Exists(path)) { File.Delete(path); } } } }, () => { string customFileName; if (!abortRequested && !string.IsNullOrEmpty(path) && File.Exists(path) && TaskHelpers.ShowAfterCaptureForm(taskSettings, out 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, taskSettings, customFileName); TaskManager.Start(task); } abortRequested = false; IsRecording = false; }); }
public static void DownloadAndUploadFile(string url, TaskSettings taskSettings = null) { DownloadFile(url, true, taskSettings); }
public static void RunImageTask(Bitmap bmp, TaskSettings taskSettings, bool skipQuickTaskMenu = false, bool skipAfterCaptureWindow = false) { TaskMetadata metadata = new TaskMetadata(bmp); RunImageTask(metadata, taskSettings, skipQuickTaskMenu, skipAfterCaptureWindow); }
public static void DownloadFile(string url, TaskSettings taskSettings = null) { DownloadFile(url, false, taskSettings); }
private WorkerTask(TaskSettings taskSettings) { Status = TaskStatus.InQueue; Info = new TaskInfo(taskSettings); }
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.ScreenRecordForm_StartRecording_FFmpeg_video_and_audio_source_both_can_t_be__None__, "ShareX - " + Resources.ScreenRecordForm_StartRecording_FFmpeg_error, MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } Rectangle captureRectangle = Rectangle.Empty; switch (startMethod) { case ScreenRecordStartMethod.Region: if (taskSettings.CaptureSettings.ScreenRecordTransparentRegion) { RegionCaptureTasks.GetRectangleRegionTransparent(out captureRectangle); } else { RegionCaptureTasks.GetRectangleRegion(out captureRectangle, taskSettings.CaptureSettings.SurfaceOptions); } 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, taskSettings, startMethod == ScreenRecordStartMethod.Region, duration); recordForm.StopRequested += StopRecording; recordForm.Show(); Task.Run(() => { try { string extension; if (taskSettings.CaptureSettings.ScreenRecordTwoPassEncoding) { extension = "mp4"; } else { extension = taskSettings.CaptureSettings.FFmpegOptions.Extension; } string filename = TaskHelpers.GetFilename(taskSettings, extension); path = TaskHelpers.HandleExistsFile(taskSettings.GetScreenshotsFolder(), 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) { ScreencastOptions options = new ScreencastOptions() { 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, 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(() => { string customFileName; if (!abortRequested && !string.IsNullOrEmpty(path) && File.Exists(path) && TaskHelpers.ShowAfterCaptureForm(taskSettings, out 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, taskSettings, customFileName); TaskManager.Start(task); } abortRequested = false; IsRecording = false; }); }
public static void ClipboardUpload(TaskSettings taskSettings = null) { if (taskSettings == null) { taskSettings = TaskSettings.GetDefaultTaskSettings(); } if (Clipboard.ContainsImage()) { Image img = ClipboardHelpers.GetImage(); if (img != null) { if (!taskSettings.AdvancedSettings.ProcessImagesDuringClipboardUpload) { taskSettings.AfterCaptureJob = AfterCaptureTasks.UploadImageToHost; } RunImageTask(img, taskSettings); } } else if (Clipboard.ContainsText()) { string text = Clipboard.GetText(); if (!string.IsNullOrEmpty(text)) { string url = text.Trim(); if (URLHelpers.IsValidURL(url)) { if (taskSettings.UploadSettings.ClipboardUploadURLContents) { DownloadAndUploadFile(url, taskSettings); return; } if (taskSettings.UploadSettings.ClipboardUploadShortenURL) { ShortenURL(url, taskSettings); return; } if (taskSettings.UploadSettings.ClipboardUploadShareURL) { ShareURL(url, taskSettings); return; } } if (taskSettings.UploadSettings.ClipboardUploadAutoIndexFolder && text.Length <= 260 && Directory.Exists(text)) { IndexFolder(text, taskSettings); } else { UploadText(text, taskSettings, true); } } } else if (Clipboard.ContainsFileDropList()) { string[] files = Clipboard.GetFileDropList().OfType <string>().ToArray(); if (files.Length > 0) { UploadFile(files, taskSettings); } } }
public static void StartStopRecording(ScreenRecordOutput outputType, ScreenRecordStartMethod startMethod, TaskSettings taskSettings) { if (IsRecording) { if (recordForm != null && !recordForm.IsDisposed) { recordForm.StartStopRecording(); } } else { StartRecording(outputType, taskSettings, startMethod); } }
public static void RunImageTask(Image img, TaskSettings taskSettings, bool skipQuickTaskMenu = false, bool skipAfterCaptureWindow = false) { ImageInfo imageInfo = new ImageInfo(img); RunImageTask(imageInfo, taskSettings, skipQuickTaskMenu, skipAfterCaptureWindow); }
public UploadTestForm() { InitializeComponent(); Icon = Resources.ShareX_Icon; if (TestImage == null) { TestImage = Resources.ShareX_Logo; } if (string.IsNullOrEmpty(TestText)) { TestText = Program.ApplicationName + " text upload test"; } if (string.IsNullOrEmpty(TestURL)) { TestURL = Links.URL_WEBSITE; } ListViewItem lvi; ListViewGroup imageUploadersGroup = new ListViewGroup("Image Uploaders", HorizontalAlignment.Left); ListViewGroup textUploadersGroup = new ListViewGroup("Text Uploaders", HorizontalAlignment.Left); ListViewGroup fileUploadersGroup = new ListViewGroup("File Uploaders", HorizontalAlignment.Left); ListViewGroup urlShortenersGroup = new ListViewGroup("URL Shorteners", HorizontalAlignment.Left); lvUploaders.Groups.AddRange(new[] { imageUploadersGroup, textUploadersGroup, fileUploadersGroup, urlShortenersGroup }); TaskSettings defaultTaskSettings = TaskSettings.GetDefaultTaskSettings(); foreach (ImageDestination uploader in Enum.GetValues(typeof(ImageDestination))) { switch (uploader) { case ImageDestination.Twitsnaps: // Not possible to upload without post Twitter case ImageDestination.FileUploader: // We are going to test this in File Uploader tests continue; } lvi = new ListViewItem(uploader.GetDescription()); UploadTask task = UploadTask.CreateImageUploaderTask((Image)TestImage.Clone(), defaultTaskSettings); task.Info.TaskSettings.ImageDestination = uploader; lvi.Tag = task; lvi.Group = imageUploadersGroup; lvUploaders.Items.Add(lvi); } foreach (TextDestination uploader in Enum.GetValues(typeof(TextDestination))) { switch (uploader) { case TextDestination.FileUploader: continue; } lvi = new ListViewItem(uploader.GetDescription()); UploadTask task = UploadTask.CreateTextUploaderTask(TestText, defaultTaskSettings); task.Info.TaskSettings.TextDestination = uploader; lvi.Tag = task; lvi.Group = textUploadersGroup; lvUploaders.Items.Add(lvi); } foreach (FileDestination uploader in Enum.GetValues(typeof(FileDestination))) { switch (uploader) { case FileDestination.CustomFileUploader: case FileDestination.SharedFolder: case FileDestination.Email: continue; } lvi = new ListViewItem(uploader.GetDescription()); UploadTask task = UploadTask.CreateImageUploaderTask((Image)TestImage.Clone(), defaultTaskSettings); task.Info.TaskSettings.ImageDestination = ImageDestination.FileUploader; task.Info.TaskSettings.FileDestination = uploader; lvi.Tag = task; lvi.Group = fileUploadersGroup; lvUploaders.Items.Add(lvi); } foreach (UrlShortenerType uploader in Enum.GetValues(typeof(UrlShortenerType))) { lvi = new ListViewItem(uploader.GetDescription()); UploadTask task = UploadTask.CreateURLShortenerTask(TestURL, defaultTaskSettings); task.Info.TaskSettings.URLShortenerDestination = uploader; lvi.Tag = task; lvi.Group = urlShortenersGroup; lvUploaders.Items.Add(lvi); } PrepareListItems(); }
public static bool SelectRegion(out Rectangle rect, TaskSettings taskSettings) { return(Surface.SelectRegion(out rect, taskSettings.CaptureSettings.SurfaceOptions)); }
public static string CreateThumbnail(Image img, string folder, string filename, TaskSettings taskSettings) { if ((taskSettings.ImageSettings.ThumbnailWidth > 0 || taskSettings.ImageSettings.ThumbnailHeight > 0) && (!taskSettings.ImageSettings.ThumbnailCheckSize || (img.Width > taskSettings.ImageSettings.ThumbnailWidth && img.Height > taskSettings.ImageSettings.ThumbnailHeight))) { string thumbnailFileName = Path.GetFileNameWithoutExtension(filename) + taskSettings.ImageSettings.ThumbnailName + ".jpg"; string thumbnailFilePath = CheckFilePath(folder, thumbnailFileName, taskSettings); if (!string.IsNullOrEmpty(thumbnailFilePath)) { Image thumbImage = null; try { thumbImage = (Image)img.Clone(); thumbImage = new Resize { Width = taskSettings.ImageSettings.ThumbnailWidth, Height = taskSettings.ImageSettings.ThumbnailHeight }.Apply(thumbImage); thumbImage = ImageHelpers.FillBackground(thumbImage, Color.White); thumbImage.SaveJPG(thumbnailFilePath, 90); return(thumbnailFilePath); } catch (Exception e) { DebugHelper.WriteException(e); } finally { if (thumbImage != null) { thumbImage.Dispose(); } } } } return(null); }
protected abstract ImageInfo Execute(TaskSettings taskSettings);
private void SetDestinations(bool isActive, EDataType dataType, object destination, TaskSettings taskSettings) { if (!isActive) { return; } switch (dataType) { case EDataType.Image: if (destination is ImageDestination) { taskSettings.ImageDestination = (ImageDestination)destination; } else if (destination is FileDestination) { taskSettings.ImageDestination = ImageDestination.FileUploader; taskSettings.ImageFileDestination = (FileDestination)destination; } break; case EDataType.Text: if (destination is TextDestination) { taskSettings.TextDestination = (TextDestination)destination; } else if (destination is FileDestination) { taskSettings.TextDestination = TextDestination.FileUploader; taskSettings.TextFileDestination = (FileDestination)destination; } break; case EDataType.File: if (destination is FileDestination) { taskSettings.ImageDestination = ImageDestination.FileUploader; taskSettings.TextDestination = TextDestination.FileUploader; taskSettings.ImageFileDestination = taskSettings.TextFileDestination = taskSettings.FileDestination = (FileDestination)destination; } break; case EDataType.URL: if (destination is UrlShortenerType) { taskSettings.URLShortenerDestination = (UrlShortenerType)destination; } break; } }
public static WorkerTask CreateDataUploaderTask(EDataType dataType, Stream stream, string fileName, TaskSettings taskSettings) { WorkerTask task = new WorkerTask(taskSettings); task.Info.Job = TaskJob.DataUpload; task.Info.DataType = dataType; task.Info.FileName = fileName; task.Data = stream; return(task); }
private void HandleTask(TaskSettings taskSettings) { TaskSettings safeTaskSettings = TaskSettings.GetSafeTaskSettings(taskSettings); switch (safeTaskSettings.Job) { case HotkeyType.StopUploads: TaskManager.StopAllTasks(); break; case HotkeyType.ClipboardUpload: UploadManager.ClipboardUpload(safeTaskSettings); break; case HotkeyType.ClipboardUploadWithContentViewer: UploadManager.ClipboardUploadWithContentViewer(safeTaskSettings); break; case HotkeyType.FileUpload: UploadManager.UploadFile(safeTaskSettings); break; case HotkeyType.DragDropUpload: TaskHelpers.OpenDropWindow(); break; case HotkeyType.PrintScreen: CaptureScreenshot(CaptureType.Screen, safeTaskSettings, false); break; case HotkeyType.ActiveWindow: CaptureScreenshot(CaptureType.ActiveWindow, safeTaskSettings, false); break; case HotkeyType.ActiveMonitor: CaptureScreenshot(CaptureType.ActiveMonitor, safeTaskSettings, false); break; case HotkeyType.RectangleRegion: CaptureScreenshot(CaptureType.Rectangle, safeTaskSettings, false); break; case HotkeyType.WindowRectangle: CaptureScreenshot(CaptureType.RectangleWindow, safeTaskSettings, false); break; case HotkeyType.RectangleLight: CaptureLightRectangle(safeTaskSettings, false); break; case HotkeyType.RoundedRectangleRegion: CaptureScreenshot(CaptureType.RoundedRectangle, safeTaskSettings, false); break; case HotkeyType.EllipseRegion: CaptureScreenshot(CaptureType.Ellipse, safeTaskSettings, false); break; case HotkeyType.TriangleRegion: CaptureScreenshot(CaptureType.Triangle, safeTaskSettings, false); break; case HotkeyType.DiamondRegion: CaptureScreenshot(CaptureType.Diamond, safeTaskSettings, false); break; case HotkeyType.PolygonRegion: CaptureScreenshot(CaptureType.Polygon, safeTaskSettings, false); break; case HotkeyType.FreeHandRegion: CaptureScreenshot(CaptureType.Freehand, safeTaskSettings, false); break; case HotkeyType.LastRegion: CaptureScreenshot(CaptureType.LastRegion, safeTaskSettings, false); break; case HotkeyType.ScreenRecorder: TaskHelpers.DoScreenRecorder(safeTaskSettings); break; case HotkeyType.AutoCapture: TaskHelpers.OpenAutoCapture(); break; case HotkeyType.ScreenColorPicker: TaskHelpers.OpenScreenColorPicker(safeTaskSettings); break; case HotkeyType.Ruler: TaskHelpers.OpenRuler(); break; case HotkeyType.FTPClient: TaskHelpers.OpenFTPClient(); break; case HotkeyType.HashCheck: TaskHelpers.OpenHashCheck(); break; case HotkeyType.IndexFolder: TaskHelpers.OpenIndexFolder(); break; case HotkeyType.ImageEffects: TaskHelpers.OpenImageEffects(); break; case HotkeyType.QRCode: TaskHelpers.OpenQRCode(); break; } }
public TaskSettingsForm(TaskSettings hotkeySetting, bool isDefault = false) { InitializeComponent(); Icon = ShareXResources.Icon; TaskSettings = hotkeySetting; IsDefault = isDefault; if (IsDefault) { tcTaskSettings.TabPages.Remove(tpTask); chkUseDefaultGeneralSettings.Visible = chkUseDefaultImageSettings.Visible = chkUseDefaultCaptureSettings.Visible = chkUseDefaultActions.Visible = chkUseDefaultUploadSettings.Visible = chkUseDefaultIndexerSettings.Visible = chkUseDefaultAdvancedSettings.Visible = false; } else { tbDescription.Text = TaskSettings.Description ?? string.Empty; cbUseDefaultAfterCaptureSettings.Checked = TaskSettings.UseDefaultAfterCaptureJob; cbUseDefaultAfterUploadSettings.Checked = TaskSettings.UseDefaultAfterUploadJob; cbUseDefaultDestinationSettings.Checked = TaskSettings.UseDefaultDestinations; chkUseDefaultGeneralSettings.Checked = TaskSettings.UseDefaultGeneralSettings; chkUseDefaultImageSettings.Checked = TaskSettings.UseDefaultImageSettings; chkUseDefaultCaptureSettings.Checked = TaskSettings.UseDefaultCaptureSettings; chkUseDefaultActions.Checked = TaskSettings.UseDefaultActions; chkUseDefaultUploadSettings.Checked = TaskSettings.UseDefaultUploadSettings; chkUseDefaultIndexerSettings.Checked = TaskSettings.UseDefaultIndexerSettings; chkUseDefaultAdvancedSettings.Checked = TaskSettings.UseDefaultAdvancedSettings; } UpdateWindowTitle(); AddEnumItemsContextMenu <HotkeyType>(x => { TaskSettings.Job = x; UpdateWindowTitle(); }, cmsTask); AddMultiEnumItemsContextMenu <AfterCaptureTasks>(x => TaskSettings.AfterCaptureJob = TaskSettings.AfterCaptureJob.Swap(x), cmsAfterCapture); AddMultiEnumItemsContextMenu <AfterUploadTasks>(x => TaskSettings.AfterUploadJob = TaskSettings.AfterUploadJob.Swap(x), cmsAfterUpload); // Destinations -> Image uploader AddEnumItems <ImageDestination>(x => { TaskSettings.ImageDestination = x; // if click on "folder" with file destinations then set ImageFileDestination and check it if (x == ImageDestination.FileUploader) { SetEnumChecked(TaskSettings.ImageFileDestination, tsmiImageFileUploaders); } else // if click not on "folder" with destinations then uncheck file destinations { MainForm.Uncheck(tsmiImageFileUploaders); } }, tsmiImageUploaders); tsmiImageFileUploaders = (ToolStripDropDownItem)tsmiImageUploaders.DropDownItems[tsmiImageUploaders.DropDownItems.Count - 1]; AddEnumItems <FileDestination>(x => { TaskSettings.ImageFileDestination = x; tsmiImageFileUploaders.PerformClick(); }, tsmiImageFileUploaders); // Destinations -> Text uploader AddEnumItems <TextDestination>(x => { TaskSettings.TextDestination = x; // if click on "folder" with file destinations then set TextFileDestination and check it if (x == TextDestination.FileUploader) { SetEnumChecked(TaskSettings.TextFileDestination, tsmiTextFileUploaders); } else // if click not on "folder" with destinations then uncheck file destinations { MainForm.Uncheck(tsmiTextFileUploaders); } }, tsmiTextUploaders); tsmiTextFileUploaders = (ToolStripDropDownItem)tsmiTextUploaders.DropDownItems[tsmiTextUploaders.DropDownItems.Count - 1]; AddEnumItems <FileDestination>(x => { TaskSettings.TextFileDestination = x; tsmiTextFileUploaders.PerformClick(); }, tsmiTextFileUploaders); // Destinations -> File uploader AddEnumItems <FileDestination>(x => TaskSettings.FileDestination = x, tsmiFileUploaders); AddEnumItems <UrlShortenerType>(x => TaskSettings.URLShortenerDestination = x, tsmiURLShorteners); AddEnumItems <URLSharingServices>(x => TaskSettings.URLSharingServiceDestination = x, tsmiURLSharingServices); SetEnumCheckedContextMenu(TaskSettings.Job, cmsTask); SetMultiEnumCheckedContextMenu(TaskSettings.AfterCaptureJob, cmsAfterCapture); SetMultiEnumCheckedContextMenu(TaskSettings.AfterUploadJob, cmsAfterUpload); SetEnumChecked(TaskSettings.ImageDestination, tsmiImageUploaders); MainForm.SetImageFileDestinationChecked(TaskSettings.ImageDestination, TaskSettings.ImageFileDestination, tsmiImageFileUploaders); SetEnumChecked(TaskSettings.TextDestination, tsmiTextUploaders); MainForm.SetTextFileDestinationChecked(TaskSettings.TextDestination, TaskSettings.TextFileDestination, tsmiTextFileUploaders); SetEnumChecked(TaskSettings.FileDestination, tsmiFileUploaders); SetEnumChecked(TaskSettings.URLShortenerDestination, tsmiURLShorteners); SetEnumChecked(TaskSettings.URLSharingServiceDestination, tsmiURLSharingServices); if (Program.UploadersConfig != null) { // FTP if (Program.UploadersConfig.FTPAccountList.Count > 0) { chkOverrideFTP.Checked = TaskSettings.OverrideFTP; cboFTPaccounts.Items.Clear(); cboFTPaccounts.Items.AddRange(Program.UploadersConfig.FTPAccountList.ToArray()); cboFTPaccounts.SelectedIndex = TaskSettings.FTPIndex.BetweenOrDefault(0, Program.UploadersConfig.FTPAccountList.Count - 1); } // Custom uploader if (Program.UploadersConfig.CustomUploadersList.Count > 0) { chkOverrideCustomUploader.Checked = TaskSettings.OverrideCustomUploader; cbOverrideCustomUploader.Items.Clear(); cbOverrideCustomUploader.Items.AddRange(Program.UploadersConfig.CustomUploadersList.ToArray()); cbOverrideCustomUploader.SelectedIndex = TaskSettings.CustomUploaderIndex.BetweenOrDefault(0, Program.UploadersConfig.CustomUploadersList.Count - 1); } } UpdateDestinationStates(); UpdateUploaderMenuNames(); // General cbPlaySoundAfterCapture.Checked = TaskSettings.GeneralSettings.PlaySoundAfterCapture; cbShowAfterCaptureTasksForm.Checked = TaskSettings.GeneralSettings.ShowAfterCaptureTasksForm; chkShowBeforeUploadForm.Checked = TaskSettings.GeneralSettings.ShowBeforeUploadForm; cbPlaySoundAfterUpload.Checked = TaskSettings.GeneralSettings.PlaySoundAfterUpload; chkShowAfterUploadForm.Checked = TaskSettings.GeneralSettings.ShowAfterUploadForm; cboPopUpNotification.Items.Clear(); cboPopUpNotification.Items.AddRange(Helpers.GetLocalizedEnumDescriptions <PopUpNotificationType>()); cboPopUpNotification.SelectedIndex = (int)TaskSettings.GeneralSettings.PopUpNotification; cbHistorySave.Checked = TaskSettings.GeneralSettings.SaveHistory; // Image - General cbImageFormat.Items.AddRange(Enum.GetNames(typeof(EImageFormat))); cbImageFormat.SelectedIndex = (int)TaskSettings.ImageSettings.ImageFormat; nudImageJPEGQuality.Value = TaskSettings.ImageSettings.ImageJPEGQuality; cbImageGIFQuality.Items.AddRange(Helpers.GetLocalizedEnumDescriptions <GIFQuality>()); cbImageGIFQuality.SelectedIndex = (int)TaskSettings.ImageSettings.ImageGIFQuality; nudUseImageFormat2After.Value = TaskSettings.ImageSettings.ImageSizeLimit; cbImageFormat2.Items.AddRange(Enum.GetNames(typeof(EImageFormat))); cbImageFormat2.SelectedIndex = (int)TaskSettings.ImageSettings.ImageFormat2; cbImageFileExist.Items.Clear(); cbImageFileExist.Items.AddRange(Helpers.GetLocalizedEnumDescriptions <FileExistAction>()); cbImageFileExist.SelectedIndex = (int)TaskSettings.ImageSettings.FileExistAction; // Image - Effects chkShowImageEffectsWindowAfterCapture.Checked = TaskSettings.ImageSettings.ShowImageEffectsWindowAfterCapture; cbImageEffectOnlyRegionCapture.Checked = TaskSettings.ImageSettings.ImageEffectOnlyRegionCapture; // Image - Thumbnail nudThumbnailWidth.Value = TaskSettings.ImageSettings.ThumbnailWidth; nudThumbnailHeight.Value = TaskSettings.ImageSettings.ThumbnailHeight; txtThumbnailName.Text = TaskSettings.ImageSettings.ThumbnailName; lblThumbnailNamePreview.Text = "ImageName" + TaskSettings.ImageSettings.ThumbnailName + ".jpg"; cbThumbnailIfSmaller.Checked = TaskSettings.ImageSettings.ThumbnailCheckSize; // Capture cbShowCursor.Checked = TaskSettings.CaptureSettings.ShowCursor; cbCaptureTransparent.Checked = TaskSettings.CaptureSettings.CaptureTransparent; cbCaptureShadow.Enabled = TaskSettings.CaptureSettings.CaptureTransparent; cbCaptureShadow.Checked = TaskSettings.CaptureSettings.CaptureShadow; nudCaptureShadowOffset.Value = TaskSettings.CaptureSettings.CaptureShadowOffset; cbCaptureClientArea.Checked = TaskSettings.CaptureSettings.CaptureClientArea; cbScreenshotDelay.Checked = TaskSettings.CaptureSettings.IsDelayScreenshot; nudScreenshotDelay.Value = TaskSettings.CaptureSettings.DelayScreenshot; cbCaptureAutoHideTaskbar.Checked = TaskSettings.CaptureSettings.CaptureAutoHideTaskbar; // Capture / Region capture if (TaskSettings.CaptureSettings.SurfaceOptions == null) { TaskSettings.CaptureSettings.SurfaceOptions = new SurfaceOptions(); } pgRegionCapture.SelectedObject = TaskSettings.CaptureSettings.SurfaceOptions; // Capture / Rectangle annotate if (TaskSettings.CaptureSettings.RectangleAnnotateOptions == null) { TaskSettings.CaptureSettings.RectangleAnnotateOptions = new RectangleAnnotateOptions(); } pgRectangleAnnotate.SelectedObject = TaskSettings.CaptureSettings.RectangleAnnotateOptions; // Capture / Screen recorder chkRunScreencastCLI.Checked = cboEncoder.Enabled = btnEncoderConfig.Enabled = TaskSettings.CaptureSettings.RunScreencastCLI; UpdateVideoEncoders(); nudScreenRecordFPS.Value = TaskSettings.CaptureSettings.ScreenRecordFPS.Between((int)nudScreenRecordFPS.Minimum, (int)nudScreenRecordFPS.Maximum); nudGIFFPS.Value = TaskSettings.CaptureSettings.GIFFPS.Between((int)nudGIFFPS.Minimum, (int)nudGIFFPS.Maximum); cbScreenRecorderFixedDuration.Checked = nudScreenRecorderDuration.Enabled = TaskSettings.CaptureSettings.ScreenRecordFixedDuration; nudScreenRecorderDuration.Value = (decimal)TaskSettings.CaptureSettings.ScreenRecordDuration; chkScreenRecordAutoStart.Checked = nudScreenRecorderStartDelay.Enabled = TaskSettings.CaptureSettings.ScreenRecordAutoStart; nudScreenRecorderStartDelay.Value = (decimal)TaskSettings.CaptureSettings.ScreenRecordStartDelay; cbScreenRecordAutoDisableAero.Checked = TaskSettings.CaptureSettings.ScreenRecordAutoDisableAero; // Actions TaskHelpers.AddDefaultExternalPrograms(TaskSettings); TaskSettings.ExternalPrograms.ForEach(AddFileAction); // Watch folders cbWatchFolderEnabled.Checked = TaskSettings.WatchFolderEnabled; if (TaskSettings.WatchFolderList == null) { TaskSettings.WatchFolderList = new List <WatchFolderSettings>(); } else { foreach (WatchFolderSettings watchFolder in TaskSettings.WatchFolderList) { AddWatchFolder(watchFolder); } } // Upload / Name pattern txtNameFormatPattern.Text = TaskSettings.UploadSettings.NameFormatPattern; txtNameFormatPatternActiveWindow.Text = TaskSettings.UploadSettings.NameFormatPatternActiveWindow; CodeMenu.Create <ReplCodeMenuEntry>(txtNameFormatPattern, ReplCodeMenuEntry.n, ReplCodeMenuEntry.t, ReplCodeMenuEntry.pn); CodeMenu.Create <ReplCodeMenuEntry>(txtNameFormatPatternActiveWindow, ReplCodeMenuEntry.n); cbFileUploadUseNamePattern.Checked = TaskSettings.UploadSettings.FileUploadUseNamePattern; // Upload / Clipboard upload chkClipboardUploadURLContents.Checked = TaskSettings.UploadSettings.ClipboardUploadURLContents; cbClipboardUploadShortenURL.Checked = TaskSettings.UploadSettings.ClipboardUploadShortenURL; cbClipboardUploadShareURL.Checked = TaskSettings.UploadSettings.ClipboardUploadShareURL; cbClipboardUploadAutoIndexFolder.Checked = TaskSettings.UploadSettings.ClipboardUploadAutoIndexFolder; // Indexer pgIndexerConfig.SelectedObject = TaskSettings.IndexerSettings; // Advanced pgTaskSettings.SelectedObject = TaskSettings.AdvancedSettings; tttvMain.MainTabControl = tcTaskSettings; UpdateDefaultSettingVisibility(); loaded = true; }