Constrain debug information to debug mode

git-svn-id: svn://claunia.com/FileSystemIDandChk@28 17725271-3d32-4980-a8cb-9ff532f270ba
This commit is contained in:
2014-04-14 01:31:32 +00:00
parent 32bb28e8c2
commit 27791637fb
3 changed files with 216 additions and 176 deletions

View File

@@ -1,3 +1,9 @@
2014-04-14 Natalia Portillo <claunia@claunia.com>
* Main.cs:
* ImagePlugins/CDRWin.cs:
Constrain debug information to debug mode
2014-04-14 Natalia Portillo <claunia@claunia.com>
* BigEndianBitConverter.cs:

View File

@@ -416,6 +416,7 @@ namespace FileSystemIDandChk.ImagePlugins
if (MatchDiskType.Success && !intrack)
{
if (MainClass.isDebug)
Console.WriteLine("DEBUG (CDRWin plugin): Found REM ORIGINAL MEDIA TYPE at line {0}", line);
discimage.disktypestr = MatchDiskType.Groups[1].Value;
}
@@ -425,6 +426,7 @@ namespace FileSystemIDandChk.ImagePlugins
}
else if (MatchSession.Success)
{
if (MainClass.isDebug)
Console.WriteLine("DEBUG (CDRWin plugin): Found REM SESSION at line {0}", line);
currentsession = Byte.Parse(MatchSession.Groups[1].Value);
@@ -432,16 +434,19 @@ namespace FileSystemIDandChk.ImagePlugins
}
else if (MatchLBA.Success)
{
if (MainClass.isDebug)
Console.WriteLine("DEBUG (CDRWin plugin): Found REM MSF at line {0}", line);
// Just ignored
}
else if (MatchLeadOut.Success)
{
if (MainClass.isDebug)
Console.WriteLine("DEBUG (CDRWin plugin): Found REM LEAD-OUT at line {0}", line);
// Just ignored
}
else if (MatchComment.Success)
{
if (MainClass.isDebug)
Console.WriteLine("DEBUG (CDRWin plugin): Found REM at line {0}", line);
if (discimage.comment == "")
discimage.comment = MatchComment.Groups[1].Value; // First comment
@@ -470,6 +475,7 @@ namespace FileSystemIDandChk.ImagePlugins
if (MatchArranger.Success)
{
if (MainClass.isDebug)
Console.WriteLine("DEBUG (CDRWin plugin): Found ARRANGER at line {0}", line);
if (intrack)
currenttrack.arranger = MatchArranger.Groups[1].Value;
@@ -478,6 +484,7 @@ namespace FileSystemIDandChk.ImagePlugins
}
else if (MatchBarCode.Success)
{
if (MainClass.isDebug)
Console.WriteLine("DEBUG (CDRWin plugin): Found UPC_EAN at line {0}", line);
if (!intrack)
discimage.barcode = MatchBarCode.Groups[1].Value;
@@ -486,6 +493,7 @@ namespace FileSystemIDandChk.ImagePlugins
}
else if (MatchCDText.Success)
{
if (MainClass.isDebug)
Console.WriteLine("DEBUG (CDRWin plugin): Found CDTEXTFILE at line {0}", line);
if (!intrack)
discimage.cdtextfile = MatchCDText.Groups[1].Value;
@@ -494,6 +502,7 @@ namespace FileSystemIDandChk.ImagePlugins
}
else if (MatchComposer.Success)
{
if (MainClass.isDebug)
Console.WriteLine("DEBUG (CDRWin plugin): Found COMPOSER at line {0}", line);
if (intrack)
currenttrack.arranger = MatchComposer.Groups[1].Value;
@@ -502,6 +511,7 @@ namespace FileSystemIDandChk.ImagePlugins
}
else if (MatchDiskID.Success)
{
if (MainClass.isDebug)
Console.WriteLine("DEBUG (CDRWin plugin): Found DISC_ID at line {0}", line);
if (!intrack)
discimage.disk_id = MatchDiskID.Groups[1].Value;
@@ -510,6 +520,7 @@ namespace FileSystemIDandChk.ImagePlugins
}
else if (MatchFile.Success)
{
if (MainClass.isDebug)
Console.WriteLine("DEBUG (CDRWin plugin): Found FILE at line {0}", line);
if (currenttrack.sequence != 0)
@@ -590,6 +601,7 @@ namespace FileSystemIDandChk.ImagePlugins
}
// File does exist, process it
if (MainClass.isDebug)
Console.WriteLine("DEBUG (CDRWin plugin): File \"{0}\" found", currentfile.datafile);
switch (currentfile.filetype)
@@ -605,12 +617,12 @@ namespace FileSystemIDandChk.ImagePlugins
throw new FeatureUnsupportedImageException(String.Format("Unknown file type {0}", currentfile.filetype));
}
Console.WriteLine("DEBUG (CDRWin plugin): Sets currentfile.offset to 0 at line 514");
currentfile.offset = 0;
currentfile.sequence = 0;
}
else if (MatchFlags.Success)
{
if (MainClass.isDebug)
Console.WriteLine("DEBUG (CDRWin plugin): Found FLAGS at line {0}", line);
if (!intrack)
throw new FeatureUnsupportedImageException(String.Format("Found FLAGS field in incorrect place at line {0}", line));
@@ -618,6 +630,7 @@ namespace FileSystemIDandChk.ImagePlugins
}
else if (MatchGenre.Success)
{
if (MainClass.isDebug)
Console.WriteLine("DEBUG (CDRWin plugin): Found GENRE at line {0}", line);
if (intrack)
currenttrack.genre = MatchGenre.Groups[1].Value;
@@ -626,6 +639,7 @@ namespace FileSystemIDandChk.ImagePlugins
}
else if (MatchIndex.Success)
{
if (MainClass.isDebug)
Console.WriteLine("DEBUG (CDRWin plugin): Found INDEX at line {0}", line);
if (!intrack)
throw new FeatureUnsupportedImageException(String.Format("Found INDEX before a track {0}", line));
@@ -643,14 +657,18 @@ namespace FileSystemIDandChk.ImagePlugins
{
cuetracks[currenttrack.sequence - 2].sectors = offset - currentfileoffsetsector;
currentfile.offset += cuetracks[currenttrack.sequence - 2].sectors * cuetracks[currenttrack.sequence - 2].bps;
if (MainClass.isDebug)
{
Console.WriteLine("DEBUG (CDRWin plugin): Sets currentfile.offset to {0} at line 553", currentfile.offset);
Console.WriteLine("DEBUG (CDRWin plugin): cuetracks[currenttrack.sequence-2].sectors = {0}", cuetracks[currenttrack.sequence - 2].sectors);
Console.WriteLine("DEBUG (CDRWin plugin): cuetracks[currenttrack.sequence-2].bps = {0}", cuetracks[currenttrack.sequence - 2].bps);
}
}
}
if ((index == 0 || (index == 1 && !currenttrack.indexes.ContainsKey(0))) && currenttrack.sequence == 1)
{
if (MainClass.isDebug)
Console.WriteLine("DEBUG (CDRWin plugin): Sets currentfile.offset to {0} at line 559", offset * currenttrack.bps);
currentfile.offset = offset * currenttrack.bps;
}
@@ -661,6 +679,7 @@ namespace FileSystemIDandChk.ImagePlugins
}
else if (MatchISRC.Success)
{
if (MainClass.isDebug)
Console.WriteLine("DEBUG (CDRWin plugin): Found ISRC at line {0}", line);
if (!intrack)
throw new FeatureUnsupportedImageException(String.Format("Found ISRC before a track {0}", line));
@@ -668,6 +687,7 @@ namespace FileSystemIDandChk.ImagePlugins
}
else if (MatchMCN.Success)
{
if (MainClass.isDebug)
Console.WriteLine("DEBUG (CDRWin plugin): Found CATALOG at line {0}", line);
if (!intrack)
discimage.mcn = MatchMCN.Groups[1].Value;
@@ -676,6 +696,7 @@ namespace FileSystemIDandChk.ImagePlugins
}
else if (MatchPerformer.Success)
{
if (MainClass.isDebug)
Console.WriteLine("DEBUG (CDRWin plugin): Found PERFORMER at line {0}", line);
if (intrack)
currenttrack.performer = MatchPerformer.Groups[1].Value;
@@ -684,6 +705,7 @@ namespace FileSystemIDandChk.ImagePlugins
}
else if (MatchPostgap.Success)
{
if (MainClass.isDebug)
Console.WriteLine("DEBUG (CDRWin plugin): Found POSTGAP at line {0}", line);
if (intrack)
{
@@ -694,6 +716,7 @@ namespace FileSystemIDandChk.ImagePlugins
}
else if (MatchPregap.Success)
{
if (MainClass.isDebug)
Console.WriteLine("DEBUG (CDRWin plugin): Found PREGAP at line {0}", line);
if (intrack)
{
@@ -704,6 +727,7 @@ namespace FileSystemIDandChk.ImagePlugins
}
else if (MatchSongWriter.Success)
{
if (MainClass.isDebug)
Console.WriteLine("DEBUG (CDRWin plugin): Found SONGWRITER at line {0}", line);
if (intrack)
currenttrack.songwriter = MatchSongWriter.Groups[1].Value;
@@ -712,6 +736,7 @@ namespace FileSystemIDandChk.ImagePlugins
}
else if (MatchTitle.Success)
{
if (MainClass.isDebug)
Console.WriteLine("DEBUG (CDRWin plugin): Found TITLE at line {0}", line);
if (intrack)
currenttrack.title = MatchTitle.Groups[1].Value;
@@ -720,6 +745,7 @@ namespace FileSystemIDandChk.ImagePlugins
}
else if (MatchTrack.Success)
{
if (MainClass.isDebug)
Console.WriteLine("DEBUG (CDRWin plugin): Found TRACK at line {0}", line);
if (currentfile.datafile == "")
throw new FeatureUnsupportedImageException(String.Format("Found TRACK field before a file is defined at line {0}", line));
@@ -736,6 +762,7 @@ namespace FileSystemIDandChk.ImagePlugins
currenttrack = new CDRWinTrack();
currenttrack.indexes = new Dictionary<int, ulong>();
currenttrack.sequence = uint.Parse(MatchTrack.Groups[1].Value);
if (MainClass.isDebug)
Console.WriteLine("DEBUG (CDRWin plugin): Setting currenttrack.sequence to {0}", currenttrack.sequence);
currentfile.sequence = currenttrack.sequence;
currenttrack.bps = CDRWinTrackTypeToBytesPerSector(MatchTrack.Groups[2].Value);
@@ -860,6 +887,8 @@ namespace FileSystemIDandChk.ImagePlugins
discimage.disktype = DiskType.CD;
}
if (MainClass.isDebug)
{
// DEBUG information
Console.WriteLine("DEBUG (CDRWin plugin): Disc image parsing results");
Console.WriteLine("DEBUG (CDRWin plugin): Disc CD-TEXT:");
@@ -980,7 +1009,9 @@ namespace FileSystemIDandChk.ImagePlugins
else
Console.WriteLine("DEBUG (CDRWin plugin): \t\tTitle: {0}", discimage.tracks[i].title);
}
}
if (MainClass.isDebug)
Console.WriteLine("DEBUG (CDRWin plugin): Building offset map");
partitions = new List<FileSystemIDandChk.PartPlugins.Partition>();
@@ -1016,14 +1047,14 @@ namespace FileSystemIDandChk.ImagePlugins
byte_offset += partition.PartitionLength;
partitionSequence++;
if(!offsetmap.ContainsKey(discimage.tracks[i].sequence))
if (!offsetmap.ContainsKey(discimage.tracks[i].sequence))
offsetmap.Add(discimage.tracks[i].sequence, partition.PartitionStartSector);
else
{
ulong old_start;
offsetmap.TryGetValue(discimage.tracks[i].sequence, out old_start);
if(partition.PartitionStartSector < old_start)
if (partition.PartitionStartSector < old_start)
{
offsetmap.Remove(discimage.tracks[i].sequence);
offsetmap.Add(discimage.tracks[i].sequence, partition.PartitionStartSector);
@@ -1054,14 +1085,14 @@ namespace FileSystemIDandChk.ImagePlugins
byte_offset += partition.PartitionLength;
partitionSequence++;
if(!offsetmap.ContainsKey(discimage.tracks[i].sequence))
if (!offsetmap.ContainsKey(discimage.tracks[i].sequence))
offsetmap.Add(discimage.tracks[i].sequence, partition.PartitionStartSector);
else
{
ulong old_start;
offsetmap.TryGetValue(discimage.tracks[i].sequence, out old_start);
if(partition.PartitionStartSector < old_start)
if (partition.PartitionStartSector < old_start)
{
offsetmap.Remove(discimage.tracks[i].sequence);
offsetmap.Add(discimage.tracks[i].sequence, partition.PartitionStartSector);
@@ -1086,14 +1117,14 @@ namespace FileSystemIDandChk.ImagePlugins
byte_offset += partition.PartitionLength;
partitionSequence++;
if(!offsetmap.ContainsKey(discimage.tracks[i].sequence))
if (!offsetmap.ContainsKey(discimage.tracks[i].sequence))
offsetmap.Add(discimage.tracks[i].sequence, partition.PartitionStartSector);
else
{
ulong old_start;
offsetmap.TryGetValue(discimage.tracks[i].sequence, out old_start);
if(partition.PartitionStartSector < old_start)
if (partition.PartitionStartSector < old_start)
{
offsetmap.Remove(discimage.tracks[i].sequence);
offsetmap.Add(discimage.tracks[i].sequence, partition.PartitionStartSector);
@@ -1105,17 +1136,20 @@ namespace FileSystemIDandChk.ImagePlugins
}
// Print offset map
Console.WriteLine("DEBUG (CDRWin plugin) printing partition map");
foreach(FileSystemIDandChk.PartPlugins.Partition partition in partitions)
if (MainClass.isDebug)
{
Console.WriteLine ("DEBUG (CDRWin plugin): Partition sequence: {0}", partition.PartitionSequence);
Console.WriteLine ("DEBUG (CDRWin plugin): \tPartition name: {0}", partition.PartitionName);
Console.WriteLine ("DEBUG (CDRWin plugin): \tPartition description: {0}", partition.PartitionDescription);
Console.WriteLine ("DEBUG (CDRWin plugin): \tPartition type: {0}", partition.PartitionType);
Console.WriteLine ("DEBUG (CDRWin plugin): \tPartition starting sector: {0}", partition.PartitionStartSector);
Console.WriteLine ("DEBUG (CDRWin plugin): \tPartition sectors: {0}", partition.PartitionSectors);
Console.WriteLine ("DEBUG (CDRWin plugin): \tPartition starting offset: {0}", partition.PartitionStart);
Console.WriteLine ("DEBUG (CDRWin plugin): \tPartition size in bytes: {0}", partition.PartitionLength);
Console.WriteLine("DEBUG (CDRWin plugin) printing partition map");
foreach (FileSystemIDandChk.PartPlugins.Partition partition in partitions)
{
Console.WriteLine("DEBUG (CDRWin plugin): Partition sequence: {0}", partition.PartitionSequence);
Console.WriteLine("DEBUG (CDRWin plugin): \tPartition name: {0}", partition.PartitionName);
Console.WriteLine("DEBUG (CDRWin plugin): \tPartition description: {0}", partition.PartitionDescription);
Console.WriteLine("DEBUG (CDRWin plugin): \tPartition type: {0}", partition.PartitionType);
Console.WriteLine("DEBUG (CDRWin plugin): \tPartition starting sector: {0}", partition.PartitionStartSector);
Console.WriteLine("DEBUG (CDRWin plugin): \tPartition sectors: {0}", partition.PartitionSectors);
Console.WriteLine("DEBUG (CDRWin plugin): \tPartition starting offset: {0}", partition.PartitionStart);
Console.WriteLine("DEBUG (CDRWin plugin): \tPartition size in bytes: {0}", partition.PartitionLength);
}
}
return true;
@@ -1220,7 +1254,7 @@ namespace FileSystemIDandChk.ImagePlugins
{
if (cdrwin_track.sequence == kvp.Key)
{
if((sectorAddress - kvp.Value) < cdrwin_track.sectors)
if ((sectorAddress - kvp.Value) < cdrwin_track.sectors)
return ReadSectors((sectorAddress - kvp.Value), length, kvp.Key);
}
}
@@ -1240,7 +1274,7 @@ namespace FileSystemIDandChk.ImagePlugins
{
if (cdrwin_track.sequence == kvp.Key)
{
if((sectorAddress - kvp.Value) < cdrwin_track.sectors)
if ((sectorAddress - kvp.Value) < cdrwin_track.sectors)
return ReadSectorsTag((sectorAddress - kvp.Value), length, kvp.Key, tag);
}
}
@@ -1344,7 +1378,7 @@ namespace FileSystemIDandChk.ImagePlugins
this.imageStream = new FileStream(_track.trackfile.datafile, FileMode.Open, FileAccess.Read);
BinaryReader br = new BinaryReader(this.imageStream);
br.BaseStream.Seek((long)_track.trackfile.offset + (long)(sectorAddress*(sector_offset + sector_size + sector_skip)), SeekOrigin.Begin);
br.BaseStream.Seek((long)_track.trackfile.offset + (long)(sectorAddress * (sector_offset + sector_size + sector_skip)), SeekOrigin.Begin);
if (sector_offset == 0 && sector_skip == 0)
buffer = br.ReadBytes((int)(sector_size * length));
@@ -1521,7 +1555,7 @@ namespace FileSystemIDandChk.ImagePlugins
throw new FeatureSupportedButNotImplementedImageException("Feature not yet implemented");
case CDRWinTrackTypeCDG:
{
if(tag != SectorTagType.CDSectorSubchannel)
if (tag != SectorTagType.CDSectorSubchannel)
throw new ArgumentException("Unsupported tag requested for this track", "tag");
sector_offset = 2352;
@@ -1538,7 +1572,7 @@ namespace FileSystemIDandChk.ImagePlugins
this.imageStream = new FileStream(_track.trackfile.datafile, FileMode.Open, FileAccess.Read);
BinaryReader br = new BinaryReader(this.imageStream);
br.BaseStream.Seek((long)_track.trackfile.offset + (long)(sectorAddress*(sector_offset + sector_size + sector_skip)), SeekOrigin.Begin);
br.BaseStream.Seek((long)_track.trackfile.offset + (long)(sectorAddress * (sector_offset + sector_size + sector_skip)), SeekOrigin.Begin);
if (sector_offset == 0 && sector_skip == 0)
buffer = br.ReadBytes((int)(sector_size * length));
@@ -1578,7 +1612,7 @@ namespace FileSystemIDandChk.ImagePlugins
{
if (cdrwin_track.sequence == kvp.Key)
{
if((sectorAddress - kvp.Value) < cdrwin_track.sectors)
if ((sectorAddress - kvp.Value) < cdrwin_track.sectors)
return ReadSectorsLong((sectorAddress - kvp.Value), length, kvp.Key);
}
}
@@ -1664,7 +1698,7 @@ namespace FileSystemIDandChk.ImagePlugins
this.imageStream = new FileStream(_track.trackfile.datafile, FileMode.Open, FileAccess.Read);
BinaryReader br = new BinaryReader(this.imageStream);
br.BaseStream.Seek((long)_track.trackfile.offset + (long)(sectorAddress*(sector_offset + sector_size + sector_skip)), SeekOrigin.Begin);
br.BaseStream.Seek((long)_track.trackfile.offset + (long)(sectorAddress * (sector_offset + sector_size + sector_skip)), SeekOrigin.Begin);
if (sector_offset == 0 && sector_skip == 0)
buffer = br.ReadBytes((int)(sector_size * length));

View File

@@ -123,19 +123,19 @@ namespace FileSystemIDandChk
try
{
if(_imageFormat.OpenImage(filename))
{
Console.WriteLine("DEBUG: Correctly opened image file.");
Console.WriteLine("DEBUG: Image without headers is {0} bytes.", _imageFormat.GetImageSize());
Console.WriteLine("DEBUG: Image has {0} sectors.", _imageFormat.GetSectors());
}
else
if(!_imageFormat.OpenImage(filename))
{
Console.WriteLine("Unable to open image format");
Console.WriteLine("No error given");
return;
}
if(isDebug)
{
Console.WriteLine("DEBUG: Correctly opened image file.");
Console.WriteLine("DEBUG: Image without headers is {0} bytes.", _imageFormat.GetImageSize());
Console.WriteLine("DEBUG: Image has {0} sectors.", _imageFormat.GetSectors());
}
}
catch(Exception ex)
{