diff --git a/Valheim Dashboard/App.axaml b/Valheim Dashboard/App.axaml index 53984b0..0c7405f 100644 --- a/Valheim Dashboard/App.axaml +++ b/Valheim Dashboard/App.axaml @@ -44,4 +44,11 @@ + + + + + + + \ No newline at end of file diff --git a/Valheim Dashboard/Valheim Dashboard.csproj b/Valheim Dashboard/Valheim Dashboard.csproj index a432276..88a38e3 100644 --- a/Valheim Dashboard/Valheim Dashboard.csproj +++ b/Valheim Dashboard/Valheim Dashboard.csproj @@ -24,6 +24,7 @@ All + @@ -40,6 +41,9 @@ True Resources.resx + + ConfirmDialog.axaml + ServerDashboard.axaml diff --git a/Valheim Dashboard/ViewModels/ServerDashboardViewModel.cs b/Valheim Dashboard/ViewModels/ServerDashboardViewModel.cs index 2b6eb9f..25d88a5 100644 --- a/Valheim Dashboard/ViewModels/ServerDashboardViewModel.cs +++ b/Valheim Dashboard/ViewModels/ServerDashboardViewModel.cs @@ -22,6 +22,7 @@ using Valheim_Dashboard.Models; using Valheim_Dashboard.Views; using static System.Net.WebRequestMethods; + namespace Valheim_Dashboard.ViewModels; public class ServerDashboardViewModel : ViewModelBase @@ -50,14 +51,29 @@ public class ServerDashboardViewModel : ViewModelBase public ObservableCollection Mods { get; } = new(); - private ModInfo _selectedMod; - public ModInfo SelectedMod + + private ModInfo? _selectedMod; + public ModInfo? SelectedMod { get => _selectedMod; set { this.RaiseAndSetIfChanged(ref _selectedMod, value); - _ = LoadSelectedModConfigFromFtp(); // async fire-and-forget + + if (value == null) + { + SelectedModConfig = string.Empty; + } + else if (string.IsNullOrEmpty(value.ConfigPath)) + { + // Keine Config zugeordnet → Hinweistext + SelectedModConfig = "Keine Config gefunden, Server bereits neugestartet?"; + } + else + { + // Config laden + _ = LoadSelectedModConfigFromFtp(); ; + } } } @@ -107,7 +123,7 @@ public class ServerDashboardViewModel : ViewModelBase public ReactiveCommand UploadModCommand { get; } public ReactiveCommand InstallFromStoreCommand { get; } public ReactiveCommand SaveConfigCommand { get; } - public ReactiveCommand RemoveModCommand { get; } + public ReactiveCommand RemoveModCommand { get; } public ReactiveCommand UpdateModCommand { get; } private bool _isLoading; @@ -124,12 +140,22 @@ public class ServerDashboardViewModel : ViewModelBase UploadModCommand = ReactiveCommand.CreateFromTask(UploadMod); InstallFromStoreCommand = ReactiveCommand.Create(InstallFromStore); SaveConfigCommand = ReactiveCommand.Create(SaveConfig); - RemoveModCommand = ReactiveCommand.Create(RemoveMod); + RemoveModCommand = ReactiveCommand.Create(RemoveMod); UpdateModCommand = ReactiveCommand.Create(UpdateMod); // DEBUG: harter Testtext – MUSS im Editor erscheinen ConfigDocument.Text = "Bitte Mod Auswählen"; + + // SelectedModConfig Sync mit ConfigDocument text (: + + ConfigDocument = new TextDocument(); + ConfigDocument.TextChanged += (s, e) => + { + if (SelectedModConfig != ConfigDocument.Text) + SelectedModConfig = ConfigDocument.Text; + }; + //SelectedMod.Name = "Bitte Mod Auswählen"; // Demo @@ -431,6 +457,14 @@ public class ServerDashboardViewModel : ViewModelBase //Mod Liste holen + private bool _isModsLoading; + public bool IsModsLoading + { + get => _isModsLoading; + set => this.RaiseAndSetIfChanged(ref _isModsLoading, value); + } + + // Hilfsfunktionen static string NormalizeKey(string s) @@ -536,6 +570,7 @@ public class ServerDashboardViewModel : ViewModelBase // Hauptmethode public async Task LoadModsFromServer() { + IsModsLoading = true; try { Mods.Clear(); @@ -585,16 +620,7 @@ public class ServerDashboardViewModel : ViewModelBase cfgHit = cfgFiles.FirstOrDefault(cf => normCandidates.Any(nc => cf.Normalized.Contains(nc))); // 3) Fallback: „bester“ Fit über LCS - if (cfgHit == null) - { - cfgHit = cfgFiles - .Select(cf => new { - cf, - score = normCandidates.Max(nc => LongestCommonSubsequenceLen(cf.Normalized, nc)) - }) - .OrderByDescending(x => x.score) - .FirstOrDefault()?.cf; - } + // cfgHit bleibt null } // Version aus DLL ziehen @@ -629,6 +655,10 @@ public class ServerDashboardViewModel : ViewModelBase { Debug.WriteLine($"LoadModsFromFtp Fehler: {ex}"); } + finally + { + IsModsLoading = false; + } } @@ -689,9 +719,62 @@ public class ServerDashboardViewModel : ViewModelBase Debug.WriteLine(SelectedMod.ConfigPath); FtpViewModel._ftpClient.UploadTextAsync(SelectedModConfig, SelectedMod.ConfigPath); } - private void RemoveMod(ModInfo mod) + private async Task RemoveMod(ModInfo mod) { - Mods.Remove(mod); + // Finde das aktive Fenster über das Visual Tree + var topLevel = TopLevel.GetTopLevel(App.Current!.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime d + ? d.MainWindow + : null); + + if (topLevel is not Window parent) + { + Debug.WriteLine("Kein gültiges Window gefunden."); + return; + } + + var dialog = new ConfirmDialog(); + dialog.SetMessage($"Möchtest du den Mod \"{mod.Name}\" wirklich löschen?"); + + bool confirmed = await dialog.ShowDialogAsync(parent); + + if (confirmed) + { + + Mods.Remove(mod); + + if (ServerSettingsView.method == "ftp") + { + + var remotePath = CombineFtp(FtpViewModel._currentPath, "BepInEx/plugins", mod.Name + ".dll"); + try + { + await FtpViewModel._ftpClient.DeleteFileAsync(remotePath); + Debug.WriteLine($"Mod {mod.Name} gelöscht."); + } + catch (Exception ex) + { + Debug.WriteLine($"Fehler beim Löschen der Mod {mod.Name}: {ex.Message}"); + } + + + try + { + await FtpViewModel._ftpClient.DeleteFileAsync(mod.ConfigPath); + Debug.WriteLine($"Mod Config {mod.Name} gelöscht."); + } + catch (Exception ex) + { + Debug.WriteLine($"Fehler beim Löschen der Mod Config {mod.Name}: {ex.Message}"); + } + + + + } + else + { + Debug.WriteLine("Plugin funktion fehlt noch"); + } + } } private void UpdateMod(ModInfo mod) diff --git a/Valheim Dashboard/Views/ConfirmDialog.axaml b/Valheim Dashboard/Views/ConfirmDialog.axaml new file mode 100644 index 0000000..3cd6795 --- /dev/null +++ b/Valheim Dashboard/Views/ConfirmDialog.axaml @@ -0,0 +1,31 @@ + + + + + + + + Content="{LucideIconContent ArrowUp}" /> + Content="{LucideIconContent Trash2}" /> - + + + + + + + +