Skip to content

Commit

Permalink
#11
Browse files Browse the repository at this point in the history
  • Loading branch information
xantari committed Feb 17, 2021
1 parent dd75372 commit 29d1784
Show file tree
Hide file tree
Showing 7 changed files with 539 additions and 71 deletions.
1 change: 1 addition & 0 deletions PinCab.Configurator/AddEditGameForm.Designer.cs

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

60 changes: 45 additions & 15 deletions PinCab.Configurator/AddEditGameForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace PinCab.Configurator
public partial class AddEditGameForm : Form
{
private FrontEndGameViewModel _setting { get; set; }
private string originalFileName { get; set; }
//private string originalFileName { get; set; }
private FrontEndManager _manager { get; set; }
private string _databaseFile { get; set; }
private IpdbBrowserForm _ipdbForm = null;
Expand Down Expand Up @@ -141,7 +141,7 @@ private void btnSave_Click(object sender, EventArgs e)
return;
}

_manager.SaveGame(result);
_manager.SaveGame(result, null);
DialogResult = DialogResult.OK;
Close();
}
Expand All @@ -163,7 +163,7 @@ private void btnSelectFile_Click(object sender, EventArgs e)
{
var fi = new FileInfo(fileDialog.FileName);
var endIndex = fi.Name.LastIndexOf(fi.Extension);
originalFileName = txtTableName.Text;
//originalFileName = txtTableName.Text;
txtTableName.Text = fi.Name.Substring(0, endIndex);
if (isNewEntry)
{
Expand Down Expand Up @@ -210,27 +210,57 @@ private void btnGameUrl_Click(object sender, EventArgs e)
private void btnDatabaseBrowser_Click(object sender, EventArgs e)
{
var form = new DatabaseBrowserForm();
form.SearchByText(txtDisplayName.Text, new DateTime(1900,1,1), DateTime.Today.AddDays(1), new List<string>());
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)
var selectedSystem = _manager.GetPinballXSystemByDatabaseFile(_databaseFile);

if (selectedSystem.Type == Platform.VP || selectedSystem.Type == Platform.FP)
{
if (addNewForm.lstFiles.SelectedItem != null) //Can't select from an empty list
var addNewForm = new AddNewGameForm(_setting.FrontEnd, _setting.DatabaseFile, _manager);
var result = addNewForm.ShowDialog(this);
if (result == DialogResult.OK)
{
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)
if (addNewForm.lstFiles.SelectedItem != null) //Can't select from an empty list
{
txtModified.Text = fi.LastWriteTime.ToString();
txtAdded.Text = fi.CreationTime.ToString();
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();
}
}
}
}
else
MessageBox.Show("Show New not available for systems other then Future Pinball and Virtual Pinball.");
}

private void txtTableName_Leave(object sender, EventArgs e)
{
if (!isNewEntry)
{
var newValue = txtTableName.Text;
var oldValue = _setting.FileName;

//See if the table name has changed. If so popup the window to aid the user in renaming media
//https://github.com/xantari/PinCab.Configurator/issues/11
if (newValue != oldValue)
{
var renameForm = new RenameGameForm(_setting, txtTableName.Text, _manager);
var result = renameForm.ShowDialog(this);
if (result == DialogResult.OK)
{
txtTableName.Text = _setting.FileName;
}
else
txtTableName.Text = oldValue;
}
}
}
Expand Down
9 changes: 9 additions & 0 deletions PinCab.Configurator/Pincab.Configurator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,12 @@
<Compile Include="AboutBoxForm.Designer.cs">
<DependentUpon>AboutBoxForm.cs</DependentUpon>
</Compile>
<Compile Include="RenameGameForm.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="RenameGameForm.Designer.cs">
<DependentUpon>RenameGameForm.cs</DependentUpon>
</Compile>
<Compile Include="AddNewGameForm.cs">
<SubType>Form</SubType>
</Compile>
Expand Down Expand Up @@ -241,6 +247,9 @@
<EmbeddedResource Include="AboutBoxForm.resx">
<DependentUpon>AboutBoxForm.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="RenameGameForm.resx">
<DependentUpon>RenameGameForm.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="AddNewGameForm.resx">
<DependentUpon>AddNewGameForm.cs</DependentUpon>
</EmbeddedResource>
Expand Down
155 changes: 155 additions & 0 deletions PinCab.Configurator/RenameGameForm.Designer.cs

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

93 changes: 93 additions & 0 deletions PinCab.Configurator/RenameGameForm.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
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 RenameGameForm : Form
{
private FrontEndManager _manager { get; set; }
private FrontEndGameViewModel _setting { get; set; }
private string _newName { get; set; }
public RenameGameForm(FrontEndGameViewModel setting, string newName, FrontEndManager manager)
{
InitializeComponent();
_manager = manager;
_setting = setting;
_newName = newName;
LoadData();
}

private void LoadData()
{
lblCurrentName.Text = _setting.FileName;
lblNewName.Text = _newName;

if (!string.IsNullOrEmpty(_setting.FullPathToB2s))
chkFilesToRename.Items.Add(_setting.FullPathToB2s, true);
if (!string.IsNullOrEmpty(_setting.FullPathToTable))
chkFilesToRename.Items.Add(_setting.FullPathToTable, true);
foreach(var file in _setting.MediaItems)
{
chkFilesToRename.Items.Add(file.MediaFullPath, true);
}
chkSelectAll.Checked = true;
}

private void btnSave_Click(object sender, EventArgs e)
{
var oldName = _setting.FileName;
_setting.FileName = _newName;

//Rename all the selected files
for (int i = 0; i < chkFilesToRename.Items.Count; i++)
{
if (chkFilesToRename.GetItemChecked(i))
{
var fileToRename = chkFilesToRename.Items[i].ToString();
var fileInfo = new FileInfo(fileToRename);
var newFilePath = $"{fileInfo.DirectoryName}\\{_newName}{fileInfo.Extension}";
File.Move(fileToRename, newFilePath);
}
}

//Save the database
_manager.SaveGame(_setting, oldName);
//Refresh the model as they may not have selected all files to rename. In this case
//what happens is that some of the media audit statuses disappear
_manager.RefreshGameModel(_setting, _manager.GetPinballXSystemByDatabaseFile(_setting.DatabaseFile));

Close();
}

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

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

private void chkSelectAll_CheckedChanged(object sender, EventArgs e)
{
for(int i = 0; i < chkFilesToRename.Items.Count; i++)
{
chkFilesToRename.SetItemChecked(i, chkSelectAll.Checked);
}
}
}
}
Loading

0 comments on commit 29d1784

Please sign in to comment.