Exemplo n.º 1
0
        //Game Tab
        // get meta data from theGamesDB.net
        private void btnGameOnGameDB_Click(object sender, EventArgs e)
        {
            string platform_name = listboxPlatforms.Text;
            int selectedrows = dataGridGames.FirstDisplayedScrollingRowIndex;

            foreach (DataGridViewRow r in dataGridGames.SelectedRows)
            {
                string game_fileName = r.Cells["file_name"].Value as string;
                string game_name = r.Cells["name"].Value as string;
                long gamedb_id = db.getGameDB_ID(platform_id, game_fileName);

                if (gamedb_id == 0)
                {

                    string searchString = Regex.Replace(game_name, "(\\[.*\\])|(\\(.*\\))", ""); /// Remove all the text between square and round brackets
                    GameDB_Search gameDB_Search = new GameDB_Search(searchString, platform_name, game_fileName);

                    if (gameDB_Search.ShowDialog() == DialogResult.OK)
                    {
                        gamedb_id = Convert.ToInt64( gameDB_Search.ReturnedID );
                    }
                    else
                    {
                        continue;
                    }
                    // Write new gamedb_id to table
                   // var command = new SQLiteCommand("update games set gamedb_id = @gamedb_id where platform_id = @platform_id and file_name = @file_name");
                   // command.Parameters.AddWithValue("@gamedb_id", gamedb_id);
                   // command.Parameters.AddWithValue("@file_name", game_fileName);
                   // command.Parameters.AddWithValue("@platform_id", platform_id);
                   // db.sqlExecute(command);
                }

                // get xml for game from gamesdb.net
                string url = string.Format("http://thegamesdb.net/api/GetGame.php?id={0}", gamedb_id);
                string xml = new WebClient().DownloadString(url);
                StringReader stringReader = new StringReader(xml);
                XDocument xmlDoc = XDocument.Load(stringReader);
                XElement game_node = xmlDoc.Descendants("Game").First();

                GameDataItem updateItem = new GameDataItem(platform_id, game_fileName);
                updateItem.gamedb_id = Convert.ToInt64(gamedb_id);

                if (game_node.Element("Overview") != null)
                    updateItem.description = game_node.Element("Overview").Value;
                if (game_node.Element("ReleaseDate") != null)
                {
                    string strReleaseDate = game_node.Element("ReleaseDate").Value;
                    DateTime releaseDateDate;
                    if (DateTime.TryParse(strReleaseDate, out releaseDateDate))
                    {
                        updateItem.release_year = releaseDateDate.Year;
                    }
                }
                if (game_node.Element("ESRB") != null)
                    updateItem.rating = game_node.Element("ESRB").Value;
                if (game_node.Element("Players") != null)
                    updateItem.players = game_node.Element("Players").Value;

                if (game_node.Element("Co-op") != null)
                {
                    if (game_node.Element("Co-op").Value == "Yes")
                        updateItem.co_op = 1;
                    else
                        updateItem.co_op = 0;
                }
                else
                    updateItem.co_op = 0;

                if (game_node.Element("Publisher") != null)
                    updateItem.publisher = game_node.Element("Publisher").Value;
                if (game_node.Element("Developer") != null)
                    updateItem.developer = game_node.Element("Developer").Value;
                if (game_node.Element("Rating") != null)
                    updateItem.gamedb_stars = Convert.ToDouble( game_node.Element("Rating").Value );

                db.upsertGamesDataset(updateItem);

                infoBox.AppendText(game_fileName + " checked on http://thegamesdb.net/ ID number " + gamedb_id + "\n", Color.WhiteSmoke);
            }
            dataGridGames.FirstDisplayedScrollingRowIndex = selectedrows;
        }
Exemplo n.º 2
0
        //Game Tab
        // get meta data from theGamesDB.net
        private void btnGameOnGameDB_Click(object sender, EventArgs e)
        {
            string platform_name = listboxPlatforms.Text;
            int    selectedrows  = dataGridGames.FirstDisplayedScrollingRowIndex;

            foreach (DataGridViewRow r in dataGridGames.SelectedRows)
            {
                string game_fileName = r.Cells["file_name"].Value as string;
                string game_name     = r.Cells["name"].Value as string;
                long   gamedb_id     = db.getGameDB_ID(platform_id, game_fileName);

                if (gamedb_id == 0)
                {
                    string        searchString  = Regex.Replace(game_name, "(\\[.*\\])|(\\(.*\\))", ""); /// Remove all the text between square and round brackets
                    GameDB_Search gameDB_Search = new GameDB_Search(searchString, platform_name, game_fileName);

                    if (gameDB_Search.ShowDialog() == DialogResult.OK)
                    {
                        gamedb_id = Convert.ToInt64(gameDB_Search.ReturnedID);
                    }
                    else
                    {
                        continue;
                    }
                    // Write new gamedb_id to table
                    // var command = new SQLiteCommand("update games set gamedb_id = @gamedb_id where platform_id = @platform_id and file_name = @file_name");
                    // command.Parameters.AddWithValue("@gamedb_id", gamedb_id);
                    // command.Parameters.AddWithValue("@file_name", game_fileName);
                    // command.Parameters.AddWithValue("@platform_id", platform_id);
                    // db.sqlExecute(command);
                }


                // get xml for game from gamesdb.net
                string       url          = string.Format("http://thegamesdb.net/api/GetGame.php?id={0}", gamedb_id);
                string       xml          = new WebClient().DownloadString(url);
                StringReader stringReader = new StringReader(xml);
                XDocument    xmlDoc       = XDocument.Load(stringReader);
                XElement     game_node    = xmlDoc.Descendants("Game").First();

                GameDataItem updateItem = new GameDataItem(platform_id, game_fileName);
                updateItem.gamedb_id = Convert.ToInt64(gamedb_id);

                if (game_node.Element("Overview") != null)
                {
                    updateItem.description = game_node.Element("Overview").Value;
                }
                if (game_node.Element("ReleaseDate") != null)
                {
                    string   strReleaseDate = game_node.Element("ReleaseDate").Value;
                    DateTime releaseDateDate;
                    if (DateTime.TryParse(strReleaseDate, out releaseDateDate))
                    {
                        updateItem.release_year = releaseDateDate.Year;
                    }
                }
                if (game_node.Element("ESRB") != null)
                {
                    updateItem.rating = game_node.Element("ESRB").Value;
                }
                if (game_node.Element("Players") != null)
                {
                    updateItem.players = game_node.Element("Players").Value;
                }

                if (game_node.Element("Co-op") != null)
                {
                    if (game_node.Element("Co-op").Value == "Yes")
                    {
                        updateItem.co_op = 1;
                    }
                    else
                    {
                        updateItem.co_op = 0;
                    }
                }
                else
                {
                    updateItem.co_op = 0;
                }

                if (game_node.Element("Publisher") != null)
                {
                    updateItem.publisher = game_node.Element("Publisher").Value;
                }
                if (game_node.Element("Developer") != null)
                {
                    updateItem.developer = game_node.Element("Developer").Value;
                }
                if (game_node.Element("Rating") != null)
                {
                    updateItem.gamedb_stars = Convert.ToDouble(game_node.Element("Rating").Value);
                }

                db.upsertGamesDataset(updateItem);


                infoBox.AppendText(game_fileName + " checked on http://thegamesdb.net/ ID number " + gamedb_id + "\n", Color.WhiteSmoke);
            }
            dataGridGames.FirstDisplayedScrollingRowIndex = selectedrows;
        }