From efd904b660d1c62ce092ae74f3332382f5ace829 Mon Sep 17 00:00:00 2001 From: Shirkie01 Date: Sat, 6 Jan 2024 22:53:42 -0800 Subject: [PATCH 1/2] Prevents crashing when a user attempts to connect without a filename. --- LiteDB.Studio/Forms/ConnectionForm.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/LiteDB.Studio/Forms/ConnectionForm.cs b/LiteDB.Studio/Forms/ConnectionForm.cs index 2f9640d..ef671d7 100644 --- a/LiteDB.Studio/Forms/ConnectionForm.cs +++ b/LiteDB.Studio/Forms/ConnectionForm.cs @@ -55,6 +55,11 @@ private void BtnConnect_Click(object sender, EventArgs e) radModeDirect.Checked ? ConnectionType.Direct : radModeShared.Checked ? ConnectionType.Shared : ConnectionType.Direct; + if(string.IsNullOrWhiteSpace(txtFilename.Text)) + { + return; + } + this.ConnectionString.Filename = txtFilename.Text; this.ConnectionString.ReadOnly = chkReadonly.Checked; this.ConnectionString.Upgrade = chkUpgrade.Checked; From 2b458b1d2ae90a7dc9a0b8efeb855ca151b0d5b9 Mon Sep 17 00:00:00 2001 From: Shirkie01 Date: Sat, 6 Jan 2024 23:05:32 -0800 Subject: [PATCH 2/2] Moved the return statement to be the first statement so the ConnectionString object isn't put into an invalid state. --- LiteDB.Studio/Forms/ConnectionForm.cs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/LiteDB.Studio/Forms/ConnectionForm.cs b/LiteDB.Studio/Forms/ConnectionForm.cs index ef671d7..a692bc5 100644 --- a/LiteDB.Studio/Forms/ConnectionForm.cs +++ b/LiteDB.Studio/Forms/ConnectionForm.cs @@ -51,15 +51,16 @@ public ConnectionForm(ConnectionString cs) private void BtnConnect_Click(object sender, EventArgs e) { - this.ConnectionString.Connection = - radModeDirect.Checked ? ConnectionType.Direct : - radModeShared.Checked ? ConnectionType.Shared : ConnectionType.Direct; - + // If no file is specified, don't try to connect if(string.IsNullOrWhiteSpace(txtFilename.Text)) { return; } + this.ConnectionString.Connection = + radModeDirect.Checked ? ConnectionType.Direct : + radModeShared.Checked ? ConnectionType.Shared : ConnectionType.Direct; + this.ConnectionString.Filename = txtFilename.Text; this.ConnectionString.ReadOnly = chkReadonly.Checked; this.ConnectionString.Upgrade = chkUpgrade.Checked;