Esempio n. 1
0
        public static PlayerSettings ReadSettings(string path)
        {
            if (File.Exists(path))
            {
                using (var stream = File.OpenRead(path))
                {
                    var ser = new XmlSerializer(typeof(PlayerSettings));
                    var settings = (PlayerSettings)ser.Deserialize(stream);
                    return settings;
                }
            }
            else
            {
                var settings = new PlayerSettings();
                settings.Name = string.IsNullOrEmpty(Game.Player.Name) ? "Player" : Game.Player.Name;
                settings.MaxStreamedNpcs = 10;
                settings.MasterServerAddress = "http://46.101.1.92/";
                settings.ActivationKey = Keys.F9;

                var ser = new XmlSerializer(typeof(PlayerSettings));
                using (var stream = File.OpenWrite(path))
                {
                    ser.Serialize(stream, settings);
                }
                return settings;
            }
        }
Esempio n. 2
0
        public static PlayerSettings ReadSettings(string path)
        {
            var ser = new XmlSerializer(typeof(PlayerSettings));

            PlayerSettings settings = null;

            if (File.Exists(path))
            {
                using (var stream = File.OpenRead(path)) settings = (PlayerSettings)ser.Deserialize(stream);

                using (var stream = new FileStream(path, File.Exists(path) ? FileMode.Truncate : FileMode.Create, FileAccess.ReadWrite)) ser.Serialize(stream, settings);
            }
            else
            {
                using (var stream = File.OpenWrite(path)) ser.Serialize(stream, settings = new PlayerSettings());
            }

            return settings;
        }