public static string GetGamesListJSONByPlatform(string platformId, string platformName)
        {
            try
            {
                string games = string.Empty;
                string key   = Functions.LoadAPIKEY();
                string json  = string.Empty;
                var    url   = Values.BaseAPIURL + "/v1/Games/ByPlatformID?apikey=" + key + "&id=" + platformId;

                while (true)
                {
                    using (WebClient client = new WebClient())
                    {
                        client.Encoding = System.Text.Encoding.UTF8;
                        json            = client.DownloadString(new Uri(url));
                    }

                    if (string.IsNullOrEmpty(json))
                    {
                        return(null);
                    }

                    var jobject = (JObject)JsonConvert.DeserializeObject(json);
                    games += jobject.SelectToken("data.games").ToString();

                    var next = jobject.SelectToken("pages.next").ToString();

                    if (string.IsNullOrEmpty(next))
                    {
                        break;
                    }

                    url = next;
                }

                games = games.Replace("][", ",");

                var platform = PlatformBusiness.GetAll().FirstOrDefault(x => x.Name == platformName);

                if (platform != null)
                {
                    if (!Directory.Exists(Values.JsonFolder))
                    {
                        Directory.CreateDirectory(Values.JsonFolder);
                    }

                    File.WriteAllText(Values.JsonFolder + "\\" + platform.Name + ".json", games);
                }

                return(games);
            }
            catch (APIException ex)
            {
                throw new Exception(ex.Message);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
        private void FillPlatformFilter(string platform = "")
        {
            updating = true;

            List <Platform> platforms = PlatformBusiness.GetAllFiltered(checkBoxArcade.Checked, checkBoxConsole.Checked, checkBoxHandheld.Checked, checkBoxCD.Checked).Where(x => x.ShowInFilter).ToList();

            platforms.Insert(0, new Platform()
            {
                Name = ""
            });
            platforms.Insert(1, new Platform()
            {
                Name = "<none>"
            });
            comboBoxPlatform.DataSource = platforms.Select(x => x.Name).ToList();

            if (string.IsNullOrEmpty(platform))
            {
                comboBoxPlatform.SelectedIndex = 0;
            }
            else
            {
                comboBoxPlatform.SelectedText = platform;
                comboBoxPlatform.Text         = platform;
            }

            buttonRescan.Enabled = comboBoxPlatform.Text != string.Empty;
            updating             = false;
        }
        private void FormEmulator_Load(object sender, EventArgs e)
        {
            buttonAdd.Click    += buttonAdd_Click;
            buttonDelete.Click += buttonDelete_Click;
            buttonCancel.Click += buttonCancel_Click;

            updating = true;
            dataGridView.ClearSelection();
            dataGridView.Rows.Clear();

            List <Platform> emus = PlatformBusiness.GetAll();

            foreach (Platform emu in emus)
            {
                AddToGrid(emu, -1);
            }

            comboBoxPlatformsDB.ValueMember   = "Key";
            comboBoxPlatformsDB.DisplayMember = "Value";
            var list = Functions.GetPlatformsXML();

            var keyvalue = new List <KeyValuePair <string, string> >();

            foreach (var item in list)
            {
                keyvalue.Add(new KeyValuePair <string, string>(item.Key, item.Value));
            }

            comboBoxPlatformsDB.DataSource = keyvalue;

            updating = false;
            Clean();
        }
        private void buttonDelete_Click(object sender, EventArgs e)
        {
            Updated = true;

            if (dataGridView.SelectedRows.Count < 1)
            {
                return;
            }

            Platform platform = (Platform)dataGridView.SelectedRows[0].Tag;

            if (MessageBox.Show(string.Format("Do you want do delete the platform {0} ?", platform.Name), "Warning", MessageBoxButtons.OKCancel) == DialogResult.Cancel)
            {
                return;
            }

            int romCount = RomBusiness.GetAll().Where(x => x.Platform == platform).Count();

            if (romCount > 0)
            {
                FormCustomMessage.ShowError(string.Format("The platform {0} is associated with {1} roms. You cannot delete it.", platform.Name, romCount));
                return;
            }

            foreach (DataGridViewRow item in dataGridView.SelectedRows)
            {
                PlatformBusiness.Delete(item.Cells[0].Value.ToString());
                dataGridView.Rows.Remove(item);
            }

            Updated = true;
            Clean();
        }
示例#5
0
        private void buttonChangeISOtoCHD_Click(object sender, EventArgs e)
        {
            if (comboBoxPlatform.Text == "")
            {
                return;
            }

            Platform platform = PlatformBusiness.Get(comboBoxPlatform.Text);
            var      roms     = RomBusiness.GetAll(platform);
            int      count    = 0;

            foreach (var rom in roms)
            {
                if (rom.FileName.EndsWith(".cue"))
                {
                    var chdpath = platform.DefaultRomPath + "\\" + rom.FileNameNoExt + ".chd";

                    if (File.Exists(chdpath))
                    {
                        var old = rom.FileName;
                        rom.FileName = rom.FileNameNoExt + ".chd";
                        RomBusiness.SetRom(rom, old);
                        count++;
                    }
                }
            }

            MessageBox.Show(count.ToString() + " roms updated");
        }
示例#6
0
        public void GetGamesListJSONByPlatform_Test()
        {
            GenreBusiness.Fill();
            PlatformBusiness.Fill();
            var games = APIFunctions.GetGamesListJSONByPlatform("6", "Snes");

            Assert.IsNotNull(games);
        }
示例#7
0
        private void FormSyncRomData_Load(object sender, EventArgs e)
        {
            Updated = false;
            var platforms = PlatformBusiness.GetAll();

            comboBoxPlatform.DisplayMember = "Name";
            comboBoxPlatform.ValueMember   = "Id";
            comboBoxPlatform.DataSource    = platforms;
        }
        private void FormBase_Load(object sender, EventArgs e)
        {
            List <Platform> emus = PlatformBusiness.GetAll();

            comboBoxChoosePlatform.DataSource    = emus;
            comboBoxChoosePlatform.DisplayMember = "Name";
            comboBoxChoosePlatform.ValueMember   = "Name";
            comboBoxChoosePlatform.SelectedIndex = 0;
        }
示例#9
0
        public static void Fill()
        {
            RomList = new List <Rom>();
            var platformnames = Directory.GetDirectories(Values.PlatformsPath);

            if (!Directory.Exists(Values.PlatformsPath))
            {
                Directory.CreateDirectory(Values.PlatformsPath);
            }

            foreach (var platformname in platformnames)
            {
                var name = platformname.Replace(Values.PlatformsPath + "\\", "");

                var romNodes = XML.GetRomNodes(name);

                if (romNodes == null)
                {
                    continue;
                }

                foreach (XmlNode node in romNodes)
                {
                    Rom rom = new Rom();
                    rom.FileName      = Functions.GetXmlAttribute(node, "FileName");
                    rom.FileNameNoExt = RomFunctions.GetFileNameNoExtension(rom.FileName);
                    rom.Id            = Functions.GetXmlAttribute(node, "Id");
                    rom.Name          = Functions.GetXmlAttribute(node, "Name");
                    rom.DBName        = Functions.GetXmlAttribute(node, "DBName");
                    rom.Platform      = PlatformBusiness.Get(Functions.GetXmlAttribute(node, "Platform"));
                    rom.Genre         = GenreBusiness.Get(Functions.GetXmlAttribute(node, "Genre"));
                    rom.Publisher     = Functions.GetXmlAttribute(node, "Publisher");
                    rom.Developer     = Functions.GetXmlAttribute(node, "Developer");
                    rom.YearReleased  = Functions.GetXmlAttribute(node, "YearReleased");
                    rom.Description   = Functions.GetXmlAttribute(node, "Description");
                    var idLocked = Functions.GetXmlAttribute(node, "IdLocked");
                    rom.IdLocked = string.IsNullOrEmpty(idLocked) ? false : Convert.ToBoolean(idLocked);
                    var favorite = Functions.GetXmlAttribute(node, "Favorite");
                    rom.Favorite = string.IsNullOrEmpty(favorite) ? false : Convert.ToBoolean(favorite);
                    rom.Emulator = Functions.GetXmlAttribute(node, "Emulator");
                    rom.Series   = Functions.GetXmlAttribute(node, "Series");
                    float result = 0;

                    if (float.TryParse(Functions.GetXmlAttribute(node, "Rating"), out result))
                    {
                        rom.Rating = result;
                    }

                    rom.Status    = RomStatusBusiness.Get(rom.Platform.Name, rom.FileName);
                    rom.RomLabels = RomLabelsBusiness.Get(rom.Platform.Name, rom.FileName);

                    RomList.Add(rom);
                }
            }
        }
示例#10
0
        public FormAudit()
        {
            InitializeComponent();

            List <Platform> platforms = PlatformBusiness.GetAll();

            platforms.Insert(0, new Platform());
            comboBoxPlatform.DataSource    = platforms;
            comboBoxPlatform.DisplayMember = "Name";
            comboBoxPlatform.ValueMember   = "Name";
        }
示例#11
0
        private void FormSyncRomData_Load(object sender, EventArgs e)
        {
            Updated = false;
            var platforms = PlatformBusiness.GetAll();

            comboBoxPlatform.DisplayMember = "Name";
            comboBoxPlatform.ValueMember   = "Id";
            comboBoxPlatform.DataSource    = platforms;
            threadSetIdAndYear             = new Thread(SetIdAndYear);
            threadSetOtherProperties       = new Thread(SetOtherProperties);
            checkBoxBasicSync_CheckedChanged(sender, e);
        }
示例#12
0
        private void buttonCleanIncorrectRomPlatform_Click(object sender, EventArgs e)
        {
            if (comboBoxPlatform.Text == "" || comboBoxPlatform.Text == "none")
            {
                FormCustomMessage.ShowError("Select a platform");
            }

            var json = RomFunctions.GetPlatformJson(comboBoxPlatform.Text);

            if (json == "")
            {
                return;
            }

            var        roms       = RomBusiness.GetAll(PlatformBusiness.Get(comboBoxPlatform.Text));
            int        count      = 0;
            List <Rom> romsUpdate = new List <Rom>();

            foreach (var rom in roms)
            {
                if (string.IsNullOrEmpty(rom.Id))
                {
                    continue;
                }

                if (!json.Contains("\"id\": " + rom.Id + ","))
                {
                    rom.Id           = "";
                    rom.Name         = rom.FileNameNoExt;
                    rom.DBName       = "";
                    rom.Description  = "";
                    rom.IdLocked     = false;
                    rom.Publisher    = "";
                    rom.YearReleased = "";
                    rom.Developer    = "";
                    rom.Rating       = 0;

                    romsUpdate.Add(rom);

                    count++;
                    Updated = true;
                }
            }

            RomBusiness.SetRom(romsUpdate);

            FormCustomMessage.ShowSuccess("Roms updated successfully! " + count.ToString() + " roms cleaned");
        }
示例#13
0
 public static void InitXml()
 {
     XML.LoadXmlConfig();
     XML.LoadXmlGenres();
     XML.LoadXmlLabels();
     XML.LoadXmlPlatforms();
     XML.LoadXmlRoms();
     XML.LoadXmlRomStatus();
     XML.LoadXmlRomLabels();
     RomLabelBusiness.Fill();
     GenreBusiness.Fill();
     PlatformBusiness.Fill();
     RomStatusBusiness.Fill();
     RomLabelsBusiness.Fill();
     RomBusiness.Fill();
 }
示例#14
0
        private void buttonRescan_Click(object sender, EventArgs e)
        {
            if (comboBoxPlatform.SelectedItem == null || comboBoxPlatform.SelectedIndex == 1)
            {
                FormCustomMessage.ShowError("No platform selected.");
                return;
            }

            var platform = PlatformBusiness.Get(comboBoxPlatform.Text);

            var result = PlatformBusiness.RescanRoms(platform);

            if (result)
            {
                FilterRoms();
            }
        }
示例#15
0
        private void buttonUpdateAllRomsNames_Click(object sender, EventArgs e)
        {
            try
            {
                if (comboBoxPlatform.Text == "" || comboBoxPlatform.Text == "none")
                {
                    FormCustomMessage.ShowError("Select a platform");
                }

                Platform   platform   = PlatformBusiness.Get(comboBoxPlatform.Text);
                var        roms       = RomBusiness.GetAll(platform);
                int        count      = 0;
                List <Rom> romsUpdate = new List <Rom>();

                foreach (var rom in roms)
                {
                    var name = RomFunctions.GetMAMENameFromCSV(rom.FileNameNoExt);

                    if (name == "")
                    {
                        continue;
                    }

                    if (rom.Name != name)
                    {
                        rom.Name = name;
                        romsUpdate.Add(rom);
                        count++;
                    }
                }

                RomBusiness.SetRom(romsUpdate);
                FormCustomMessage.ShowSuccess("Rom names updated successfully! Total:" + count.ToString());
                Updated = true;
            }
            catch (Exception ex)
            {
                //FormWait.CloseWait();
                FormCustomMessage.ShowError(ex.Message);
            }
            finally
            {
                //FormWait.CloseWait();
            }
        }
示例#16
0
        private void buttonShowMissingRoms_Click(object sender, EventArgs e)
        {
            try
            {
                if (comboBoxPlatform.Text == "" || comboBoxPlatform.Text == "none")
                {
                    FormCustomMessage.ShowError("Select a platform");
                }

                Platform platform = PlatformBusiness.Get(comboBoxPlatform.Text);
                var      json     = RomFunctions.GetPlatformJson(comboBoxPlatform.Text);

                if (string.IsNullOrEmpty(json))
                {
                    FormCustomMessage.ShowError("Json not found. Sync platform first");
                }

                var games = APIFunctions.GetGamesListByPlatform(platform.Id, json, platform.Name);
                var roms  = RomBusiness.GetAll(platform);

                StringBuilder builder = new StringBuilder("");

                foreach (var game in games)
                {
                    if (!roms.Any(x => x.Id == game.Id))
                    {
                        builder.Append(game.Id + "-" + game.DBName + Environment.NewLine);
                    }
                }

                FormInfo info = new FormInfo(builder.ToString());
                info.Show();

                Updated = true;
            }
            catch (Exception ex)
            {
                //FormWait.CloseWait();
                FormCustomMessage.ShowError(ex.Message);
            }
            finally
            {
                //FormWait.CloseWait();
            }
        }
示例#17
0
        private void buttonUpdateNameFromDBName_Click(object sender, EventArgs e)
        {
            try
            {
                if (comboBoxPlatform.Text == "" || comboBoxPlatform.Text == "none")
                {
                    FormCustomMessage.ShowError("Select a platform");
                }

                Platform   platform   = PlatformBusiness.Get(comboBoxPlatform.Text);
                var        roms       = RomBusiness.GetAll(platform);
                int        count      = 0;
                List <Rom> romsUpdate = new List <Rom>();

                foreach (var rom in roms)
                {
                    if (!string.IsNullOrEmpty(rom.DBName))
                    {
                        var newname = rom.DBName.Replace(":", " -");

                        if (rom.Name != newname)
                        {
                            rom.Name = newname;
                            romsUpdate.Add(rom);
                            count++;
                        }
                    }
                }

                RomBusiness.SetRom(romsUpdate);
                FormCustomMessage.ShowSuccess("Rom names updated successfully! Total:" + count.ToString());
                Updated = true;
            }
            catch (Exception ex)
            {
                //FormWait.CloseWait();
                FormCustomMessage.ShowError(ex.Message);
            }
            finally
            {
                //FormWait.CloseWait();
            }
        }
示例#18
0
        private void buttonSearchInDB_Click(object sender, EventArgs e)
        {
            string url  = "https://thegamesdb.net/search.php?name={0}&platform_id%5B%5D={1}";
            string name = textBoxRomName.Text.Replace("[!]", string.Empty).Replace("!", string.Empty).Replace("&", " ").Replace(" ", "+");

            name = Functions.RemoveSubstring(name, '[', ']');
            name = Functions.RemoveSubstring(name, '(', ')');
            var platform = PlatformBusiness.GetAll().Where(x => x.Name == labelPlatform.Text).FirstOrDefault();

            if (platform != null)
            {
                url = string.Format(url, name, platform.Id);
            }
            else
            {
                url = string.Format(url, name, labelPlatform.Text);
            }

            ProcessStartInfo sInfo = new ProcessStartInfo(url);

            Process.Start(sInfo);
        }
        private void FillPlatformGrid()
        {
            var emus = PlatformBusiness.GetAll().Where(x => x.ShowInList).ToList();

            dataGridViewPlatforms.Rows.Clear();

            foreach (var platform in emus)
            {
                int             rowId = dataGridViewPlatforms.Rows.Add();
                DataGridViewRow row   = dataGridViewPlatforms.Rows[rowId];

                if (platform.Icon != null)
                {
                    row.Cells[ColumnIcon.Index].Value = platform.Icon;
                }

                row.Cells[columnPlatforms.Index].Value           = platform.Name;
                row.Cells[columnPlatforms.Index].Style.BackColor = platform.Color;
                row.Cells[columnPlatforms.Index].Style.ForeColor = Functions.SetFontContrast(platform.Color);
                row.Tag = platform;
            }
        }
示例#20
0
        private void toolStripButtonRemoveInvalid_Click(object sender, EventArgs e)
        {
            try
            {
                if (comboBoxPlatform.SelectedValue != null)
                {
                    RomFunctions.RemoveInvalidRomsEntries(PlatformBusiness.Get(comboBoxPlatform.SelectedValue.ToString()));
                }
                else
                {
                    RomFunctions.RemoveInvalidRomsEntries();
                }

                FilterRoms();
            }
            catch (OperationCanceledException ioex)
            {
                return;
            }
            catch (Exception ex)
            {
                FormCustomMessage.ShowError(ex.Message);
            }
        }
示例#21
0
        private void buttonChangePath_Click(object sender, EventArgs e)
        {
            var dir  = Environment.CurrentDirectory + "\\" + Values.PlatformsPath;
            var dirs = Directory.GetDirectories(dir);

            foreach (var item in dirs)
            {
                var platformname = item.Substring(item.LastIndexOf("\\") + 1);
                var platform     = PlatformBusiness.Get(platformname);

                var file = item + "\\roms.xml";

                if (!File.Exists(file))
                {
                    continue;
                }

                var text = File.ReadAllText(file);
                text = text.Replace("Path=", "FileName=");
                text = text.Replace(platform.DefaultRomPath + "\\", "");

                File.WriteAllText(file, text);
            }
        }
示例#22
0
        private void buttonAdd_Click(object sender, EventArgs e)
        {
            Platform platform = null;
            int      index    = -1;

            updating = true;

            if (string.IsNullOrEmpty(textBoxPlatformName.Text.Trim()))
            {
                FormCustomMessage.ShowError("Can not save without a valid name.");
                return;
            }

            if (textBoxPlatformName.Enabled)
            {
                if (PlatformBusiness.Get(textBoxPlatformName.Text.Trim()) != null)
                {
                    FormCustomMessage.ShowError("A platform with this name already exists.");
                    return;
                }
            }

            if (!string.IsNullOrEmpty(textBoxDefaultRomPath.Text) && string.IsNullOrEmpty(textBoxDefaultRomExtensions.Text))
            {
                FormCustomMessage.ShowError("Default rom extensions must also be filled");
                return;
            }
            if (textBoxPlatformName.Enabled)
            {
                platform = new Platform();
            }
            else
            {
                DataGridViewRow row = dataGridView.SelectedRows[0];
                index    = row.Index;
                platform = (Platform)row.Tag;
                textBoxPlatformName.Enabled = true;
                buttonAdd.Text = "Add";
            }

            platform.Id                   = comboBoxPlatformsDB.SelectedValue.ToString();
            platform.Name                 = textBoxPlatformName.Text.Trim();
            platform.Color                = buttonColor.BackColor;
            platform.ShowInFilter         = checkBoxShowInFilters.Checked;
            platform.ShowInList           = checkBoxShowInLinksList.Checked;
            platform.DefaultRomPath       = textBoxDefaultRomPath.Text;
            platform.DefaultRomExtensions = textBoxDefaultRomExtensions.Text.Replace(".", "");
            platform.UseRetroarch         = checkBoxUseRetroarch.Checked;
            platform.DefaultEmulator      = defaultEmulator;
            platform.Arcade               = checkBoxArcade.Checked;
            platform.Console              = checkBoxConsole.Checked;
            platform.Handheld             = checkBoxHandheld.Checked;
            platform.CD                   = checkBoxCD.Checked;
            platform.Emulators            = emulators;
            platform.IconPath             = textBoxPlatformIcon.Text;

            PlatformBusiness.Set(platform);
            AddToGrid(platform, index);
            Updated  = true;
            updating = false;
            Clean();
        }