Example #1
0
        static FlagsManager()
        {
            try {
                FlagTypeData flagTypeData = null;

                string[] lines;

                if (File.Exists("def.txt"))
                {
                    lines = File.ReadAllLines("def.txt");
                }
                else
                {
                    lines = TextFileHelper.ReadAllLines(ApplicationManager.GetResource("def.txt")).ToArray();
                }

                foreach (var line in lines)
                {
                    if (String.IsNullOrEmpty(line))
                    {
                        continue;
                    }

                    FlagDataProperty property = FlagDataProperty.None;

                    if (line.StartsWith("["))
                    {
                        var name = line.Trim('[', ']');

                        if (flagTypeData != null)
                        {
                            _flags[flagTypeData.Name] = flagTypeData;
                        }

                        flagTypeData = new FlagTypeData(name);
                    }
                    else if (flagTypeData != null)
                    {
                        var    data        = line.Split('\t');
                        var    name        = data[0];
                        long   value       = 0;
                        string description = null;

                        if (data[1] == "auto")
                        {
                            if (flagTypeData.LatestValue == 0)
                            {
                                value = 1;
                            }
                            else
                            {
                                value = flagTypeData.LatestValue << 1;
                            }

                            flagTypeData.LatestValue = value;
                        }
                        else if (!char.IsDigit(data[1][0]) && !data[1].StartsWith("0x") && !data[1].StartsWith("0X"))
                        {
                            try {
                                Condition cond      = ConditionLogic.GetCondition(data[1]);
                                var       predicate = cond.ToLong(flagTypeData);
                                flagTypeData.LatestValue = value = predicate();
                            }
                            catch {
                                ErrorHandler.HandleException("Unable to parse the flag definition for " + line);
                            }
                        }
                        else
                        {
                            flagTypeData.LatestValue = value = FormatConverters.LongOrHexConverter(data[1]);
                        }

                        if (data.Length > 2)
                        {
                            description = data[2];
                        }

                        if (data.Length > 3)
                        {
                            if (data[3] == "hide")
                            {
                                property |= FlagDataProperty.Hide;
                            }
                        }

                        flagTypeData.AddValue(new FlagData(name, value, description)
                        {
                            DataFlag = property
                        });
                    }
                }

                if (flagTypeData != null)
                {
                    _flags[flagTypeData.Name] = flagTypeData;
                }
            }
            catch (Exception err) {
                ErrorHandler.HandleException(err);
            }
        }
Example #2
0
        public static void AddValue(FlagTypeData flagData, string key)
        {
            long value = flagData.LatestValue = flagData.LatestValue << 1;

            flagData.AddValue(new FlagData(key, value, null));
        }