Exemplo n.º 1
0
        public void SaveStatistic(UserStatisticsData data)
        {
            var bf = new BinaryFormatter();

            using (FileStream fs = new FileStream(Path.Combine(AppDataPath, StatisticsFileName), FileMode.OpenOrCreate))
            {
                bf.Serialize(fs, data);
            }
        }
Exemplo n.º 2
0
 public UserStatisticsData LoadStatistics()
 {
     if (!File.Exists(Path.Combine(AppDataPath, StatisticsFileName)))
     {
         using (FileStream fs = File.Create(Path.Combine(AppDataPath, StatisticsFileName)))
         {
             fs.Close();
         }
         var newStat = new UserStatisticsData();
         SaveStatistic(newStat);
         return(newStat);
     }
     else
     {
         var bf = new BinaryFormatter();
         using (FileStream fs = new FileStream(Path.Combine(AppDataPath, StatisticsFileName), FileMode.OpenOrCreate))
         {
             UserStatisticsData data = (UserStatisticsData)bf.Deserialize(fs);
             return(data);
         }
     }
 }