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
|
2017-01-11 21:39:40 +13:00
|
|
|
|
Copyright (c) 2007-2017 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;
|
2013-11-03 23:53:49 +13:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Drawing.Imaging;
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
2014-12-11 09:25:20 +13:00
|
|
|
|
namespace ShareX.ScreenCaptureLib
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2014-05-07 01:42:46 +12:00
|
|
|
|
public class HardDiskCache : ImageCache
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
|
|
|
|
public int Count
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (indexList != null)
|
|
|
|
|
{
|
|
|
|
|
return indexList.Count;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-07 09:06:26 +12:00
|
|
|
|
private FileStream fsCache;
|
2013-11-03 23:53:49 +13:00
|
|
|
|
private List<LocationInfo> indexList;
|
|
|
|
|
|
2014-05-09 01:28:46 +12:00
|
|
|
|
public HardDiskCache(ScreencastOptions options)
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2014-05-07 01:42:46 +12:00
|
|
|
|
Options = options;
|
2016-02-22 12:15:23 +13:00
|
|
|
|
Helpers.CreateDirectoryFromFilePath(Options.OutputPath);
|
2014-05-07 09:06:26 +12:00
|
|
|
|
fsCache = new FileStream(Options.OutputPath, FileMode.Create, FileAccess.Write, FileShare.Read);
|
2013-11-03 23:53:49 +13:00
|
|
|
|
indexList = new List<LocationInfo>();
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-07 09:06:26 +12:00
|
|
|
|
protected override void WriteFrame(Image img)
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2014-05-07 09:06:26 +12:00
|
|
|
|
using (MemoryStream ms = new MemoryStream())
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2014-05-07 09:06:26 +12:00
|
|
|
|
img.Save(ms, ImageFormat.Bmp);
|
|
|
|
|
long position = fsCache.Position;
|
|
|
|
|
ms.CopyStreamTo(fsCache);
|
|
|
|
|
indexList.Add(new LocationInfo(position, fsCache.Length - position));
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-11-03 23:53:49 +13:00
|
|
|
|
|
2014-05-07 09:06:26 +12:00
|
|
|
|
public override void Dispose()
|
|
|
|
|
{
|
|
|
|
|
if (fsCache != null)
|
|
|
|
|
{
|
|
|
|
|
fsCache.Dispose();
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
2014-05-07 09:06:26 +12:00
|
|
|
|
|
|
|
|
|
base.Dispose();
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IEnumerable<Image> GetImageEnumerator()
|
|
|
|
|
{
|
2014-05-07 01:42:46 +12:00
|
|
|
|
if (!IsWorking && File.Exists(Options.OutputPath) && indexList != null && indexList.Count > 0)
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2014-05-07 01:42:46 +12:00
|
|
|
|
using (FileStream fsCache = new FileStream(Options.OutputPath, FileMode.Open, FileAccess.Read, FileShare.Read))
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
|
|
|
|
foreach (LocationInfo index in indexList)
|
|
|
|
|
{
|
|
|
|
|
using (MemoryStream ms = new MemoryStream())
|
|
|
|
|
{
|
2015-02-10 04:17:04 +13:00
|
|
|
|
fsCache.CopyStreamTo64(ms, index.Location, (int)index.Length);
|
2013-11-03 23:53:49 +13:00
|
|
|
|
yield return Image.FromStream(ms);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|