示例#1
0
        public override void LoadFromXml(XElement element)
        {
            WowVersion             = element.Element("WowVersion").Value;
            AutoStart              = GetElementValue <bool>(element.Element("AutoStart"));
            WowDelay               = GetElementValue <int>(element.Element("WowDelay"));
            HBDelay                = GetElementValue(element.Element("HBDelay"), 10);
            LoginDelay             = GetElementValue(element.Element("LoginDelay"), 3);
            UseDarkStyle           = GetElementValue(element.Element("UseDarkStyle"), true);
            CheckRealmStatus       = GetElementValue(element.Element("CheckRealmStatus"), false);
            CheckHbResponsiveness  = GetElementValue(element.Element("CheckHbResponsiveness"), true);
            CheckWowResponsiveness = GetElementValue(element.Element("CheckWowResponsiveness"), true);
            AutoUpdateHB           = GetElementValue(element.Element("AutoUpdateHB"), true);
            UseLocalSettings       = GetElementValue(element.Element("UseLocalSettings"), false);
            AutoAcceptTosEula      = GetElementValue(element.Element("AutoAcceptTosEula"), false);
            SetGameWindowTitle     = GetElementValue(element.Element("SetGameWindowTitle"), true);
            GameWindowTitle        = GetElementValue(element.Element("GameWindowTitle"), "{name} - {pid}");
            EncryptSettings        = GetElementValue(element.Element("EncryptSettings"), true);
            GameStateOffset        = GetElementValue(element.Element("GameStateOffset"), 0u);
            // settings.FrameScriptExecuteOffset = GetElementValue(root.Element("FrameScriptExecuteOffset"), 0u);
            FocusedWidgetOffset            = GetElementValue(element.Element("FocusedWidgetOffset"), 0u);
            LuaStateOffset                 = GetElementValue(element.Element("LuaStateOffset"), 0u);
            LoadingScreenEnableCountOffset = GetElementValue(element.Element("LoadingScreenEnableCountOffset"), 0u);
            //settings.LastHardwareEventOffset = GetElementValue(root.Element("LastHardwareEventOffset"), 0u);
            CharacterProfiles.Clear();
            XElement characterProfilesElement = element.Element("CharacterProfiles");

            foreach (XElement profileElement in characterProfilesElement.Elements("CharacterProfile"))
            {
                var profile = new CharacterProfile();
                profile.LoadFromXml(profileElement);
                CharacterProfiles.Add(profile);
            }
        }
