Beispiel #1
0
        public bool Load()
        {
            if (m_Name == null || m_Name.Trim() == "")
            {
                return(false);
            }

            string path = Config.GetUserDirectory("Profiles");
            string file = Path.Combine(path, String.Format("{0}.xml", m_Name));

            if (!File.Exists(file))
            {
                return(false);
            }

            XmlDocument doc = new XmlDocument();

            try
            {
                doc.Load(file);
            }
            catch
            {
                MessageBox.Show(Engine.ActiveWindow, Language.Format(LocString.ProfileCorrupt, file), "Profile Load Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                return(false);
            }

            XmlElement root = doc["profile"];

            if (root == null)
            {
                return(false);
            }

            Assembly exe = Assembly.GetCallingAssembly();

            if (exe == null)
            {
                return(false);
            }

            foreach (XmlElement el in root.GetElementsByTagName("property"))
            {
                try
                {
                    string name    = el.GetAttribute("name");
                    string typeStr = el.GetAttribute("type");
                    string val     = el.InnerText;

                    if (typeStr == "-null-" || name == "LimitSize" || name == "VisRange")
                    {
                        //m_Props[name] = null;
                        if (m_Props.ContainsKey(name))
                        {
                            m_Props.Remove(name);
                        }
                    }
                    else
                    {
                        Type type = Type.GetType(typeStr);
                        if (type == null)
                        {
                            type = exe.GetType(typeStr);
                        }

                        if (m_Props.ContainsKey(name) || name == "ForceSize")
                        {
                            if (type == null)
                            {
                                m_Props.Remove(name);
                            }
                            else
                            {
                                m_Props[name] = GetObjectFromString(val, type);
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    MessageBox.Show(Engine.ActiveWindow, Language.Format(LocString.ProfileLoadEx, e.ToString()), "Profile Load Exception", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }

            Filter.Load(root["filters"]);
            Counter.LoadProfile(root["counters"]);
            Agent.LoadProfile(root["agents"]);
            DressList.Load(root["dresslists"]);
            HotKey.Load(root["hotkeys"]);
            PasswordMemory.Load(root["passwords"]);
            OverheadMessages.Load(root["overheadmessages"]);
            ContainerLabels.Load(root["containerlabels"]);
            AbsoluteTargetVariables.Load(root["absolutetargets"]);
            DoubleClickVariables.Load(root["doubleclickvariables"]);

            GoldPerHourTimer.Stop();
            DamageTracker.Stop();

            if (m_Props.ContainsKey("ForceSize"))
            {
                try
                {
                    int x, y;
                    switch ((int)m_Props["ForceSize"])
                    {
                    case 1: x = 960; y = 600; break;

                    case 2: x = 1024; y = 768; break;

                    case 3: x = 1152; y = 864; break;

                    case 4: x = 1280; y = 720; break;

                    case 5: x = 1280; y = 768; break;

                    case 6: x = 1280; y = 800; break;

                    case 7: x = 1280; y = 960; break;

                    case 8: x = 1280; y = 1024; break;

                    case 0:
                    default: x = 800; y = 600; break;
                    }

                    SetProperty("ForceSizeX", x);
                    SetProperty("ForceSizeY", y);

                    if (x != 800 || y != 600)
                    {
                        SetProperty("ForceSizeEnabled", true);
                    }

                    m_Props.Remove("ForceSize");
                }
                catch
                {
                }
            }

            //if ( !Language.Load( GetString( "Language" ) ) )
            //	MessageBox.Show( Engine.ActiveWindow, "Warning: Could not load language from profile, using current language instead.", "Language Error", MessageBoxButtons.OK, MessageBoxIcon.Warning );

            return(true);
        }