2013-11-03 23:53:49 +13:00
|
|
|
|
#region License Information (GPL v3)
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
ShareX - A program that allows you to take screenshots and share any file type
|
2020-02-05 20:19:48 +13:00
|
|
|
|
Copyright (c) 2007-2020 ShareX Team
|
2013-11-03 23:53:49 +13:00
|
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
|
|
|
|
|
Optionally you can also view the license at <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#endregion License Information (GPL v3)
|
|
|
|
|
|
2014-12-11 09:25:20 +13:00
|
|
|
|
using ShareX.HelpersLib;
|
2016-02-22 08:50:49 +13:00
|
|
|
|
using ShareX.HistoryLib;
|
2014-12-11 09:25:20 +13:00
|
|
|
|
using ShareX.ImageEffectsLib;
|
2016-02-03 01:58:34 +13:00
|
|
|
|
using ShareX.IndexerLib;
|
2015-08-04 23:47:34 +12:00
|
|
|
|
using ShareX.MediaLib;
|
2014-10-17 22:58:15 +13:00
|
|
|
|
using ShareX.Properties;
|
2014-12-11 12:19:28 +13:00
|
|
|
|
using ShareX.ScreenCaptureLib;
|
|
|
|
|
using ShareX.UploadersLib;
|
2018-11-15 14:10:54 +13:00
|
|
|
|
using ShareX.UploadersLib.OtherServices;
|
2017-03-18 18:41:02 +13:00
|
|
|
|
using ShareX.UploadersLib.SharingServices;
|
2014-12-18 07:24:27 +13:00
|
|
|
|
using System;
|
2013-11-03 23:53:49 +13:00
|
|
|
|
using System.Collections.Generic;
|
2014-05-03 05:56:51 +12:00
|
|
|
|
using System.Diagnostics;
|
2013-11-03 23:53:49 +13:00
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Drawing.Imaging;
|
|
|
|
|
using System.IO;
|
2018-01-25 20:45:56 +13:00
|
|
|
|
using System.Linq;
|
2018-02-26 19:26:35 +13:00
|
|
|
|
using System.Text;
|
2017-10-31 00:14:13 +13:00
|
|
|
|
using System.Threading;
|
2018-08-03 23:01:12 +12:00
|
|
|
|
using System.Threading.Tasks;
|
2013-11-03 23:53:49 +13:00
|
|
|
|
using System.Windows.Forms;
|
2018-01-25 20:45:56 +13:00
|
|
|
|
using ZXing;
|
|
|
|
|
using ZXing.Common;
|
|
|
|
|
using ZXing.QrCode;
|
|
|
|
|
using ZXing.Rendering;
|
2013-11-03 23:53:49 +13:00
|
|
|
|
|
|
|
|
|
namespace ShareX
|
|
|
|
|
{
|
|
|
|
|
public static class TaskHelpers
|
|
|
|
|
{
|
2016-11-01 09:55:12 +13:00
|
|
|
|
public static void ExecuteJob(HotkeyType job, CLICommand command = null)
|
|
|
|
|
{
|
|
|
|
|
ExecuteJob(Program.DefaultTaskSettings, job, command);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void ExecuteJob(TaskSettings taskSettings)
|
|
|
|
|
{
|
|
|
|
|
ExecuteJob(taskSettings, taskSettings.Job);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void ExecuteJob(TaskSettings taskSettings, HotkeyType job, CLICommand command = null)
|
|
|
|
|
{
|
|
|
|
|
if (job == HotkeyType.None) return;
|
|
|
|
|
|
|
|
|
|
DebugHelper.WriteLine("Executing: " + job.GetLocalizedDescription());
|
|
|
|
|
|
|
|
|
|
TaskSettings safeTaskSettings = TaskSettings.GetSafeTaskSettings(taskSettings);
|
|
|
|
|
|
|
|
|
|
switch (job)
|
|
|
|
|
{
|
|
|
|
|
// Upload
|
|
|
|
|
case HotkeyType.FileUpload:
|
|
|
|
|
UploadManager.UploadFile(safeTaskSettings);
|
|
|
|
|
break;
|
|
|
|
|
case HotkeyType.FolderUpload:
|
|
|
|
|
UploadManager.UploadFolder(safeTaskSettings);
|
|
|
|
|
break;
|
|
|
|
|
case HotkeyType.ClipboardUpload:
|
|
|
|
|
UploadManager.ClipboardUpload(safeTaskSettings);
|
|
|
|
|
break;
|
|
|
|
|
case HotkeyType.ClipboardUploadWithContentViewer:
|
|
|
|
|
UploadManager.ClipboardUploadWithContentViewer(safeTaskSettings);
|
|
|
|
|
break;
|
2017-09-03 02:13:26 +12:00
|
|
|
|
case HotkeyType.UploadText:
|
|
|
|
|
UploadManager.ShowTextUploadDialog(safeTaskSettings);
|
|
|
|
|
break;
|
2016-11-01 09:55:12 +13:00
|
|
|
|
case HotkeyType.UploadURL:
|
|
|
|
|
UploadManager.UploadURL(safeTaskSettings);
|
|
|
|
|
break;
|
|
|
|
|
case HotkeyType.DragDropUpload:
|
|
|
|
|
OpenDropWindow(safeTaskSettings);
|
|
|
|
|
break;
|
2017-09-03 02:13:26 +12:00
|
|
|
|
case HotkeyType.ShortenURL:
|
|
|
|
|
UploadManager.ShowShortenURLDialog(safeTaskSettings);
|
|
|
|
|
break;
|
2016-11-01 09:55:12 +13:00
|
|
|
|
case HotkeyType.StopUploads:
|
|
|
|
|
TaskManager.StopAllTasks();
|
|
|
|
|
break;
|
|
|
|
|
// Screen capture
|
|
|
|
|
case HotkeyType.PrintScreen:
|
2017-02-28 21:34:08 +13:00
|
|
|
|
new CaptureFullscreen().Capture(safeTaskSettings);
|
2016-11-01 09:55:12 +13:00
|
|
|
|
break;
|
|
|
|
|
case HotkeyType.ActiveWindow:
|
2017-02-28 21:34:08 +13:00
|
|
|
|
new CaptureActiveWindow().Capture(safeTaskSettings);
|
2016-11-01 09:55:12 +13:00
|
|
|
|
break;
|
|
|
|
|
case HotkeyType.ActiveMonitor:
|
2017-02-28 21:34:08 +13:00
|
|
|
|
new CaptureActiveMonitor().Capture(safeTaskSettings);
|
2016-11-01 09:55:12 +13:00
|
|
|
|
break;
|
|
|
|
|
case HotkeyType.RectangleRegion:
|
2017-02-28 21:34:08 +13:00
|
|
|
|
new CaptureRegion().Capture(safeTaskSettings);
|
2016-11-01 09:55:12 +13:00
|
|
|
|
break;
|
|
|
|
|
case HotkeyType.RectangleLight:
|
2017-02-28 21:34:08 +13:00
|
|
|
|
new CaptureRegion(RegionCaptureType.Light).Capture(safeTaskSettings);
|
2016-11-01 09:55:12 +13:00
|
|
|
|
break;
|
|
|
|
|
case HotkeyType.RectangleTransparent:
|
2017-02-28 21:34:08 +13:00
|
|
|
|
new CaptureRegion(RegionCaptureType.Transparent).Capture(safeTaskSettings);
|
2016-11-01 09:55:12 +13:00
|
|
|
|
break;
|
|
|
|
|
case HotkeyType.CustomRegion:
|
2017-02-28 21:34:08 +13:00
|
|
|
|
new CaptureCustomRegion().Capture(safeTaskSettings);
|
2016-11-01 09:55:12 +13:00
|
|
|
|
break;
|
|
|
|
|
case HotkeyType.LastRegion:
|
2017-02-28 21:34:08 +13:00
|
|
|
|
new CaptureLastRegion().Capture(safeTaskSettings);
|
2016-11-01 09:55:12 +13:00
|
|
|
|
break;
|
|
|
|
|
case HotkeyType.ScrollingCapture:
|
|
|
|
|
OpenScrollingCapture(safeTaskSettings, true);
|
|
|
|
|
break;
|
|
|
|
|
case HotkeyType.TextCapture:
|
2018-11-30 20:43:56 +13:00
|
|
|
|
_ = OCRImage(safeTaskSettings);
|
2016-11-01 09:55:12 +13:00
|
|
|
|
break;
|
|
|
|
|
case HotkeyType.AutoCapture:
|
2018-04-02 23:43:29 +12:00
|
|
|
|
OpenAutoCapture(safeTaskSettings);
|
2016-11-01 09:55:12 +13:00
|
|
|
|
break;
|
|
|
|
|
case HotkeyType.StartAutoCapture:
|
2018-04-02 23:43:29 +12:00
|
|
|
|
StartAutoCapture(safeTaskSettings);
|
2016-11-01 09:55:12 +13:00
|
|
|
|
break;
|
|
|
|
|
// Screen record
|
|
|
|
|
case HotkeyType.ScreenRecorder:
|
|
|
|
|
StartScreenRecording(ScreenRecordOutput.FFmpeg, ScreenRecordStartMethod.Region, safeTaskSettings);
|
|
|
|
|
break;
|
|
|
|
|
case HotkeyType.ScreenRecorderActiveWindow:
|
|
|
|
|
StartScreenRecording(ScreenRecordOutput.FFmpeg, ScreenRecordStartMethod.ActiveWindow, safeTaskSettings);
|
|
|
|
|
break;
|
|
|
|
|
case HotkeyType.ScreenRecorderCustomRegion:
|
|
|
|
|
StartScreenRecording(ScreenRecordOutput.FFmpeg, ScreenRecordStartMethod.CustomRegion, safeTaskSettings);
|
|
|
|
|
break;
|
|
|
|
|
case HotkeyType.StartScreenRecorder:
|
|
|
|
|
StartScreenRecording(ScreenRecordOutput.FFmpeg, ScreenRecordStartMethod.LastRegion, safeTaskSettings);
|
|
|
|
|
break;
|
|
|
|
|
case HotkeyType.ScreenRecorderGIF:
|
|
|
|
|
StartScreenRecording(ScreenRecordOutput.GIF, ScreenRecordStartMethod.Region, safeTaskSettings);
|
|
|
|
|
break;
|
|
|
|
|
case HotkeyType.ScreenRecorderGIFActiveWindow:
|
|
|
|
|
StartScreenRecording(ScreenRecordOutput.GIF, ScreenRecordStartMethod.ActiveWindow, safeTaskSettings);
|
|
|
|
|
break;
|
|
|
|
|
case HotkeyType.ScreenRecorderGIFCustomRegion:
|
|
|
|
|
StartScreenRecording(ScreenRecordOutput.GIF, ScreenRecordStartMethod.CustomRegion, safeTaskSettings);
|
|
|
|
|
break;
|
|
|
|
|
case HotkeyType.StartScreenRecorderGIF:
|
|
|
|
|
StartScreenRecording(ScreenRecordOutput.GIF, ScreenRecordStartMethod.LastRegion, safeTaskSettings);
|
|
|
|
|
break;
|
|
|
|
|
case HotkeyType.AbortScreenRecording:
|
|
|
|
|
AbortScreenRecording();
|
|
|
|
|
break;
|
|
|
|
|
// Tools
|
|
|
|
|
case HotkeyType.ColorPicker:
|
2018-04-19 04:29:02 +12:00
|
|
|
|
ShowScreenColorPickerDialog(safeTaskSettings);
|
2016-11-01 09:55:12 +13:00
|
|
|
|
break;
|
|
|
|
|
case HotkeyType.ScreenColorPicker:
|
|
|
|
|
OpenScreenColorPicker(safeTaskSettings);
|
|
|
|
|
break;
|
|
|
|
|
case HotkeyType.ImageEditor:
|
|
|
|
|
if (command != null && !string.IsNullOrEmpty(command.Parameter) && File.Exists(command.Parameter))
|
|
|
|
|
{
|
2017-12-27 00:46:29 +13:00
|
|
|
|
AnnotateImageFromFile(command.Parameter, safeTaskSettings);
|
2016-11-01 09:55:12 +13:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2017-12-27 00:46:29 +13:00
|
|
|
|
OpenImageEditor(safeTaskSettings);
|
2016-11-01 09:55:12 +13:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case HotkeyType.ImageEffects:
|
2020-08-03 00:46:40 +12:00
|
|
|
|
if (command != null && !string.IsNullOrEmpty(command.Parameter) && File.Exists(command.Parameter))
|
|
|
|
|
{
|
|
|
|
|
OpenImageEffects(command.Parameter, taskSettings);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
OpenImageEffects(taskSettings);
|
|
|
|
|
}
|
2016-11-01 09:55:12 +13:00
|
|
|
|
break;
|
|
|
|
|
case HotkeyType.HashCheck:
|
|
|
|
|
OpenHashCheck();
|
|
|
|
|
break;
|
|
|
|
|
case HotkeyType.DNSChanger:
|
|
|
|
|
OpenDNSChanger();
|
|
|
|
|
break;
|
|
|
|
|
case HotkeyType.QRCode:
|
|
|
|
|
OpenQRCode();
|
|
|
|
|
break;
|
2020-07-20 02:30:21 +12:00
|
|
|
|
case HotkeyType.QRCodeDecodeFromScreen:
|
|
|
|
|
OpenQRCodeDecodeFromScreen();
|
|
|
|
|
break;
|
2016-11-01 09:55:12 +13:00
|
|
|
|
case HotkeyType.Ruler:
|
|
|
|
|
OpenRuler(safeTaskSettings);
|
|
|
|
|
break;
|
|
|
|
|
case HotkeyType.IndexFolder:
|
|
|
|
|
UploadManager.IndexFolder();
|
|
|
|
|
break;
|
|
|
|
|
case HotkeyType.ImageCombiner:
|
|
|
|
|
OpenImageCombiner(safeTaskSettings);
|
|
|
|
|
break;
|
2020-04-06 05:57:10 +12:00
|
|
|
|
case HotkeyType.ImageSplitter:
|
|
|
|
|
OpenImageSplitter();
|
|
|
|
|
break;
|
|
|
|
|
case HotkeyType.ImageThumbnailer:
|
|
|
|
|
OpenImageThumbnailer();
|
|
|
|
|
break;
|
|
|
|
|
case HotkeyType.VideoConverter:
|
|
|
|
|
OpenVideoConverter(safeTaskSettings);
|
|
|
|
|
break;
|
2016-11-01 09:55:12 +13:00
|
|
|
|
case HotkeyType.VideoThumbnailer:
|
|
|
|
|
OpenVideoThumbnailer(safeTaskSettings);
|
|
|
|
|
break;
|
|
|
|
|
case HotkeyType.TweetMessage:
|
|
|
|
|
TweetMessage();
|
|
|
|
|
break;
|
|
|
|
|
case HotkeyType.MonitorTest:
|
|
|
|
|
OpenMonitorTest();
|
|
|
|
|
break;
|
|
|
|
|
// Other
|
|
|
|
|
case HotkeyType.DisableHotkeys:
|
|
|
|
|
ToggleHotkeys();
|
|
|
|
|
break;
|
|
|
|
|
case HotkeyType.OpenMainWindow:
|
|
|
|
|
Program.MainForm.ForceActivate();
|
|
|
|
|
break;
|
|
|
|
|
case HotkeyType.OpenScreenshotsFolder:
|
|
|
|
|
OpenScreenshotsFolder();
|
|
|
|
|
break;
|
|
|
|
|
case HotkeyType.OpenHistory:
|
|
|
|
|
OpenHistory();
|
|
|
|
|
break;
|
|
|
|
|
case HotkeyType.OpenImageHistory:
|
|
|
|
|
OpenImageHistory();
|
|
|
|
|
break;
|
2017-01-23 00:15:47 +13:00
|
|
|
|
case HotkeyType.ToggleActionsToolbar:
|
|
|
|
|
ToggleActionsToolbar();
|
|
|
|
|
break;
|
2017-01-23 01:41:20 +13:00
|
|
|
|
case HotkeyType.ExitShareX:
|
|
|
|
|
Program.MainForm.ForceClose();
|
|
|
|
|
break;
|
2016-11-01 09:55:12 +13:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-03 23:53:49 +13:00
|
|
|
|
public static ImageData PrepareImage(Image img, TaskSettings taskSettings)
|
|
|
|
|
{
|
|
|
|
|
ImageData imageData = new ImageData();
|
2016-09-19 03:28:57 +12:00
|
|
|
|
imageData.ImageStream = SaveImageAsStream(img, taskSettings.ImageSettings.ImageFormat, taskSettings);
|
2016-07-22 19:22:18 +12:00
|
|
|
|
imageData.ImageFormat = taskSettings.ImageSettings.ImageFormat;
|
2013-11-03 23:53:49 +13:00
|
|
|
|
|
2016-07-22 19:22:18 +12:00
|
|
|
|
if (taskSettings.ImageSettings.ImageAutoUseJPEG && taskSettings.ImageSettings.ImageFormat != EImageFormat.JPEG &&
|
|
|
|
|
imageData.ImageStream.Length > taskSettings.ImageSettings.ImageAutoUseJPEGSize * 1000)
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2016-09-19 03:28:57 +12:00
|
|
|
|
imageData.ImageStream.Dispose();
|
|
|
|
|
imageData.ImageStream = SaveImageAsStream(img, EImageFormat.JPEG, taskSettings);
|
2016-07-22 19:22:18 +12:00
|
|
|
|
imageData.ImageFormat = EImageFormat.JPEG;
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return imageData;
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-22 11:07:38 +13:00
|
|
|
|
public static string CreateThumbnail(Bitmap bmp, string folder, string filename, TaskSettings taskSettings)
|
2014-04-23 08:44:58 +12:00
|
|
|
|
{
|
2014-05-11 23:47:37 +12:00
|
|
|
|
if ((taskSettings.ImageSettings.ThumbnailWidth > 0 || taskSettings.ImageSettings.ThumbnailHeight > 0) && (!taskSettings.ImageSettings.ThumbnailCheckSize ||
|
2020-03-22 11:07:38 +13:00
|
|
|
|
(bmp.Width > taskSettings.ImageSettings.ThumbnailWidth && bmp.Height > taskSettings.ImageSettings.ThumbnailHeight)))
|
2014-04-23 08:44:58 +12:00
|
|
|
|
{
|
2014-05-11 23:47:37 +12:00
|
|
|
|
string thumbnailFileName = Path.GetFileNameWithoutExtension(filename) + taskSettings.ImageSettings.ThumbnailName + ".jpg";
|
2018-07-16 21:44:23 +12:00
|
|
|
|
string thumbnailFilePath = HandleExistsFile(folder, thumbnailFileName, taskSettings);
|
2014-04-23 08:44:58 +12:00
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(thumbnailFilePath))
|
|
|
|
|
{
|
2020-03-22 11:07:38 +13:00
|
|
|
|
Bitmap thumbnail = null;
|
2014-04-23 08:44:58 +12:00
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
2020-03-22 11:07:38 +13:00
|
|
|
|
thumbnail = (Bitmap)bmp.Clone();
|
|
|
|
|
thumbnail = new Resize(taskSettings.ImageSettings.ThumbnailWidth, taskSettings.ImageSettings.ThumbnailHeight).Apply(thumbnail);
|
|
|
|
|
thumbnail = ImageHelpers.FillBackground(thumbnail, Color.White);
|
|
|
|
|
thumbnail.SaveJPG(thumbnailFilePath, 90);
|
2014-04-23 09:00:41 +12:00
|
|
|
|
return thumbnailFilePath;
|
2014-04-23 08:44:58 +12:00
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
2020-03-22 11:07:38 +13:00
|
|
|
|
if (thumbnail != null)
|
2014-04-23 08:44:58 +12:00
|
|
|
|
{
|
2020-03-22 11:07:38 +13:00
|
|
|
|
thumbnail.Dispose();
|
2014-04-23 08:44:58 +12:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-23 09:00:41 +12:00
|
|
|
|
return null;
|
2014-04-23 08:44:58 +12:00
|
|
|
|
}
|
|
|
|
|
|
2016-09-19 03:28:57 +12:00
|
|
|
|
public static MemoryStream SaveImageAsStream(Image img, EImageFormat imageFormat, TaskSettings taskSettings)
|
2016-05-13 17:56:33 +12:00
|
|
|
|
{
|
2017-06-18 22:47:37 +12:00
|
|
|
|
return SaveImageAsStream(img, imageFormat, taskSettings.ImageSettings.ImagePNGBitDepth,
|
|
|
|
|
taskSettings.ImageSettings.ImageJPEGQuality, taskSettings.ImageSettings.ImageGIFQuality);
|
2016-05-13 17:56:33 +12:00
|
|
|
|
}
|
|
|
|
|
|
2017-06-18 22:47:37 +12:00
|
|
|
|
public static MemoryStream SaveImageAsStream(Image img, EImageFormat imageFormat, PNGBitDepth pngBitDepth = PNGBitDepth.Automatic,
|
|
|
|
|
int jpegQuality = 90, GIFQuality gifQuality = GIFQuality.Default)
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
|
|
|
|
MemoryStream stream = new MemoryStream();
|
|
|
|
|
|
|
|
|
|
switch (imageFormat)
|
|
|
|
|
{
|
|
|
|
|
case EImageFormat.PNG:
|
2017-06-18 22:47:37 +12:00
|
|
|
|
SaveImageAsPNGStream(img, stream, pngBitDepth);
|
2018-11-13 21:10:33 +13:00
|
|
|
|
|
|
|
|
|
if (Program.Settings.PNGStripColorSpaceInformation)
|
|
|
|
|
{
|
|
|
|
|
using (stream)
|
|
|
|
|
{
|
|
|
|
|
return PNGStripColorSpaceInformation(stream);
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-11-03 23:53:49 +13:00
|
|
|
|
break;
|
|
|
|
|
case EImageFormat.JPEG:
|
2017-06-18 22:47:37 +12:00
|
|
|
|
SaveImageAsJPEGStream(img, stream, jpegQuality);
|
2013-11-03 23:53:49 +13:00
|
|
|
|
break;
|
|
|
|
|
case EImageFormat.GIF:
|
2016-05-13 17:56:33 +12:00
|
|
|
|
img.SaveGIF(stream, gifQuality);
|
2013-11-03 23:53:49 +13:00
|
|
|
|
break;
|
|
|
|
|
case EImageFormat.BMP:
|
|
|
|
|
img.Save(stream, ImageFormat.Bmp);
|
|
|
|
|
break;
|
|
|
|
|
case EImageFormat.TIFF:
|
|
|
|
|
img.Save(stream, ImageFormat.Tiff);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return stream;
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-18 22:47:37 +12:00
|
|
|
|
private static void SaveImageAsPNGStream(Image img, Stream stream, PNGBitDepth bitDepth)
|
|
|
|
|
{
|
|
|
|
|
if (bitDepth == PNGBitDepth.Automatic)
|
|
|
|
|
{
|
|
|
|
|
if (ImageHelpers.IsImageTransparent((Bitmap)img))
|
|
|
|
|
{
|
|
|
|
|
bitDepth = PNGBitDepth.Bit32;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
bitDepth = PNGBitDepth.Bit24;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (bitDepth == PNGBitDepth.Bit32)
|
|
|
|
|
{
|
|
|
|
|
if (img.PixelFormat != PixelFormat.Format32bppArgb && img.PixelFormat != PixelFormat.Format32bppRgb)
|
|
|
|
|
{
|
|
|
|
|
using (Bitmap bmpNew = ((Bitmap)img).Clone(new Rectangle(0, 0, img.Width, img.Height), PixelFormat.Format32bppArgb))
|
|
|
|
|
{
|
|
|
|
|
bmpNew.Save(stream, ImageFormat.Png);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (bitDepth == PNGBitDepth.Bit24)
|
|
|
|
|
{
|
|
|
|
|
if (img.PixelFormat != PixelFormat.Format24bppRgb)
|
|
|
|
|
{
|
|
|
|
|
using (Bitmap bmpNew = ((Bitmap)img).Clone(new Rectangle(0, 0, img.Width, img.Height), PixelFormat.Format24bppRgb))
|
|
|
|
|
{
|
|
|
|
|
bmpNew.Save(stream, ImageFormat.Png);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
img.Save(stream, ImageFormat.Png);
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-13 21:10:33 +13:00
|
|
|
|
private static MemoryStream PNGStripChunks(MemoryStream stream, params string[] chunks)
|
|
|
|
|
{
|
|
|
|
|
MemoryStream output = new MemoryStream();
|
|
|
|
|
stream.Seek(0, SeekOrigin.Begin);
|
|
|
|
|
|
|
|
|
|
byte[] signature = new byte[8];
|
|
|
|
|
stream.Read(signature, 0, 8);
|
|
|
|
|
output.Write(signature, 0, 8);
|
|
|
|
|
|
|
|
|
|
while (true)
|
|
|
|
|
{
|
|
|
|
|
byte[] lenBytes = new byte[4];
|
|
|
|
|
if (stream.Read(lenBytes, 0, 4) != 4)
|
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (BitConverter.IsLittleEndian)
|
|
|
|
|
{
|
|
|
|
|
Array.Reverse(lenBytes);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int len = BitConverter.ToInt32(lenBytes, 0);
|
|
|
|
|
|
|
|
|
|
if (BitConverter.IsLittleEndian)
|
|
|
|
|
{
|
|
|
|
|
Array.Reverse(lenBytes);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
byte[] type = new byte[4];
|
|
|
|
|
stream.Read(type, 0, 4);
|
|
|
|
|
|
|
|
|
|
byte[] data = new byte[len + 4];
|
|
|
|
|
stream.Read(data, 0, data.Length);
|
|
|
|
|
|
|
|
|
|
string strType = Encoding.ASCII.GetString(type);
|
|
|
|
|
|
|
|
|
|
if (!chunks.Contains(strType))
|
|
|
|
|
{
|
|
|
|
|
output.Write(lenBytes, 0, lenBytes.Length);
|
|
|
|
|
output.Write(type, 0, type.Length);
|
|
|
|
|
output.Write(data, 0, data.Length);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return output;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static MemoryStream PNGStripColorSpaceInformation(MemoryStream stream)
|
|
|
|
|
{
|
|
|
|
|
// http://www.libpng.org/pub/png/spec/1.2/PNG-Chunks.html
|
|
|
|
|
// 4.2.2.1. gAMA Image gamma
|
|
|
|
|
// 4.2.2.2. cHRM Primary chromaticities
|
|
|
|
|
// 4.2.2.3. sRGB Standard RGB color space
|
|
|
|
|
// 4.2.2.4. iCCP Embedded ICC profile
|
|
|
|
|
return PNGStripChunks(stream, "gAMA", "cHRM", "sRGB", "iCCP");
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-18 22:47:37 +12:00
|
|
|
|
private static void SaveImageAsJPEGStream(Image img, Stream stream, int jpegQuality)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
img = (Image)img.Clone();
|
|
|
|
|
img = ImageHelpers.FillBackground(img, Color.White);
|
|
|
|
|
img.SaveJPG(stream, jpegQuality);
|
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
if (img != null) img.Dispose();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-24 08:33:26 +13:00
|
|
|
|
public static void SaveImageAsFile(Bitmap bmp, TaskSettings taskSettings, bool overwriteFile = false)
|
2016-09-19 03:28:57 +12:00
|
|
|
|
{
|
2020-03-24 08:33:26 +13:00
|
|
|
|
using (ImageData imageData = PrepareImage(bmp, taskSettings))
|
2016-09-19 03:28:57 +12:00
|
|
|
|
{
|
2020-03-24 08:33:26 +13:00
|
|
|
|
string fileName = GetFilename(taskSettings, imageData.ImageFormat.GetDescription(), bmp);
|
2020-04-23 00:26:04 +12:00
|
|
|
|
string filePath = Path.Combine(taskSettings.GetScreenshotsFolder(), fileName);
|
2018-07-16 21:44:23 +12:00
|
|
|
|
|
|
|
|
|
if (!overwriteFile)
|
|
|
|
|
{
|
|
|
|
|
filePath = HandleExistsFile(filePath, taskSettings);
|
|
|
|
|
}
|
2016-09-19 03:28:57 +12:00
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(filePath))
|
|
|
|
|
{
|
|
|
|
|
imageData.Write(filePath);
|
|
|
|
|
DebugHelper.WriteLine("Image saved to file: " + filePath);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-24 08:33:26 +13:00
|
|
|
|
public static string GetFilename(TaskSettings taskSettings, string extension, Bitmap bmp)
|
2017-02-27 11:48:18 +13:00
|
|
|
|
{
|
2020-03-24 08:33:26 +13:00
|
|
|
|
ImageInfo imageInfo = new ImageInfo(bmp);
|
2017-02-27 11:48:18 +13:00
|
|
|
|
return GetFilename(taskSettings, extension, imageInfo);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static string GetFilename(TaskSettings taskSettings, string extension = null, ImageInfo imageInfo = null)
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
|
|
|
|
string filename;
|
|
|
|
|
|
2014-01-13 19:38:53 +13:00
|
|
|
|
NameParser nameParser = new NameParser(NameParserType.FileName)
|
|
|
|
|
{
|
|
|
|
|
AutoIncrementNumber = Program.Settings.NameParserAutoIncrementNumber,
|
2014-05-11 23:47:37 +12:00
|
|
|
|
MaxNameLength = taskSettings.AdvancedSettings.NamePatternMaxLength,
|
2015-03-12 11:35:31 +13:00
|
|
|
|
MaxTitleLength = taskSettings.AdvancedSettings.NamePatternMaxTitleLength,
|
|
|
|
|
CustomTimeZone = taskSettings.UploadSettings.UseCustomTimeZone ? taskSettings.UploadSettings.CustomTimeZone : null
|
2014-01-13 19:38:53 +13:00
|
|
|
|
};
|
2013-11-03 23:53:49 +13:00
|
|
|
|
|
2017-03-01 23:32:41 +13:00
|
|
|
|
if (imageInfo != null)
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2017-03-01 23:32:41 +13:00
|
|
|
|
if (imageInfo.Image != null)
|
|
|
|
|
{
|
|
|
|
|
nameParser.ImageWidth = imageInfo.Image.Width;
|
|
|
|
|
nameParser.ImageHeight = imageInfo.Image.Height;
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-27 11:48:18 +13:00
|
|
|
|
nameParser.WindowText = imageInfo.WindowTitle;
|
|
|
|
|
nameParser.ProcessName = imageInfo.ProcessName;
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
|
2015-10-22 12:52:41 +13:00
|
|
|
|
if (!string.IsNullOrEmpty(nameParser.WindowText))
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2015-10-22 12:52:41 +13:00
|
|
|
|
filename = nameParser.Parse(taskSettings.UploadSettings.NameFormatPatternActiveWindow);
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2015-10-22 12:52:41 +13:00
|
|
|
|
filename = nameParser.Parse(taskSettings.UploadSettings.NameFormatPattern);
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Program.Settings.NameParserAutoIncrementNumber = nameParser.AutoIncrementNumber;
|
|
|
|
|
|
2015-10-22 12:52:41 +13:00
|
|
|
|
if (!string.IsNullOrEmpty(extension))
|
|
|
|
|
{
|
|
|
|
|
filename += "." + extension.TrimStart('.');
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-03 23:53:49 +13:00
|
|
|
|
return filename;
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-27 11:48:18 +13:00
|
|
|
|
public static bool ShowAfterCaptureForm(TaskSettings taskSettings, out string fileName, ImageInfo imageInfo = null, string filePath = null)
|
2014-07-19 07:13:32 +12:00
|
|
|
|
{
|
2015-10-23 11:43:04 +13:00
|
|
|
|
fileName = null;
|
|
|
|
|
|
2015-12-04 04:18:46 +13:00
|
|
|
|
if (taskSettings.AfterCaptureJob.HasFlag(AfterCaptureTasks.ShowAfterCaptureWindow))
|
2014-07-19 07:13:32 +12:00
|
|
|
|
{
|
2016-10-01 00:22:51 +13:00
|
|
|
|
AfterCaptureForm afterCaptureForm = null;
|
|
|
|
|
|
|
|
|
|
try
|
2014-07-19 07:13:32 +12:00
|
|
|
|
{
|
2016-10-01 00:22:51 +13:00
|
|
|
|
if (!string.IsNullOrEmpty(filePath))
|
|
|
|
|
{
|
|
|
|
|
afterCaptureForm = new AfterCaptureForm(filePath, taskSettings);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2017-02-27 11:48:18 +13:00
|
|
|
|
afterCaptureForm = new AfterCaptureForm(imageInfo, taskSettings);
|
2016-10-01 00:22:51 +13:00
|
|
|
|
}
|
|
|
|
|
|
2015-10-23 11:43:04 +13:00
|
|
|
|
if (afterCaptureForm.ShowDialog() == DialogResult.Cancel)
|
2014-07-19 07:13:32 +12:00
|
|
|
|
{
|
2017-02-27 11:48:18 +13:00
|
|
|
|
if (imageInfo != null)
|
2016-10-01 00:22:51 +13:00
|
|
|
|
{
|
2017-02-27 11:48:18 +13:00
|
|
|
|
imageInfo.Dispose();
|
2016-10-01 00:22:51 +13:00
|
|
|
|
}
|
|
|
|
|
|
2015-10-23 11:43:04 +13:00
|
|
|
|
return false;
|
2014-07-19 07:13:32 +12:00
|
|
|
|
}
|
2015-10-23 11:43:04 +13:00
|
|
|
|
|
|
|
|
|
fileName = afterCaptureForm.FileName;
|
2014-07-19 07:13:32 +12:00
|
|
|
|
}
|
2016-10-01 00:22:51 +13:00
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
afterCaptureForm.Dispose();
|
|
|
|
|
}
|
2014-07-19 07:13:32 +12:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-26 17:58:04 +12:00
|
|
|
|
public static void PrintImage(Image img)
|
|
|
|
|
{
|
|
|
|
|
if (Program.Settings.DontShowPrintSettingsDialog)
|
|
|
|
|
{
|
|
|
|
|
using (PrintHelper printHelper = new PrintHelper(img))
|
|
|
|
|
{
|
|
|
|
|
printHelper.Settings = Program.Settings.PrintSettings;
|
|
|
|
|
printHelper.Print();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
using (PrintForm printForm = new PrintForm(img, Program.Settings.PrintSettings))
|
|
|
|
|
{
|
|
|
|
|
printForm.ShowDialog();
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
|
2020-07-06 10:37:56 +12:00
|
|
|
|
public static Bitmap ApplyImageEffects(Bitmap bmp, TaskSettingsImage taskSettingsImage)
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2020-03-21 08:02:26 +13:00
|
|
|
|
if (bmp != null && !bmp.PixelFormat.HasFlag(PixelFormat.Indexed))
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2018-01-06 13:46:37 +13:00
|
|
|
|
if (taskSettingsImage.ShowImageEffectsWindowAfterCapture)
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2020-03-21 08:02:26 +13:00
|
|
|
|
using (ImageEffectsForm imageEffectsForm = new ImageEffectsForm(bmp, taskSettingsImage.ImageEffectPresets,
|
2018-01-06 13:46:37 +13:00
|
|
|
|
taskSettingsImage.SelectedImageEffectPreset))
|
|
|
|
|
{
|
|
|
|
|
imageEffectsForm.ShowDialog();
|
|
|
|
|
taskSettingsImage.SelectedImageEffectPreset = imageEffectsForm.SelectedPresetIndex;
|
|
|
|
|
}
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
|
2018-01-06 13:46:37 +13:00
|
|
|
|
if (taskSettingsImage.ImageEffectPresets.IsValidIndex(taskSettingsImage.SelectedImageEffectPreset))
|
2017-09-24 00:07:18 +12:00
|
|
|
|
{
|
2020-03-21 08:02:26 +13:00
|
|
|
|
using (bmp)
|
2018-01-06 13:46:37 +13:00
|
|
|
|
{
|
2020-03-21 08:02:26 +13:00
|
|
|
|
return taskSettingsImage.ImageEffectPresets[taskSettingsImage.SelectedImageEffectPreset].ApplyEffects(bmp);
|
2018-01-06 13:46:37 +13:00
|
|
|
|
}
|
2017-09-24 00:07:18 +12:00
|
|
|
|
}
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
2017-09-24 00:07:18 +12:00
|
|
|
|
|
2020-03-21 08:02:26 +13:00
|
|
|
|
return bmp;
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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");
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-21 01:02:51 +12:00
|
|
|
|
private static void AddExternalProgramFromRegistry(TaskSettings taskSettings, string name, string fileName)
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2014-05-11 23:47:37 +12:00
|
|
|
|
if (!taskSettings.ExternalPrograms.Exists(x => x.Name == name))
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2019-09-21 01:02:51 +12:00
|
|
|
|
string filePath = RegistryHelpers.SearchProgramPath(fileName);
|
2013-11-03 23:53:49 +13:00
|
|
|
|
|
2019-09-21 01:02:51 +12:00
|
|
|
|
if (!string.IsNullOrEmpty(filePath))
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2019-09-21 01:02:51 +12:00
|
|
|
|
ExternalProgram externalProgram = new ExternalProgram(name, filePath);
|
2014-05-11 23:47:37 +12:00
|
|
|
|
taskSettings.ExternalPrograms.Add(externalProgram);
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static Icon GetProgressIcon(int percentage)
|
|
|
|
|
{
|
2019-05-24 07:59:16 +12:00
|
|
|
|
percentage = percentage.Clamp(0, 99);
|
2017-05-17 20:26:16 +12:00
|
|
|
|
|
2018-06-09 05:13:14 +12:00
|
|
|
|
Size size = SystemInformation.SmallIconSize;
|
|
|
|
|
using (Bitmap bmp = new Bitmap(size.Width, size.Height))
|
2013-11-03 23:53:49 +13:00
|
|
|
|
using (Graphics g = Graphics.FromImage(bmp))
|
|
|
|
|
{
|
2018-06-09 05:13:14 +12:00
|
|
|
|
int y = (int)(size.Height * (percentage / 100f));
|
2013-11-03 23:53:49 +13:00
|
|
|
|
|
2017-05-17 20:26:16 +12:00
|
|
|
|
if (y > 0)
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2017-05-17 20:26:16 +12:00
|
|
|
|
using (Brush brush = new SolidBrush(Color.FromArgb(16, 116, 193)))
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2018-06-09 05:13:14 +12:00
|
|
|
|
g.FillRectangle(brush, 0, size.Height - 1 - y, size.Width, y);
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-09 05:13:14 +12:00
|
|
|
|
using (Font font = new Font("Arial", 10))
|
2013-11-03 23:53:49 +13:00
|
|
|
|
using (StringFormat sf = new StringFormat { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center })
|
|
|
|
|
{
|
2019-09-20 19:48:45 +12:00
|
|
|
|
g.DrawString(percentage.ToString(), font, Brushes.Black, size.Width / 2f, size.Height / 2f, sf);
|
|
|
|
|
g.DrawString(percentage.ToString(), font, Brushes.White, size.Width / 2f, (size.Height / 2f) - 1, sf);
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Icon.FromHandle(bmp.GetHicon());
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-11-28 12:18:00 +13:00
|
|
|
|
|
2018-07-16 21:44:23 +12:00
|
|
|
|
public static string HandleExistsFile(string folder, string filename, TaskSettings taskSettings)
|
2014-03-13 22:13:02 +13:00
|
|
|
|
{
|
2014-03-13 22:31:03 +13:00
|
|
|
|
string filepath = Path.Combine(folder, filename);
|
2018-07-16 21:44:23 +12:00
|
|
|
|
return HandleExistsFile(filepath, taskSettings);
|
|
|
|
|
}
|
2014-03-13 22:31:03 +13:00
|
|
|
|
|
2018-07-16 21:44:23 +12:00
|
|
|
|
public static string HandleExistsFile(string filepath, TaskSettings taskSettings)
|
|
|
|
|
{
|
2014-03-13 22:13:02 +13:00
|
|
|
|
if (File.Exists(filepath))
|
|
|
|
|
{
|
2014-05-11 23:47:37 +12:00
|
|
|
|
switch (taskSettings.ImageSettings.FileExistAction)
|
2014-03-13 22:13:02 +13:00
|
|
|
|
{
|
2014-03-13 22:31:03 +13:00
|
|
|
|
case FileExistAction.Ask:
|
|
|
|
|
using (FileExistForm form = new FileExistForm(filepath))
|
|
|
|
|
{
|
|
|
|
|
form.ShowDialog();
|
|
|
|
|
filepath = form.Filepath;
|
|
|
|
|
}
|
|
|
|
|
break;
|
2014-03-13 23:05:24 +13:00
|
|
|
|
case FileExistAction.UniqueName:
|
2014-03-13 22:31:03 +13:00
|
|
|
|
filepath = Helpers.GetUniqueFilePath(filepath);
|
|
|
|
|
break;
|
|
|
|
|
case FileExistAction.Cancel:
|
2016-05-25 06:15:45 +12:00
|
|
|
|
filepath = "";
|
2014-03-13 22:31:03 +13:00
|
|
|
|
break;
|
2014-03-13 22:13:02 +13:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return filepath;
|
|
|
|
|
}
|
2013-11-03 23:53:49 +13:00
|
|
|
|
|
2015-07-16 00:02:27 +12:00
|
|
|
|
public static void OpenDropWindow(TaskSettings taskSettings = null)
|
2014-05-03 05:56:51 +12:00
|
|
|
|
{
|
2015-07-16 00:02:27 +12:00
|
|
|
|
DropForm.GetInstance(Program.Settings.DropSize, Program.Settings.DropOffset, Program.Settings.DropAlignment, Program.Settings.DropOpacity,
|
2016-03-10 05:37:54 +13:00
|
|
|
|
Program.Settings.DropHoverOpacity, taskSettings).ForceActivate();
|
2014-05-03 05:56:51 +12:00
|
|
|
|
}
|
|
|
|
|
|
2018-08-04 02:16:36 +12:00
|
|
|
|
public static void StartScreenRecording(ScreenRecordOutput outputType, ScreenRecordStartMethod startMethod, TaskSettings taskSettings = null)
|
2014-05-03 05:56:51 +12:00
|
|
|
|
{
|
|
|
|
|
if (taskSettings == null) taskSettings = TaskSettings.GetDefaultTaskSettings();
|
|
|
|
|
|
2018-08-04 02:16:36 +12:00
|
|
|
|
ScreenRecordManager.StartStopRecording(outputType, startMethod, taskSettings);
|
2014-05-03 05:56:51 +12:00
|
|
|
|
}
|
|
|
|
|
|
2016-07-23 21:39:22 +12:00
|
|
|
|
public static void AbortScreenRecording()
|
|
|
|
|
{
|
|
|
|
|
ScreenRecordManager.AbortRecording();
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-27 20:55:42 +13:00
|
|
|
|
public static void OpenScrollingCapture(TaskSettings taskSettings = null, bool forceSelection = false)
|
2015-09-25 20:12:03 +12:00
|
|
|
|
{
|
|
|
|
|
if (taskSettings == null) taskSettings = TaskSettings.GetDefaultTaskSettings();
|
|
|
|
|
|
2016-08-23 07:39:38 +12:00
|
|
|
|
ScrollingCaptureForm scrollingCaptureForm = new ScrollingCaptureForm(taskSettings.CaptureSettingsReference.ScrollingCaptureOptions,
|
|
|
|
|
taskSettings.CaptureSettings.SurfaceOptions, forceSelection);
|
2016-04-01 23:11:43 +13:00
|
|
|
|
scrollingCaptureForm.ImageProcessRequested += img => UploadManager.RunImageTask(img, taskSettings);
|
2015-09-27 13:53:45 +13:00
|
|
|
|
scrollingCaptureForm.Show();
|
2015-09-25 20:12:03 +12:00
|
|
|
|
}
|
|
|
|
|
|
2018-04-02 23:43:29 +12:00
|
|
|
|
public static void OpenAutoCapture(TaskSettings taskSettings = null)
|
2014-05-03 05:56:51 +12:00
|
|
|
|
{
|
2018-04-02 23:43:29 +12:00
|
|
|
|
if (taskSettings == null) taskSettings = TaskSettings.GetDefaultTaskSettings();
|
|
|
|
|
|
|
|
|
|
AutoCaptureForm.Instance.TaskSettings = taskSettings;
|
2016-03-10 05:37:54 +13:00
|
|
|
|
AutoCaptureForm.Instance.ForceActivate();
|
2014-05-03 05:56:51 +12:00
|
|
|
|
}
|
|
|
|
|
|
2018-04-02 23:43:29 +12:00
|
|
|
|
public static void StartAutoCapture(TaskSettings taskSettings = null)
|
2014-12-11 08:23:05 +13:00
|
|
|
|
{
|
2018-04-02 23:43:29 +12:00
|
|
|
|
if (taskSettings == null) taskSettings = TaskSettings.GetDefaultTaskSettings();
|
|
|
|
|
|
2014-12-11 08:23:05 +13:00
|
|
|
|
if (!AutoCaptureForm.IsRunning)
|
|
|
|
|
{
|
|
|
|
|
AutoCaptureForm form = AutoCaptureForm.Instance;
|
2018-04-02 23:43:29 +12:00
|
|
|
|
form.TaskSettings = taskSettings;
|
2014-12-11 08:23:05 +13:00
|
|
|
|
form.Show();
|
|
|
|
|
form.Execute();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-02 10:21:16 +12:00
|
|
|
|
public static void OpenScreenshotsFolder()
|
|
|
|
|
{
|
|
|
|
|
if (Directory.Exists(Program.ScreenshotsFolder))
|
|
|
|
|
{
|
|
|
|
|
Helpers.OpenFolder(Program.ScreenshotsFolder);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Helpers.OpenFolder(Program.ScreenshotsParentFolder);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-22 08:50:49 +13:00
|
|
|
|
public static void OpenHistory()
|
|
|
|
|
{
|
2018-08-02 01:52:10 +12:00
|
|
|
|
HistoryForm historyForm = new HistoryForm(Program.HistoryFilePath, Program.Settings.HistorySettings,
|
2018-05-20 02:10:53 +12:00
|
|
|
|
filePath => UploadManager.UploadFile(filePath), filePath => AnnotateImageFromFile(filePath));
|
2016-02-22 08:50:49 +13:00
|
|
|
|
historyForm.Show();
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-03 23:05:59 +13:00
|
|
|
|
public static void OpenImageHistory()
|
|
|
|
|
{
|
2018-08-01 23:44:48 +12:00
|
|
|
|
ImageHistoryForm imageHistoryForm = new ImageHistoryForm(Program.HistoryFilePath, Program.Settings.ImageHistorySettings,
|
2018-05-20 02:10:53 +12:00
|
|
|
|
filePath => UploadManager.UploadFile(filePath), filePath => AnnotateImageFromFile(filePath));
|
2016-03-03 23:05:59 +13:00
|
|
|
|
imageHistoryForm.Show();
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-03 23:56:15 +13:00
|
|
|
|
public static void OpenDebugLog()
|
|
|
|
|
{
|
|
|
|
|
DebugForm form = DebugForm.GetFormInstance(DebugHelper.Logger);
|
|
|
|
|
|
|
|
|
|
if (!form.HasUploadRequested)
|
|
|
|
|
{
|
|
|
|
|
form.UploadRequested += text =>
|
|
|
|
|
{
|
|
|
|
|
if (MessageBox.Show(form, Resources.MainForm_UploadDebugLogWarning, "ShareX", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
|
|
|
|
|
{
|
|
|
|
|
UploadManager.UploadText(text);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
form.ForceActivate();
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-03 00:34:52 +12:00
|
|
|
|
public static void ShowScreenColorPickerDialog(TaskSettings taskSettings = null)
|
2015-01-25 19:51:24 +13:00
|
|
|
|
{
|
2018-04-19 04:29:02 +12:00
|
|
|
|
if (taskSettings == null) taskSettings = TaskSettings.GetDefaultTaskSettings();
|
|
|
|
|
|
2020-07-28 23:52:12 +12:00
|
|
|
|
RegionCaptureTasks.ShowScreenColorPickerDialog(taskSettings.CaptureSettings.SurfaceOptions);
|
2015-01-25 19:51:24 +13:00
|
|
|
|
}
|
|
|
|
|
|
2015-01-26 20:24:26 +13:00
|
|
|
|
public static void OpenScreenColorPicker(TaskSettings taskSettings = null)
|
2014-05-03 05:56:51 +12:00
|
|
|
|
{
|
2015-01-25 13:58:00 +13:00
|
|
|
|
if (taskSettings == null) taskSettings = TaskSettings.GetDefaultTaskSettings();
|
|
|
|
|
|
2016-09-05 22:31:49 +12:00
|
|
|
|
PointInfo pointInfo = RegionCaptureTasks.GetPointInfo(taskSettings.CaptureSettings.SurfaceOptions);
|
2015-01-25 13:58:00 +13:00
|
|
|
|
|
2015-01-25 19:51:24 +13:00
|
|
|
|
if (pointInfo != null)
|
|
|
|
|
{
|
2016-07-30 05:32:01 +12:00
|
|
|
|
string text = CodeMenuEntryPixelInfo.Parse(taskSettings.ToolsSettings.ScreenColorPickerFormat, pointInfo.Color, pointInfo.Position);
|
2015-01-25 13:58:00 +13:00
|
|
|
|
|
|
|
|
|
ClipboardHelpers.CopyText(text);
|
2015-01-25 19:51:24 +13:00
|
|
|
|
|
2020-10-01 05:38:17 +13:00
|
|
|
|
if (!taskSettings.AdvancedSettings.DisableNotifications)
|
2015-01-25 19:51:24 +13:00
|
|
|
|
{
|
2020-10-01 06:37:44 +13:00
|
|
|
|
// TODO: Translate
|
|
|
|
|
string tipTitle = "ShareX - " + "Screen color picker";
|
2020-10-01 05:38:17 +13:00
|
|
|
|
string tipText = string.Format(Resources.TaskHelpers_OpenQuickScreenColorPicker_Copied_to_clipboard___0_, text);
|
|
|
|
|
|
|
|
|
|
switch (taskSettings.GeneralSettings.PopUpNotification)
|
|
|
|
|
{
|
|
|
|
|
case PopUpNotificationType.BalloonTip:
|
2020-10-01 06:37:44 +13:00
|
|
|
|
ShowBalloonTip(tipText, ToolTipIcon.Info, 3000, tipTitle);
|
2020-10-01 05:38:17 +13:00
|
|
|
|
break;
|
|
|
|
|
case PopUpNotificationType.ToastNotification:
|
2020-10-01 06:37:44 +13:00
|
|
|
|
ShowNotificationTip(tipText, tipTitle);
|
2020-10-01 05:38:17 +13:00
|
|
|
|
break;
|
|
|
|
|
}
|
2015-01-25 19:51:24 +13:00
|
|
|
|
}
|
2015-01-25 13:58:00 +13:00
|
|
|
|
}
|
2014-05-03 05:56:51 +12:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void OpenHashCheck()
|
|
|
|
|
{
|
|
|
|
|
new HashCheckForm().Show();
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-03 01:58:34 +13:00
|
|
|
|
public static void OpenDirectoryIndexer(TaskSettings taskSettings = null)
|
2014-05-03 05:56:51 +12:00
|
|
|
|
{
|
2016-02-03 01:58:34 +13:00
|
|
|
|
if (taskSettings == null) taskSettings = TaskSettings.GetDefaultTaskSettings();
|
|
|
|
|
|
2016-02-03 02:25:09 +13:00
|
|
|
|
IndexerSettings indexerSettings = taskSettings.ToolsSettingsReference.IndexerSettings;
|
|
|
|
|
indexerSettings.BinaryUnits = Program.Settings.BinaryUnits;
|
|
|
|
|
DirectoryIndexerForm form = new DirectoryIndexerForm(indexerSettings);
|
2016-02-03 01:58:34 +13:00
|
|
|
|
form.UploadRequested += source =>
|
|
|
|
|
{
|
|
|
|
|
WorkerTask task = WorkerTask.CreateTextUploaderTask(source, taskSettings);
|
2016-02-03 02:25:09 +13:00
|
|
|
|
task.Info.FileName = Path.ChangeExtension(task.Info.FileName, indexerSettings.Output.ToString().ToLowerInvariant());
|
2016-02-03 01:58:34 +13:00
|
|
|
|
TaskManager.Start(task);
|
|
|
|
|
};
|
|
|
|
|
form.Show();
|
2014-05-03 05:56:51 +12:00
|
|
|
|
}
|
|
|
|
|
|
2017-01-07 21:48:36 +13:00
|
|
|
|
public static void OpenImageCombiner(TaskSettings taskSettings = null, IEnumerable<string> imageFiles = null)
|
2015-10-01 01:44:19 +13:00
|
|
|
|
{
|
|
|
|
|
if (taskSettings == null) taskSettings = TaskSettings.GetDefaultTaskSettings();
|
|
|
|
|
|
2017-01-07 21:48:36 +13:00
|
|
|
|
ImageCombinerForm imageCombinerForm = new ImageCombinerForm(taskSettings.ToolsSettingsReference.ImageCombinerOptions, imageFiles);
|
2020-03-24 08:33:26 +13:00
|
|
|
|
imageCombinerForm.ProcessRequested += bmp => UploadManager.RunImageTask(bmp, taskSettings);
|
2015-10-01 02:35:45 +13:00
|
|
|
|
imageCombinerForm.Show();
|
2015-10-01 01:44:19 +13:00
|
|
|
|
}
|
|
|
|
|
|
2019-09-29 04:55:26 +13:00
|
|
|
|
public static void OpenImageSplitter()
|
|
|
|
|
{
|
|
|
|
|
ImageSplitterForm imageSplitterForm = new ImageSplitterForm();
|
|
|
|
|
imageSplitterForm.Show();
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-17 08:34:32 +13:00
|
|
|
|
public static void OpenImageThumbnailer()
|
2017-07-10 11:04:19 +12:00
|
|
|
|
{
|
|
|
|
|
ImageThumbnailerForm imageThumbnailerForm = new ImageThumbnailerForm();
|
|
|
|
|
imageThumbnailerForm.Show();
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-17 08:34:32 +13:00
|
|
|
|
public static void OpenVideoConverter(TaskSettings taskSettings = null)
|
|
|
|
|
{
|
|
|
|
|
if (taskSettings == null) taskSettings = TaskSettings.GetDefaultTaskSettings();
|
|
|
|
|
|
|
|
|
|
if (!CheckFFmpeg(taskSettings))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-22 21:26:08 +13:00
|
|
|
|
VideoConverterForm videoConverterForm = new VideoConverterForm(taskSettings.CaptureSettings.FFmpegOptions.FFmpegPath,
|
|
|
|
|
taskSettings.ToolsSettingsReference.VideoConverterOptions);
|
2019-11-17 08:34:32 +13:00
|
|
|
|
videoConverterForm.Show();
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-04 23:47:34 +12:00
|
|
|
|
public static void OpenVideoThumbnailer(TaskSettings taskSettings = null)
|
|
|
|
|
{
|
|
|
|
|
if (taskSettings == null) taskSettings = TaskSettings.GetDefaultTaskSettings();
|
|
|
|
|
|
2015-08-14 09:51:58 +12:00
|
|
|
|
if (!CheckFFmpeg(taskSettings))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-23 00:26:04 +12:00
|
|
|
|
taskSettings.ToolsSettingsReference.VideoThumbnailOptions.DefaultOutputDirectory = taskSettings.GetScreenshotsFolder();
|
2019-11-22 21:26:08 +13:00
|
|
|
|
VideoThumbnailerForm thumbnailerForm = new VideoThumbnailerForm(taskSettings.CaptureSettings.FFmpegOptions.FFmpegPath,
|
|
|
|
|
taskSettings.ToolsSettingsReference.VideoThumbnailOptions);
|
2015-08-06 21:22:07 +12:00
|
|
|
|
thumbnailerForm.ThumbnailsTaken += thumbnails =>
|
|
|
|
|
{
|
2015-08-31 22:44:23 +12:00
|
|
|
|
if (taskSettings.ToolsSettingsReference.VideoThumbnailOptions.UploadThumbnails)
|
2015-08-06 21:22:07 +12:00
|
|
|
|
{
|
|
|
|
|
foreach (VideoThumbnailInfo thumbnailInfo in thumbnails)
|
|
|
|
|
{
|
|
|
|
|
UploadManager.UploadFile(thumbnailInfo.Filepath, taskSettings);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
2015-08-05 23:44:04 +12:00
|
|
|
|
thumbnailerForm.Show();
|
2015-08-04 23:47:34 +12:00
|
|
|
|
}
|
|
|
|
|
|
2020-09-14 06:00:49 +12:00
|
|
|
|
public static void OpenClipboardViewer()
|
|
|
|
|
{
|
|
|
|
|
ClipboardViewerForm clipboardViewerForm = new ClipboardViewerForm();
|
|
|
|
|
clipboardViewerForm.Show();
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-27 00:46:29 +13:00
|
|
|
|
public static void OpenImageEditor(TaskSettings taskSettings = null)
|
2014-05-04 10:22:47 +12:00
|
|
|
|
{
|
2016-09-04 23:23:21 +12:00
|
|
|
|
if (taskSettings == null) taskSettings = TaskSettings.GetDefaultTaskSettings();
|
|
|
|
|
|
2017-12-27 02:40:36 +13:00
|
|
|
|
using (EditorStartupForm editorStartupForm = new EditorStartupForm(taskSettings.CaptureSettingsReference.SurfaceOptions))
|
2014-05-04 10:22:47 +12:00
|
|
|
|
{
|
2017-12-27 00:46:29 +13:00
|
|
|
|
if (editorStartupForm.ShowDialog() == DialogResult.OK)
|
2015-08-23 01:44:40 +12:00
|
|
|
|
{
|
2017-12-27 00:46:29 +13:00
|
|
|
|
AnnotateImageAsync(editorStartupForm.Image, editorStartupForm.ImageFilePath, taskSettings);
|
2015-08-23 01:44:40 +12:00
|
|
|
|
}
|
2014-05-04 10:22:47 +12:00
|
|
|
|
}
|
2016-09-06 00:23:25 +12:00
|
|
|
|
}
|
|
|
|
|
|
2017-12-27 00:46:29 +13:00
|
|
|
|
public static void AnnotateImageFromFile(string filePath, TaskSettings taskSettings = null)
|
2016-09-06 00:23:25 +12:00
|
|
|
|
{
|
2016-10-18 13:59:45 +13:00
|
|
|
|
if (!string.IsNullOrEmpty(filePath) && File.Exists(filePath))
|
2014-07-17 08:43:20 +12:00
|
|
|
|
{
|
2016-09-06 00:23:25 +12:00
|
|
|
|
if (taskSettings == null) taskSettings = TaskSettings.GetDefaultTaskSettings();
|
2016-09-05 21:21:32 +12:00
|
|
|
|
|
2020-03-22 12:22:43 +13:00
|
|
|
|
Bitmap bmp = ImageHelpers.LoadImage(filePath);
|
2017-12-27 00:46:29 +13:00
|
|
|
|
|
2020-03-21 08:02:26 +13:00
|
|
|
|
AnnotateImageAsync(bmp, filePath, taskSettings);
|
2014-07-17 08:43:20 +12:00
|
|
|
|
}
|
2016-10-18 13:59:45 +13:00
|
|
|
|
else
|
|
|
|
|
{
|
2016-10-19 02:30:08 +13:00
|
|
|
|
MessageBox.Show("File does not exist:" + Environment.NewLine + filePath, "ShareX", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
2016-10-18 13:59:45 +13:00
|
|
|
|
}
|
2014-07-17 08:43:20 +12:00
|
|
|
|
}
|
|
|
|
|
|
2020-03-21 08:02:26 +13:00
|
|
|
|
public static void AnnotateImageAsync(Bitmap bmp, string filePath, TaskSettings taskSettings)
|
2017-03-18 13:07:59 +13:00
|
|
|
|
{
|
2017-11-12 19:35:09 +13:00
|
|
|
|
ThreadWorker worker = new ThreadWorker();
|
|
|
|
|
|
2017-10-31 00:14:13 +13:00
|
|
|
|
worker.DoWork += () =>
|
2017-03-18 13:07:59 +13:00
|
|
|
|
{
|
2020-03-21 08:02:26 +13:00
|
|
|
|
bmp = AnnotateImage(bmp, filePath, taskSettings);
|
2017-10-31 00:14:13 +13:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
worker.Completed += () =>
|
|
|
|
|
{
|
2020-03-21 08:02:26 +13:00
|
|
|
|
if (bmp != null)
|
2017-10-31 00:14:13 +13:00
|
|
|
|
{
|
2020-03-21 08:02:26 +13:00
|
|
|
|
UploadManager.RunImageTask(bmp, taskSettings);
|
2017-10-31 00:14:13 +13:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
worker.Start(ApartmentState.STA);
|
2017-03-18 13:07:59 +13:00
|
|
|
|
}
|
|
|
|
|
|
2020-03-21 08:02:26 +13:00
|
|
|
|
public static Bitmap AnnotateImage(Bitmap bmp, string filePath, TaskSettings taskSettings, bool taskMode = false)
|
2017-02-28 08:32:32 +13:00
|
|
|
|
{
|
2020-03-21 08:02:26 +13:00
|
|
|
|
if (bmp != null)
|
2017-02-27 04:37:04 +13:00
|
|
|
|
{
|
2020-03-21 08:02:26 +13:00
|
|
|
|
using (bmp)
|
2017-02-27 04:37:04 +13:00
|
|
|
|
{
|
2017-12-27 02:40:36 +13:00
|
|
|
|
RegionCaptureMode mode = taskMode ? RegionCaptureMode.TaskEditor : RegionCaptureMode.Editor;
|
|
|
|
|
RegionCaptureOptions options = taskSettings.CaptureSettingsReference.SurfaceOptions;
|
2017-12-17 20:30:39 +13:00
|
|
|
|
|
2020-03-21 08:02:26 +13:00
|
|
|
|
using (RegionCaptureForm form = new RegionCaptureForm(mode, options, bmp))
|
2017-12-17 20:30:39 +13:00
|
|
|
|
{
|
2017-12-27 02:40:36 +13:00
|
|
|
|
form.ImageFilePath = filePath;
|
|
|
|
|
|
|
|
|
|
form.SaveImageRequested += (output, newFilePath) =>
|
2017-12-17 20:30:39 +13:00
|
|
|
|
{
|
2018-07-16 21:44:23 +12:00
|
|
|
|
using (output)
|
2017-12-27 02:40:36 +13:00
|
|
|
|
{
|
2018-07-16 21:44:23 +12:00
|
|
|
|
if (string.IsNullOrEmpty(newFilePath))
|
|
|
|
|
{
|
2018-11-14 00:19:37 +13:00
|
|
|
|
string fileName = GetFilename(taskSettings, taskSettings.ImageSettings.ImageFormat.GetDescription(), output);
|
2020-04-23 00:26:04 +12:00
|
|
|
|
newFilePath = Path.Combine(taskSettings.GetScreenshotsFolder(), fileName);
|
2018-07-16 21:44:23 +12:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ImageHelpers.SaveImage(output, newFilePath);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return newFilePath;
|
2017-12-27 02:40:36 +13:00
|
|
|
|
};
|
2017-12-17 20:30:39 +13:00
|
|
|
|
|
2017-12-27 02:40:36 +13:00
|
|
|
|
form.SaveImageAsRequested += (output, newFilePath) =>
|
2017-12-17 20:30:39 +13:00
|
|
|
|
{
|
2018-07-16 21:44:23 +12:00
|
|
|
|
using (output)
|
2017-12-27 02:40:36 +13:00
|
|
|
|
{
|
2018-07-16 21:44:23 +12:00
|
|
|
|
if (string.IsNullOrEmpty(newFilePath))
|
|
|
|
|
{
|
2018-11-14 00:19:37 +13:00
|
|
|
|
string fileName = GetFilename(taskSettings, taskSettings.ImageSettings.ImageFormat.GetDescription(), output);
|
2020-04-23 00:26:04 +12:00
|
|
|
|
newFilePath = Path.Combine(taskSettings.GetScreenshotsFolder(), fileName);
|
2018-07-16 21:44:23 +12:00
|
|
|
|
}
|
|
|
|
|
|
2018-07-16 22:11:17 +12:00
|
|
|
|
newFilePath = ImageHelpers.SaveImageFileDialog(output, newFilePath);
|
2018-07-16 21:44:23 +12:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return newFilePath;
|
2017-12-27 02:40:36 +13:00
|
|
|
|
};
|
2017-12-17 20:30:39 +13:00
|
|
|
|
|
2017-12-27 02:40:36 +13:00
|
|
|
|
form.CopyImageRequested += output =>
|
2017-12-17 20:30:39 +13:00
|
|
|
|
{
|
2017-12-27 02:40:36 +13:00
|
|
|
|
Program.MainForm.InvokeSafe(() =>
|
|
|
|
|
{
|
|
|
|
|
using (output) { ClipboardHelpers.CopyImage(output); }
|
|
|
|
|
});
|
|
|
|
|
};
|
2017-12-17 20:30:39 +13:00
|
|
|
|
|
2017-12-27 02:40:36 +13:00
|
|
|
|
form.UploadImageRequested += output =>
|
2017-12-17 20:30:39 +13:00
|
|
|
|
{
|
2017-12-27 02:40:36 +13:00
|
|
|
|
Program.MainForm.InvokeSafe(() =>
|
|
|
|
|
{
|
2020-08-26 07:43:27 +12:00
|
|
|
|
UploadManager.UploadImage(output, taskSettings);
|
2017-12-27 02:40:36 +13:00
|
|
|
|
});
|
|
|
|
|
};
|
2017-12-17 20:30:39 +13:00
|
|
|
|
|
2017-12-27 02:40:36 +13:00
|
|
|
|
form.PrintImageRequested += output =>
|
2017-12-17 20:30:39 +13:00
|
|
|
|
{
|
2017-12-27 02:40:36 +13:00
|
|
|
|
Program.MainForm.InvokeSafe(() =>
|
|
|
|
|
{
|
|
|
|
|
using (output) { PrintImage(output); }
|
|
|
|
|
});
|
|
|
|
|
};
|
2017-12-17 20:30:39 +13:00
|
|
|
|
|
2017-12-27 02:40:36 +13:00
|
|
|
|
form.ShowDialog();
|
2017-12-17 20:30:39 +13:00
|
|
|
|
|
2017-12-27 02:40:36 +13:00
|
|
|
|
switch (form.Result)
|
|
|
|
|
{
|
|
|
|
|
case RegionResult.Close: // Esc
|
|
|
|
|
case RegionResult.AnnotateCancelTask:
|
|
|
|
|
return null;
|
|
|
|
|
case RegionResult.Region: // Enter
|
|
|
|
|
case RegionResult.AnnotateRunAfterCaptureTasks:
|
2020-03-21 14:41:34 +13:00
|
|
|
|
return form.GetResultImage();
|
2017-12-27 02:40:36 +13:00
|
|
|
|
case RegionResult.Fullscreen: // Space or right click
|
|
|
|
|
case RegionResult.AnnotateContinueTask:
|
2020-03-21 08:02:26 +13:00
|
|
|
|
return (Bitmap)form.Canvas.Clone();
|
2017-12-27 02:40:36 +13:00
|
|
|
|
}
|
2017-12-17 20:30:39 +13:00
|
|
|
|
}
|
2017-02-27 04:37:04 +13:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-03-08 03:27:05 +13:00
|
|
|
|
|
|
|
|
|
return null;
|
2017-02-27 04:37:04 +13:00
|
|
|
|
}
|
|
|
|
|
|
2017-09-24 00:07:18 +12:00
|
|
|
|
public static void OpenImageEffects(TaskSettings taskSettings = null)
|
2014-05-03 05:56:51 +12:00
|
|
|
|
{
|
|
|
|
|
string filePath = ImageHelpers.OpenImageFileDialog();
|
2020-08-03 00:41:53 +12:00
|
|
|
|
OpenImageEffects(filePath, taskSettings);
|
|
|
|
|
}
|
2019-11-05 23:56:08 +13:00
|
|
|
|
|
2020-08-03 00:41:53 +12:00
|
|
|
|
public static void OpenImageEffects(string filePath, TaskSettings taskSettings = null)
|
|
|
|
|
{
|
2014-05-03 05:56:51 +12:00
|
|
|
|
if (!string.IsNullOrEmpty(filePath))
|
|
|
|
|
{
|
2020-03-22 12:22:43 +13:00
|
|
|
|
Bitmap bmp = ImageHelpers.LoadImage(filePath);
|
2017-10-15 02:13:24 +13:00
|
|
|
|
|
2020-03-21 08:02:26 +13:00
|
|
|
|
if (bmp != null)
|
2018-01-06 13:46:37 +13:00
|
|
|
|
{
|
2020-03-21 08:02:26 +13:00
|
|
|
|
if (bmp.PixelFormat.HasFlag(PixelFormat.Indexed))
|
2018-01-06 13:46:37 +13:00
|
|
|
|
{
|
2020-03-21 08:02:26 +13:00
|
|
|
|
MessageBox.Show("Unsupported pixel format: " + bmp.PixelFormat, "ShareX - Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
2019-11-05 23:56:08 +13:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2020-08-03 00:41:53 +12:00
|
|
|
|
if (taskSettings == null) taskSettings = Program.DefaultTaskSettings;
|
|
|
|
|
|
2020-03-21 08:02:26 +13:00
|
|
|
|
using (ImageEffectsForm imageEffectsForm = new ImageEffectsForm(bmp, taskSettings.ImageSettings.ImageEffectPresets,
|
2019-11-05 23:56:08 +13:00
|
|
|
|
taskSettings.ImageSettings.SelectedImageEffectPreset))
|
|
|
|
|
{
|
|
|
|
|
imageEffectsForm.EnableToolMode(x => UploadManager.RunImageTask(x, taskSettings), filePath);
|
|
|
|
|
imageEffectsForm.ShowDialog();
|
|
|
|
|
//taskSettings.ImageSettings.SelectedImageEffectPreset = imageEffectsForm.SelectedPresetIndex;
|
|
|
|
|
}
|
2018-01-06 13:46:37 +13:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-10-15 02:13:24 +13:00
|
|
|
|
}
|
2014-05-03 05:56:51 +12:00
|
|
|
|
}
|
|
|
|
|
|
2020-07-06 10:37:56 +12:00
|
|
|
|
public static ImageEffectsForm OpenImageEffectsSingleton(TaskSettings taskSettings = null)
|
|
|
|
|
{
|
|
|
|
|
if (taskSettings == null) taskSettings = Program.DefaultTaskSettings;
|
|
|
|
|
|
|
|
|
|
bool firstInstance = !ImageEffectsForm.IsInstanceActive;
|
|
|
|
|
|
|
|
|
|
ImageEffectsForm imageEffectsForm = ImageEffectsForm.GetFormInstance(taskSettings.ImageSettings.ImageEffectPresets,
|
|
|
|
|
taskSettings.ImageSettings.SelectedImageEffectPreset);
|
|
|
|
|
|
|
|
|
|
if (firstInstance)
|
|
|
|
|
{
|
|
|
|
|
imageEffectsForm.FormClosed += (sender, e) => taskSettings.ImageSettings.SelectedImageEffectPreset = imageEffectsForm.SelectedPresetIndex;
|
|
|
|
|
imageEffectsForm.Show();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
imageEffectsForm.ForceActivate();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return imageEffectsForm;
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-03 05:56:51 +12:00
|
|
|
|
public static void OpenMonitorTest()
|
|
|
|
|
{
|
|
|
|
|
using (MonitorTestForm monitorTestForm = new MonitorTestForm())
|
|
|
|
|
{
|
|
|
|
|
monitorTestForm.ShowDialog();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void OpenDNSChanger()
|
2014-09-07 07:13:21 +12:00
|
|
|
|
{
|
2017-05-03 22:20:06 +12:00
|
|
|
|
#if WindowsStore
|
2017-12-11 03:58:47 +13:00
|
|
|
|
MessageBox.Show("Not supported in Microsoft Store build.", "ShareX", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
2017-05-03 22:20:06 +12:00
|
|
|
|
#else
|
2015-05-07 04:49:57 +12:00
|
|
|
|
if (Helpers.IsAdministrator())
|
|
|
|
|
{
|
|
|
|
|
new DNSChangerForm().Show();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
RunShareXAsAdmin("-dnschanger");
|
|
|
|
|
}
|
2017-05-03 22:20:06 +12:00
|
|
|
|
#endif
|
2014-09-07 07:13:21 +12:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void RunShareXAsAdmin(string arguments)
|
2014-05-03 05:56:51 +12:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2018-12-07 07:51:41 +13:00
|
|
|
|
using (Process process = new Process())
|
|
|
|
|
{
|
|
|
|
|
ProcessStartInfo psi = new ProcessStartInfo()
|
|
|
|
|
{
|
|
|
|
|
FileName = Application.ExecutablePath,
|
|
|
|
|
Arguments = arguments,
|
2019-01-01 13:45:01 +13:00
|
|
|
|
UseShellExecute = true,
|
2018-12-07 07:51:41 +13:00
|
|
|
|
Verb = "runas"
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
process.StartInfo = psi;
|
|
|
|
|
process.Start();
|
|
|
|
|
}
|
2014-05-03 05:56:51 +12:00
|
|
|
|
}
|
2018-05-16 20:09:01 +12:00
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
}
|
2014-05-03 05:56:51 +12:00
|
|
|
|
}
|
|
|
|
|
|
2014-05-21 10:46:06 +12:00
|
|
|
|
public static void OpenQRCode()
|
|
|
|
|
{
|
2018-04-04 06:21:41 +12:00
|
|
|
|
QRCodeForm.EncodeClipboard().Show();
|
2014-05-21 10:46:06 +12:00
|
|
|
|
}
|
|
|
|
|
|
2020-07-20 02:30:21 +12:00
|
|
|
|
public static void OpenQRCodeDecodeFromScreen()
|
|
|
|
|
{
|
|
|
|
|
QRCodeForm.OpenFormDecodeFromScreen();
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-23 07:39:38 +12:00
|
|
|
|
public static void OpenRuler(TaskSettings taskSettings = null)
|
2016-05-13 17:56:33 +12:00
|
|
|
|
{
|
2016-08-23 07:39:38 +12:00
|
|
|
|
if (taskSettings == null) taskSettings = TaskSettings.GetDefaultTaskSettings();
|
|
|
|
|
|
2016-09-05 22:31:49 +12:00
|
|
|
|
RegionCaptureTasks.ShowScreenRuler(taskSettings.CaptureSettings.SurfaceOptions);
|
2016-08-23 07:39:38 +12:00
|
|
|
|
}
|
|
|
|
|
|
2018-11-15 14:10:54 +13:00
|
|
|
|
public static void SearchImage(string url)
|
|
|
|
|
{
|
|
|
|
|
new GoogleImageSearchSharingService().CreateSharer(null, null).ShareURL(url);
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-29 02:14:19 +13:00
|
|
|
|
public static async Task OCRImage(TaskSettings taskSettings = null)
|
2016-08-23 07:39:38 +12:00
|
|
|
|
{
|
2020-01-06 10:57:45 +13:00
|
|
|
|
if (IsUploadAllowed())
|
2016-05-13 17:56:33 +12:00
|
|
|
|
{
|
2020-01-06 10:57:45 +13:00
|
|
|
|
if (taskSettings == null) taskSettings = TaskSettings.GetDefaultTaskSettings();
|
2020-01-06 08:43:20 +13:00
|
|
|
|
|
2020-03-21 14:41:34 +13:00
|
|
|
|
using (Bitmap bmp = RegionCaptureTasks.GetRegionImage(taskSettings.CaptureSettings.SurfaceOptions))
|
2020-01-06 10:57:45 +13:00
|
|
|
|
{
|
2020-03-21 14:41:34 +13:00
|
|
|
|
await OCRImage(bmp, taskSettings);
|
2020-01-06 10:57:45 +13:00
|
|
|
|
}
|
2020-01-06 08:43:20 +13:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-29 02:14:19 +13:00
|
|
|
|
public static async Task OCRImage(Image img, TaskSettings taskSettings = null)
|
2016-12-12 21:45:16 +13:00
|
|
|
|
{
|
2020-01-06 08:43:20 +13:00
|
|
|
|
if (IsUploadAllowed() && img != null)
|
2016-12-12 21:45:16 +13:00
|
|
|
|
{
|
|
|
|
|
using (Stream stream = SaveImageAsStream(img, EImageFormat.PNG))
|
2016-05-13 17:56:33 +12:00
|
|
|
|
{
|
2018-11-29 02:14:19 +13:00
|
|
|
|
await OCRImage(stream, "ShareX.png", null, taskSettings);
|
2016-12-12 21:45:16 +13:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-29 02:14:19 +13:00
|
|
|
|
public static async Task OCRImage(string filePath, TaskSettings taskSettings = null)
|
2016-12-12 21:45:16 +13:00
|
|
|
|
{
|
2020-01-06 08:43:20 +13:00
|
|
|
|
if (IsUploadAllowed() && File.Exists(filePath))
|
2016-12-12 21:45:16 +13:00
|
|
|
|
{
|
|
|
|
|
using (FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read))
|
|
|
|
|
{
|
2018-11-29 02:14:19 +13:00
|
|
|
|
await OCRImage(fs, Path.GetFileName(filePath), filePath, taskSettings);
|
2016-12-12 21:45:16 +13:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-30 20:43:56 +13:00
|
|
|
|
private static async Task OCRImage(Stream stream, string fileName, string filePath = null, TaskSettings taskSettings = null)
|
2016-12-12 21:45:16 +13:00
|
|
|
|
{
|
|
|
|
|
if (stream != null)
|
|
|
|
|
{
|
2018-11-15 14:10:54 +13:00
|
|
|
|
if (taskSettings == null) taskSettings = TaskSettings.GetDefaultTaskSettings();
|
|
|
|
|
|
|
|
|
|
OCROptions ocrOptions = taskSettings.CaptureSettings.OCROptions;
|
2018-11-29 02:14:19 +13:00
|
|
|
|
|
2019-01-18 19:23:25 +13:00
|
|
|
|
if (!ocrOptions.Permission)
|
|
|
|
|
{
|
2019-04-05 08:22:16 +13:00
|
|
|
|
if (MessageBox.Show(Resources.PleaseNoteThatShareXIsUsingOCRSpaceSOnlineAPIToPerformOpticalCharacterRecognitionDoYouGivePermissionToShareXToUploadImagesToThisService,
|
|
|
|
|
Resources.ShareXOpticalCharacterRecognition, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
2019-01-18 19:23:25 +13:00
|
|
|
|
{
|
|
|
|
|
taskSettings.CaptureSettingsReference.OCROptions.Permission = true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-29 02:14:19 +13:00
|
|
|
|
if (ocrOptions.Silent)
|
|
|
|
|
{
|
|
|
|
|
await AsyncOCRImage(stream, fileName, filePath, ocrOptions);
|
|
|
|
|
}
|
|
|
|
|
else
|
2016-12-12 21:45:16 +13:00
|
|
|
|
{
|
2018-11-29 02:14:19 +13:00
|
|
|
|
using (OCRSpaceForm form = new OCRSpaceForm(stream, fileName, ocrOptions))
|
2018-11-15 14:10:54 +13:00
|
|
|
|
{
|
2018-11-29 02:14:19 +13:00
|
|
|
|
form.ShowDialog();
|
2018-11-15 14:10:54 +13:00
|
|
|
|
|
2018-11-29 02:14:19 +13:00
|
|
|
|
if (!string.IsNullOrEmpty(form.Result) && !string.IsNullOrEmpty(filePath))
|
2018-11-15 14:10:54 +13:00
|
|
|
|
{
|
2018-11-29 02:14:19 +13:00
|
|
|
|
string textPath = Path.ChangeExtension(filePath, "txt");
|
|
|
|
|
File.WriteAllText(textPath, form.Result, Encoding.UTF8);
|
2018-11-15 14:10:54 +13:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-11-29 02:14:19 +13:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-06 10:57:45 +13:00
|
|
|
|
private static async Task AsyncOCRImage(Stream stream, string fileName, string filePath, OCROptions ocrOptions)
|
2018-11-29 02:14:19 +13:00
|
|
|
|
{
|
2019-03-31 01:54:46 +13:00
|
|
|
|
ShowBalloonTip(Resources.OCRForm_AutoProcessing, ToolTipIcon.None, 3000);
|
2018-11-29 02:14:19 +13:00
|
|
|
|
|
|
|
|
|
string result = null;
|
|
|
|
|
|
|
|
|
|
if (stream != null && stream.Length > 0 && !string.IsNullOrEmpty(fileName))
|
|
|
|
|
{
|
2018-11-29 02:45:06 +13:00
|
|
|
|
result = await OCRSpace.DoOCRAsync(ocrOptions.DefaultLanguage, stream, fileName);
|
2018-11-29 02:14:19 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(result))
|
|
|
|
|
{
|
|
|
|
|
ClipboardHelpers.CopyText(result);
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(filePath))
|
|
|
|
|
{
|
|
|
|
|
string textPath = Path.ChangeExtension(filePath, "txt");
|
|
|
|
|
File.WriteAllText(textPath, result, Encoding.UTF8);
|
2016-05-13 17:56:33 +12:00
|
|
|
|
}
|
2018-11-29 02:14:19 +13:00
|
|
|
|
|
2019-03-31 01:54:46 +13:00
|
|
|
|
ShowBalloonTip(Resources.OCRForm_AutoComplete, ToolTipIcon.None, 3000);
|
2018-11-29 02:14:19 +13:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2019-03-31 01:54:46 +13:00
|
|
|
|
ShowBalloonTip(Resources.OCRForm_AutoCompleteFail, ToolTipIcon.Warning, 3000);
|
2016-05-13 17:56:33 +12:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-17 22:30:49 +12:00
|
|
|
|
public static void TweetMessage()
|
|
|
|
|
{
|
2020-01-06 10:57:45 +13:00
|
|
|
|
if (IsUploadAllowed())
|
2014-06-17 22:30:49 +12:00
|
|
|
|
{
|
2020-01-06 10:57:45 +13:00
|
|
|
|
if (Program.UploadersConfig != null && Program.UploadersConfig.TwitterOAuthInfoList != null)
|
2014-06-17 22:30:49 +12:00
|
|
|
|
{
|
2020-01-06 10:57:45 +13:00
|
|
|
|
OAuthInfo twitterOAuth = Program.UploadersConfig.TwitterOAuthInfoList.ReturnIfValidIndex(Program.UploadersConfig.TwitterSelectedAccount);
|
|
|
|
|
|
|
|
|
|
if (twitterOAuth != null && OAuthInfo.CheckOAuth(twitterOAuth))
|
2014-06-17 22:30:49 +12:00
|
|
|
|
{
|
2020-01-06 10:57:45 +13:00
|
|
|
|
Task.Run(() =>
|
2014-06-17 22:30:49 +12:00
|
|
|
|
{
|
2020-01-06 10:57:45 +13:00
|
|
|
|
using (TwitterTweetForm twitter = new TwitterTweetForm(twitterOAuth))
|
2014-06-17 22:30:49 +12:00
|
|
|
|
{
|
2020-01-06 10:57:45 +13:00
|
|
|
|
if (twitter.ShowDialog() == DialogResult.OK && twitter.IsTweetSent)
|
|
|
|
|
{
|
|
|
|
|
ShowBalloonTip(Resources.TaskHelpers_TweetMessage_Tweet_successfully_sent_, ToolTipIcon.Info, 3000);
|
|
|
|
|
}
|
2014-06-17 22:30:49 +12:00
|
|
|
|
}
|
2020-01-06 10:57:45 +13:00
|
|
|
|
});
|
2014-06-17 22:30:49 +12:00
|
|
|
|
|
2020-01-06 10:57:45 +13:00
|
|
|
|
return;
|
|
|
|
|
}
|
2015-04-27 06:44:44 +12:00
|
|
|
|
}
|
|
|
|
|
|
2020-01-06 10:57:45 +13:00
|
|
|
|
MessageBox.Show(Resources.TaskHelpers_TweetMessage_Unable_to_find_valid_Twitter_account_, "ShareX", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
|
|
|
}
|
2014-05-03 05:56:51 +12:00
|
|
|
|
}
|
2015-03-08 14:13:55 +13:00
|
|
|
|
|
|
|
|
|
public static EDataType FindDataType(string filePath, TaskSettings taskSettings)
|
|
|
|
|
{
|
2016-09-11 09:36:01 +12:00
|
|
|
|
if (Helpers.CheckExtension(filePath, taskSettings.AdvancedSettings.ImageExtensions))
|
2015-03-08 14:13:55 +13:00
|
|
|
|
{
|
2016-09-11 09:36:01 +12:00
|
|
|
|
return EDataType.Image;
|
|
|
|
|
}
|
2015-03-08 14:13:55 +13:00
|
|
|
|
|
2016-09-11 09:36:01 +12:00
|
|
|
|
if (Helpers.CheckExtension(filePath, taskSettings.AdvancedSettings.TextExtensions))
|
|
|
|
|
{
|
|
|
|
|
return EDataType.Text;
|
2015-03-08 14:13:55 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return EDataType.File;
|
|
|
|
|
}
|
2015-07-19 06:49:34 +12:00
|
|
|
|
|
|
|
|
|
public static bool ToggleHotkeys()
|
|
|
|
|
{
|
2015-11-01 07:26:12 +13:00
|
|
|
|
bool hotkeysDisabled = !Program.Settings.DisableHotkeys;
|
2015-07-19 06:49:34 +12:00
|
|
|
|
|
2015-11-01 07:26:12 +13:00
|
|
|
|
Program.Settings.DisableHotkeys = hotkeysDisabled;
|
|
|
|
|
Program.HotkeyManager.ToggleHotkeys(hotkeysDisabled);
|
2015-07-19 06:49:34 +12:00
|
|
|
|
Program.MainForm.UpdateToggleHotkeyButton();
|
|
|
|
|
|
2019-03-31 01:54:46 +13:00
|
|
|
|
string balloonTipText = hotkeysDisabled ? Resources.TaskHelpers_ToggleHotkeys_Hotkeys_disabled_ : Resources.TaskHelpers_ToggleHotkeys_Hotkeys_enabled_;
|
|
|
|
|
ShowBalloonTip(balloonTipText, ToolTipIcon.Info, 3000);
|
2015-07-19 06:49:34 +12:00
|
|
|
|
|
2015-11-01 07:26:12 +13:00
|
|
|
|
return hotkeysDisabled;
|
2015-07-19 06:49:34 +12:00
|
|
|
|
}
|
2015-08-14 09:51:58 +12:00
|
|
|
|
|
|
|
|
|
public static bool CheckFFmpeg(TaskSettings taskSettings)
|
|
|
|
|
{
|
2015-10-16 08:19:24 +13:00
|
|
|
|
string ffmpegPath = taskSettings.CaptureSettings.FFmpegOptions.FFmpegPath;
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(ffmpegPath))
|
2015-08-14 09:51:58 +12:00
|
|
|
|
{
|
2015-10-27 15:03:24 +13:00
|
|
|
|
ffmpegPath = Program.DefaultFFmpegFilePath;
|
2015-10-16 08:19:24 +13:00
|
|
|
|
}
|
2015-08-14 09:51:58 +12:00
|
|
|
|
|
2015-10-16 08:19:24 +13:00
|
|
|
|
if (!File.Exists(ffmpegPath))
|
|
|
|
|
{
|
|
|
|
|
if (MessageBox.Show(string.Format(Resources.ScreenRecordForm_StartRecording_does_not_exist, ffmpegPath),
|
2015-08-14 09:51:58 +12:00
|
|
|
|
"ShareX - " + Resources.ScreenRecordForm_StartRecording_Missing + " ffmpeg.exe", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
|
|
|
|
|
{
|
2020-09-02 21:19:20 +12:00
|
|
|
|
DialogResult downloadDialogResult = FFmpegGitHubDownloader.DownloadFFmpeg(false, DownloaderForm_InstallRequested);
|
2017-03-14 16:29:02 +13:00
|
|
|
|
|
|
|
|
|
if (downloadDialogResult == DialogResult.OK)
|
2015-08-14 09:51:58 +12:00
|
|
|
|
{
|
|
|
|
|
Program.DefaultTaskSettings.CaptureSettings.FFmpegOptions.CLIPath = taskSettings.TaskSettingsReference.CaptureSettings.FFmpegOptions.CLIPath =
|
2015-10-27 15:03:24 +13:00
|
|
|
|
taskSettings.CaptureSettings.FFmpegOptions.CLIPath = Program.DefaultFFmpegFilePath;
|
2015-09-13 08:32:51 +12:00
|
|
|
|
|
2017-12-05 19:53:04 +13:00
|
|
|
|
#if STEAM || WindowsStore
|
2015-09-13 08:32:51 +12:00
|
|
|
|
Program.DefaultTaskSettings.CaptureSettings.FFmpegOptions.OverrideCLIPath = taskSettings.TaskSettingsReference.CaptureSettings.FFmpegOptions.OverrideCLIPath =
|
|
|
|
|
taskSettings.CaptureSettings.FFmpegOptions.OverrideCLIPath = true;
|
|
|
|
|
#endif
|
2015-08-14 09:51:58 +12:00
|
|
|
|
}
|
2017-03-16 13:20:59 +13:00
|
|
|
|
else if (downloadDialogResult == DialogResult.Cancel)
|
2017-03-14 16:29:02 +13:00
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2015-08-14 09:51:58 +12:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void DownloaderForm_InstallRequested(string filePath)
|
|
|
|
|
{
|
2020-09-02 21:19:20 +12:00
|
|
|
|
bool result = FFmpegGitHubDownloader.ExtractFFmpeg(filePath, Program.ToolsFolder);
|
2015-08-14 09:51:58 +12:00
|
|
|
|
|
|
|
|
|
if (result)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show(Resources.ScreenRecordForm_DownloaderForm_InstallRequested_FFmpeg_successfully_downloaded_, "ShareX", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show(Resources.ScreenRecordForm_DownloaderForm_InstallRequested_Download_of_FFmpeg_failed_, "ShareX", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-08-16 20:34:46 +12:00
|
|
|
|
|
|
|
|
|
public static void PlayCaptureSound(TaskSettings taskSettings)
|
|
|
|
|
{
|
|
|
|
|
if (taskSettings == null) taskSettings = TaskSettings.GetDefaultTaskSettings();
|
|
|
|
|
|
2020-04-23 04:26:56 +12:00
|
|
|
|
if (taskSettings.AdvancedSettings.UseCustomCaptureSound && !string.IsNullOrEmpty(taskSettings.AdvancedSettings.CustomCaptureSoundPath))
|
2015-08-16 20:34:46 +12:00
|
|
|
|
{
|
|
|
|
|
Helpers.PlaySoundAsync(taskSettings.AdvancedSettings.CustomCaptureSoundPath);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Helpers.PlaySoundAsync(Resources.CaptureSound);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void PlayTaskCompleteSound(TaskSettings taskSettings)
|
|
|
|
|
{
|
|
|
|
|
if (taskSettings == null) taskSettings = TaskSettings.GetDefaultTaskSettings();
|
|
|
|
|
|
2020-04-23 04:26:56 +12:00
|
|
|
|
if (taskSettings.AdvancedSettings.UseCustomTaskCompletedSound && !string.IsNullOrEmpty(taskSettings.AdvancedSettings.CustomTaskCompletedSoundPath))
|
2015-08-16 20:34:46 +12:00
|
|
|
|
{
|
2015-08-17 09:51:18 +12:00
|
|
|
|
Helpers.PlaySoundAsync(taskSettings.AdvancedSettings.CustomTaskCompletedSoundPath);
|
2015-08-16 20:34:46 +12:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Helpers.PlaySoundAsync(Resources.TaskCompletedSound);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void PlayErrorSound(TaskSettings taskSettings)
|
|
|
|
|
{
|
|
|
|
|
if (taskSettings == null) taskSettings = TaskSettings.GetDefaultTaskSettings();
|
|
|
|
|
|
|
|
|
|
if (taskSettings.AdvancedSettings.UseCustomErrorSound && !string.IsNullOrEmpty(taskSettings.AdvancedSettings.CustomErrorSoundPath))
|
|
|
|
|
{
|
|
|
|
|
Helpers.PlaySoundAsync(taskSettings.AdvancedSettings.CustomErrorSoundPath);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Helpers.PlaySoundAsync(Resources.ErrorSound);
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-04-22 03:23:03 +12:00
|
|
|
|
|
2016-04-30 10:26:49 +12:00
|
|
|
|
public static void OpenUploadersConfigWindow(IUploaderService uploaderService = null)
|
|
|
|
|
{
|
2017-03-27 04:19:52 +13:00
|
|
|
|
SettingManager.WaitUploadersConfig();
|
2016-04-30 10:26:49 +12:00
|
|
|
|
|
2017-01-17 06:57:40 +13:00
|
|
|
|
bool firstInstance = !UploadersConfigForm.IsInstanceActive;
|
|
|
|
|
|
|
|
|
|
UploadersConfigForm form = UploadersConfigForm.GetFormInstance(Program.UploadersConfig);
|
2016-04-30 20:30:03 +12:00
|
|
|
|
|
|
|
|
|
if (firstInstance)
|
2016-04-30 10:26:49 +12:00
|
|
|
|
{
|
2017-03-27 08:21:10 +13:00
|
|
|
|
form.FormClosed += (sender, e) => SettingManager.SaveUploadersConfigAsync();
|
2016-04-30 20:30:03 +12:00
|
|
|
|
|
2016-04-30 10:26:49 +12:00
|
|
|
|
if (uploaderService != null)
|
|
|
|
|
{
|
2016-04-30 20:30:03 +12:00
|
|
|
|
form.NavigateToTabPage(uploaderService.GetUploadersConfigTabPage(form));
|
2016-04-30 10:26:49 +12:00
|
|
|
|
}
|
|
|
|
|
|
2016-04-30 20:30:03 +12:00
|
|
|
|
form.Show();
|
2016-04-30 10:26:49 +12:00
|
|
|
|
}
|
2016-04-30 20:30:03 +12:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (uploaderService != null)
|
|
|
|
|
{
|
|
|
|
|
form.NavigateToTabPage(uploaderService.GetUploadersConfigTabPage(form));
|
|
|
|
|
}
|
2016-04-30 10:26:49 +12:00
|
|
|
|
|
2016-04-30 20:30:03 +12:00
|
|
|
|
form.ForceActivate();
|
|
|
|
|
}
|
2016-04-30 10:26:49 +12:00
|
|
|
|
}
|
2016-05-22 06:33:25 +12:00
|
|
|
|
|
2019-01-23 23:13:48 +13:00
|
|
|
|
public static void OpenCustomUploaderSettingsWindow()
|
|
|
|
|
{
|
|
|
|
|
SettingManager.WaitUploadersConfig();
|
|
|
|
|
|
|
|
|
|
bool firstInstance = !CustomUploaderSettingsForm.IsInstanceActive;
|
|
|
|
|
|
|
|
|
|
CustomUploaderSettingsForm form = CustomUploaderSettingsForm.GetFormInstance(Program.UploadersConfig);
|
|
|
|
|
|
|
|
|
|
if (firstInstance)
|
|
|
|
|
{
|
|
|
|
|
form.FormClosed += (sender, e) => SettingManager.SaveUploadersConfigAsync();
|
|
|
|
|
form.Show();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
form.ForceActivate();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-06 07:07:42 +12:00
|
|
|
|
public static Image FindMenuIcon<T>(T value) where T : Enum
|
2016-05-22 06:33:25 +12:00
|
|
|
|
{
|
2020-04-06 07:07:42 +12:00
|
|
|
|
if (value is AfterCaptureTasks afterCaptureTask)
|
|
|
|
|
{
|
|
|
|
|
switch (afterCaptureTask)
|
|
|
|
|
{
|
|
|
|
|
default: throw new Exception("Icon missing for after capture task: " + afterCaptureTask);
|
|
|
|
|
case AfterCaptureTasks.ShowQuickTaskMenu: return Resources.ui_menu_blue;
|
|
|
|
|
case AfterCaptureTasks.ShowAfterCaptureWindow: return Resources.application_text_image;
|
|
|
|
|
case AfterCaptureTasks.AddImageEffects: return Resources.image_saturation;
|
|
|
|
|
case AfterCaptureTasks.AnnotateImage: return Resources.image_pencil;
|
|
|
|
|
case AfterCaptureTasks.CopyImageToClipboard: return Resources.clipboard_paste_image;
|
|
|
|
|
case AfterCaptureTasks.SendImageToPrinter: return Resources.printer;
|
|
|
|
|
case AfterCaptureTasks.SaveImageToFile: return Resources.disk;
|
|
|
|
|
case AfterCaptureTasks.SaveImageToFileWithDialog: return Resources.disk_rename;
|
|
|
|
|
case AfterCaptureTasks.SaveThumbnailImageToFile: return Resources.disk_small;
|
|
|
|
|
case AfterCaptureTasks.PerformActions: return Resources.application_terminal;
|
|
|
|
|
case AfterCaptureTasks.CopyFileToClipboard: return Resources.clipboard_block;
|
|
|
|
|
case AfterCaptureTasks.CopyFilePathToClipboard: return Resources.clipboard_list;
|
|
|
|
|
case AfterCaptureTasks.ShowInExplorer: return Resources.folder_stand;
|
|
|
|
|
case AfterCaptureTasks.ScanQRCode: return ShareXResources.IsDarkTheme ? Resources.barcode_2d_white : Resources.barcode_2d;
|
|
|
|
|
case AfterCaptureTasks.DoOCR: return ShareXResources.IsDarkTheme ? Resources.edit_drop_cap_white : Resources.edit_drop_cap;
|
|
|
|
|
case AfterCaptureTasks.ShowBeforeUploadWindow: return Resources.application__arrow;
|
|
|
|
|
case AfterCaptureTasks.UploadImageToHost: return Resources.upload_cloud;
|
|
|
|
|
case AfterCaptureTasks.DeleteFile: return Resources.bin;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (value is AfterUploadTasks afterUploadTask)
|
2016-05-22 06:33:25 +12:00
|
|
|
|
{
|
2020-04-06 07:07:42 +12:00
|
|
|
|
switch (afterUploadTask)
|
2016-05-22 06:33:25 +12:00
|
|
|
|
{
|
2020-04-06 07:07:42 +12:00
|
|
|
|
default: throw new Exception("Icon missing for after upload task: " + afterUploadTask);
|
|
|
|
|
case AfterUploadTasks.ShowAfterUploadWindow: return Resources.application_browser;
|
|
|
|
|
case AfterUploadTasks.UseURLShortener: return ShareXResources.IsDarkTheme ? Resources.edit_scale_white : Resources.edit_scale;
|
|
|
|
|
case AfterUploadTasks.ShareURL: return Resources.globe_share;
|
|
|
|
|
case AfterUploadTasks.CopyURLToClipboard: return Resources.clipboard_paste_document_text;
|
|
|
|
|
case AfterUploadTasks.OpenURL: return Resources.globe__arrow;
|
|
|
|
|
case AfterUploadTasks.ShowQRCode: return ShareXResources.IsDarkTheme ? Resources.barcode_2d_white : Resources.barcode_2d;
|
2016-05-22 06:33:25 +12:00
|
|
|
|
}
|
|
|
|
|
}
|
2020-04-06 07:07:42 +12:00
|
|
|
|
else if (value is HotkeyType hotkeyType)
|
2016-05-22 06:33:25 +12:00
|
|
|
|
{
|
2020-04-06 07:07:42 +12:00
|
|
|
|
switch (hotkeyType)
|
2016-05-22 06:33:25 +12:00
|
|
|
|
{
|
2020-04-06 07:07:42 +12:00
|
|
|
|
default: throw new Exception("Icon missing for hotkey type: " + hotkeyType);
|
|
|
|
|
case HotkeyType.None: return null;
|
|
|
|
|
// Upload
|
|
|
|
|
case HotkeyType.FileUpload: return Resources.folder_open_document;
|
|
|
|
|
case HotkeyType.FolderUpload: return Resources.folder;
|
|
|
|
|
case HotkeyType.ClipboardUpload: return Resources.clipboard;
|
|
|
|
|
case HotkeyType.ClipboardUploadWithContentViewer: return Resources.clipboard_task;
|
|
|
|
|
case HotkeyType.UploadText: return Resources.notebook;
|
|
|
|
|
case HotkeyType.UploadURL: return Resources.drive;
|
|
|
|
|
case HotkeyType.DragDropUpload: return Resources.inbox;
|
|
|
|
|
case HotkeyType.ShortenURL: return ShareXResources.IsDarkTheme ? Resources.edit_scale_white : Resources.edit_scale;
|
|
|
|
|
case HotkeyType.StopUploads: return Resources.cross_button;
|
|
|
|
|
// Screen capture
|
|
|
|
|
case HotkeyType.PrintScreen: return Resources.layer_fullscreen;
|
|
|
|
|
case HotkeyType.ActiveWindow: return Resources.application_blue;
|
|
|
|
|
case HotkeyType.ActiveMonitor: return Resources.monitor;
|
|
|
|
|
case HotkeyType.RectangleRegion: return Resources.layer_shape;
|
|
|
|
|
case HotkeyType.RectangleLight: return Resources.Rectangle;
|
|
|
|
|
case HotkeyType.RectangleTransparent: return Resources.layer_transparent;
|
|
|
|
|
case HotkeyType.CustomRegion: return Resources.layer__arrow;
|
|
|
|
|
case HotkeyType.LastRegion: return Resources.layers;
|
|
|
|
|
case HotkeyType.ScrollingCapture: return Resources.ui_scroll_pane_image;
|
|
|
|
|
case HotkeyType.TextCapture: return ShareXResources.IsDarkTheme ? Resources.edit_drop_cap_white : Resources.edit_drop_cap;
|
|
|
|
|
case HotkeyType.AutoCapture: return Resources.clock;
|
|
|
|
|
case HotkeyType.StartAutoCapture: return Resources.clock__arrow;
|
|
|
|
|
// Screen record
|
|
|
|
|
case HotkeyType.ScreenRecorder: return Resources.camcorder_image;
|
|
|
|
|
case HotkeyType.ScreenRecorderActiveWindow: return Resources.camcorder__arrow;
|
|
|
|
|
case HotkeyType.ScreenRecorderCustomRegion: return Resources.camcorder__arrow;
|
|
|
|
|
case HotkeyType.StartScreenRecorder: return Resources.camcorder__arrow;
|
|
|
|
|
case HotkeyType.ScreenRecorderGIF: return Resources.film;
|
|
|
|
|
case HotkeyType.ScreenRecorderGIFActiveWindow: return Resources.film__arrow;
|
|
|
|
|
case HotkeyType.ScreenRecorderGIFCustomRegion: return Resources.film__arrow;
|
|
|
|
|
case HotkeyType.StartScreenRecorderGIF: return Resources.film__arrow;
|
|
|
|
|
case HotkeyType.AbortScreenRecording: return Resources.camcorder__exclamation;
|
|
|
|
|
// Tools
|
|
|
|
|
case HotkeyType.ColorPicker: return Resources.color;
|
|
|
|
|
case HotkeyType.ScreenColorPicker: return Resources.pipette;
|
|
|
|
|
case HotkeyType.ImageEditor: return Resources.image_pencil;
|
|
|
|
|
case HotkeyType.ImageEffects: return Resources.image_saturation;
|
|
|
|
|
case HotkeyType.HashCheck: return Resources.application_task;
|
|
|
|
|
case HotkeyType.DNSChanger: return Resources.network_ip;
|
|
|
|
|
case HotkeyType.QRCode: return ShareXResources.IsDarkTheme ? Resources.barcode_2d_white : Resources.barcode_2d;
|
2020-07-20 02:30:21 +12:00
|
|
|
|
case HotkeyType.QRCodeDecodeFromScreen: return ShareXResources.IsDarkTheme ? Resources.barcode_2d_white : Resources.barcode_2d;
|
2020-04-06 07:07:42 +12:00
|
|
|
|
case HotkeyType.Ruler: return Resources.ruler_triangle;
|
|
|
|
|
case HotkeyType.IndexFolder: return Resources.folder_tree;
|
|
|
|
|
case HotkeyType.ImageCombiner: return Resources.document_break;
|
|
|
|
|
case HotkeyType.ImageSplitter: return Resources.image_split;
|
|
|
|
|
case HotkeyType.ImageThumbnailer: return Resources.image_resize_actual;
|
|
|
|
|
case HotkeyType.VideoConverter: return Resources.camcorder_pencil;
|
|
|
|
|
case HotkeyType.VideoThumbnailer: return Resources.images_stack;
|
|
|
|
|
case HotkeyType.TweetMessage: return Resources.Twitter;
|
|
|
|
|
case HotkeyType.MonitorTest: return Resources.monitor;
|
|
|
|
|
// Other
|
|
|
|
|
case HotkeyType.DisableHotkeys: return Resources.keyboard__minus;
|
|
|
|
|
case HotkeyType.OpenMainWindow: return Resources.application_home;
|
|
|
|
|
case HotkeyType.OpenScreenshotsFolder: return Resources.folder_open_image;
|
|
|
|
|
case HotkeyType.OpenHistory: return Resources.application_blog;
|
|
|
|
|
case HotkeyType.OpenImageHistory: return Resources.application_icon_large;
|
|
|
|
|
case HotkeyType.ToggleActionsToolbar: return Resources.ui_toolbar__arrow;
|
|
|
|
|
case HotkeyType.ExitShareX: return Resources.cross;
|
2016-05-22 06:33:25 +12:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2016-07-22 02:23:45 +12:00
|
|
|
|
|
2020-04-06 07:07:42 +12:00
|
|
|
|
public static Image FindMenuIcon<T>(int index) where T : Enum
|
2016-12-29 00:23:01 +13:00
|
|
|
|
{
|
2020-04-06 07:07:42 +12:00
|
|
|
|
T value = Helpers.GetEnumFromIndex<T>(index);
|
|
|
|
|
return FindMenuIcon(value);
|
2016-12-29 00:23:01 +13:00
|
|
|
|
}
|
|
|
|
|
|
2016-07-22 02:23:45 +12:00
|
|
|
|
public static Screenshot GetScreenshot(TaskSettings taskSettings = null)
|
|
|
|
|
{
|
|
|
|
|
if (taskSettings == null) taskSettings = TaskSettings.GetDefaultTaskSettings();
|
|
|
|
|
|
|
|
|
|
Screenshot screenshot = new Screenshot()
|
|
|
|
|
{
|
|
|
|
|
CaptureCursor = taskSettings.CaptureSettings.ShowCursor,
|
|
|
|
|
CaptureClientArea = taskSettings.CaptureSettings.CaptureClientArea,
|
|
|
|
|
RemoveOutsideScreenArea = true,
|
|
|
|
|
CaptureShadow = taskSettings.CaptureSettings.CaptureShadow,
|
|
|
|
|
ShadowOffset = taskSettings.CaptureSettings.CaptureShadowOffset,
|
|
|
|
|
AutoHideTaskbar = taskSettings.CaptureSettings.CaptureAutoHideTaskbar
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return screenshot;
|
|
|
|
|
}
|
2017-01-10 05:41:55 +13:00
|
|
|
|
|
2020-07-06 10:37:56 +12:00
|
|
|
|
public static void ImportCustomUploader(string filePath)
|
2017-01-10 05:41:55 +13:00
|
|
|
|
{
|
|
|
|
|
if (Program.UploadersConfig != null)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2020-09-30 02:42:46 +13:00
|
|
|
|
CustomUploaderItem cui = JsonHelpers.DeserializeFromFile<CustomUploaderItem>(filePath);
|
2017-01-10 05:41:55 +13:00
|
|
|
|
|
|
|
|
|
if (cui != null)
|
|
|
|
|
{
|
2017-01-16 05:42:31 +13:00
|
|
|
|
bool activate = false;
|
|
|
|
|
|
2017-01-10 19:38:30 +13:00
|
|
|
|
if (cui.DestinationType == CustomUploaderDestinationType.None)
|
|
|
|
|
{
|
2020-09-23 22:24:07 +12:00
|
|
|
|
DialogResult result = MessageBox.Show($"Would you like to add \"{cui}\" custom uploader?",
|
2017-01-10 19:38:30 +13:00
|
|
|
|
"ShareX - Custom uploader confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);
|
|
|
|
|
|
|
|
|
|
if (result == DialogResult.No)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
List<string> destinations = new List<string>();
|
2017-12-06 02:47:32 +13:00
|
|
|
|
if (cui.DestinationType.HasFlag(CustomUploaderDestinationType.ImageUploader)) destinations.Add("images");
|
|
|
|
|
if (cui.DestinationType.HasFlag(CustomUploaderDestinationType.TextUploader)) destinations.Add("texts");
|
|
|
|
|
if (cui.DestinationType.HasFlag(CustomUploaderDestinationType.FileUploader)) destinations.Add("files");
|
|
|
|
|
if (cui.DestinationType.HasFlag(CustomUploaderDestinationType.URLShortener) ||
|
2020-07-06 10:37:56 +12:00
|
|
|
|
cui.DestinationType.HasFlag(CustomUploaderDestinationType.URLSharingService)) destinations.Add("urls");
|
2017-01-10 19:38:30 +13:00
|
|
|
|
|
|
|
|
|
string destinationsText = string.Join("/", destinations);
|
|
|
|
|
|
2020-09-23 22:24:07 +12:00
|
|
|
|
DialogResult result = MessageBox.Show($"Would you like to set \"{cui}\" as the active custom uploader for {destinationsText}?",
|
2017-01-10 19:38:30 +13:00
|
|
|
|
"ShareX - Custom uploader confirmation", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);
|
|
|
|
|
|
|
|
|
|
if (result == DialogResult.Yes)
|
|
|
|
|
{
|
2017-01-16 05:42:31 +13:00
|
|
|
|
activate = true;
|
2017-01-10 19:38:30 +13:00
|
|
|
|
}
|
|
|
|
|
else if (result == DialogResult.Cancel)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-05 00:37:24 +13:00
|
|
|
|
cui.CheckBackwardCompatibility();
|
2017-01-10 05:41:55 +13:00
|
|
|
|
Program.UploadersConfig.CustomUploadersList.Add(cui);
|
2017-01-16 05:42:31 +13:00
|
|
|
|
|
|
|
|
|
if (activate)
|
|
|
|
|
{
|
|
|
|
|
int index = Program.UploadersConfig.CustomUploadersList.Count - 1;
|
|
|
|
|
|
2017-12-06 02:47:32 +13:00
|
|
|
|
if (cui.DestinationType.HasFlag(CustomUploaderDestinationType.ImageUploader))
|
2017-01-16 05:42:31 +13:00
|
|
|
|
{
|
|
|
|
|
Program.UploadersConfig.CustomImageUploaderSelected = index;
|
|
|
|
|
Program.DefaultTaskSettings.ImageDestination = ImageDestination.CustomImageUploader;
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-06 02:47:32 +13:00
|
|
|
|
if (cui.DestinationType.HasFlag(CustomUploaderDestinationType.TextUploader))
|
2017-01-16 05:42:31 +13:00
|
|
|
|
{
|
|
|
|
|
Program.UploadersConfig.CustomTextUploaderSelected = index;
|
|
|
|
|
Program.DefaultTaskSettings.TextDestination = TextDestination.CustomTextUploader;
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-06 02:47:32 +13:00
|
|
|
|
if (cui.DestinationType.HasFlag(CustomUploaderDestinationType.FileUploader))
|
2017-01-16 05:42:31 +13:00
|
|
|
|
{
|
|
|
|
|
Program.UploadersConfig.CustomFileUploaderSelected = index;
|
|
|
|
|
Program.DefaultTaskSettings.FileDestination = FileDestination.CustomFileUploader;
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-06 02:47:32 +13:00
|
|
|
|
if (cui.DestinationType.HasFlag(CustomUploaderDestinationType.URLShortener))
|
2017-01-16 05:42:31 +13:00
|
|
|
|
{
|
|
|
|
|
Program.UploadersConfig.CustomURLShortenerSelected = index;
|
|
|
|
|
Program.DefaultTaskSettings.URLShortenerDestination = UrlShortenerType.CustomURLShortener;
|
|
|
|
|
}
|
2017-09-10 22:55:21 +12:00
|
|
|
|
|
2017-12-06 02:47:32 +13:00
|
|
|
|
if (cui.DestinationType.HasFlag(CustomUploaderDestinationType.URLSharingService))
|
2017-09-10 22:55:21 +12:00
|
|
|
|
{
|
|
|
|
|
Program.UploadersConfig.CustomURLSharingServiceSelected = index;
|
|
|
|
|
Program.DefaultTaskSettings.URLSharingServiceDestination = URLSharingServices.CustomURLSharingService;
|
|
|
|
|
}
|
2017-01-16 05:42:31 +13:00
|
|
|
|
|
|
|
|
|
Program.MainForm.UpdateCheckStates();
|
|
|
|
|
Program.MainForm.UpdateUploaderMenuNames();
|
2019-02-20 20:57:30 +13:00
|
|
|
|
}
|
2017-01-17 06:57:40 +13:00
|
|
|
|
|
2019-02-20 20:57:30 +13:00
|
|
|
|
if (CustomUploaderSettingsForm.IsInstanceActive)
|
|
|
|
|
{
|
|
|
|
|
CustomUploaderSettingsForm.CustomUploaderUpdateTab();
|
2017-01-16 05:42:31 +13:00
|
|
|
|
}
|
2017-01-10 05:41:55 +13:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
DebugHelper.WriteException(e);
|
2020-09-30 03:48:58 +13:00
|
|
|
|
e.ShowError();
|
2017-01-10 05:41:55 +13:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-01-20 01:39:10 +13:00
|
|
|
|
|
2020-07-06 10:37:56 +12:00
|
|
|
|
public static void ImportImageEffect(string filePath)
|
|
|
|
|
{
|
|
|
|
|
string configJson = null;
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
configJson = ImageEffectPackager.ExtractPackage(filePath, Program.ImageEffectsFolder);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
ex.ShowError(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(configJson))
|
|
|
|
|
{
|
|
|
|
|
ImageEffectsForm imageEffectsForm = OpenImageEffectsSingleton(Program.DefaultTaskSettings);
|
|
|
|
|
|
|
|
|
|
if (imageEffectsForm != null)
|
|
|
|
|
{
|
|
|
|
|
imageEffectsForm.ImportImageEffect(configJson);
|
|
|
|
|
}
|
2020-09-23 22:24:07 +12:00
|
|
|
|
|
|
|
|
|
// TODO: Translate
|
|
|
|
|
if (!Program.DefaultTaskSettings.AfterCaptureJob.HasFlag(AfterCaptureTasks.AddImageEffects) &&
|
|
|
|
|
MessageBox.Show("Would you like to enable image effects?\r\n\r\nYou can later disable it from \"After capture tasks\" menu.",
|
|
|
|
|
"ShareX", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
|
|
|
|
{
|
|
|
|
|
Program.DefaultTaskSettings.AfterCaptureJob = Program.DefaultTaskSettings.AfterCaptureJob.Add(AfterCaptureTasks.AddImageEffects);
|
|
|
|
|
Program.MainForm.UpdateCheckStates();
|
|
|
|
|
}
|
2020-07-06 10:37:56 +12:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-20 01:39:10 +13:00
|
|
|
|
public static void OpenActionsToolbar()
|
|
|
|
|
{
|
|
|
|
|
ActionsToolbarForm.Instance.ForceActivate();
|
|
|
|
|
}
|
2017-01-21 00:56:44 +13:00
|
|
|
|
|
|
|
|
|
public static void ToggleActionsToolbar()
|
|
|
|
|
{
|
|
|
|
|
if (ActionsToolbarForm.IsInstanceActive)
|
|
|
|
|
{
|
|
|
|
|
ActionsToolbarForm.Instance.Close();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
ActionsToolbarForm.Instance.ForceActivate();
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-11-04 01:27:26 +13:00
|
|
|
|
|
|
|
|
|
public static void DownloadAppVeyorBuild()
|
|
|
|
|
{
|
|
|
|
|
AppVeyorUpdateChecker updateChecker = new AppVeyorUpdateChecker()
|
|
|
|
|
{
|
2018-05-19 05:39:01 +12:00
|
|
|
|
IsBeta = Program.Dev,
|
2017-11-04 01:27:26 +13:00
|
|
|
|
IsPortable = Program.Portable,
|
|
|
|
|
Proxy = HelpersOptions.CurrentProxy.GetWebProxy()
|
|
|
|
|
};
|
|
|
|
|
updateChecker.CheckUpdate();
|
|
|
|
|
UpdateMessageBox.Start(updateChecker);
|
|
|
|
|
}
|
2018-01-25 20:45:56 +13:00
|
|
|
|
|
2018-12-20 09:47:38 +13:00
|
|
|
|
public static Image CreateQRCode(string text, int width, int height)
|
2018-01-25 20:45:56 +13:00
|
|
|
|
{
|
2018-02-26 19:26:35 +13:00
|
|
|
|
if (CheckQRCodeContent(text))
|
2018-01-25 20:45:56 +13:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
BarcodeWriter writer = new BarcodeWriter
|
|
|
|
|
{
|
|
|
|
|
Format = BarcodeFormat.QR_CODE,
|
|
|
|
|
Options = new QrCodeEncodingOptions
|
|
|
|
|
{
|
|
|
|
|
Width = width,
|
|
|
|
|
Height = height,
|
|
|
|
|
CharacterSet = "UTF-8"
|
|
|
|
|
},
|
|
|
|
|
Renderer = new BitmapRenderer()
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return writer.Write(text);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
e.ShowError();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-20 09:47:38 +13:00
|
|
|
|
public static Image CreateQRCode(string text, int size)
|
2018-02-26 19:47:34 +13:00
|
|
|
|
{
|
2018-12-20 09:47:38 +13:00
|
|
|
|
return CreateQRCode(text, size, size);
|
2018-02-26 19:47:34 +13:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-20 09:47:38 +13:00
|
|
|
|
public static string[] BarcodeScan(Bitmap bmp, bool scanQRCodeOnly = false)
|
2018-01-25 20:45:56 +13:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
BarcodeReader barcodeReader = new BarcodeReader
|
|
|
|
|
{
|
|
|
|
|
AutoRotate = true,
|
|
|
|
|
TryInverted = true,
|
|
|
|
|
Options = new DecodingOptions
|
|
|
|
|
{
|
|
|
|
|
TryHarder = true
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2018-12-20 09:47:38 +13:00
|
|
|
|
if (scanQRCodeOnly)
|
|
|
|
|
{
|
|
|
|
|
barcodeReader.Options.PossibleFormats = new List<BarcodeFormat>() { BarcodeFormat.QR_CODE };
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-25 20:45:56 +13:00
|
|
|
|
Result[] results = barcodeReader.DecodeMultiple(bmp);
|
|
|
|
|
|
|
|
|
|
if (results != null)
|
|
|
|
|
{
|
2018-12-20 09:47:38 +13:00
|
|
|
|
return results.Where(x => x != null && !string.IsNullOrEmpty(x.Text)).Select(x => x.Text).ToArray();
|
2018-01-25 20:45:56 +13:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
e.ShowError();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2018-02-26 19:26:35 +13:00
|
|
|
|
|
|
|
|
|
public static bool CheckQRCodeContent(string content)
|
|
|
|
|
{
|
|
|
|
|
return !string.IsNullOrEmpty(content) && Encoding.UTF8.GetByteCount(content) <= 2952;
|
|
|
|
|
}
|
2019-03-31 01:54:46 +13:00
|
|
|
|
|
2019-04-03 23:56:15 +13:00
|
|
|
|
public static void ShowBalloonTip(string text, ToolTipIcon icon, int timeout, string title = "ShareX", BalloonTipAction clickAction = null)
|
2019-03-31 01:54:46 +13:00
|
|
|
|
{
|
|
|
|
|
if (Program.MainForm != null && !Program.MainForm.IsDisposed && Program.MainForm.niTray != null && Program.MainForm.niTray.Visible)
|
|
|
|
|
{
|
2019-04-03 23:56:15 +13:00
|
|
|
|
Program.MainForm.niTray.Tag = clickAction;
|
2019-03-31 01:54:46 +13:00
|
|
|
|
Program.MainForm.niTray.ShowBalloonTip(timeout, title, text, icon);
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-01-06 10:57:45 +13:00
|
|
|
|
|
2020-10-01 06:37:44 +13:00
|
|
|
|
public static void ShowNotificationTip(string text, string title = "ShareX")
|
2020-10-01 05:38:17 +13:00
|
|
|
|
{
|
|
|
|
|
NotificationFormConfig toastConfig = new NotificationFormConfig()
|
|
|
|
|
{
|
|
|
|
|
Duration = (int)(Program.DefaultTaskSettings.AdvancedSettings.ToastWindowDuration * 1000),
|
|
|
|
|
FadeDuration = (int)(Program.DefaultTaskSettings.AdvancedSettings.ToastWindowFadeDuration * 1000),
|
|
|
|
|
Placement = Program.DefaultTaskSettings.AdvancedSettings.ToastWindowPlacement,
|
|
|
|
|
Size = Program.DefaultTaskSettings.AdvancedSettings.ToastWindowSize,
|
2020-10-01 06:37:44 +13:00
|
|
|
|
Text = text,
|
|
|
|
|
Title = title
|
2020-10-01 05:38:17 +13:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
NotificationForm.Show(toastConfig);
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-06 10:57:45 +13:00
|
|
|
|
public static bool IsUploadAllowed()
|
|
|
|
|
{
|
|
|
|
|
if (Program.Settings.DisableUpload)
|
|
|
|
|
{
|
2020-02-15 10:21:30 +13:00
|
|
|
|
MessageBox.Show(Resources.ThisFeatureWillNotWorkWhenDisableUploadOptionIsEnabled, "ShareX",
|
2020-01-06 10:57:45 +13:00
|
|
|
|
MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
}
|