- methode hinzugefügt um für plugin oder ftp zu entschieden -> demnach wird dashboard oder ftpview geöffnet

- 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
This commit is contained in:
tbS
2025-08-22 17:12:15 +02:00
parent 7120c81089
commit 4a7b283aa3
9 changed files with 196 additions and 45 deletions

View File

@@ -17,7 +17,8 @@
<views:FtpView/> <views:FtpView/>
</DataTemplate> </DataTemplate>
</Application.DataTemplates> </Application.DataTemplates>
<Application.Styles> <Application.Styles>
<FluentTheme /> <FluentTheme/>
</Application.Styles> <StyleInclude Source="Styles.axaml"/>
</Application.Styles>
</Application> </Application>

View File

@@ -26,11 +26,31 @@ namespace Valheim_Dashboard
_ftpServer = ftpServer.EndsWith("/") ? ftpServer : ftpServer + "/"; _ftpServer = ftpServer.EndsWith("/") ? ftpServer : ftpServer + "/";
_username = username; _username = username;
_password = password; _password = password;
FolderClickedCommand = ViewModel.FolderClickedCommand;
} }
private FtpViewModel ViewModel;
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;
}
}
public ReactiveCommand<FtpItem, Unit> FolderClickedCommand { get; private set; } public ReactiveCommand<FtpItem, Unit> FolderClickedCommand { get; private set; }

View File

@@ -0,0 +1,36 @@
<Styles xmlns="https://github.com/avaloniaui">
<Style Selector="Button.NavButton">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="Foreground" Value="White"/>
<Setter Property="Padding" Value="10,5"/>
<Setter Property="BorderBrush" Value="Transparent"/>
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="FontWeight" Value="SemiBold"/>
<Setter Property="Cursor" Value="Hand"/>
<Setter Property="Template">
<Template>
<Border Background="{TemplateBinding Background}"
CornerRadius="4">
<ContentPresenter HorizontalAlignment="Center"
VerticalAlignment="Center"/>
</Border>
</Template>
</Setter>
<Style Selector="^:pointerover">
<Setter Property="Background" Value="#444"/>
</Style>
</Style>
<Style Selector="Button.SideButton">
<Setter Property="Background" Value="#444"/>
<Setter Property="Foreground" Value="White"/>
<Setter Property="Padding" Value="8,4"/>
<Setter Property="BorderBrush" Value="#666"/>
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="CornerRadius" Value="4"/>
<Setter Property="Cursor" Value="Hand"/>
<Style Selector="^:pointerover">
<Setter Property="Background" Value="#555"/>
</Style>
</Style>
</Styles>

View File

