Naming fixes.

This commit is contained in:
2020-07-20 21:11:32 +01:00
parent c58c0fd1f8
commit 6220425ac6
525 changed files with 15675 additions and 15524 deletions

View File

@@ -49,9 +49,9 @@ namespace Aaru.DiscImages
byte[] footerB = new byte[Marshal.SizeOf<UdifFooter>()];
stream.Read(footerB, 0, Marshal.SizeOf<UdifFooter>());
footer = Marshal.ByteArrayToStructureBigEndian<UdifFooter>(footerB);
_footer = Marshal.ByteArrayToStructureBigEndian<UdifFooter>(footerB);
if(footer.signature == UDIF_SIGNATURE)
if(_footer.signature == UDIF_SIGNATURE)
return true;
// Old UDIF as created by DiskCopy 6.5 using "OBSOLETE" format. (DiskCopy 5 rumored format?)
@@ -59,9 +59,9 @@ namespace Aaru.DiscImages
byte[] headerB = new byte[Marshal.SizeOf<UdifFooter>()];
stream.Read(headerB, 0, Marshal.SizeOf<UdifFooter>());
footer = Marshal.ByteArrayToStructureBigEndian<UdifFooter>(headerB);
_footer = Marshal.ByteArrayToStructureBigEndian<UdifFooter>(headerB);
return footer.signature == UDIF_SIGNATURE;
return _footer.signature == UDIF_SIGNATURE;
}
}
}

View File

