Exemplo n.º 1
0
        public static void Save()
        {
            List <string> frg = new List <string>();

            foreach (var usrigh in UsersRights)
            {
                try
                {
                    frg.Add(usrigh.Key + ":" + usrigh.Value.ToString());
                }
                catch
                {
                }
            }
            Current.UserRightes = frg.ToArray();
            MySave        X         = Current;
            XmlSerializer formatter = new XmlSerializer(typeof(MySave));

            if (File.Exists("save.xml"))
            {
                File.Delete("save.xml");
            }
            using (FileStream fs = new FileStream("save.xml", FileMode.OpenOrCreate))
            {
                formatter.Serialize(fs, X);
            }
        }
Exemplo n.º 2
0
 public static void Load()
 {
     if (File.Exists("save.xml"))
     {
         try
         {
             XmlSerializer formatter = new XmlSerializer(typeof(MySave));
             using (FileStream fs = new FileStream("save.xml", FileMode.OpenOrCreate))
             {
                 Current = (MySave)formatter.Deserialize(fs);
             }
         }
         catch
         {
             File.Copy("save.xml", "save_errored" + Rand.Next() + ".xml");
             Current = new MySave();
             Save();
         }
         if (Current.Nums.Length < NL)
         {
             int[] nms = Current.Nums;
             Array.Resize <int>(ref nms, NL);
             Current.Nums = nms;
         }
         if (Current.Bools.Length < BL)
         {
             bool[] nms = Current.Bools;
             Array.Resize <bool>(ref nms, BL);
             Current.Bools = nms;
         }
     }
     foreach (string usrigh in Current.UserRightes)
     {
         try
         {
             string[] Flds = usrigh.Split(':');
             if (UsersRights.ContainsKey(Flds[0]))
             {
                 continue;
             }
             UsersRights.Add(Flds[0], (UserRights)Enum.Parse(typeof(UserRights), Flds[1]));
         }
         catch
         {
         }
     }
 }