Beispiel #1
0
            public override void CalcHashes(Hashes hashFlags, Validations validationFlags)
            {
                if (Data.Issues.HasFatal)
                {
                    return;
                }

                if ((hashFlags & Hashes.Intrinsic) != 0 && Data.ActualAudioHeaderCRC8 == null)
                {
                    var hasher1 = new Crc8Hasher();
                    hasher1.Append(Data.aHdr);
                    byte[] hash1 = hasher1.GetHashAndReset();
                    Data.ActualAudioHeaderCRC8 = hash1[0];

                    try
                    {
                        var hasher2 = new Crc16nHasher();
                        hasher2.Append(Data.fbs, Data.mediaPosition, Data.FileSize - Data.mediaPosition - 2);
                        byte[] hash2 = hasher2.GetHashAndReset();
                        Data.ActualAudioBlockCRC16 = BitConverter.ToUInt16(hash2, 0);
                    }
                    catch (EndOfStreamException ex)
                    {
                        IssueModel.Add("Read failed while checking audio CRC: " + ex.Message, Severity.Fatal);
                        return;
                    }

                    if (!Data.IsBadDataCRC && !Data.IsBadHeaderCRC)
                    {
                        Data.ChIssue = Data.CdIssue = IssueModel.Add("CRC checks successful on audio header and data.", Severity.Noise, IssueTags.Success);
                    }
                    else
                    {
                        if (Data.IsBadHeaderCRC)
                        {
                            Data.ChIssue = IssueModel.Add("CRC-8 check failed on audio header.", Severity.Error, IssueTags.Failure);
                        }
                        else
                        {
                            Data.ChIssue = IssueModel.Add("CRC-8 check successful on audio header.", Severity.Noise, IssueTags.Success);
                        }

                        if (Data.IsBadDataCRC)
                        {
                            Data.CdIssue = IssueModel.Add("CRC-16 check failed on audio data.", Severity.Error, IssueTags.Failure);
                        }
                        else
                        {
                            Data.CdIssue = IssueModel.Add("CRC-16 check successful on audio data.", Severity.Noise, IssueTags.Success);
                        }
                    }
                }

                if ((hashFlags & Hashes.PcmMD5) != 0 && Data.actualAudioDataMD5 == null)
                {
                    Process px = null;
                    try
                    { px = StartFlac(Data.Path); }
                    catch (Exception ex)
                    { IssueModel.Add("flac executable failed with '" + ex.Message.Trim(null) + "'."); }

                    if (px != null)
                    {
                        using (var br = new BinaryReader(px.StandardOutput.BaseStream))
                        {
                            try
                            {
                                var hasher = new Md5Hasher();
                                hasher.Append(br);
                                var hash = hasher.GetHashAndReset();
                                Data.actualAudioDataMD5 = hash;
                            }
                            catch (EndOfStreamException ex)
                            { IssueModel.Add("Read failed while verifying audio MD5: " + ex.Message, Severity.Fatal); }

                            if (Data.IsBadDataMD5)
                            {
                                Data.CmIssue = IssueModel.Add("MD5 check failed on audio data.", Severity.Error, IssueTags.Failure);
                            }
                            else
                            {
                                Data.CmIssue = IssueModel.Add("MD5 check successful on audio data.", Severity.Noise, IssueTags.Success);
                            }
                        }
                    }
                }

                if ((hashFlags & (Hashes.PcmCRC32 | Hashes._FlacMatch)) != 0 && Data.ActualPcmCRC32 == null)
                {
                    Process px = null;
                    try
                    { px = StartFlac(Data.Path); }
                    catch (Exception ex)
                    { IssueModel.Add("flac executable failed with '" + ex.Message.Trim(null) + "'."); }

                    if (px != null)
                    {
                        using (var br = new BinaryReader(px.StandardOutput.BaseStream))
                        {
                            var hasher = new Crc32rHasher();
                            hasher.Append(br);
                            byte[] hash = hasher.GetHashAndReset();
                            Data.ActualPcmCRC32 = BitConverter.ToUInt32(hash, 0);
                        }
                    }
                }

                if ((hashFlags & (Hashes._FlacTags)) != 0)
                {
                    TagCheckNumber("TRACKNUMBER");
                    TagCheckNumber("TRACKTOTAL", optional: true);
                    TagCheckNumber("DISCNUMBER", true);
                    TagCheckNumber("DISCTOTAL", true);
                    TagCheckDate("DATE");
                    TagCheckDate("RELEASE DATE", optional: true);
                    TagCheckDate("ORIGINAL RELEASE DATE", true);
                    TagCheckText("TITLE");
                    TagCheckText("ARTIST");
                    TagCheckText("ALBUM");
                    TagCheckText("ALBUMARTIST", optional: true);
                    TagCheckText("ALBUMARTISTSORTORDER", true);
                    TagCheckText("ORGANIZATION", true);
                    TagCheckText("BARCODE", true);
                    TagCheckText("CATALOGNUMBER", true);
                }

                base.CalcHashes(hashFlags, validationFlags);
            }
