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();
            }
        }
        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();
            }
        }