Rewrote a method and improved behavior

Rewrote the File Manager Form's 'lstDirectory_DoubleClick' method so it
is more clear, to prevent unnecessary strings being recreated, and
because it was making the same decision twice when it didn't need to.
Also placed the Setting Form's 'btnListen_Click' method in a try-finally
block so if anything goes wrong in the method, the state of it won't be
frozen (before, you would have to click out of the Form, discard
changes, then re-open. Perhaps it would be advisable to notify the user
of an issue with the listening if it failed...
This commit is contained in:
yankejustin 2015-04-12 22:19:08 -04:00
parent 0624500555
commit 40b2b8db5b
2 changed files with 31 additions and 22 deletions

View File

@ -60,14 +60,14 @@ private void lstDirectory_DoubleClick(object sender, EventArgs e)
{
if (lstDirectory.SelectedItems.Count != 0)
{
if (lstDirectory.SelectedItems[0].Tag.ToString() == "dir" && lstDirectory.SelectedItems[0].SubItems[0].Text == "..")
if (lstDirectory.SelectedItems[0].Tag.ToString() == "dir" && _connectClient.Value != null)
{
if (_connectClient.Value != null)
if (lstDirectory.SelectedItems[0].SubItems[0].Text == "..")
{
if (!_currentDir.EndsWith(@"\"))
_currentDir = _currentDir + @"\";
_currentDir = _currentDir.Remove(_currentDir.Length - 1);
if (_currentDir.EndsWith(@"\"))
{
_currentDir = _currentDir.Remove(_currentDir.Length - 1);
}
if (_currentDir.Length > 2)
_currentDir = _currentDir.Remove(_currentDir.LastIndexOf(@"\"));
@ -78,17 +78,14 @@ private void lstDirectory_DoubleClick(object sender, EventArgs e)
new Core.Packets.ServerPackets.Directory(_currentDir).Execute(_connectClient);
_connectClient.Value.LastDirectorySeen = false;
}
}
else if (lstDirectory.SelectedItems[0].Tag.ToString() == "dir")
{
if (_connectClient.Value != null)
else
{
if (_connectClient.Value.LastDirectorySeen)
{
if (_currentDir.EndsWith(@"\"))
_currentDir = _currentDir + lstDirectory.SelectedItems[0].SubItems[0].Text;
_currentDir += lstDirectory.SelectedItems[0].SubItems[0].Text;
else
_currentDir = _currentDir + @"\" + lstDirectory.SelectedItems[0].SubItems[0].Text;
_currentDir += @"\" + lstDirectory.SelectedItems[0].SubItems[0].Text;
new Core.Packets.ServerPackets.Directory(_currentDir).Execute(_connectClient);
_connectClient.Value.LastDirectorySeen = false;

View File

@ -36,20 +36,32 @@ private void btnListen_Click(object sender, EventArgs e)
{
if (btnListen.Text == "Start listening" && !_listenServer.Listening)
{
if (chkUseUpnp.Checked)
Core.Helper.UPnP.ForwardPort(ushort.Parse(ncPort.Value.ToString()));
try
{
if (chkUseUpnp.Checked)
Core.Helper.UPnP.ForwardPort(ushort.Parse(ncPort.Value.ToString()));
_listenServer.Listen(ushort.Parse(ncPort.Value.ToString()));
}
finally
{
_listenServer.Listen(ushort.Parse(ncPort.Value.ToString()));
btnListen.Text = "Stop listening";
ncPort.Enabled = false;
txtPassword.Enabled = false;
btnListen.Text = "Stop listening";
ncPort.Enabled = false;
txtPassword.Enabled = false;
}
}
else if (btnListen.Text == "Stop listening" && _listenServer.Listening)
{
_listenServer.Disconnect();
btnListen.Text = "Start listening";
ncPort.Enabled = true;
txtPassword.Enabled = true;
try
{
_listenServer.Disconnect();
}
finally
{
btnListen.Text = "Start listening";
ncPort.Enabled = true;
txtPassword.Enabled = true;
}
}
}