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
|
2015-08-13 13:07:38 +12:00
|
|
|
|
Copyright (c) 2007-2015 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;
|
|
|
|
|
using ShareX.ImageEffectsLib;
|
2015-08-25 04:38:35 +12:00
|
|
|
|
using ShareX.IRCLib;
|
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;
|
|
|
|
|
using ShareX.UploadersLib.HelperClasses;
|
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.Drawing2D;
|
|
|
|
|
using System.Drawing.Imaging;
|
|
|
|
|
using System.IO;
|
2015-03-08 14:13:55 +13:00
|
|
|
|
using System.Linq;
|
2013-11-03 23:53:49 +13:00
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
|
|
|
|
namespace ShareX
|
|
|
|
|
{
|
|
|
|
|
public static class TaskHelpers
|
|
|
|
|
{
|
|
|
|
|
public static ImageData PrepareImage(Image img, TaskSettings taskSettings)
|
|
|
|
|
{
|
|
|
|
|
ImageData imageData = new ImageData();
|
2014-05-11 23:47:37 +12:00
|
|
|
|
imageData.ImageFormat = taskSettings.ImageSettings.ImageFormat;
|
2013-11-03 23:53:49 +13:00
|
|
|
|
|
2014-05-11 23:47:37 +12:00
|
|
|
|
if (taskSettings.ImageSettings.ImageFormat == EImageFormat.JPEG)
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2013-11-09 13:56:37 +13:00
|
|
|
|
img = ImageHelpers.FillBackground(img, Color.White);
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
|
2014-05-11 23:47:37 +12:00
|
|
|
|
imageData.ImageStream = SaveImage(img, taskSettings.ImageSettings.ImageFormat, taskSettings);
|
2013-11-03 23:53:49 +13:00
|
|
|
|
|
2014-05-11 23:47:37 +12:00
|
|
|
|
int sizeLimit = taskSettings.ImageSettings.ImageSizeLimit * 1000;
|
2013-11-03 23:53:49 +13:00
|
|
|
|
|
2014-05-11 23:47:37 +12:00
|
|
|
|
if (taskSettings.ImageSettings.ImageFormat != taskSettings.ImageSettings.ImageFormat2 && sizeLimit > 0 && imageData.ImageStream.Length > sizeLimit)
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2014-05-11 23:47:37 +12:00
|
|
|
|
if (taskSettings.ImageSettings.ImageFormat2 == EImageFormat.JPEG)
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2013-11-09 13:56:37 +13:00
|
|
|
|
img = ImageHelpers.FillBackground(img, Color.White);
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
|
2014-05-11 23:47:37 +12:00
|
|
|
|
imageData.ImageStream = SaveImage(img, taskSettings.ImageSettings.ImageFormat2, taskSettings);
|
|
|
|
|
imageData.ImageFormat = taskSettings.ImageSettings.ImageFormat2;
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return imageData;
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-23 09:55:49 +12:00
|
|
|
|
public static string CreateThumbnail(Image img, 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 ||
|
|
|
|
|
(img.Width > taskSettings.ImageSettings.ThumbnailWidth && img.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";
|
2014-10-19 10:48:47 +13:00
|
|
|
|
string thumbnailFilePath = CheckFilePath(folder, thumbnailFileName, taskSettings);
|
2014-04-23 08:44:58 +12:00
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(thumbnailFilePath))
|
|
|
|
|
{
|
|
|
|
|
Image thumbImage = null;
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
thumbImage = (Image)img.Clone();
|
|
|
|
|
thumbImage = new Resize
|
|
|
|
|
{
|
2014-05-11 23:47:37 +12:00
|
|
|
|
Width = taskSettings.ImageSettings.ThumbnailWidth,
|
|
|
|
|
Height = taskSettings.ImageSettings.ThumbnailHeight
|
2014-04-23 08:44:58 +12:00
|
|
|
|
}.Apply(thumbImage);
|
|
|
|
|
thumbImage = ImageHelpers.FillBackground(thumbImage, Color.White);
|
|
|
|
|
thumbImage.SaveJPG(thumbnailFilePath, 90);
|
2014-04-23 09:00:41 +12:00
|
|
|
|
return thumbnailFilePath;
|
2014-04-23 08:44:58 +12:00
|
|
|
|
}
|
2014-12-18 07:24:27 +13:00
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
DebugHelper.WriteException(e);
|
|
|
|
|
}
|
2014-04-23 08:44:58 +12:00
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
if (thumbImage != null)
|
|
|
|
|
{
|
|
|
|
|
thumbImage.Dispose();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-23 09:00:41 +12:00
|
|
|
|
return null;
|
2014-04-23 08:44:58 +12:00
|
|
|
|
}
|
|
|
|
|
|
2013-11-03 23:53:49 +13:00
|
|
|
|
public static MemoryStream SaveImage(Image img, EImageFormat imageFormat, TaskSettings taskSettings)
|
|
|
|
|
{
|
|
|
|
|
MemoryStream stream = new MemoryStream();
|
|
|
|
|
|
|
|
|
|
switch (imageFormat)
|
|
|
|
|
{
|
|
|
|
|
case EImageFormat.PNG:
|
|
|
|
|
img.Save(stream, ImageFormat.Png);
|
|
|
|
|
break;
|
|
|
|
|
case EImageFormat.JPEG:
|
2014-05-11 23:47:37 +12:00
|
|
|
|
img.SaveJPG(stream, taskSettings.ImageSettings.ImageJPEGQuality);
|
2013-11-03 23:53:49 +13:00
|
|
|
|
break;
|
|
|
|
|
case EImageFormat.GIF:
|
2014-05-11 23:47:37 +12:00
|
|
|
|
img.SaveGIF(stream, taskSettings.ImageSettings.ImageGIFQuality);
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-22 12:52:41 +13:00
|
|
|
|
public static string GetFilename(TaskSettings taskSettings, string extension = null, Image image = 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
|
|
|
|
|
2015-10-22 12:52:41 +13:00
|
|
|
|
if (image != null)
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2015-10-22 12:52:41 +13:00
|
|
|
|
nameParser.Picture = image;
|
|
|
|
|
|
|
|
|
|
ImageTag imageTag = image.Tag as ImageTag;
|
|
|
|
|
|
|
|
|
|
if (imageTag != null)
|
|
|
|
|
{
|
|
|
|
|
nameParser.WindowText = imageTag.ActiveWindowTitle;
|
|
|
|
|
nameParser.ProcessName = imageTag.ActiveProcessName;
|
|
|
|
|
}
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-23 11:43:04 +13:00
|
|
|
|
public static bool ShowAfterCaptureForm(TaskSettings taskSettings, out string fileName, Image img = null)
|
2014-07-19 07:13:32 +12:00
|
|
|
|
{
|
2015-10-23 11:43:04 +13:00
|
|
|
|
fileName = null;
|
|
|
|
|
|
2014-07-19 07:13:32 +12:00
|
|
|
|
if (taskSettings.GeneralSettings.ShowAfterCaptureTasksForm)
|
|
|
|
|
{
|
|
|
|
|
using (AfterCaptureForm afterCaptureForm = new AfterCaptureForm(img, taskSettings))
|
|
|
|
|
{
|
2015-10-23 11:43:04 +13:00
|
|
|
|
if (afterCaptureForm.ShowDialog() == DialogResult.Cancel)
|
2014-07-19 07:13:32 +12:00
|
|
|
|
{
|
2015-10-23 11:43:04 +13:00
|
|
|
|
if (img != null) img.Dispose();
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-05 00:31:35 +12:00
|
|
|
|
public static void AnnotateImage(string filePath)
|
2014-05-04 12:53:11 +12:00
|
|
|
|
{
|
2014-05-05 00:31:35 +12:00
|
|
|
|
AnnotateImage(null, filePath);
|
2014-05-04 12:53:11 +12:00
|
|
|
|
}
|
|
|
|
|
|
2014-05-04 15:27:27 +12:00
|
|
|
|
public static Image AnnotateImage(Image img, string imgPath)
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2014-05-04 15:27:27 +12:00
|
|
|
|
return ImageHelpers.AnnotateImage(img, imgPath, !Program.IsSandbox, Program.PersonalPath,
|
2013-11-03 23:53:49 +13:00
|
|
|
|
x => Program.MainForm.InvokeSafe(() => ClipboardHelpers.CopyImage(x)),
|
2014-08-04 11:28:07 +12:00
|
|
|
|
x => Program.MainForm.InvokeSafe(() => UploadManager.UploadImage(x)),
|
2014-05-05 00:31:35 +12:00
|
|
|
|
(x, filePath) => Program.MainForm.InvokeSafe(() => ImageHelpers.SaveImage(x, filePath)),
|
|
|
|
|
(x, filePath) =>
|
|
|
|
|
{
|
|
|
|
|
string newFilePath = null;
|
|
|
|
|
Program.MainForm.InvokeSafe(() => newFilePath = ImageHelpers.SaveImageFileDialog(x, filePath));
|
|
|
|
|
return newFilePath;
|
2014-09-26 17:58:04 +12:00
|
|
|
|
},
|
2014-10-19 10:48:47 +13:00
|
|
|
|
x => Program.MainForm.InvokeSafe(() => PrintImage(x)));
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static Image AddImageEffects(Image img, TaskSettings taskSettings)
|
|
|
|
|
{
|
2014-05-11 23:47:37 +12:00
|
|
|
|
if (taskSettings.ImageSettings.ShowImageEffectsWindowAfterCapture)
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2014-05-11 23:47:37 +12:00
|
|
|
|
using (ImageEffectsForm imageEffectsForm = new ImageEffectsForm(img, taskSettings.ImageSettings.ImageEffects))
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
|
|
|
|
if (imageEffectsForm.ShowDialog() == DialogResult.OK)
|
|
|
|
|
{
|
2014-05-11 23:47:37 +12:00
|
|
|
|
taskSettings.ImageSettings.ImageEffects = imageEffectsForm.Effects;
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
using (img)
|
|
|
|
|
{
|
2014-05-11 23:47:37 +12:00
|
|
|
|
return ImageEffectManager.ApplyEffects(img, taskSettings.ImageSettings.ImageEffects);
|
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");
|
|
|
|
|
AddExternalProgramFromFile(taskSettings, "OptiPNG", "optipng.exe");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void AddExternalProgramFromFile(TaskSettings taskSettings, string name, string filename, string args = "")
|
|
|
|
|
{
|
2014-05-11 23:47:37 +12:00
|
|
|
|
if (!taskSettings.ExternalPrograms.Exists(x => x.Name == name))
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
|
|
|
|
if (File.Exists(filename))
|
|
|
|
|
{
|
|
|
|
|
DebugHelper.WriteLine("Found program: " + filename);
|
|
|
|
|
|
2014-05-11 23:47:37 +12:00
|
|
|
|
taskSettings.ExternalPrograms.Add(new ExternalProgram(name, filename, args));
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void AddExternalProgramFromRegistry(TaskSettings taskSettings, string name, string filename)
|
|
|
|
|
{
|
2014-05-11 23:47:37 +12:00
|
|
|
|
if (!taskSettings.ExternalPrograms.Exists(x => x.Name == name))
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
|
|
|
|
ExternalProgram externalProgram = RegistryHelpers.FindProgram(name, filename);
|
|
|
|
|
|
|
|
|
|
if (externalProgram != null)
|
|
|
|
|
{
|
2014-05-11 23:47:37 +12:00
|
|
|
|
taskSettings.ExternalPrograms.Add(externalProgram);
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-21 22:29:24 +13:00
|
|
|
|
public static bool SelectRegion(out Rectangle rect, TaskSettings taskSettings)
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2015-09-27 23:02:53 +13:00
|
|
|
|
return Surface.SelectRegion(out rect, taskSettings.CaptureSettings.SurfaceOptions);
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
|
2015-01-25 13:58:00 +13:00
|
|
|
|
public static PointInfo SelectPointColor()
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2014-11-27 06:48:25 +13:00
|
|
|
|
using (RectangleRegion surface = new RectangleRegion())
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2015-05-13 05:02:51 +12:00
|
|
|
|
surface.ScreenColorPickerMode = true;
|
2015-05-13 05:08:49 +12:00
|
|
|
|
surface.Config.UseDimming = false;
|
2015-05-13 05:02:51 +12:00
|
|
|
|
surface.Config.ShowInfo = true;
|
|
|
|
|
surface.Config.ShowMagnifier = true;
|
2015-05-07 05:46:19 +12:00
|
|
|
|
surface.Config.ShowTips = false;
|
2013-11-03 23:53:49 +13:00
|
|
|
|
surface.Prepare();
|
|
|
|
|
surface.ShowDialog();
|
|
|
|
|
|
|
|
|
|
if (surface.Result == SurfaceResult.Region)
|
|
|
|
|
{
|
|
|
|
|
PointInfo pointInfo = new PointInfo();
|
2015-05-19 20:09:21 +12:00
|
|
|
|
pointInfo.Position = surface.CurrentPosition;
|
2015-01-25 13:22:46 +13:00
|
|
|
|
pointInfo.Color = surface.CurrentColor;
|
2013-11-03 23:53:49 +13:00
|
|
|
|
return pointInfo;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static Icon GetProgressIcon(int percentage)
|
|
|
|
|
{
|
|
|
|
|
using (Bitmap bmp = new Bitmap(16, 16))
|
|
|
|
|
using (Graphics g = Graphics.FromImage(bmp))
|
|
|
|
|
{
|
|
|
|
|
g.Clear(Color.Black);
|
|
|
|
|
|
|
|
|
|
int width = (int)(16 * (percentage / 100f));
|
|
|
|
|
|
|
|
|
|
if (width > 0)
|
|
|
|
|
{
|
|
|
|
|
using (Brush brush = new LinearGradientBrush(new Rectangle(0, 0, width, 16), Color.DarkBlue, Color.DodgerBlue, LinearGradientMode.Vertical))
|
|
|
|
|
{
|
|
|
|
|
g.FillRectangle(brush, 0, 0, width, 16);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-19 04:23:53 +13:00
|
|
|
|
using (Font font = new Font("Arial", 11, GraphicsUnit.Pixel))
|
2013-11-03 23:53:49 +13:00
|
|
|
|
using (StringFormat sf = new StringFormat { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center })
|
|
|
|
|
{
|
2014-07-20 07:10:25 +12:00
|
|
|
|
g.DrawString(percentage.ToString(), font, Brushes.White, 8, 8, sf);
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
|
2013-11-11 19:28:23 +13:00
|
|
|
|
g.DrawRectangleProper(Pens.WhiteSmoke, 0, 0, 16, 16);
|
2013-11-03 23:53:49 +13:00
|
|
|
|
|
|
|
|
|
return Icon.FromHandle(bmp.GetHicon());
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-11-28 12:18:00 +13:00
|
|
|
|
|
|
|
|
|
public static UpdateChecker CheckUpdate()
|
|
|
|
|
{
|
|
|
|
|
UpdateChecker updateChecker = new GitHubUpdateChecker("ShareX", "ShareX");
|
2014-07-23 12:18:49 +12:00
|
|
|
|
updateChecker.IsBeta = Program.IsBeta;
|
2015-01-12 22:14:59 +13:00
|
|
|
|
updateChecker.Proxy = HelpersOptions.CurrentProxy.GetWebProxy();
|
2013-11-28 12:18:00 +13:00
|
|
|
|
updateChecker.CheckUpdate();
|
|
|
|
|
|
2015-09-17 18:59:22 +12:00
|
|
|
|
/*
|
2013-12-04 21:54:32 +13:00
|
|
|
|
// Fallback if GitHub API fails
|
2014-07-23 12:18:49 +12:00
|
|
|
|
if (updateChecker.Status == UpdateStatus.None || updateChecker.Status == UpdateStatus.UpdateCheckFailed)
|
2013-11-28 12:18:00 +13:00
|
|
|
|
{
|
2015-01-04 03:06:32 +13:00
|
|
|
|
updateChecker = new XMLUpdateChecker(Links.URL_UPDATE, "ShareX");
|
2014-07-23 12:18:49 +12:00
|
|
|
|
updateChecker.IsBeta = Program.IsBeta;
|
2015-01-12 22:14:59 +13:00
|
|
|
|
updateChecker.Proxy = HelpersOptions.CurrentProxy.GetWebProxy();
|
2013-11-28 12:18:00 +13:00
|
|
|
|
updateChecker.CheckUpdate();
|
|
|
|
|
}
|
2015-09-17 18:59:22 +12:00
|
|
|
|
*/
|
2013-11-28 12:18:00 +13:00
|
|
|
|
|
|
|
|
|
return updateChecker;
|
|
|
|
|
}
|
2014-03-13 22:13:02 +13:00
|
|
|
|
|
2015-04-15 20:58:40 +12:00
|
|
|
|
public static void CheckDownloadCounts()
|
|
|
|
|
{
|
|
|
|
|
GitHubUpdateChecker updateChecker = new GitHubUpdateChecker("ShareX", "ShareX");
|
|
|
|
|
updateChecker.Proxy = HelpersOptions.CurrentProxy.GetWebProxy();
|
|
|
|
|
string output = updateChecker.GetDownloadCounts();
|
|
|
|
|
Debug.WriteLine(output);
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-13 22:31:03 +13:00
|
|
|
|
public static string CheckFilePath(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);
|
|
|
|
|
|
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:
|
|
|
|
|
filepath = string.Empty;
|
|
|
|
|
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,
|
|
|
|
|
Program.Settings.DropHoverOpacity, taskSettings).ShowActivate();
|
2014-05-03 05:56:51 +12:00
|
|
|
|
}
|
|
|
|
|
|
2015-06-22 18:56:18 +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();
|
|
|
|
|
|
2015-09-08 01:29:37 +12:00
|
|
|
|
ScreenRecordManager.StartStopRecording(outputType, startMethod, taskSettings);
|
2014-05-03 05:56:51 +12:00
|
|
|
|
}
|
|
|
|
|
|
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();
|
|
|
|
|
|
2015-09-27 20:55:42 +13:00
|
|
|
|
ScrollingCaptureForm scrollingCaptureForm = new ScrollingCaptureForm(taskSettings.CaptureSettingsReference.ScrollingCaptureOptions, forceSelection);
|
2015-09-26 00:33:13 +12:00
|
|
|
|
scrollingCaptureForm.ProcessRequested += image => UploadManager.RunImageTask(image, taskSettings);
|
2015-09-27 13:53:45 +13:00
|
|
|
|
scrollingCaptureForm.Show();
|
2015-09-25 20:12:03 +12:00
|
|
|
|
}
|
|
|
|
|
|
2014-05-03 05:56:51 +12:00
|
|
|
|
public static void OpenAutoCapture()
|
|
|
|
|
{
|
|
|
|
|
AutoCaptureForm.Instance.ShowActivate();
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-27 03:59:30 +12:00
|
|
|
|
public static void OpenWebpageCapture(TaskSettings taskSettings = null)
|
2015-06-26 20:10:27 +12:00
|
|
|
|
{
|
2015-06-27 03:59:30 +12:00
|
|
|
|
if (taskSettings == null) taskSettings = TaskSettings.GetDefaultTaskSettings();
|
|
|
|
|
|
|
|
|
|
WebpageCaptureForm webpageCaptureForm = new WebpageCaptureForm();
|
|
|
|
|
webpageCaptureForm.OnImageUploadRequested += img => UploadManager.RunImageTask(img, taskSettings);
|
|
|
|
|
webpageCaptureForm.OnImageCopyRequested += img =>
|
|
|
|
|
{
|
|
|
|
|
using (img)
|
|
|
|
|
{
|
|
|
|
|
ClipboardHelpers.CopyImage(img);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
webpageCaptureForm.Show();
|
2015-06-26 20:10:27 +12:00
|
|
|
|
}
|
|
|
|
|
|
2014-12-11 08:23:05 +13:00
|
|
|
|
public static void StartAutoCapture()
|
|
|
|
|
{
|
|
|
|
|
if (!AutoCaptureForm.IsRunning)
|
|
|
|
|
{
|
|
|
|
|
AutoCaptureForm form = AutoCaptureForm.Instance;
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-26 20:24:26 +13:00
|
|
|
|
public static void OpenColorPicker()
|
2015-01-25 19:51:24 +13:00
|
|
|
|
{
|
|
|
|
|
new ScreenColorPicker().Show();
|
|
|
|
|
}
|
|
|
|
|
|
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();
|
|
|
|
|
|
2015-01-25 19:51:24 +13:00
|
|
|
|
PointInfo pointInfo = SelectPointColor();
|
2015-01-25 13:58:00 +13:00
|
|
|
|
|
2015-01-25 19:51:24 +13:00
|
|
|
|
if (pointInfo != null)
|
|
|
|
|
{
|
2015-01-26 21:48:49 +13:00
|
|
|
|
string text = taskSettings.AdvancedSettings.ScreenColorPickerFormat;
|
2015-01-25 13:58:00 +13:00
|
|
|
|
|
2015-01-26 21:48:49 +13:00
|
|
|
|
text = text.Replace("$r", pointInfo.Color.R.ToString(), StringComparison.InvariantCultureIgnoreCase).
|
|
|
|
|
Replace("$g", pointInfo.Color.G.ToString(), StringComparison.InvariantCultureIgnoreCase).
|
|
|
|
|
Replace("$b", pointInfo.Color.B.ToString(), StringComparison.InvariantCultureIgnoreCase).
|
2015-01-27 22:11:31 +13:00
|
|
|
|
Replace("$hex", ColorHelpers.ColorToHex(pointInfo.Color), StringComparison.InvariantCultureIgnoreCase).
|
|
|
|
|
Replace("$x", pointInfo.Position.X.ToString(), StringComparison.InvariantCultureIgnoreCase).
|
|
|
|
|
Replace("$y", pointInfo.Position.Y.ToString(), StringComparison.InvariantCultureIgnoreCase);
|
2015-01-25 13:58:00 +13:00
|
|
|
|
|
|
|
|
|
ClipboardHelpers.CopyText(text);
|
2015-01-25 19:51:24 +13:00
|
|
|
|
|
|
|
|
|
if (Program.MainForm.niTray.Visible)
|
|
|
|
|
{
|
|
|
|
|
Program.MainForm.niTray.Tag = null;
|
|
|
|
|
Program.MainForm.niTray.ShowBalloonTip(3000, "ShareX", string.Format(Resources.TaskHelpers_OpenQuickScreenColorPicker_Copied_to_clipboard___0_, text), ToolTipIcon.Info);
|
|
|
|
|
}
|
2015-01-25 13:58:00 +13:00
|
|
|
|
}
|
2014-05-03 05:56:51 +12:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void OpenRuler()
|
|
|
|
|
{
|
2014-11-27 06:48:25 +13:00
|
|
|
|
using (RectangleRegion surface = new RectangleRegion())
|
2014-05-03 05:56:51 +12:00
|
|
|
|
{
|
|
|
|
|
surface.RulerMode = true;
|
2015-05-07 05:46:19 +12:00
|
|
|
|
surface.Config.ShowTips = false;
|
2014-05-03 05:56:51 +12:00
|
|
|
|
surface.Config.QuickCrop = false;
|
2014-06-07 06:35:18 +12:00
|
|
|
|
surface.Config.ShowInfo = true;
|
2014-09-21 04:12:41 +12:00
|
|
|
|
surface.AreaManager.MinimumSize = 3;
|
2014-05-03 05:56:51 +12:00
|
|
|
|
surface.Prepare();
|
|
|
|
|
surface.ShowDialog();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-18 22:29:36 +13:00
|
|
|
|
public static void OpenAutomate()
|
2015-02-17 02:31:19 +13:00
|
|
|
|
{
|
2015-02-18 01:51:19 +13:00
|
|
|
|
AutomateForm form = AutomateForm.GetInstance(Program.Settings.AutomateScripts);
|
|
|
|
|
form.ShowActivate();
|
2015-02-18 22:29:36 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void StartAutomate()
|
|
|
|
|
{
|
|
|
|
|
AutomateForm form = AutomateForm.GetInstance(Program.Settings.AutomateScripts);
|
2015-02-18 01:51:19 +13:00
|
|
|
|
|
2015-02-18 22:29:36 +13:00
|
|
|
|
if (form.Visible)
|
|
|
|
|
{
|
|
|
|
|
if (AutomateForm.IsRunning)
|
|
|
|
|
{
|
|
|
|
|
form.Stop();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
form.Start();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
2015-02-18 01:51:19 +13:00
|
|
|
|
{
|
2015-02-18 22:29:36 +13:00
|
|
|
|
form.ShowActivate();
|
2015-02-18 01:51:19 +13:00
|
|
|
|
}
|
2015-02-17 02:31:19 +13:00
|
|
|
|
}
|
|
|
|
|
|
2014-05-03 05:56:51 +12:00
|
|
|
|
public static void OpenHashCheck()
|
|
|
|
|
{
|
|
|
|
|
new HashCheckForm().Show();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void OpenIndexFolder()
|
|
|
|
|
{
|
|
|
|
|
UploadManager.IndexFolder();
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-01 01:44:19 +13:00
|
|
|
|
public static void OpenImageCombiner(TaskSettings taskSettings = null)
|
|
|
|
|
{
|
|
|
|
|
if (taskSettings == null) taskSettings = TaskSettings.GetDefaultTaskSettings();
|
|
|
|
|
|
2015-10-01 02:35:45 +13:00
|
|
|
|
ImageCombinerForm imageCombinerForm = new ImageCombinerForm(taskSettings.ToolsSettingsReference.ImageCombinerOptions);
|
|
|
|
|
imageCombinerForm.ProcessRequested += image => UploadManager.RunImageTask(image, taskSettings);
|
|
|
|
|
imageCombinerForm.Show();
|
2015-10-01 01:44:19 +13:00
|
|
|
|
}
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-25 03:30:49 +12:00
|
|
|
|
taskSettings.ToolsSettings.VideoThumbnailOptions.DefaultOutputDirectory = taskSettings.CaptureFolder;
|
2015-09-13 08:32:51 +12: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
|
|
|
|
}
|
|
|
|
|
|
2014-07-17 18:58:17 +12:00
|
|
|
|
public static void OpenImageEditor(string filePath = null)
|
2014-05-04 10:22:47 +12:00
|
|
|
|
{
|
2014-07-17 18:58:17 +12:00
|
|
|
|
if (string.IsNullOrEmpty(filePath))
|
2014-05-04 10:22:47 +12:00
|
|
|
|
{
|
2015-08-23 01:44:40 +12:00
|
|
|
|
if (Clipboard.ContainsImage() &&
|
2015-08-23 03:15:41 +12:00
|
|
|
|
MessageBox.Show(Resources.TaskHelpers_OpenImageEditor_Your_clipboard_contains_image,
|
|
|
|
|
Resources.TaskHelpers_OpenImageEditor_Image_editor___How_to_load_image_, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
2015-08-23 01:44:40 +12:00
|
|
|
|
{
|
|
|
|
|
using (Image img = Clipboard.GetImage())
|
|
|
|
|
{
|
|
|
|
|
if (img != null)
|
|
|
|
|
{
|
|
|
|
|
AnnotateImage(img, null);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-17 18:58:17 +12:00
|
|
|
|
filePath = ImageHelpers.OpenImageFileDialog();
|
2014-05-04 10:22:47 +12:00
|
|
|
|
}
|
|
|
|
|
|
2014-07-17 08:43:20 +12:00
|
|
|
|
if (!string.IsNullOrEmpty(filePath))
|
|
|
|
|
{
|
2014-10-19 10:48:47 +13:00
|
|
|
|
AnnotateImage(filePath);
|
2014-07-17 08:43:20 +12:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-03 05:56:51 +12:00
|
|
|
|
public static void OpenImageEffects()
|
|
|
|
|
{
|
|
|
|
|
string filePath = ImageHelpers.OpenImageFileDialog();
|
2015-03-27 10:30:29 +13:00
|
|
|
|
Image img = null;
|
2014-05-03 05:56:51 +12:00
|
|
|
|
if (!string.IsNullOrEmpty(filePath))
|
|
|
|
|
{
|
2015-03-27 10:30:29 +13:00
|
|
|
|
img = ImageHelpers.LoadImage(filePath);
|
2014-05-03 05:56:51 +12:00
|
|
|
|
}
|
2015-03-27 10:30:29 +13:00
|
|
|
|
ImageEffectsForm form = new ImageEffectsForm(img);
|
|
|
|
|
form.EditorMode();
|
|
|
|
|
form.Show();
|
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
|
|
|
|
{
|
2015-05-07 04:49:57 +12:00
|
|
|
|
if (Helpers.IsAdministrator())
|
|
|
|
|
{
|
|
|
|
|
new DNSChangerForm().Show();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
RunShareXAsAdmin("-dnschanger");
|
|
|
|
|
}
|
2014-09-07 07:13:21 +12:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void RunShareXAsAdmin(string arguments)
|
2014-05-03 05:56:51 +12:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2014-09-07 07:13:21 +12:00
|
|
|
|
ProcessStartInfo psi = new ProcessStartInfo(Application.ExecutablePath);
|
|
|
|
|
psi.Arguments = arguments;
|
2014-05-03 05:56:51 +12:00
|
|
|
|
psi.Verb = "runas";
|
|
|
|
|
Process.Start(psi);
|
|
|
|
|
}
|
|
|
|
|
catch { }
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-21 10:46:06 +12:00
|
|
|
|
public static void OpenQRCode()
|
|
|
|
|
{
|
|
|
|
|
new QRCodeForm().Show();
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-27 06:44:44 +12:00
|
|
|
|
public static void OpenFTPClient()
|
|
|
|
|
{
|
|
|
|
|
if (Program.UploadersConfig != null && Program.UploadersConfig.FTPAccountList != null)
|
|
|
|
|
{
|
|
|
|
|
FTPAccount account = Program.UploadersConfig.FTPAccountList.ReturnIfValidIndex(Program.UploadersConfig.FTPSelectedImage);
|
|
|
|
|
|
|
|
|
|
if (account != null)
|
|
|
|
|
{
|
|
|
|
|
if (account.Protocol == FTPProtocol.FTP || account.Protocol == FTPProtocol.FTPS)
|
|
|
|
|
{
|
|
|
|
|
new FTPClientForm(account).Show();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2015-04-28 19:50:41 +12:00
|
|
|
|
MessageBox.Show(Resources.TaskHelpers_OpenFTPClient_FTP_client_only_supports_FTP_or_FTPS_, "ShareX", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
2015-04-27 06:44:44 +12:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-28 19:50:41 +12:00
|
|
|
|
MessageBox.Show(Resources.TaskHelpers_OpenFTPClient_Unable_to_find_valid_FTP_account_, "ShareX", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
2015-04-27 06:44:44 +12:00
|
|
|
|
}
|
|
|
|
|
|
2015-08-25 04:38:35 +12:00
|
|
|
|
public static void OpenIRCClient(TaskSettings taskSettings = null)
|
|
|
|
|
{
|
|
|
|
|
if (taskSettings == null) taskSettings = TaskSettings.GetDefaultTaskSettings();
|
|
|
|
|
|
2015-08-31 22:44:23 +12:00
|
|
|
|
new IRCClientForm(taskSettings.ToolsSettingsReference.IRCSettings).Show();
|
2015-08-25 04:38:35 +12:00
|
|
|
|
}
|
|
|
|
|
|
2014-06-17 22:30:49 +12:00
|
|
|
|
public static void TweetMessage()
|
|
|
|
|
{
|
2015-04-27 06:44:44 +12:00
|
|
|
|
if (Program.UploadersConfig != null && Program.UploadersConfig.TwitterOAuthInfoList != null)
|
2014-06-17 22:30:49 +12:00
|
|
|
|
{
|
|
|
|
|
OAuthInfo twitterOAuth = Program.UploadersConfig.TwitterOAuthInfoList.ReturnIfValidIndex(Program.UploadersConfig.TwitterSelectedAccount);
|
|
|
|
|
|
2015-04-27 06:44:44 +12:00
|
|
|
|
if (twitterOAuth != null && OAuthInfo.CheckOAuth(twitterOAuth))
|
2014-06-17 22:30:49 +12:00
|
|
|
|
{
|
2015-04-27 06:44:44 +12:00
|
|
|
|
TaskEx.Run(() =>
|
2014-06-17 22:30:49 +12:00
|
|
|
|
{
|
2015-04-27 06:44:44 +12:00
|
|
|
|
using (TwitterTweetForm twitter = new TwitterTweetForm(twitterOAuth))
|
2014-06-17 22:30:49 +12:00
|
|
|
|
{
|
2015-04-27 06:44:44 +12:00
|
|
|
|
if (twitter.ShowDialog() == DialogResult.OK && twitter.IsTweetSent)
|
2014-06-17 22:30:49 +12:00
|
|
|
|
{
|
2015-04-27 06:44:44 +12:00
|
|
|
|
if (Program.MainForm.niTray.Visible)
|
|
|
|
|
{
|
|
|
|
|
Program.MainForm.niTray.Tag = null;
|
|
|
|
|
Program.MainForm.niTray.ShowBalloonTip(5000, "ShareX - Twitter", Resources.TaskHelpers_TweetMessage_Tweet_successfully_sent_, ToolTipIcon.Info);
|
|
|
|
|
}
|
2014-06-17 22:30:49 +12:00
|
|
|
|
}
|
|
|
|
|
}
|
2015-04-27 06:44:44 +12:00
|
|
|
|
});
|
2014-06-17 22:30:49 +12:00
|
|
|
|
|
2015-04-27 06:44:44 +12:00
|
|
|
|
return;
|
|
|
|
|
}
|
2014-05-03 05:56:51 +12:00
|
|
|
|
}
|
2015-04-27 06:44:44 +12:00
|
|
|
|
|
2015-04-28 19:50:41 +12: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)
|
|
|
|
|
{
|
|
|
|
|
string ext = Helpers.GetFilenameExtension(filePath);
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(ext))
|
|
|
|
|
{
|
|
|
|
|
if (taskSettings.AdvancedSettings.ImageExtensions.Any(x => ext.Equals(x, StringComparison.InvariantCultureIgnoreCase)))
|
|
|
|
|
{
|
|
|
|
|
return EDataType.Image;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (taskSettings.AdvancedSettings.TextExtensions.Any(x => ext.Equals(x, StringComparison.InvariantCultureIgnoreCase)))
|
|
|
|
|
{
|
|
|
|
|
return EDataType.Text;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return EDataType.File;
|
|
|
|
|
}
|
2015-07-19 06:49:34 +12:00
|
|
|
|
|
|
|
|
|
public static bool ToggleHotkeys()
|
|
|
|
|
{
|
|
|
|
|
bool result = !Program.Settings.DisableHotkeys;
|
|
|
|
|
Program.Settings.DisableHotkeys = result;
|
|
|
|
|
|
|
|
|
|
Program.MainForm.UpdateToggleHotkeyButton();
|
|
|
|
|
|
|
|
|
|
if (Program.MainForm.niTray.Visible)
|
|
|
|
|
{
|
|
|
|
|
Program.MainForm.niTray.Tag = null;
|
2015-08-12 05:33:30 +12:00
|
|
|
|
string balloonTipText = result ? Resources.TaskHelpers_ToggleHotkeys_Hotkeys_disabled_ : Resources.TaskHelpers_ToggleHotkeys_Hotkeys_enabled_;
|
2015-07-19 06:49:34 +12:00
|
|
|
|
Program.MainForm.niTray.ShowBalloonTip(3000, "ShareX", balloonTipText, ToolTipIcon.Info);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
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-16 08:19:24 +13:00
|
|
|
|
ffmpegPath = Program.DefaultFFmpegPath;
|
|
|
|
|
}
|
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)
|
|
|
|
|
{
|
|
|
|
|
if (FFmpegDownloader.DownloadFFmpeg(false, DownloaderForm_InstallRequested) == DialogResult.OK)
|
|
|
|
|
{
|
|
|
|
|
Program.DefaultTaskSettings.CaptureSettings.FFmpegOptions.CLIPath = taskSettings.TaskSettingsReference.CaptureSettings.FFmpegOptions.CLIPath =
|
2015-10-16 04:59:38 +13:00
|
|
|
|
taskSettings.CaptureSettings.FFmpegOptions.CLIPath = Program.DefaultFFmpegPath;
|
2015-09-13 08:32:51 +12:00
|
|
|
|
|
|
|
|
|
#if STEAM
|
|
|
|
|
Program.DefaultTaskSettings.CaptureSettings.FFmpegOptions.OverrideCLIPath = taskSettings.TaskSettingsReference.CaptureSettings.FFmpegOptions.OverrideCLIPath =
|
|
|
|
|
taskSettings.CaptureSettings.FFmpegOptions.OverrideCLIPath = true;
|
|
|
|
|
#endif
|
2015-08-14 09:51:58 +12:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void DownloaderForm_InstallRequested(string filePath)
|
|
|
|
|
{
|
2015-10-16 04:59:38 +13:00
|
|
|
|
bool result = FFmpegDownloader.ExtractFFmpeg(filePath, Program.DefaultFFmpegPath);
|
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();
|
|
|
|
|
|
|
|
|
|
if (taskSettings.AdvancedSettings.UseCustomCaptureSound && !string.IsNullOrEmpty(taskSettings.AdvancedSettings.CustomCaptureSoundPath))
|
|
|
|
|
{
|
|
|
|
|
Helpers.PlaySoundAsync(taskSettings.AdvancedSettings.CustomCaptureSoundPath);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Helpers.PlaySoundAsync(Resources.CaptureSound);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void PlayTaskCompleteSound(TaskSettings taskSettings)
|
|
|
|
|
{
|
|
|
|
|
if (taskSettings == null) taskSettings = TaskSettings.GetDefaultTaskSettings();
|
|
|
|
|
|
2015-08-17 09:51:18 +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);
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
}
|