Exemplo n.º 1
0
        public void PreviewGameData(ComparableMetadatGameData metadata)
        {
            ShowCheckBoxes = true;

            var diffItems = GetDisplayDiffFields(EditingGame, metadata);

            if (diffItems.HasItems())
            {
                var comp = new MetadataComparisonViewModel(
                    database,
                    new MetadataComparisonWindowFactory(),
                    dialogs,
                    resources,
                    EditingGame,
                    metadata,
                    diffItems);

                if (comp.OpenView() == true)
                {
                    LoadNewMetadata(comp.ResultMetadata);
                }
            }
            else
            {
                LoadNewMetadata(metadata);
            }
        }
Exemplo n.º 2
0
        private List <GameField> GetDisplayDiffFields(Game oldGame, ComparableMetadatGameData newGame)
        {
            var diffFields = new List <GameField>();

            void checkListChanged <T>(List <T> oldData, List <T> newData, GameField field) where T : DatabaseObject
            {
                if (!oldData.HasItems() && newData.HasItems())
                {
                    diffFields.Add(field);
                    return;
                }

                if (newData.HasItems() && oldData.HasItems() && !oldData.Select(a => a.Id).IsListEqual(newData.Select(b => b.Id)))
                {
                    diffFields.Add(field);
                }
            }

            //void checkItemChanged<T>(T source, string other, GameField field) where T : DatabaseObject
            //{
            //    if (!other.IsNullOrEmpty())
            //    {
            //        if (source != null && !string.Equals(source.Name, other, StringComparison.OrdinalIgnoreCase))
            //        {
            //            diffFields.Add(field);
            //        }
            //    }
            //}

            if (!newGame.Name.IsNullOrEmpty())
            {
                if (!oldGame.Name.IsNullOrEmpty() && !string.Equals(oldGame.Name, newGame.Name, StringComparison.OrdinalIgnoreCase))
                {
                    diffFields.Add(GameField.Name);
                }
            }

            if (!newGame.Description.IsNullOrEmpty())
            {
                if (!oldGame.Description.IsNullOrEmpty() && !string.Equals(oldGame.Description, newGame.Description, StringComparison.Ordinal))
                {
                    diffFields.Add(GameField.Description);
                }
            }

            checkListChanged(oldGame.AgeRatings, newGame.AgeRatings, GameField.AgeRatings);
            checkListChanged(oldGame.Regions, newGame.Regions, GameField.Regions);
            checkListChanged(oldGame.Series, newGame.Series, GameField.Series);
            checkListChanged(oldGame.Platforms, newGame.Platforms, GameField.Platforms);
            checkListChanged(oldGame.Developers, newGame.Developers, GameField.Developers);
            checkListChanged(oldGame.Publishers, newGame.Publishers, GameField.Publishers);
            checkListChanged(oldGame.Genres, newGame.Genres, GameField.Genres);
            checkListChanged(oldGame.Tags, newGame.Tags, GameField.Tags);
            checkListChanged(oldGame.Features, newGame.Features, GameField.Features);

            if (newGame.ReleaseDate != null)
            {
                if (oldGame.ReleaseDate != null && oldGame.ReleaseDate != newGame.ReleaseDate)
                {
                    diffFields.Add(GameField.ReleaseDate);
                }
            }

            if (newGame.Links.HasItems())
            {
                if (oldGame.Links.HasItems() && !oldGame.Links.IsListEqualExact(newGame.Links))
                {
                    diffFields.Add(GameField.Links);
                }
            }

            if (newGame.CriticScore != null)
            {
                if (oldGame.CriticScore != null && oldGame.CriticScore != newGame.CriticScore)
                {
                    diffFields.Add(GameField.CriticScore);
                }
            }

            if (newGame.CommunityScore != null)
            {
                if (oldGame.CommunityScore != null && oldGame.CommunityScore != newGame.CommunityScore)
                {
                    diffFields.Add(GameField.CommunityScore);
                }
            }

            if (newGame.Icon != null && !oldGame.Icon.IsNullOrEmpty())
            {
                var newIcon = ProcessMetadataFile(newGame.Icon, tempIconFileName);
                if (newIcon != null)
                {
                    var currentPath = ImageSourceManager.GetImagePath(EditingGame.Icon);
                    if (currentPath.IsNullOrEmpty() ||
                        !File.Exists(currentPath) ||
                        !FileSystem.AreFileContentsEqual(newIcon, currentPath))
                    {
                        newGame.Icon = new MetadataFile(newIcon);
                        diffFields.Add(GameField.Icon);
                    }
                    else
                    {
                        newGame.Icon = null;
                    }
                }
                else
                {
                    newGame.Icon = null;
                }
            }

            if (newGame.CoverImage != null && !oldGame.CoverImage.IsNullOrEmpty())
            {
                var newCover = ProcessMetadataFile(newGame.CoverImage, tempCoverFileName);
                if (newCover != null)
                {
                    var currentPath = ImageSourceManager.GetImagePath(EditingGame.CoverImage);
                    if (currentPath.IsNullOrEmpty() ||
                        !File.Exists(currentPath) ||
                        !FileSystem.AreFileContentsEqual(newCover, currentPath))
                    {
                        newGame.CoverImage = new MetadataFile(newCover);
                        diffFields.Add(GameField.CoverImage);
                    }
                    else
                    {
                        newGame.CoverImage = null;
                    }
                }
                else
                {
                    newGame.CoverImage = null;
                }
            }

            if (newGame.BackgroundImage != null && !oldGame.BackgroundImage.IsNullOrEmpty())
            {
                var newBack = ProcessMetadataFile(newGame.BackgroundImage, tempBackgroundFileName);
                if (newBack != null)
                {
                    var currentPath = ImageSourceManager.GetImagePath(EditingGame.BackgroundImage);
                    if (currentPath.IsNullOrEmpty() ||
                        !File.Exists(currentPath) ||
                        !FileSystem.AreFileContentsEqual(newBack, currentPath))
                    {
                        newGame.BackgroundImage = new MetadataFile(newBack);
                        diffFields.Add(GameField.BackgroundImage);
                    }
                    else
                    {
                        newGame.BackgroundImage = null;
                    }
                }
                else
                {
                    newGame.BackgroundImage = null;
                }
            }

            return(diffFields);
        }
