Пример #1
0
        public void ProcessGame(string romName, string hash, string relPath, string fileName, string extension)
        {
            Game newGame = new Game();

            // check whether game already exists (by gameName and systemId)
            Game chkGame = (from g in Games
                            where g.systemId == systemId && g.gameName == romName //&& g.archiveGame == archiveGame
                            select g).FirstOrDefault();

            // filter DAT by systemId
            List <DATMerge> lookup = DATMerge.FilterByMedLaunchSystemId(DAT, systemId);

            // lookup game in master dat - order by DATProviderId (so NoIntro first)
            string nHash = hash.ToUpper().Trim().ToString();
            //List<DATMerge> look = lookup.Where(a => a.MD5.ToUpper().Trim() == nHash || a.CRC.ToUpper().Trim() == nHash || a.SHA1.ToUpper().Trim() == nHash).OrderBy(a => a.DatProviderId).ToList();
            List <DATMerge> look = lookup.Where(a =>
                                                (a.MD5 != null && a.MD5.ToUpper().Trim() == nHash) ||
                                                (a.CRC != null && a.CRC.ToUpper().Trim() == nHash) ||
                                                (a.SHA1 != null && a.SHA1.ToUpper().Trim() == nHash)).OrderBy(a => a.DatProviderId).ToList();

            int subSysId = GSystem.GetSubSystemId(systemId, extension);

            if (chkGame == null)
            {
                // does not already exist - create new game
                newGame.configId = 1;

                if (look != null && look.Count > 0)
                {
                    newGame.gameNameFromDAT = look.First().GameName;
                    //newGame.Publisher = look.First().Publisher;
                    //newGame.Year = look.First().Year;
                    newGame.romNameFromDAT    = look.First().RomName;
                    newGame.Copyright         = look.First().Copyright;
                    newGame.Country           = look.First().Country;
                    newGame.DevelopmentStatus = look.First().DevelopmentStatus;
                    newGame.Language          = look.First().Language;
                    newGame.OtherFlags        = look.First().OtherFlags;
                    //newGame.Publisher = look.First().Publisher;
                    //newGame.Year = look.First().Year;
                    //newGame.Developer = look.First().Developer;

                    if (look.First().Year != null && look.First().Year != "")
                    {
                        newGame.Year = look.First().Year;
                    }
                    if (look.First().Publisher != null && look.First().Publisher != "")
                    {
                        newGame.Publisher = look.First().Publisher;
                    }
                    if (look.First().Developer != null && look.First().Developer != "")
                    {
                        newGame.Developer = look.First().Developer;
                    }
                }

                newGame.gameName    = romName;
                newGame.gamePath    = relPath;
                newGame.hidden      = false;
                newGame.isDiskBased = false;
                newGame.isFavorite  = false;
                newGame.systemId    = systemId;
                newGame.CRC32       = hash;

                // check for subsystemid
                if (subSysId > 0)
                {
                    // sub system found
                    newGame.subSystemId = subSysId;
                }

                // add to finaGames list
                RomsToAdd.Add(newGame);
                // increment the added counter
                AddedStats++;
            }
            else
            {
                // matching game found - update it
                if (chkGame.gamePath == relPath && chkGame.hidden == false && (chkGame.CRC32 == hash || chkGame.CRC == hash || chkGame.SHA1 == hash) && chkGame.subSystemId == subSysId)
                {
                    //nothing to update - increment untouched counter
                    UntouchedStats++;
                }
                else
                {
                    newGame = chkGame;
                    // update path in case it has changed location
                    newGame.gamePath = relPath;
                    // mark as not hidden
                    newGame.hidden = false;

                    newGame.CRC32 = hash;
                    if (look != null && look.Count > 0)
                    {
                        newGame.gameNameFromDAT = look.First().GameName;
                        //newGame.Publisher = look.First().Publisher;
                        //newGame.Year = look.First().Year;
                        //newGame.Developer = look.First().Developer;
                        newGame.romNameFromDAT    = look.First().RomName;
                        newGame.Copyright         = look.First().Copyright;
                        newGame.Country           = look.First().Country;
                        newGame.DevelopmentStatus = look.First().DevelopmentStatus;
                        newGame.Language          = look.First().Language;
                        newGame.OtherFlags        = look.First().OtherFlags;

                        if (look.First().Year != null && look.First().Year != "")
                        {
                            newGame.Year = look.First().Year;
                        }
                        if (look.First().Publisher != null && look.First().Publisher != "")
                        {
                            newGame.Publisher = look.First().Publisher;
                        }
                        if (look.First().Developer != null && look.First().Developer != "")
                        {
                            newGame.Developer = look.First().Developer;
                        }
                    }

                    // check for subsystemid
                    if (subSysId > 0)
                    {
                        // sub system found
                        newGame.subSystemId = subSysId;
                    }

                    // add to finalGames list
                    RomsToUpdate.Add(newGame);
                    // increment updated counter
                    UpdatedStats++;
                }

                // remove game from presentGames list - remaining games in this list will be marked as hidden at the end
                presentGames.Remove(chkGame);
            }
        }