- 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/>
</DataTemplate>
</Application.DataTemplates>
<Application.Styles>
<FluentTheme />
</Application.Styles>
<Application.Styles>
<FluentTheme/>
<StyleInclude Source="Styles.axaml"/>
</Application.Styles>
</Application>

View File

@@ -26,11 +26,31 @@ namespace Valheim_Dashboard
_ftpServer = ftpServer.EndsWith("/") ? ftpServer : ftpServer + "/";
_username = username;
_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; }

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.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,6 +22,13 @@ 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
@@ -32,9 +41,12 @@ namespace Valheim_Dashboard.ViewModels
public ReactiveCommand<Unit, Unit> LoadFtpCommand { get; }
// 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()
{
@@ -47,9 +59,17 @@ namespace Valheim_Dashboard.ViewModels
FolderClickedCommand = ReactiveCommand.Create<FtpItem>(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
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 != "/";
}
}
}
}

View File

@@ -29,6 +29,16 @@
Margin="50,0,50,0"
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 x:Name="ftp_ScrollVie2"
Grid.Row="1"
@@ -38,8 +48,8 @@
<ListBox.ItemTemplate>
<DataTemplate>
<Button
CommandParameter="{Binding}"
Command="{Binding $parent[views:FtpView].ViewModel.FolderClickedCommand}"
CommandParameter="{Binding }"
Background="Transparent"
BorderBrush="Transparent"
HorizontalAlignment="Stretch">

View File

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

View File

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

View File

@@ -95,6 +95,7 @@
Width="100"
Height="100"
IsVisible="true"
IsEnabled="False"
Click="Weiter_OnClick">
</Button>
</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.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)
{
if (method == "plugin")
{
mainWindowViewModel.SwitchToDashboard();
}
else
{
mainWindowViewModel.SwitchToFTP(ftpClient);
}
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<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
{
@@ -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)
{