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
|
2014-05-13 21:06:40 +12:00
|
|
|
|
Copyright (C) 2007-2014 ShareX Developers
|
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)
|
|
|
|
|
|
|
|
|
|
using HelpersLib;
|
2013-11-16 22:11:39 +13:00
|
|
|
|
using ScreenCaptureLib;
|
2013-11-03 23:53:49 +13:00
|
|
|
|
using ShareX.Properties;
|
2014-05-10 13:52:09 +12:00
|
|
|
|
using System;
|
2013-11-03 23:53:49 +13:00
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Windows.Forms;
|
2014-05-07 20:59:19 +12:00
|
|
|
|
using UploadersLib;
|
2013-11-03 23:53:49 +13:00
|
|
|
|
|
|
|
|
|
namespace ShareX
|
|
|
|
|
{
|
|
|
|
|
public class ScreenRecordForm : TrayForm
|
|
|
|
|
{
|
|
|
|
|
public bool IsRecording { get; private set; }
|
|
|
|
|
|
|
|
|
|
private static ScreenRecordForm instance;
|
|
|
|
|
|
|
|
|
|
public static ScreenRecordForm Instance
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (instance == null || instance.IsDisposed)
|
|
|
|
|
{
|
|
|
|
|
instance = new ScreenRecordForm();
|
|
|
|
|
instance.Show();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return instance;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private ScreenRecorder screenRecorder;
|
2014-05-15 01:52:10 +12:00
|
|
|
|
private Rectangle captureRectangle;
|
2013-11-03 23:53:49 +13:00
|
|
|
|
|
|
|
|
|
private ScreenRecordForm()
|
|
|
|
|
{
|
|
|
|
|
TrayIcon.Text = "ShareX - Screen recording";
|
|
|
|
|
TrayIcon.MouseClick += TrayIcon_MouseClick;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void TrayIcon_MouseClick(object sender, MouseEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (e.Button == MouseButtons.Left)
|
|
|
|
|
{
|
|
|
|
|
StopRecording();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SelectRegion()
|
|
|
|
|
{
|
2014-05-15 01:52:10 +12:00
|
|
|
|
if (TaskHelpers.SelectRegion(out captureRectangle) && !captureRectangle.IsEmpty)
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2014-05-15 01:52:10 +12:00
|
|
|
|
captureRectangle = CaptureHelpers.EvenRectangleSize(captureRectangle);
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-22 13:22:32 +12:00
|
|
|
|
public void StartRecording(TaskSettings TaskSettings)
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2014-05-11 23:47:37 +12:00
|
|
|
|
if (TaskSettings.CaptureSettings.RunScreencastCLI)
|
2014-04-20 03:39:17 +12:00
|
|
|
|
{
|
2014-05-11 23:47:37 +12:00
|
|
|
|
if (!Program.Settings.VideoEncoders.IsValidIndex(TaskSettings.CaptureSettings.VideoEncoderSelected))
|
2014-04-20 03:39:17 +12:00
|
|
|
|
{
|
2014-04-20 16:24:03 +12:00
|
|
|
|
MessageBox.Show("There is no valid CLI video encoder selected.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
2014-04-20 03:39:17 +12:00
|
|
|
|
return;
|
|
|
|
|
}
|
2014-05-11 23:47:37 +12:00
|
|
|
|
else if (!Program.Settings.VideoEncoders[TaskSettings.CaptureSettings.VideoEncoderSelected].IsValid())
|
2014-04-20 03:39:17 +12:00
|
|
|
|
{
|
2014-05-11 23:47:37 +12:00
|
|
|
|
MessageBox.Show("CLI video encoder file does not exist: " + Program.Settings.VideoEncoders[TaskSettings.CaptureSettings.VideoEncoderSelected].Path,
|
2014-05-05 04:09:53 +12:00
|
|
|
|
Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
2014-04-20 03:39:17 +12:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-11 23:47:37 +12:00
|
|
|
|
if (TaskSettings.CaptureSettings.ScreenRecordOutput == ScreenRecordOutput.FFmpeg && !File.Exists(TaskSettings.CaptureSettings.FFmpegOptions.CLIPath))
|
2014-05-10 12:23:47 +12:00
|
|
|
|
{
|
2014-05-12 10:58:10 +12:00
|
|
|
|
string ffmpegText = string.IsNullOrEmpty(TaskSettings.CaptureSettings.FFmpegOptions.CLIPath) ? "ffmpeg.exe" : TaskSettings.CaptureSettings.FFmpegOptions.CLIPath;
|
|
|
|
|
|
|
|
|
|
if (MessageBox.Show(ffmpegText + " does not exist." + Environment.NewLine + Environment.NewLine + "Would you like to automatically download it?",
|
2014-05-12 10:13:09 +12:00
|
|
|
|
Application.ProductName + " - Missing ffmpeg.exe", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
|
2014-05-10 13:52:09 +12:00
|
|
|
|
{
|
2014-05-12 10:58:10 +12:00
|
|
|
|
if (FFmpegHelper.DownloadFFmpeg(false, DownloaderForm_InstallRequested) == DialogResult.OK)
|
2014-05-10 13:52:09 +12:00
|
|
|
|
{
|
2014-05-12 10:58:10 +12:00
|
|
|
|
Program.DefaultTaskSettings.CaptureSettings.FFmpegOptions.CLIPath = TaskSettings.TaskSettingsReference.CaptureSettings.FFmpegOptions.CLIPath =
|
|
|
|
|
TaskSettings.CaptureSettings.FFmpegOptions.CLIPath = Path.Combine(Program.ToolsFolder, "ffmpeg.exe");
|
2014-05-10 13:52:09 +12:00
|
|
|
|
}
|
|
|
|
|
}
|
2014-05-10 20:04:18 +12:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2014-05-10 12:23:47 +12:00
|
|
|
|
}
|
|
|
|
|
|
2013-11-03 23:53:49 +13:00
|
|
|
|
SelectRegion();
|
|
|
|
|
|
2014-05-15 01:52:10 +12:00
|
|
|
|
if (IsRecording || captureRectangle.IsEmpty || screenRecorder != null)
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
IsRecording = true;
|
2014-05-15 01:52:10 +12:00
|
|
|
|
Screenshot.CaptureCursor = TaskSettings.CaptureSettings.ShowCursor;
|
2013-11-03 23:53:49 +13:00
|
|
|
|
|
|
|
|
|
TrayIcon.Icon = Resources.control_record_yellow.ToIcon();
|
|
|
|
|
TrayIcon.Visible = true;
|
|
|
|
|
|
|
|
|
|
string path = "";
|
|
|
|
|
|
2014-05-22 13:22:32 +12:00
|
|
|
|
ScreenRegionManager screenRegionManager = new ScreenRegionManager();
|
|
|
|
|
screenRegionManager.Start(captureRectangle);
|
|
|
|
|
|
2014-05-22 13:48:27 +12:00
|
|
|
|
Task.Run(() =>
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2014-05-22 13:22:32 +12:00
|
|
|
|
if (TaskSettings.CaptureSettings.ScreenRecordOutput == ScreenRecordOutput.AVI)
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2014-05-22 13:22:32 +12:00
|
|
|
|
path = Path.Combine(TaskSettings.CaptureFolder, TaskHelpers.GetFilename(TaskSettings, "avi"));
|
|
|
|
|
}
|
|
|
|
|
else if (TaskSettings.CaptureSettings.ScreenRecordOutput == ScreenRecordOutput.FFmpeg)
|
|
|
|
|
{
|
|
|
|
|
path = Path.Combine(TaskSettings.CaptureFolder, TaskHelpers.GetFilename(TaskSettings, TaskSettings.CaptureSettings.FFmpegOptions.Extension));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
path = Program.ScreenRecorderCacheFilePath;
|
|
|
|
|
}
|
2013-11-03 23:53:49 +13:00
|
|
|
|
|
2014-05-22 13:22:32 +12:00
|
|
|
|
ScreencastOptions options = new ScreencastOptions()
|
|
|
|
|
{
|
|
|
|
|
CaptureArea = captureRectangle,
|
|
|
|
|
GIFFPS = TaskSettings.CaptureSettings.GIFFPS,
|
|
|
|
|
ScreenRecordFPS = TaskSettings.CaptureSettings.ScreenRecordFPS,
|
|
|
|
|
OutputPath = path,
|
|
|
|
|
Duration = TaskSettings.CaptureSettings.ScreenRecordFixedDuration ? TaskSettings.CaptureSettings.ScreenRecordDuration : 0,
|
|
|
|
|
AVI = TaskSettings.CaptureSettings.AVIOptions,
|
|
|
|
|
FFmpeg = TaskSettings.CaptureSettings.FFmpegOptions,
|
|
|
|
|
DrawCursor = TaskSettings.CaptureSettings.ShowCursor
|
|
|
|
|
};
|
2014-05-09 01:28:46 +12:00
|
|
|
|
|
2014-05-22 13:22:32 +12:00
|
|
|
|
screenRecorder = new ScreenRecorder(options, captureRectangle, TaskSettings.CaptureSettings.ScreenRecordOutput);
|
2013-11-03 23:53:49 +13:00
|
|
|
|
|
2014-05-22 13:22:32 +12:00
|
|
|
|
int delay = (int)(TaskSettings.CaptureSettings.ScreenRecordStartDelay * 1000);
|
2013-11-03 23:53:49 +13:00
|
|
|
|
|
2014-05-22 13:22:32 +12:00
|
|
|
|
if (delay > 0)
|
|
|
|
|
{
|
|
|
|
|
Thread.Sleep(delay);
|
|
|
|
|
}
|
2013-11-03 23:53:49 +13:00
|
|
|
|
|
2014-05-22 13:22:32 +12:00
|
|
|
|
this.InvokeSafe(() =>
|
|
|
|
|
{
|
|
|
|
|
screenRegionManager.ChangeColor(Color.FromArgb(0, 255, 0));
|
|
|
|
|
TrayIcon.Icon = Resources.control_record.ToIcon();
|
|
|
|
|
});
|
2013-11-03 23:53:49 +13:00
|
|
|
|
|
2014-05-22 13:22:32 +12:00
|
|
|
|
screenRecorder.StartRecording();
|
2013-11-03 23:53:49 +13:00
|
|
|
|
|
2014-05-22 13:22:32 +12:00
|
|
|
|
if (screenRegionManager != null)
|
|
|
|
|
{
|
|
|
|
|
this.InvokeSafe(() => screenRegionManager.Dispose());
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
|
2014-05-06 23:23:12 +12:00
|
|
|
|
if (screenRecorder != null)
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2014-05-22 13:22:32 +12:00
|
|
|
|
TrayIcon.Icon = Resources.camcorder_pencil.ToIcon();
|
2013-11-03 23:53:49 +13:00
|
|
|
|
|
2014-05-22 13:22:32 +12:00
|
|
|
|
string sourceFilePath = path;
|
2014-05-07 12:16:11 +12:00
|
|
|
|
|
2014-05-22 13:22:32 +12:00
|
|
|
|
if (TaskSettings.CaptureSettings.ScreenRecordOutput == ScreenRecordOutput.GIF)
|
|
|
|
|
{
|
|
|
|
|
if (TaskSettings.CaptureSettings.RunScreencastCLI)
|
2014-05-06 23:23:12 +12:00
|
|
|
|
{
|
2014-05-22 13:22:32 +12:00
|
|
|
|
sourceFilePath = Path.ChangeExtension(Program.ScreenRecorderCacheFilePath, "gif");
|
2014-05-06 23:23:12 +12:00
|
|
|
|
}
|
2014-05-22 13:22:32 +12:00
|
|
|
|
else
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2014-05-22 13:22:32 +12:00
|
|
|
|
sourceFilePath = path = Path.Combine(TaskSettings.CaptureFolder, TaskHelpers.GetFilename(TaskSettings, "gif"));
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
2014-05-22 13:22:32 +12:00
|
|
|
|
screenRecorder.SaveAsGIF(sourceFilePath, TaskSettings.ImageSettings.ImageGIFQuality);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (TaskSettings.CaptureSettings.RunScreencastCLI)
|
|
|
|
|
{
|
|
|
|
|
VideoEncoder encoder = Program.Settings.VideoEncoders[TaskSettings.CaptureSettings.VideoEncoderSelected];
|
|
|
|
|
path = Path.Combine(TaskSettings.CaptureFolder, TaskHelpers.GetFilename(TaskSettings, encoder.OutputExtension));
|
|
|
|
|
screenRecorder.EncodeUsingCommandLine(encoder, sourceFilePath, path);
|
|
|
|
|
}
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
2014-05-22 13:22:32 +12:00
|
|
|
|
},
|
|
|
|
|
() =>
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
|
|
|
|
if (screenRecorder != null)
|
|
|
|
|
{
|
2014-05-22 13:22:32 +12:00
|
|
|
|
if (TaskSettings.CaptureSettings.RunScreencastCLI && !string.IsNullOrEmpty(screenRecorder.CachePath) && File.Exists(screenRecorder.CachePath))
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
|
|
|
|
File.Delete(screenRecorder.CachePath);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
screenRecorder.Dispose();
|
|
|
|
|
screenRecorder = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (TrayIcon.Visible)
|
|
|
|
|
{
|
|
|
|
|
TrayIcon.Visible = false;
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-22 13:22:32 +12:00
|
|
|
|
if (!string.IsNullOrEmpty(path) && File.Exists(path))
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2014-05-22 13:22:32 +12:00
|
|
|
|
if (TaskSettings.AfterCaptureJob.HasFlag(AfterCaptureTasks.UploadImageToHost))
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2014-05-22 13:22:32 +12:00
|
|
|
|
UploadManager.UploadFile(path, TaskSettings);
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
2014-05-22 13:22:32 +12:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (TaskSettings.AfterCaptureJob.HasFlag(AfterCaptureTasks.CopyFilePathToClipboard))
|
|
|
|
|
{
|
|
|
|
|
ClipboardHelpers.CopyText(path);
|
|
|
|
|
}
|
2013-11-03 23:53:49 +13:00
|
|
|
|
|
2014-05-22 13:22:32 +12:00
|
|
|
|
TaskHelpers.ShowResultNotifications(path, TaskSettings, path);
|
|
|
|
|
}
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
|
2014-05-22 13:22:32 +12:00
|
|
|
|
IsRecording = false;
|
|
|
|
|
});
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
|
2014-05-12 10:58:10 +12:00
|
|
|
|
private void DownloaderForm_InstallRequested(string filePath)
|
|
|
|
|
{
|
|
|
|
|
string extractPath = Path.Combine(Program.ToolsFolder, "ffmpeg.exe");
|
|
|
|
|
bool result = FFmpegHelper.ExtractFFmpeg(filePath, extractPath);
|
|
|
|
|
|
|
|
|
|
if (result)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("FFmpeg successfully downloaded.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Download of FFmpeg failed.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-03 23:53:49 +13:00
|
|
|
|
public void StopRecording()
|
|
|
|
|
{
|
|
|
|
|
if (IsRecording && screenRecorder != null)
|
|
|
|
|
{
|
|
|
|
|
screenRecorder.StopRecording();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|