From 4a7b283aa33426e478a76e3756548c33f315a8bd Mon Sep 17 00:00:00 2001 From: tbS Date: Fri, 22 Aug 2025 17:12:15 +0200 Subject: [PATCH] =?UTF-8?q?-=20methode=20hinzugef=C3=BCgt=20um=20f=C3=BCr?= =?UTF-8?q?=20plugin=20oder=20ftp=20zu=20entschieden=20->=20demnach=20wird?= =?UTF-8?q?=20dashboard=20oder=20ftpview=20ge=C3=B6ffnet=20-=20plugin=20ze?= =?UTF-8?q?ile=20gee=C3=A4ndert=20um=20user=20eingabe=20zu=20nutzen=20-=20?= =?UTF-8?q?ftp=20ge=C3=A4ndert=20f=C3=BCr=20schnelleres=20testen=20der=20v?= =?UTF-8?q?erbindung=20und=20nutzen=20der=20user=20eingabe=20-=20function?= =?UTF-8?q?=20erweitert=20bei=20ftp=20daten=20in=20globale=20variable=20zu?= =?UTF-8?q?=20speichern=20->=20addvar,=20editvar=20-=20FTP=20Ordner=20aufr?= =?UTF-8?q?ufen=20und=20zur=C3=BCck=20funktion=20hinzugef=C3=BCgt=20/=20fe?= =?UTF-8?q?hler=20behoben?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Valheim Dashboard/App.axaml | 7 +- Valheim Dashboard/FtpClient.cs | 30 +++++-- Valheim Dashboard/Styles.axaml | 36 ++++++++ Valheim Dashboard/ViewModels/FTPViewModel.cs | 62 ++++++++++++-- Valheim Dashboard/Views/FTPView.axaml | 18 +++- Valheim Dashboard/Views/FTPView.axaml.cs | 4 +- Valheim Dashboard/Views/LizenzView.axaml | 1 + .../Views/ServerSettingsView.axaml | 1 + .../Views/ServerSettingsView.axaml.cs | 82 ++++++++++++++----- 9 files changed, 196 insertions(+), 45 deletions(-) create mode 100644 Valheim Dashboard/Styles.axaml diff --git a/Valheim Dashboard/App.axaml b/Valheim Dashboard/App.axaml index 903513b..2c9ba19 100644 --- a/Valheim Dashboard/App.axaml +++ b/Valheim Dashboard/App.axaml @@ -17,7 +17,8 @@ - - - + + + + \ No newline at end of file diff --git a/Valheim Dashboard/FtpClient.cs b/Valheim Dashboard/FtpClient.cs index 63acf47..c30542b 100644 --- a/Valheim Dashboard/FtpClient.cs +++ b/Valheim Dashboard/FtpClient.cs @@ -25,13 +25,33 @@ namespace Valheim_Dashboard { _ftpServer = ftpServer.EndsWith("/") ? ftpServer : ftpServer + "/"; _username = username; - _password = password; - FolderClickedCommand = ViewModel.FolderClickedCommand; + _password = password; + } + + + public bool TestConnection() + { + try + { + var request = (FtpWebRequest)WebRequest.Create(_ftpServer); + request.Method = WebRequestMethods.Ftp.ListDirectory; + request.Credentials = new NetworkCredential(_username, _password); + request.UsePassive = true; + request.UseBinary = true; + request.KeepAlive = false; + + using (var response = (FtpWebResponse)request.GetResponse()) + { + return response.StatusCode == FtpStatusCode.OpeningData + || response.StatusCode == FtpStatusCode.DataAlreadyOpen; + } + } + catch + { + return false; + } } - private FtpViewModel ViewModel; - - public ReactiveCommand FolderClickedCommand { get; private set; } diff --git a/Valheim Dashboard/Styles.axaml b/Valheim Dashboard/Styles.axaml new file mode 100644 index 0000000..005a3ac --- /dev/null +++ b/Valheim Dashboard/Styles.axaml @@ -0,0 +1,36 @@ + + + + + + + diff --git a/Valheim Dashboard/ViewModels/FTPViewModel.cs b/Valheim Dashboard/ViewModels/FTPViewModel.cs index aad6d1c..b51317a 100644 --- a/Valheim Dashboard/ViewModels/FTPViewModel.cs +++ b/Valheim Dashboard/ViewModels/FTPViewModel.cs @@ -1,9 +1,11 @@ using System; using System.Collections.ObjectModel; +using System.Diagnostics; using System.Linq; using System.Reactive; using System.Threading.Tasks; using ReactiveUI; +using Valheim_Dashboard.Views; namespace Valheim_Dashboard.ViewModels { @@ -20,8 +22,15 @@ namespace Valheim_Dashboard.ViewModels set => this.RaiseAndSetIfChanged(ref _currentPath, value); } + private bool _canGoBack; + public bool CanGoBack + { + get => _canGoBack; + set => this.RaiseAndSetIfChanged(ref _canGoBack, value); + } + + - // ObservableCollection, die jetzt FtpItem-Objekte enthält public ObservableCollection Files { get; } = new(); @@ -32,9 +41,12 @@ namespace Valheim_Dashboard.ViewModels public ReactiveCommand LoadFtpCommand { get; } // Command, der ausgeführt wird, wenn ein Ordner geklickt wird - public ReactiveCommand FolderClickedCommand { get; } + public ReactiveCommand FolderClickedCommand { get; } + + + // Command, der ausgeführt wird, wenn ein Ordner Zurück geklickt wird + public ReactiveCommand FolderBackClickedCommand { get; } - public FtpViewModel() { @@ -47,9 +59,17 @@ namespace Valheim_Dashboard.ViewModels FolderClickedCommand = ReactiveCommand.Create(item => { // Logik für den Klick auf das Folder-Item - Console.WriteLine($"Folder {item.Name} clicked!"); + Debug.WriteLine($"Folder {item.Name} clicked!"); + OnFolderClicked(item); }); - + + + FolderBackClickedCommand = ReactiveCommand.Create(item => + { + // Logik für den Klick auf das Folder-Item + OnFolderBackClicked(); + }); + // Beim Erstellen direkt FTP-Verzeichnis laden LoadFtpCommand.Execute().Subscribe(); Files.Add(new FtpItem { Name = "TestFile.txt", IsDirectory = false }); @@ -74,29 +94,53 @@ namespace Valheim_Dashboard.ViewModels Files.Clear(); foreach (var item in sortedItems) { - Console.WriteLine($"Item geladen: {item.Name}"); + Debug.WriteLine($"Item geladen: {item.Name + item.IsDirectory}"); // Je nach Bedarf kannst du hier den Namen oder auch weitere Infos anzeigen. Files.Add(item); } } catch (Exception ex) { - Console.WriteLine($"Fehler beim Laden des FTP-Verzeichnisses: {ex.Message}"); + Debug.WriteLine($"Fehler beim Laden des FTP-Verzeichnisses: {ex.Message}"); } } private void OnFolderClicked(FtpItem item) { - Console.WriteLine("OrdnerKlick"); + Debug.WriteLine("OrdnerKlick"); if (item.IsDirectory) { // Beispiel: Den aktuellen Pfad serweitern und das neue Verzeichnis laden // Je nach Bedarf kannst du hier auch Navigation oder andere Logik einbauen CurrentPath = System.IO.Path.Combine(CurrentPath, item.Name); + CurrentPath = CurrentPath.Replace("\\", "/"); + + + Debug.WriteLine("PATH: " + CurrentPath); + // Neues Verzeichnis laden LoadFtpCommand.Execute().Subscribe(); + + CanGoBack = true; } } - + + private void OnFolderBackClicked() + { + if (CurrentPath != "/") + { + var lastSlash = CurrentPath.LastIndexOf('/'); + if (lastSlash > 0) + CurrentPath = CurrentPath.Substring(0, lastSlash); + else + CurrentPath = "/"; + + LoadFtpCommand.Execute().Subscribe(); + + CanGoBack = CurrentPath != "/"; + } + } + + } } \ No newline at end of file diff --git a/Valheim Dashboard/Views/FTPView.axaml b/Valheim Dashboard/Views/FTPView.axaml index f5b504c..8b53f95 100644 --- a/Valheim Dashboard/Views/FTPView.axaml +++ b/Valheim Dashboard/Views/FTPView.axaml @@ -28,7 +28,17 @@ Height="100" Margin="50,0,50,0" Text="{Binding CurrentPath}"/> - + + diff --git a/Valheim Dashboard/Views/ServerSettingsView.axaml.cs b/Valheim Dashboard/Views/ServerSettingsView.axaml.cs index de44c98..10abc5d 100644 --- a/Valheim Dashboard/Views/ServerSettingsView.axaml.cs +++ b/Valheim Dashboard/Views/ServerSettingsView.axaml.cs @@ -1,15 +1,17 @@ -using System; -using System.Diagnostics; -using System.Net; -using System.Net.Http; -using System.Net.Http.Json; -using System.Reactive.Linq; -using System.Threading.Tasks; 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; @@ -136,13 +138,22 @@ public partial class ServerSettingsView : UserControl }); }); } + + string method; private void Weiter_OnClick(object? sender, RoutedEventArgs e) { if (this.Parent.Parent.Parent is MainWindow mainWindow) { if (mainWindow.DataContext is MainWindowViewModel mainWindowViewModel) { - - mainWindowViewModel.SwitchToFTP(ftpClient); + if (method == "plugin") + { + mainWindowViewModel.SwitchToDashboard(); + } + else + { + mainWindowViewModel.SwitchToFTP(ftpClient); + } + } } @@ -189,12 +200,14 @@ public partial class ServerSettingsView : UserControl try { - var response = await PluginClient.GetAsync("http://amp.tbs-server.de:2456"); + var response = await PluginClient.GetAsync("http://" + plugin_ip.Text + ":" + plugin_port.Text); if (response.IsSuccessStatusCode) { var data = await response.Content.ReadFromJsonAsync(); plugin_prüfen.Background = new SolidColorBrush(Colors.Green); plugin_prüfen.Content = "Verbindung Erfolgreich"; + weiter.IsEnabled = true; + method = "plugin"; Debug.WriteLine(data.ModVersion); }else { @@ -208,6 +221,7 @@ public partial class ServerSettingsView : UserControl plugin_prüfen.Background = new SolidColorBrush(Colors.Red); plugin_prüfen.Content = "Verbindung Fehlgeschlagen"; + weiter.IsEnabled = false; } @@ -221,24 +235,48 @@ public partial class ServerSettingsView : UserControl {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); - FtpViewModel._ftpClient = new FtpClient("ftp://192.168.178.34:21", "tbs_ftp", "JLI_._nTH-DyG53Se9"); - var files = await ftpClient.ListDirectoryDetailsAsync(); - - if (files != null && files.Count > 0) + + //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()) { - 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); - + 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.Green); - ftp_prüfen.Content = "Verbindung Erfolgreich2"; + 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) {