예제 #1
0
        private void load(Game game)
        {
            //We add the game's tags to the main list of tags
            //We also add the game to the Tag/Games dictionary
            if (game.tags != null)
            {
                foreach (String tag in game.tags)
                {
                    if (!listbox_tags.Items.Contains(tag))
                    {
                        listbox_tags.Items.Add(tag);
                    }

                    if (games_by_tag.ContainsKey(tag))
                    {
                        games_by_tag[tag].Add(game);
                    }
                    else
                    {
                        games_by_tag.Add(tag, new List<Game>());
                        games_by_tag[tag].Add(game);
                    }
                }
            }

            //We do the same with genres/categories
            if (game.genres != null)
            {
                foreach (String cat in game.genres)
                {
                    if (!listbox_categories.Items.Contains(cat))
                    {
                        listbox_categories.Items.Add(cat);
                    }

                    if (games_by_genre.ContainsKey(cat))
                    {
                        games_by_genre[cat].Add(game);
                    }
                    else
                    {
                        games_by_genre.Add(cat, new List<Game>());
                        games_by_genre[cat].Add(game);
                    }
                }
            }

            //We add the game's ID to the list of all IDs
            if(!ids.Contains(Int32.Parse(game.id))) ids.Add(Int32.Parse(game.id));

            //Update status bar
            toolStripStatusLabel1.Text = games_by_genre.Count + " Categories";
            toolStripStatusLabel2.Text = games_by_tag.Count + " Tags";
            toolStripStatusLabel3.Text = games.Count + " Games";
        }
예제 #2
0
        private void getNewGames_Click(object sender, EventArgs e)
        {
            //Like getAllGames, but we check if the game already exists using the list of IDs
            if (!String.IsNullOrEmpty(textUserName.Text))
            {
                WebClient x = new WebClient();
                x.Encoding = Encoding.UTF8;
                x.Headers.Add(HttpRequestHeader.Cookie, "birthtime=-2208959999");

                string source = x.DownloadString("http://steamcommunity.com/id/" + textUserName.Text + "/games/?tab=all");
                //MatchCollection matches = Regex.Matches(source, "appid\":(\\d+),\"name\":\"(.*?)\",\"logo", RegexOptions.IgnoreCase);
                //MatchCollection matches = Regex.Matches(source, "appid\":(\\d+),\"name\":\"(.*?)\",\"logo.*?friendlyURL\":.+?,\"(.*?)\":\"(.+?)\"", RegexOptions.IgnoreCase);
                MatchCollection matches = Regex.Matches(source, "{\"appid\":(\\d+),\"name\":\"(.+?)\"(.*?)}(.*?)}", RegexOptions.IgnoreCase);

                if (matches.Count > 0)
                {
                    foreach (Match ma in matches)
                    {
                        Game aux_game = new Game();
                        aux_game.id = WebUtility.HtmlDecode(ma.Groups[1].Value.Trim());;
                        aux_game.name = WebUtility.HtmlDecode(ma.Groups[2].Value.Trim());
                        //Because some games have unicode characters, we look for \u followed by 4 characters and convert that into a single character
                        Regex rx = new Regex(@"\\[uU]([0-9A-Fa-f]{4})");
                        aux_game.name = rx.Replace(aux_game.name, match => ((char)Int32.Parse(match.Value.Substring(2), NumberStyles.HexNumber)).ToString());
                        Match hours = Regex.Match(WebUtility.HtmlDecode(ma.Groups[3].Value.Trim()), "hours_forever\":\"(.+?)\"");
                        if (hours.Success)
                        {
                            float hours_played = float.Parse(hours.Value.Trim());
                            if (hours_played <= 1)
                            {
                                aux_game.tags = new List<string>();
                                aux_game.tags.Add("Less than 1h played");
                            }
                        }
                        //If we don't get "hours_forever" that means we haven't played it
                        else
                        {
                            aux_game.tags = new List<string>();
                            aux_game.tags.Add("Less than 1h played");
                            aux_game.tags.Add("Never played");
                        }
                        if (ids.Contains(Int32.Parse(aux_game.id)))
                        {
                            Console.Write("Game " + aux_game.name + " (" + aux_game.id + ") already exists\n");
                        }
                        else
                        {
                            //If it doesn't exist, we ask the user if they want to add the game to the list
                            Console.Write("New game found: " + aux_game.name + "(" + aux_game.id + ")\n");
                            DialogResult dialogResult = MessageBox.Show("Do you want to add " + aux_game.name + " (" + aux_game.id + ") to the list?", "New game found", MessageBoxButtons.YesNoCancel);
                            switch(dialogResult)
                            {
                                case DialogResult.Cancel:
                                        return;
                                case DialogResult.Yes:
                                    Console.Write("    Adding game to list\n");
                                    games.Add(aux_game);
                                    load(aux_game);
                                    break;
                                case DialogResult.No:
                                    Console.Write("    Skipping game\n");
                                    break;
                            }
                        }
                    }
                    //We update all the listboxes in the form
                    listbox_games.DataSource = null;
                    generate_list();
                }
            }
        }
