Merge pull request #191 from yankejustin/Improvements

Builder Code Improvements
This commit is contained in:
MaxXor 2015-05-25 09:11:42 +02:00
commit 043cfac6b7
1 changed files with 23 additions and 25 deletions

View File

@ -1,5 +1,6 @@
using System; using System;
using System.IO; using System.IO;
using System.Linq;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using System.Windows.Forms; using System.Windows.Forms;
using xServer.Core.Build; using xServer.Core.Build;
@ -20,8 +21,19 @@ namespace xServer.Forms
private void HasChanged() private void HasChanged()
{ {
if (_loadedProfile && !_changed) _changed = (_loadedProfile && !_changed);
_changed = true; }
private void UpdateControlStates()
{
txtInstallname.Enabled = chkInstall.Checked;
rbAppdata.Enabled = chkInstall.Checked;
rbProgramFiles.Enabled = chkInstall.Checked;
rbSystem.Enabled = chkInstall.Checked;
txtInstallsub.Enabled = chkInstall.Checked;
chkHide.Enabled = chkInstall.Checked;
chkStartup.Enabled = chkInstall.Checked;
txtRegistryKeyName.Enabled = (chkInstall.Checked && chkStartup.Checked);
} }
private void LoadProfile(string profilename) private void LoadProfile(string profilename)
@ -95,13 +107,7 @@ namespace xServer.Forms
txtMutex.Text = Helper.GetRandomName(32); txtMutex.Text = Helper.GetRandomName(32);
} }
txtInstallname.Enabled = chkInstall.Checked; UpdateControlStates();
rbAppdata.Enabled = chkInstall.Checked;
rbProgramFiles.Enabled = chkInstall.Checked;
rbSystem.Enabled = chkInstall.Checked;
txtInstallsub.Enabled = chkInstall.Checked;
chkHide.Enabled = chkInstall.Checked;
chkStartup.Enabled = chkInstall.Checked;
txtRegistryKeyName.Enabled = (chkInstall.Checked && chkStartup.Checked); txtRegistryKeyName.Enabled = (chkInstall.Checked && chkStartup.Checked);
@ -131,22 +137,21 @@ namespace xServer.Forms
private void txtDelay_KeyPress(object sender, KeyPressEventArgs e) private void txtDelay_KeyPress(object sender, KeyPressEventArgs e)
{ {
if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar)) e.Handled = (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar));
e.Handled = true;
} }
private void txtInstallname_KeyPress(object sender, KeyPressEventArgs e) private void txtInstallname_KeyPress(object sender, KeyPressEventArgs e)
{ {
string illegal = new string(Path.GetInvalidPathChars()) + new string(Path.GetInvalidFileNameChars()); char[] illegal = Path.GetInvalidPathChars().Union(Path.GetInvalidFileNameChars()).ToArray();
if ((e.KeyChar == '\\' || illegal.Contains(e.KeyChar.ToString())) && !char.IsControl(e.KeyChar))
e.Handled = true; e.Handled = ((e.KeyChar == '\\' || illegal.Any(illegalChar => (illegalChar == e.KeyChar))) && !char.IsControl(e.KeyChar));
} }
private void txtInstallsub_KeyPress(object sender, KeyPressEventArgs e) private void txtInstallsub_KeyPress(object sender, KeyPressEventArgs e)
{ {
string illegal = new string(Path.GetInvalidPathChars()) + new string(Path.GetInvalidFileNameChars()); char[] illegal = Path.GetInvalidPathChars().Union(Path.GetInvalidFileNameChars()).ToArray();
if ((e.KeyChar == '\\' || illegal.Contains(e.KeyChar.ToString())) && !char.IsControl(e.KeyChar))
e.Handled = true; e.Handled = ((e.KeyChar == '\\' || illegal.Any(illegalChar => (illegalChar == e.KeyChar))) && !char.IsControl(e.KeyChar));
} }
private void txtInstallname_TextChanged(object sender, EventArgs e) private void txtInstallname_TextChanged(object sender, EventArgs e)
@ -195,14 +200,7 @@ namespace xServer.Forms
{ {
HasChanged(); HasChanged();
txtInstallname.Enabled = chkInstall.Checked; UpdateControlStates();
rbAppdata.Enabled = chkInstall.Checked;
rbProgramFiles.Enabled = chkInstall.Checked;
rbSystem.Enabled = chkInstall.Checked;
txtInstallsub.Enabled = chkInstall.Checked;
chkHide.Enabled = chkInstall.Checked;
chkStartup.Enabled = chkInstall.Checked;
txtRegistryKeyName.Enabled = (chkInstall.Checked && chkStartup.Checked);
} }
private void chkStartup_CheckedChanged(object sender, EventArgs e) private void chkStartup_CheckedChanged(object sender, EventArgs e)