From cf6bd3765f81a633d0ed4711ab5e830f8cceadcd Mon Sep 17 00:00:00 2001 From: tbS Date: Wed, 27 Aug 2025 19:19:23 +0200 Subject: [PATCH] =?UTF-8?q?-=20BepInEx=20Installation=20schneller=20gemach?= =?UTF-8?q?=20-=20BepInEx=20Installation=20Progress=20Bar=20hinzugef=C3=BC?= =?UTF-8?q?gt=20um=20fortschritt=20anzuzeigen=20-BepInEx=20Leere=20ordner?= =?UTF-8?q?=20werden=20jetzt=20direkt=20mit=20erstellt,=20falls=20der=20us?= =?UTF-8?q?er=20selber=20pr=C3=BCfen=20will=20oder=20so=20damit=20er=20sie?= =?UTF-8?q?=20sieht.=20Also=201zu1=20die=20ZIP=20-Mods=20werden=20jetzt=20?= =?UTF-8?q?vom=20ftp=20server=20gelesen=20mit=20version=20und=20config=20s?= =?UTF-8?q?uche.=20Plugin=20funktion=20fehlt=20daf=C3=BCr=20nur=20-=20Text?= =?UTF-8?q?=20Editor=20f=C3=BCr=20Config=20von=20Simple=20zu=20wirklichen?= =?UTF-8?q?=20Editor=20mit=20highlights=20wie=20notepad++=20ge=C3=A4ndert.?= =?UTF-8?q?=20funktioniert=20aber=20noch=20nicht?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Valheim Dashboard/App.axaml | 18 + Valheim Dashboard/App.axaml.cs | 91 +++- Valheim Dashboard/FtpClient.cs | 2 + Valheim Dashboard/Valheim Dashboard.csproj | 1 + .../ViewModels/ServerDashboardViewModel.cs | 397 +++++++++++++++--- Valheim Dashboard/Views/MainWindow.axaml | 5 +- Valheim Dashboard/Views/MainWindow.axaml.cs | 8 + Valheim Dashboard/Views/ServerDashboard.axaml | 29 +- .../Views/ServerDashboard.axaml.cs | 6 + 9 files changed, 497 insertions(+), 60 deletions(-) diff --git a/Valheim Dashboard/App.axaml b/Valheim Dashboard/App.axaml index 2c9ba19..5a36921 100644 --- a/Valheim Dashboard/App.axaml +++ b/Valheim Dashboard/App.axaml @@ -20,5 +20,23 @@ + \ No newline at end of file diff --git a/Valheim Dashboard/App.axaml.cs b/Valheim Dashboard/App.axaml.cs index 161d9ef..e567d15 100644 --- a/Valheim Dashboard/App.axaml.cs +++ b/Valheim Dashboard/App.axaml.cs @@ -1,8 +1,15 @@ using Avalonia; +using Avalonia.Controls; using Avalonia.Controls.ApplicationLifetimes; using Avalonia.Markup.Xaml; +using Avalonia.Media; +using System.Collections.Generic; +using System.Text.RegularExpressions; using Valheim_Dashboard.ViewModels; using Valheim_Dashboard.Views; +using AvaloniaEdit.Highlighting; +using AvaloniaEdit.Highlighting.Xshd; +using System; namespace Valheim_Dashboard; @@ -13,8 +20,90 @@ public partial class App : Application AvaloniaXamlLoader.Load(this); } + private void RegisterCfgHighlighting() + { + static HighlightingBrush HB(string key) + { + var obj = Application.Current!.FindResource(key); + if (obj is ISolidColorBrush scb) + return new SimpleHighlightingBrush(scb.Color); // <-- Color, nicht IBrush + throw new InvalidOperationException($"Resource '{key}' must be a SolidColorBrush."); + } + + var section = new HighlightingColor { Foreground = HB("Cfg.SectionBrush"), FontWeight = FontWeight.Bold }; + var comment = new HighlightingColor { Foreground = HB("Cfg.CommentBrush"), FontStyle = FontStyle.Italic }; + var key = new HighlightingColor { Foreground = HB("Cfg.KeyBrush") }; + var equal = new HighlightingColor { Foreground = HB("Cfg.EqualBrush") }; + var value = new HighlightingColor { Foreground = HB("Cfg.ValueBrush") }; + var number = new HighlightingColor { Foreground = HB("Cfg.NumberBrush") }; + + var rules = new HighlightingRuleSet(); + + // 1) Kommentare: ^\s*#.* + rules.Rules.Add(new HighlightingRule + { + Regex = new Regex(@"^\s*#.*", RegexOptions.Compiled | RegexOptions.Multiline), + Color = comment + }); + + // 2) Sektionen: [Name] + rules.Rules.Add(new HighlightingRule + { + Regex = new Regex(@"^\s*\[[^\]\r\n]+\]\s*$", RegexOptions.Compiled | RegexOptions.Multiline), + Color = section + }); + + // 3a) Schlüssel (von Zeilenbeginn bis vor "=") + rules.Spans.Add(new HighlightingSpan + { + StartExpression = new Regex(@"^\s*", RegexOptions.Compiled | RegexOptions.Multiline), + EndExpression = new Regex(@"=", RegexOptions.Compiled), + SpanColor = key + }); + + // 3b) Gleichheitszeichen + rules.Rules.Add(new HighlightingRule + { + Regex = new Regex(@"=", RegexOptions.Compiled), + Color = equal + }); + + // 3c) Werte (von "=" bis Zeilenende; Kommentar nicht einschließen) + rules.Spans.Add(new HighlightingSpan + { + StartExpression = new Regex(@"=(?!.*#)", RegexOptions.Compiled), // bis Zeilenende ohne # + EndExpression = new Regex(@"$", RegexOptions.Compiled | RegexOptions.Multiline), + SpanColor = value + }); + // 3d) Zahlen im Wert hervorheben + rules.Rules.Add(new HighlightingRule + { + Regex = new Regex(@"\b-?\d+(\.\d+)?\b", RegexOptions.Compiled), + Color = number + }); + + var def = new CustomHighlightingDefinition("CfgDark", rules); + HighlightingManager.Instance.RegisterHighlighting("CfgDark", new[] { ".cfg", ".cfg.txt", ".properties" }, def); + + IBrush? TryRes(string key) => (IBrush?)Current?.FindResource(key); + } + + // kleine Helper-Definition + sealed class CustomHighlightingDefinition : IHighlightingDefinition + { + public CustomHighlightingDefinition(string name, HighlightingRuleSet rules) { Name = name; MainRuleSet = rules; } + public string Name { get; } + public HighlightingRuleSet MainRuleSet { get; } + public IEnumerable NamedHighlightingColors => Array.Empty(); + public IDictionary Properties => new Dictionary(); + public HighlightingRuleSet? GetNamedRuleSet(string name) => null; + public HighlightingColor? GetNamedColor(string name) => null; + } + public override void OnFrameworkInitializationCompleted() { + + if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) { // ViewModelLocator im Ressourcenverzeichnis registrieren @@ -25,7 +114,7 @@ public partial class App : Application DataContext = (Resources["Locator"] as ViewModelLocator)?.MainWindowViewModel, }; } - + RegisterCfgHighlighting(); base.OnFrameworkInitializationCompleted(); } } diff --git a/Valheim Dashboard/FtpClient.cs b/Valheim Dashboard/FtpClient.cs index d24513e..5ce813c 100644 --- a/Valheim Dashboard/FtpClient.cs +++ b/Valheim Dashboard/FtpClient.cs @@ -252,7 +252,9 @@ namespace Valheim_Dashboard request.UseBinary = true; request.UsePassive = true; request.KeepAlive = false; + Debug.WriteLine($"FTP URI: {uri}"); return request; + } public async Task> OpenFolderAsync(string folderPath) diff --git a/Valheim Dashboard/Valheim Dashboard.csproj b/Valheim Dashboard/Valheim Dashboard.csproj index 77c4e6d..faf838f 100644 --- a/Valheim Dashboard/Valheim Dashboard.csproj +++ b/Valheim Dashboard/Valheim Dashboard.csproj @@ -14,6 +14,7 @@ + diff --git a/Valheim Dashboard/ViewModels/ServerDashboardViewModel.cs b/Valheim Dashboard/ViewModels/ServerDashboardViewModel.cs index bba995d..1cffda7 100644 --- a/Valheim Dashboard/ViewModels/ServerDashboardViewModel.cs +++ b/Valheim Dashboard/ViewModels/ServerDashboardViewModel.cs @@ -1,6 +1,8 @@ using Avalonia.Controls; +using AvaloniaEdit.Document; using ReactiveUI; using System; +using System.Collections.Generic; using System.Collections.ObjectModel; using System.Diagnostics; using System.IO; @@ -10,6 +12,8 @@ using System.Net; using System.Net.Http; using System.Reactive; using System.Reactive.Linq; +using System.Reflection; +using System.Text; using System.Text.Json; using System.Threading.Tasks; using Valheim_Dashboard.Models; @@ -74,11 +78,19 @@ public class ServerDashboardViewModel : ViewModelBase } - private string _selectedModConfig; - public string SelectedModConfig + public TextDocument ConfigDocument { get; } = new TextDocument(); + + private string? _selectedModConfig; + public string? SelectedModConfig { get => _selectedModConfig; - set => this.RaiseAndSetIfChanged(ref _selectedModConfig, value); + set + { + this.RaiseAndSetIfChanged(ref _selectedModConfig, value); + var text = value ?? string.Empty; + if (ConfigDocument.Text != text) + ConfigDocument.Text = text; + } } private Window _mainWindow; public void SetMainWindow(Window mainWindow) @@ -111,13 +123,18 @@ public class ServerDashboardViewModel : ViewModelBase SaveConfigCommand = ReactiveCommand.Create(SaveConfig); RemoveModCommand = ReactiveCommand.Create(RemoveMod); + + // DEBUG: harter Testtext – MUSS im Editor erscheinen + ConfigDocument.Text = "[Berries]\n# test\nRaspberryCost = 5"; + + // 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" }); + //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" }); // Start async Initialisierung _ = InitializeAsync(); @@ -130,6 +147,7 @@ public class ServerDashboardViewModel : ViewModelBase IsLoading = true; await CheckBepInExStatus(); IsLoading = false; + await LoadModsFromServer(); } private async Task CheckBepInExStatus() @@ -147,12 +165,6 @@ public class ServerDashboardViewModel : ViewModelBase return; } - var llist = await FtpViewModel._ftpClient.ListDirectoryDetailsAsync(FtpViewModel._currentPath+ "/BepInEx/core"); - foreach (var item1 in llist) - { - Debug.WriteLine(item1.Name); - } - // BepInEx installiert, jetzt Version prüfen string remoteDllPath = FtpViewModel._currentPath + "/BepInEx/core/BepInEx.dll"; Debug.WriteLine("remotedllpath: " + remoteDllPath); @@ -207,52 +219,51 @@ public class ServerDashboardViewModel : ViewModelBase - /* private void InstallBepInEx() - { - BepInExStatus = "Installiert (vX.Y.Z)"; - ShowInstallButton = false; - ShowUpdateButton = true; - } - */ - private readonly HttpClient _http = new HttpClient(); + private int _progressValue; + public int ProgressValue + { + get => _progressValue; + set => this.RaiseAndSetIfChanged(ref _progressValue, value); + } + + private string _progressText; + public string ProgressText + { + get => _progressText; + set => this.RaiseAndSetIfChanged(ref _progressText, value); + } + + private bool _isProgress; + public bool IsProgress + { + get => _isProgress; + set => this.RaiseAndSetIfChanged(ref _isProgress, value); + } public async Task InstallBepInEx() { - Debug.WriteLine("Install star"); + Debug.WriteLine("Install start"); + ShowInstallButton = false; + IsProgress = true; + ProgressValue = 0; + ProgressText = "Starte…"; try { _http.DefaultRequestHeaders.UserAgent.Clear(); _http.DefaultRequestHeaders.UserAgent.ParseAdd("ValheimDashboard/1.0.0"); - HttpResponseMessage resp; - try - { - resp = await _http.GetAsync("https://thunderstore.io/api/experimental/package/denikson/BepInExPack_Valheim/"); - resp.EnsureSuccessStatusCode(); - } - catch (WebException ex) - { - Debug.WriteLine($"Fehler bei Thunderstore Request: {ex.Message}"); - return; - } + // 1) Thunderstore API + HttpResponseMessage resp = await _http.GetAsync("https://thunderstore.io/api/experimental/package/denikson/BepInExPack_Valheim/"); + resp.EnsureSuccessStatusCode(); using var stream = await resp.Content.ReadAsStreamAsync(); - JsonDocument doc; - try - { - doc = await JsonDocument.ParseAsync(stream); - } - catch (Exception ex) - { - Debug.WriteLine($"Fehler beim Parsen von JSON: {ex.Message}"); - return; - } + using var doc = await JsonDocument.ParseAsync(stream); - if (!doc.RootElement.TryGetProperty("latest", out var latestElement) || - !latestElement.TryGetProperty("download_url", out var urlElement)) + if (!doc.RootElement.TryGetProperty("latest", out var latest) || + !latest.TryGetProperty("download_url", out var urlElement)) { Debug.WriteLine("download_url nicht gefunden im JSON"); return; @@ -261,13 +272,16 @@ public class ServerDashboardViewModel : ViewModelBase string downloadUrl = urlElement.GetString()!; Debug.WriteLine($"Starte Download von BepInExPack: {downloadUrl}"); + // --- Fortschritt: Download = 0..25 % + const int DL_START = 0, DL_END = 25, MKDIR_END = 40, UP_END = 100; + using var downloadResponse = await _http.GetAsync(downloadUrl, HttpCompletionOption.ResponseHeadersRead); downloadResponse.EnsureSuccessStatusCode(); var totalBytes = downloadResponse.Content.Headers.ContentLength ?? -1L; using var downloadStream = await downloadResponse.Content.ReadAsStreamAsync(); using var ms = new MemoryStream(); - byte[] buffer = new byte[8192]; + byte[] buffer = new byte[64 * 1024]; // größerer Buffer = schneller long totalRead = 0; int bytesRead; while ((bytesRead = await downloadStream.ReadAsync(buffer, 0, buffer.Length)) > 0) @@ -277,22 +291,85 @@ public class ServerDashboardViewModel : ViewModelBase if (totalBytes > 0) { - int progress = (int)((totalRead * 100) / totalBytes); - Console.Write($"\rDownload Fortschritt: {progress}%"); + int dlPct = (int)((totalRead * 100) / totalBytes); + int uiPct = DL_START + (int)((dlPct / 100.0) * (DL_END - DL_START)); + ProgressValue = uiPct; + ProgressText = $"Download: {dlPct}%"; } } ms.Position = 0; - Console.WriteLine("\nDownload abgeschlossen, entpacke ZIP..."); + ProgressValue = DL_END; + ProgressText = "Download fertig. Entpacke…"; + // 2) ZIP öffnen using var archive = new ZipArchive(ms); + + // 2a) Alle Ordner (inkl. leerer) sammeln -> erster Ordnerteil (BepInExPack_Valheim) wird weggeschnitten + var allFolders = new HashSet(StringComparer.Ordinal); + var allFiles = new List(); + foreach (var entry in archive.Entries) { - if (string.IsNullOrEmpty(entry.Name)) continue; - var parts = entry.FullName.Split(new[] { '/', '\\' }, StringSplitOptions.RemoveEmptyEntries); - if (parts.Length <= 1) continue; - string relativePath = string.Join('/', parts.Skip(1)); + if (parts.Length <= 1) continue; // root-pack-ordner allein ignorieren + // relative Teile ohne Top-Level-Ordner + var relParts = parts.Skip(1).ToArray(); + if (string.IsNullOrEmpty(entry.Name)) + { + // Ein echter Verzeichniseintrag im ZIP (leer) + string folder = string.Join('/', relParts); + if (!string.IsNullOrWhiteSpace(folder)) + allFolders.Add(folder); + } + else + { + // Datei -> über alle Zwischenordner iterieren + for (int i = 0; i < relParts.Length - 1; i++) + { + string folder = string.Join('/', relParts.Take(i + 1)); + allFolders.Add(folder); + } + allFiles.Add(entry); + } + } + + // --- Fortschritt: Ordner anlegen = 25..40 % + ProgressText = "Lege Ordner an…"; + int foldersTotal = allFolders.Count; + int foldersDone = 0; + foreach (var folder in allFolders.OrderBy(s => s.Length)) // erst flache, dann tiefe Ordner + { + Debug.WriteLine("ordner: " + folder); + try + { + // relative Pfade an Ensure übergeben – deine CreateFtpWebRequest() hängt _currentPath selbst an + await FtpViewModel._ftpClient.EnsureFtpDirectoryExistsAsync( + FtpViewModel._currentPath.TrimEnd('/') + "/" + folder + ); + + } + catch (Exception ex) + { + Debug.WriteLine($"Ordner konnte nicht erstellt werden: {folder} - {ex.Message}"); + // idempotent – wenn schon vorhanden, passts + } + + foldersDone++; + int uiPct = DL_END + (int)(((foldersDone / (double)Math.Max(1, foldersTotal)) * (MKDIR_END - DL_END))); + ProgressValue = uiPct; + ProgressText = $"Ordner: {foldersDone}/{foldersTotal}"; + } + + // --- Fortschritt: Dateien hochladen = 40..100 % + ProgressText = "Lade Dateien hoch…"; + int filesTotal = allFiles.Count; + int filesDone = 0; + + foreach (var entry in allFiles) + { + var parts = entry.FullName.Split(new[] { '/', '\\' }, StringSplitOptions.RemoveEmptyEntries); + var relativePath = string.Join('/', parts.Skip(1)); // Top-Level-Ordner weg string remotePath = FtpViewModel._currentPath.TrimEnd('/') + "/" + relativePath; try @@ -304,25 +381,243 @@ public class ServerDashboardViewModel : ViewModelBase { Debug.WriteLine($"FTP Upload Fehler für {remotePath}: {ex.Message}"); } + + filesDone++; + int uiPct = MKDIR_END + (int)(((filesDone / (double)Math.Max(1, filesTotal)) * (UP_END - MKDIR_END))); + ProgressValue = uiPct; + ProgressText = $"Hochgeladen: {filesDone}/{filesTotal}"; } + ProgressValue = 100; + ProgressText = "Fertig ✅"; await CheckBepInExStatus(); } catch (Exception ex) { Debug.WriteLine($"Unbekannter Fehler: {ex}"); + ProgressText = "Fehler"; + } + finally + { + IsProgress = false; } } + private void UpdateBepInEx() { BepInExStatus = "Aktuell (vX.Y.Z)"; ShowUpdateButton = false; } + + //Mod Liste holen + + // Hilfsfunktionen + + static string NormalizeKey(string s) + { + // nur Buchstaben/Ziffern, alles klein + var sb = new StringBuilder(s.Length); + foreach (var ch in s) + if (char.IsLetterOrDigit(ch)) + sb.Append(char.ToLowerInvariant(ch)); + return sb.ToString(); + } + + static string[] SplitBySeparators(string s) + { + // trennt per _,.,-,+, Leerzeichen und Slash/Backslash + return s.Split(new[] { '_', '.', '-', '+', ' ', '/', '\\' }, + StringSplitOptions.RemoveEmptyEntries); + } + + static string ExtractCoreModName(string dllNameNoExt) + { + var parts = SplitBySeparators(dllNameNoExt); + if (parts.Length == 0) return dllNameNoExt; + // häufig ist der letzte Part der eigentliche Modname + return parts[^1]; + } + + static IEnumerable BuildCandidates(string dllNameNoExt) + { + var parts = SplitBySeparators(dllNameNoExt); + + // 1) ganzer Name + yield return dllNameNoExt; + + // 2) Core-Name (letzter Part) + if (parts.Length > 0) + yield return parts[^1]; + + // 3) Varianten mit Punkt/Unterstrich (für Fälle wie Advize_PlantEverything vs advize.PlantEverything) + if (parts.Length > 1) + { + yield return string.Join(".", parts); + yield return string.Join("_", parts); + } + } + + static int LongestCommonSubsequenceLen(string a, string b) + { + // kleine, schnelle Heuristik als Fallback (O(n*m)), nur bei wenigen Kandidaten benutzt + var dp = new int[a.Length + 1, b.Length + 1]; + for (int i = 1; i <= a.Length; i++) + for (int j = 1; j <= b.Length; j++) + dp[i, j] = a[i - 1] == b[j - 1] ? dp[i - 1, j - 1] + 1 : Math.Max(dp[i - 1, j], dp[i, j - 1]); + return dp[a.Length, b.Length]; + } + + + private static string CombineFtp(params string[] parts) + { + return string.Join("/", parts.Where(p => !string.IsNullOrWhiteSpace(p)) + .Select(p => p.Trim('/'))); + } + + private static bool LooksLikeDirectory(dynamic item) // FtpItem? Falls es IsDirectory gibt, nutzen wir das + { + try { return item.IsDirectory; } catch { /* fallback */ } + // Fallback-Heuristik: wenn kein Punkt im Namen, ist es sehr wahrscheinlich ein Ordner + var name = (string)item.Name; + return !name.Contains('.'); + } + + private async Task GetDllVersionFromFtpAsync(string remoteDllPath) + { + using var ms = new MemoryStream(); + await FtpViewModel._ftpClient.DownloadStreamAsync(remoteDllPath, ms); + ms.Position = 0; + + string? version = null; + string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString("N") + ".dll"); + try + { + await System.IO.File.WriteAllBytesAsync(tempPath, ms.ToArray()); + var fvi = FileVersionInfo.GetVersionInfo(tempPath); + version = fvi.FileVersion ?? fvi.ProductVersion; + // Falls FileVersion leer ist, optional Assembly-Version probieren: + if (string.IsNullOrWhiteSpace(version)) + { + try + { + var an = AssemblyName.GetAssemblyName(tempPath); + version = an.Version?.ToString(); + } + catch { /* ignorieren */ } + } + } + finally + { + try { if (System.IO.File.Exists(tempPath)) System.IO.File.Delete(tempPath); } catch { /* ignore */ } + } + return version; + } + + // Hauptmethode + public async Task LoadModsFromServer() + { + try + { + Mods.Clear(); + + if (ServerSettingsView.method == "ftp") + { + + var basePath = FtpViewModel._currentPath.TrimEnd('/'); + var pluginsDir = $"{basePath}/BepInEx/plugins"; + var configDir = $"{basePath}/BepInEx/config"; + + var pluginList = await FtpViewModel._ftpClient.ListDirectoryDetailsAsync(pluginsDir); + var configList = await FtpViewModel._ftpClient.ListDirectoryDetailsAsync(configDir); + + // Vorbereiten: normalisierte Config-Namen mapen + var cfgFiles = configList + .Where(c => c.Name.EndsWith(".cfg", StringComparison.OrdinalIgnoreCase)) + .Select(c => new { + Name = c.Name, + NameNoExt = Path.GetFileNameWithoutExtension(c.Name), + Normalized = NormalizeKey(Path.GetFileNameWithoutExtension(c.Name)) + }) + .ToList(); + + + + foreach (var pl in pluginList) + { + if (!pl.Name.EndsWith(".dll", StringComparison.OrdinalIgnoreCase)) + continue; + + string dllNoExt = Path.GetFileNameWithoutExtension(pl.Name); + + // Kandidaten + normalisierte Kandidaten + var candidates = BuildCandidates(dllNoExt).Distinct(StringComparer.OrdinalIgnoreCase).ToList(); + var normCandidates = candidates.Select(NormalizeKey).Distinct().ToList(); + + // 1) Bevorzugt: Core-Modname muss vorkommen + string core = ExtractCoreModName(dllNoExt); + string normCore = NormalizeKey(core); + + // Match: irgendein normalisierter Kandidat kommt im normalisierten Config-Namen vor + var cfgHit = cfgFiles.FirstOrDefault(cf => cf.Normalized.Contains(normCore)); + if (cfgHit == null) + { + // 2) sonst: irgendein Kandidat kommt vor + 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; + } + } + + // Version aus DLL ziehen + string dllRemote = $"{pluginsDir}/{pl.Name}"; + string? version = null; + try + { + version = await GetDllVersionFromFtpAsync(dllRemote); // wie zuvor implementiert + } + catch (Exception ex) + { + Debug.WriteLine($"Version für {pl.Name} nicht lesbar: {ex.Message}"); + } + + // Config-Pfad setzen (siehe Punkt 2 unten für „absolute“ URI) + string? configRelPath = cfgHit != null ? $"{FtpViewModel._currentPath}/BepInEx/config/{cfgHit.Name}" : null; + + Mods.Add(new ModInfo + { + Name = candidates.Last(), // z.B. „PlantEverything“ statt Autor.Mod + Version = string.IsNullOrWhiteSpace(version) ? "Unbekannt" : version, + ConfigPath = configRelPath // relativ (empfohlen) + }); + } + } + else + { + Debug.WriteLine("Plugin funktion fehlt noch"); + } + } + catch (Exception ex) + { + Debug.WriteLine($"LoadModsFromFtp Fehler: {ex}"); + } + } + + + //Mod Installation / Löschung public async Task OpenFileAsync(Window parent) diff --git a/Valheim Dashboard/Views/MainWindow.axaml b/Valheim Dashboard/Views/MainWindow.axaml index ac12ba1..c81d895 100644 --- a/Valheim Dashboard/Views/MainWindow.axaml +++ b/Valheim Dashboard/Views/MainWindow.axaml @@ -3,11 +3,12 @@ xmlns:vm="using:Valheim_Dashboard.ViewModels" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" - mc:Ignorable="d" d:DesignWidth="1280" d:DesignHeight="800" + mc:Ignorable="d" d:DesignWidth="1424" d:DesignHeight="714" x:Class="Valheim_Dashboard.Views.MainWindow" x:DataType="vm:MainWindowViewModel" CanResize="false" Icon="/Assets/avalonia-logo.ico" - Title="Valheim_Dashboard"> + Title="Valheim_Dashboard" + > - +