예제 #3
0
        private Game get_tags_genres(String id)
        {
            //We load the game's store page and get the name, genres and tags
            WebClient x = new WebClient();
            x.Encoding = Encoding.UTF8;
            x.Headers.Add(HttpRequestHeader.Cookie, "birthtime=-2208959999");

            string source = x.DownloadString("http://store.steampowered.com/app/" + id);

            Game aux_game = new Game();
            //data-appid="31290"
            Match match = Regex.Match(source, "data-appid=\"(\\d+?)\"", RegexOptions.IgnoreCase);
            aux_game.name = "";
            aux_game.id = id;

            if (match.Success)
            {
                string appid = WebUtility.HtmlDecode(match.Groups[1].Value);
                //We check if the ID returned by the store is the same as the game's ID. We can remove things like Back to the future episodes this way, or duplicated games
                if (appid == id)
                {
                    match = Regex.Match(source, "<div class=\"apphub_AppName\">(.+)</div>", RegexOptions.IgnoreCase);
                    string title = WebUtility.HtmlDecode(match.Groups[1].Value);
                    //Because some games have unicode characters, we look for \u followed by 4 characters and convert that into a single character
                    Regex rx = new Regex(@"\\[uU]([0-9A-Fa-f]{4})");
                    title = rx.Replace(title, matchutf => ((char)Int32.Parse(matchutf.Value.Substring(2), NumberStyles.HexNumber)).ToString());

                    aux_game.name = title;
                    aux_game.id = id;
                    Console.Write("Processing data for " + aux_game.name + " with ID: " + aux_game.id + "\n");
                    aux_game.genres = new List<string>();
                    aux_game.tags = new List<string>();

                    Regex regTags = new Regex("<a[^>]*class=\\\"app_tag\\\"[^>]*>([^<]*)</a>", RegexOptions.IgnoreCase | RegexOptions.Compiled);

                    //We add each found tag to the game
                    MatchCollection matches = regTags.Matches(source);
                    if (matches.Count > 0)
                    {
                        foreach (Match ma in matches)
                        {
                            string tag = WebUtility.HtmlDecode(ma.Groups[1].Value.Trim()); ;
                            if (!string.IsNullOrWhiteSpace(tag))
                            {
                                aux_game.tags.Add(tag);
                            }
                        }
                    }

                    string regexp = "\"description\":\"(.*?)\"";
                    source = x.DownloadString("http://store.steampowered.com/api/appdetails/?appids=" + id);

                    //We add each found genre to the game
                    matches = Regex.Matches(source, regexp);
                    if (matches.Count > 0)
                    {
                        foreach (Match ma in matches)
                        {
                            string genre = WebUtility.HtmlDecode(ma.Groups[1].Value.Trim()); ;
                            if (!string.IsNullOrWhiteSpace(genre))
                            {
                                aux_game.genres.Add(genre);
                            }
                        }
                    }
                }
                else
                {
                    aux_game.id = "-1";
                }
            }

            return aux_game;
        }
예제 #4
0
        private void getAllGames_Click(object sender, EventArgs e)
        {
            //We get all the user's games
            if (!String.IsNullOrEmpty(textUserName.Text))
            {
                //Check user profile and obtain all games and ids
                WebClient x = new WebClient();
                x.Encoding = Encoding.UTF8;
                x.Headers.Add(HttpRequestHeader.Cookie, "birthtime=-2208959999");

                string source = x.DownloadString("http://steamcommunity.com/id/" + textUserName.Text + "/games/?tab=all");
                //MatchCollection matches = Regex.Matches(source, "appid\":(\\d+),\"name\":\"(.*?)\",\"logo", RegexOptions.IgnoreCase);
                //appid\":(\\d+),\"name\":\"(.*?)\",\"logo.*friendlyURL\":.+?,\"(.*?)\":\"(.+?)\"
                //MatchCollection matches = Regex.Matches(source, "appid\":(\\d+),\"name\":\"(.*?)\",\"logo.*?friendlyURL\":.+?,\"(.*?)\":\"(.+?)\",\"(.*?)\":(.+?)\"", RegexOptions.IgnoreCase);
                MatchCollection matches = Regex.Matches(source, "{\"appid\":(\\d+),\"name\":\"(.+?)\"(.*?)}(.*?)}", RegexOptions.IgnoreCase);

                games.Clear();
                listbox_categories.Items.Clear();
                listbox_tags.Items.Clear();

                games_by_genre.Clear();
                games_by_tag.Clear();

                //For each result, we create a game with the obtained name and ID and add it to the list
                if (matches.Count > 0)
                {
                    foreach (Match ma in matches)
                    {
                        Game aux_game = new Game();
                        aux_game.id = WebUtility.HtmlDecode(ma.Groups[1].Value.Trim());;
                        aux_game.name = WebUtility.HtmlDecode(ma.Groups[2].Value.Trim());
                        //Because some games have unicode characters, we look for \u followed by 4 characters and convert that into a single character
                        Regex rx = new Regex(@"\\[uU]([0-9A-Fa-f]{4})");
                        aux_game.name = rx.Replace(aux_game.name, match => ((char)Int32.Parse(match.Value.Substring(2), NumberStyles.HexNumber)).ToString());
                        Match hours = Regex.Match(WebUtility.HtmlDecode(ma.Groups[3].Value.Trim()), "hours_forever\":\"(.+?)\"");
                        if(hours.Success)
                        {
                            float hours_played = float.Parse(hours.Value.Trim());
                            if (hours_played <= 1)
                            {
                                aux_game.tags = new List<string>();
                                aux_game.tags.Add("Less than 1h played");
                            }
                        }
                        //If we don't get "hours_forever" that means we haven't played it
                        else
                        {
                                aux_game.tags = new List<string>();
                                aux_game.tags.Add("Less than 1h played");
                                aux_game.tags.Add("Never played");
                        }
                        games.Add(aux_game);
                        load(aux_game);
                    }
                }
                //We update all the listboxes in the form
                listbox_games.DataSource = null;
                generate_list();
            }
        }