Beispiel #2
0
            public override void CalcHashes(Hashes hashFlags, Validations validationFlags)
            {
                if (Data.Issues.HasFatal)
                {
                    return;
                }

                if ((hashFlags & Hashes.Intrinsic) != 0)
                {
                    if (Data.ActualAudioHeaderCRC8 == null)
                    {
                        var hasher = new Crc8Hasher();
                        hasher.Append(Data.aHdr);
                        var hash = hasher.GetHashAndReset();
                        Data.ActualAudioHeaderCRC8 = hash[0];

                        if (Data.IsBadHeader)
                        {
                            IssueModel.Add("CRC-8 check failed on audio header.");
                        }
                    }

                    if (Data.ActualAudioBlockCRC16 == null)
                    {
                        try
                        {
                            var hasher = new Crc16nHasher();
                            hasher.Append(Data.fbs, Data.mediaPosition, Data.FileSize - Data.mediaPosition - 2);
                            var hash = hasher.GetHashAndReset();
                            Data.ActualAudioBlockCRC16 = BitConverter.ToUInt16(hash, 0);
                        }
                        catch (EndOfStreamException ex)
                        {
                            IssueModel.Add("Read failed while verifying audio CRC: " + ex.Message, Severity.Fatal);
                            return;
                        }
                    }

                    if (Data.IsBadDataCRC16)
                    {
                        IssueModel.Add("CRC-16 check failed on audio data.");
                    }
                    else
                    if (Data.IsBadHeader)
                    {
                        IssueModel.Add("CRC-16 check successful.", Severity.Advisory);
                    }
                    else
                    {
                        IssueModel.Add("CRC-8, CRC-16 checks successful.", Severity.Noise);
                    }
                }

#if !NETFX_CORE
                if ((hashFlags & Hashes.PcmMD5) != 0 && Data.actualAudioDataMD5 == null)
                {
                    Process px = null;
                    try
                    { px = StartFlac(Data.Path); }
                    catch (Exception ex)
                    { IssueModel.Add("flac executable failed with '" + ex.Message.Trim(null) + "'."); }

                    if (px != null)
                    {
                        using (var br = new BinaryReader(px.StandardOutput.BaseStream))
                        {
                            try
                            {
                                var hasher = new Md5Hasher();
                                hasher.Append(br);
                                var hash = hasher.GetHashAndReset();
                                Data.actualAudioDataMD5 = hash;
                            }
                            catch (EndOfStreamException ex)
                            { IssueModel.Add("Read failed while verifying audio MD5: " + ex.Message, Severity.Fatal); }

                            if (Data.IsBadDataMD5)
                            {
                                IssueModel.Add("MD5 check failed on audio data.");
                            }
                            else
                            {
                                IssueModel.Add("MD5 check successful.", Severity.Noise);
                            }
                        }
                    }
                }

                if ((hashFlags & Hashes.PcmCRC32) != 0 && Data.ActualPcmCRC32 == null)
                {
                    Process px = null;
                    try
                    { px = StartFlac(Data.Path); }
                    catch (Exception ex)
                    { IssueModel.Add("flac executable failed with '" + ex.Message.Trim(null) + "'."); }

                    if (px != null)
                    {
                        using (var br = new BinaryReader(px.StandardOutput.BaseStream))
                        {
                            var hasher = new Crc32rHasher();
                            hasher.Append(br);
                            var hash = hasher.GetHashAndReset();
                            Data.ActualPcmCRC32 = BitConverter.ToUInt32(hash, 0);
                        }
                    }
                }
#endif
                base.CalcHashes(hashFlags, validationFlags);
            }