small improvements to MultiDiskBundler

This commit is contained in:
zeromus 2020-10-01 02:18:43 -04:00
parent 995993357f
commit 3fd7e11f60
2 changed files with 219 additions and 176 deletions

View File

@ -28,173 +28,187 @@
/// </summary> /// </summary>
private void InitializeComponent() private void InitializeComponent()
{ {
this.MultiDiskMenuStrip = new System.Windows.Forms.MenuStrip(); this.MultiDiskMenuStrip = new System.Windows.Forms.MenuStrip();
this.SaveRunButton = new System.Windows.Forms.Button(); this.SaveRunButton = new System.Windows.Forms.Button();
this.CancelBtn = new System.Windows.Forms.Button(); this.CancelBtn = new System.Windows.Forms.Button();
this.grpName = new System.Windows.Forms.GroupBox(); this.grpName = new System.Windows.Forms.GroupBox();
this.BrowseBtn = new System.Windows.Forms.Button(); this.BrowseBtn = new System.Windows.Forms.Button();
this.NameBox = new System.Windows.Forms.TextBox(); this.NameBox = new System.Windows.Forms.TextBox();
this.FileSelectorPanel = new System.Windows.Forms.Panel(); this.FileSelectorPanel = new System.Windows.Forms.Panel();
this.AddButton = new System.Windows.Forms.Button(); this.AddButton = new System.Windows.Forms.Button();
this.SystemDropDown = new System.Windows.Forms.ComboBox(); this.SystemDropDown = new System.Windows.Forms.ComboBox();
this.SystemLabel = new BizHawk.WinForms.Controls.LocLabelEx(); this.SystemLabel = new BizHawk.WinForms.Controls.LocLabelEx();
this.btnRemove = new System.Windows.Forms.Button(); this.btnRemove = new System.Windows.Forms.Button();
this.grpName.SuspendLayout(); this.SaveButton = new System.Windows.Forms.Button();
this.SuspendLayout(); this.grpName.SuspendLayout();
// this.SuspendLayout();
// MultiDiskMenuStrip //
// // MultiDiskMenuStrip
this.MultiDiskMenuStrip.Location = new System.Drawing.Point(0, 0); //
this.MultiDiskMenuStrip.Name = "MultiDiskMenuStrip"; this.MultiDiskMenuStrip.Location = new System.Drawing.Point(0, 0);
this.MultiDiskMenuStrip.Size = new System.Drawing.Size(506, 24); this.MultiDiskMenuStrip.Name = "MultiDiskMenuStrip";
this.MultiDiskMenuStrip.TabIndex = 0; this.MultiDiskMenuStrip.Size = new System.Drawing.Size(506, 24);
this.MultiDiskMenuStrip.Text = "menuStrip1"; this.MultiDiskMenuStrip.TabIndex = 0;
// this.MultiDiskMenuStrip.Text = "menuStrip1";
// SaveRunButton //
// // SaveRunButton
this.SaveRunButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); //
this.SaveRunButton.Enabled = false; this.SaveRunButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.SaveRunButton.Location = new System.Drawing.Point(343, 329); this.SaveRunButton.Enabled = false;
this.SaveRunButton.Name = "SaveRunButton"; this.SaveRunButton.Location = new System.Drawing.Point(318, 329);
this.SaveRunButton.Size = new System.Drawing.Size(85, 23); this.SaveRunButton.Name = "SaveRunButton";
this.SaveRunButton.TabIndex = 9; this.SaveRunButton.Size = new System.Drawing.Size(85, 23);
this.SaveRunButton.Text = "&Save and Run"; this.SaveRunButton.TabIndex = 9;
this.SaveRunButton.UseVisualStyleBackColor = true; this.SaveRunButton.Text = "Save and &Run";
this.SaveRunButton.Click += new System.EventHandler(this.SaveRunButton_Click); this.SaveRunButton.UseVisualStyleBackColor = true;
// this.SaveRunButton.Click += new System.EventHandler(this.SaveRunButton_Click);
// CancelBtn //
// // CancelBtn
this.CancelBtn.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); //
this.CancelBtn.DialogResult = System.Windows.Forms.DialogResult.Cancel; this.CancelBtn.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.CancelBtn.Location = new System.Drawing.Point(434, 329); this.CancelBtn.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.CancelBtn.Name = "CancelBtn"; this.CancelBtn.Location = new System.Drawing.Point(409, 329);
this.CancelBtn.Size = new System.Drawing.Size(60, 23); this.CancelBtn.Name = "CancelBtn";
this.CancelBtn.TabIndex = 10; this.CancelBtn.Size = new System.Drawing.Size(85, 23);
this.CancelBtn.Text = "&Cancel"; this.CancelBtn.TabIndex = 10;
this.CancelBtn.UseVisualStyleBackColor = true; this.CancelBtn.Text = "&Close";
this.CancelBtn.Click += new System.EventHandler(this.CancelBtn_Click); this.CancelBtn.UseVisualStyleBackColor = true;
// this.CancelBtn.Click += new System.EventHandler(this.CancelBtn_Click);
// grpName //
// // grpName
this.grpName.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) //
this.grpName.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right))); | System.Windows.Forms.AnchorStyles.Right)));
this.grpName.Controls.Add(this.BrowseBtn); this.grpName.Controls.Add(this.BrowseBtn);
this.grpName.Controls.Add(this.NameBox); this.grpName.Controls.Add(this.NameBox);
this.grpName.Location = new System.Drawing.Point(8, 28); this.grpName.Location = new System.Drawing.Point(8, 28);
this.grpName.Name = "grpName"; this.grpName.Name = "grpName";
this.grpName.Size = new System.Drawing.Size(486, 45); this.grpName.Size = new System.Drawing.Size(486, 45);
this.grpName.TabIndex = 11; this.grpName.TabIndex = 11;
this.grpName.TabStop = false; this.grpName.TabStop = false;
this.grpName.Text = "Name"; this.grpName.Text = "Name";
// //
// BrowseBtn // BrowseBtn
// //
this.BrowseBtn.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.BrowseBtn.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.BrowseBtn.Location = new System.Drawing.Point(417, 18); this.BrowseBtn.Location = new System.Drawing.Point(417, 18);
this.BrowseBtn.Name = "BrowseBtn"; this.BrowseBtn.Name = "BrowseBtn";
this.BrowseBtn.Size = new System.Drawing.Size(63, 23); this.BrowseBtn.Size = new System.Drawing.Size(63, 23);
this.BrowseBtn.TabIndex = 14; this.BrowseBtn.TabIndex = 14;
this.BrowseBtn.Text = "Browse..."; this.BrowseBtn.Text = "Browse...";
this.BrowseBtn.UseVisualStyleBackColor = true; this.BrowseBtn.UseVisualStyleBackColor = true;
this.BrowseBtn.Click += new System.EventHandler(this.BrowseBtn_Click); this.BrowseBtn.Click += new System.EventHandler(this.BrowseBtn_Click);
// //
// NameBox // NameBox
// //
this.NameBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) this.NameBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right))); | System.Windows.Forms.AnchorStyles.Right)));
this.NameBox.Location = new System.Drawing.Point(6, 19); this.NameBox.Location = new System.Drawing.Point(6, 19);
this.NameBox.Name = "NameBox"; this.NameBox.Name = "NameBox";
this.NameBox.Size = new System.Drawing.Size(405, 20); this.NameBox.Size = new System.Drawing.Size(405, 20);
this.NameBox.TabIndex = 0; this.NameBox.TabIndex = 0;
this.NameBox.TextChanged += new System.EventHandler(this.NameBox_TextChanged); this.NameBox.TextChanged += new System.EventHandler(this.NameBox_TextChanged);
// //
// FileSelectorPanel // FileSelectorPanel
// //
this.FileSelectorPanel.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) this.FileSelectorPanel.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right))); | System.Windows.Forms.AnchorStyles.Right)));
this.FileSelectorPanel.AutoScroll = true; this.FileSelectorPanel.AutoScroll = true;
this.FileSelectorPanel.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.FileSelectorPanel.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.FileSelectorPanel.Location = new System.Drawing.Point(8, 101); this.FileSelectorPanel.Location = new System.Drawing.Point(8, 101);
this.FileSelectorPanel.Name = "FileSelectorPanel"; this.FileSelectorPanel.Name = "FileSelectorPanel";
this.FileSelectorPanel.Size = new System.Drawing.Size(486, 222); this.FileSelectorPanel.Size = new System.Drawing.Size(486, 214);
this.FileSelectorPanel.TabIndex = 12; this.FileSelectorPanel.TabIndex = 12;
// //
// AddButton // AddButton
// //
this.AddButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); this.AddButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.AddButton.Location = new System.Drawing.Point(8, 329); this.AddButton.Location = new System.Drawing.Point(8, 329);
this.AddButton.Name = "AddButton"; this.AddButton.Name = "AddButton";
this.AddButton.Size = new System.Drawing.Size(60, 23); this.AddButton.Size = new System.Drawing.Size(60, 23);
this.AddButton.TabIndex = 13; this.AddButton.TabIndex = 13;
this.AddButton.Text = "Add"; this.AddButton.Text = "Add";
this.AddButton.UseVisualStyleBackColor = true; this.AddButton.UseVisualStyleBackColor = true;
this.AddButton.Click += new System.EventHandler(this.AddButton_Click); this.AddButton.Click += new System.EventHandler(this.AddButton_Click);
// //
// SystemDropDown // SystemDropDown
// //
this.SystemDropDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.SystemDropDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.SystemDropDown.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.SystemDropDown.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.SystemDropDown.FormattingEnabled = true; this.SystemDropDown.FormattingEnabled = true;
this.SystemDropDown.Items.AddRange(new object[] { this.SystemDropDown.Items.AddRange(new object[] {
"AppleII", "AppleII",
"C64", "C64",
"DGB", "DGB",
"GB3x", "GB3x",
"GB4x", "GB4x",
"GEN", "GEN",
"PCFX", "PCFX",
"PSX", "PSX",
"SAT", "SAT",
"ZXSpectrum", "ZXSpectrum",
"AmstradCPC", "AmstradCPC",
"Game Gear"}); "Game Gear"});
this.SystemDropDown.Location = new System.Drawing.Point(405, 75); this.SystemDropDown.Location = new System.Drawing.Point(405, 75);
this.SystemDropDown.Name = "SystemDropDown"; this.SystemDropDown.Name = "SystemDropDown";
this.SystemDropDown.Size = new System.Drawing.Size(89, 21); this.SystemDropDown.Size = new System.Drawing.Size(89, 21);
this.SystemDropDown.TabIndex = 14; this.SystemDropDown.TabIndex = 14;
this.SystemDropDown.SelectedIndexChanged += new System.EventHandler(this.SystemDropDown_SelectedIndexChanged); this.SystemDropDown.SelectedIndexChanged += new System.EventHandler(this.SystemDropDown_SelectedIndexChanged);
// //
// SystemLabel // SystemLabel
// //
this.SystemLabel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.SystemLabel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.SystemLabel.Location = new System.Drawing.Point(355, 78); this.SystemLabel.Location = new System.Drawing.Point(355, 78);
this.SystemLabel.Name = "SystemLabel"; this.SystemLabel.Name = "SystemLabel";
this.SystemLabel.Text = "System:"; this.SystemLabel.Text = "System:";
// //
// btnRemove // btnRemove
// //
this.btnRemove.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); this.btnRemove.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.btnRemove.Location = new System.Drawing.Point(74, 329); this.btnRemove.Location = new System.Drawing.Point(74, 329);
this.btnRemove.Name = "btnRemove"; this.btnRemove.Name = "btnRemove";
this.btnRemove.Size = new System.Drawing.Size(60, 23); this.btnRemove.Size = new System.Drawing.Size(60, 23);
this.btnRemove.TabIndex = 16; this.btnRemove.TabIndex = 16;
this.btnRemove.Text = "Remove"; this.btnRemove.Text = "Remove";
this.btnRemove.UseVisualStyleBackColor = true; this.btnRemove.UseVisualStyleBackColor = true;
this.btnRemove.Click += new System.EventHandler(this.btnRemove_Click); this.btnRemove.Click += new System.EventHandler(this.btnRemove_Click);
// //
// MultiDiskBundler // SaveButton
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.SaveButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.SaveButton.Enabled = false;
this.ClientSize = new System.Drawing.Size(506, 364); this.SaveButton.Location = new System.Drawing.Point(227, 329);
this.Controls.Add(this.btnRemove); this.SaveButton.Name = "SaveButton";
this.Controls.Add(this.SystemLabel); this.SaveButton.Size = new System.Drawing.Size(85, 23);
this.Controls.Add(this.SystemDropDown); this.SaveButton.TabIndex = 18;
this.Controls.Add(this.AddButton); this.SaveButton.Text = "&Save";
this.Controls.Add(this.FileSelectorPanel); this.SaveButton.UseVisualStyleBackColor = true;
this.Controls.Add(this.grpName); this.SaveButton.Click += new System.EventHandler(this.SaveButton_Click);
this.Controls.Add(this.CancelBtn); //
this.Controls.Add(this.SaveRunButton); // MultiDiskBundler
this.Controls.Add(this.MultiDiskMenuStrip); //
this.MainMenuStrip = this.MultiDiskMenuStrip; this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.Name = "MultiDiskBundler"; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; this.ClientSize = new System.Drawing.Size(506, 364);
this.Load += new System.EventHandler(this.MultiGameCreator_Load); this.Controls.Add(this.SaveButton);
this.grpName.ResumeLayout(false); this.Controls.Add(this.btnRemove);
this.grpName.PerformLayout(); this.Controls.Add(this.SystemLabel);
this.ResumeLayout(false); this.Controls.Add(this.SystemDropDown);
this.PerformLayout(); this.Controls.Add(this.AddButton);
this.Controls.Add(this.FileSelectorPanel);
this.Controls.Add(this.grpName);
this.Controls.Add(this.CancelBtn);
this.Controls.Add(this.SaveRunButton);
this.Controls.Add(this.MultiDiskMenuStrip);
this.MainMenuStrip = this.MultiDiskMenuStrip;
this.Name = "MultiDiskBundler";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Load += new System.EventHandler(this.MultiGameCreator_Load);
this.grpName.ResumeLayout(false);
this.grpName.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
} }
@ -211,5 +225,6 @@
private System.Windows.Forms.ComboBox SystemDropDown; private System.Windows.Forms.ComboBox SystemDropDown;
private BizHawk.WinForms.Controls.LocLabelEx SystemLabel; private BizHawk.WinForms.Controls.LocLabelEx SystemLabel;
private System.Windows.Forms.Button btnRemove; private System.Windows.Forms.Button btnRemove;
private System.Windows.Forms.Button SaveButton;
} }
} }

