Пример #1
0
        public bool TryGetGame(string hash, out Game game)
        {
            if (games.TryGetValue(hash, out game))
                return true;

            if (!File.Exists(getFilePath(hash)))
                return false;

            game = Game.FromFile(getFilePath(hash));
            games.Add(hash, game);
            return true;
        }
Пример #2
0
            public Commit(Game game, string sha, string message, string username, int added, int removed, byte[] guesses)
            {
                this.game = game;

                this.sha = sha;

                this.message = message;
                this.username = username;

                this.added = added;
                this.removed = removed;

                this.guesses = guesses;
            }
Пример #3
0
        public static Game FromFile(string filepath)
        {
            using (FileStream fs = new FileStream(filepath, FileMode.Open))
            {
                string hash = fs.ReadString();
                string owner = fs.ReadString();
                string repo = fs.ReadString();
                string token = fs.ReadString();
                byte set = (byte)fs.ReadInt32();

                Game game = new Game(filepath, token, owner, repo, hash);

                game.users = new User[fs.ReadInt32()];
                for (int i = 0; i < game.users.Length; i++)
                    game.users[i] = User.FromStream(fs);

                game.contributors = new string[fs.ReadInt32()];
                for (int i = 0; i < game.contributors.Length; i++)
                    game.contributors[i] = fs.ReadString();

                game.rowCount = fs.ReadInt32();
                game.commits = new CommitCollection(game);

                game.tableStart = fs.Position;
                game.rowSize = 40 + game.users.Length;

                for (game.tableIndex = 0; game.tableIndex < game.rowCount; game.tableIndex++)
                {
                    fs.Seek(40, SeekOrigin.Current);
                    bool stop = false;

                    for (int i = 0; i < game.users.Length; i++)
                        if (fs.ReadByte() == 0)
                        {
                            stop = true;
                            fs.Seek(-(40 + i + 1), SeekOrigin.Current);
                            break;
                        }

                    if (stop)
                        break;
                }

                fs.Seek(game.tableStart + game.rowCount * game.rowSize, SeekOrigin.Begin);
                while (fs.Position < fs.Length)
                    game.messages.Add(Message.FromStream(fs));

                return game;
            }
        }
Пример #4
0
 public CommitCollection(Game game)
 {
     this.game = game;
     this.commits = new Commit[game.rowCount];
 }