Exemplo n.º 3
0
        ComparableMetadatGameData ConvertGameInfo(GameMetadata game)
        {
            var result = new ComparableMetadatGameData
            {
                Name           = game.Name,
                Description    = game.Description,
                ReleaseDate    = game.ReleaseDate,
                CommunityScore = game.CommunityScore,
                CriticScore    = game.CriticScore,
                Links          = game.Links
            };

            if (game.Genres.HasItems())
            {
                result.Genres = (database.Genres as GenresCollection).GetOrGenerate(game.Genres).Where(a => a != null).ToList();
            }

            if (game.Developers.HasItems())
            {
                result.Developers = (database.Companies as CompaniesCollection).GetOrGenerate(game.Developers).Where(a => a != null).ToList();
            }

            if (game.Publishers.HasItems())
            {
                result.Publishers = (database.Companies as CompaniesCollection).GetOrGenerate(game.Publishers).Where(a => a != null).ToList();
            }

            if (game.Tags.HasItems())
            {
                result.Tags = (database.Tags as TagsCollection).GetOrGenerate(game.Tags).Where(a => a != null).ToList();
            }

            if (game.Features.HasItems())
            {
                result.Features = (database.Features as FeaturesCollection).GetOrGenerate(game.Features).Where(a => a != null).ToList();
            }

            if (game.AgeRatings.HasItems())
            {
                result.AgeRatings = (database.AgeRatings as AgeRatingsCollection).GetOrGenerate(game.AgeRatings).Where(a => a != null).ToList();
            }

            if (game.Series.HasItems())
            {
                result.Series = (database.Series as SeriesCollection).GetOrGenerate(game.Series).Where(a => a != null).ToList();
            }

            if (game.Regions.HasItems())
            {
                result.Regions = (database.Regions as RegionsCollection).GetOrGenerate(game.Regions).Where(a => a != null).ToList();
            }

            if (game.Platforms.HasItems())
            {
                result.Platforms = (database.Platforms as PlatformsCollection).GetOrGenerate(game.Platforms).Where(a => a != null).ToList();
            }

            if (game.CoverImage != null)
            {
                result.CoverImage = new MetadataFile(ProcessMetadataFile(game.CoverImage, tempCoverFileName));
            }

            if (game.Icon != null)
            {
                result.Icon = new MetadataFile(ProcessMetadataFile(game.Icon, tempIconFileName));
            }

            if (game.BackgroundImage != null)
            {
                result.BackgroundImage = new MetadataFile(ProcessMetadataFile(game.BackgroundImage, tempBackgroundFileName));
            }

            return(result);
        }
