Exemplo n.º 1
0
        public void Save(List <Gump> gumps = null)
        {
            if (string.IsNullOrEmpty(ServerName))
            {
                throw new InvalidDataException();
            }

            if (string.IsNullOrEmpty(Username))
            {
                throw new InvalidDataException();
            }

            if (string.IsNullOrEmpty(CharacterName))
            {
                throw new InvalidDataException();
            }

            string path = FileSystemHelper.CreateFolderIfNotExists(ProfilePath, Username.Trim(), ServerName.Trim(), CharacterName.Trim());

            Log.Trace($"Saving path:\t\t{path}");

            // Save profile settings
            ConfigurationResolver.Save(this, Path.Combine(path, "profile.json"), new JsonSerializerSettings
            {
                TypeNameHandling         = TypeNameHandling.All,
                MetadataPropertyHandling = MetadataPropertyHandling.ReadAhead
            });

            // Save opened gumps
            SaveGumps(path, gumps);

            Log.Trace("Saving done!");
        }
Exemplo n.º 2
0
        public List <Gump> ReadGumps()
        {
            string      path  = FileSystemHelper.CreateFolderIfNotExists(ProfilePath, Username.Trim(), ServerName.Trim(), CharacterName.Trim());
            List <Gump> gumps = new List <Gump>();



            // #########################################################
            // [FILE_FIX]
            // TODO: this code is a workaround to port old macros to the new xml system.
            string skillsGroupsPath = Path.Combine(path, "skillsgroups.bin");

            if (File.Exists(skillsGroupsPath))
            {
                try
                {
                    using (BinaryReader reader = new BinaryReader(File.OpenRead(skillsGroupsPath)))
                    {
                        int version = reader.ReadInt32();

                        int groupCount = reader.ReadInt32();

                        for (int i = 0; i < groupCount; i++)
                        {
                            int    entriesCount = reader.ReadInt32();
                            string groupName    = reader.ReadUTF8String(reader.ReadInt32());

                            SkillsGroup g = new SkillsGroup();
                            g.Name = groupName;

                            for (int j = 0; j < entriesCount; j++)
                            {
                                byte idx = (byte)reader.ReadInt32();
                                g.Add(idx);
                            }

                            g.Sort();

                            SkillsGroupManager.Add(g);
                        }
                    }
                }
                catch (Exception e)
                {
                    SkillsGroupManager.MakeDefault();
                    Log.Error(e.StackTrace);
                }


                SkillsGroupManager.Save();

                try
                {
                    File.Delete(skillsGroupsPath);
                }
                catch { }
            }

            string binpath = Path.Combine(path, "gumps.bin");

            if (File.Exists(binpath))
            {
                using (BinaryReader reader = new BinaryReader(File.OpenRead(binpath)))
                {
                    if (reader.BaseStream.Position + 12 < reader.BaseStream.Length)
                    {
                        GumpsVersion = reader.ReadUInt32();
                        uint empty = reader.ReadUInt32();

                        int count = reader.ReadInt32();

                        for (int i = 0; i < count; i++)
                        {
                            try
                            {
                                int    typeLen  = reader.ReadUInt16();
                                string typeName = reader.ReadUTF8String(typeLen);
                                int    x        = reader.ReadInt32();
                                int    y        = reader.ReadInt32();

                                Type type = Type.GetType(typeName, true);
                                Gump gump = (Gump)Activator.CreateInstance(type);
                                gump.Restore(reader);
                                gump.X = x;
                                gump.Y = y;

                                //gump.SetInScreen();

                                if (gump.LocalSerial != 0)
                                {
                                    UIManager.SavePosition(gump.LocalSerial, new Point(x, y));
                                }

                                if (!gump.IsDisposed)
                                {
                                    gumps.Add(gump);
                                }
                            }
                            catch (Exception e)
                            {
                                Log.Error(e.StackTrace);
                            }
                        }
                    }
                }

                SaveGumps(path, gumps);

                gumps.Clear();

                try
                {
                    File.Delete(binpath);
                }
                catch
                {
                }
            }
            // #########################################################



            // load skillsgroup
            //SkillsGroupManager.Load();
            SkillsGroupManager.Load();

            // load gumps
            string gumpsXmlPath = Path.Combine(path, "gumps.xml");

            if (File.Exists(gumpsXmlPath))
            {
                XmlDocument doc = new XmlDocument();
                try
                {
                    doc.Load(gumpsXmlPath);
                }
                catch (Exception ex)
                {
                    Log.Error(ex.ToString());

                    return(gumps);
                }

                XmlElement root = doc["gumps"];

                if (root != null)
                {
                    foreach (XmlElement xml in root.GetElementsByTagName("gump"))
                    {
                        try
                        {
                            GUMP_TYPE type   = (GUMP_TYPE)int.Parse(xml.GetAttribute("type"));
                            int       x      = int.Parse(xml.GetAttribute("x"));
                            int       y      = int.Parse(xml.GetAttribute("y"));
                            uint      serial = uint.Parse(xml.GetAttribute("serial"));

                            Gump gump = null;
                            switch (type)
                            {
                            case GUMP_TYPE.GT_BUFF:
                                gump = new BuffGump();
                                break;

                            case GUMP_TYPE.GT_CONTAINER:
                                gump = new ContainerGump();
                                break;

                            case GUMP_TYPE.GT_COUNTERBAR:
                                gump = new CounterBarGump();
                                break;

                            case GUMP_TYPE.GT_HEALTHBAR:
                                if (CustomBarsToggled)
                                {
                                    gump = new HealthBarGumpCustom();
                                }
                                else
                                {
                                    gump = new HealthBarGump();
                                }
                                break;

                            case GUMP_TYPE.GT_INFOBAR:
                                gump = new InfoBarGump();
                                break;

                            case GUMP_TYPE.GT_JOURNAL:
                                gump = new JournalGump();
                                break;

                            case GUMP_TYPE.GT_MACROBUTTON:
                                gump = new MacroButtonGump();
                                break;

                            case GUMP_TYPE.GT_MINIMAP:
                                gump = new MiniMapGump();
                                break;

                            case GUMP_TYPE.GT_PAPERDOLL:
                                gump = new PaperDollGump();
                                break;

                            case GUMP_TYPE.GT_SKILLMENU:
                                if (StandardSkillsGump)
                                {
                                    gump = new StandardSkillsGump();
                                }
                                else
                                {
                                    gump = new SkillGumpAdvanced();
                                }
                                break;

                            case GUMP_TYPE.GT_SPELLBOOK:
                                gump = new SpellbookGump();
                                break;

                            case GUMP_TYPE.GT_STATUSGUMP:
                                switch (Settings.GlobalSettings.ShardType)
                                {
                                default:
                                case 0:         // modern

                                    gump = new StatusGumpModern();

                                    break;

                                case 1:         // old

                                    gump = new StatusGumpOld();

                                    break;

                                case 2:         // outlands

                                    gump = new StatusGumpOutlands();

                                    break;
                                }
                                break;

                            //case GUMP_TYPE.GT_TIPNOTICE:
                            //    gump = new TipNoticeGump();
                            //    break;
                            case GUMP_TYPE.GT_ABILITYBUTTON:
                                gump = new UseAbilityButtonGump();
                                break;

                            case GUMP_TYPE.GT_SPELLBUTTON:
                                gump = new UseSpellButtonGump();
                                break;

                            case GUMP_TYPE.GT_SKILLBUTTON:
                                gump = new SkillButtonGump();
                                break;

                            case GUMP_TYPE.GT_RACIALBUTTON:
                                gump = new RacialAbilityButton();
                                break;

                            case GUMP_TYPE.GT_WORLDMAP:
                                gump = new WorldMapGump();
                                break;
                            }

                            if (gump == null)
                            {
                                continue;
                            }

                            gump.LocalSerial = serial;
                            gump.Restore(xml);
                            gump.X = x;
                            gump.Y = y;

                            if (gump.LocalSerial != 0)
                            {
                                UIManager.SavePosition(gump.LocalSerial, new Point(x, y));
                            }

                            if (!gump.IsDisposed)
                            {
                                gumps.Add(gump);
                            }
                        }
                        catch (Exception ex)
                        {
                            Log.Error(ex.ToString());
                        }
                    }
                }
            }


            // load anchors
            string anchorsPath = Path.Combine(path, "anchors.bin");

            if (File.Exists(anchorsPath))
            {
                try
                {
                    using (BinaryReader reader = new BinaryReader(File.OpenRead(anchorsPath)))
                        UIManager.AnchorManager.Restore(reader, gumps);
                }
                catch (Exception e)
                {
                    Log.Error(e.StackTrace);
                }
            }


            return(gumps);
        }
