コード例 #1
0
        /* ---------------------------------------------------------------------------------------------------------------------------------- */
        public static bool TestRleConversionAgainstReferenceBmps(string rlesDirectory, string referenceBmpsDirectory, bool logInfo = true)
        {
            var rleFiles          = Directory.GetFiles(rlesDirectory, "*.rle", SearchOption.AllDirectories);
            var referenceBmpFiles = Directory.GetFiles(referenceBmpsDirectory, "*.bmp", SearchOption.AllDirectories);

            foreach (var rlePath in rleFiles)
            {
                RleFile rle = RleFile.CreateFromFile(rlePath);
                BmpFile bmp = RleToBmp.Convert(rle);

                var convertedBmpPath = Path.ChangeExtension(rlePath, "bmp");

                bmp.WriteToFile(convertedBmpPath);

                var referenceBmpPath = referenceBmpFiles.SingleOrDefault(b => Path.GetFileNameWithoutExtension(b) == Path.GetFileNameWithoutExtension(rlePath));

                if (referenceBmpPath == null)
                {
                    if (logInfo)
                    {
                        Console.WriteLine("ERROR. Ref bmp not found for " + rle);
                    }

                    continue;
                }

                bool areMd5Equal = ValidityUtils.AreMD5Equal(convertedBmpPath, referenceBmpPath);

                if (!areMd5Equal)
                {
                    if (logInfo)
                    {
                        Console.WriteLine(string.Format("Converted BMP differs from the reference BMP: \nConverted: {0} \nReference: {1}", convertedBmpPath, referenceBmpPath));
                    }

                    return(false);
                }

                File.Delete(convertedBmpPath);
            }

            return(true);
        }
コード例 #2
0
        /* ---------------------------------------------------------------------------------------------------------------------------------- */
        public bool TestWdtDecompressionAgainstReferenceWdt(string wdtPath, string referenceWdtPath, bool logInfo = true)
        {
            bool isWdtValid = true;

            var    wdtFile             = WdtFile.CreateFromFile(wdtPath);
            string decompressedWdtPath = Path.ChangeExtension(wdtPath, "temp");

            using (var inFile = File.OpenRead(wdtPath))
                using (var compareFile = File.OpenRead(referenceWdtPath))
                    using (var outFile = File.Create(decompressedWdtPath))
                    {
                        byte[] comparisonBuffer = new byte[wdtFile.PageSize];

                        for (int i = 0; i < wdtFile.ChapterList.Count; i++)
                        {
                            compareFile.Read(comparisonBuffer, 0, comparisonBuffer.Length);
                            var chapter = wdtFile.ChapterList[i];

                            byte[] contentDecompressed = new byte[wdtFile.PageSize];
                            var    memStream           = new MemoryStream(contentDecompressed);
                            int    decompressedSize    = WdtDecompressor.DecompressChapter(wdtFile, chapter, memStream);

                            if (logInfo)
                            {
                                Console.WriteLine(string.Format("Chapter: {0} Start: {3:X} End: {4:X} Size: {1} Bytes: {2}",
                                                                i, chapter.Size, decompressedSize, chapter.StartPosition, chapter.EndPosition));
                            }

                            decompressedSize = Math.Min(wdtFile.PageSize, decompressedSize);

                            // Byte-by-byte comparison of the original decompressed file against
                            // our decompressed file - just to be 100% sure that everything went right
                            for (int x = 0; x < decompressedSize; x++)
                            {
                                if (comparisonBuffer[x] != contentDecompressed[x])
                                {
                                    isWdtValid = false;

                                    if (logInfo)
                                    {
                                        int misPos = wdtFile.PageSize * i + x;
                                        Console.WriteLine();
                                        DebugUtils.PrintHex(misPos, "Byte mismatch at");
                                        DebugUtils.PrintHex(comparisonBuffer[i], "Original");
                                        DebugUtils.PrintHex(contentDecompressed[i], "Ours");
                                    }
                                }
                            }

                            outFile.Write(contentDecompressed, 0, decompressedSize);
                        }
                    }

            bool areMd5Equal = ValidityUtils.AreMD5Equal(decompressedWdtPath, referenceWdtPath);

            isWdtValid &= areMd5Equal;

            if (logInfo)
            {
                Console.WriteLine("Are MD5 equal: " + areMd5Equal);
            }

            File.Delete(decompressedWdtPath);

            return(isWdtValid);
        }