示例#2
0
        /// <summary>
        ///     Attempts to load settings from file
        /// </summary>
        /// <returns>A GlocalSettings</returns>
        private void Load(string path)
        {
            try
            {
                var hasSettings = File.Exists(path);

                var tempPath = GetTempSettingsPath(path);

                var recoverFromCrash = !hasSettings && File.Exists(tempPath);
                if (hasSettings || recoverFromCrash)
                {
                    if (recoverFromCrash)
                    {
                        File.Move(tempPath, path);
                    }

                    XElement root = XElement.Load(path);
                    WowVersion             = root.Element("WowVersion").Value;
                    AutoStart              = GetElementValue <bool>(root.Element("AutoStart"));
                    WowDelay               = GetElementValue <int>(root.Element("WowDelay"));
                    HBDelay                = GetElementValue(root.Element("HBDelay"), 10);
                    LoginDelay             = GetElementValue(root.Element("LoginDelay"), 3);
                    UseDarkStyle           = GetElementValue(root.Element("UseDarkStyle"), true);
                    CheckRealmStatus       = GetElementValue(root.Element("CheckRealmStatus"), false);
                    CheckHbResponsiveness  = GetElementValue(root.Element("CheckHbResponsiveness"), true);
                    CheckWowResponsiveness = GetElementValue(root.Element("CheckWowResponsiveness"), true);
                    AutoUpdateHB           = GetElementValue(root.Element("AutoUpdateHB"), true);
                    UseLocalSettings       = GetElementValue(root.Element("UseLocalSettings"), false);
                    AutoAcceptTosEula      = GetElementValue(root.Element("AutoAcceptTosEula"), false);
                    SetGameWindowTitle     = GetElementValue(root.Element("SetGameWindowTitle"), true);
                    GameWindowTitle        = GetElementValue(root.Element("GameWindowTitle"), "{name} - {pid}");
                    EncryptSettings        = GetElementValue(root.Element("EncryptSettings"), true);

                    GameStateOffset = GetElementValue(root.Element("GameStateOffset"), 0u);
                    // settings.FrameScriptExecuteOffset = GetElementValue(root.Element("FrameScriptExecuteOffset"), 0u);
                    FocusedWidgetOffset = GetElementValue(root.Element("FocusedWidgetOffset"), 0u);
                    LuaStateOffset      = GetElementValue(root.Element("LuaStateOffset"), 0u);
                    //settings.LastHardwareEventOffset = GetElementValue(root.Element("LastHardwareEventOffset"), 0u);

                    CharacterProfiles.Clear();
                    XElement characterProfilesElement = root.Element("CharacterProfiles");
                    foreach (XElement profileElement in characterProfilesElement.Elements("CharacterProfile"))
                    {
                        var      profile         = new CharacterProfile();
                        XElement settingsElement = profileElement.Element("Settings");
                        profile.Settings.ProfileName = GetElementValue <string>(settingsElement.Element("ProfileName"));
                        profile.Settings.IsEnabled   = GetElementValue <bool>(settingsElement.Element("IsEnabled"));
                        XElement wowSettingsElement = settingsElement.Element("WowSettings");

                        // Wow Settings
                        if (wowSettingsElement != null)
                        {
                            profile.Settings.WowSettings.LoginData                    = GetElementValue <string>(wowSettingsElement.Element("LoginData"));
                            profile.Settings.WowSettings.PasswordData                 = GetElementValue <string>(wowSettingsElement.Element("PasswordData"));
                            profile.Settings.WowSettings.AcountName                   = GetElementValue <string>(wowSettingsElement.Element("AcountName"));
                            profile.Settings.WowSettings.CharacterName                = GetElementValue <string>(wowSettingsElement.Element("CharacterName"));
                            profile.Settings.WowSettings.ServerName                   = GetElementValue <string>(wowSettingsElement.Element("ServerName"));
                            profile.Settings.WowSettings.AuthenticatorSerialData      = GetElementValue <string>(wowSettingsElement.Element("AuthenticatorSerialData"));
                            profile.Settings.WowSettings.AuthenticatorRestoreCodeData = GetElementValue <string>(wowSettingsElement.Element("AuthenticatorRestoreCodeData"));
                            profile.Settings.WowSettings.Region          = GetElementValue <WowSettings.WowRegion>(wowSettingsElement.Element("Region"));
                            profile.Settings.WowSettings.WowPath         = GetElementValue <string>(wowSettingsElement.Element("WowPath"));
                            profile.Settings.WowSettings.WowArgs         = GetElementValue <string>(wowSettingsElement.Element("WowArgs"));
                            profile.Settings.WowSettings.WowWindowWidth  = GetElementValue <int>(wowSettingsElement.Element("WowWindowWidth"));
                            profile.Settings.WowSettings.WowWindowHeight = GetElementValue <int>(wowSettingsElement.Element("WowWindowHeight"));
                            profile.Settings.WowSettings.WowWindowX      = GetElementValue <int>(wowSettingsElement.Element("WowWindowX"));
                            profile.Settings.WowSettings.WowWindowY      = GetElementValue <int>(wowSettingsElement.Element("WowWindowY"));
                        }
                        XElement hbSettingsElement = settingsElement.Element("HonorbuddySettings");
                        // Honorbuddy Settings
                        if (hbSettingsElement != null)
                        {
                            profile.Settings.HonorbuddySettings.HonorbuddyKeyData = GetElementValue <string>(hbSettingsElement.Element("HonorbuddyKeyData"));
                            profile.Settings.HonorbuddySettings.CustomClass       = GetElementValue <string>(hbSettingsElement.Element("CustomClass"));
                            profile.Settings.HonorbuddySettings.HonorbuddyArgs    = GetElementValue <string>(hbSettingsElement.Element("HonorbuddyArgs"));
                            profile.Settings.HonorbuddySettings.BotBase           = GetElementValue <string>(hbSettingsElement.Element("BotBase"));
                            profile.Settings.HonorbuddySettings.HonorbuddyProfile = GetElementValue <string>(hbSettingsElement.Element("HonorbuddyProfile"));
                            profile.Settings.HonorbuddySettings.HonorbuddyPath    = GetElementValue <string>(hbSettingsElement.Element("HonorbuddyPath"));
                            profile.Settings.HonorbuddySettings.UseHBBeta         = GetElementValue <bool>(hbSettingsElement.Element("UseHBBeta"));
                        }
                        XElement tasksElement = profileElement.Element("Tasks");
                        // Load the Task list.
                        foreach (XElement taskElement in tasksElement.Elements())
                        {
                            Type taskType = Type.GetType("HighVoltz.HBRelog.Tasks." + taskElement.Name);
                            if (taskType != null)
                            {
                                var task = (BMTask)Activator.CreateInstance(taskType);
                                task.SetProfile(profile);
                                // Dictionary of property Names and the corresponding PropertyInfo
                                Dictionary <string, PropertyInfo> propertyDict =
                                    task.GetType()
                                    .GetProperties()
                                    .Where(pi => pi.GetCustomAttributesData().All(cad => cad.Constructor.DeclaringType != typeof(XmlIgnoreAttribute)))
                                    .ToDictionary(k => k.Name);

                                foreach (XAttribute attr in taskElement.Attributes())
                                {
                                    string propKey = attr.Name.ToString();
                                    if (propertyDict.ContainsKey(propKey))
                                    {
                                        // if property is an enum then use Enum.Parse.. otherwise use Convert.ChangeValue
                                        object val = typeof(Enum).IsAssignableFrom(propertyDict[propKey].PropertyType)
                                                         ? Enum.Parse(propertyDict[propKey].PropertyType, attr.Value)
                                                         : Convert.ChangeType(attr.Value, propertyDict[propKey].PropertyType);
                                        propertyDict[propKey].SetValue(task, val, null);
                                    }
                                    else
                                    {
                                        Log.Err("{0} does not have a property called {1}", taskElement.Name, attr.Name);
                                    }
                                }
                                profile.Tasks.Add(task);
                            }
                            else
                            {
                                Log.Err("{0} is not a known task type", taskElement.Name);
                            }
                        }
                        CharacterProfiles.Add(profile);
                    }
                }

                SettingsPath = UseLocalSettings ? LocalSettingsPath : UserSettingsPath;
            }
            catch (Exception ex)
            {
                Log.Err(ex.ToString());
            }
        }