mirror of
https://github.com/aaru-dps/Aaru.Server.git
synced 2025-12-16 19:24:27 +00:00
Cache MHDD and IBG logs til write end to prevent race condition with file handles under Windows.
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user