Exemplo n.º 4
0
        private void LoadNewMetadata(ComparableMetadatGameData newData)
        {
            if (!string.IsNullOrEmpty(newData.Name))
            {
                EditingGame.Name = newData.Name;
            }

            if (newData.Developers.HasItems())
            {
                AddNewAndSetItems(newData.Developers, database.Companies, Developers);
            }

            if (newData.Publishers.HasItems())
            {
                AddNewAndSetItems(newData.Publishers, database.Companies, Publishers);
            }

            if (newData.Genres.HasItems())
            {
                AddNewAndSetItems(newData.Genres, database.Genres, Genres);
            }

            if (newData.Tags.HasItems())
            {
                AddNewAndSetItems(newData.Tags, database.Tags, Tags);
            }

            if (newData.Features.HasItems())
            {
                AddNewAndSetItems(newData.Features, database.Features, Features);
            }

            if (newData.AgeRatings.HasItems())
            {
                AddNewAndSetItems(newData.AgeRatings, database.AgeRatings, AgeRatings);
            }

            if (newData.Regions.HasItems())
            {
                AddNewAndSetItems(newData.Regions, database.Regions, Regions);
            }

            if (newData.Series.HasItems())
            {
                AddNewAndSetItems(newData.Series, database.Series, Series);
            }

            if (newData.Platforms.HasItems())
            {
                AddNewAndSetItems(newData.Platforms, database.Platforms, Platforms);
            }

            if (newData.ReleaseDate != null)
            {
                EditingGame.ReleaseDate = newData.ReleaseDate;
            }

            if (!newData.Description.IsNullOrEmpty())
            {
                EditingGame.Description = newData.Description;
            }

            if (newData.Links.HasItems())
            {
                EditingGame.Links = newData.Links.ToObservable();
            }

            if (newData.CriticScore != null)
            {
                EditingGame.CriticScore = newData.CriticScore;
            }

            if (newData.CommunityScore != null)
            {
                EditingGame.CommunityScore = newData.CommunityScore;
            }

            if (newData.CoverImage != null)
            {
                var newCover = ProcessMetadataFile(newData.CoverImage, tempCoverFileName);
                if (newCover != null)
                {
                    EditingGame.CoverImage = newCover;
                }
            }

            if (newData.Icon != null)
            {
                var newIcon = ProcessMetadataFile(newData.Icon, tempIconFileName);
                if (newIcon != null)
                {
                    EditingGame.Icon = newIcon;
                }
            }

            if (newData.BackgroundImage != null)
            {
                var newBackground = ProcessMetadataFile(newData.BackgroundImage, tempBackgroundFileName);
                if (newBackground != null)
                {
                    EditingGame.BackgroundImage = newBackground;
                }
            }
        }