Beispiel #1
0
        /** Add an option to the optionlist with the given values. */
        public static void Add(OptionList optionList, string name, int value, string strValue)
        {
            #if DEBUG
            Console.WriteLine("Option.Add");
            #endif
            if (optionList.list == null)
                optionList.list = new ArrayList();
            if (optionList.datalist == null)
                optionList.datalist = new Dictionary<string, OptionStruct>();

            if (optionList.datalist.ContainsKey(name))
            {
                OptionStruct option = optionList.datalist[name];
                if (Variables.debug_level > 0)
                    Debug.PrintMessage("Option {0} already in optionlist\n", name);
                option.value = value;
                option.stringValue = strValue;
            }
            else
            {
                OptionStruct newOption = new OptionStruct();
                newOption.name = name;
                newOption.value = value;
                newOption.stringValue = strValue;
                optionList.list.Add(newOption);

                optionList.datalist.Clear();
                foreach (OptionStruct option in optionList.list)
                {
                    if (!optionList.datalist.ContainsKey(option.name))
                        optionList.datalist.Add(option.name, option);
                }
            }
        }
Beispiel #2
0
        /** Load a file containing name - value pairs into
         * the specified array. */
        public static void LoadOptFile(string filename, ref OptionList optionList, bool sort)
        {
            #if DEBUG
            Console.WriteLine("FileHelper.LoadOptFile");
            #endif
            optionList = new OptionList();
            string path = FindSupportFile(filename, false);
            string[] lines = File.ReadAllLines(path);
            foreach (string line in lines)
            {
                string optName = null, optValue = null;
                if (ParseOptLine(line, ref optName, ref optValue))
                {
                    OptionStruct option = new OptionStruct();
                    option.name = optName;
                    if (optName.StartsWith("string_"))
                    {
                        option.stringValue = optValue;
                        option.value = -1;
                    }
                    else
                    {
                        option.stringValue = null;
                        option.value = Int32.Parse(optValue);
                    }
                    optionList.list.Add(option);

                    if ((optName.EndsWith("_unix") && Variables.os_is_unix) ||
                        (optName.EndsWith("_win32") && !Variables.os_is_unix))
                    {
                        option.name = optName.Remove(optName.IndexOf(Variables.os_is_unix ? "_unix" : "_win32"));
                        optionList.list.Add(option);
                    }
                }
            }

            if (sort)
            {
                OptionCompare comparer = new OptionCompare();
                optionList.list.Sort(comparer);
            }

            foreach (OptionStruct option in optionList.list)
            {
                if (!optionList.datalist.ContainsKey(option.name))
                    optionList.datalist.Add(option.name, option);
            }
        }