@@ -1,9 +1,11 @@
using System; using System;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Reactive; using System.Reactive;
using System.Threading.Tasks; using System.Threading.Tasks;
using ReactiveUI; using ReactiveUI;
using Valheim_Dashboard.Views;
namespace Valheim_Dashboard.ViewModels namespace Valheim_Dashboard.ViewModels
{ {
@@ -20,6 +22,13 @@ namespace Valheim_Dashboard.ViewModels
set => this.RaiseAndSetIfChanged(ref _currentPath, value); 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 // ObservableCollection, die jetzt FtpItem-Objekte enthält
@@ -32,9 +41,12 @@ namespace Valheim_Dashboard.ViewModels
public ReactiveCommand<Unit, Unit> LoadFtpCommand { get; } public ReactiveCommand<Unit, Unit> LoadFtpCommand { get; }
// Command, der ausgeführt wird, wenn ein Ordner geklickt wird // Command, der ausgeführt wird, wenn ein Ordner geklickt wird
public ReactiveCommand<FtpItem, Unit> FolderClickedCommand { get; } public ReactiveCommand<FtpItem,Unit> FolderClickedCommand { get; }
// Command, der ausgeführt wird, wenn ein Ordner Zurück geklickt wird
public ReactiveCommand<FtpItem, Unit> FolderBackClickedCommand { get; }
public FtpViewModel() public FtpViewModel()
{ {
@@ -47,9 +59,17 @@ namespace Valheim_Dashboard.ViewModels
FolderClickedCommand = ReactiveCommand.Create<FtpItem>(item => FolderClickedCommand = ReactiveCommand.Create<FtpItem>(item =>
{ {
// Logik für den Klick auf das Folder-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<FtpItem>(item =>
{
// Logik für den Klick auf das Folder-Item
OnFolderBackClicked();
});
// Beim Erstellen direkt FTP-Verzeichnis laden // Beim Erstellen direkt FTP-Verzeichnis laden
LoadFtpCommand.Execute().Subscribe(); LoadFtpCommand.Execute().Subscribe();
Files.Add(new FtpItem { Name = "TestFile.txt", IsDirectory = false }); Files.Add(new FtpItem { Name = "TestFile.txt", IsDirectory = false });
@@ -74,29 +94,53 @@ namespace Valheim_Dashboard.ViewModels
Files.Clear(); Files.Clear();
foreach (var item in sortedItems) 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. // Je nach Bedarf kannst du hier den Namen oder auch weitere Infos anzeigen.
Files.Add(item); Files.Add(item);
} }
} }
catch (Exception ex) 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) private void OnFolderClicked(FtpItem item)
{ {
Console.WriteLine("OrdnerKlick"); Debug.WriteLine("OrdnerKlick");
if (item.IsDirectory) if (item.IsDirectory)
{ {
// Beispiel: Den aktuellen Pfad serweitern und das neue Verzeichnis laden // Beispiel: Den aktuellen Pfad serweitern und das neue Verzeichnis laden
// Je nach Bedarf kannst du hier auch Navigation oder andere Logik einbauen // Je nach Bedarf kannst du hier auch Navigation oder andere Logik einbauen
CurrentPath = System.IO.Path.Combine(CurrentPath, item.Name); CurrentPath = System.IO.Path.Combine(CurrentPath, item.Name);
CurrentPath = CurrentPath.Replace("\\", "/");
Debug.WriteLine("PATH: " + CurrentPath);
// Neues Verzeichnis laden // Neues Verzeichnis laden
LoadFtpCommand.Execute().Subscribe(); 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 != "/";
}
}
} }
} }

View File

@@ -29,6 +29,16 @@
Margin="50,0,50,0" Margin="50,0,50,0"
Text="{Binding CurrentPath}"/> Text="{Binding CurrentPath}"/>
<Button
x:Name="CurrentPathBack"
Grid.Row="0"
VerticalAlignment="Center"
HorizontalAlignment="Left"
Content="Zurück"
IsVisible="{Binding CanGoBack}"
Command="{Binding $parent[views:FtpView].ViewModel.FolderBackClickedCommand}"
/>
<!-- ScrollViewer mit ListBox --> <!-- ScrollViewer mit ListBox -->
<ScrollViewer x:Name="ftp_ScrollVie2" <ScrollViewer x:Name="ftp_ScrollVie2"
Grid.Row="1" Grid.Row="1"
@@ -38,8 +48,8 @@
<ListBox.ItemTemplate> <ListBox.ItemTemplate>
<DataTemplate> <DataTemplate>
<Button <Button
Command="{Binding $parent[views:FtpView].ViewModel.FolderClickedCommand}"
CommandParameter="{Binding}" CommandParameter="{Binding }"
Background="Transparent" Background="Transparent"
BorderBrush="Transparent" BorderBrush="Transparent"
HorizontalAlignment="Stretch"> HorizontalAlignment="Stretch">

View File

