Пример #1
0
        private static Profile Load(IContentStorage storage, string profileFolder, Guid id, string file)
        {
            Profile profile = null;
            var     path    = storage.CombinePath(profileFolder, file);

            if (storage.IsFileExist(path))
            {
                var document = new XmlDocument();
                using (var stream = storage.OpenForRead(path))
                {
                    document.Load(stream);
                }

                var rootElement  = document.DocumentElement;
                var name         = rootElement.GetChildElementText(NameElementName) ?? file;
                var passwordHash = rootElement.GetChildElementText(PasswordHashElementName);
                profile           = new Profile(id, name, passwordHash);
                profile.WorldName = rootElement.GetChildElementText(WorldElemenName);

                var      activeData = rootElement.GetChildElementText(LastActiveElementName);
                DateTime lastActive;
                if (!string.IsNullOrEmpty(activeData) &&
                    DateTime.TryParse(activeData, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal, out lastActive))
                {
                    profile.LastActive = lastActive;
                }
                else
                {
                    profile.LastActive = DateTime.MinValue;
                }
            }

            return(profile);
        }
Пример #2
0
        public static XmlElement LoadXml(this IContentStorage storage, string path)
        {
            XmlElement element = null;

            if (storage.IsFileExist(path))
            {
                using (var stream = storage.OpenForRead(path))
                {
                    var document = new XmlDocument();
                    document.Load(stream);
                    element = document.DocumentElement;
                }
            }

            return(element);
        }
Пример #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GameSettingsData" /> class.
        /// </summary>
        public GameSettings(IContentStorage storage, ILog log, string filename = DefaultSettingsFilename)
        {
            if (!storage.IsFileExist(filename))
            {
                // TODO: Write error. Settings file does not exist
                return;
            }

            var rootElement = storage.LoadXml(filename);

            this.DefaultLocale  = rootElement.GetChildElementText(LocaleElementName);
            this.HeartBeat      = rootElement.GetChildElementValue <int>(HeartBeatElementName, 500);
            this.LineSpace      = Math.Max(1, rootElement.GetChildElementValue <int>(LineSpaceElementName, 1));
            this.LoginWorldName = rootElement.GetChildElementText(LoginWorldElementName);
            this.StartWorldName = rootElement.GetChildElementText(StartWorldElementName);

            this.PlayerProfileFolder = DefaultPlayerProfileFolder;
            this.PlayerDataFolder    = DefaultPlayerDataFolder;
            this.MapDataFolder       = DefaultMapDataFolder;
            this.MapDesignFolder     = DefaultMapDesignFolder;
            this.WorldDataFolder     = DefaultWorldDataFolder;
            this.SetFolders(rootElement.SelectSingleNode(FolderRootElementName) as XmlElement, log);
            this.LoadWorldConfigurations(rootElement.SelectSingleNode(WorldRootElementName) as XmlElement, log);
        }