- Installation von BepInEx über ftp hinzugefügt -> lädt aktuellste version von github runter und lädt sie hoch, prüft danach ob ordner vorhanden ist indem nochmal CheckBepInEx aufgerufen wird. Lies dabei die Version aus von der DLL -> update prüfung kann somit vorgenommen werden (user manuell sicher somit) Todo: -FTP Installation von BepInEx überarbeiten... dauert zu lange aktuell - Installation von BepInEx lässt aktuell leere ordner außen vor... müssen aber im ftp danach auch vorhanden sein!! (patchers, plugins, cache)
146 lines
4.8 KiB
C#
146 lines
4.8 KiB
C#
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
|
|
{
|
|
public class FtpViewModel : ViewModelBase
|
|
{
|
|
public static FtpClient _ftpClient;
|
|
|
|
// Speichert den aktuellen FTP-Pfad
|
|
public static string _currentPath = "/";
|
|
|
|
public string CurrentPath
|
|
{
|
|
get => _currentPath;
|
|
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<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; }
|
|
|
|
|
|
// Command, der ausgeführt wird, wenn ein Ordner Zurück geklickt wird
|
|
public ReactiveCommand<FtpItem, Unit> FolderBackClickedCommand { 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
|
|
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 });
|
|
|
|
}
|
|
|
|
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)
|
|
{
|
|
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)
|
|
{
|
|
Debug.WriteLine($"Fehler beim Laden des FTP-Verzeichnisses: {ex.Message}");
|
|
}
|
|
}
|
|
|
|
private void OnFolderClicked(FtpItem item)
|
|
{
|
|
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 != "/";
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
} |