- plugin zeile geeändert um user eingabe zu nutzen - ftp geändert für schnelleres testen der verbindung und nutzen der user eingabe - function erweitert bei ftp daten in globale variable zu speichern -> addvar, editvar - FTP Ordner aufrufen und zurück funktion hinzugefügt / fehler behoben
287 lines
13 KiB
C#
287 lines
13 KiB
C#
using Avalonia;
|
|
using Avalonia.Controls;
|
|
using Avalonia.Interactivity;
|
|
using Avalonia.Markup.Xaml;
|
|
using Avalonia.Media;
|
|
using System;
|
|
using System.Diagnostics;
|
|
using System.Net;
|
|
using System.Net.Http;
|
|
using System.Net.Http.Json;
|
|
using System.Net.Mail;
|
|
using System.Reactive.Linq;
|
|
using System.Text.Json;
|
|
using System.Threading.Tasks;
|
|
using Tmds.DBus.Protocol;
|
|
using Valheim_Dashboard.ViewModels;
|
|
|
|
namespace Valheim_Dashboard.Views;
|
|
|
|
public partial class ServerSettingsView : UserControl
|
|
{
|
|
|
|
|
|
private TutorialManager _tutorialManager;
|
|
|
|
public ServerSettingsView()
|
|
{
|
|
InitializeComponent();
|
|
|
|
this.Initialized += (sender, e) =>
|
|
{
|
|
var window = this.VisualRoot as Window;
|
|
|
|
if (window == null)
|
|
throw new InvalidOperationException("Das übergeordnete Element ist kein Fenster.");
|
|
|
|
// TutorialManager direkt im Code-Behind initialisieren
|
|
_tutorialManager = new TutorialManager(window);
|
|
|
|
// Beispiel: Ein Tutorial starten
|
|
// StartTutorial();
|
|
};
|
|
}
|
|
|
|
public void StartTutorial()
|
|
{
|
|
var pluginExpander = Plugin;
|
|
var pluginIpTextBox = plugin_ip;
|
|
var pluginPortTextBox = plugin_port;
|
|
var pluginUeberpruefen = plugin_prüfen;
|
|
var ftpExpander = FTP;
|
|
var ftpIpTextBox = ftp_ip;
|
|
var ftpPortTextBox = ftp_port;
|
|
var ftpBenutzernameTextBox = ftp_benutzername;
|
|
var ftpPasswortTextBox = ftp_passwort;
|
|
var ftpUeberpruefen = ftp_prüfen;
|
|
|
|
// Schritt 1: Sprechblase anzeigen: Öffnen des Plugin-Expanders oder FTP-Expanders
|
|
_tutorialManager.HighlightElement(pluginExpander, new SolidColorBrush(Colors.Yellow));
|
|
_tutorialManager.HighlightElement(ftpExpander, new SolidColorBrush(Colors.Yellow));
|
|
_tutorialManager.ShowSpeechBubble(pluginExpander, TutorialManager.SpeechBubblePosition.Top, Language.GetString("Server_Schritt_1"), () =>
|
|
{
|
|
// Schritt 2: Plugin-Expander öffnen und Sprechblase ändern
|
|
_tutorialManager.OpenExpander(pluginExpander);
|
|
_tutorialManager.HighlightElement(pluginExpander, new SolidColorBrush(Colors.Transparent));
|
|
_tutorialManager.HighlightElement(ftpExpander, new SolidColorBrush(Colors.Transparent));
|
|
// Beide Felder hervorheben
|
|
_tutorialManager.HighlightElement(pluginIpTextBox, new SolidColorBrush(Colors.LightBlue));
|
|
_tutorialManager.HighlightElement(pluginPortTextBox, new SolidColorBrush(Colors.LightBlue));
|
|
|
|
_tutorialManager.ShowSpeechBubble(pluginExpander, TutorialManager.SpeechBubblePosition.Right,Language.GetString("Server_Schritt_2"), () =>
|
|
{
|
|
// Schritt 3: Beispielwerte in IP- und Port-Felder eintragen
|
|
pluginIpTextBox.Text = "127.0.0.1";
|
|
pluginPortTextBox.Text = "2456";
|
|
_tutorialManager.HighlightElement(pluginUeberpruefen, new SolidColorBrush(Colors.LightBlue));
|
|
|
|
|
|
|
|
// Nächste Sprechblase: Warten auf Weiter!
|
|
_tutorialManager.ShowSpeechBubble(pluginExpander, TutorialManager.SpeechBubblePosition.Right,Language.GetString("Server_Schritt_3"), () =>
|
|
{
|
|
// Schritt 4: Nächste Aktion einleiten (falls notwendig)
|
|
_tutorialManager.ClickButton(pluginUeberpruefen);
|
|
Task.Delay(2000);
|
|
pluginUeberpruefen.Background = new SolidColorBrush(Colors.Green);
|
|
pluginUeberpruefen.Content = "Erfolgreich Verbunden!";
|
|
|
|
_tutorialManager.ShowSpeechBubble(ftpExpander, TutorialManager.SpeechBubblePosition.Left,
|
|
Language.GetString("Server_Schritt_4"),
|
|
() =>
|
|
{
|
|
_tutorialManager.CloseExpander(pluginExpander);
|
|
_tutorialManager.HighlightElement(pluginIpTextBox, new SolidColorBrush(Colors.Transparent));
|
|
_tutorialManager.HighlightElement(pluginPortTextBox, new SolidColorBrush(Colors.Transparent));
|
|
_tutorialManager.HighlightElement(pluginUeberpruefen, new SolidColorBrush(Colors.Transparent));
|
|
pluginIpTextBox.Text = "";
|
|
pluginPortTextBox.Text = "";
|
|
pluginUeberpruefen.Background = new SolidColorBrush(Colors.Gray);
|
|
pluginUeberpruefen.Content = "Verbindung Prüfen";
|
|
_tutorialManager.OpenExpander(ftpExpander);
|
|
_tutorialManager.HighlightElement(ftpIpTextBox, new SolidColorBrush(Colors.LightBlue));
|
|
_tutorialManager.HighlightElement(ftpPortTextBox, new SolidColorBrush(Colors.LightBlue));
|
|
_tutorialManager.HighlightElement(ftpBenutzernameTextBox, new SolidColorBrush(Colors.LightBlue));
|
|
_tutorialManager.HighlightElement(ftpPasswortTextBox, new SolidColorBrush(Colors.LightBlue));
|
|
|
|
_tutorialManager.ShowSpeechBubble(ftpExpander, TutorialManager.SpeechBubblePosition.Left,
|
|
Language.GetString("Server_Schritt_5"),
|
|
async () =>
|
|
{
|
|
|
|
_tutorialManager.WriteText(ftpIpTextBox, "127.0.0.1");
|
|
_tutorialManager.WriteText(ftpPortTextBox, "21");
|
|
_tutorialManager.WriteText(ftpBenutzernameTextBox, "ftpUser");
|
|
_tutorialManager.WriteText(ftpPasswortTextBox, "123456789");
|
|
|
|
await _tutorialManager.SmoothScrollToControl(ftp_scroll, ftpUeberpruefen);
|
|
Task.Delay(2000);
|
|
|
|
_tutorialManager.ClickButton(ftpUeberpruefen);
|
|
ftpUeberpruefen.Background = new SolidColorBrush(Colors.Green);
|
|
ftpUeberpruefen.Content = "Verbindung Erfolgreich";
|
|
|
|
_tutorialManager.ShowSpeechBubble(ftpExpander,
|
|
TutorialManager.SpeechBubblePosition.Left,
|
|
Language.GetString("Server_Schritt_6"),
|
|
() =>
|
|
{
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
});
|
|
});
|
|
});
|
|
}
|
|
|
|
string method;
|
|
private void Weiter_OnClick(object? sender, RoutedEventArgs e)
|
|
{
|
|
if (this.Parent.Parent.Parent is MainWindow mainWindow) {
|
|
if (mainWindow.DataContext is MainWindowViewModel mainWindowViewModel)
|
|
{
|
|
if (method == "plugin")
|
|
{
|
|
mainWindowViewModel.SwitchToDashboard();
|
|
}
|
|
else
|
|
{
|
|
mainWindowViewModel.SwitchToFTP(ftpClient);
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
public class DataPluginJson
|
|
{
|
|
public string ModVersion { get; set; }
|
|
public string PluginVersion { get; set; }
|
|
public string HashPlugins { get; set; }
|
|
public string HashConfig { get; set; }
|
|
public string HashClientSide { get; set; }
|
|
public string OldConfigFiles { get; set; }
|
|
public string OldConfigFolder { get; set; }
|
|
public string OldConfigFolderFiles { get; set; }
|
|
public string OldPluginFiles { get; set; }
|
|
public string OldPluginFolder { get; set; }
|
|
public string OldPluginFolderFiles { get; set; }
|
|
public string ConfigFilestoDelete { get; set; }
|
|
public string ConfigFoldertoDelete { get; set; }
|
|
public string ConfigFolderFilestoDelete { get; set; }
|
|
public string PluginFilestoDelete { get; set; }
|
|
public string PluginFoldertoDelete { get; set; }
|
|
public string PluginFolderFilestoDelete { get; set; }
|
|
public string OldClientSideConfigFiles { get; set; }
|
|
public string OldClientSideConfigFolder { get; set; }
|
|
public string OldClientSideConfigFolderFiles { get; set; }
|
|
public string OldClientSidePluginFiles { get; set; }
|
|
public string OldClientSidePluginFolder { get; set; }
|
|
public string OldClientSidePluginFolderFiles { get; set; }
|
|
public string ClientSideConfigFilestoDelete { get; set; }
|
|
public string ClientSideConfigFoldertoDelete { get; set; }
|
|
public string ClientSideConfigFolderFilestoDelete { get; set; }
|
|
public string ClientSidePluginFilestoDelete { get; set; }
|
|
public string ClientSidePluginFoldertoDelete { get; set; }
|
|
public string ClientSidePluginFolderFilestoDelete { get; set; }
|
|
}
|
|
|
|
|
|
private async void Plugin_prüfen_OnClick(object? sender, RoutedEventArgs e)
|
|
{
|
|
|
|
HttpClient PluginClient = new HttpClient();
|
|
|
|
try
|
|
{
|
|
var response = await PluginClient.GetAsync("http://" + plugin_ip.Text + ":" + plugin_port.Text);
|
|
if (response.IsSuccessStatusCode)
|
|
{
|
|
var data = await response.Content.ReadFromJsonAsync<DataPluginJson>();
|
|
plugin_prüfen.Background = new SolidColorBrush(Colors.Green);
|
|
plugin_prüfen.Content = "Verbindung Erfolgreich";
|
|
weiter.IsEnabled = true;
|
|
method = "plugin";
|
|
Debug.WriteLine(data.ModVersion);
|
|
}else
|
|
{
|
|
plugin_prüfen.Background = new SolidColorBrush(Colors.Red);
|
|
plugin_prüfen.Content = "Verbindung Fehlgeschlagen";
|
|
}
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
|
|
plugin_prüfen.Background = new SolidColorBrush(Colors.Red);
|
|
plugin_prüfen.Content = "Verbindung Fehlgeschlagen";
|
|
weiter.IsEnabled = false;
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
private FtpClient ftpClient;
|
|
private async void Ftp_prüfen_OnClick(object? sender, RoutedEventArgs e)
|
|
{
|
|
try
|
|
{Console.WriteLine(ftp_ip.Text + ftp_port.Text + ftp_benutzername.Text + ftp_passwort.Text);
|
|
|
|
//ftpClient = new FtpClient("ftp://"+ ftp_ip.Text + ":" +ftp_port.Text, ftp_benutzername.Text, ftp_passwort.Text);
|
|
|
|
//FtpClient ftpClient = new FtpClient("ftp://"+ ftp_ip.Text + ":" +ftp_port.Text, ftp_benutzername.Text, ftp_passwort.Text);
|
|
FtpViewModel._ftpClient = new FtpClient("ftp://" + ftp_ip.Text + ":" + ftp_port.Text, ftp_benutzername.Text, ftp_passwort.Text);
|
|
if (FtpViewModel._ftpClient.TestConnection())
|
|
{
|
|
ftp_prüfen.Background = new SolidColorBrush(Colors.Green);
|
|
ftp_prüfen.Content = "Verbindung Erfolgreich";
|
|
if (JsonDocument.Parse(LizenzView.KeyAuthApp.webhook("recivevar", "&name=" + LizenzView.lizenz_name[1], "")).RootElement.GetProperty("success").GetBoolean())
|
|
{
|
|
LizenzView.KeyAuthApp.webhook("editvar", "&varid=" + LizenzView.lizenz_name[1] + "&data=fhtjfthjtfh", "");
|
|
}else
|
|
{
|
|
LizenzView.KeyAuthApp.webhook("aHtrWbrxrZ", "&name=" + LizenzView.lizenz_name[1] + "&data=teasdrz", "");
|
|
}
|
|
|
|
weiter.IsEnabled = true;
|
|
method = "ftp";
|
|
}
|
|
else
|
|
{
|
|
ftp_prüfen.Background = new SolidColorBrush(Colors.Red);
|
|
ftp_prüfen.Content = "Verbindung Fehlgeschlagen";
|
|
weiter.IsEnabled = false;
|
|
}
|
|
|
|
//var files = await ftpClient.ListDirectoryDetailsAsync();
|
|
|
|
/* if (files != null && files.Count > 0)
|
|
{
|
|
var name = "tbs";
|
|
ftp_prüfen.Background = new SolidColorBrush(Colors.Green);
|
|
ftp_prüfen.Content = "Verbindung Erfolgreich1";
|
|
Console.WriteLine(files);
|
|
LizenzView.KeyAuthApp.webhook("aHtrWbrxrZ", "&name="+ LizenzView.lizenz_name[1] +"&data=testabc", "");
|
|
Console.WriteLine(LizenzView.KeyAuthApp.response.message);
|
|
|
|
}
|
|
else
|
|
{
|
|
ftp_prüfen.Background = new SolidColorBrush(Colors.Green);
|
|
ftp_prüfen.Content = "Verbindung Erfolgreich2";
|
|
} */
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Console.WriteLine($"Fehler beim Verbinden: {ex.Message}");
|
|
}
|
|
|
|
}
|
|
} |