- ServerDashbord Hinzugefügt

-Ftp Seite überarbeitet mit path auswahl und zurück plus weiter button. Fehlt noch logik zum speichern vom path in global variable (: um sie zu laden evtl local zwischen speichern damit nicht jedes mal eine anfrage zum server kommt.

-Server Dashboard beispiel mod config hinzugefügt um ftp string zu lesen und schreiben. Plugin unterstützung fehlt hier noch plus plugin muss erstmal geschrieben werden das er es kann :P
This commit is contained in:
tbS
2025-08-23 16:13:08 +02:00
parent 4a7b283aa3
commit 7afbf78bb0
11 changed files with 391 additions and 56 deletions

View File

@@ -1,10 +1,11 @@
using ReactiveUI;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Net; using System.Net;
using System.Reactive; using System.Reactive;
using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using ReactiveUI;
using Valheim_Dashboard.ViewModels; using Valheim_Dashboard.ViewModels;
namespace Valheim_Dashboard namespace Valheim_Dashboard
@@ -123,6 +124,32 @@ namespace Valheim_Dashboard
await fileStream.CopyToAsync(requestStream); await fileStream.CopyToAsync(requestStream);
} }
public async Task UploadTextAsync(string text, string remoteFilePath)
{
var request = CreateFtpWebRequest(remoteFilePath, WebRequestMethods.Ftp.UploadFile);
// Konvertiere den String in ein Byte-Array (UTF-8)
byte[] bytes = Encoding.UTF8.GetBytes(text);
request.ContentLength = bytes.Length;
using var requestStream = await request.GetRequestStreamAsync();
await requestStream.WriteAsync(bytes, 0, bytes.Length);
}
public async Task<string> DownloadTextAsync(string remoteFilePath)
{
var request = CreateFtpWebRequest(remoteFilePath, WebRequestMethods.Ftp.DownloadFile);
using var response = (FtpWebResponse)await request.GetResponseAsync();
using var responseStream = response.GetResponseStream();
using var reader = new StreamReader(responseStream!, Encoding.UTF8);
string content = await reader.ReadToEndAsync();
return content;
}
/// <summary> /// <summary>
/// Löscht eine Datei vom FTP-Server (Async). /// Löscht eine Datei vom FTP-Server (Async).
/// </summary> /// </summary>

View File

@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Valheim_Dashboard.Models;
public class ModInfo
{
public string Name { get; set; }
public string Version { get; set; }
public string ConfigPath { get; set; }
}

View File

