Example #1
0
        /// <summary>
        /// Return a search list
        /// </summary>
        /// <param name="systemId"></param>
        /// <param name="gameName"></param>
        /// <returns></returns>
        public List <SearchOrdering> ShowPlatformGames(int systemId, string gameName)
        {
            // get a list with all games for this system
            SystemCollection = PlatformGames.Where(a => GSystem.GetMedLaunchSystemIdFromGDBPlatformId(a.pid) == systemId).ToList();
            // Match all words and return a list ordered by higest matches
            List <SearchOrdering> searchResult = OrderByMatchedWords(StripSymbols(gameName.ToLower()));

            return(searchResult);
        }
Example #2
0
        public List <SearchOrdering> ShowPlatformGamesBySub(int systemId, GamesLibraryModel game)
        {
            // get gamesdb sub entry
            var subIdObj = GSystem.GetSubSystems()
                           .Where(a => a.systemName == game.System).FirstOrDefault();

            if (subIdObj == null)
            {
                // no sub found
                SystemCollection = PlatformGames.Where(a => GSystem.GetMedLaunchSystemIdFromGDBPlatformId(a.pid) == systemId).ToList();
            }
            else
            {
                // sub found
                SystemCollection = PlatformGames.Where(a => a.pid == subIdObj.theGamesDBPlatformId.First()).ToList();
            }

            // megadrive check
            if (game.System == "Sega Mega Drive/Genesis")
            {
                if (game.Country == "US" ||
                    game.Country == "USA")
                {
                    SystemCollection = SystemCollection.Where(a => a.pid == 18).ToList();
                }
                else if (game.Country == "EU" || game.Country == "EUR" ||
                         game.Country == "JP" || game.Country == "JAP" || game.Country == "JPN")
                {
                    SystemCollection = SystemCollection.Where(a => a.pid == 36).ToList();
                }
                else
                {
                    // show all games
                }
            }

            // Match all words and return a list ordered by higest matches
            List <SearchOrdering> searchResult = OrderByMatchedWords(StripSymbols(game.Game.ToLower()));

            return(searchResult);
        }
Example #3
0
        public ICollection <ScraperMaster> SearchGameLocal(string gameName, int systemId, int gameId)
        {
            SearchString            = gameName;
            LocalIterationCount     = 0;
            WorkingSearchCollection = new List <ScraperMaster>();
            SearchCollection        = new List <ScraperMaster>();

            if (gameName == null || gameName.Trim() == "")
            {
                return(SearchCollection);
            }

            if (systemId == 0 || gameId == 0)
            {
                return(SearchCollection);
            }

            if (SearchString.Contains("[PD]") || SearchString.Contains("(PD)") || SearchString.Contains("SC-3000") || SearchString.Contains("BIOS"))
            {
                // ignore public domain games
                return(SearchCollection);
            }

            // convert pce-cd systemid
            if (systemId == 18)
            {
                systemId = 7;
            }

            // get a list with all games for this system

            Game gam = Game.GetGame(gameId);

            if (gam.subSystemId != null && gam.subSystemId > 0)
            {
                // sub found
                var sub = GSystem.GetSubSystems().Where(a => a.systemId == gam.subSystemId.Value).FirstOrDefault();
                SystemCollection = PlatformGames.Where(a => a.pid == sub.theGamesDBPlatformId.First()).ToList();
            }
            else
            {
                //sub not found
                SystemCollection = PlatformGames.Where(a => GSystem.GetMedLaunchSystemIdFromGDBPlatformId(a.pid) == systemId).ToList();
            }

            // genesis/megadrive region selection
            if (gam.systemId == 4)
            {
                if (
                    gam.Country != null &&
                    (
                        gam.Country.ToUpper() == "US" ||
                        gam.Country.ToUpper() == "USA" ||
                        gam.Country.ToUpper() == "U"
                    )
                    )
                {
                    SystemCollection = SystemCollection.Where(a => a.pid == 18).ToList();
                }
                else if
                (
                    gam.Country != null &&
                    (
                        gam.Country.ToUpper() == "EU" ||
                        gam.Country.ToUpper() == "EUR" ||
                        gam.Country.ToUpper() == "EUROPE" ||
                        gam.Country.ToUpper() == "JP" ||
                        gam.Country.ToUpper() == "JAP" ||
                        gam.Country.ToUpper() == "J" ||
                        gam.Country.ToUpper() == "JPN"
                    )
                )
                {
                    SystemCollection = SystemCollection.Where(a => a.pid == 36).ToList();
                }
                else
                {
                    // Region not detected - use globalsettings choice
                    if (_GlobalSettings.preferGenesis == true)
                    {
                        SystemCollection = SystemCollection.Where(a => a.pid == 18).ToList();
                    }
                    else
                    {
                        SystemCollection = SystemCollection.Where(a => a.pid == 36).ToList();
                    }
                }
            }


            // Match all words and return a list ordered by higest matches
            List <SearchOrdering> searchResult = OrderByMatchedWords(StripSymbols(gameName.ToLower()));

            // get max value in the list
            var maxValueRecord = searchResult.OrderByDescending(v => v.Matches).FirstOrDefault();

            if (maxValueRecord == null)
            {
                SearchCollection = (from a in searchResult
                                    select a.Game).ToList();
            }
            else
            {
                int maxValue = maxValueRecord.Matches;
                // select all records that have the max value

                List <SearchOrdering> matches = (from a in searchResult
                                                 where (a.Matches == maxValue) // || a.Matches == maxValue - 1)
                                                 select a).ToList();
                SearchCollection = (from a in matches
                                    select a.Game).ToList();
                if (matches.Count == 1)
                {
                    // single entry returned
                    List <ScraperMaster> single = (from a in matches
                                                   select a.Game).ToList();
                    return(single);
                }
                if (matches.Count == 0)
                {
                    return(null);
                }
            }


            // Multiple records returned - continue

            // match order of words starting with the first and incrementing
            List <ScraperMaster> m = MatchOneWordAtATime(SearchCollection, StripSymbols(gameName.ToLower()));

            if (m.Count == 1)
            {
                return(m);
            }
            if (m.Count > 1)
            {
                SearchCollection = m;
            }


            if (SearchCollection.Count == 2 && _GlobalSettings.preferGenesis == true)
            {
                // 2 records returned - check whether they match exactly
                string first = (from a in SearchCollection
                                select a.GDBTitle).First();
                string last = (from a in SearchCollection
                               select a.GDBTitle).Last();
                if (first == last)
                {
                    // looks like the same game - perhaps different systems on the games db (ie - Megadrive / Genesis) - return the first result
                    ScraperMaster pg = (from a in SearchCollection
                                        select a).First();
                    List <ScraperMaster> l = new List <ScraperMaster>();
                    l.Add(pg);
                    return(l);
                }
            }

            // still no definiate match found
            // run levenshetein fuzzy search on SearchCollection - 10 iterations
            List <ScraperMaster> lg = LevenIteration(SearchCollection, StripSymbols(gameName.ToLower()));

            return(lg);
        }