Пример #1
0
        private int CompareRaw(BackgroundWorker worker, string[] files, CompareInfo ci, DiffWriter sw)
        {
            CompareCore cc = new CompareCore(sw);

            cc.HexOut = ci.setting.hexOut;

            int ret = 0;

            try {
                using (BinaryReader br1 = new BinaryReader(File.OpenRead(files[0])))
                    using (BinaryReader br2 = new BinaryReader(File.OpenRead(files[1]))) {
                        br1.BaseStream.Seek(0, SeekOrigin.Begin);
                        br2.BaseStream.Seek(0, SeekOrigin.Begin);

                        long limit        = (br1.BaseStream.Length > br2.BaseStream.Length) ? br2.BaseStream.Length : br1.BaseStream.Length;
                        long read         = 0;
                        int  prevProgress = 0;

                        int BLOCK_LENGTH = 2 * 1024 * 1024;
                        while (read < limit)
                        {
                            int size = BLOCK_LENGTH;
                            if (read + BLOCK_LENGTH > limit)
                            {
                                size = (int)(limit - read);
                            }

                            // まとめて読んで
                            byte[] ba1 = br1.ReadBytes(size);
                            byte[] ba2 = br2.ReadBytes(size);

                            // 比較
                            if (cc.CompareLoop(ba1, ba2, read))
                            {
                                ret = 1;
                            }
                            read += size;

                            // 進捗を通知
                            int progress = (int)(read * 100 / limit);
                            if (progress > prevProgress)
                            {
                                prevProgress = progress;
                                worker.ReportProgress(progress);
                            }
                        }
                    }
            } catch {
                return(-1);
            }
            if (sw != null && ret == 1)
            {
                sw.PrintResult(cc.Count, cc.Max);
            }
            return(ret);
        }
Пример #2
0
        private int CompareWav(BackgroundWorker worker, string[] files, CompareInfo ci, DiffWriter sw)
        {
            CompareCore cc = new CompareCore(sw);

            cc.HexOut = ci.setting.hexOut;
            int ret = 0;

            try {
                using (RiffReader rr1 = new RiffReader(files[0]))
                    using (RiffReader rr2 = new RiffReader(files[1])) {
                        if (!rr1.Parse())
                        {
                            return(-1);
                        }
                        if (!rr2.Parse())
                        {
                            return(-1);
                        }
                        if (!ci.setting.streamOrigin)
                        {
                            cc.Offset = rr1.StreamOffset;
                        }

                        // 読み込み終端。単位に注意
                        long limit = 0;
                        if (ci.setting.sampleOrder)
                        {
                            limit = (rr1.Samples > rr2.Samples) ? rr2.Samples : rr1.Samples;
                        }
                        else
                        {
                            limit = (rr1.Length > rr2.Length) ? rr2.Length : rr1.Length;
                        }
                        // 現在処理位置。単位に注意
                        long read         = 0;
                        int  prevProgress = 0;

                        int BLOCK_LENGTH = 2 * 1024 * 1024;
                        while (read < limit)
                        {
                            int size = BLOCK_LENGTH;
                            if (read + BLOCK_LENGTH > limit)
                            {
                                size = (int)(limit - read);
                            }

                            if (ci.setting.sampleOrder)
                            {
                                int q = rr1.WaveFormat.BitsPerSample / 8;

                                // まとめて読んで比較
                                if (q == 1)
                                {
                                    byte[] ba1 = rr1.Read8(size);
                                    byte[] ba2 = rr2.Read8(size);
                                    if (cc.CompareLoop(ba1, ba2, read))
                                    {
                                        ret = 1;
                                    }
                                }
                                else if (q == 2)
                                {
                                    short[] sa1 = rr1.Read16(size);
                                    short[] sa2 = rr2.Read16(size);
                                    if (cc.CompareLoop(sa1, sa2, read * q))
                                    {
                                        ret = 1;
                                    }
                                }
                                else if (q == 3)
                                {
                                    int[] sa1 = rr1.Read24(size);
                                    int[] sa2 = rr2.Read24(size);
                                    if (cc.CompareLoop(sa1, sa2, read * q, q))
                                    {
                                        ret = 1;
                                    }
                                }
                                else if (q == 4)
                                {
                                    if (rr1.WaveFormat.FormatTag == WaveFormatTag.IEEE_FLOAT)
                                    {
                                        float[] sa1 = rr1.Read32F(size);
                                        float[] sa2 = rr2.Read32F(size);
                                        if (cc.CompareLoop(sa1, sa2, read * q))
                                        {
                                            ret = 1;
                                        }
                                    }
                                    else
                                    {
                                        int[] sa1 = rr1.Read32(size);
                                        int[] sa2 = rr2.Read32(size);
                                        if (cc.CompareLoop(sa1, sa2, read * q, q))
                                        {
                                            ret = 1;
                                        }
                                    }
                                }
                                else
                                {
                                    return(-1);
                                }
                            }
                            else
                            {
                                // まとめて読んで比較
                                byte[] ba1 = rr1.Read8(size);
                                byte[] ba2 = rr2.Read8(size);
                                if (cc.CompareLoop(ba1, ba2, read))
                                {
                                    ret = 1;
                                }
                            }

                            read += size;

                            // 進捗を通知
                            int progress = (int)(read * 100 / limit);
                            if (progress > prevProgress)
                            {
                                prevProgress = progress;
                                worker.ReportProgress(progress);
                            }
                        }
                    }
            } catch {
                return(-1);
            }
            if (sw != null && ret == 1)
            {
                if (cc.DiffType)
                {
                    sw.PrintResult(cc.Count, cc.Max);
                }
                else
                {
                    sw.PrintResult(cc.Count, cc.fMax);
                }
            }
            return(ret);
        }