Exemple #1
0
        public static Opts Parse(string[] args)
        {
            Opts opts = new Opts();

            bool            showHelp        = false;
            IList <BeeOpts> CommandLineOpts = new BeeOptsBuilder()
                                              .Add('d', "depth", OPTTYPE.VALUE, "max depth to go down", v => opts.Depth       = Convert.ToInt32(v))
                                              .Add('j', "follow", OPTTYPE.BOOL, "follow junctions", v => opts.FollowJunctions = (v != null))
                                              .Add('t', "threads", OPTTYPE.VALUE, "max enumeration threads parallel", v => opts.MaxThreads           = Convert.ToInt32(v))
                                              .Add('s', "same", OPTTYPE.BOOL, "report equal files (same.txt)", v => opts.reportSameFile              = true)
                                              .Add(null, "sorts", OPTTYPE.BOOL, "force sorting of entries on source side", v => opts.forceSortSource = true)
                                              .Add(null, "sortt", OPTTYPE.BOOL, "force sorting of entries on target side", v => opts.forceSortTarget = true)
                                              .Add('h', "help", OPTTYPE.BOOL, "show this help", v => showHelp = true)
                                              .GetOpts();

            IList <string> dirs = BeeOpts.Parse(
                args,
                CommandLineOpts,
                OnUnknown: (optname) => Console.Error.WriteLine($"unknow option: [{optname}]"));

            if (showHelp)
            {
                opts = null;
                PrintUsage(CommandLineOpts);
            }
            else
            {
                if (dirs.Count != 2)
                {
                    Console.Error.WriteLine("no two dir's given");
                    opts     = null;
                    showHelp = true;
                }
                else
                {
                    opts.sourceDir = dirs[0];
                    opts.targetDir = dirs[1];
                }

                if (opts != null && opts.forceSortSource)
                {
                    Console.Error.WriteLine("will sort items in source dir");
                }
                if (opts != null && opts.forceSortTarget)
                {
                    Console.Error.WriteLine("will sort items in target dir");
                }

                if (showHelp)
                {
                    Spi.BeeOpts.PrintOptions(CommandLineOpts);
                    opts = null;
                }
            }
            return(opts);
        }
Exemple #2
0
        private static void RunCompare(Opts opts, CancellationToken CtrlCEvent, TextWriter errWriter)
        {
            DateTime start = DateTime.Now;

            using (DiffWriter diffWriters = new DiffWriter())
            {
                Stats stats    = new Stats();
                var   enumOpts = new EnumOptions()
                {
                    followJunctions = opts.FollowJunctions,
                    maxDepth        = opts.Depth,
                    forceSortSource = opts.forceSortSource,
                    forceSortTarget = opts.forceSortTarget
                };

                DiffProcessing diffProcessor = new DiffProcessing(stats, diffWriters, opts.reportSameFile);

                string src = Spi.Long.GetLongFilenameNotation(opts.sourceDir.TrimEnd('\\'));
                string trg = Spi.Long.GetLongFilenameNotation(opts.targetDir.TrimEnd('\\'));

                Console.Error.WriteLine($"source: {src}\ntarget: {trg}");

                var paraCmp = new CmpDirsParallel(
                    sourceDir:       src,
                    targetDir:       trg,
                    opts:            enumOpts,
                    diffHandler:     diffProcessor.DiffCallback,
                    errorHandler:    (int RetCode, string Message) =>
                {
                    Interlocked.Increment(ref stats.Errors);
                    errWriter.WriteLine($"E: rc={RetCode}\t{Message}");
                },
                    CtrlCEvent:      CtrlCEvent,
                    maxThreadsToRun: opts.MaxThreads);
                paraCmp.Start();

                StatusLineWriter statWriter = new StatusLineWriter();
                using (Process currProc = System.Diagnostics.Process.GetCurrentProcess())
                {
                    Misc.ExecUtilWaitHandleSet(paraCmp.Finished, 2000,
                                               () => WriteProgress(stats, currProc, paraCmp.Queued, paraCmp.Running, paraCmp.Done, statWriter));
                }

                WriteStatistics(new TimeSpan(DateTime.Now.Ticks - start.Ticks), paraCmp.Done, stats);
                if (stats.Errors > 0)
                {
                    Console.Error.WriteLine($"{stats.Errors} erros occoured. please see file {opts.errorFilename}.");
                }
            }
        }