Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Xml;
- using System.Collections.Generic;
- using Microsoft.Xna.Framework;
- using Microsoft.Xna.Framework.Graphics;
- using Microsoft.Xna.Framework.Input;
- using Microsoft.Xna.Framework.Storage;
- using System.IO;
- using System.Xml.Serialization;
- using System.Diagnostics;
- namespace Engine
- {
- class controlsloader
- {
- [Serializable]
- public struct Savekeysdata
- {
- public List<int> listi;
- }
- public void DoSave(List<int> listy)
- {
- //create data to save
- Savekeysdata data = new Savekeysdata();
- data.listi = listy;
- string filename = "controls.xml";
- // Check to see whether the save exists.
- if (File.Exists(filename))
- // Delete it so that we can create one fresh.
- File.Delete(filename);
- StreamWriter stream = new StreamWriter(filename);
- // Convert the object to XML data and put it in the stream.
- XmlSerializer serializer = new XmlSerializer(typeof(List<int>));
- serializer.Serialize(stream, data);
- // Close the file.
- stream.Close();
- // Dispose the container, to commit changes.
- }
- public List<int> load()
- {
- Savekeysdata newdata = new Savekeysdata();
- newdata.listi = new List<int> { 37, 39, 38, 40 };
- // Open a storage container.
- string filename = "controls.xml";
- // Check to see whether the save exists.
- if (!File.Exists(filename))
- {
- // If not, dispose of the container and return.
- return newdata.listi;
- }
- // Open the file.
- StreamReader stream = new StreamReader(filename);
- XmlSerializer serializer = new XmlSerializer(typeof(List<int>));
- newdata = (Savekeysdata)serializer.Deserialize(stream);
- stream.Close();
- return newdata.listi;
- }
- }
- }
Add Comment
Please, Sign In to add comment