Example #1
0
      static void Main(string[] args)
      {
         if (args.Length == 0)
         {
            printUsage();
            return;
         }

         Config config = new Config();
         Inputs inputs = new Inputs();

         foreach (var arg in args)
         {
            if ("--try_harder".Equals(arg))
            {
               config.TryHarder = true;
            }
            else if ("--pure_barcode".Equals(arg))
            {
               config.PureBarcode = true;
            }
            else if ("--products_only".Equals(arg))
            {
               config.ProductsOnly = true;
            }
            else if ("--dump_results".Equals(arg))
            {
               config.DumpResults = true;
            }
            else if ("--dump_black_point".Equals(arg))
            {
               config.DumpBlackPoint = true;
            }
            else if ("--multi".Equals(arg))
            {
               config.Multi = true;
            }
            else if ("--brief".Equals(arg))
            {
               config.Brief = true;
            }
            else if ("--recursive".Equals(arg))
            {
               config.Recursive = true;
            }
            else if ("--autorotate".Equals(arg))
            {
               config.AutoRotate = true;
            }
            else if (arg.StartsWith("--crop"))
            {
               int[] crop = new int[4];
               String[] tokens = arg.Substring(7).Split(',');
               for (int i = 0; i < crop.Length; i++)
               {
                  crop[i] = int.Parse(tokens[i]);
               }
               config.Crop = crop;
            }
            else if (arg.StartsWith("--threads") && arg.Length >= 10)
            {
               int threadsCount = int.Parse(arg.Substring(10));
               if (threadsCount > 1)
               {
                  config.Threads = threadsCount;
               }
            }
            else if ("--get_from_clipboard".Equals(arg))
            {
               config.BitmapFromClipboard = (Bitmap)Clipboard.GetImage();
               if (config.BitmapFromClipboard == null)
               {
                  Console.Error.WriteLine("There is no image in the clipboard.");
                  Environment.ExitCode = 1;
                  return;
               }
               // Dummy
               inputs.addInput(".");
            }
            else if (arg.StartsWith("-"))
            {
               Console.Error.WriteLine("Unknown command line option " + arg);
               printUsage();
               return;
            }
         }

         config.Hints = buildHints(config);

         foreach (var arg in args)
         {
            if (!arg.StartsWith("--"))
            {
               addArgumentToInputs(arg, config, inputs);
            }
         }

         var threads = new Dictionary<Thread, DecodeThread>(Math.Min(config.Threads, inputs.getInputCount()));
         var decodeObjects = new List<DecodeThread>();
         for (int x = 0; x < config.Threads; x++)
         {
            var decodeThread = new DecodeThread(config, inputs);
            decodeObjects.Add(decodeThread);
            var thread = new Thread(decodeThread.run);
            threads.Add(thread, decodeThread);
            thread.Start();
         }

         int successful = 0;
         foreach (var thread in threads.Keys)
         {
            thread.Join();
            successful += threads[thread].getSuccessful();
         }

         var completeResult = String.Empty;
         foreach (var decodeObject in decodeObjects)
         {
            completeResult += decodeObject.ResultString;
            completeResult += Environment.NewLine;
         }
         Clipboard.SetText(completeResult);

         int total = inputs.getInputCount();
         if (total > 1)
         {
            Console.Out.WriteLine("\nDecoded " + successful + " files out of " + total +
                " successfully (" + (successful * 100 / total) + "%)\n");
         }
      }
Example #2
0
 // Build all the inputs up front into a single flat list, so the threads can atomically pull
 // paths/URLs off the queue.
 private static void addArgumentToInputs(String argument, Config config, Inputs inputs)
 {
    if (Directory.Exists(argument))
    {
       foreach (var singleFile in Directory.EnumerateFiles(argument))
       {
          String filename = singleFile.ToLower(CultureInfo.InvariantCulture);
          // Skip hidden files and directories (e.g. svn stuff).)
          if (filename.StartsWith("."))
          {
             continue;
          }
          // Skip text files and the results of dumping the black point.
          if (filename.EndsWith(".txt") || filename.Contains(".mono.png"))
          {
             continue;
          }
          inputs.addInput(singleFile);
       }
       // Recurse on nested directories if requested, otherwise skip them.
       if (config.Recursive)
       {
          foreach (var dirName in Directory.EnumerateDirectories(argument))
          {
             addArgumentToInputs(dirName, config, inputs);
          }
       }
    }
    else
    {
       inputs.addInput(argument);
    }
 }
Example #3
0
 public DecodeThread(Config config, Inputs inputs)
 {
    this.config = config;
    this.inputs = inputs;
 }
Example #4
0
 public DecodeThread(Config config, Inputs inputs)
 {
     this.config = config;
     this.inputs = inputs;
 }
