From 113dc3e0faf45b970323db8e124ffa1aaa7fd733 Mon Sep 17 00:00:00 2001 From: xantari Date: Thu, 21 Jan 2021 21:45:23 -0600 Subject: [PATCH] game manager updates added delete game function --- .../AddEditGameForm.Designer.cs | 42 +++++++--- PinCab.Configurator/AddEditGameForm.cs | 65 ++++++++++++++- .../GameManagerForm.Designer.cs | 29 +++---- PinCab.Configurator/GameManagerForm.cs | 83 ++++++++++++++++++- PinCab.Configurator/SettingsForm.cs | 6 +- .../Models/{PinballX => }/Platform.cs | 2 +- PinCab.Utils/PinCab.Utils.csproj | 2 +- PinCab.Utils/Utils/FrontEndManager.cs | 78 +++++++++++++++-- .../Utils/PinballX/PinballXManager.cs | 1 + .../ViewModels/FrontEndGameViewModel.cs | 5 ++ 10 files changed, 268 insertions(+), 45 deletions(-) rename PinCab.Utils/Models/{PinballX => }/Platform.cs (92%) diff --git a/PinCab.Configurator/AddEditGameForm.Designer.cs b/PinCab.Configurator/AddEditGameForm.Designer.cs index be601e5..693961b 100644 --- a/PinCab.Configurator/AddEditGameForm.Designer.cs +++ b/PinCab.Configurator/AddEditGameForm.Designer.cs @@ -34,7 +34,6 @@ private void InitializeComponent() this.colorDialogDmdColor = new System.Windows.Forms.ColorDialog(); this.label2 = new System.Windows.Forms.Label(); this.chkEnabled = new System.Windows.Forms.CheckBox(); - this.txtAlternateExe = new System.Windows.Forms.TextBox(); this.chkFavorite = new System.Windows.Forms.CheckBox(); this.txtTableName = new System.Windows.Forms.TextBox(); this.label3 = new System.Windows.Forms.Label(); @@ -79,6 +78,8 @@ private void InitializeComponent() this.label18 = new System.Windows.Forms.Label(); this.txtPlayers = new System.Windows.Forms.TextBox(); this.label19 = new System.Windows.Forms.Label(); + this.cmbAlternateExe = new System.Windows.Forms.ComboBox(); + this.btnDatabaseBrowser = new System.Windows.Forms.Button(); this.SuspendLayout(); // // label1 @@ -130,13 +131,6 @@ private void InitializeComponent() this.chkEnabled.Text = "Table Enabled"; this.chkEnabled.UseVisualStyleBackColor = true; // - // txtAlternateExe - // - this.txtAlternateExe.Location = new System.Drawing.Point(80, 344); - this.txtAlternateExe.Name = "txtAlternateExe"; - this.txtAlternateExe.Size = new System.Drawing.Size(215, 20); - this.txtAlternateExe.TabIndex = 12; - // // chkFavorite // this.chkFavorite.AutoSize = true; @@ -422,6 +416,7 @@ private void InitializeComponent() this.btnSelectFile.TabIndex = 48; this.btnSelectFile.Text = "Select File"; this.btnSelectFile.UseVisualStyleBackColor = true; + this.btnSelectFile.Click += new System.EventHandler(this.btnSelectFile_Click); // // btnFillFromIpdb // @@ -431,6 +426,7 @@ private void InitializeComponent() this.btnFillFromIpdb.TabIndex = 49; this.btnFillFromIpdb.Text = "Fill From IPDB"; this.btnFillFromIpdb.UseVisualStyleBackColor = true; + this.btnFillFromIpdb.Click += new System.EventHandler(this.btnFillFromIpdb_Click); // // label17 // @@ -466,6 +462,7 @@ private void InitializeComponent() this.btnGameUrl.Size = new System.Drawing.Size(27, 23); this.btnGameUrl.TabIndex = 62; this.btnGameUrl.UseVisualStyleBackColor = true; + this.btnGameUrl.Click += new System.EventHandler(this.btnGameUrl_Click); // // btnIpdbUrl // @@ -478,6 +475,7 @@ private void InitializeComponent() this.btnIpdbUrl.Size = new System.Drawing.Size(26, 23); this.btnIpdbUrl.TabIndex = 63; this.btnIpdbUrl.UseVisualStyleBackColor = true; + this.btnIpdbUrl.Click += new System.EventHandler(this.btnIpdbUrl_Click); // // txtRating // @@ -511,11 +509,31 @@ private void InitializeComponent() this.label19.TabIndex = 66; this.label19.Text = "Players"; // + // cmbAlternateExe + // + this.cmbAlternateExe.FormattingEnabled = true; + this.cmbAlternateExe.Location = new System.Drawing.Point(80, 347); + this.cmbAlternateExe.Name = "cmbAlternateExe"; + this.cmbAlternateExe.Size = new System.Drawing.Size(367, 21); + this.cmbAlternateExe.TabIndex = 68; + // + // btnDatabaseBrowser + // + this.btnDatabaseBrowser.Location = new System.Drawing.Point(382, 15); + this.btnDatabaseBrowser.Name = "btnDatabaseBrowser"; + this.btnDatabaseBrowser.Size = new System.Drawing.Size(107, 23); + this.btnDatabaseBrowser.TabIndex = 69; + this.btnDatabaseBrowser.Text = "Database Browser"; + this.btnDatabaseBrowser.UseVisualStyleBackColor = true; + this.btnDatabaseBrowser.Click += new System.EventHandler(this.btnDatabaseBrowser_Click); + // // AddEditGameForm // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(562, 583); + this.ClientSize = new System.Drawing.Size(534, 583); + this.Controls.Add(this.btnDatabaseBrowser); + this.Controls.Add(this.cmbAlternateExe); this.Controls.Add(this.txtPlayers); this.Controls.Add(this.label19); this.Controls.Add(this.txtRating); @@ -560,13 +578,12 @@ private void InitializeComponent() this.Controls.Add(this.txtTableName); this.Controls.Add(this.label3); this.Controls.Add(this.chkFavorite); - this.Controls.Add(this.txtAlternateExe); this.Controls.Add(this.chkEnabled); this.Controls.Add(this.label2); this.Controls.Add(this.btnCancel); this.Controls.Add(this.btnSave); this.Controls.Add(this.label1); - this.MinimumSize = new System.Drawing.Size(578, 622); + this.MinimumSize = new System.Drawing.Size(550, 622); this.Name = "AddEditGameForm"; this.Text = "Edit Game"; this.ResumeLayout(false); @@ -582,7 +599,6 @@ private void InitializeComponent() private System.Windows.Forms.ColorDialog colorDialogDmdColor; private System.Windows.Forms.Label label2; private System.Windows.Forms.CheckBox chkEnabled; - private System.Windows.Forms.TextBox txtAlternateExe; private System.Windows.Forms.CheckBox chkFavorite; private System.Windows.Forms.TextBox txtTableName; private System.Windows.Forms.Label label3; @@ -627,5 +643,7 @@ private void InitializeComponent() private System.Windows.Forms.Label label18; private System.Windows.Forms.TextBox txtPlayers; private System.Windows.Forms.Label label19; + private System.Windows.Forms.ComboBox cmbAlternateExe; + private System.Windows.Forms.Button btnDatabaseBrowser; } } \ No newline at end of file diff --git a/PinCab.Configurator/AddEditGameForm.cs b/PinCab.Configurator/AddEditGameForm.cs index 46ce895..61ff1c6 100644 --- a/PinCab.Configurator/AddEditGameForm.cs +++ b/PinCab.Configurator/AddEditGameForm.cs @@ -8,6 +8,7 @@ using System.ComponentModel; using System.Data; using System.Drawing; +using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -18,12 +19,15 @@ namespace PinCab.Configurator public partial class AddEditGameForm : Form { private FrontEndGameViewModel _setting { get; set; } + private string originalFileName { get; set; } private FrontEndManager _manager { get; set; } - public AddEditGameForm(FrontEndGameViewModel setting, FrontEndManager manager) + private string _databaseFile { get; set; } + public AddEditGameForm(FrontEndGameViewModel setting, string databaseFile, FrontEndManager manager) { InitializeComponent(); _setting = setting; _manager = manager; + _databaseFile = databaseFile; LoadForm(); } @@ -44,7 +48,6 @@ private void LoadForm() txtSeconds.Text = _setting.SecondsPlayed.ToString(); txtAdded.Text = _setting.DateAdded.ToString(); txtModified.Text = _setting.DateModified.ToString(); - txtAlternateExe.Text = _setting.AlternateExe; txtComment.Text = _setting.Comment; txtGameUrl.Text = _setting.TableFileUrl; chkHideBackglass.Checked = _setting.HideBackglass; @@ -52,6 +55,17 @@ private void LoadForm() chkHideTopper.Checked = _setting.HideTopper; chkEnabled.Checked = _setting.Enabled; chkFavorite.Checked = _setting.Favorite; + + //Load the alternate exe list + if (_setting.FrontEnd.System == FrontEndSystem.PinballX) + { + var system = _manager.PinballXSystems.FirstOrDefault(c => c.DatabaseFiles.Contains(_databaseFile)); + cmbAlternateExe.Items.AddRange(system.Executables.ToArray()); + } + if (string.IsNullOrEmpty(_setting.AlternateExe)) + cmbAlternateExe.SelectedItem = ""; + else + cmbAlternateExe.SelectedItem = _setting.AlternateExe; } private FrontEndGameViewModel GetSettingFromControls() @@ -84,8 +98,11 @@ private FrontEndGameViewModel GetSettingFromControls() if (success) _setting.DateModified = result; } - - _setting.AlternateExe = txtAlternateExe.Text.IfEmptyThenNull(); + + if (cmbAlternateExe.SelectedText == "" || string.IsNullOrEmpty(cmbAlternateExe.SelectedText)) + _setting.AlternateExe = null; + else + _setting.AlternateExe = cmbAlternateExe.SelectedText.IfEmptyThenNull(); _setting.Comment = txtComment.Text.IfEmptyThenNull(); _setting.TableFileUrl = txtGameUrl.Text.IfEmptyThenNull(); _setting.HideBackglass = chkHideBackglass.Checked; @@ -107,5 +124,45 @@ private void btnSave_Click(object sender, EventArgs e) Close(); } + private void btnSelectFile_Click(object sender, EventArgs e) + { + using (OpenFileDialog fileDialog = new OpenFileDialog()) + { + fileDialog.Filter = "All files (*.*)|*.*|VPX Files|*.vpx|FPT Files|*.fpx|VPT Files|*.vpt"; + fileDialog.FilterIndex = 1; + fileDialog.RestoreDirectory = true; + var result = fileDialog.ShowDialog(); + if (result == DialogResult.OK) + { + var fi = new FileInfo(fileDialog.FileName); + var endIndex = fi.Name.LastIndexOf(fi.Extension); + originalFileName = txtTableName.Text; + txtTableName.Text = fi.Name.Substring(0, endIndex); + } + } + } + + private void btnIpdbUrl_Click(object sender, EventArgs e) + { + if (!string.IsNullOrEmpty(txtIpdb.Text)) + System.Diagnostics.Process.Start("https://www.ipdb.org/machine.cgi?id=" + txtIpdb.Text); + } + + private void btnFillFromIpdb_Click(object sender, EventArgs e) + { + + } + + private void btnGameUrl_Click(object sender, EventArgs e) + { + if (!string.IsNullOrEmpty(txtGameUrl.Text)) + System.Diagnostics.Process.Start(txtGameUrl.Text); + } + + private void btnDatabaseBrowser_Click(object sender, EventArgs e) + { + var form = new DatabaseBrowserForm(); + var result = form.ShowDialog(); + } } } diff --git a/PinCab.Configurator/GameManagerForm.Designer.cs b/PinCab.Configurator/GameManagerForm.Designer.cs index 1cb0cf8..1f67618 100644 --- a/PinCab.Configurator/GameManagerForm.Designer.cs +++ b/PinCab.Configurator/GameManagerForm.Designer.cs @@ -77,7 +77,6 @@ private void InitializeComponent() this.viewIPDBPageToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.findGamesFromIPDBNotInMyDatabaseToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.showGamesWithUpdatesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.markMyVersionAsLatestToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.frontEndGameBindingSource = new System.Windows.Forms.BindingSource(this.components); this.txtLog = new System.Windows.Forms.TextBox(); this.progressBar = new System.Windows.Forms.ProgressBar(); @@ -98,6 +97,7 @@ private void InitializeComponent() this.utilitiesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.mediaAuditToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.helpToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.massRecordToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit(); this.splitContainer1.Panel1.SuspendLayout(); this.splitContainer1.Panel2.SuspendLayout(); @@ -174,7 +174,7 @@ private void InitializeComponent() this.dataGridViewGameList.Location = new System.Drawing.Point(0, 0); this.dataGridViewGameList.Name = "dataGridViewGameList"; this.dataGridViewGameList.ReadOnly = true; - this.dataGridViewGameList.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.CellSelect; + this.dataGridViewGameList.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect; this.dataGridViewGameList.Size = new System.Drawing.Size(955, 344); this.dataGridViewGameList.TabIndex = 2; this.dataGridViewGameList.CellDoubleClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGridViewGameList_CellDoubleClick); @@ -464,10 +464,9 @@ private void InitializeComponent() this.launchGameToolStripMenuItem, this.viewIPDBPageToolStripMenuItem, this.findGamesFromIPDBNotInMyDatabaseToolStripMenuItem, - this.showGamesWithUpdatesToolStripMenuItem, - this.markMyVersionAsLatestToolStripMenuItem}); + this.showGamesWithUpdatesToolStripMenuItem}); this.contextMenuStripGridActions.Name = "contextMenuStripGridActions"; - this.contextMenuStripGridActions.Size = new System.Drawing.Size(303, 246); + this.contextMenuStripGridActions.Size = new System.Drawing.Size(303, 224); // // editToolStripMenuItem // @@ -505,6 +504,7 @@ private void InitializeComponent() this.deleteGameToolStripMenuItem.Name = "deleteGameToolStripMenuItem"; this.deleteGameToolStripMenuItem.Size = new System.Drawing.Size(302, 22); this.deleteGameToolStripMenuItem.Text = "Delete Game"; + this.deleteGameToolStripMenuItem.Click += new System.EventHandler(this.deleteGameToolStripMenuItem_Click); // // launchGameToolStripMenuItem // @@ -531,12 +531,6 @@ private void InitializeComponent() this.showGamesWithUpdatesToolStripMenuItem.Size = new System.Drawing.Size(302, 22); this.showGamesWithUpdatesToolStripMenuItem.Text = "Show Games With Updates"; // - // markMyVersionAsLatestToolStripMenuItem - // - this.markMyVersionAsLatestToolStripMenuItem.Name = "markMyVersionAsLatestToolStripMenuItem"; - this.markMyVersionAsLatestToolStripMenuItem.Size = new System.Drawing.Size(302, 22); - this.markMyVersionAsLatestToolStripMenuItem.Text = "Mark My Version as Latest"; - // // frontEndGameBindingSource // this.frontEndGameBindingSource.DataSource = typeof(PinCab.Utils.ViewModels.FrontEndGameViewModel); @@ -694,7 +688,8 @@ private void InitializeComponent() // utilitiesToolStripMenuItem // this.utilitiesToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.mediaAuditToolStripMenuItem}); + this.mediaAuditToolStripMenuItem, + this.massRecordToolStripMenuItem}); this.utilitiesToolStripMenuItem.Name = "utilitiesToolStripMenuItem"; this.utilitiesToolStripMenuItem.Size = new System.Drawing.Size(58, 20); this.utilitiesToolStripMenuItem.Text = "Utilities"; @@ -702,7 +697,7 @@ private void InitializeComponent() // mediaAuditToolStripMenuItem // this.mediaAuditToolStripMenuItem.Name = "mediaAuditToolStripMenuItem"; - this.mediaAuditToolStripMenuItem.Size = new System.Drawing.Size(139, 22); + this.mediaAuditToolStripMenuItem.Size = new System.Drawing.Size(180, 22); this.mediaAuditToolStripMenuItem.Text = "Media Audit"; this.mediaAuditToolStripMenuItem.Click += new System.EventHandler(this.mediaAuditToolStripMenuItem_Click); // @@ -713,6 +708,12 @@ private void InitializeComponent() this.helpToolStripMenuItem.Text = "Help"; this.helpToolStripMenuItem.Click += new System.EventHandler(this.helpToolStripMenuItem_Click); // + // massRecordToolStripMenuItem + // + this.massRecordToolStripMenuItem.Name = "massRecordToolStripMenuItem"; + this.massRecordToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.massRecordToolStripMenuItem.Text = "Mass Record"; + // // GameManagerForm // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); @@ -811,6 +812,6 @@ private void InitializeComponent() private System.Windows.Forms.Label label2; private System.Windows.Forms.ToolStripMenuItem findGamesFromIPDBNotInMyDatabaseToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem showGamesWithUpdatesToolStripMenuItem; - private System.Windows.Forms.ToolStripMenuItem markMyVersionAsLatestToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem massRecordToolStripMenuItem; } } \ No newline at end of file diff --git a/PinCab.Configurator/GameManagerForm.cs b/PinCab.Configurator/GameManagerForm.cs index b63dbb0..20dee5f 100644 --- a/PinCab.Configurator/GameManagerForm.cs +++ b/PinCab.Configurator/GameManagerForm.cs @@ -9,6 +9,7 @@ using System.ComponentModel; using System.Data; using System.Drawing; +using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -20,11 +21,13 @@ public partial class GameManagerForm : Form { private readonly FrontEndManager _manager = new FrontEndManager(); private List _fullGameListCache { get; set; } + //private bool _loading = true; public GameManagerForm() { InitializeComponent(); InitForm(); + //_loading = false; } private void InitForm() @@ -107,7 +110,7 @@ private void editToolStripMenuItem_Click(object sender, EventArgs e) var row = GetActiveRow(); if (row != null) { - var mediaAuditForm = new AddEditGameForm(row, _manager); + var mediaAuditForm = new AddEditGameForm(row, row.DatabaseFile, _manager); var result = mediaAuditForm.ShowDialog(); if (result == DialogResult.OK) { @@ -125,6 +128,7 @@ private void mediaAuditToolStripMenuItem_Click(object sender, EventArgs e) private void cmbDatabase_SelectedIndexChanged(object sender, EventArgs e) { RefreshGameGrid(); + LogGameDiscrepencies(); } private void RefreshGameGrid() @@ -143,7 +147,32 @@ private void RefreshGameGrid() else lblDatabaseStatus.Text = "Disabled"; } + } + } + + private void AddOrUpdateLog(string text) + { + if (string.IsNullOrEmpty(txtLog.Text)) + txtLog.Text = text; + else + txtLog.Text += "\r\n" + text; + } + + private void LogGameDiscrepencies() + { + if (_fullGameListCache.Any(p => p.MissingTable)) + { + AddOrUpdateLog("Missing tables have been found. Rows highlighted in RED with discrepencies."); + } + } + private void DisplayGameDiscrepencies() + { + foreach (DataGridViewRow row in dataGridViewGameList.Rows) + { + var model = row.DataBoundItem as FrontEndGameViewModel; + if (model.MissingTable) + row.DefaultCellStyle.BackColor = Color.Red; } } @@ -198,6 +227,7 @@ private void viewIPDBPageToolStripMenuItem_Click(object sender, EventArgs e) private void dataGridViewGameList_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e) { dataGridViewGameList.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells); + DisplayGameDiscrepencies(); } private void dataGridViewGameList_CellDoubleClick(object sender, DataGridViewCellEventArgs e) @@ -207,7 +237,7 @@ private void dataGridViewGameList_CellDoubleClick(object sender, DataGridViewCel var row = GetActiveRow(); if (row != null) { - var mediaAuditForm = new AddEditGameForm(row, _manager); + var mediaAuditForm = new AddEditGameForm(row, row.DatabaseFile, _manager); var result = mediaAuditForm.ShowDialog(); if (result == DialogResult.OK) { @@ -215,5 +245,54 @@ private void dataGridViewGameList_CellDoubleClick(object sender, DataGridViewCel } } } + + private void deleteGameToolStripMenuItem_Click(object sender, EventArgs e) + { + var deleteFromDatabase = MessageBox.Show($"Are you sure you want to delete the {dataGridViewGameList.SelectedRows.Count} selected items from the database?", "Are you sure?", MessageBoxButtons.YesNo); + + List selectedRowsToDelete = new List(); + foreach (DataGridViewRow selectedRow in dataGridViewGameList.SelectedRows) + { + selectedRowsToDelete.Add(selectedRow.DataBoundItem as FrontEndGameViewModel); + } + + var removeTableFileList = selectedRowsToDelete.Where(p => !string.IsNullOrEmpty(p.FullPathToTable)).Select(p => p.FullPathToTable).ToList(); + var removeB2sFileList = selectedRowsToDelete.Where(p => !string.IsNullOrEmpty(p.FullPathToB2s)).Select(p => p.FullPathToB2s).ToList(); + + DialogResult removeTableFiles = DialogResult.No; + DialogResult removeB2sFiles = DialogResult.No; + if (removeTableFileList.Count > 0) + removeTableFiles = MessageBox.Show($"Do want to delete the actual table files?\r\n {string.Join("\r\n",removeTableFileList)}", "Delete Table Files?", MessageBoxButtons.YesNo); + if (removeB2sFileList.Count > 0) + removeB2sFiles = MessageBox.Show($"Do want to delete the actual B2S files?\r\n {string.Join("\r\n", removeB2sFileList)}", "Delete B2S Files?", MessageBoxButtons.YesNo); + + if (deleteFromDatabase == DialogResult.Yes) + { + if (dataGridViewGameList.SelectedRows.Count > 0) + { + var databaseFile = string.Empty; + foreach (DataGridViewRow selectedRow in dataGridViewGameList.SelectedRows) + { + var model = selectedRow.DataBoundItem as FrontEndGameViewModel; + databaseFile = model.DatabaseFile; + _manager.DeleteGame(model); + _fullGameListCache.Remove(model); + } + var frontEnd = cmbFrontEnd.SelectedItem as FrontEnd; + _manager.SaveDatabase(frontEnd.System, databaseFile); + RefreshGameGrid(); + } + } + if (removeTableFiles == DialogResult.Yes) + { + foreach (var tableFilePathToDelete in removeTableFileList) + File.Delete(tableFilePathToDelete); + } + if (removeB2sFiles == DialogResult.Yes) + { + foreach (var b2sFilePathToDelete in removeB2sFileList) + File.Delete(b2sFilePathToDelete); + } + } } } diff --git a/PinCab.Configurator/SettingsForm.cs b/PinCab.Configurator/SettingsForm.cs index 5812a02..335be9e 100644 --- a/PinCab.Configurator/SettingsForm.cs +++ b/PinCab.Configurator/SettingsForm.cs @@ -106,9 +106,9 @@ private void btnFFMpegFilePath_Click(object sender, EventArgs e) fileDialog.FilterIndex = 1; fileDialog.FileName = "ffmpeg.exe"; fileDialog.RestoreDirectory = true; - fileDialog.ShowDialog(); - - txtFFMpegFilePath.Text = fileDialog.FileName; + var result = fileDialog.ShowDialog(); + if (result == DialogResult.OK) + txtFFMpegFilePath.Text = fileDialog.FileName; } } diff --git a/PinCab.Utils/Models/PinballX/Platform.cs b/PinCab.Utils/Models/Platform.cs similarity index 92% rename from PinCab.Utils/Models/PinballX/Platform.cs rename to PinCab.Utils/Models/Platform.cs index 4b1a553..19ac1a6 100644 --- a/PinCab.Utils/Models/PinballX/Platform.cs +++ b/PinCab.Utils/Models/Platform.cs @@ -4,7 +4,7 @@ using System.Text; using System.Threading.Tasks; -namespace PinCab.Utils.Models.PinballX +namespace PinCab.Utils.Models { /// /// Different types of systems. diff --git a/PinCab.Utils/PinCab.Utils.csproj b/PinCab.Utils/PinCab.Utils.csproj index 32f9b58..ec1269c 100644 --- a/PinCab.Utils/PinCab.Utils.csproj +++ b/PinCab.Utils/PinCab.Utils.csproj @@ -156,7 +156,7 @@ - + diff --git a/PinCab.Utils/Utils/FrontEndManager.cs b/PinCab.Utils/Utils/FrontEndManager.cs index 58dd9e3..fec37e8 100644 --- a/PinCab.Utils/Utils/FrontEndManager.cs +++ b/PinCab.Utils/Utils/FrontEndManager.cs @@ -80,7 +80,26 @@ public void SaveGame(FrontEndGameViewModel game) pbxGame = MapViewToGame(system, pbxGame, game); _pinballXManager.AddOrUpdateGame(system, game.DatabaseFile, pbxGame); - _pinballXManager.SaveDatabase(system, game.DatabaseFile, true); + SaveDatabase(FrontEndSystem.PinballX, game.DatabaseFile); + } + } + + public void DeleteGame(FrontEndGameViewModel game) + { + if (game.FrontEnd.System == FrontEndSystem.PinballX) + { + var system = _pinballXSystems.FirstOrDefault(c => c.DatabaseFiles.Contains(game.DatabaseFile)); + var existingGame = system.Games[game.DatabaseFile].FirstOrDefault(c => c.FileName == game.FileName); + system.Games[game.DatabaseFile].Remove(existingGame); + } + } + + public void SaveDatabase(FrontEndSystem frontEnd, string databaseFile) + { + if (frontEnd == FrontEndSystem.PinballX) + { + var system = _pinballXSystems.FirstOrDefault(c => c.DatabaseFiles.Any(b => b.EndsWith(databaseFile))); + _pinballXManager.SaveDatabase(system, databaseFile, true); } } @@ -131,21 +150,21 @@ public List GetMediaAuditResults(FrontEnd frontEnd) if (frontEnd.System == FrontEndSystem.PinballX) { var games = new List(); - foreach (var system in _pinballXSystems) + foreach (var system in _pinballXSystems) { - foreach(var database in system.DatabaseFiles) + foreach (var database in system.DatabaseFiles) games.AddRange(GetPinballXFrontEndGames(frontEnd, database)); } //Now that we have all the games loaded and we have the statuses on all the media we can check into stranded media //by parsing all the media folders and getting every file inside of it, and matching it up with the games.MediaItems files //and if we have files that don't exist in the games.MediaItems list it is considered a stranded media item List allGameMedia = new List(); - foreach(var game in games) + foreach (var game in games) allGameMedia.AddRange(game.MediaItems.Select(c => c.MediaFullPath)); var allMediaFiles = GetAllMediaItems(frontEnd); - foreach(var media in allMediaFiles) + foreach (var media in allMediaFiles) { if (!allGameMedia.Contains(media.MediaFullPath)) auditResults.Add(new MediaAuditResult() { FrontEnd = frontEnd, FullPathToFile = media.MediaFullPath, Status = MediaAuditStatus.UnusedMedia, MediaType = media.MediaType }); @@ -213,11 +232,11 @@ public List GetAllMediaItems(FrontEnd frontEnd) private List GetMediaItemsInDirectory(MediaCategory category, string directory) { var mediaItems = new List(); - + if (Directory.Exists(directory)) { var filesInDirectory = Directory.GetFiles(directory, "*.*", SearchOption.AllDirectories); - foreach(var filePath in filesInDirectory) + foreach (var filePath in filesInDirectory) { var mediaItem = new MediaItem() { Category = category, MediaFullPath = filePath }; var mimeType = MimeTypes.MimeTypeMap.GetMimeType(filePath); @@ -271,7 +290,8 @@ private List GetPinballXFrontEndGames(FrontEnd frontEnd, Year = game.Year, Version = game.Version, PopperGameId = null, - TableFileUrl = game.TableFileUrl + TableFileUrl = game.TableFileUrl, + PlatformType = system.Type }; //Grab the table Statistics @@ -283,6 +303,10 @@ private List GetPinballXFrontEndGames(FrontEnd frontEnd, frontEndGame.Favorite = stats.Favorite; } + //See if there are discrepencies in the entries, such as missing DirectB2S for .vpx / .vpt files + //Or missing table + LoadPinballXAdditionalInfoAndDiscrepencies(system, frontEndGame); + //Load the Media Statuses for this game LoadPinballXMediaStatus(system, frontEndGame, new SearchMode[] { SearchMode.ByFileNameExactMatch }); @@ -295,6 +319,44 @@ private List GetPinballXFrontEndGames(FrontEnd frontEnd, return frontEndGames; } + private void LoadPinballXAdditionalInfoAndDiscrepencies(PinballXSystem system, FrontEndGameViewModel model) + { + //Find the detected game type + if (system.Type == Platform.VP) + { + //Populate the full file path to the game + if (File.Exists($"{system.TablePath}\\{model.FileName}.vpt")) + { + model.FullPathToTable = $"{system.TablePath}\\{model.FileName}.vpt"; + } + else if (File.Exists($"{system.TablePath}\\{model.FileName}.vpx")) + { + model.FullPathToTable = $"{system.TablePath}\\{model.FileName}.vpx"; + } + + else + { + //If it's a VPT or VPX, see if the directb2s is found and populate the file path to it as well + if (File.Exists($"{system.TablePath}\\{model.FileName}.directb2s")) + { + model.FullPathToB2s = $"{system.TablePath}\\{model.FileName}.directb2s"; + } + } + } + else if (system.Type == Platform.FP) //Could be a .fpt future pinball file + { + //Populate the full file path to the game + if (File.Exists($"{system.TablePath}\\{model.FileName}.fpt")) + { + model.FullPathToTable = $"{system.TablePath}\\{model.FileName}.fpt"; + } + } + + //If the file doesn't exist on the file system skip all these checks and mark it as a missing table entry + if (string.IsNullOrEmpty(model.FullPathToTable)) + model.MissingTable = true; + } + private void LoadPinballXMediaStatus(PinballXSystem system, FrontEndGameViewModel model, SearchMode[] searchModes) { var rootMediaPath = system.MediaPath.Replace(system.Name, string.Empty); diff --git a/PinCab.Utils/Utils/PinballX/PinballXManager.cs b/PinCab.Utils/Utils/PinballX/PinballXManager.cs index c790438..46ea3b8 100644 --- a/PinCab.Utils/Utils/PinballX/PinballXManager.cs +++ b/PinCab.Utils/Utils/PinballX/PinballXManager.cs @@ -1,6 +1,7 @@ using IniParser; using IniParser.Model; using Newtonsoft.Json; +using PinCab.Utils.Models; using PinCab.Utils.Models.PinballX; using Serilog; using System; diff --git a/PinCab.Utils/ViewModels/FrontEndGameViewModel.cs b/PinCab.Utils/ViewModels/FrontEndGameViewModel.cs index b46e064..bbc386e 100644 --- a/PinCab.Utils/ViewModels/FrontEndGameViewModel.cs +++ b/PinCab.Utils/ViewModels/FrontEndGameViewModel.cs @@ -77,5 +77,10 @@ public FrontEndGameViewModel() public bool Favorite { get; set; } public int TimesPlayed { get; set; } public int SecondsPlayed { get; set; } + + public bool MissingTable { get; set; } + public Platform PlatformType { get; set; } + public string FullPathToTable { get; set; } + public string FullPathToB2s { get; set; } } }