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

Commit 599acae

Browse files
committed
finish RCON test button
1 parent 6ca6b7f commit 599acae

File tree

2 files changed

+37
-19
lines changed

2 files changed

+37
-19
lines changed

UI/Components/EditorElement/EditorElement.xaml.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -286,9 +286,7 @@ private void FileWatcher_Changed(object sender, FileSystemEventArgs e)
286286
{
287287
// ignored
288288
}
289-
290-
Thread.Sleep(
291-
100); //dont include System.Threading in the using directives, cause its onlyused once and the Timer class will double
289+
Thread.Sleep(100);
292290
}
293291
});
294292
}

UI/Windows/ConfigWindow.xaml.cs

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ private void C_FTPDir_TextChanged(object sender, TextChangedEventArgs e)
505505

506506
private async void FTPTestConnectionButton_Click(object sender, RoutedEventArgs e)
507507
{
508-
var dialog = await this.ShowProgressAsync("Testing the FTP connection with the provided details...", "Please wait...", settings: Program.MainWindow.MetroDialogOptions);
508+
ProgressDialogController? dialog = await this.ShowProgressAsync(Translate("TestingFTPConn"), Translate("PleaseWait"), settings: Program.MainWindow.MetroDialogOptions);
509509
var ftp = new FTP(C_FTPHost.Text, C_FTPUser.Text, C_FTPPW.Password);
510510
dialog.SetIndeterminate();
511511
dialog.SetCancelable(true);
@@ -514,15 +514,20 @@ private async void FTPTestConnectionButton_Click(object sender, RoutedEventArgs
514514
await dialog?.CloseAsync();
515515
return;
516516
};
517-
if (await ftp.TestConnection())
517+
var result = await ftp.TestConnection();
518+
if ((bool)dialog?.IsCanceled)
519+
{
520+
return;
521+
}
522+
if (result)
518523
{
519524
await dialog?.CloseAsync();
520-
await this.ShowMessageAsync("Success", "Connection successful!", settings: Program.MainWindow.MetroDialogOptions);
525+
await this.ShowMessageAsync(Translate("Success"), string.Empty, settings: Program.MainWindow.MetroDialogOptions);
521526
}
522527
else
523528
{
524529
await dialog?.CloseAsync();
525-
await this.ShowMessageAsync("Error", $"The connection could not be made! Message: {ftp.ErrorMessage}", settings: Program.MainWindow.MetroDialogOptions);
530+
await this.ShowMessageAsync(Translate("Error"), ftp.ErrorMessage, settings: Program.MainWindow.MetroDialogOptions);
526531
}
527532
}
528533

@@ -564,43 +569,58 @@ private void C_RConPW_TextChanged(object sender, RoutedEventArgs e)
564569

565570
private async void RCONTestConnectionButton_Click(object sender, RoutedEventArgs e)
566571
{
567-
var dialog = await this.ShowProgressAsync("Testing RCON connection...", "Please wait...", settings: Program.MainWindow.MetroDialogOptions);
572+
ProgressDialogController? dialog = await this.ShowProgressAsync(Translate("TestingRCONConn"), Translate("PleaseWait"), settings: Program.MainWindow.MetroDialogOptions);
568573
dialog.SetIndeterminate();
569574
dialog.SetCancelable(true);
570575
dialog.Canceled += async delegate
571576
{
572577
await dialog?.CloseAsync();
573578
return;
574579
};
580+
575581
var success = true;
576582
var errorMsg = "";
583+
577584
try
578585
{
579-
await Dispatcher.InvokeAsync(() =>
586+
var server = ServerQuery.GetServerInstance(C_RConIP.Text, ushort.Parse(C_RConPort.Text));
587+
var sInfo = new ServerInfo();
588+
// See if the provided details at least point to a valid server
589+
await Task.Run(() => { sInfo = server.GetInfo(); });
590+
if (sInfo == null)
580591
{
581-
var server = ServerQuery.GetServerInstance(C_RConIP.Text, ushort.Parse(C_RConPort.Text));
582-
server.GetInfo();
583-
if (!server.GetControl(C_RConPW.Password, false))
584-
{
585-
success = false;
586-
errorMsg = "Invalid credentials!";
587-
}
588-
});
592+
success = false;
593+
errorMsg = Translate("RCONFailureMessage");
594+
goto End;
595+
}
596+
bool done = false;
597+
await Task.Run(() => { done = server.GetControl(C_RConPW.Password, false); });
598+
if (!done)
599+
{
600+
success = false;
601+
errorMsg = Translate("InvalidCredentials");
602+
}
589603
}
590604
catch (Exception ex)
591605
{
592606
success = false;
593607
errorMsg = ex.Message;
594608
}
595609

610+
End:
611+
612+
if ((bool)dialog?.IsCanceled)
613+
{
614+
return;
615+
}
596616
await dialog?.CloseAsync();
597617
if (success)
598618
{
599-
await this.ShowMessageAsync("Success", "The connection was successful!", settings: Program.MainWindow.MetroDialogOptions);
619+
await this.ShowMessageAsync(Translate("Success"), string.Empty, settings: Program.MainWindow.MetroDialogOptions);
600620
}
601621
else
602622
{
603-
await this.ShowMessageAsync("Error", $"The connection could not be made! Message: {errorMsg}", settings: Program.MainWindow.MetroDialogOptions);
623+
await this.ShowMessageAsync(Translate("Error"), errorMsg, settings: Program.MainWindow.MetroDialogOptions);
604624
}
605625
}
606626

0 commit comments

Comments
 (0)