Cache MHDD and IBG logs til write end to prevent race condition with file handles under Windows.

This commit is contained in:
2017-12-22 21:46:38 +00:00
parent 071f9df122
commit 78437ef90c
2 changed files with 29 additions and 22 deletions

View File

@@ -40,25 +40,25 @@ namespace DiscImageChef.Core.Logging
{
class IbgLog
{
static FileStream ibgFs;
static StringBuilder ibgSb;
static DateTime ibgDatePoint;
static CultureInfo ibgCulture;
static double ibgStartSpeed;
static string ibgMediaType;
static double ibgDivider;
static bool ibgStartSet;
static double ibgMaxSpeed;
static double ibgIntSpeed;
static int ibgSnaps;
static ulong ibgIntSector;
static int ibgSampleRate;
StringBuilder ibgSb;
DateTime ibgDatePoint;
CultureInfo ibgCulture;
double ibgStartSpeed;
string ibgMediaType;
double ibgDivider;
bool ibgStartSet;
double ibgMaxSpeed;
double ibgIntSpeed;
int ibgSnaps;
ulong ibgIntSector;
int ibgSampleRate;
string logFile;
internal IbgLog(string outputFile, ushort currentProfile)
{
if(string.IsNullOrEmpty(outputFile)) return;
ibgFs = new FileStream(outputFile, FileMode.Create);
logFile = outputFile;
ibgSb = new StringBuilder();
ibgDatePoint = DateTime.Now;
ibgCulture = new CultureInfo("en-US");
@@ -194,7 +194,7 @@ namespace DiscImageChef.Core.Logging
internal void Write(ulong sector, double currentSpeed)
{
if(ibgFs == null) return;
if(logFile == null) return;
ibgIntSpeed += currentSpeed;
ibgSampleRate += (int)Math.Floor((DateTime.Now - ibgDatePoint).TotalMilliseconds);
@@ -222,8 +222,8 @@ namespace DiscImageChef.Core.Logging
internal void Close(Device dev, ulong blocks, ulong blockSize, double totalSeconds, double currentSpeed,
double averageSpeed, string devicePath)
{
if(ibgFs == null) return;
if(logFile == null) return;
FileStream ibgFs = new FileStream(logFile, FileMode.Create);
StringBuilder ibgHeader = new StringBuilder();
string ibgBusType;

View File

@@ -40,14 +40,16 @@ namespace DiscImageChef.Core.Logging
{
class MhddLog
{
FileStream mhddFs;
MemoryStream mhddFs;
string logFile;
internal MhddLog(string outputFile, Device dev, ulong blocks, ulong blockSize, ulong blocksToRead)
{
if(dev == null || string.IsNullOrEmpty(outputFile)) return;
mhddFs = new FileStream(outputFile, FileMode.Create);
mhddFs = new MemoryStream();
logFile = outputFile;
string mode;
switch(dev.Type)
@@ -123,7 +125,7 @@ namespace DiscImageChef.Core.Logging
internal void Write(ulong sector, double duration)
{
if(mhddFs == null) return;
if(logFile == null) return;
byte[] sectorBytes = BitConverter.GetBytes(sector);
byte[] durationBytes = BitConverter.GetBytes((ulong)(duration * 1000));
@@ -134,7 +136,12 @@ namespace DiscImageChef.Core.Logging
internal void Close()
{
if(mhddFs != null) mhddFs.Close();
if(logFile == null) return;
FileStream fs = new FileStream(logFile, FileMode.Create);
mhddFs.WriteTo(fs);
mhddFs.Close();
fs.Close();
}
}
}