Skip to content

Commit

Permalink
Added quick add new table function
Browse files Browse the repository at this point in the history
  • Loading branch information
xantari committed Feb 7, 2021
1 parent d1ac66b commit f45f62a
Show file tree
Hide file tree
Showing 11 changed files with 446 additions and 75 deletions.
76 changes: 44 additions & 32 deletions PinCab.Configurator/AddEditGameForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions PinCab.Configurator/AddEditGameForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ public AddEditGameForm(FrontEndGameViewModel setting, string databaseFile, Front
_databaseFile = databaseFile;
_ipdbForm = ipdbForm;
if (string.IsNullOrEmpty(setting.Description))
{
isNewEntry = true;
}
if (_ipdbForm == null)
_ipdbForm = new IpdbBrowserForm(txtTableName.Text, true);
LoadForm();
Expand Down Expand Up @@ -90,6 +92,7 @@ private FrontEndGameViewModel GetSettingFromControls()
_setting.Players = txtPlayCount.Text.IfEmptyThenNull();
_setting.TimesPlayed = Convert.ToInt32(txtPlayCount.Text);
_setting.SecondsPlayed = Convert.ToInt32(txtSeconds.Text);
_setting.Enabled = chkEnabled.Checked;
if (!string.IsNullOrEmpty(txtAdded.Text))
{
DateTime result;
Expand Down Expand Up @@ -139,6 +142,7 @@ private void btnSave_Click(object sender, EventArgs e)
}

_manager.SaveGame(result);
DialogResult = DialogResult.OK;
Close();
}

Expand Down Expand Up @@ -209,5 +213,26 @@ private void btnDatabaseBrowser_Click(object sender, EventArgs e)
form.SearchByText(txtDisplayName.Text, new DateTime(1900,1,1), DateTime.Today.AddDays(1), new List<string>());
var result = form.ShowDialog(this);
}

private void btnShowNew_Click(object sender, EventArgs e)
{
var addNewForm = new AddNewGameForm(_setting.FrontEnd, _setting.DatabaseFile, _manager);
var result = addNewForm.ShowDialog(this);
if (result == DialogResult.OK)
{
if (addNewForm.lstFiles.SelectedItem != null) //Can't select from an empty list
{
var fi = new FileInfo(addNewForm.lstFiles.SelectedItem.ToString());
var endIndex = fi.Name.LastIndexOf(fi.Extension);
originalFileName = txtTableName.Text;
txtTableName.Text = fi.Name.Substring(0, endIndex);
if (isNewEntry)
{
txtModified.Text = fi.LastWriteTime.ToString();
txtAdded.Text = fi.CreationTime.ToString();
}
}
}
}
}
}
88 changes: 88 additions & 0 deletions PinCab.Configurator/AddNewGameForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

80 changes: 80 additions & 0 deletions PinCab.Configurator/AddNewGameForm.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
using PinCab.Utils.Extensions;
using PinCab.Utils.Models;
using PinCab.Utils.Utils;
using PinCab.Utils.ViewModels;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace PinCab.Configurator
{
public partial class AddNewGameForm : Form
{
private string _databaseFile { get; set; }
private FrontEndManager _manager { get; set; }
private FrontEnd _frontEnd { get; set; }
public AddNewGameForm(FrontEnd frontEnd, string databaseFile, FrontEndManager manager)
{
InitializeComponent();
_databaseFile = databaseFile;
_manager = manager;
_frontEnd = frontEnd;
LoadNewEntries();
}

private void LoadNewEntries()
{
if (_frontEnd.System == FrontEndSystem.PinballX)
{
var selectedSystem = _manager.GetPinballXSystemByDatabaseFile(_databaseFile);
var gameList = _manager.GetGamesForFrontEndAndDatabase(_frontEnd, _databaseFile);

//Now find all files in the systems folder that don't already exist in the gameList
var di = new DirectoryInfo(selectedSystem.TablePath);
if (di.Exists)
{
var files = di.GetFiles();
var tablePathsAlreadyInDatabase = gameList.Select(c => c.FullPathToTable);
foreach (var file in files)
{
if (selectedSystem.Type == Platform.VP &&
file.Extension.In(".vpt", ".vpx") &&
!tablePathsAlreadyInDatabase.Any(c => c == file.FullName))
{
lstFiles.Items.Add(file.FullName);
}
else if (selectedSystem.Type == Platform.FP &&
file.Extension.In(".fpt") &&
!tablePathsAlreadyInDatabase.Any(c => c == file.FullName))
{
lstFiles.Items.Add(file.FullName);
}
}
}
}
}

private void btnSelect_Click(object sender, EventArgs e)
{
Close();
}

private void button1_Click(object sender, EventArgs e)
{
Close();
}

private void lstFiles_SelectedIndexChanged(object sender, EventArgs e)
{
DialogResult = DialogResult.OK;
Close();
}
}
}
Loading

0 comments on commit f45f62a

Please sign in to comment.