Esempio n. 1
0
        public static void Load()
        {
            PrintLine("Atempting Load of leadeboards");
            FileStream fs = null;

            if (!UFile.Exits(_savePath))
            {
                PrintLine("no file found");
                return;
            }
            try
            {
                fs = UFile.Open(_savePath, FileMode.Open);
                PrintLine("Loading Scores");
                CustomXmlReader reader = CustomXmlReader.Create(fs);
                _scoresToSend.Clear();
                while (reader.Read())
                {
                    if (reader.Name == "ScoresToSend")
                    {
                        if (reader.IsStartElement())
                        {
                            HighScore hs = new Networking.HighScore()
                            {
                                Principal_ID       = reader.ReadAttributeULong("Id"),
                                Nex_Unique_ID      = reader.ReadAttributeULong("Nex_Id"),
                                Misc               = reader.ReadAttributeULong("Misc"),
                                Score              = reader.ReadAttributeUInt("Score"),
                                CommonDataBinary   = reader.ReadAttributeArrayOfByte("Cud"),
                                CommonDataUserName = reader.ReadAttributeString("UserName"),
                            };

                            QueuededScore qhs = new QueuededScore(hs, reader.ReadAttributeString("Leaderboard"),
                                                                  (HighScoreType)reader.ReadAttributeInt("Type"));
                            _scoresToSend.Add(qhs);
                        }
                    }
                    string currentLeaderboard;
                    if (reader.Name == "Leaderboard")
                    {
                        if (reader.IsStartElement())
                        {
                            currentLeaderboard = reader.ReadAttributeString("Name");

                            if (!_localLeaderboards.ContainsKey(currentLeaderboard))
                            {
                                _localLeaderboards.Add(currentLeaderboard, new List <HighScore>());
                            }
                            while (reader.Read())
                            {
                                if (reader.Name == "Leaderboard")
                                {
                                    if (!reader.IsStartElement())
                                    {
                                        break;
                                    }
                                }

                                if (reader.Name == "Score")
                                {
                                    if (reader.IsStartElement())
                                    {
                                        HighScore hs = new HighScore()
                                        {
                                            Principal_ID       = reader.ReadAttributeULong("Id"),
                                            Nex_Unique_ID      = reader.ReadAttributeULong("Nex_Id"),
                                            Misc               = reader.ReadAttributeULong("Misc"),
                                            Score              = reader.ReadAttributeUInt("Score"),
                                            CommonDataUserName = reader.ReadAttributeString("UserName"),
                                            CommonDataBinary   = reader.ReadAttributeArrayOfByte("Cud"),
                                        };


                                        _localLeaderboards[currentLeaderboard].Add(hs);
                                    }
                                }
                            }
                        }
                    }
                }

                foreach (QueuededScore qs in _scoresToSend)
                {
                    PrintLine($"{qs.Leaderboard} > {qs.Score.Principal_ID}, {qs.Score.Score}");
                }
                reader.Close();
                PrintLine("Loading Compleate");
            }
            catch (System.Exception x)
            {
                PrintLine($"Error Saving: {x.Message}");
//
            }
            fs.Close();
        }