daily pastebin goal
22%
SHARE
TWEET

Untitled

a guest May 16th, 2018 110 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Xml;
  3. using System.Collections.Generic;
  4. using Microsoft.Xna.Framework;
  5. using Microsoft.Xna.Framework.Graphics;
  6. using Microsoft.Xna.Framework.Input;
  7. using Microsoft.Xna.Framework.Storage;
  8. using System.IO;
  9. using System.Xml.Serialization;
  10. using System.Diagnostics;
  11. namespace Engine
  12. {
  13.     class controlsloader
  14.     {
  15.  
  16.         [Serializable]
  17.         public struct Savekeysdata
  18.         {
  19.             public List<int> listi;
  20.         }
  21.  
  22.         public void DoSave(List<int> listy)
  23.         {
  24.             //create data to save
  25.             Savekeysdata data = new Savekeysdata();
  26.             data.listi = listy;
  27.  
  28.             string filename = "controls.xml";
  29.  
  30.             // Check to see whether the save exists.
  31.             if (File.Exists(filename))
  32.                 // Delete it so that we can create one fresh.
  33.                 File.Delete(filename);
  34.  
  35.             StreamWriter stream = new StreamWriter(filename);
  36.                 // Convert the object to XML data and put it in the stream.
  37.                 XmlSerializer serializer = new XmlSerializer(typeof(List<int>));
  38.  
  39.                 serializer.Serialize(stream, data);
  40.                 // Close the file.
  41.                 stream.Close();
  42.                 // Dispose the container, to commit changes.
  43.        
  44.         }
  45.  
  46.  
  47.  
  48.         public List<int> load()
  49.         {
  50.             Savekeysdata newdata = new Savekeysdata();
  51.             newdata.listi = new List<int> { 37, 39, 38, 40 };
  52.             // Open a storage container.
  53.  
  54.             string filename = "controls.xml";
  55.  
  56.             // Check to see whether the save exists.
  57.             if (!File.Exists(filename))
  58.             {
  59.                 // If not, dispose of the container and return.
  60.                 return newdata.listi;
  61.             }
  62.  
  63.             // Open the file.
  64.             StreamReader stream = new StreamReader(filename);
  65.  
  66.             XmlSerializer serializer = new XmlSerializer(typeof(List<int>));
  67.  
  68.             newdata = (Savekeysdata)serializer.Deserialize(stream);
  69.             stream.Close();
  70.             return newdata.listi;
  71.         }
  72.  
  73.     }
  74. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top