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(); } }
private void favoriteUnfavoriteToolStripMenuItem_Click(object sender, EventArgs e) { try { if (dataGridView.SelectedRows.Count == 0) { return; } Rom rom = (Rom)dataGridView.SelectedRows[0].Tag; rom.Favorite = !rom.Favorite; RomBusiness.SetRom(rom); LoadGridRow(rom, dataGridView.SelectedRows[0]); } catch (Exception ex) { FormCustomMessage.ShowError(ex.Message); } }
private void deleteRomToolStripMenuItem_Click(object sender, EventArgs e) { try { if (dataGridView.SelectedRows.Count == 0) { return; } DataGridViewRow row = dataGridView.SelectedRows[0]; Rom rom = (Rom)row.Tag; var message = string.Format("Do you want to remove \"{0}\" ? (Remove to recycle bin)", rom.Name); var result = MessageBox.Show(message, "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result.ToString() == "No") { return; } Microsoft.VisualBasic.FileIO.FileSystem.DeleteFile(rom.Platform.DefaultRomPath + "\\" + rom.FileName, Microsoft.VisualBasic.FileIO.UIOption.AllDialogs, Microsoft.VisualBasic.FileIO.RecycleOption.SendToRecycleBin); dataGridView.Rows.Remove(row); RomBusiness.DeleteRom(rom); RomFunctions.RemoveRomPics(rom); FilteredRoms.Remove(rom); labelTotalRomsCount.Text = FilteredRoms.Count.ToString(); } catch (OperationCanceledException ioex) { return; } catch (Exception ex) { FormCustomMessage.ShowError(ex.Message); } }
private void dataGridView_KeyDown(object sender, KeyEventArgs e) { try { if (e.KeyData == Keys.Space) { dataGridView_DoubleClick(sender, e); } else if (e.KeyData == Keys.Delete) { removeRomEntryToolStripMenuItem_Click(sender, e); } else if (e.KeyData == Keys.F5) { FilteredRoms.Clear(); FilteredRoms.AddRange(RomBusiness.GetAll()); AddRomsToGrid(FilteredRoms); } else if (e.KeyData == Keys.G) { changeGenreToolStripMenuItem_Click(sender, null); } else if (e.KeyData == Keys.L) { changeLabelsToolStripMenuItem_Click(sender, null); } } catch (OperationCanceledException ioex) { return; } catch (Exception ex) { FormCustomMessage.ShowError(ex.Message); } }
private void buttonRemoveUnused_Click(object sender, EventArgs e) { Platform emu = (Platform)comboBoxChoosePlatform.SelectedItem; var roms = RomBusiness.GetAll().Where(x => x.Platform != null && x.Platform.Name == emu.Name).ToList(); var path = Environment.CurrentDirectory + "\\" + Values.PlatformsPath + "\\" + emu.Name + "\\"; int successfulFind = 0; var images = new List <string>(); if (radioButtonBoxart.Checked) { images = RomFunctions.GetRomPicturesByPlatformWithExt(comboBoxChoosePlatform.Text, Values.BoxartFolder); path += Values.BoxartFolder + "\\"; } else if (radioButtonTitle.Checked) { images = RomFunctions.GetRomPicturesByPlatformWithExt(comboBoxChoosePlatform.Text, Values.TitleFolder); path += Values.TitleFolder + "\\"; } else if (radioButtonGameplay.Checked) { images = RomFunctions.GetRomPicturesByPlatformWithExt(comboBoxChoosePlatform.Text, Values.GameplayFolder); path += Values.GameplayFolder + "\\"; } foreach (var image in images) { if (!roms.Any(x => x.FileNameNoExt.ToLower() == RomFunctions.GetFileNameNoExtension(image).ToLower())) { File.Delete(path + image); successfulFind++; } } FormCustomMessage.ShowSuccess("Number of successful unused rom pictures removed: " + successfulFind); }
private void buttonUnlockIds_Click(object sender, EventArgs e) { var roms = RomBusiness.GetAll().Where(x => x.Platform.Name == comboBoxPlatform.Text && x.IdLocked).ToList(); if (roms == null || roms.Count == 0) { FormCustomMessage.ShowInfo("There are no roms with locked Ids"); comboBoxPlatform.Enabled = true; buttonSync.Enabled = true; return; } progressBar.Maximum = roms.Count; progressBar.Value = 0; foreach (var item in roms) { item.IdLocked = false; progressBar.Value++; } RomBusiness.SetRom(roms); FormCustomMessage.ShowSuccess(string.Format("{0} rom Ids unlocked successfully!", roms.Count)); }
private void purgeRomDataToolStripMenuItem_Click(object sender, EventArgs e) { try { FormPurgeRomData form = new FormPurgeRomData(); form.ShowDialog(); if (form.Updated) { RomBusiness.Fill(); FillGenreFilter(); FilterRoms(); FillPlatformFilter(); FillPlatformGrid(); FillPublisherFilter(); FillDeveloperFilter(); FillYearReleasedFilter(); } } catch (Exception ex) { FormCustomMessage.ShowError(ex.Message); } }
private void comboBoxPlatform_SelectedIndexChanged(object sender, EventArgs e) { labelId.Text = "-"; labelGenre.Text = "-"; labelPublisher.Text = "-"; labelDeveloper.Text = "-"; labelDescription.Text = "-"; labelYearReleased.Text = "-"; labelBoxart.Text = "-"; labelTitle.Text = "-"; labelGameplay.Text = "-"; Roms.Clear(); Roms.AddRange(RomBusiness.GetAll().Where(r => r.Platform != null && r.Platform.Name == comboBoxPlatform.Text).ToList()); labelId.Text = Roms.Where(x => string.IsNullOrEmpty(x.Id)).Count().ToString(); labelGenre.Text = Roms.Where(x => x.Genre == null).Count().ToString(); labelPublisher.Text = Roms.Where(x => string.IsNullOrEmpty(x.Publisher)).Count().ToString(); labelDeveloper.Text = Roms.Where(x => string.IsNullOrEmpty(x.Developer)).Count().ToString(); labelDescription.Text = Roms.Where(x => string.IsNullOrEmpty(x.Description)).Count().ToString(); labelYearReleased.Text = Roms.Where(x => string.IsNullOrEmpty(x.YearReleased)).Count().ToString(); var boxartPictures = RomFunctions.GetRomPicturesByPlatform(comboBoxPlatform.Text, Values.BoxartFolder); var titlePictures = RomFunctions.GetRomPicturesByPlatform(comboBoxPlatform.Text, Values.TitleFolder); var gameplayPictures = RomFunctions.GetRomPicturesByPlatform(comboBoxPlatform.Text, Values.GameplayFolder); var romsList = Roms.Select(x => x.Name).ToList(); missingBoxartPictures = romsList.Except(boxartPictures).ToList(); missingTitlePictures = romsList.Except(titlePictures).ToList(); missingGameplayPictures = romsList.Except(gameplayPictures).ToList(); labelBoxart.Text = missingBoxartPictures.Count().ToString(); labelTitle.Text = missingTitlePictures.Count().ToString(); labelGameplay.Text = missingGameplayPictures.Count().ToString(); }
private void SetOtherProperties() { var notSyncedRoms = Roms.Where(x => !string.IsNullOrEmpty(x.Id) && (string.IsNullOrEmpty(x.DBName) || string.IsNullOrEmpty(x.Publisher) || string.IsNullOrEmpty(x.Developer))).ToList(); bool updated = false; syncRomsCount = 0; ThreadStopped = false; List <Rom> romList = new List <Rom>(); foreach (var rom in notSyncedRoms) { if (StopThread) { StopThread = false; RomBusiness.SetRom(romList); Thread.CurrentThread.Abort(); comboBoxPlatform_SelectedIndexChanged(null, new EventArgs()); } if (progressBar.Maximum > progressBar.Value) { progressBar.Invoke((MethodInvoker) delegate { progressBar.Value++; }); } var access = ""; LogMessage("UPDATING - " + rom.Name); var game = APIFunctions.GetGameDetails(rom.Id, rom.Platform, out access); labelAccessLeftCount.Text = access; if (game == null) { continue; } if (string.IsNullOrEmpty(rom.DBName) && !string.IsNullOrEmpty(game.DBName)) { rom.DBName = game.DBName; updated = true; } if (string.IsNullOrEmpty(rom.Publisher) && !string.IsNullOrEmpty(game.Publisher)) { rom.Publisher = game.Publisher; updated = true; } if (string.IsNullOrEmpty(rom.Developer) && !string.IsNullOrEmpty(game.Developer)) { rom.Developer = game.Developer; updated = true; } if (string.IsNullOrEmpty(rom.Description) && !string.IsNullOrEmpty(game.Description)) { rom.Description = game.Description; updated = true; } if (rom.Genre == null && game.Genre != null) { rom.Genre = game.Genre; updated = true; } if ((rom.Rating == null || rom.Rating == 0) && (game.Rating != null && game.Rating > 0)) { rom.Rating = game.Rating; updated = true; } if (updated) { syncRomsCount++; romList.Add(rom); updated = false; } } RomBusiness.SetRom(romList); ThreadStopped = true; }
private void SetIdAndYear() { syncRomsCount = 0; bool updated = false; ThreadStopped = false; bool found = false; string gameNameToDelete = string.Empty; List <Rom> romList = new List <Rom>(); foreach (var rom in notSyncedRoms) { if (found && !string.IsNullOrEmpty(gameNameToDelete)) { games.RemoveAll(x => x.DBName == gameNameToDelete); gameNameToDelete = string.Empty; } if (progressBar.Maximum > progressBar.Value) { labelProgress.Invoke((MethodInvoker) delegate { progressBar.Value++; }); } if (StopThread) { StopThread = false; RomBusiness.SetRom(romList); Thread.CurrentThread.Abort(); comboBoxPlatform_SelectedIndexChanged(null, new EventArgs()); } var romName = RomFunctions.TrimRomName(rom.Name); found = false; foreach (var game in games) { var gameName = RomFunctions.TrimRomName(game.DBName); if (romName == gameName) { gameNameToDelete = game.DBName; found = true; if (string.IsNullOrEmpty(rom.Id) && !string.IsNullOrEmpty(game.Id)) { rom.Id = game.Id; updated = true; } if (string.IsNullOrEmpty(rom.YearReleased) && !string.IsNullOrEmpty(game.YearReleased)) { rom.YearReleased = game.YearReleased; updated = true; } if (string.IsNullOrEmpty(rom.DBName) && !string.IsNullOrEmpty(game.DBName)) { rom.DBName = game.DBName; updated = true; } if (updated) { syncRomsCount++; LogMessage("ID AND YEAR SET - " + rom.Name); romList.Add(rom); updated = false; } break; } } if (!found) { LogMessage("NOT FOUND - " + rom.Name); if (!checkBoxBasicSync.Checked) { LogMessage("TRYING BY NAME - " + rom.Name); var gameName = Functions.RemoveSubstring(rom.Name, '(', ')'); gameName = Functions.RemoveSubstring(gameName, '[', ']').Trim(); string acessos = ""; var game = APIFunctions.GetGameByName(platformId, gameName, out acessos); if (game == null) { LogMessage("REALLY NOT FOUND - " + rom.Name); continue; } found = true; if (string.IsNullOrEmpty(rom.Id) && !string.IsNullOrEmpty(game.Id)) { rom.Id = game.Id; updated = true; } if (string.IsNullOrEmpty(rom.YearReleased) && !string.IsNullOrEmpty(game.YearReleased)) { rom.YearReleased = game.YearReleased; updated = true; } if (string.IsNullOrEmpty(rom.DBName) && !string.IsNullOrEmpty(game.DBName)) { rom.DBName = game.DBName; updated = true; } if (updated) { syncRomsCount++; LogMessage("ID AND YEAR SET - " + rom.Name); romList.Add(rom); updated = false; } } } } RomBusiness.SetRom(romList); ThreadStopped = true; }
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; }
private void buttonSync_Click(object sender, EventArgs e) { try { if (string.IsNullOrEmpty(textBoxXMLPath.Text)) { FormCustomMessage.ShowError("Load the XML file first"); return; } if (!File.Exists(textBoxXMLPath.Text)) { FormCustomMessage.ShowError("Invalid file path"); return; } if (string.IsNullOrEmpty(comboBoxPlatform.Text)) { FormCustomMessage.ShowError("Choose a platform"); return; } XmlDocument doc = new XmlDocument(); doc.Load(textBoxXMLPath.Text); var roms = RomBusiness.GetAll().Where(x => x.Platform != null && x.Platform.Name == comboBoxPlatform.Text).ToList(); XmlNode list = doc.ChildNodes[1]; int count = 0; Dictionary <string, Rom> romsDic = new Dictionary <string, Rom>(); Dictionary <string, XmlNode> nodesDic = new Dictionary <string, XmlNode>(); string name = ""; foreach (var item in roms) { name = RomFunctions.TrimRomName(item.Name); if (!romsDic.ContainsKey(name)) { romsDic.Add(name, item); } } foreach (XmlNode node in list) { name = RomFunctions.TrimRomName(node.ChildNodes[1].InnerText); if (!nodesDic.ContainsKey(name)) { nodesDic.Add(name, node); } } foreach (string node in nodesDic.Keys) { if (!romsDic.ContainsKey(node)) { continue; } var rom = romsDic[node]; XmlNode selectedNode = nodesDic[node]; bool updated = false; if (rom != null) { foreach (XmlNode childNode in selectedNode.ChildNodes) { if (childNode.Name == "releasedate") { if (string.IsNullOrEmpty(rom.YearReleased) && !string.IsNullOrEmpty(selectedNode.InnerText) && selectedNode.InnerText.Length > 3) { rom.YearReleased = childNode.InnerText.Substring(0, 4); updated = true; } } else if (childNode.Name == "name") { if (string.IsNullOrEmpty(rom.DBName)) { rom.DBName = childNode.InnerText; updated = true; } } else if (childNode.Name == "desc") { if (string.IsNullOrEmpty(rom.Description)) { rom.Description = childNode.InnerText; updated = true; } } else if (childNode.Name == "publisher") { if (string.IsNullOrEmpty(rom.Publisher)) { rom.Publisher = childNode.InnerText; updated = true; } } else if (childNode.Name == "developer") { if (string.IsNullOrEmpty(rom.Developer)) { rom.Developer = childNode.InnerText; updated = true; } } else if (childNode.Name == "genre") { var genrename = childNode.InnerText; if (rom.Genre == null && !string.IsNullOrEmpty(genrename)) { updated = true; var genre = GenreBusiness.Get(genrename); if (genre == null) { //genre = RomFunctions.CreateNewGenre(genrename); } else { rom.Genre = genre; } } } } if (updated) { count++; Updated = true; } } } RomBusiness.SetRom(roms); FormCustomMessage.ShowSuccess(count + " roms updated"); } catch (Exception ex) { FormCustomMessage.ShowError(ex.Message); } }