Пример #1
0
        private static IEnumerable <ReadTestResult> Read_Archive_Items(IEnumerable <FileEntry> files)
        {
            var results = new ConcurrentBag <ReadTestResult>();

            //foreach (var file in files)
            Parallel.ForEach(files, file =>
            {
                try
                {
                    if (file.Archive is not Archive ar)
                    {
                        return;
                    }

                    using var ms = new MemoryStream();
                    ar.CopyFileToStream(ms, file.NameHash64, false);

                    var c = new CR2WFile {
                        FileName = file.NameOrHash
                    };
                    ms.Seek(0, SeekOrigin.Begin);
                    var readResult = c.Read(ms);

                    switch (readResult)
                    {
                    case EFileReadErrorCodes.NoCr2w:
                        results.Add(new ReadTestResult
                        {
                            FileEntry  = file,
                            Success    = true,
                            ReadResult = ReadTestResult.ReadResultType.NoCr2W
                        });
                        break;

                    case EFileReadErrorCodes.UnsupportedVersion:
                        results.Add(new ReadTestResult
                        {
                            FileEntry  = file,
                            Success    = false,
                            ReadResult = ReadTestResult.ReadResultType.UnsupportedVersion,
                            Message    = $"Unsupported Version ({c.GetFileHeader().version})"
                        });
                        break;

                    case EFileReadErrorCodes.NoError:
                        var hasAdditionalBytes =
                            c.AdditionalCr2WFileBytes != null && c.AdditionalCr2WFileBytes.Any();

                        var(unknownTypes, unknownBytes) = c.GetUnknownBytes();
                        var hasUnknownBytes             = unknownBytes > 0;

                        var res = ReadTestResult.ReadResultType.NoError;
                        var msg = "";
                        if (hasAdditionalBytes)
                        {
                            res |= ReadTestResult.ReadResultType.HasAdditionalBytes;
                            msg += $"Additional Bytes: {c.AdditionalCr2WFileBytes.Length}";
                        }

                        if (hasUnknownBytes)
                        {
                            res |= ReadTestResult.ReadResultType.HasUnknownBytes;
                            msg += $"UnknownBytes Bytes: {unknownBytes}";
                        }

                        results.Add(new ReadTestResult
                        {
                            FileEntry       = file,
                            Success         = true /*!hasAdditionalBytes && !hasUnknownBytes*/,
                            ReadResult      = res,
                            Message         = msg,
                            AdditionalBytes = hasAdditionalBytes ? c.AdditionalCr2WFileBytes.Length : 0,
                            UnknownBytes    = hasUnknownBytes ? unknownBytes : 0,
                            UnknownTypes    = hasUnknownBytes ? unknownTypes : null,
                        });

                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }
                }
Пример #2
0
        private static IEnumerable <ReadTestResult> Read_Archive_Items(IEnumerable <FileEntry> files)
        {
            var results = new ConcurrentBag <ReadTestResult>();

#if IS_PARALLEL
            Parallel.ForEach(files, file =>
#else
            foreach (var file in files)
#endif
            {
                try
                {
                    var ar       = s_bm.Archives.Lookup(file.Archive.ArchiveAbsolutePath).Value as Archive;
                    using var ms = new MemoryStream();
                    ar?.CopyFileToStreamWithoutBuffers(ms, file.NameHash64);

                    var c = new CR2WFile {
                        FileName = file.NameOrHash
                    };
                    ms.Seek(0, SeekOrigin.Begin);
                    var readResult = c.Read(ms);

                    switch (readResult)
                    {
                    case EFileReadErrorCodes.NoCr2w:
                        results.Add(new ReadTestResult
                        {
                            FileEntry = file, Success = true, ReadResult = ReadTestResult.ReadResultType.NoCr2W
                        });
                        break;

                    case EFileReadErrorCodes.UnsupportedVersion:
                        results.Add(new ReadTestResult
                        {
                            FileEntry  = file,
                            Success    = false,
                            ReadResult = ReadTestResult.ReadResultType.UnsupportedVersion,
                            Message    = $"Unsupported Version ({c.GetFileHeader().version})"
                        });
                        break;

                    case EFileReadErrorCodes.NoError:
                        var hasAdditionalBytes =
                            c.AdditionalCr2WFileBytes != null && c.AdditionalCr2WFileBytes.Any();

                        var(unknownTypes, unknownBytes) = c.GetUnknownBytes();
                        var hasUnknownBytes             = unknownBytes > 0;

                        var res = ReadTestResult.ReadResultType.NoError;
                        var msg = "";
                        if (hasAdditionalBytes)
                        {
                            res |= ReadTestResult.ReadResultType.HasAdditionalBytes;
                            msg += $"Additional Bytes: {c.AdditionalCr2WFileBytes.Length}";
                        }

                        if (hasUnknownBytes)
                        {
                            res |= ReadTestResult.ReadResultType.HasUnknownBytes;
                            msg += $"UnknownBytes Bytes: {unknownBytes}";
                        }

                        results.Add(new ReadTestResult
                        {
                            FileEntry       = file,
                            Success         = true /*!hasAdditionalBytes && !hasUnknownBytes*/,
                            ReadResult      = res,
                            Message         = msg,
                            AdditionalBytes = hasAdditionalBytes ? c.AdditionalCr2WFileBytes.Length : 0,
                            UnknownBytes    = hasUnknownBytes ? unknownBytes : 0,
                            UnknownTypes    = hasUnknownBytes ? unknownTypes : null,
                        });

                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }
                }
                catch (Exception e)
                {
                    results.Add(new ReadTestResult
                    {
                        FileEntry     = file,
                        Success       = false,
                        ReadResult    = ReadTestResult.ReadResultType.RuntimeException,
                        ExceptionType = e.GetType(),
                        Message       = $"{e.Message}"
                    });
                }
#if IS_PARALLEL
            });