示例#1
0
        private static void Main(string[] args)
        {
            StringWriter      writer = new StringWriter();
            Parser            p      = new Parser(with => with.HelpWriter = writer);
            TapCheckerOptions opts   = new TapCheckerOptions();

            if (!p.ParseArguments(args, opts))
            {
                Console.WriteLine(writer.ToString());
                return;
            }

            List <string> files = new List <string>();

            if ((opts.Files.Length == 1) && (opts.Files[0] == "*"))
            {
                files.AddRange(Directory.GetFiles(".", "*.tap"));
            }
            else
            {
                files.AddRange(opts.Files.ToArray());
            }

            ConsoleColor currentColor = Console.ForegroundColor;
            TapChecker   checker      = new TapChecker();

            foreach (var fileToCheck in files)
            {
                List <ReportLine> report = checker.Check(fileToCheck, opts);

                foreach (var reportLine in report)
                {
                    switch (reportLine.Status)
                    {
                    case ReportLineStatus.Info:
                        Console.ForegroundColor = currentColor;
                        break;

                    case ReportLineStatus.Error:
                        Console.ForegroundColor = ConsoleColor.Red;
                        break;

                    case ReportLineStatus.Warning:
                        Console.ForegroundColor = ConsoleColor.Yellow;
                        break;
                    }
                    Console.WriteLine(reportLine.Message);
                }
                Console.WriteLine();
            }
            Console.ForegroundColor = currentColor;
            Console.WriteLine("Press enter to exit");
            Console.ReadLine();
        }
示例#2
0
        private static void Main(string[] args)
        {
            StringWriter writer = new StringWriter();
              Parser p = new Parser(with => with.HelpWriter = writer);
              TapCheckerOptions opts = new TapCheckerOptions();
              if (!p.ParseArguments(args, opts))
              {
            Console.WriteLine(writer.ToString());
            return;
              }

              List<string> files = new List<string>();
              if ((opts.Files.Length == 1) && (opts.Files[0] == "*"))
              {
            files.AddRange(Directory.GetFiles(".", "*.tap"));
              }
              else
              {
            files.AddRange(opts.Files.ToArray());
              }

              ConsoleColor currentColor = Console.ForegroundColor;
              TapChecker checker = new TapChecker();
              foreach (var fileToCheck in files)
              {
            List<ReportLine> report = checker.Check(fileToCheck, opts);

            foreach (var reportLine in report)
            {
              switch (reportLine.Status)
              {
            case ReportLineStatus.Info:
              Console.ForegroundColor = currentColor;
              break;
            case ReportLineStatus.Error:
              Console.ForegroundColor = ConsoleColor.Red;
              break;
            case ReportLineStatus.Warning:
              Console.ForegroundColor = ConsoleColor.Yellow;
              break;
              }
              Console.WriteLine(reportLine.Message);
            }
            Console.WriteLine();
              }
              Console.ForegroundColor = currentColor;
              Console.WriteLine("Press enter to exit");
              Console.ReadLine();
        }
示例#3
0
        internal List <ReportLine> Check(string fullFileName, TapCheckerOptions opts)
        {
            List <ReportLine> report = new List <ReportLine>();
            List <ReportLine> pauses = new List <ReportLine>();

            string fileName = Path.GetFileName(fullFileName);

            report.Add(new ReportLine(String.Format("TAP file: {0}", fileName), ReportLineStatus.Info));

            FileInfo fi = new FileInfo(fullFileName);

            if (!fi.Exists)
            {
                report.Add(new ReportLine("File not found", ReportLineStatus.Error));
                return(report);
            }

            TapHeader header = new TapHeader();

            try
            {
                using (MemoryStream ms = new MemoryStream(File.ReadAllBytes(fullFileName)))
                {
                    BinaryReader br = new BinaryReader(ms);
                    header.ReadHeader(br);
                    if (opts.LongPauseDetail && header.Version != TapFormat.VERSION_0_INITIAL)
                    {
                        UInt32 ticksDiv = (UInt32)(header.VideoStandard == TapVideoStandard.PAL ? 985248 : 1022730);

                        while (ms.Position < ms.Length)
                        {
                            if (br.ReadByte() != 0)
                            {
                                continue;
                            }
                            byte data = br.ReadByte();

                            UInt32 pause = data;
                            data   = br.ReadByte();
                            pause |= (UInt32)(data << 8);
                            data   = br.ReadByte();
                            pause |= (UInt32)(data << 16);
                            pauses.Add(new ReportLine(String.Format("Pause at: {0} for {1} (~ {2:F2}s)", ms.Position - 4, pause, (double)pause / ticksDiv), ReportLineStatus.Info));
                        }
                    }
                }
            }
            catch (Exception e)
            {
                report.Add(new ReportLine(string.Format("Error reading file: {0}", e.Message), ReportLineStatus.Error));
                return(report);
            }

            AddHeaderInfo(header, report);

            UInt32 computedLength = (UInt32)fi.Length - TapHeader.HeaderSize;

            if ((header.Magic == TapHeaderMagic.C64_Magic && header.Platform != TapPlatform.C64) || (header.Magic == TapHeaderMagic.C16_Magic && header.Platform != TapPlatform.C16))
            {
                report.Add(new ReportLine("Header Magic and Platform do not match!", ReportLineStatus.Error));
            }
            else
            {
                report.Add(new ReportLine("Header Magic and Platform match", ReportLineStatus.Info));
            }

            report.AddRange(pauses);

            if (header.DataLength != computedLength)
            {
                report.Add(new ReportLine("TAP Header Data Length INCORRECT!", ReportLineStatus.Warning));
                report.Add(new ReportLine(string.Format("\tHeader reports: {0}", header.DataLength), ReportLineStatus.Warning));
                report.Add(new ReportLine(string.Format("\tComputed Length: {0}", computedLength), ReportLineStatus.Warning));
                report.Add(new ReportLine(string.Format("\tFile is: {0}", computedLength > header.DataLength ? "Longer" : "Shorter"), ReportLineStatus.Warning));
                header.DataLength = computedLength;
                if (opts.Fix)
                {
                    Fix(report, fullFileName, header);
                }
            }
            return(report);
        }