示例#1
0
        private void FileValidation()
        {
            if (BaseValidation() /* || State == FileState.InValidFile*/)
            {
                return;
            }
            switch (Extension)
            {
            case ".flac":
            {
                if (!GlobalConfiguration.Instance().InspectionOptions.FLACCompressRate)
                {
                    goto SKIP_FLAC_COMPRESS_RATE;
                }
                Flac = FlacData.GetMetadataFromFlac(FullPath);
                // _confidence = (float)Flac.CompressRate;
                Suffix += $"[{Flac.CompressRate * 100:00.00}%]";
                if (Flac.IsHiRes)
                {
                    Suffix += "[HR]";
                }
                if (Flac.HasCover)
                {
                    Suffix += "[图]";
                }
                Encode = Flac.Encoder;
                if (Flac.CompressRate > 0.9)     //Maybe an uncompressed file
                {
                    State = FileState.InValidFlacLevel;
                }
            }
SKIP_FLAC_COMPRESS_RATE:
                break;

            case ".cue":
                if (!GlobalConfiguration.Instance().InspectionOptions.CUEEncoding)
                {
                    break;
                }
                CheckCUE();
                break;

            case ".log":
            {
                if (!GlobalConfiguration.Instance().InspectionOptions.LogValidation)
                {
                    break;
                }
                Logger.Log(Logger.Level.Info, $"Log check for '{FullPath}'");
                Encode = EncodingDetector.GetEncoding(FullPath, out var confidence);
                if (confidence < 0.9)
                {
                    break;
                }
                var text  = File.ReadAllText(FullPath, System.Text.Encoding.GetEncoding(Encode));
                var index = 1;
                foreach (var(version, oldSignature, actualSignature) in LogChecker.Core.eac_verify(text))
                {
                    if (oldSignature == "")
                    {
                        Logger.Log(Logger.Level.Debug, $"No signature found, it could be '{actualSignature}'");
                        continue;
                    }
                    if (oldSignature != actualSignature)
                    {
                        Logger.Log(Logger.Level.Debug, $"Expect signature '{actualSignature}', but get '{oldSignature}'");
                        State = FileState.TamperedLog;
                    }
                    else
                    {
                        Logger.Log(Logger.Level.Fine, $"{index++}. Log entry is fine!");
                    }
                }
                break;
            }

            case ".png":
            {
                Logger.Log(Logger.Level.Info, $"Png check for '{FullPath}'");
                var pngInfo = PngData.GetMetadataFrom(FullPath);
                Suffix += $"[{pngInfo.CompressRate * 100:00.00}%]";
                if (pngInfo.CompressRate > 0.9)     //Maybe an uncompressed file
                {
                    State = FileState.InValidFlacLevel;
                }
                break;
            }

            default:
                if (!GlobalConfiguration.Instance().InspectionOptions.FileHeader)
                {
                    break;
                }
                if (!FileHeader.Check(FullPath))
                {
                    State = FileState.InValidFileSignature;
                }
                break;
            }
        }