public GameInfo GetGameInfoFromFile(int gameId)
        {
            var gamesDirectory = Filesystem.GetGamesDirectory(_configuration["GamesPath"]);

            Configuration config = null;

            var path = Path.Combine(new [] { gamesDirectory, gameId.ToString(), "GameData", "Game.ini" });

            config = Configuration.LoadFromFile(path);

            var section = config["Game"];

            var game = new GameInfo()
            {
                Id        = gameId,
                Title     = section["Title"].StringValue,
                Publisher = section["Publisher"].StringValue,
                Year      = section["Year"].IntValue,
                Players   = section["Players"].IntValue,
                DiscIds   = section["Discs"].StringValue.Split(',').ToList()
            };

            return(game);
        }
        public GameInfo GetGameInfoFromCentral(int gameId)
        {
            var gamesDirectory = Filesystem.GetGamesDirectory(_configuration["GamesPath"]);

            var files    = Directory.GetFiles(Path.Combine(gamesDirectory, gameId.ToString(), "GameData"));
            var discMap  = new Dictionary <string, string>();
            var gameInfo = new GameInfo();

            foreach (var file in files)
            {
                var fileInfo = new FileInfo(file);

                if (fileInfo.Extension == ".bin" || fileInfo.Extension == ".iso")
                {
                    try
                    {
                        var serial = DiscImage.GetSerialNumber(Path.Combine(gamesDirectory, gameId.ToString(), file));

                        discMap.Add(serial, fileInfo.Name.Replace(fileInfo.Extension, ""));

                        Console.WriteLine($"Found serial {serial} from disc image file {file}");
                    }
                    catch {
                        Console.WriteLine($"Could not find a valid serial from the disc image {file}");
                    }
                }
            }

            try
            {
                var client  = new RestClient(_configuration["BleemSyncCentralUrl"]);
                var request = new RestRequest($"api/PlayStation/GetBySerial/{discMap.Keys.First()}");
                var result  = client.Execute <GameDTO>(request);

                var game = JsonConvert.DeserializeObject <GameDTO>(result.Content);

                gameInfo.Title     = game.Title;
                gameInfo.Year      = game.DateReleased.Year;
                gameInfo.Publisher = game.Publisher;
                gameInfo.Players   = game.Players;

                foreach (var serial in game.Discs.Select(d => d.SerialNumber))
                {
                    gameInfo.DiscIds.Add(discMap[serial]);
                }

                WriteGameInfoToFile(gameInfo, Path.Combine(gamesDirectory, gameId.ToString()));

                var coverFileName = gameInfo.DiscIds.First() + ".png";

                // Download the cover
                if (!File.Exists(Path.Combine(gamesDirectory, gameId.ToString(), "GameData", coverFileName)))
                {
                    try
                    {
                        using (WebClient wc = new WebClient())
                        {
                            wc.DownloadFile(
                                new Uri(_configuration["BleemSyncCentralUrl"] + "/api/PlayStation/GetCoverBySerial/" + discMap.Keys.First()),
                                Path.Combine(gamesDirectory, gameId.ToString(), "GameData", coverFileName)
                                );
                        }
                    }
                    catch
                    {
                        Console.WriteLine("Could not download the cover from BleemSync Central");
                    }
                }
            }
            catch
            {
                Console.WriteLine($"Could not grab game info for serial {discMap.Keys.First()}");
                throw;
            }

            return(gameInfo);
        }