@@ -18,7 +18,7 @@ public partial class FtpView : ReactiveUserControl<FtpViewModel>
{ {
InitializeComponent(); InitializeComponent();
//DataContext = new FtpViewModel();
// Aktivierungslogik für Bindings // Aktivierungslogik für Bindings
this.WhenActivated(disposables => this.WhenActivated(disposables =>

View File

@@ -48,6 +48,7 @@
Content="Verifizieren" Content="Verifizieren"
Width="100" Width="100"
Height="100" Height="100"
Classes="SideButton"
HorizontalAlignment="Right" HorizontalAlignment="Right"
VerticalAlignment="Center" VerticalAlignment="Center"
HorizontalContentAlignment="Center" HorizontalContentAlignment="Center"

View File

@@ -95,6 +95,7 @@
Width="100" Width="100"
Height="100" Height="100"
IsVisible="true" IsVisible="true"
IsEnabled="False"
Click="Weiter_OnClick"> Click="Weiter_OnClick">
</Button> </Button>
</Grid> </Grid>

View File

@@ -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;
using Avalonia.Controls; using Avalonia.Controls;
using Avalonia.Interactivity; using Avalonia.Interactivity;
using Avalonia.Markup.Xaml; using Avalonia.Markup.Xaml;
using Avalonia.Media; 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 Tmds.DBus.Protocol;
using Valheim_Dashboard.ViewModels; using Valheim_Dashboard.ViewModels;
@@ -136,13 +138,22 @@ public partial class ServerSettingsView : UserControl
}); });
}); });
} }
string method;
private void Weiter_OnClick(object? sender, RoutedEventArgs e) private void Weiter_OnClick(object? sender, RoutedEventArgs e)
{ {
if (this.Parent.Parent.Parent is MainWindow mainWindow) { if (this.Parent.Parent.Parent is MainWindow mainWindow) {
if (mainWindow.DataContext is MainWindowViewModel mainWindowViewModel) if (mainWindow.DataContext is MainWindowViewModel mainWindowViewModel)
{ {
if (method == "plugin")
{
mainWindowViewModel.SwitchToDashboard();
}
else
{
mainWindowViewModel.SwitchToFTP(ftpClient);
}
mainWindowViewModel.SwitchToFTP(ftpClient);
} }
} }
@@ -189,12 +200,14 @@ public partial class ServerSettingsView : UserControl
try 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) if (response.IsSuccessStatusCode)
{ {
var data = await response.Content.ReadFromJsonAsync<DataPluginJson>(); var data = await response.Content.ReadFromJsonAsync<DataPluginJson>();
plugin_prüfen.Background = new SolidColorBrush(Colors.Green); plugin_prüfen.Background = new SolidColorBrush(Colors.Green);
plugin_prüfen.Content = "Verbindung Erfolgreich"; plugin_prüfen.Content = "Verbindung Erfolgreich";
weiter.IsEnabled = true;
method = "plugin";
Debug.WriteLine(data.ModVersion); Debug.WriteLine(data.ModVersion);
}else }else
{ {
@@ -208,6 +221,7 @@ public partial class ServerSettingsView : UserControl
plugin_prüfen.Background = new SolidColorBrush(Colors.Red); plugin_prüfen.Background = new SolidColorBrush(Colors.Red);
plugin_prüfen.Content = "Verbindung Fehlgeschlagen"; 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); {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 = 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.Background = new SolidColorBrush(Colors.Green);
ftp_prüfen.Content = "Verbindung Erfolgreich1"; ftp_prüfen.Content = "Verbindung Erfolgreich";
Console.WriteLine(files); if (JsonDocument.Parse(LizenzView.KeyAuthApp.webhook("recivevar", "&name=" + LizenzView.lizenz_name[1], "")).RootElement.GetProperty("success").GetBoolean())
LizenzView.KeyAuthApp.webhook("aHtrWbrxrZ", "&name="+ LizenzView.lizenz_name[1] +"&data=testabc", ""); {
Console.WriteLine(LizenzView.KeyAuthApp.response.message); 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 else
{ {
ftp_prüfen.Background = new SolidColorBrush(Colors.Green); ftp_prüfen.Background = new SolidColorBrush(Colors.Red);
ftp_prüfen.Content = "Verbindung Erfolgreich2"; 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) catch (Exception ex)
{ {