Exemplo n.º 1
0
        public static bool RemoveInvalidRomsEntries(Platform platform = null)
        {
            bool result = false;

            List <Rom> roms = new List <Rom>();

            if (platform == null)
            {
                roms = RomBusiness.GetAll();
            }
            else
            {
                roms = RomBusiness.GetAll(platform);
            }

            List <Rom> romList = new List <Rom>();

            foreach (Rom rom in roms)
            {
                if (!File.Exists(rom.FileName))
                {
                    romList.Add(rom);
                    RemoveRomPics(rom);
                    result = true;
                }
            }

            RomBusiness.DeleteRom(romList);

            return(result);
        }
Exemplo n.º 2
0
        public static List <Rom> FilterRoms(Filter filter)
        {
            List <Rom> FilteredRoms = new List <Rom>();
            //List<Platform> platforms = new List<Platform>();
            List <string> platforms = new List <string>();

            if (filter.text.StartsWith("p:"))
            {
                var text = "";
                platforms   = GetPlatforms(filter.text, out text);
                filter.text = text;
            }

            FilteredRoms = RomBusiness.GetAll();

            if (string.IsNullOrEmpty(filter.text) &&
                string.IsNullOrEmpty(filter.platform) &&
                string.IsNullOrEmpty(filter.label) &&
                string.IsNullOrEmpty(filter.genre) &&
                string.IsNullOrEmpty(filter.publisher) &&
                string.IsNullOrEmpty(filter.developer) &&
                string.IsNullOrEmpty(filter.year) &&
                string.IsNullOrEmpty(filter.status) &&
                !filter.favorite &&
                filter.arcade &&
                filter.console &&
                filter.handheld &&
                filter.cd &&
                platforms.Count == 0)
            {
                return(FilteredRoms);
            }

            try
            {
                if (platforms.Count > 0)
                {
                    var filterRoms = FilteredRoms.Where(x => x.Platform != null && platforms.Contains(x.Platform.Name.ToLower())).ToList();
                    FilteredRoms = filterRoms;
                }
                else if (!string.IsNullOrEmpty(filter.platform))
                {
                    var filterRoms = filter.platform == "<none>" ? FilteredRoms.Where(x => x.Platform == null).ToList() : FilteredRoms.Where(x => x.Platform != null && x.Platform.Name == filter.platform).ToList();
                    FilteredRoms = filterRoms;
                }

                if (!string.IsNullOrEmpty(filter.genre))
                {
                    var filterRoms = filter.genre == "<none>" ? FilteredRoms.Where(x => x.Genre == null).ToList() : FilteredRoms.Where(x => x.Genre != null && x.Genre.Name == filter.genre).ToList();
                    FilteredRoms = filterRoms;
                }

                if (!string.IsNullOrEmpty(filter.status))
                {
                    var filterRoms = filter.status == "<none>" ? FilteredRoms.Where(x => x.Status.Status == string.Empty).ToList() : FilteredRoms.Where(x => x.Status != null && x.Status.Status == filter.status).ToList();
                    FilteredRoms = filterRoms;
                }

                if (!string.IsNullOrEmpty(filter.label))
                {
                    var filterRoms = filter.label == "<none>" ? FilteredRoms.Where(x => x.RomLabels == null || x.RomLabels == null).ToList() : FilteredRoms.Where(x => x.RomLabels != null && x.RomLabels.Labels.Any(l => l == filter.label)).ToList();
                    FilteredRoms = filterRoms;
                }

                if (!string.IsNullOrEmpty(filter.publisher))
                {
                    var filterRoms = filter.publisher == "<none>" ? FilteredRoms.Where(x => x.Publisher == string.Empty).ToList() : FilteredRoms.Where(x => x.Publisher == filter.publisher).ToList();
                    FilteredRoms = filterRoms;
                }

                if (!string.IsNullOrEmpty(filter.developer))
                {
                    var filterRoms = filter.developer == "<none>" ? FilteredRoms.Where(x => x.Developer == string.Empty).ToList() : FilteredRoms.Where(x => x.Developer == filter.developer).ToList();
                    FilteredRoms = filterRoms;
                }

                if (!string.IsNullOrEmpty(filter.year))
                {
                    var filterRoms = filter.year == "<none>" ? FilteredRoms.Where(x => x.YearReleased == string.Empty).ToList() : FilteredRoms.Where(x => x.YearReleased == filter.year).ToList();
                    FilteredRoms = filterRoms;
                }

                if (!string.IsNullOrEmpty(filter.text))
                {
                    var filterRoms = new List <Rom>();

                    if (filter.textType == "Starts with")
                    {
                        filterRoms = FilteredRoms.Where(x => x.Name.ToLower().StartsWith(filter.text.ToLower()) || (x.Series != null && x.Series.ToLower().StartsWith(filter.text.ToLower()))).ToList();
                    }
                    else if (filter.textType == "Ends with")
                    {
                        filterRoms = FilteredRoms.Where(x => x.Name.ToLower().EndsWith(filter.text.ToLower()) || (x.Series != null && x.Series.ToLower().EndsWith(filter.text.ToLower()))).ToList();
                    }
                    else
                    {
                        filterRoms = FilteredRoms.Where(x => x.Name.ToLower().Contains(filter.text.ToLower()) || (x.Series != null && x.Series.ToLower().Contains(filter.text.ToLower()))).ToList();
                    }

                    FilteredRoms = filterRoms;
                }

                if (filter.favorite)
                {
                    var filterRoms = FilteredRoms.Where(x => x.Favorite).ToList();
                    FilteredRoms = filterRoms;
                }

                if (filter.arcade || filter.console || filter.handheld || filter.cd)
                {
                    FilteredRoms = FilteredRoms.Where(x => (filter.arcade && x.Platform.Arcade) ||
                                                      (filter.console && x.Platform.Console) ||
                                                      (filter.handheld && x.Platform.Handheld) ||
                                                      (filter.cd && x.Platform.CD)
                                                      ).ToList();
                }
            }
            catch (Exception ex)
            {
            }

            return(FilteredRoms);
        }