Initial commit
This commit is contained in:
6
Valheim Dashboard/ViewModels/DashboardViewModel.cs
Normal file
6
Valheim Dashboard/ViewModels/DashboardViewModel.cs
Normal file
@@ -0,0 +1,6 @@
|
||||
namespace Valheim_Dashboard.ViewModels;
|
||||
|
||||
public class DashboardViewModel : ViewModelBase
|
||||
{
|
||||
|
||||
}
|
||||
28
Valheim Dashboard/ViewModels/ErsterStartViewModel.cs
Normal file
28
Valheim Dashboard/ViewModels/ErsterStartViewModel.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using Avalonia;
|
||||
using ReactiveUI;
|
||||
|
||||
namespace Valheim_Dashboard.ViewModels;
|
||||
|
||||
public class ErsterStartViewModel : ViewModelBase
|
||||
{
|
||||
private bool _startAnimation;
|
||||
public bool StartAnimation
|
||||
{
|
||||
get => _startAnimation;
|
||||
set => this.RaiseAndSetIfChanged(ref _startAnimation, value);
|
||||
}
|
||||
|
||||
|
||||
private Point _animationTargetPosition;
|
||||
public Point AnimationTargetPosition
|
||||
{
|
||||
get => _animationTargetPosition;
|
||||
set => this.RaiseAndSetIfChanged(ref _animationTargetPosition, value);
|
||||
}
|
||||
|
||||
public ErsterStartViewModel()
|
||||
{
|
||||
StartAnimation = true; // Property auf true setzen
|
||||
}
|
||||
|
||||
}
|
||||
102
Valheim Dashboard/ViewModels/FTPViewModel.cs
Normal file
102
Valheim Dashboard/ViewModels/FTPViewModel.cs
Normal file
@@ -0,0 +1,102 @@
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Reactive;
|
||||
using System.Threading.Tasks;
|
||||
using ReactiveUI;
|
||||
|
||||
namespace Valheim_Dashboard.ViewModels
|
||||
{
|
||||
public class FtpViewModel : ViewModelBase
|
||||
{
|
||||
public static FtpClient _ftpClient;
|
||||
|
||||
// Speichert den aktuellen FTP-Pfad
|
||||
private string _currentPath = "/";
|
||||
|
||||
public string CurrentPath
|
||||
{
|
||||
get => _currentPath;
|
||||
set => this.RaiseAndSetIfChanged(ref _currentPath, value);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// ObservableCollection, die jetzt FtpItem-Objekte enthält
|
||||
public ObservableCollection<FtpItem> Files { get; } = new();
|
||||
|
||||
// Liste für FTP-Dateien und Ordner
|
||||
// public ObservableCollection<string> Files { get; } = new();
|
||||
|
||||
// Befehl zum Laden des Verzeichnisses
|
||||
public ReactiveCommand<Unit, Unit> LoadFtpCommand { get; }
|
||||
|
||||
// Command, der ausgeführt wird, wenn ein Ordner geklickt wird
|
||||
public ReactiveCommand<FtpItem, Unit> FolderClickedCommand { get; }
|
||||
|
||||
|
||||
public FtpViewModel()
|
||||
{
|
||||
|
||||
|
||||
// Befehl für das Neuladen des Verzeichnisses
|
||||
LoadFtpCommand = ReactiveCommand.CreateFromTask(LoadFtpDirectory);
|
||||
|
||||
// Command, der beim Klick auf einen Ordner ausgeführt wird
|
||||
// FolderClickedCommand = ReactiveCommand.Create<FtpItem>(OnFolderClicked);
|
||||
FolderClickedCommand = ReactiveCommand.Create<FtpItem>(item =>
|
||||
{
|
||||
// Logik für den Klick auf das Folder-Item
|
||||
Console.WriteLine($"Folder {item.Name} clicked!");
|
||||
});
|
||||
|
||||
// Beim Erstellen direkt FTP-Verzeichnis laden
|
||||
LoadFtpCommand.Execute().Subscribe();
|
||||
Files.Add(new FtpItem { Name = "TestFile.txt", IsDirectory = false });
|
||||
|
||||
}
|
||||
|
||||
private async Task LoadFtpDirectory()
|
||||
{
|
||||
try
|
||||
{
|
||||
// Verwende die neue Methode, um detaillierte Informationen zu erhalten
|
||||
var items = await _ftpClient.ListDirectoryDetailsAsync(CurrentPath);
|
||||
|
||||
// Sortiere: Ordner zuerst, dann Dateien, jeweils alphabetisch
|
||||
var sortedItems = items
|
||||
.OrderBy(item => item.IsDirectory ? 0 : 1)
|
||||
.ThenBy(item => item.Name, StringComparer.OrdinalIgnoreCase)
|
||||
.ToList();
|
||||
|
||||
// Hier gehen wir davon aus, dass du z. B. eine ObservableCollection vom Typ string hast.
|
||||
// Du kannst aber auch deine ObservableCollection umstellen, sodass du FtpItem-Objekte speicherst.
|
||||
Files.Clear();
|
||||
foreach (var item in sortedItems)
|
||||
{
|
||||
Console.WriteLine($"Item geladen: {item.Name}");
|
||||
// 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}");
|
||||
}
|
||||
}
|
||||
|
||||
private void OnFolderClicked(FtpItem item)
|
||||
{
|
||||
Console.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);
|
||||
// Neues Verzeichnis laden
|
||||
LoadFtpCommand.Execute().Subscribe();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
29
Valheim Dashboard/ViewModels/LizenzViewModel.cs
Normal file
29
Valheim Dashboard/ViewModels/LizenzViewModel.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using System.ComponentModel;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace Valheim_Dashboard.ViewModels;
|
||||
|
||||
public class LizenzViewModel : ViewModelBase
|
||||
{
|
||||
|
||||
public string LizenzKey { get; set; }
|
||||
|
||||
private string _verifizierungsAntwort;
|
||||
public string VerifizierungsAntwort
|
||||
{
|
||||
get => _verifizierungsAntwort;
|
||||
set
|
||||
{
|
||||
if (_verifizierungsAntwort != value)
|
||||
{
|
||||
_verifizierungsAntwort = value;
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public event PropertyChangedEventHandler? PropertyChanged;
|
||||
protected void OnPropertyChanged([CallerMemberName] string? name = null)
|
||||
=> PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
|
||||
|
||||
}
|
||||
84
Valheim Dashboard/ViewModels/MainWindowViewModel.cs
Normal file
84
Valheim Dashboard/ViewModels/MainWindowViewModel.cs
Normal file
@@ -0,0 +1,84 @@
|
||||
using ReactiveUI;
|
||||
using Valheim_Dashboard.ViewModels;
|
||||
using Valheim_Dashboard.Views;
|
||||
|
||||
namespace Valheim_Dashboard.ViewModels
|
||||
{
|
||||
public class MainWindowViewModel : ViewModelBase
|
||||
{
|
||||
private readonly ViewModelLocator _locator;
|
||||
private ViewModelBase _currentViewModel;
|
||||
private LizenzView _lizenzView;
|
||||
|
||||
|
||||
public MainWindowViewModel(ViewModelLocator locator)
|
||||
{
|
||||
_locator = locator;
|
||||
|
||||
// Initialer ViewModel über Locator setzen
|
||||
if (Settings.SettingsLoad("LizenzKey") != null) {
|
||||
|
||||
|
||||
|
||||
// Lizenzkey aus den Einstellungen laden
|
||||
string lizenzKey = Settings.SettingsLoad("LizenzKey");
|
||||
var lizenzViewModel = _locator.LizenzViewModel;
|
||||
lizenzViewModel.LizenzKey = lizenzKey; // Lizenzkey übergeben
|
||||
_currentViewModel = lizenzViewModel;
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
_currentViewModel = _locator.ErsterStartViewModel;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public ViewModelBase CurrentViewModel
|
||||
{
|
||||
get => _currentViewModel;
|
||||
set => this.RaiseAndSetIfChanged(ref _currentViewModel, value);
|
||||
}
|
||||
|
||||
public void SwitchToErsterStart()
|
||||
{
|
||||
CurrentViewModel = _locator.ErsterStartViewModel;
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void SwitchToLizenzView()
|
||||
{
|
||||
|
||||
CurrentViewModel = _locator.LizenzViewModel;
|
||||
}
|
||||
|
||||
public void SwitchToServerSettings()
|
||||
{
|
||||
|
||||
CurrentViewModel = _locator.ServerSettingsViewModel;
|
||||
}
|
||||
|
||||
public void SwitchToDashboard()
|
||||
{
|
||||
CurrentViewModel = _locator.DashboardViewModel;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public void SwitchToFTP(FtpClient ftpClient)
|
||||
{
|
||||
// var ftpViewModel = new FtpViewModel(ftpClient);
|
||||
// var ftpView = new FTPView(ftpViewModel);
|
||||
CurrentViewModel = _locator.FtpViewModel;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
76
Valheim Dashboard/ViewModels/ServerSettingsViewModel.cs
Normal file
76
Valheim Dashboard/ViewModels/ServerSettingsViewModel.cs
Normal file
@@ -0,0 +1,76 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Reactive;
|
||||
using System.Reactive.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Windows.Input;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Media;
|
||||
using ReactiveUI;
|
||||
using Valheim_Dashboard.Views;
|
||||
|
||||
namespace Valheim_Dashboard.ViewModels;
|
||||
|
||||
public class ServerSettingsViewModel : ViewModelBase
|
||||
{
|
||||
|
||||
// Eigenschaften für Plugin
|
||||
private string? _pluginIp;
|
||||
|
||||
public string? PluginIp
|
||||
{
|
||||
get => _pluginIp;
|
||||
set => this.RaiseAndSetIfChanged(ref _pluginIp, value);
|
||||
}
|
||||
|
||||
private string? _pluginPort;
|
||||
|
||||
public string? PluginPort
|
||||
{
|
||||
get => _pluginPort;
|
||||
set => this.RaiseAndSetIfChanged(ref _pluginPort, value);
|
||||
}
|
||||
|
||||
// Eigenschaften für FTP
|
||||
private string? _ftpIp;
|
||||
|
||||
public string? FtpIp
|
||||
{
|
||||
get => _ftpIp;
|
||||
set => this.RaiseAndSetIfChanged(ref _ftpIp, value);
|
||||
}
|
||||
|
||||
private string? _ftpPort;
|
||||
|
||||
public string? FtpPort
|
||||
{
|
||||
get => _ftpPort;
|
||||
set => this.RaiseAndSetIfChanged(ref _ftpPort, value);
|
||||
}
|
||||
|
||||
private string? _ftpUsername;
|
||||
|
||||
public string? FtpUsername
|
||||
{
|
||||
get => _ftpUsername;
|
||||
set => this.RaiseAndSetIfChanged(ref _ftpUsername, value);
|
||||
}
|
||||
|
||||
private string? _ftpPassword;
|
||||
|
||||
public string? FtpPassword
|
||||
{
|
||||
get => _ftpPassword;
|
||||
set => this.RaiseAndSetIfChanged(ref _ftpPassword, value);
|
||||
}
|
||||
|
||||
private readonly TutorialManager _tutorialManager;
|
||||
private Window? _window;
|
||||
public ServerSettingsViewModel()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
7
Valheim Dashboard/ViewModels/ViewModelBase.cs
Normal file
7
Valheim Dashboard/ViewModels/ViewModelBase.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
using ReactiveUI;
|
||||
|
||||
namespace Valheim_Dashboard.ViewModels;
|
||||
|
||||
public class ViewModelBase : ReactiveObject
|
||||
{
|
||||
}
|
||||
16
Valheim Dashboard/ViewModels/ViewModelLocator.cs
Normal file
16
Valheim Dashboard/ViewModels/ViewModelLocator.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using Valheim_Dashboard.ViewModels;
|
||||
|
||||
namespace Valheim_Dashboard
|
||||
{
|
||||
public class ViewModelLocator
|
||||
{
|
||||
public MainWindowViewModel MainWindowViewModel => new MainWindowViewModel(this);
|
||||
public ErsterStartViewModel ErsterStartViewModel => new ErsterStartViewModel();
|
||||
public LizenzViewModel LizenzViewModel => new LizenzViewModel(); // Hinzugefügt
|
||||
public ServerSettingsViewModel ServerSettingsViewModel => new ServerSettingsViewModel(); // Hinzugefügt
|
||||
public DashboardViewModel DashboardViewModel => new DashboardViewModel(); // Hinzugefügt
|
||||
public FtpViewModel FtpViewModel => new FtpViewModel(); // Hinzugefügt
|
||||
|
||||
public ViewModelLocator() { }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user