View File

@ -74,28 +74,45 @@ namespace BizHawk.Client.EmuHawk
Close(); Close();
} }
bool DoSave(out FileInfo fileInfo)
{
fileInfo = null;
if (!Recalculate())
return false;
fileInfo = new FileInfo(NameBox.Text);
if (fileInfo.Exists)
{
var result = MessageBox.Show(this, "File already exists, overwrite?", "File exists", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
if (result != DialogResult.OK)
{
return false;
}
}
File.WriteAllText(fileInfo.FullName, _currentXml.ToString());
return true;
}
private void SaveButton_Click(object sender, EventArgs e)
{
FileInfo dummy;
DoSave(out dummy);
}
private void SaveRunButton_Click(object sender, EventArgs e) private void SaveRunButton_Click(object sender, EventArgs e)
{ {
if (Recalculate()) FileInfo fileInfo;
{
var fileInfo = new FileInfo(NameBox.Text);
if (fileInfo.Exists)
{
var result = MessageBox.Show(this, "File already exists, overwrite?", "File exists", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
if (result != DialogResult.OK)
{
return;
}
}
File.WriteAllText(fileInfo.FullName, _currentXml.ToString()); if (!DoSave(out fileInfo))
return;
DialogResult = DialogResult.OK; DialogResult = DialogResult.OK;
Close(); Close();
var lra = new LoadRomArgs { OpenAdvanced = new OpenAdvanced_OpenRom { Path = fileInfo.FullName } }; var lra = new LoadRomArgs { OpenAdvanced = new OpenAdvanced_OpenRom { Path = fileInfo.FullName } };
MainForm.LoadRom(fileInfo.FullName, lra); MainForm.LoadRom(fileInfo.FullName, lra);
}
} }
private void AddButton_Click(object sender, EventArgs e) private void AddButton_Click(object sender, EventArgs e)
@ -141,6 +158,8 @@ namespace BizHawk.Client.EmuHawk
//One to our looper //One to our looper
i++; i++;
} }
Recalculate();
} }
private void FileSelector_NameChanged(object sender, EventArgs e) private void FileSelector_NameChanged(object sender, EventArgs e)
@ -159,6 +178,9 @@ namespace BizHawk.Client.EmuHawk
{ {
var names = FileSelectors.Select(f => f.Path).ToList(); var names = FileSelectors.Select(f => f.Path).ToList();
if (names.Count == 0)
goto BAIL;
var name = NameBox.Text; var name = NameBox.Text;
if (string.IsNullOrWhiteSpace(name)) if (string.IsNullOrWhiteSpace(name))
@ -198,14 +220,19 @@ namespace BizHawk.Client.EmuHawk
); );
SaveRunButton.Enabled = true; SaveRunButton.Enabled = true;
SaveButton.Enabled = true;
return true; return true;
} }
catch (Exception) catch (Exception)
{ {
_currentXml = null; //swallow exceptions, since this is just validation logic
SaveRunButton.Enabled = false;
return false;
} }
BAIL:
_currentXml = null;
SaveRunButton.Enabled = false;
SaveButton.Enabled = false;
return false;
} }
private void NameBox_TextChanged(object sender, EventArgs e) private void NameBox_TextChanged(object sender, EventArgs e)
@ -297,5 +324,6 @@ namespace BizHawk.Client.EmuHawk
AddButton_Click(null, null); AddButton_Click(null, null);
AddButton_Click(null, null); AddButton_Click(null, null);
} }
} }
} }