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
|
class IbgLog
|
||||||
{
|
{
|
||||||
static FileStream ibgFs;
|
StringBuilder ibgSb;
|
||||||
static StringBuilder ibgSb;
|
DateTime ibgDatePoint;
|
||||||
static DateTime ibgDatePoint;
|
CultureInfo ibgCulture;
|
||||||
static CultureInfo ibgCulture;
|
double ibgStartSpeed;
|
||||||
static double ibgStartSpeed;
|
string ibgMediaType;
|
||||||
static string ibgMediaType;
|
double ibgDivider;
|
||||||
static double ibgDivider;
|
bool ibgStartSet;
|
||||||
static bool ibgStartSet;
|
double ibgMaxSpeed;
|
||||||
static double ibgMaxSpeed;
|
double ibgIntSpeed;
|
||||||
static double ibgIntSpeed;
|
int ibgSnaps;
|
||||||
static int ibgSnaps;
|
ulong ibgIntSector;
|
||||||
static ulong ibgIntSector;
|
int ibgSampleRate;
|
||||||
static int ibgSampleRate;
|
string logFile;
|
||||||
|
|
||||||
internal IbgLog(string outputFile, ushort currentProfile)
|
internal IbgLog(string outputFile, ushort currentProfile)
|
||||||
{
|
{
|
||||||
if(string.IsNullOrEmpty(outputFile)) return;
|
if(string.IsNullOrEmpty(outputFile)) return;
|
||||||
|
|
||||||
ibgFs = new FileStream(outputFile, FileMode.Create);
|
logFile = outputFile;
|
||||||
ibgSb = new StringBuilder();
|
ibgSb = new StringBuilder();
|
||||||
ibgDatePoint = DateTime.Now;
|
ibgDatePoint = DateTime.Now;
|
||||||
ibgCulture = new CultureInfo("en-US");
|
ibgCulture = new CultureInfo("en-US");
|
||||||
@@ -194,7 +194,7 @@ namespace DiscImageChef.Core.Logging
|
|||||||
|
|
||||||
internal void Write(ulong sector, double currentSpeed)
|
internal void Write(ulong sector, double currentSpeed)
|
||||||
{
|
{
|
||||||
if(ibgFs == null) return;
|
if(logFile == null) return;
|
||||||
|
|
||||||
ibgIntSpeed += currentSpeed;
|
ibgIntSpeed += currentSpeed;
|
||||||
ibgSampleRate += (int)Math.Floor((DateTime.Now - ibgDatePoint).TotalMilliseconds);
|
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,
|
internal void Close(Device dev, ulong blocks, ulong blockSize, double totalSeconds, double currentSpeed,
|
||||||
double averageSpeed, string devicePath)
|
double averageSpeed, string devicePath)
|
||||||
{
|
{
|
||||||
if(ibgFs == null) return;
|
if(logFile == null) return;
|
||||||
|
FileStream ibgFs = new FileStream(logFile, FileMode.Create);
|
||||||
StringBuilder ibgHeader = new StringBuilder();
|
StringBuilder ibgHeader = new StringBuilder();
|
||||||
string ibgBusType;
|
string ibgBusType;
|
||||||
|
|
||||||
|
|||||||
@@ -40,14 +40,16 @@ namespace DiscImageChef.Core.Logging
|
|||||||
{
|
{
|
||||||
class MhddLog
|
class MhddLog
|
||||||
{
|
{
|
||||||
FileStream mhddFs;
|
MemoryStream mhddFs;
|
||||||
|
string logFile;
|
||||||
|
|
||||||
internal MhddLog(string outputFile, Device dev, ulong blocks, ulong blockSize, ulong blocksToRead)
|
internal MhddLog(string outputFile, Device dev, ulong blocks, ulong blockSize, ulong blocksToRead)
|
||||||
{
|
{
|
||||||
if(dev == null || string.IsNullOrEmpty(outputFile)) return;
|
if(dev == null || string.IsNullOrEmpty(outputFile)) return;
|
||||||
|
|
||||||
mhddFs = new FileStream(outputFile, FileMode.Create);
|
mhddFs = new MemoryStream();
|
||||||
|
logFile = outputFile;
|
||||||
|
|
||||||
string mode;
|
string mode;
|
||||||
|
|
||||||
switch(dev.Type)
|
switch(dev.Type)
|
||||||
@@ -123,7 +125,7 @@ namespace DiscImageChef.Core.Logging
|
|||||||
|
|
||||||
internal void Write(ulong sector, double duration)
|
internal void Write(ulong sector, double duration)
|
||||||
{
|
{
|
||||||
if(mhddFs == null) return;
|
if(logFile == null) return;
|
||||||
|
|
||||||
byte[] sectorBytes = BitConverter.GetBytes(sector);
|
byte[] sectorBytes = BitConverter.GetBytes(sector);
|
||||||
byte[] durationBytes = BitConverter.GetBytes((ulong)(duration * 1000));
|
byte[] durationBytes = BitConverter.GetBytes((ulong)(duration * 1000));
|
||||||
@@ -134,7 +136,12 @@ namespace DiscImageChef.Core.Logging
|
|||||||
|
|
||||||
internal void Close()
|
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