diff --git a/HelpersLib/Enums.cs b/HelpersLib/Enums.cs index 43c63f6c1..bea0b9591 100644 --- a/HelpersLib/Enums.cs +++ b/HelpersLib/Enums.cs @@ -225,7 +225,7 @@ public enum ScreenRecordOutput { [Description("Animated GIF")] GIF, - [Description("Video for Windows (VfW)")] + [Description("AVI")] AVI, [Description("FFmpeg")] FFmpeg, diff --git a/ScreenCaptureLib/AVICache.cs b/ScreenCaptureLib/AVICache.cs index 2d0d8e4ed..c8d474b5a 100644 --- a/ScreenCaptureLib/AVICache.cs +++ b/ScreenCaptureLib/AVICache.cs @@ -38,55 +38,13 @@ public class AVICache : ImageCache public AVICache(AVIOptions options) { Options = options; - Helpers.CreateDirectoryIfNotExist(Options.OutputPath); aviWriter = new AVIWriter(Options); - imageQueue = new BlockingCollection(); } - protected override void StartConsumerThread() + protected override void WriteFrame(Image img) { - if (!IsWorking) - { - IsWorking = true; - - task = TaskEx.Run(() => - { - try - { - position = 0; - - while (!imageQueue.IsCompleted) - { - Image img = null; - - try - { - img = imageQueue.Take(); - - if (img != null) - { - //using (new DebugTimer("Frame saved")) - aviWriter.AddFrame((Bitmap)img); - - position++; - } - } - catch (InvalidOperationException) - { - } - finally - { - if (img != null) img.Dispose(); - } - } - } - finally - { - IsWorking = false; - } - }); - } + aviWriter.AddFrame((Bitmap)img); } public override void Dispose() diff --git a/ScreenCaptureLib/FFmpegCache.cs b/ScreenCaptureLib/FFmpegCache.cs index 8c2f8ff7b..1a74b2d09 100644 --- a/ScreenCaptureLib/FFmpegCache.cs +++ b/ScreenCaptureLib/FFmpegCache.cs @@ -39,69 +39,21 @@ namespace ScreenCaptureLib { public class FFmpegCache : ImageCache { - private VideoFileWriter ffmpegWriter; + private static readonly string[] ffmpegFiles = new string[] { "avcodec-53.dll", "avdevice-53.dll", "avfilter-2.dll", "avformat-53.dll", "avutil-51.dll", "swresample-0.dll", "swscale-2.dll" }; - private static readonly string[] ffMpegFiles = new string[] { "avcodec-53.dll", - "avdevice-53.dll", - "avfilter-2.dll", - "avformat-53.dll", - "avutil-51.dll", - "swresample-0.dll", - "swscale-2.dll" }; + private VideoFileWriter ffmpegWriter; public FFmpegCache(AVIOptions options) { Options = options; - Helpers.CreateDirectoryIfNotExist(Options.OutputPath); ffmpegWriter = new VideoFileWriter(); ffmpegWriter.Open(options.OutputPath, options.Size.Width, options.Size.Height, options.FPS, AForge.Video.FFMPEG.VideoCodec.MPEG4); - imageQueue = new BlockingCollection(); } - protected override void StartConsumerThread() + protected override void WriteFrame(Image img) { - if (!IsWorking) - { - IsWorking = true; - - task = TaskEx.Run(() => - { - try - { - position = 0; - - while (!imageQueue.IsCompleted) - { - Image img = null; - - try - { - img = imageQueue.Take(); - - if (img != null) - { - //using (new DebugTimer("Frame saved")) - ffmpegWriter.WriteVideoFrame((Bitmap)img); - - position++; - } - } - catch (InvalidOperationException) - { - } - finally - { - if (img != null) img.Dispose(); - } - } - } - finally - { - IsWorking = false; - } - }); - } + ffmpegWriter.WriteVideoFrame((Bitmap)img); } public override void Dispose() @@ -111,23 +63,12 @@ public override void Dispose() ffmpegWriter.Dispose(); } - if (imageQueue != null) - { - imageQueue.Dispose(); - } + base.Dispose(); } public static bool HasDependencies() { - foreach (string fn in ffMpegFiles) - { - string fp = Path.Combine(Application.StartupPath, fn); - if (!File.Exists(fp)) - { - return false; - } - } - return true; + return ffmpegFiles.Select(x => Path.Combine(Application.StartupPath, x)).All(x => File.Exists(x)); } } } \ No newline at end of file diff --git a/ScreenCaptureLib/HardDiskCache.cs b/ScreenCaptureLib/HardDiskCache.cs index 0a1e80964..5054b0574 100644 --- a/ScreenCaptureLib/HardDiskCache.cs +++ b/ScreenCaptureLib/HardDiskCache.cs @@ -49,62 +49,38 @@ public int Count } } + private FileStream fsCache; private List indexList; public HardDiskCache(AVIOptions options) { Options = options; + Helpers.CreateDirectoryIfNotExist(Options.OutputPath); + fsCache = new FileStream(Options.OutputPath, FileMode.Create, FileAccess.Write, FileShare.Read); indexList = new List(); - imageQueue = new BlockingCollection(); - StartConsumerThread(); } - protected override void StartConsumerThread() + protected override void WriteFrame(Image img) { - if (!IsWorking) + using (MemoryStream ms = new MemoryStream()) { - IsWorking = true; - - task = TaskEx.Run(() => - { - Helpers.CreateDirectoryIfNotExist(Options.OutputPath); - - using (FileStream fsCache = new FileStream(Options.OutputPath, FileMode.Create, FileAccess.Write, FileShare.Read)) - { - while (!imageQueue.IsCompleted) - { - Image img = null; - - try - { - img = imageQueue.Take(); - - if (img != null) - { - using (MemoryStream ms = new MemoryStream()) - { - img.Save(ms, ImageFormat.Bmp); - long position = fsCache.Position; - ms.CopyStreamTo(fsCache); - indexList.Add(new LocationInfo(position, fsCache.Length - position)); - } - } - } - catch (InvalidOperationException) - { - } - finally - { - if (img != null) img.Dispose(); - } - } - } - - IsWorking = false; - }); + img.Save(ms, ImageFormat.Bmp); + long position = fsCache.Position; + ms.CopyStreamTo(fsCache); + indexList.Add(new LocationInfo(position, fsCache.Length - position)); } } + public override void Dispose() + { + if (fsCache != null) + { + fsCache.Dispose(); + } + + base.Dispose(); + } + public IEnumerable GetImageEnumerator() { if (!IsWorking && File.Exists(Options.OutputPath) && indexList != null && indexList.Count > 0) diff --git a/ScreenCaptureLib/ImageCache.cs b/ScreenCaptureLib/ImageCache.cs index 70ea44434..3fef66f8a 100644 --- a/ScreenCaptureLib/ImageCache.cs +++ b/ScreenCaptureLib/ImageCache.cs @@ -41,7 +41,11 @@ public abstract class ImageCache : IDisposable protected Task task; protected BlockingCollection imageQueue; - protected int position; + + public ImageCache() + { + imageQueue = new BlockingCollection(); + } public void AddImageAsync(Image img) { @@ -49,18 +53,52 @@ public void AddImageAsync(Image img) { StartConsumerThread(); } - else - { - imageQueue.Add(img); - } - /*if (imageQueue.Count > 0) - { - Debug.WriteLine("ImageQueue count: " + imageQueue.Count); - }*/ + imageQueue.Add(img); } - protected abstract void StartConsumerThread(); + protected virtual void StartConsumerThread() + { + if (!IsWorking) + { + IsWorking = true; + + task = TaskEx.Run(() => + { + try + { + while (!imageQueue.IsCompleted) + { + Image img = null; + + try + { + img = imageQueue.Take(); + + if (img != null) + { + //using (new DebugTimer("WriteFrame")) + WriteFrame(img); + } + } + catch (InvalidOperationException) + { + } + finally + { + if (img != null) img.Dispose(); + } + } + } + finally + { + IsWorking = false; + } + }); + } + } + + protected abstract void WriteFrame(Image img); public void Finish() { @@ -69,6 +107,8 @@ public void Finish() imageQueue.CompleteAdding(); task.Wait(); } + + Dispose(); } public virtual void Dispose() diff --git a/ScreenCaptureLib/ScreenRecorder.cs b/ScreenCaptureLib/ScreenRecorder.cs index 26b065c7c..8551e5ad5 100644 --- a/ScreenCaptureLib/ScreenRecorder.cs +++ b/ScreenCaptureLib/ScreenRecorder.cs @@ -132,8 +132,6 @@ public ScreenRecorder(int fps, float durationSeconds, Rectangle captureRectangle case ScreenRecordOutput.GIF: imgCache = new HardDiskCache(Options); break; - default: - throw new Exception("Not all possible ScreenRecordOutput types are handled."); } } @@ -150,35 +148,35 @@ public void StartRecording() IsRecording = true; stopRequest = false; - for (int i = 0; !stopRequest && (frameCount == 0 || i < frameCount); i++) + try { - Stopwatch timer = Stopwatch.StartNew(); - - Image img = Screenshot.CaptureRectangle(CaptureRectangle); - //DebugHelper.WriteLine("Screen capture: " + (int)timer.ElapsedMilliseconds); - - imgCache.AddImageAsync(img); - - if (!stopRequest && (frameCount == 0 || i + 1 < frameCount)) + for (int i = 0; !stopRequest && (frameCount == 0 || i < frameCount); i++) { - int sleepTime = delay - (int)timer.ElapsedMilliseconds; + Stopwatch timer = Stopwatch.StartNew(); - if (sleepTime > 0) + Image img = Screenshot.CaptureRectangle(CaptureRectangle); + //DebugHelper.WriteLine("Screen capture: " + (int)timer.ElapsedMilliseconds); + + imgCache.AddImageAsync(img); + + if (!stopRequest && (frameCount == 0 || i + 1 < frameCount)) { - Thread.Sleep(sleepTime); - } - else if (sleepTime < 0) - { - //DebugHelper.WriteLine("FPS drop: " + -sleepTime); + int sleepTime = delay - (int)timer.ElapsedMilliseconds; + + if (sleepTime > 0) + { + Thread.Sleep(sleepTime); + } + else if (sleepTime < 0) + { + // Need to handle FPS drops + } } } } - - imgCache.Finish(); - - if (OutputType != ScreenRecordOutput.GIF) + finally { - imgCache.Dispose(); + imgCache.Finish(); } } diff --git a/ShareX/Forms/MainForm.Designer.cs b/ShareX/Forms/MainForm.Designer.cs index 8b10f40e8..ad2930ede 100644 --- a/ShareX/Forms/MainForm.Designer.cs +++ b/ShareX/Forms/MainForm.Designer.cs @@ -211,6 +211,7 @@ private void InitializeComponent() this.tsmiTrayFTPClient = new System.Windows.Forms.ToolStripMenuItem(); this.tsmiTrayHashCheck = new System.Windows.Forms.ToolStripMenuItem(); this.tsmiTrayIndexFolder = new System.Windows.Forms.ToolStripMenuItem(); + this.tsmiTrayImageEditor = new System.Windows.Forms.ToolStripMenuItem(); this.tsmiTrayImageEffects = new System.Windows.Forms.ToolStripMenuItem(); this.tsmiTrayMonitorTest = new System.Windows.Forms.ToolStripMenuItem(); this.tsmiTrayDNSChanger = new System.Windows.Forms.ToolStripMenuItem(); @@ -613,7 +614,7 @@ private void InitializeComponent() // // tsmiImageEditor // - this.tsmiImageEditor.Image = global::ShareX.Properties.Resources._90; + this.tsmiImageEditor.Image = global::ShareX.Properties.Resources.Greenshot; this.tsmiImageEditor.Name = "tsmiImageEditor"; this.tsmiImageEditor.Size = new System.Drawing.Size(183, 22); this.tsmiImageEditor.Text = "Image editor..."; @@ -1559,6 +1560,7 @@ private void InitializeComponent() this.tsmiTrayFTPClient, this.tsmiTrayHashCheck, this.tsmiTrayIndexFolder, + this.tsmiTrayImageEditor, this.tsmiTrayImageEffects, this.tsmiTrayMonitorTest, this.tsmiTrayDNSChanger}); @@ -1607,6 +1609,14 @@ private void InitializeComponent() this.tsmiTrayIndexFolder.Text = "Index folder..."; this.tsmiTrayIndexFolder.Click += new System.EventHandler(this.tsmiIndexFolder_Click); // + // tsmiTrayImageEditor + // + this.tsmiTrayImageEditor.Image = global::ShareX.Properties.Resources.Greenshot; + this.tsmiTrayImageEditor.Name = "tsmiTrayImageEditor"; + this.tsmiTrayImageEditor.Size = new System.Drawing.Size(183, 22); + this.tsmiTrayImageEditor.Text = "Image editor..."; + this.tsmiTrayImageEditor.Click += new System.EventHandler(this.tsmiImageEditor_Click); + // // tsmiTrayImageEffects // this.tsmiTrayImageEffects.Image = global::ShareX.Properties.Resources.image_saturation; @@ -1898,5 +1908,6 @@ private void InitializeComponent() private System.Windows.Forms.ToolStripMenuItem tsmiFTPClient; private System.Windows.Forms.ToolStripMenuItem tsmiTrayFTPClient; private System.Windows.Forms.ToolStripMenuItem tsmiImageEditor; + private System.Windows.Forms.ToolStripMenuItem tsmiTrayImageEditor; } } \ No newline at end of file diff --git a/ShareX/Forms/TaskSettingsForm.Designer.cs b/ShareX/Forms/TaskSettingsForm.Designer.cs index 00a786c61..255237ed2 100644 --- a/ShareX/Forms/TaskSettingsForm.Designer.cs +++ b/ShareX/Forms/TaskSettingsForm.Designer.cs @@ -1154,7 +1154,7 @@ private void InitializeComponent() this.btnScreenRecorderAVIOptions.Name = "btnScreenRecorderAVIOptions"; this.btnScreenRecorderAVIOptions.Size = new System.Drawing.Size(96, 23); this.btnScreenRecorderAVIOptions.TabIndex = 12; - this.btnScreenRecorderAVIOptions.Text = "VfW options..."; + this.btnScreenRecorderAVIOptions.Text = "AVI options..."; this.btnScreenRecorderAVIOptions.UseVisualStyleBackColor = true; this.btnScreenRecorderAVIOptions.Click += new System.EventHandler(this.btnScreenRecorderAVIOptions_Click); // diff --git a/ShareX/Properties/Resources.Designer.cs b/ShareX/Properties/Resources.Designer.cs index dbd5c894e..aa38eb9d9 100644 --- a/ShareX/Properties/Resources.Designer.cs +++ b/ShareX/Properties/Resources.Designer.cs @@ -1,7 +1,7 @@ //------------------------------------------------------------------------------ // // This code was generated by a tool. -// Runtime Version:4.0.30319.34014 +// Runtime Version:4.0.30319.18444 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. @@ -60,16 +60,6 @@ public class Resources { } } - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - public static System.Drawing.Bitmap _90 { - get { - object obj = ResourceManager.GetObject("90", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - /// /// Looks up a localized resource of type System.Drawing.Bitmap. /// @@ -145,7 +135,7 @@ public class Resources { /// public static System.Drawing.Bitmap application_network { get { - object obj = ResourceManager.GetObject("application-network", resourceCulture); + object obj = ResourceManager.GetObject("application_network", resourceCulture); return ((System.Drawing.Bitmap)(obj)); } } @@ -469,6 +459,16 @@ public class Resources { } } + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + public static System.Drawing.Bitmap Greenshot { + get { + object obj = ResourceManager.GetObject("Greenshot", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + /// /// Looks up a localized resource of type System.Drawing.Bitmap. /// diff --git a/ShareX/Properties/Resources.resx b/ShareX/Properties/Resources.resx index 7f2ce3db0..48b8638cc 100644 --- a/ShareX/Properties/Resources.resx +++ b/ShareX/Properties/Resources.resx @@ -127,9 +127,6 @@ ..\Resources\application-form.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - ..\Resources\Camera.wav;System.IO.MemoryStream, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - ..\Resources\layer-shape-curve.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a @@ -175,6 +172,9 @@ ..\Resources\folder-open-image.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + ..\Resources\navigation-090-button.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + ..\Resources\layers-ungroup.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a @@ -199,9 +199,6 @@ ..\Resources\image-export.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - ..\Resources\au.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - ..\Resources\keyboard--pencil.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a @@ -268,12 +265,12 @@ ..\Resources\monitor.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + ..\Resources\control-record.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + ..\Resources\ruler-triangle.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - ..\Resources\navigation-090-button.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - ..\Resources\upload-cloud.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a @@ -283,6 +280,9 @@ ..\Resources\clipboard--plus.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + ..\Resources\application-network.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + ..\Resources\cross-button.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a @@ -295,8 +295,8 @@ ..\Resources\color.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - ..\Resources\control-record.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + ..\Resources\Camera.wav;System.IO.MemoryStream, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 ..\Resources\drive-globe.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a @@ -313,6 +313,9 @@ ..\Resources\folder-tree.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + ..\Resources\clock--plus.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + ..\Resources\globe-share.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a @@ -328,8 +331,8 @@ ..\Resources\Window.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - ..\Resources\clock--plus.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + ..\Resources\au.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a ..\Resources\checkbox_uncheck.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a @@ -337,9 +340,6 @@ ..\Resources\layer-shape-polygon.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - ..\Resources\application-network.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - ..\Resources\layer-shape-round.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a @@ -356,7 +356,7 @@ ..\Resources\application-task.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - ..\Resources\90.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + ..\Resources\Greenshot.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a \ No newline at end of file diff --git a/ShareX/Resources/90.png b/ShareX/Resources/90.png deleted file mode 100644 index 2087c5b13..000000000 Binary files a/ShareX/Resources/90.png and /dev/null differ diff --git a/ShareX/Resources/Greenshot.png b/ShareX/Resources/Greenshot.png new file mode 100644 index 000000000..41de4cd0a Binary files /dev/null and b/ShareX/Resources/Greenshot.png differ diff --git a/ShareX/ShareX.csproj b/ShareX/ShareX.csproj index 6b20427d2..74d025352 100644 --- a/ShareX/ShareX.csproj +++ b/ShareX/ShareX.csproj @@ -469,7 +469,7 @@ - + diff --git a/UploadersLib/FileUploaders/FTP/FTPAccount.cs b/UploadersLib/FileUploaders/FTP/FTPAccount.cs index e1d3a887d..847cabef3 100644 --- a/UploadersLib/FileUploaders/FTP/FTPAccount.cs +++ b/UploadersLib/FileUploaders/FTP/FTPAccount.cs @@ -136,6 +136,7 @@ public FTPAccount() SubFolderPath = string.Empty; BrowserProtocol = BrowserProtocol.Http; HttpHomePath = string.Empty; + HttpHomePathAutoAddSubFolderPath = true; HttpHomePathNoExtension = false; IsActive = false; FtpsSecurityProtocol = FtpSecurityProtocol.Ssl2Explicit;