Example #5
0
        static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                printUsage();
                return;
            }

            Config config = new Config();
            Inputs inputs = new Inputs();
            var    copyResultToClipboard = false;

            foreach (var arg in args)
            {
                if ("--try_harder".Equals(arg))
                {
                    config.TryHarder = true;
                }
                else if ("--pure_barcode".Equals(arg))
                {
                    config.PureBarcode = true;
                }
                else if ("--products_only".Equals(arg))
                {
                    config.ProductsOnly = true;
                }
                else if ("--dump_results".Equals(arg))
                {
                    config.DumpResults = true;
                }
                else if ("--dump_black_point".Equals(arg))
                {
                    config.DumpBlackPoint = true;
                }
                else if ("--multi".Equals(arg))
                {
                    config.Multi = true;
                }
                else if ("--brief".Equals(arg))
                {
                    config.Brief = true;
                }
                else if ("--recursive".Equals(arg))
                {
                    config.Recursive = true;
                }
                else if ("--autorotate".Equals(arg))
                {
                    config.AutoRotate = true;
                }
                else if (arg.StartsWith("--crop"))
                {
                    int[]    crop   = new int[4];
                    String[] tokens = arg.Substring(7).Split(',');
                    for (int i = 0; i < crop.Length; i++)
                    {
                        crop[i] = int.Parse(tokens[i]);
                    }
                    config.Crop = crop;
                }
                else if (arg.StartsWith("--threads") && arg.Length >= 10)
                {
                    int threadsCount = int.Parse(arg.Substring(10));
                    if (threadsCount > 1)
                    {
                        config.Threads = threadsCount;
                    }
                }
                else if ("--get_from_clipboard".Equals(arg))
                {
                    config.BitmapFromClipboard = (Bitmap)Clipboard.GetImage();
                    if (config.BitmapFromClipboard == null)
                    {
                        Console.Error.WriteLine("There is no image in the clipboard.");
                        Environment.ExitCode = 1;
                        return;
                    }
                    // Dummy
                    inputs.addInput(".");
                }
                else if ("--copy_to_clipboard".Equals(arg))
                {
                    copyResultToClipboard = true;
                }
                else if (arg.StartsWith("-"))
                {
                    Console.Error.WriteLine("Unknown command line option " + arg);
                    printUsage();
                    return;
                }
            }

            config.Hints = buildHints(config);

            foreach (var arg in args)
            {
                if (!arg.StartsWith("--"))
                {
                    addArgumentToInputs(arg, config, inputs);
                }
            }

            var threads       = new Dictionary <Thread, DecodeThread>(Math.Min(config.Threads, inputs.getInputCount()));
            var decodeObjects = new List <DecodeThread>();

            for (int x = 0; x < config.Threads; x++)
            {
                var decodeThread = new DecodeThread(config, inputs);
                decodeObjects.Add(decodeThread);
                var thread = new Thread(decodeThread.run);
                threads.Add(thread, decodeThread);
                thread.Start();
            }

            int successful = 0;

            foreach (var thread in threads.Keys)
            {
                thread.Join();
                successful += threads[thread].getSuccessful();
            }

            if (copyResultToClipboard)
            {
                var completeResult = String.Empty;
                foreach (var decodeObject in decodeObjects)
                {
                    completeResult += decodeObject.ResultString;
                    completeResult += Environment.NewLine;
                }
                Clipboard.SetText(completeResult);
            }

            int total = inputs.getInputCount();

            if (total > 1)
            {
                Console.Out.WriteLine("\nDecoded " + successful + " files out of " + total +
                                      " successfully (" + (successful * 100 / total) + "%)\n");
            }
        }
Example #6
0
      static void Main(string[] args)
      {
         if (args.Length == 0)
         {
            printUsage();
            return;
         }

         Config config = new Config();
         Inputs inputs = new Inputs();


         foreach (var arg in args)
         {
            if ("--try_harder".Equals(arg))
            {
               config.TryHarder = true;
            }
            else if ("--pure_barcode".Equals(arg))
            {
               config.PureBarcode = true;
            }
            else if ("--products_only".Equals(arg))
            {
               config.ProductsOnly = true;
            }
            else if ("--dump_results".Equals(arg))
            {
               config.DumpResults = true;
            }
            else if ("--dump_black_point".Equals(arg))
            {
               config.DumpBlackPoint = true;
            }
            else if ("--multi".Equals(arg))
            {
               config.Multi = true;
            }
            else if ("--brief".Equals(arg))
            {
               config.Brief = true;
            }
            else if ("--recursive".Equals(arg))
            {
               config.Recursive = true;
            }
            else if (arg.StartsWith("--crop"))
            {
               int[] crop = new int[4];
               String[] tokens = arg.Substring(7).Split(',');
               for (int i = 0; i < crop.Length; i++)
               {
                  crop[i] = int.Parse(tokens[i]);
               }
               config.Crop = crop;
            }
            else if (arg.StartsWith("--threads") && arg.Length >= 10)
            {
               int threadsCount = int.Parse(arg.Substring(10));
               if (threadsCount > 1)
               {
                  config.Threads = threadsCount;
               }
            }
            else if (arg.StartsWith("-"))
            {
               Console.Error.WriteLine("Unknown command line option " + arg);
               printUsage();
               return;
            }
         }

         config.Hints = buildHints(config);

         foreach (var arg in args)
         {
            if (!arg.StartsWith("--"))
            {
               addArgumentToInputs(arg, config, inputs);
            }
         }

         var threads = new Dictionary<Thread, DecodeThread>(config.Threads);
         for (int x = 0; x < config.Threads; x++)
         {
            var decodeThread = new DecodeThread(config, inputs);
            var thread = new Thread(decodeThread.run);
            threads.Add(thread, decodeThread);
            thread.Start();
         }

         int successful = 0;
         foreach (var thread in threads.Keys)
         {
            thread.Join();
            successful += threads[thread].getSuccessful();
         }
         int total = inputs.getInputCount();
         if (total > 1)
         {
            Console.Out.WriteLine("\nDecoded " + successful + " files out of " + total +
                " successfully (" + (successful * 100 / total) + "%)\n");
         }
      }