コード例 #1
0
        public static SettingsData LoadSettings(XmlNode settingsNode, Context context)
        {
            SettingsData data = new SettingsData();

            data.Context = context;

            PropertyInfo[] properties = typeof(SettingsData).GetProperties();
            foreach (PropertyInfo property in properties)
            {
                Type    type  = property.PropertyType;
                string  xpath = "add[@key='" + property.Name + "']";
                XmlNode node  = settingsNode.SelectSingleNode(xpath);

                if (node != null)
                {
                    string strValue = node.Attributes["value"].InnerText;
                    object value    = 0;
                    bool   isSet    = true;

                    if (type == typeof(string))
                    {
                        if (property.Name.ToLower().Trim().StartsWith("filepath"))
                        {
                            value = data.GetFilepath(strValue);
                        }
                        else
                        {
                            value = strValue;
                        }
                    }
                    else if (type == typeof(int))
                    {
                        value = Utilities.ParseInt(strValue);
                    }
                    else if (type == typeof(bool))
                    {
                        value = Utilities.ParseBool(strValue);
                    }
                    else if (type == typeof(byte[]))
                    {
                        value = Utilities.GetBytesFromHexString(strValue.Replace("0x", ""));
                    }
                    else if (type == typeof(Enum))
                    {
                        value = ISOHelper.GetSector(strValue, context);
                    }
                    else
                    {
                        isSet = false;
                    }

                    if (isSet)
                    {
                        property.SetValue(data, value, null);
                    }
                }
            }

            data.TotalEventSize = data.EventSize * data.NumEvents;
            data.WorldConditionalsPointerRAMLocation     = ISOHelper.GetRamOffset(data.WorldConditionalsPointerSector, context) + data.WorldConditionalsPointerOffset;
            data.BattleConditionalsLimitPatchRAMLocation = ISOHelper.GetRamOffset(data.BattleConditionalsLimitPatchSector, context) + data.BattleConditionalsLimitPatchOffset;
            data.ScenariosRAMLocation             = ISOHelper.GetRamOffset(data.ScenariosSector, context) + data.ScenariosOffset;
            data.WorldConditionalsCalcRAMLocation = ISOHelper.GetRamOffset(data.WorldConditionalsSector, context) + data.WorldConditionalsOffset;

            return(data);
        }