Skip to content
This repository was archived by the owner on Sep 11, 2023. It is now read-only.

Commit 103e9a5

Browse files
committed
add empty field checks for test connection buttons in configs
1 parent dadd5c7 commit 103e9a5

File tree

2 files changed

+37
-9
lines changed

2 files changed

+37
-9
lines changed

UI/Windows/ConfigWindow.xaml.cs

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,19 @@ private void C_FTPDir_TextChanged(object sender, TextChangedEventArgs e)
530530

531531
private async void FTPTestConnectionButton_Click(object sender, RoutedEventArgs e)
532532
{
533-
ProgressDialogController? dialog = await this.ShowProgressAsync(Translate("TestingFTPConn"), Translate("PleaseWait"), settings: Program.MainWindow.MetroDialogOptions);
533+
var dialog = await this.ShowProgressAsync(Translate("TestingFTPConn"), Translate("PleaseWait"), settings: Program.MainWindow.MetroDialogOptions);
534+
535+
var host = C_FTPHost.Text;
536+
var user = C_FTPUser.Text;
537+
var pw = C_FTPPW.Password;
538+
539+
if (string.IsNullOrEmpty(host) || string.IsNullOrEmpty(user) || string.IsNullOrEmpty(pw))
540+
{
541+
await dialog?.CloseAsync();
542+
await this.ShowMessageAsync(Translate("Warning"), Translate("FTPFieldsEmpty"), settings: Program.MainWindow.MetroDialogOptions);
543+
return;
544+
}
545+
534546
var ftp = new FTP(C_FTPHost.Text, C_FTPUser.Text, C_FTPPW.Password);
535547
dialog.SetIndeterminate();
536548
dialog.SetCancelable(true);
@@ -594,7 +606,20 @@ private void C_RConPW_TextChanged(object sender, RoutedEventArgs e)
594606

595607
private async void RCONTestConnectionButton_Click(object sender, RoutedEventArgs e)
596608
{
597-
ProgressDialogController? dialog = await this.ShowProgressAsync(Translate("TestingRCONConn"), Translate("PleaseWait"), settings: Program.MainWindow.MetroDialogOptions);
609+
var success = true;
610+
var errorMsg = "";
611+
var dialog = await this.ShowProgressAsync(Translate("TestingRCONConn"), Translate("PleaseWait"), settings: Program.MainWindow.MetroDialogOptions);
612+
613+
var ip = C_RConIP.Text;
614+
var port = C_RConPort.Text;
615+
616+
if (string.IsNullOrEmpty(ip) || string.IsNullOrEmpty(port))
617+
{
618+
success = false;
619+
errorMsg = Translate("RCONFieldsEmpty");
620+
goto End;
621+
}
622+
598623
dialog.SetIndeterminate();
599624
dialog.SetCancelable(true);
600625
dialog.Canceled += async delegate
@@ -603,9 +628,6 @@ private async void RCONTestConnectionButton_Click(object sender, RoutedEventArgs
603628
return;
604629
};
605630

606-
var success = true;
607-
var errorMsg = "";
608-
609631
try
610632
{
611633
var server = ServerQuery.GetServerInstance(C_RConIP.Text, ushort.Parse(C_RConPort.Text));

Utils/Models/FTP.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Threading.Tasks;
55
using Renci.SshNet;
66
using Renci.SshNet.Common;
7+
using static SPCode.Interop.TranslationProvider;
78

89
namespace SPCode.Utils
910
{
@@ -51,7 +52,6 @@ public async Task<bool> TestConnection()
5152
{
5253
var requestUri = new UriBuilder(_host).Uri;
5354
var success = true;
54-
5555
if (requestUri.Scheme == "sftp")
5656
{
5757
var connectionInfo = new ConnectionInfo(requestUri.Host, requestUri.Port == -1 ? 22 : requestUri.Port, _user, new PasswordAuthenticationMethod(_user, _pass));
@@ -64,7 +64,7 @@ public async Task<bool> TestConnection()
6464
catch (SshAuthenticationException)
6565
{
6666
success = false;
67-
ErrorMessage = "Invalid credentials!";
67+
ErrorMessage = Translate("InvalidCredentials");
6868
}
6969
catch (Exception ex)
7070
{
@@ -77,7 +77,7 @@ public async Task<bool> TestConnection()
7777
sftp.Dispose();
7878
}
7979
}
80-
else
80+
else if (requestUri.Scheme == "ftp")
8181
{
8282
var requestDir = WebRequest.Create(requestUri);
8383
requestDir.Credentials = new NetworkCredential(_user, _pass);
@@ -86,11 +86,17 @@ public async Task<bool> TestConnection()
8686
{
8787
var response = await requestDir.GetResponseAsync();
8888
}
89-
catch
89+
catch (Exception ex)
9090
{
9191
success = false;
92+
ErrorMessage = ex.Message;
9293
}
9394
}
95+
else
96+
{
97+
success = false;
98+
ErrorMessage = Translate("InvalidFTPSchema");
99+
}
94100
return success;
95101
}
96102
}

0 commit comments

Comments
 (0)