Exemplo n.º 1
0
        // Internal load all extensions
        internal static void LoadExtensions(Character character)
        {
            var dir = SLSaveManager.GetSaveFolderForCharacter(character)
                      + "\\" + SLSaveManager.CUSTOM_FOLDER + "\\";

            bool isWorldHost = character.UID == CharacterManager.Instance.GetWorldHostCharacter()?.UID;

            foreach (var file in Directory.GetFiles(dir))
            {
                try
                {
                    var typename = Path.GetFileNameWithoutExtension(file);

                    var type = s_registeredModels.FirstOrDefault(it => it.FullName == typename);
                    if (type != null)
                    {
                        using (var xml = File.OpenRead(file))
                        {
                            var serializer = Serializer.GetXmlSerializer(type);

                            if (serializer.Deserialize(xml) is PlayerSaveExtension loaded)
                            {
                                loaded.LoadSaveData(character, isWorldHost);
                            }
                            else
                            {
                                throw new Exception("Unknown - extension was null after attempting to load XML!");
                            }
                        }
                    }
                    else
                    {
                        SL.LogWarning("Loading PlayerSaveExtensions, could not find a matching registered type for " + typename);
                    }
                }
                catch (Exception ex)
                {
                    SL.LogWarning($"Exception loading Player Save Extension XML from '{file}'!");
                    SL.LogInnerException(ex);
                }
            }
        }
Exemplo n.º 2
0
        // Internal save all extensions
        internal static void SaveAllExtensions(Character character, bool isWorldHost)
        {
            var baseDir = SLSaveManager.GetSaveFolderForCharacter(character)
                          + "\\" + SLSaveManager.CUSTOM_FOLDER + "\\";

            //bool isWorldHost = character.UID == CharacterManager.Instance.GetWorldHostCharacter()?.UID;

            foreach (var type in s_registeredModels)
            {
                try
                {
                    PlayerSaveExtension model;

                    var path = baseDir + type.FullName + ".xml";
                    if (File.Exists(path))
                    {
                        using (var file = File.OpenRead(path))
                        {
                            var serializer = Serializer.GetXmlSerializer(type);
                            model = (PlayerSaveExtension)serializer.Deserialize(file);
                        }
                    }
                    else
                    {
                        model = (PlayerSaveExtension)Activator.CreateInstance(type);
                    }

                    model.SaveDataFromCharacter(character, isWorldHost);

                    Serializer.SaveToXml(baseDir, model.GetType().FullName, model);
                }
                catch (Exception ex)
                {
                    SL.LogWarning($"Exception saving PlayerSaveExtension type: {type.FullName}!");
                    SL.Log(ex.ToString());
                }
            }
        }
Exemplo n.º 3
0
 public static string GetSaveFilePath <T>(string characterUID)
 => SLSaveManager.GetSaveFolderForCharacter(characterUID)
 + "\\" + SLSaveManager.CUSTOM_FOLDER + "\\" + $"{typeof(T).FullName}.xml";