コード例 #1
0
        static int Main(string[] args)
        {
            long total = 0;

#if DEBUG
            args = new string[]
            {
                "COM3", "/S", "10", "/N", "0", "/M", "rnd_!.bin", "/D", @"C:\TEMP\RNG"
            };
#endif
            if (args.Length > 0)
            {
                Arguments A = parseArgs(args);
                if (A.ex == null)
                {
                    Stream     Output = null;
                    FileWriter FW     = null;
                    if (A.Mask == "-")
                    {
                        Output = Console.OpenStandardOutput();
                    }
                    else
                    {
                        FW = new FileWriter(A.Directory, A.Mask, A.FileSize * 1024 * 1024, A.NumFiles);
                    }
                    Console.Clear();
                    libOneRNG.RNG R = new libOneRNG.RNG(A.Port);
                    R.Start();
                    while (!HasKey(ConsoleKey.Escape))
                    {
                        byte[] b = R.Read(1024);
                        total += b.Length;
                        Console.SetCursorPosition(0, 0);
                        Console.Error.WriteLine("Processed: {0}", nice(total));
                        if (Output != null)
                        {
                            Output.Write(b, 0, b.Length);
                        }
                        else
                        {
                            Console.Error.WriteLine("File: {0}/{1} ({2,6:0.00}%)", FW.CurrentNumber, FW.Count, perc(FW.Count, FW.CurrentNumber));
                            Console.Error.WriteLine("Size: {0} ({1,6:0.00}%)", nice(FW.CurrentPosition), perc(FW.Size, FW.CurrentPosition));
                            if (!FW.Write(b))
                            {
                                FW.Dispose();
                                return(0);
                            }
                        }
                        Console.Error.WriteLine("Press [ESC] to abort");
                    }
                    R.Stop();
                    R.Dispose();
                    Console.Error.WriteLine("Operation aborted by user input");
                    return(2);
                }
                else
                {
                    Console.Error.WriteLine("Error parsing arguments: {0}", A.ex.Message);
                    return(3);
                }
            }
            else
            {
                Help();
                return(1);
            }
        }