@@ -41,7 +41,7 @@ namespace Aaru.DiscImages
{
public partial class Udif
{
public ImageInfo Info => imageInfo;
public ImageInfo Info => _imageInfo;
public string Name => "Apple Universal Disk Image Format";
public Guid Id => new Guid("5BEB9002-CF3D-429C-8E06-9A96F49203FF");

View File

@@ -65,71 +65,71 @@ namespace Aaru.DiscImages
byte[] footerB = new byte[Marshal.SizeOf<UdifFooter>()];
stream.Read(footerB, 0, Marshal.SizeOf<UdifFooter>());
footer = Marshal.ByteArrayToStructureBigEndian<UdifFooter>(footerB);
_footer = Marshal.ByteArrayToStructureBigEndian<UdifFooter>(footerB);
if(footer.signature != UDIF_SIGNATURE)
if(_footer.signature != UDIF_SIGNATURE)
{
stream.Seek(0, SeekOrigin.Begin);
footerB = new byte[Marshal.SizeOf<UdifFooter>()];
stream.Read(footerB, 0, Marshal.SizeOf<UdifFooter>());
footer = Marshal.ByteArrayToStructureBigEndian<UdifFooter>(footerB);
_footer = Marshal.ByteArrayToStructureBigEndian<UdifFooter>(footerB);
if(footer.signature != UDIF_SIGNATURE)
if(_footer.signature != UDIF_SIGNATURE)
throw new Exception("Unable to find UDIF signature.");
AaruConsole.VerboseWriteLine("Found obsolete UDIF format.");
}
AaruConsole.DebugWriteLine("UDIF plugin", "footer.signature = 0x{0:X8}", footer.signature);
AaruConsole.DebugWriteLine("UDIF plugin", "footer.version = {0}", footer.version);
AaruConsole.DebugWriteLine("UDIF plugin", "footer.headerSize = {0}", footer.headerSize);
AaruConsole.DebugWriteLine("UDIF plugin", "footer.flags = {0}", footer.flags);
AaruConsole.DebugWriteLine("UDIF plugin", "footer.runningDataForkOff = {0}", footer.runningDataForkOff);
AaruConsole.DebugWriteLine("UDIF plugin", "footer.dataForkOff = {0}", footer.dataForkOff);
AaruConsole.DebugWriteLine("UDIF plugin", "footer.dataForkLen = {0}", footer.dataForkLen);
AaruConsole.DebugWriteLine("UDIF plugin", "footer.rsrcForkOff = {0}", footer.rsrcForkOff);
AaruConsole.DebugWriteLine("UDIF plugin", "footer.rsrcForkLen = {0}", footer.rsrcForkLen);
AaruConsole.DebugWriteLine("UDIF plugin", "footer.segmentNumber = {0}", footer.segmentNumber);
AaruConsole.DebugWriteLine("UDIF plugin", "footer.segmentCount = {0}", footer.segmentCount);
AaruConsole.DebugWriteLine("UDIF plugin", "footer.segmentId = {0}", footer.segmentId);
AaruConsole.DebugWriteLine("UDIF plugin", "footer.dataForkChkType = {0}", footer.dataForkChkType);
AaruConsole.DebugWriteLine("UDIF plugin", "footer.dataForkLen = {0}", footer.dataForkLen);
AaruConsole.DebugWriteLine("UDIF plugin", "footer.dataForkChk = 0x{0:X8}", footer.dataForkChk);
AaruConsole.DebugWriteLine("UDIF plugin", "footer.plistOff = {0}", footer.plistOff);
AaruConsole.DebugWriteLine("UDIF plugin", "footer.plistLen = {0}", footer.plistLen);
AaruConsole.DebugWriteLine("UDIF plugin", "footer.masterChkType = {0}", footer.masterChkType);
AaruConsole.DebugWriteLine("UDIF plugin", "footer.masterChkLen = {0}", footer.masterChkLen);
AaruConsole.DebugWriteLine("UDIF plugin", "footer.masterChk = 0x{0:X8}", footer.masterChk);
AaruConsole.DebugWriteLine("UDIF plugin", "footer.imageVariant = {0}", footer.imageVariant);
AaruConsole.DebugWriteLine("UDIF plugin", "footer.sectorCount = {0}", footer.sectorCount);
AaruConsole.DebugWriteLine("UDIF plugin", "footer.signature = 0x{0:X8}", _footer.signature);
AaruConsole.DebugWriteLine("UDIF plugin", "footer.version = {0}", _footer.version);
AaruConsole.DebugWriteLine("UDIF plugin", "footer.headerSize = {0}", _footer.headerSize);
AaruConsole.DebugWriteLine("UDIF plugin", "footer.flags = {0}", _footer.flags);
AaruConsole.DebugWriteLine("UDIF plugin", "footer.runningDataForkOff = {0}", _footer.runningDataForkOff);
AaruConsole.DebugWriteLine("UDIF plugin", "footer.dataForkOff = {0}", _footer.dataForkOff);
AaruConsole.DebugWriteLine("UDIF plugin", "footer.dataForkLen = {0}", _footer.dataForkLen);
AaruConsole.DebugWriteLine("UDIF plugin", "footer.rsrcForkOff = {0}", _footer.rsrcForkOff);
AaruConsole.DebugWriteLine("UDIF plugin", "footer.rsrcForkLen = {0}", _footer.rsrcForkLen);
AaruConsole.DebugWriteLine("UDIF plugin", "footer.segmentNumber = {0}", _footer.segmentNumber);
AaruConsole.DebugWriteLine("UDIF plugin", "footer.segmentCount = {0}", _footer.segmentCount);
AaruConsole.DebugWriteLine("UDIF plugin", "footer.segmentId = {0}", _footer.segmentId);
AaruConsole.DebugWriteLine("UDIF plugin", "footer.dataForkChkType = {0}", _footer.dataForkChkType);
AaruConsole.DebugWriteLine("UDIF plugin", "footer.dataForkLen = {0}", _footer.dataForkLen);
AaruConsole.DebugWriteLine("UDIF plugin", "footer.dataForkChk = 0x{0:X8}", _footer.dataForkChk);
AaruConsole.DebugWriteLine("UDIF plugin", "footer.plistOff = {0}", _footer.plistOff);
AaruConsole.DebugWriteLine("UDIF plugin", "footer.plistLen = {0}", _footer.plistLen);
AaruConsole.DebugWriteLine("UDIF plugin", "footer.masterChkType = {0}", _footer.masterChkType);
AaruConsole.DebugWriteLine("UDIF plugin", "footer.masterChkLen = {0}", _footer.masterChkLen);
AaruConsole.DebugWriteLine("UDIF plugin", "footer.masterChk = 0x{0:X8}", _footer.masterChk);
AaruConsole.DebugWriteLine("UDIF plugin", "footer.imageVariant = {0}", _footer.imageVariant);
AaruConsole.DebugWriteLine("UDIF plugin", "footer.sectorCount = {0}", _footer.sectorCount);
AaruConsole.DebugWriteLine("UDIF plugin", "footer.reserved1 is empty? = {0}",
ArrayHelpers.ArrayIsNullOrEmpty(footer.reserved1));
ArrayHelpers.ArrayIsNullOrEmpty(_footer.reserved1));
AaruConsole.DebugWriteLine("UDIF plugin", "footer.reserved2 is empty? = {0}",
ArrayHelpers.ArrayIsNullOrEmpty(footer.reserved2));
ArrayHelpers.ArrayIsNullOrEmpty(_footer.reserved2));
AaruConsole.DebugWriteLine("UDIF plugin", "footer.reserved3 is empty? = {0}",
ArrayHelpers.ArrayIsNullOrEmpty(footer.reserved3));
ArrayHelpers.ArrayIsNullOrEmpty(_footer.reserved3));
AaruConsole.DebugWriteLine("UDIF plugin", "footer.reserved4 is empty? = {0}",
ArrayHelpers.ArrayIsNullOrEmpty(footer.reserved4));
ArrayHelpers.ArrayIsNullOrEmpty(_footer.reserved4));
// Block chunks and headers
List<byte[]> blkxList = new List<byte[]>();
chunks = new Dictionary<ulong, BlockChunk>();
_chunks = new Dictionary<ulong, BlockChunk>();
bool fakeBlockChunks = false;
byte[] vers = null;
if(footer.plistLen == 0 &&
footer.rsrcForkLen != 0)
if(_footer.plistLen == 0 &&
_footer.rsrcForkLen != 0)
{
AaruConsole.DebugWriteLine("UDIF plugin", "Reading resource fork.");
byte[] rsrcB = new byte[footer.rsrcForkLen];
stream.Seek((long)footer.rsrcForkOff, SeekOrigin.Begin);
byte[] rsrcB = new byte[_footer.rsrcForkLen];
stream.Seek((long)_footer.rsrcForkOff, SeekOrigin.Begin);
stream.Read(rsrcB, 0, rsrcB.Length);
var rsrc = new ResourceFork(rsrcB);
@@ -155,11 +155,11 @@ namespace Aaru.DiscImages
if(versRez != null)
vers = versRez.GetResource(versRez.GetIds()[0]);
}
else if(footer.plistLen != 0)
else if(_footer.plistLen != 0)
{
AaruConsole.DebugWriteLine("UDIF plugin", "Reading property list.");
byte[] plistB = new byte[footer.plistLen];
stream.Seek((long)footer.plistOff, SeekOrigin.Begin);
byte[] plistB = new byte[_footer.plistLen];
stream.Seek((long)_footer.plistOff, SeekOrigin.Begin);
stream.Read(plistB, 0, plistB.Length);
AaruConsole.DebugWriteLine("UDIF plugin", "Parsing property list.");
@@ -203,16 +203,16 @@ namespace Aaru.DiscImages
// So let's falsify a block chunk
var bChnk = new BlockChunk
{
length = footer.dataForkLen,
offset = footer.dataForkOff,
length = _footer.dataForkLen,
offset = _footer.dataForkOff,
sector = 0,
sectors = footer.sectorCount,
sectors = _footer.sectorCount,
type = CHUNK_TYPE_COPY
};
imageInfo.Sectors = footer.sectorCount;
chunks.Add(bChnk.sector, bChnk);
buffersize = 2048 * SECTOR_SIZE;
_imageInfo.Sectors = _footer.sectorCount;
_chunks.Add(bChnk.sector, bChnk);
_buffersize = 2048 * SECTOR_SIZE;
fakeBlockChunks = true;
}
@@ -253,22 +253,22 @@ namespace Aaru.DiscImages
if(dev != null)
pre = $"{version.PreReleaseVersion}";
imageInfo.ApplicationVersion = $"{major}{minor}{release}{dev}{pre}";
imageInfo.Application = version.VersionString;
imageInfo.Comments = version.VersionMessage;
_imageInfo.ApplicationVersion = $"{major}{minor}{release}{dev}{pre}";
_imageInfo.Application = version.VersionString;
_imageInfo.Comments = version.VersionMessage;
if(version.MajorVersion == 3)
imageInfo.Application = "ShrinkWrap™";
_imageInfo.Application = "ShrinkWrap™";
else if(version.MajorVersion == 6)
imageInfo.Application = "DiskCopy";
_imageInfo.Application = "DiskCopy";
}
else
imageInfo.Application = "DiskCopy";
_imageInfo.Application = "DiskCopy";
AaruConsole.DebugWriteLine("UDIF plugin", "Image application = {0} version {1}", imageInfo.Application,
imageInfo.ApplicationVersion);
AaruConsole.DebugWriteLine("UDIF plugin", "Image application = {0} version {1}", _imageInfo.Application,
_imageInfo.ApplicationVersion);
imageInfo.Sectors = 0;
_imageInfo.Sectors = 0;
if(!fakeBlockChunks)
{
@@ -276,7 +276,7 @@ namespace Aaru.DiscImages
throw new
ImageNotSupportedException("Could not retrieve block chunks. Please fill an issue and send it to us.");
buffersize = 0;
_buffersize = 0;
foreach(byte[] blkxBytes in blkxList)
{
@@ -306,8 +306,8 @@ namespace Aaru.DiscImages
AaruConsole.DebugWriteLine("UDIF plugin", "bHdr.reservedChk is empty? = {0}",
ArrayHelpers.ArrayIsNullOrEmpty(bHdr.reservedChk));
if(bHdr.buffers > buffersize)
buffersize = bHdr.buffers * SECTOR_SIZE;
if(bHdr.buffers > _buffersize)
_buffersize = bHdr.buffers * SECTOR_SIZE;
for(int i = 0; i < bHdr.chunks; i++)
{
@@ -329,7 +329,7 @@ namespace Aaru.DiscImages
if(bChnk.type == CHUNK_TYPE_END)
break;
imageInfo.Sectors += bChnk.sectors;
_imageInfo.Sectors += bChnk.sectors;
// Chunk offset is relative
bChnk.sector += bHdr.sectorStart;
@@ -357,46 +357,46 @@ namespace Aaru.DiscImages
throw new ImageNotSupportedException($"Unsupported chunk type 0x{bChnk.type:X8} found");
if(bChnk.sectors > 0)
chunks.Add(bChnk.sector, bChnk);
_chunks.Add(bChnk.sector, bChnk);
}
}
}
sectorCache = new Dictionary<ulong, byte[]>();
chunkCache = new Dictionary<ulong, byte[]>();
currentChunkCacheSize = 0;
imageStream = stream;
_sectorCache = new Dictionary<ulong, byte[]>();
_chunkCache = new Dictionary<ulong, byte[]>();
_currentChunkCacheSize = 0;
_imageStream = stream;
imageInfo.CreationTime = imageFilter.GetCreationTime();
imageInfo.LastModificationTime = imageFilter.GetLastWriteTime();
imageInfo.MediaTitle = Path.GetFileNameWithoutExtension(imageFilter.GetFilename());
imageInfo.SectorSize = SECTOR_SIZE;
imageInfo.XmlMediaType = XmlMediaType.BlockMedia;
imageInfo.MediaType = MediaType.GENERIC_HDD;
imageInfo.ImageSize = imageInfo.Sectors * SECTOR_SIZE;
imageInfo.Version = $"{footer.version}";
_imageInfo.CreationTime = imageFilter.GetCreationTime();
_imageInfo.LastModificationTime = imageFilter.GetLastWriteTime();
_imageInfo.MediaTitle = Path.GetFileNameWithoutExtension(imageFilter.GetFilename());
_imageInfo.SectorSize = SECTOR_SIZE;
_imageInfo.XmlMediaType = XmlMediaType.BlockMedia;
_imageInfo.MediaType = MediaType.GENERIC_HDD;
_imageInfo.ImageSize = _imageInfo.Sectors * SECTOR_SIZE;
_imageInfo.Version = $"{_footer.version}";
imageInfo.Cylinders = (uint)(imageInfo.Sectors / 16 / 63);
imageInfo.Heads = 16;
imageInfo.SectorsPerTrack = 63;
_imageInfo.Cylinders = (uint)(_imageInfo.Sectors / 16 / 63);
_imageInfo.Heads = 16;
_imageInfo.SectorsPerTrack = 63;
return true;
}
public byte[] ReadSector(ulong sectorAddress)
{
if(sectorAddress > imageInfo.Sectors - 1)
if(sectorAddress > _imageInfo.Sectors - 1)
throw new ArgumentOutOfRangeException(nameof(sectorAddress),
$"Sector address {sectorAddress} not found");
if(sectorCache.TryGetValue(sectorAddress, out byte[] sector))
if(_sectorCache.TryGetValue(sectorAddress, out byte[] sector))
return sector;
var readChunk = new BlockChunk();
bool chunkFound = false;
ulong chunkStartSector = 0;
foreach(KeyValuePair<ulong, BlockChunk> kvp in chunks.Where(kvp => sectorAddress >= kvp.Key))
foreach(KeyValuePair<ulong, BlockChunk> kvp in _chunks.Where(kvp => sectorAddress >= kvp.Key))
{
readChunk = kvp.Value;
chunkFound = true;
@@ -415,11 +415,11 @@ namespace Aaru.DiscImages
if((readChunk.type & CHUNK_TYPE_COMPRESSED_MASK) == CHUNK_TYPE_COMPRESSED_MASK)
{
if(!chunkCache.TryGetValue(chunkStartSector, out byte[] buffer))
if(!_chunkCache.TryGetValue(chunkStartSector, out byte[] buffer))
{
byte[] cmpBuffer = new byte[readChunk.length];
imageStream.Seek((long)readChunk.offset, SeekOrigin.Begin);
imageStream.Read(cmpBuffer, 0, cmpBuffer.Length);
_imageStream.Seek((long)readChunk.offset, SeekOrigin.Begin);
_imageStream.Read(cmpBuffer, 0, cmpBuffer.Length);
var cmpMs = new MemoryStream(cmpBuffer);
Stream decStream = null;
@@ -455,27 +455,27 @@ namespace Aaru.DiscImages
case CHUNK_TYPE_ADC:
case CHUNK_TYPE_ZLIB:
case CHUNK_TYPE_BZIP:
tmpBuffer = new byte[buffersize];
realSize = decStream.Read(tmpBuffer, 0, (int)buffersize);
tmpBuffer = new byte[_buffersize];
realSize = decStream.Read(tmpBuffer, 0, (int)_buffersize);
buffer = new byte[realSize];
Array.Copy(tmpBuffer, 0, buffer, 0, realSize);
if(currentChunkCacheSize + realSize > MAX_CACHE_SIZE)
if(_currentChunkCacheSize + realSize > MAX_CACHE_SIZE)
{
chunkCache.Clear();
currentChunkCacheSize = 0;
_chunkCache.Clear();
_currentChunkCacheSize = 0;
}
chunkCache.Add(chunkStartSector, buffer);
currentChunkCacheSize += (uint)realSize;
_chunkCache.Add(chunkStartSector, buffer);
_currentChunkCacheSize += (uint)realSize;
break;
case CHUNK_TYPE_RLE:
tmpBuffer = new byte[buffersize];
tmpBuffer = new byte[_buffersize];
realSize = 0;
var rle = new AppleRle(cmpMs);
for(int i = 0; i < buffersize; i++)
for(int i = 0; i < _buffersize; i++)
{
int b = rle.ProduceByte();
@@ -505,10 +505,10 @@ namespace Aaru.DiscImages
sector = new byte[SECTOR_SIZE];
Array.Copy(buffer, relOff, sector, 0, SECTOR_SIZE);
if(sectorCache.Count >= MAX_CACHED_SECTORS)
sectorCache.Clear();
if(_sectorCache.Count >= MAX_CACHED_SECTORS)
_sectorCache.Clear();
sectorCache.Add(sectorAddress, sector);
_sectorCache.Add(sectorAddress, sector);
return sector;
}
@@ -519,21 +519,21 @@ namespace Aaru.DiscImages
case CHUNK_TYPE_ZERO:
sector = new byte[SECTOR_SIZE];
if(sectorCache.Count >= MAX_CACHED_SECTORS)
sectorCache.Clear();
if(_sectorCache.Count >= MAX_CACHED_SECTORS)
_sectorCache.Clear();
sectorCache.Add(sectorAddress, sector);
_sectorCache.Add(sectorAddress, sector);
return sector;
case CHUNK_TYPE_COPY:
imageStream.Seek((long)readChunk.offset + relOff, SeekOrigin.Begin);
_imageStream.Seek((long)readChunk.offset + relOff, SeekOrigin.Begin);
sector = new byte[SECTOR_SIZE];
imageStream.Read(sector, 0, sector.Length);
_imageStream.Read(sector, 0, sector.Length);
if(sectorCache.Count >= MAX_CACHED_SECTORS)
sectorCache.Clear();
if(_sectorCache.Count >= MAX_CACHED_SECTORS)
_sectorCache.Clear();
sectorCache.Add(sectorAddress, sector);
_sectorCache.Add(sectorAddress, sector);
return sector;
}
@@ -543,11 +543,11 @@ namespace Aaru.DiscImages
public byte[] ReadSectors(ulong sectorAddress, uint length)
{
if(sectorAddress > imageInfo.Sectors - 1)
if(sectorAddress > _imageInfo.Sectors - 1)
throw new ArgumentOutOfRangeException(nameof(sectorAddress),
$"Sector address {sectorAddress} not found");
if(sectorAddress + length > imageInfo.Sectors)
if(sectorAddress + length > _imageInfo.Sectors)
throw new ArgumentOutOfRangeException(nameof(length), "Requested more sectors than available");
var ms = new MemoryStream();

View File

@@ -43,21 +43,21 @@ namespace Aaru.DiscImages
{
public partial class Udif : IWritableImage
{
uint buffersize;
Dictionary<ulong, byte[]> chunkCache;
Dictionary<ulong, BlockChunk> chunks;
BlockChunk currentChunk;
uint currentChunkCacheSize;
ulong currentSector;
Crc32Context dataForkChecksum;
UdifFooter footer;
ImageInfo imageInfo;
Stream imageStream;
Crc32Context masterChecksum;
Dictionary<ulong, byte[]> sectorCache;
FileStream writingStream;
uint _buffersize;
Dictionary<ulong, byte[]> _chunkCache;
Dictionary<ulong, BlockChunk> _chunks;
BlockChunk _currentChunk;
uint _currentChunkCacheSize;
ulong _currentSector;
Crc32Context _dataForkChecksum;
UdifFooter _footer;
ImageInfo _imageInfo;
Stream _imageStream;
Crc32Context _masterChecksum;
Dictionary<ulong, byte[]> _sectorCache;
FileStream _writingStream;
public Udif() => imageInfo = new ImageInfo
public Udif() => _imageInfo = new ImageInfo
{
ReadableSectorTags = new List<SectorTagType>(),
ReadableMediaTags = new List<MediaTagType>(),

View File

@@ -64,7 +64,7 @@ namespace Aaru.DiscImages
return false;
}
imageInfo = new ImageInfo
_imageInfo = new ImageInfo
{
MediaType = mediaType,
SectorSize = sectorSize,
@@ -73,7 +73,7 @@ namespace Aaru.DiscImages
try
{
writingStream = new FileStream(path, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None);
_writingStream = new FileStream(path, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None);
}
catch(IOException e)
{
@@ -82,11 +82,11 @@ namespace Aaru.DiscImages
return false;
}
chunks = new Dictionary<ulong, BlockChunk>();
currentChunk = new BlockChunk();
currentSector = 0;
dataForkChecksum = new Crc32Context();
masterChecksum = new Crc32Context();
_chunks = new Dictionary<ulong, BlockChunk>();
_currentChunk = new BlockChunk();
_currentSector = 0;
_dataForkChecksum = new Crc32Context();
_masterChecksum = new Crc32Context();
IsWriting = true;
ErrorMessage = null;
@@ -110,59 +110,59 @@ namespace Aaru.DiscImages
return false;
}
if(data.Length != imageInfo.SectorSize)
if(data.Length != _imageInfo.SectorSize)
{
ErrorMessage = "Incorrect data size";
return false;
}
if(sectorAddress >= imageInfo.Sectors)
if(sectorAddress >= _imageInfo.Sectors)
{
ErrorMessage = "Tried to write past image size";
return false;
}
if(sectorAddress < currentSector)
if(sectorAddress < _currentSector)
{
ErrorMessage = "Tried to rewind, this format rewinded on writing";
return false;
}
masterChecksum.Update(data);
_masterChecksum.Update(data);
bool isEmpty = ArrayHelpers.ArrayIsNullOrEmpty(data);
switch(currentChunk.type)
switch(_currentChunk.type)
{
case CHUNK_TYPE_ZERO:
currentChunk.type = isEmpty ? CHUNK_TYPE_NOCOPY : CHUNK_TYPE_COPY;
_currentChunk.type = isEmpty ? CHUNK_TYPE_NOCOPY : CHUNK_TYPE_COPY;
break;
case CHUNK_TYPE_NOCOPY when !isEmpty:
case CHUNK_TYPE_COPY when isEmpty:
chunks.Add(currentChunk.sector, currentChunk);
_chunks.Add(_currentChunk.sector, _currentChunk);
currentChunk = new BlockChunk
_currentChunk = new BlockChunk
{
type = isEmpty ? CHUNK_TYPE_NOCOPY : CHUNK_TYPE_COPY,
sector = currentSector,
offset = (ulong)(isEmpty ? 0 : writingStream.Position)
sector = _currentSector,
offset = (ulong)(isEmpty ? 0 : _writingStream.Position)
};
break;
}
currentChunk.sectors++;
currentChunk.length += (ulong)(isEmpty ? 0 : 512);
currentSector++;
_currentChunk.sectors++;
_currentChunk.length += (ulong)(isEmpty ? 0 : 512);
_currentSector++;
if(!isEmpty)
{
dataForkChecksum.Update(data);
writingStream.Write(data, 0, data.Length);
_dataForkChecksum.Update(data);
_writingStream.Write(data, 0, data.Length);
}
ErrorMessage = "";
@@ -180,14 +180,14 @@ namespace Aaru.DiscImages
return false;
}
if(data.Length % imageInfo.SectorSize != 0)
if(data.Length % _imageInfo.SectorSize != 0)
{
ErrorMessage = "Incorrect data size";
return false;
}
if(sectorAddress + length > imageInfo.Sectors)
if(sectorAddress + length > _imageInfo.Sectors)
{
ErrorMessage = "Tried to write past image size";
@@ -197,20 +197,20 @@ namespace Aaru.DiscImages
// Ignore empty sectors
if(ArrayHelpers.ArrayIsNullOrEmpty(data))
{
if(currentChunk.type == CHUNK_TYPE_COPY)
if(_currentChunk.type == CHUNK_TYPE_COPY)
{
chunks.Add(currentChunk.sector, currentChunk);
_chunks.Add(_currentChunk.sector, _currentChunk);
currentChunk = new BlockChunk
_currentChunk = new BlockChunk
{
type = CHUNK_TYPE_NOCOPY,
sector = currentSector
sector = _currentSector
};
}
currentChunk.sectors += (ulong)(data.Length / imageInfo.SectorSize);
currentSector += (ulong)(data.Length / imageInfo.SectorSize);
masterChecksum.Update(data);
_currentChunk.sectors += (ulong)(data.Length / _imageInfo.SectorSize);
_currentSector += (ulong)(data.Length / _imageInfo.SectorSize);
_masterChecksum.Update(data);
ErrorMessage = "";
@@ -219,8 +219,8 @@ namespace Aaru.DiscImages
for(uint i = 0; i < length; i++)
{
byte[] tmp = new byte[imageInfo.SectorSize];
Array.Copy(data, i * imageInfo.SectorSize, tmp, 0, imageInfo.SectorSize);
byte[] tmp = new byte[_imageInfo.SectorSize];
Array.Copy(data, i * _imageInfo.SectorSize, tmp, 0, _imageInfo.SectorSize);
if(!WriteSector(tmp, sectorAddress + i))
return false;
@@ -254,26 +254,26 @@ namespace Aaru.DiscImages
return false;
}
if(currentChunk.type != CHUNK_TYPE_NOCOPY)
currentChunk.length = currentChunk.sectors * 512;
if(_currentChunk.type != CHUNK_TYPE_NOCOPY)
_currentChunk.length = _currentChunk.sectors * 512;
chunks.Add(currentChunk.sector, currentChunk);
_chunks.Add(_currentChunk.sector, _currentChunk);
chunks.Add(imageInfo.Sectors, new BlockChunk
_chunks.Add(_imageInfo.Sectors, new BlockChunk
{
type = CHUNK_TYPE_END,
sector = imageInfo.Sectors
sector = _imageInfo.Sectors
});
var bHdr = new BlockHeader
{
signature = CHUNK_SIGNATURE,
version = 1,
sectorCount = imageInfo.Sectors,
sectorCount = _imageInfo.Sectors,
checksumType = UDIF_CHECKSUM_TYPE_CRC32,
checksumLen = 32,
checksum = BitConverter.ToUInt32(dataForkChecksum.Final().Reverse().ToArray(), 0),
chunks = (uint)chunks.Count
checksum = BitConverter.ToUInt32(_dataForkChecksum.Final().Reverse().ToArray(), 0),
chunks = (uint)_chunks.Count
};
var chunkMs = new MemoryStream();
@@ -296,7 +296,7 @@ namespace Aaru.DiscImages
chunkMs.Write(new byte[124], 0, 124);
chunkMs.Write(BigEndianBitConverter.GetBytes(bHdr.chunks), 0, 4);
foreach(BlockChunk chunk in chunks.Values)
foreach(BlockChunk chunk in _chunks.Values)
{
chunkMs.Write(BigEndianBitConverter.GetBytes(chunk.type), 0, 4);
chunkMs.Write(BigEndianBitConverter.GetBytes(chunk.comment), 0, 4);
@@ -338,20 +338,20 @@ namespace Aaru.DiscImages
}
}.ToXmlPropertyList());
footer = new UdifFooter
_footer = new UdifFooter
{
signature = UDIF_SIGNATURE,
version = 4,
headerSize = 512,
flags = 1,
dataForkLen = (ulong)writingStream.Length,
dataForkLen = (ulong)_writingStream.Length,
segmentNumber = 1,
segmentCount = 1,
segmentId = Guid.NewGuid(),
dataForkChkType = UDIF_CHECKSUM_TYPE_CRC32,
dataForkChkLen = 32,
dataForkChk = BitConverter.ToUInt32(dataForkChecksum.Final().Reverse().ToArray(), 0),
plistOff = (ulong)writingStream.Length,
dataForkChk = BitConverter.ToUInt32(_dataForkChecksum.Final().Reverse().ToArray(), 0),
plistOff = (ulong)_writingStream.Length,
plistLen = (ulong)plist.Length,
// TODO: Find how is this calculated
@@ -359,40 +359,40 @@ namespace Aaru.DiscImages
masterChkLen = 32,
masterChk = BitConverter.ToUInt32(masterChecksum.Final().Reverse().ToArray(), 0),*/
imageVariant = 2,
sectorCount = imageInfo.Sectors
sectorCount = _imageInfo.Sectors
};
writingStream.Seek(0, SeekOrigin.End);
writingStream.Write(plist, 0, plist.Length);
writingStream.Write(BigEndianBitConverter.GetBytes(footer.signature), 0, 4);
writingStream.Write(BigEndianBitConverter.GetBytes(footer.version), 0, 4);
writingStream.Write(BigEndianBitConverter.GetBytes(footer.headerSize), 0, 4);
writingStream.Write(BigEndianBitConverter.GetBytes(footer.flags), 0, 4);
writingStream.Write(BigEndianBitConverter.GetBytes(footer.runningDataForkOff), 0, 8);
writingStream.Write(BigEndianBitConverter.GetBytes(footer.dataForkOff), 0, 8);
writingStream.Write(BigEndianBitConverter.GetBytes(footer.dataForkLen), 0, 8);
writingStream.Write(BigEndianBitConverter.GetBytes(footer.rsrcForkOff), 0, 8);
writingStream.Write(BigEndianBitConverter.GetBytes(footer.rsrcForkLen), 0, 8);
writingStream.Write(BigEndianBitConverter.GetBytes(footer.segmentNumber), 0, 4);
writingStream.Write(BigEndianBitConverter.GetBytes(footer.segmentCount), 0, 4);
writingStream.Write(footer.segmentId.ToByteArray(), 0, 16);
writingStream.Write(BigEndianBitConverter.GetBytes(footer.dataForkChkType), 0, 4);
writingStream.Write(BigEndianBitConverter.GetBytes(footer.dataForkChkLen), 0, 4);
writingStream.Write(BigEndianBitConverter.GetBytes(footer.dataForkChk), 0, 4);
writingStream.Write(new byte[124], 0, 124);
writingStream.Write(BigEndianBitConverter.GetBytes(footer.plistOff), 0, 8);
writingStream.Write(BigEndianBitConverter.GetBytes(footer.plistLen), 0, 8);
writingStream.Write(new byte[120], 0, 120);
writingStream.Write(BigEndianBitConverter.GetBytes(footer.masterChkType), 0, 4);
writingStream.Write(BigEndianBitConverter.GetBytes(footer.masterChkLen), 0, 4);
writingStream.Write(BigEndianBitConverter.GetBytes(footer.masterChk), 0, 4);
writingStream.Write(new byte[124], 0, 124);
writingStream.Write(BigEndianBitConverter.GetBytes(footer.imageVariant), 0, 4);
writingStream.Write(BigEndianBitConverter.GetBytes(footer.sectorCount), 0, 8);
writingStream.Write(new byte[12], 0, 12);
_writingStream.Seek(0, SeekOrigin.End);
_writingStream.Write(plist, 0, plist.Length);
_writingStream.Write(BigEndianBitConverter.GetBytes(_footer.signature), 0, 4);
_writingStream.Write(BigEndianBitConverter.GetBytes(_footer.version), 0, 4);
_writingStream.Write(BigEndianBitConverter.GetBytes(_footer.headerSize), 0, 4);
_writingStream.Write(BigEndianBitConverter.GetBytes(_footer.flags), 0, 4);
_writingStream.Write(BigEndianBitConverter.GetBytes(_footer.runningDataForkOff), 0, 8);
_writingStream.Write(BigEndianBitConverter.GetBytes(_footer.dataForkOff), 0, 8);
_writingStream.Write(BigEndianBitConverter.GetBytes(_footer.dataForkLen), 0, 8);
_writingStream.Write(BigEndianBitConverter.GetBytes(_footer.rsrcForkOff), 0, 8);
_writingStream.Write(BigEndianBitConverter.GetBytes(_footer.rsrcForkLen), 0, 8);
_writingStream.Write(BigEndianBitConverter.GetBytes(_footer.segmentNumber), 0, 4);
_writingStream.Write(BigEndianBitConverter.GetBytes(_footer.segmentCount), 0, 4);
_writingStream.Write(_footer.segmentId.ToByteArray(), 0, 16);
_writingStream.Write(BigEndianBitConverter.GetBytes(_footer.dataForkChkType), 0, 4);
_writingStream.Write(BigEndianBitConverter.GetBytes(_footer.dataForkChkLen), 0, 4);
_writingStream.Write(BigEndianBitConverter.GetBytes(_footer.dataForkChk), 0, 4);
_writingStream.Write(new byte[124], 0, 124);
_writingStream.Write(BigEndianBitConverter.GetBytes(_footer.plistOff), 0, 8);
_writingStream.Write(BigEndianBitConverter.GetBytes(_footer.plistLen), 0, 8);
_writingStream.Write(new byte[120], 0, 120);
_writingStream.Write(BigEndianBitConverter.GetBytes(_footer.masterChkType), 0, 4);
_writingStream.Write(BigEndianBitConverter.GetBytes(_footer.masterChkLen), 0, 4);
_writingStream.Write(BigEndianBitConverter.GetBytes(_footer.masterChk), 0, 4);
_writingStream.Write(new byte[124], 0, 124);
_writingStream.Write(BigEndianBitConverter.GetBytes(_footer.imageVariant), 0, 4);
_writingStream.Write(BigEndianBitConverter.GetBytes(_footer.sectorCount), 0, 8);
_writingStream.Write(new byte[12], 0, 12);
writingStream.Flush();
writingStream.Close();
_writingStream.Flush();
_writingStream.Close();
IsWriting = false;
ErrorMessage = "";