@@ -9,7 +9,6 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Folder Include="Models\" />
<AvaloniaResource Include="Assets\**" /> <AvaloniaResource Include="Assets\**" />
</ItemGroup> </ItemGroup>
@@ -39,5 +38,8 @@
<AutoGen>True</AutoGen> <AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon> <DependentUpon>Resources.resx</DependentUpon>
</Compile> </Compile>
<Compile Update="Views\ServerDashboard.axaml.cs">
<DependentUpon>ServerDashboard.axaml</DependentUpon>
</Compile>
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@@ -32,6 +32,8 @@ namespace Valheim_Dashboard.ViewModels
{ {
_currentViewModel = _locator.ErsterStartViewModel; _currentViewModel = _locator.ErsterStartViewModel;
} }
} }
@@ -61,6 +63,11 @@ namespace Valheim_Dashboard.ViewModels
CurrentViewModel = _locator.ServerSettingsViewModel; CurrentViewModel = _locator.ServerSettingsViewModel;
} }
public void SwitchToServerDashboard()
{
CurrentViewModel = _locator.ServerDashboardViewModel;
}
public void SwitchToDashboard() public void SwitchToDashboard()
{ {
CurrentViewModel = _locator.DashboardViewModel; CurrentViewModel = _locator.DashboardViewModel;

View File

@@ -0,0 +1,152 @@
using Avalonia.Controls;
using ReactiveUI;
using System;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Linq;
using System.Reactive;
using System.Reactive.Linq;
using System.Threading.Tasks;
using Valheim_Dashboard.Models;
namespace Valheim_Dashboard.ViewModels;
public class ServerDashboardViewModel : ViewModelBase
{
// BepInEx Status
private string _bepInExStatus;
public string BepInExStatus
{
get => _bepInExStatus;
set => this.RaiseAndSetIfChanged(ref _bepInExStatus, value);
}
private bool _showInstallButton;
public bool ShowInstallButton
{
get => _showInstallButton;
set => this.RaiseAndSetIfChanged(ref _showInstallButton, value);
}
private bool _showUpdateButton;
public bool ShowUpdateButton
{
get => _showUpdateButton;
set => this.RaiseAndSetIfChanged(ref _showUpdateButton, value);
}
public ObservableCollection<ModInfo> Mods { get; } = new();
private ModInfo _selectedMod;
public ModInfo SelectedMod
{
get => _selectedMod;
set
{
this.RaiseAndSetIfChanged(ref _selectedMod, value);
_ = LoadSelectedModConfigFromFtp(); // async fire-and-forget
}
}
private async Task LoadSelectedModConfigFromFtp()
{
if (SelectedMod == null)
{
SelectedModConfig = string.Empty;
return;
}
try
{
SelectedModConfig = await FtpViewModel._ftpClient.DownloadTextAsync(SelectedMod.ConfigPath);
}
catch (Exception ex)
{
SelectedModConfig = $"Fehler beim Laden: {ex.Message}";
}
}
private string _selectedModConfig;
public string SelectedModConfig
{
get => _selectedModConfig;
set => this.RaiseAndSetIfChanged(ref _selectedModConfig, value);
}
private Window _mainWindow;
public void SetMainWindow(Window mainWindow)
{
_mainWindow = mainWindow;
}
// Reactive Commands
public ReactiveCommand<Unit, Unit> InstallBepInExCommand { get; }
public ReactiveCommand<Unit, Unit> UpdateBepInExCommand { get; }
public ReactiveCommand<Unit, Unit> UploadModCommand { get; }
public ReactiveCommand<Unit, Unit> InstallFromStoreCommand { get; }
public ReactiveCommand<Unit, Unit> SaveConfigCommand { get; }
public ReactiveCommand<Unit, Unit> RemoveModCommand { get; }
public ServerDashboardViewModel()
{
InstallBepInExCommand = ReactiveCommand.Create(InstallBepInEx);
UpdateBepInExCommand = ReactiveCommand.Create(UpdateBepInEx);
UploadModCommand = ReactiveCommand.Create(UploadMod);
InstallFromStoreCommand = ReactiveCommand.Create(InstallFromStore);
SaveConfigCommand = ReactiveCommand.Create(SaveConfig);
RemoveModCommand = ReactiveCommand.Create(RemoveMod);
// Demo
BepInExStatus = "Nicht installiert";
ShowInstallButton = true;
ShowUpdateButton = false;
Mods.Add(new ModInfo { Name = "ValheimPlus", Version = "1.0.0", ConfigPath = "config/valheim_plus.cfg" });
Mods.Add(new ModInfo { Name = "BetterUI", Version = "2.3.4", ConfigPath = "config/better_ui.cfg" });
}
private void InstallBepInEx()
{
BepInExStatus = "Installiert (vX.Y.Z)";
ShowInstallButton = false;
ShowUpdateButton = true;
}
private void UpdateBepInEx()
{
BepInExStatus = "Aktuell (vX.Y.Z)";
ShowUpdateButton = false;
}
public async Task<string?> OpenFileAsync(Window parent)
{
var dialog = new OpenFileDialog
{
AllowMultiple = false
};
dialog.Filters.Add(new FileDialogFilter { Name = "Config Files", Extensions = { "cfg" } });
dialog.Filters.Add(new FileDialogFilter { Name = "All Files", Extensions = { "*" } });
var result = await dialog.ShowAsync(parent);
return result?.FirstOrDefault(); // Gibt den ausgew<65>hlten Pfad zur<75>ck oder null
}
private async void UploadMod() {
if (_mainWindow == null)
return; // Window muss gesetzt sein
var path = await OpenFileAsync(_mainWindow);
FtpViewModel._ftpClient.UploadFileAsync("", "");
}
private void InstallFromStore() { /* TODO */ }
private void SaveConfig() {
Debug.WriteLine(SelectedMod.ConfigPath);
FtpViewModel._ftpClient.UploadTextAsync(SelectedModConfig, SelectedMod.ConfigPath);
}
private void RemoveMod()
{
if (SelectedMod != null)
Mods.Remove(SelectedMod);
}
}

View File

@@ -8,6 +8,8 @@ namespace Valheim_Dashboard
public ErsterStartViewModel ErsterStartViewModel => new ErsterStartViewModel(); public ErsterStartViewModel ErsterStartViewModel => new ErsterStartViewModel();
public LizenzViewModel LizenzViewModel => new LizenzViewModel(); // Hinzugefügt public LizenzViewModel LizenzViewModel => new LizenzViewModel(); // Hinzugefügt
public ServerSettingsViewModel ServerSettingsViewModel => new ServerSettingsViewModel(); // Hinzugefügt public ServerSettingsViewModel ServerSettingsViewModel => new ServerSettingsViewModel(); // Hinzugefügt
public ServerDashboardViewModel ServerDashboardViewModel => new ServerDashboardViewModel(); // Hinzugefügt
public DashboardViewModel DashboardViewModel => new DashboardViewModel(); // Hinzugefügt public DashboardViewModel DashboardViewModel => new DashboardViewModel(); // Hinzugefügt
public FtpViewModel FtpViewModel => new FtpViewModel(); // Hinzugefügt public FtpViewModel FtpViewModel => new FtpViewModel(); // Hinzugefügt

View File

@@ -2,62 +2,83 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Valheim_Dashboard"
xmlns:vm="clr-namespace:Valheim_Dashboard.ViewModels" xmlns:vm="clr-namespace:Valheim_Dashboard.ViewModels"
xmlns:views="clr-namespace:Valheim_Dashboard.Views" xmlns:views="clr-namespace:Valheim_Dashboard.Views"
mc:Ignorable="d" mc:Ignorable="d"
x:Name="root" x:Class="Valheim_Dashboard.Views.FtpView"
x:Class="Valheim_Dashboard.Views.FtpView" x:DataType="vm:FtpViewModel">
x:DataType="vm:FtpViewModel"
>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="0.5*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<!-- TextBox für den aktuellen FTP-Pfad -->
<TextBox x:Name="CurrentPathTextBox"
Grid.Row="0"
HorizontalAlignment="Stretch"
VerticalAlignment="Center"
HorizontalContentAlignment="Center"
VerticalContentAlignment="Center"
IsEnabled="False"
Height="100"
Margin="50,0,50,0"
Text="{Binding CurrentPath}"/>
<Button <!-- Äußerer Border für Padding -->
x:Name="CurrentPathBack" <Border Padding="20">
Grid.Row="0" <Grid RowDefinitions="Auto,*,Auto">
VerticalAlignment="Center"
HorizontalAlignment="Left" <!-- Header mit Zurück-Button + Pfad -->
Content="Zurück" <Grid Grid.Row="0" ColumnDefinitions="Auto,*" Margin="0,0,0,20">
IsVisible="{Binding CanGoBack}"
Command="{Binding $parent[views:FtpView].ViewModel.FolderBackClickedCommand}" <Button x:Name="CurrentPathBack"
/> Grid.Column="0"
Content="←"
<!-- ScrollViewer mit ListBox --> FontSize="36"
<ScrollViewer x:Name="ftp_ScrollVie2" HorizontalAlignment="Center"
Grid.Row="1" VerticalAlignment="Center"
Background="Brown" Width="100" Height="100"
Margin="50,0,50,50"> IsVisible="{Binding CanGoBack}"
<ListBox x:Name="FtpFileList" ItemsSource="{Binding Files}"> Command="{Binding $parent[views:FtpView].ViewModel.FolderBackClickedCommand}"/>
<ListBox.ItemTemplate>
<DataTemplate> <TextBox x:Name="CurrentPathTextBox"
<Button Grid.Column="1"
Command="{Binding $parent[views:FtpView].ViewModel.FolderClickedCommand}" Text="{Binding CurrentPath}"
CommandParameter="{Binding }" FontSize="28"
Background="Transparent" IsReadOnly="True"
BorderBrush="Transparent" VerticalContentAlignment="Center"
HorizontalAlignment="Stretch"> HorizontalContentAlignment="Left"
<TextBlock Text="{Binding Name}" Foreground="Green" /> Height="100"
</Button> BorderThickness="2"
</DataTemplate> BorderBrush="Gray"
</ListBox.ItemTemplate> CornerRadius="8"
</ListBox> Padding="20,0"/>
</ScrollViewer> </Grid>
</Grid>
<!-- Dateiliste -->
<ScrollViewer Grid.Row="1" Margin="0,0,0,20">
<ListBox x:Name="FtpFileList"
ItemsSource="{Binding Files}"
BorderThickness="0">
<ListBox.ItemTemplate>
<DataTemplate>
<Button Command="{Binding $parent[views:FtpView].ViewModel.FolderClickedCommand}"
CommandParameter="{Binding}"
Background="Transparent"
BorderBrush="Transparent"
HorizontalAlignment="Stretch"
Height="100"
Padding="20">
<TextBlock Text="{Binding Name}"
FontSize="28"
VerticalAlignment="Center"/>
</Button>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</ScrollViewer>
<!-- Weiter-Button unten -->
<Button Grid.Row="2"
x:Name="weiter"
Content="Weiter"
FontSize="28"
FontWeight="Bold"
HorizontalAlignment="Right"
VerticalAlignment="Bottom"
Width="200" Height="100"
VerticalContentAlignment="Center"
HorizontalContentAlignment="Center"
CornerRadius="12"
Background="#3B82F6"
Foreground="White"
Margin="0,0,0,10"
IsEnabled="True"
Click="Weiter_Clicked"/>
</Grid>
</Border>
</UserControl> </UserControl>

View File

@@ -47,4 +47,18 @@ public partial class FtpView : ReactiveUserControl<FtpViewModel>
private TextBox CurrentPathTextBox_ => this.FindControl<TextBox>("CurrentPathTextBox"); private TextBox CurrentPathTextBox_ => this.FindControl<TextBox>("CurrentPathTextBox");
private ListBox FtpFileList_ => this.FindControl<ListBox>("FtpFileList"); private ListBox FtpFileList_ => this.FindControl<ListBox>("FtpFileList");
private void Weiter_Clicked(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
{
//Settings.SettingsSave("LizenzKey", LizenzKeyTextBox.Text);
if (this.Parent.Parent.Parent is MainWindow mainWindow)
{
if (mainWindow.DataContext is MainWindowViewModel mainWindowViewModel)
{
mainWindowViewModel.SwitchToServerDashboard();
}
}
}
} }

View File

@@ -1,4 +1,5 @@
using Avalonia.Controls; using Avalonia.Controls;
using Valheim_Dashboard.ViewModels;
namespace Valheim_Dashboard.Views; namespace Valheim_Dashboard.Views;
@@ -7,5 +8,16 @@ public partial class MainWindow : Window
public MainWindow() public MainWindow()
{ {
InitializeComponent(); InitializeComponent();
var locator = new ViewModelLocator();
var mainVm = new MainWindowViewModel(locator);
DataContext = mainVm;
// MainWindow ins ServerDashboardViewModel setzen
if (locator.ServerDashboardViewModel is ServerDashboardViewModel dashboardVm)
{
dashboardVm.SetMainWindow(this); // <-- hier 'this' ist MainWindow
}
this.DataContext = mainVm;
} }
} }