Exemplo n.º 3
0
        public List <Gump> ReadGumps()
        {
            string path = FileSystemHelper.CreateFolderIfNotExists(ProfilePath, Username.Trim(), ServerName.Trim(), CharacterName.Trim());

            string binpath = Path.Combine(path, "gumps.bin");

            if (!File.Exists(binpath))
            {
                return(null);
            }


            string skillsGroupsPath = Path.Combine(path, "skillsgroups.bin");

            if (File.Exists(skillsGroupsPath))
            {
                try
                {
                    using (BinaryReader reader = new BinaryReader(File.OpenRead(skillsGroupsPath)))
                        SkillsGroupManager.Load(reader);
                }
                catch (Exception e)
                {
                    SkillsGroupManager.LoadDefault();
                    Log.Error(e.StackTrace);
                }
            }

            List <Gump> gumps = new List <Gump>();

            using (BinaryReader reader = new BinaryReader(File.OpenRead(binpath)))
            {
                if (reader.BaseStream.Position + 12 < reader.BaseStream.Length)
                {
                    GumpsVersion = reader.ReadUInt32();
                    uint empty = reader.ReadUInt32();

                    int count = reader.ReadInt32();

                    for (int i = 0; i < count; i++)
                    {
                        try
                        {
                            int    typeLen  = reader.ReadUInt16();
                            string typeName = reader.ReadUTF8String(typeLen);
                            int    x        = reader.ReadInt32();
                            int    y        = reader.ReadInt32();

                            Type type = Type.GetType(typeName, true);
                            Gump gump = (Gump)Activator.CreateInstance(type);
                            gump.Initialize();
                            gump.Restore(reader);
                            gump.X = x;
                            gump.Y = y;

                            //gump.SetInScreen();

                            if (gump.LocalSerial != 0)
                            {
                                UIManager.SavePosition(gump.LocalSerial, new Point(x, y));
                            }

                            if (!gump.IsDisposed)
                            {
                                gumps.Add(gump);
                            }
                        }
                        catch (Exception e)
                        {
                            Log.Error(e.StackTrace);
                        }
                    }
                }
            }


            string anchorsPath = Path.Combine(path, "anchors.bin");

            if (File.Exists(anchorsPath))
            {
                try
                {
                    using (BinaryReader reader = new BinaryReader(File.OpenRead(anchorsPath)))
                        UIManager.AnchorManager.Restore(reader, gumps);
                }
                catch (Exception e)
                {
                    Log.Error(e.StackTrace);
                }
            }


            return(gumps);
        }