Пример #1
0
        public void MatchImage_TestMethod()
        {
            Dictionary <string, Region> imageRegion = new Dictionary <string, Region>();
            var item = @"D:\User\Downloads\1 - Super Famicom Boxart1\4 Nin Shogi.jpg";

            imageRegion.Add(RomFunctions.GetFileName(item), RomFunctions.DetectRegion(item));
            string imageFoundPath;
            var    found = RomFunctions.MatchImages(new string[] { item }, imageRegion, "4-nin Shougi", out imageFoundPath);

            Assert.IsTrue(found);
        }
Пример #2
0
        private void buttonSelectCore_Click(object sender, EventArgs e)
        {
            var            config = ConfigBusiness.GetFolder(Folder.Retroarch);
            OpenFileDialog dialog = new OpenFileDialog();

            if (!string.IsNullOrEmpty(config))
            {
                config = config + "\\" + "cores";

                if (Directory.Exists(config))
                {
                    dialog.InitialDirectory = config;
                }
            }

            dialog.Filter = "Libreto Core | *.dll";

            if (dialog.ShowDialog() == DialogResult.OK)
            {
                var corename = RomFunctions.GetFileName(dialog.FileName);
                textBoxCommand.Text = Values.RetroarchCommand.Replace("[CORE]", corename);
                textBoxEmuName.Text = RomFunctions.FillEmuName(textBoxEmuName.Text, textBoxPath.Text, checkBoxUseRetroarch.Checked, corename);
            }
        }
        private void buttonAdd_Click(object sender, EventArgs e)
        {
            progressBar1.Value = 0;

            if (!Directory.Exists(textBoxDir.Text))
            {
                FormCustomMessage.ShowError("Directory doesn't exists");
                return;
            }

            Platform platform = (Platform)comboBoxChoosePlatform.SelectedItem;
            var      images   = Directory.GetFiles(textBoxDir.Text);
            var      roms     = RomBusiness.GetAll().Where
                                    (x =>
                                    x.Platform != null &&
                                    x.Platform.Name == platform.Name &&
                                    (
                                        (radioButtonBoxart.Checked && string.IsNullOrEmpty(RomFunctions.GetRomPicture(x, Values.BoxartFolder))) ||
                                        (radioButtonTitle.Checked && string.IsNullOrEmpty(RomFunctions.GetRomPicture(x, Values.TitleFolder))) ||
                                        (radioButtonGameplay.Checked && string.IsNullOrEmpty(RomFunctions.GetRomPicture(x, Values.GameplayFolder)))
                                    )
                                    ).ToList();

            int successfulFind = 0;

            progressBar1.Maximum = roms.Count < images.Length ? roms.Count : images.Length;
            string type = radioButtonBoxart.Checked ? Values.BoxartFolder : radioButtonTitle.Checked ? Values.TitleFolder : Values.GameplayFolder;

            Dictionary <string, Region> imageRegion = new Dictionary <string, Region>();

            foreach (var item in images)
            {
                imageRegion.Add(RomFunctions.GetFileName(item), RomFunctions.DetectRegion(item));
            }

            foreach (var rom in roms)
            {
                string imageFoundPath;
                var    found = RomFunctions.MatchImagesExact(images, rom.FileNameNoExt, out imageFoundPath);

                if (found)
                {
                    successfulFind++;

                    if (progressBar1.Value < progressBar1.Maximum)
                    {
                        progressBar1.Value++;
                    }

                    RomFunctions.SavePicture(rom, imageFoundPath, type, checkBoxSaveAsJpg.Checked);
                }
                else
                {
                    found = RomFunctions.MatchImages(images, imageRegion, rom.Name, out imageFoundPath);

                    if (found)
                    {
                        successfulFind++;

                        if (progressBar1.Value < progressBar1.Maximum)
                        {
                            progressBar1.Value++;
                        }

                        RomFunctions.SavePicture(rom, imageFoundPath, type, checkBoxSaveAsJpg.Checked);
                    }
                    else
                    {
                        found = RomFunctions.MatchImages(images, imageRegion, rom.FileNameNoExt, out imageFoundPath);

                        if (found)
                        {
                            successfulFind++;

                            if (progressBar1.Value < progressBar1.Maximum)
                            {
                                progressBar1.Value++;
                            }

                            RomFunctions.SavePicture(rom, imageFoundPath, type, checkBoxSaveAsJpg.Checked);
                        }
                    }
                }
            }

            progressBar1.Value = progressBar1.Maximum;
            FormCustomMessage.ShowSuccess("Number of successful rom pictures saved: " + successfulFind);
            progressBar1.Value = 0;
        }