View File

@@ -0,0 +1,69 @@
<UserControl
xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:vm="clr-namespace:Valheim_Dashboard.ViewModels"
mc:Ignorable="d" d:DesignWidth="1280" d:DesignHeight="800"
x:Class="Valheim_Dashboard.Views.ServerDashboardView"
x:DataType="vm:ServerDashboardViewModel">
<Grid ColumnDefinitions="2*,3*">
<!-- Linke Spalte -->
<StackPanel Margin="20" Spacing="20">
<!-- BepInEx Status -->
<Border BorderBrush="Gray" BorderThickness="2" CornerRadius="12" Padding="20">
<StackPanel Spacing="10" Height="150">
<TextBlock Text="BepInEx Status" FontSize="28" FontWeight="Bold"/>
<TextBlock Text="{Binding BepInExStatus}" FontSize="20"/>
<Button Content="Installieren"
Command="{Binding InstallBepInExCommand}"
IsVisible="{Binding ShowInstallButton}"
Height="80"/>
<Button Content="Update"
Command="{Binding UpdateBepInExCommand}"
IsVisible="{Binding ShowUpdateButton}"
Height="80"/>
</StackPanel>
</Border>
<!-- Mods Liste -->
<Border BorderBrush="Gray" BorderThickness="2" CornerRadius="12" Padding="20">
<StackPanel Height="450">
<TextBlock Text="Mods" FontSize="28" FontWeight="Bold"/>
<ListBox ItemsSource="{Binding Mods}" SelectedItem="{Binding SelectedMod}" Height="380">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Name}" FontWeight="Bold" Margin="0,0,5,0"/>
<TextBlock Text="{Binding Version}" Foreground="Gray"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<Grid>
<Button Content="Mod hochladen" Command="{Binding UploadModCommand}" Height="80" HorizontalAlignment="Left"/>
<Button Content="Aus Store installieren" Command="{Binding InstallFromStoreCommand}" Height="80" HorizontalAlignment="Right"/>
</Grid>
</StackPanel>
</Border>
</StackPanel>
<!-- Rechte Spalte (Config Editor) -->
<StackPanel Grid.Column="1" Margin="20" Spacing="20">
<TextBlock Text="{Binding SelectedMod.Name}" FontSize="28" FontWeight="Bold"/>
<TextBox Text="{Binding SelectedModConfig}" AcceptsReturn="True" FontSize="20" Height="550"/>
<Grid>
<Button Content="Speichern" Command="{Binding SaveConfigCommand}" Height="80" HorizontalAlignment="Left"/>
<Button Content="Mod entfernen" Command="{Binding RemoveModCommand}" Height="80" Background="Red" HorizontalAlignment="Right"/>
</Grid>
</StackPanel>
</Grid>
</UserControl>

View File

@@ -0,0 +1,14 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Markup.Xaml;
using Valheim_Dashboard.ViewModels;
namespace Valheim_Dashboard.Views;
public partial class ServerDashboardView : UserControl
{
public ServerDashboardView()
{
InitializeComponent();
}
}