コード例 #1
0
ファイル: Options.cs プロジェクト: FSofTlpz/GmTool
        /// <summary>
        /// Auswertung der Optionen
        /// </summary>
        /// <param name="args"></param>
        public void Evaluate(string[] args)
        {
            if (args == null)
            {
                return;
            }
            List <string> InputArray_Tmp = new List <string>();

            try {
                cmd.Parse(args);

                foreach (MyOptions opt in Enum.GetValues(typeof(MyOptions)))  // jede denkbare Option testen
                {
                    int    optcount = cmd.OptionAssignment((int)opt);         // Wie oft wurde diese Option verwendet?
                    string arg;
                    if (optcount > 0)
                    {
                        switch (opt)
                        {
                        case MyOptions.Input:
                            for (int i = 0; i < optcount; i++)
                            {
                                InputArray_Tmp.Add(cmd.StringValue((int)opt, i).Trim());
                            }
                            break;

                        case MyOptions.InputWithSubdirs:
                            if (cmd.ArgIsUsed((int)opt))
                            {
                                InputWithSubdirs = cmd.BooleanValue((int)opt);
                            }
                            else
                            {
                                InputWithSubdirs = true;
                            }
                            break;

                        case MyOptions.InputListfile:
                            InputArray_Tmp.AddRange(System.IO.File.ReadAllLines(cmd.StringValue((int)opt)));
                            for (int i = InputArray_Tmp.Count - 1; i >= 0; i--)
                            {
                                InputArray_Tmp[i] = InputArray_Tmp[i].Trim();
                                if (InputArray_Tmp[i].Length == 0)
                                {
                                    InputArray_Tmp.RemoveAt(i);
                                }
                            }
                            break;

                        case MyOptions.Output:
                            Output = cmd.StringValue((int)opt).Trim();
                            break;

                        case MyOptions.OutputOverwrite:
                            if (cmd.ArgIsUsed((int)opt))
                            {
                                OutputOverwrite = cmd.BooleanValue((int)opt);
                            }
                            else
                            {
                                OutputOverwrite = true;
                            }
                            break;

                        case MyOptions.Info:
                            if (cmd.ArgIsUsed((int)opt))
                            {
                                switch (cmd.UnsignedIntegerValue((int)opt))
                                {
                                case 0: ToDo = ToDoType.Info; break;

                                case 1: ToDo = ToDoType.LongInfo; break;

                                case 2: ToDo = ToDoType.ExtLongInfo; break;

                                default: ToDo = ToDoType.VeryLongInfo; break;
                                }
                            }
                            else
                            {
                                ToDo = ToDoType.Info;
                            }
                            break;

                        case MyOptions.Split:
                            if (cmd.ArgIsUsed((int)opt))
                            {
                                arg = cmd.StringValue((int)opt);
                                if (arg == "r")
                                {
                                    ToDo = ToDoType.SplitRecursive;
                                }
                                else if (arg == "j")
                                {
                                    ToDo = ToDoType.SplitJoin;
                                }
                                else if (arg == "rj" || arg == "jr")
                                {
                                    ToDo = ToDoType.SplitRecursiveJoin;
                                }
                            }
                            else
                            {
                                ToDo = ToDoType.Split;
                            }
                            break;

                        case MyOptions.CreateFiles4Mapsource:
                            for (int i = 0; i < optcount; i++)
                            {
                                if (cmd.ArgIsUsed((int)opt, i))
                                {
                                    arg = cmd.StringValue((int)opt, i);
                                    if (!string.IsNullOrEmpty(arg))
                                    {
                                        if (arg.StartsWith("pid:"))
                                        {
                                            PID.Set(InterpretUInt(arg));
                                        }
                                        else if (arg.StartsWith("fid:"))
                                        {
                                            FID.Set(InterpretUInt(arg));
                                        }
                                        else if (arg.StartsWith("cp:"))
                                        {
                                            Codepage.Set(InterpretUInt(arg));
                                            //} else if (arg.StartsWith("ovno:")) {
                                            //   MapsourceOverviewNo.Set(InterpretUInt(arg));
                                        }
                                        else if (arg.StartsWith("ov:"))
                                        {
                                            MapsourceOverviewfile.Set(arg.Substring(3));
                                        }
                                        else if (arg.StartsWith("typ:"))
                                        {
                                            MapsourceTYPfile.Set(arg.Substring(4));
                                        }
                                        else if (arg.StartsWith("tdb:"))
                                        {
                                            MapsourceTDBfile.Set(arg.Substring(4));
                                        }
                                        else if (arg.StartsWith("mdx:"))
                                        {
                                            MapsourceMDXfile.Set(arg.Substring(4));
                                        }
                                        else if (arg.StartsWith("mdr:"))
                                        {
                                            MapsourceMDRfile.Set(arg.Substring(4));
                                        }
                                        else if (arg.StartsWith("tdb:"))
                                        {
                                            MapsourceTDBfile.Set(arg.Substring(4));
                                        }
                                        else if (arg.StartsWith("mindim:"))
                                        {
                                            MapsourceMinDimension.Set(InterpretUInt(arg));
                                        }
                                        else if (arg.StartsWith("points:"))
                                        {
                                            InterpretTypes(arg, MapsourceOVPointtypes);
                                        }
                                        else if (arg.StartsWith("lines:"))
                                        {
                                            InterpretTypes(arg, MapsourceOVLinetypes);
                                        }
                                        else if (arg.StartsWith("areas:"))
                                        {
                                            InterpretTypes(arg, MapsourceOVAreatypes);
                                        }
                                        else if (arg == "noov")
                                        {
                                            MapsourceNoOverviewfile.Set(true);
                                        }
                                        else if (arg == "notyp")
                                        {
                                            MapsourceNoTYPfile.Set(true);
                                        }
                                        else if (arg == "nomdx")
                                        {
                                            MapsourceNoMDXfile.Set(true);
                                        }
                                        else if (arg == "nomdr")
                                        {
                                            MapsourceNoMDRfile.Set(true);
                                        }
                                        else if (arg == "notdb")
                                        {
                                            MapsourceNoTDBfile.Set(true);
                                        }
                                        else if (arg == "noinst")
                                        {
                                            MapsourceNoInstfiles.Set(true);
                                        }
                                        else
                                        {
                                            throw new Exception("unbekanntes Argument: " + arg);
                                        }
                                    }
                                }
                            }
                            ToDo = ToDoType.CreateFiles4Mapsource;
                            break;

                        case MyOptions.Join:
                            if (cmd.ArgIsUsed((int)opt))
                            {
                                arg = cmd.StringValue((int)opt);
                                if (arg == "device")
                                {
                                    ToDo = ToDoType.JoinDevice;
                                }
                                else if (arg == "tile")
                                {
                                    ToDo = ToDoType.JoinTile;
                                }
                            }
                            else
                            {
                                ToDo = ToDoType.Join;
                            }
                            break;

                        case MyOptions.AnalyzingTypes:
                            switch (cmd.UnsignedIntegerValue((int)opt))
                            {
                            case 1: ToDo = ToDoType.AnalyzingTypesLong; break;

                            default: ToDo = ToDoType.AnalyzingTypes; break;
                            }
                            break;


                        case MyOptions.SetPID:
                            PID.Set((int)cmd.UnsignedIntegerValue((int)opt));
                            break;

                        case MyOptions.SetFID:
                            FID.Set((int)cmd.UnsignedIntegerValue((int)opt));
                            break;

                        case MyOptions.SetCodepage:
                            Codepage.Set((int)cmd.UnsignedIntegerValue((int)opt));
                            break;

                        case MyOptions.SetTDBCopyright:
                            for (int j = 0; j < optcount; j++)
                            {
                                arg = cmd.StringValue((int)opt, j);
                                if (arg.Length < 3)
                                {
                                    throw new Exception("Falscher Aufbau der Copyright-Option '" + arg + "'");
                                }
                                else
                                {
                                    switch (arg[0])
                                    {
                                    case 'S':
                                        TDBCopyrightCodes.Add(new Property((int)GarminCore.Files.File_TDB.SegmentedCopyright.Segment.CopyrightCodes.SourceInformation, true));
                                        break;

                                    case 'C':
                                        TDBCopyrightCodes.Add(new Property((int)GarminCore.Files.File_TDB.SegmentedCopyright.Segment.CopyrightCodes.CopyrightInformation, true));
                                        break;

                                    case '*':
                                        TDBCopyrightCodes.Add(new Property((int)GarminCore.Files.File_TDB.SegmentedCopyright.Segment.CopyrightCodes.Unknown, true));
                                        break;

                                    default:
                                        throw new Exception("Falsche Angabe in der Copyright-Option: '" + arg[0] + "'");
                                    }

                                    switch (arg[1])
                                    {
                                    case 'I':
                                        TDBCopyrightWhereCodes.Add(new Property((int)GarminCore.Files.File_TDB.SegmentedCopyright.Segment.WhereCodes.ProductInformation, true));
                                        break;

                                    case 'P':
                                        TDBCopyrightWhereCodes.Add(new Property((int)GarminCore.Files.File_TDB.SegmentedCopyright.Segment.WhereCodes.Printing, true));
                                        break;

                                    case 'E':
                                        TDBCopyrightWhereCodes.Add(new Property((int)GarminCore.Files.File_TDB.SegmentedCopyright.Segment.WhereCodes.ProductInformationAndPrinting, true));
                                        break;

                                    case '*':
                                        TDBCopyrightWhereCodes.Add(new Property((int)GarminCore.Files.File_TDB.SegmentedCopyright.Segment.WhereCodes.Unknown, true));
                                        break;

                                    default:
                                        throw new Exception("Falsche Angabe in der Copyright-Option: '" + arg[1] + "'");
                                    }

                                    switch (arg[2])
                                    {
                                    case 'N':
                                        string sText = arg.Substring(3).Trim();
                                        if (sText.Length >= 2)
                                        {
                                            if (sText[0] == '"' && sText[sText.Length - 1] == '"')
                                            {
                                                sText = sText.Substring(1, sText.Length - 2);
                                            }
                                        }
                                        TDBCopyrightText.Add(new Property(sText, true));
                                        break;

                                    case 'D':
                                        TDBCopyrightText.Add(new Property(null, false));
                                        break;

                                    case '*':
                                        TDBCopyrightText.Add(new Property(null, true));
                                        break;

                                    default:
                                        throw new Exception("Falsche Angabe in der Copyright-Option: '" + arg[1] + "'");
                                    }
                                }
                            }
                            break;

                        case MyOptions.SetDescription:
                            Description.Set(cmd.StringValue((int)opt));
                            break;

                        case MyOptions.SetTransparent:
                            Transparent.Set(cmd.BooleanValue((int)opt) ? 1 : 0);
                            break;

                        case MyOptions.SetPriority:
                            Priority.Set((int)cmd.UnsignedIntegerValue((int)opt));
                            break;

                        case MyOptions.SetMapFamilyName:
                            MapFamilyName.Set(cmd.StringValue((int)opt));
                            break;

                        case MyOptions.SetMapSeriesName:
                            MapSeriesName.Set(cmd.StringValue((int)opt));
                            break;

                        case MyOptions.SetVersion:
                            Version.Set((int)cmd.UnsignedIntegerValue((int)opt));
                            break;

                        case MyOptions.SetRoutable:
                            Routable.Set((int)cmd.UnsignedIntegerValue((int)opt));
                            break;

                        case MyOptions.SetHighestRoutable:
                            HighestRoutable.Set((int)cmd.UnsignedIntegerValue((int)opt));
                            break;

                        case MyOptions.SetHasDEM:
                            HasDEM.Set((int)cmd.UnsignedIntegerValue((int)opt));
                            break;

                        case MyOptions.SetHasProfile:
                            HasProfile.Set((int)cmd.UnsignedIntegerValue((int)opt));
                            break;

                        case MyOptions.SetMaxCoordBits4Overview:
                            MaxCoordBits4Overview.Set((int)cmd.UnsignedIntegerValue((int)opt));
                            break;

                        case MyOptions.RefreshTDB:
                            ToDo = ToDoType.RefreshTDB;
                            break;

                        case MyOptions.NewTypfile:
                            NewTypfile.Set(cmd.StringValue((int)opt));
                            ToDo = ToDoType.SetNewTypfile;
                            break;

                        case MyOptions.Help:
                            ShowHelp();
                            break;
                        }
                    }
                }

                //TestParameter = new string[cmd.Parameters.Count];
                //cmd.Parameters.CopyTo(TestParameter);

                if (cmd.Parameters.Count > 0)
                {
                    throw new Exception("Es sind keine Argumente sondern nur Optionen erlaubt.");
                }

                Input = new string[InputArray_Tmp.Count];
                InputArray_Tmp.CopyTo(Input);
            } catch (Exception ex) {
                Console.Error.WriteLine(ex.Message);
                ShowHelp();
                throw new Exception("Fehler beim Ermitteln oder Anwenden der Programmoptionen.");
            }
        }