- BepInEx Installation schneller gemach
- BepInEx Installation Progress Bar hinzugefügt um fortschritt anzuzeigen -BepInEx Leere ordner werden jetzt direkt mit erstellt, falls der user selber prüfen will oder so damit er sie sieht. Also 1zu1 die ZIP -Mods werden jetzt vom ftp server gelesen mit version und config suche. Plugin funktion fehlt dafür nur - Text Editor für Config von Simple zu wirklichen Editor mit highlights wie notepad++ geändert. funktioniert aber noch nicht
This commit is contained in:
@@ -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<68>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<69>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<HighlightingColor> NamedHighlightingColors => Array.Empty<HighlightingColor>();
|
||||
public IDictionary<string, string> Properties => new Dictionary<string, string>();
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user