- Layout Verschiebung behoben bei Configeditor
- Config zuordnung überarbeitet -> keine vorhanden zeigt im editor dann hinweis an: Keine Config gefunden. Server bereits neu gestartet ? - Config Speichern behoben - Ladeanimationen hinzugefügt - Mod löschen funktion eingefügt -> Popup zur bestätigung ob gelöscht werden soll
This commit is contained in:
@@ -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<ModInfo> 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<Unit, Unit> UploadModCommand { get; }
|
||||
public ReactiveCommand<Unit, Unit> InstallFromStoreCommand { get; }
|
||||
public ReactiveCommand<Unit, Unit> SaveConfigCommand { get; }
|
||||
public ReactiveCommand<ModInfo, Unit> RemoveModCommand { get; }
|
||||
public ReactiveCommand<ModInfo, Task> RemoveModCommand { get; }
|
||||
public ReactiveCommand<ModInfo, Unit> 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<ModInfo>(RemoveMod);
|
||||
RemoveModCommand = ReactiveCommand.Create<ModInfo,Task>(RemoveMod);
|
||||
UpdateModCommand = ReactiveCommand.Create<ModInfo>(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)
|
||||
|
||||
Reference in New Issue
Block a user