Ejemplo n.º 1
0
        public void ParseArguments(string[] args)
        {
            string[] arguments = args.Skip(1).ToArray();

            if (arguments.Length < 1)
            {
                return;
            }

            string joined = string.Join(" ", arguments);

            log.DebugFormat("Command line arguments:{0}", string.Join(" ", arguments));

            try
            {
                if (arguments.Length == 1)
                {
                    if (arguments[0].Trim() == "-help" || arguments[0].Trim() == "-h")
                    {
                        PrintUsage();
                    }
                    else if (File.Exists(arguments[0]))
                    {
                        // Special case for dragging a file on kinovea.exe icon.
                        ScreenDescriptionPlayback sdp = new ScreenDescriptionPlayback();
                        sdp.FullPath = arguments[0];
                        LaunchSettingsManager.AddScreenDescription(sdp);
                    }
                }
                else
                {
                    CommandLineArgumentParser.ParseArguments(arguments);

                    // TODO: check coherence.
                    ScreenDescriptionPlayback sdp = new ScreenDescriptionPlayback();
                    sdp.FullPath = CommandLineArgumentParser.GetParamValue("-file");
                    int speed = int.Parse(CommandLineArgumentParser.GetParamValue("-speed"));
                    speed = Math.Max(Math.Min(200, speed), 1);
                    sdp.SpeedPercentage = speed;
                    sdp.Stretch         = CommandLineArgumentParser.IsSwitchOn("-stretch");

                    LaunchSettingsManager.AddScreenDescription(sdp);
                    LaunchSettingsManager.ShowExplorer = !CommandLineArgumentParser.IsSwitchOn("-noexp");
                }
            }
            catch (CommandLineArgumentException e)
            {
                log.Error("Command line arguments couldn't be parsed.");
                log.Error(e.Message);
                PrintUsage();
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Parse command line options
 /// </summary>
 /// <param name="args">arguments from main method</param>
 private static void ParseArguments(string[] args)
 {
     //
     // Handle the special case "-help" separately
     //
     if (args.Length == 1 && args[0].Trim() == "-help")
     {
         PrintUsage();
     }
     else
     {
         CommandLineArgumentParser.ParseArguments(args);
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Parses the passed command line parameters and populates the static properties used as global parameters of this application.
        /// </summary>
        /// <param name="args">String array containing the command line parameters.</param>
        public static void ParseCommandLineArguments(string[] args)
        {
            IsGui = false;
            CommandLineArgumentParser.ParseArguments(args);
            if (CommandLineArgumentParser.UniqueParameter != null)
            {
                if (CommandLineArgumentParser.UniqueParameter == "-gui")
                {
                    IsGui = true;
                }

                if (CommandLineArgumentParser.UniqueParameter == "-help")
                {
                    IsHelp = true;
                }
            }

            VirtualPort          = CommandLineArgumentParser.GetParamValue("-tx");
            RealPort             = CommandLineArgumentParser.GetParamValue("-rx");
            OutputFileName       = CommandLineArgumentParser.GetParamValue("-output");
            TransmissionBaudRate = int.Parse(CommandLineArgumentParser.GetParamValue("-baud"));
            BytesPerLine         = int.Parse(CommandLineArgumentParser.GetParamValue("-bytesPerLine"));
            TransmissionParity   = CommandLineArgumentParser.GetParamValue <Parity>(
                "-parity",
                new Dictionary <string, Parity>()
            {
                { "even", Parity.Even },
                { "odd", Parity.Odd },
                { "none", Parity.None }
            });
            TransmissionStopBits = CommandLineArgumentParser.GetParamValue <StopBits>(
                "-stopbit",
                Value2StopBits);
            TransmissionDataBits = CommandLineArgumentParser.GetParamValue <int>(
                "-data",
                new Dictionary <string, int>()
            {
                { "7", 7 },
                { "8", 8 }
            });
            IsOnlyHex       = CommandLineArgumentParser.IsSwitchOn("-onlyHex");
            IsOnlyAscii     = CommandLineArgumentParser.IsSwitchOn("-onlyAscii");
            IsShowTime      = CommandLineArgumentParser.IsSwitchOn("-time");
            IsShowCollapsed = CommandLineArgumentParser.IsSwitchOn("-collapsed");
            Mode            = CommandLineArgumentParser.IsSwitchOn("-ycable") ? SnifferMode.YCable : SnifferMode.Simulate;
        }
        public void ParseArguments(string[] args)
        {
            string[] arguments = args.Skip(1).ToArray();

            if (arguments.Length < 1)
            {
                return;
            }

            string joined = string.Join(" ", arguments);

            log.DebugFormat("Command line arguments:{0}", string.Join(" ", arguments));

            try
            {
                if (arguments.Length == 1)
                {
                    if (arguments[0].Trim() == "-help" || arguments[0].Trim() == "-h")
                    {
                        PrintUsage();
                    }
                    else if (File.Exists(arguments[0]))
                    {
                        // Special case for dragging a file on top of the program icon or starting with a workspace.
                        if (Path.GetExtension(arguments[0]).ToLower() == ".xml")
                        {
                            Workspace workspace = new Workspace();
                            bool      loaded    = workspace.Load(arguments[0]);
                            if (loaded)
                            {
                                foreach (IScreenDescription screen in workspace.Screens)
                                {
                                    LaunchSettingsManager.AddScreenDescription(screen);
                                }
                            }
                        }
                        else
                        {
                            // Assume video and try to load it in a single screen.
                            ScreenDescriptionPlayback sdp = new ScreenDescriptionPlayback();
                            sdp.FullPath = arguments[0];
                            sdp.Autoplay = true;
                            sdp.Stretch  = true;
                            LaunchSettingsManager.AddScreenDescription(sdp);
                        }
                    }
                }
                else
                {
                    CommandLineArgumentParser.ParseArguments(arguments);

                    string name         = CommandLineArgumentParser.GetParamValue("-name");
                    bool   hideExplorer = CommandLineArgumentParser.IsSwitchOn("-hideExplorer");
                    string workspace    = CommandLineArgumentParser.GetParamValue("-workspace");
                    string video        = CommandLineArgumentParser.GetParamValue("-video");
                    string speed        = CommandLineArgumentParser.GetParamValue("-speed");
                    bool   stretch      = CommandLineArgumentParser.IsSwitchOn("-stretch");

                    // General program state.
                    if (!string.IsNullOrEmpty(name))
                    {
                        LaunchSettingsManager.Name = name;
                    }

                    LaunchSettingsManager.ShowExplorer = !hideExplorer;

                    // Workspace.
                    if (!string.IsNullOrEmpty(workspace))
                    {
                        Workspace w      = new Workspace();
                        bool      loaded = w.Load(workspace);
                        if (loaded)
                        {
                            foreach (IScreenDescription screen in w.Screens)
                            {
                                LaunchSettingsManager.AddScreenDescription(screen);
                            }
                        }
                    }
                    else if (!string.IsNullOrEmpty(video))
                    {
                        // Manual description.
                        ScreenDescriptionPlayback sdp = new ScreenDescriptionPlayback();
                        sdp.FullPath = video;

                        double speedValue;
                        bool   parsed = double.TryParse(speed, NumberStyles.Any, CultureInfo.InvariantCulture, out speedValue);
                        if (parsed)
                        {
                            speedValue = Math.Max(1, Math.Min(200, speedValue));
                        }
                        else
                        {
                            speedValue = 100;
                        }

                        sdp.SpeedPercentage = speedValue;
                        sdp.Stretch         = stretch;

                        LaunchSettingsManager.AddScreenDescription(sdp);
                    }
                }
            }
            catch (CommandLineArgumentException e)
            {
                log.Error("Command line arguments couldn't be parsed.");
                log.Error(e.Message);
                PrintUsage();
            }
        }
        public void ParseArguments(string[] _args)
        {
            // Log argumets.
            if (_args.Length > 1)
            {
                log.Debug("Command line arguments:");
                foreach (string arg in _args)
                {
                    log.Debug(arg);
                }
            }

            // Remove first argument (name of the executable) before parsing.
            string[] args = new string[_args.Length - 1];
            for (int i = 1; i < _args.Length; i++)
            {
                args[i - 1] = _args[i];
            }

            try
            {
                // Check for the special case where the only argument is a filename.
                // this happens when you drag a video on kinovea.exe
                if (args.Length == 1)
                {
                    if (File.Exists(args[0]))
                    {
                        m_InputFile = args[0];
                    }
                }
                else if (args.Length == 1 && (args[0].Trim() == "-help" || args[0].Trim() == "-h"))
                {
                    // Check for the special parameter -help or -h,
                    // and then output info on supported params.
                    PrintUsage();
                }
                else
                {
                    CommandLineArgumentParser.ParseArguments(args);

                    // Reparse the types, (we do that in the try catch block in case it fails.)
                    m_InputFile        = CommandLineArgumentParser.GetParamValue("-file");
                    m_iSpeedPercentage = int.Parse(CommandLineArgumentParser.GetParamValue("-speed"));
                    if (m_iSpeedPercentage > 200)
                    {
                        m_iSpeedPercentage = 200;
                    }
                    if (m_iSpeedPercentage < 1)
                    {
                        m_iSpeedPercentage = 1;
                    }
                    m_bStretchImage = CommandLineArgumentParser.IsSwitchOn("-stretch");
                    m_bHideExplorer = CommandLineArgumentParser.IsSwitchOn("-noexp");
                }
            }
            catch (CommandLineArgumentException e)
            {
                log.Error("Command line arguments couldn't be parsed.");
                log.Error(e.Message);
                PrintUsage();
            }

            // Validate parameters.
            // Here maybe we should check for the coherence of what the user entered.
            // for exemple if he entered a -speed but no -file...

            m_bParametersParsed = true;
        }
Ejemplo n.º 6
0
        public static IList <CommandLineArgument> GetArguments(this CommandLineArgumentParser paser, string args)
        {
            var arguments = paser.ParseArguments(args);

            return(arguments.Values.ToArray());
        }
Ejemplo n.º 7
0
        public static CommandLineArgument GetSingleArgument(this CommandLineArgumentParser paser, string args)
        {
            var arguments = paser.ParseArguments(args);

            return(arguments.Values.Single(arg => arg.Index == 0));
        }