- add: config invoke
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
<Styles xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
|
||||
<Styles xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:pages="clr-namespace:Nebula.Launcher.ViewModels.Pages">
|
||||
<Style Selector="Window">
|
||||
<Setter Property="Background" Value="{StaticResource DefaultBackground}" />
|
||||
</Style>
|
||||
@@ -85,4 +86,41 @@
|
||||
<Setter Property="Background" Value="Transparent" />
|
||||
<Setter Property="BorderThickness" Value="0,0,0,1" />
|
||||
</Style>
|
||||
|
||||
<Style Selector="pages|ComplexUnitConfigControl.ConfigBorder">
|
||||
<Setter Property="Background" Value="#333333" />
|
||||
<Setter Property="BorderThickness" Value="2,2,2,2"/>
|
||||
<Setter Property="BorderBrush" Value="Azure"/>
|
||||
</Style>
|
||||
|
||||
<Style Selector="pages|ArrayUnitConfigControl.ConfigBorder">
|
||||
<Setter Property="Background" Value="#333333" />
|
||||
<Setter Property="BorderThickness" Value="2,2,2,2"/>
|
||||
<Setter Property="BorderBrush" Value="Azure"/>
|
||||
</Style>
|
||||
|
||||
<Style Selector="pages|StringUnitConfigControl.ConfigBorder">
|
||||
<Setter Property="Background" Value="#333333" />
|
||||
<Setter Property="BorderThickness" Value="2,2,2,2"/>
|
||||
<Setter Property="BorderBrush" Value="Azure"/>
|
||||
</Style>
|
||||
|
||||
<Style Selector="pages|IntUnitConfigControl.ConfigBorder">
|
||||
<Setter Property="Background" Value="#333333" />
|
||||
<Setter Property="BorderThickness" Value="2,2,2,2"/>
|
||||
<Setter Property="BorderBrush" Value="Azure"/>
|
||||
</Style>
|
||||
|
||||
<Style Selector="pages|FloatUnitConfigControl.ConfigBorder">
|
||||
<Setter Property="Background" Value="#333333" />
|
||||
<Setter Property="BorderThickness" Value="2,2,2,2"/>
|
||||
<Setter Property="BorderBrush" Value="Azure"/>
|
||||
</Style>
|
||||
|
||||
<Style Selector="Button.ConfigBorder /template/ ContentPresenter">
|
||||
<Setter Property="Background" Value="#333333" />
|
||||
<Setter Property="BorderThickness" Value="2,2,2,2"/>
|
||||
<Setter Property="BorderBrush" Value="Azure"/>
|
||||
<Setter Property="CornerRadius" Value="0"/>
|
||||
</Style>
|
||||
</Styles>
|
||||
@@ -78,8 +78,4 @@
|
||||
<ItemGroup>
|
||||
<AdditionalFiles Include="Controls\ServerListView.axaml" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Views\Config\" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
||||
@@ -24,6 +24,7 @@ public sealed partial class FavoriteServerListProvider : IServerListProvider, IS
|
||||
[GenerateProperty] private ServerViewContainer ServerViewContainer { get; }
|
||||
|
||||
private List<IFilterConsumer> _serverLists = [];
|
||||
private string[] rawServerLists = [];
|
||||
|
||||
public bool IsLoaded { get; private set; }
|
||||
public Action? OnLoaded { get; set; }
|
||||
@@ -67,7 +68,6 @@ public sealed partial class FavoriteServerListProvider : IServerListProvider, IS
|
||||
servers.Add(robustUrl.ToString());
|
||||
ConfigurationService.SetConfigValue(LauncherConVar.Favorites, servers.ToArray());
|
||||
ServerViewContainer.Get(robustUrl).IsFavorite = true;
|
||||
Dirty?.Invoke();
|
||||
}
|
||||
|
||||
public void RemoveFavorite(ServerEntryModelView entryModelView)
|
||||
@@ -75,15 +75,31 @@ public sealed partial class FavoriteServerListProvider : IServerListProvider, IS
|
||||
var servers = GetFavoriteEntries();
|
||||
servers.Remove(entryModelView.Address.ToString());
|
||||
ConfigurationService.SetConfigValue(LauncherConVar.Favorites, servers.ToArray());
|
||||
Dirty?.Invoke();
|
||||
}
|
||||
|
||||
private List<string> GetFavoriteEntries()
|
||||
{
|
||||
return ConfigurationService.GetConfigValue(LauncherConVar.Favorites)?.ToList() ?? [];
|
||||
return rawServerLists.ToList();
|
||||
}
|
||||
|
||||
private void Initialise(){}
|
||||
|
||||
private void Initialise()
|
||||
{
|
||||
ConfigurationService.SubscribeVarChanged(LauncherConVar.Favorites, OnVarChanged, true);
|
||||
}
|
||||
|
||||
private void OnVarChanged(string[]? value)
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
rawServerLists = [];
|
||||
Dirty?.Invoke();
|
||||
return;
|
||||
}
|
||||
|
||||
rawServerLists = value;
|
||||
Dirty?.Invoke();
|
||||
}
|
||||
|
||||
private void InitialiseInDesignMode(){}
|
||||
}
|
||||
|
||||
|
||||
34
Nebula.Launcher/Services/ExplorerService.cs
Normal file
34
Nebula.Launcher/Services/ExplorerService.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.InteropServices;
|
||||
using Nebula.Shared;
|
||||
|
||||
namespace Nebula.Launcher.Services;
|
||||
|
||||
|
||||
public static class ExplorerHelper
|
||||
{
|
||||
public static void OpenFolder(string path)
|
||||
{
|
||||
string command;
|
||||
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||
command = "explorer.exe";
|
||||
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
||||
command = "xdg-open";
|
||||
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
|
||||
command = "open";
|
||||
else
|
||||
throw new PlatformNotSupportedException("Unsupported OS platform");
|
||||
|
||||
|
||||
var startInfo = new ProcessStartInfo
|
||||
{
|
||||
FileName = command,
|
||||
Arguments = path,
|
||||
UseShellExecute = false
|
||||
};
|
||||
|
||||
Process.Start(startInfo);
|
||||
}
|
||||
}
|
||||
@@ -2,13 +2,15 @@ using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Layout;
|
||||
using Nebula.Launcher.Services;
|
||||
using Nebula.Launcher.Views.Pages;
|
||||
using Nebula.Shared;
|
||||
using Nebula.Shared.Services;
|
||||
@@ -22,6 +24,8 @@ public partial class ConfigurationViewModel : ViewModelBase
|
||||
public ObservableCollection<IConfigControl> ConfigurationVerbose { get; } = new();
|
||||
|
||||
[GenerateProperty] private ConfigurationService ConfigurationService { get; } = default!;
|
||||
[GenerateProperty] private PopupMessageService PopupService { get; } = default!;
|
||||
[GenerateProperty] private FileService FileService { get; set; } = default!;
|
||||
|
||||
public List<(object, Type)> ConVarList = new();
|
||||
|
||||
@@ -45,9 +49,40 @@ public partial class ConfigurationViewModel : ViewModelBase
|
||||
methodInfo.Invoke(ConfigurationService, [conVar.Item1, conVarControl.GetValue()]);
|
||||
}
|
||||
}
|
||||
|
||||
public void ResetConfig()
|
||||
{
|
||||
foreach (var conVar in ConVarList)
|
||||
{
|
||||
var methodInfo = ConfigurationService.GetType().GetMethod("SetConfigValue")!.MakeGenericMethod(conVar.Item2);
|
||||
methodInfo.Invoke(ConfigurationService, [conVar.Item1, null]);
|
||||
}
|
||||
|
||||
ConVarList.Clear();
|
||||
ConfigurationVerbose.Clear();
|
||||
|
||||
InitConfiguration();
|
||||
|
||||
PopupService.Popup("Configuration has been reset.");
|
||||
}
|
||||
|
||||
public void OpenDataFolder()
|
||||
{
|
||||
ExplorerHelper.OpenFolder(FileService.RootPath);
|
||||
}
|
||||
|
||||
public void ExportLogs()
|
||||
{
|
||||
var logPath = Path.Join(FileService.RootPath, "log");
|
||||
var path = Path.Combine(Path.GetTempPath(), "tempThink"+Path.GetRandomFileName());
|
||||
Directory.CreateDirectory(path);
|
||||
|
||||
ZipFile.CreateFromDirectory(logPath, Path.Join(path, DateTime.Now.ToString("yyyy-MM-dd") + ".zip"));
|
||||
ExplorerHelper.OpenFolder(path);
|
||||
}
|
||||
|
||||
protected override void InitialiseInDesignMode()
|
||||
{
|
||||
private void InitConfiguration()
|
||||
{
|
||||
AddCvarConf(LauncherConVar.ILSpyUrl);
|
||||
AddCvarConf(LauncherConVar.Hub);
|
||||
AddCvarConf(LauncherConVar.AuthServers);
|
||||
@@ -55,10 +90,15 @@ public partial class ConfigurationViewModel : ViewModelBase
|
||||
AddCvarConf(CurrentConVar.RobustAssemblyName);
|
||||
AddCvarConf(CurrentConVar.ManifestDownloadProtocolVersion);
|
||||
}
|
||||
|
||||
protected override void InitialiseInDesignMode()
|
||||
{
|
||||
InitConfiguration();
|
||||
}
|
||||
|
||||
protected override void Initialise()
|
||||
{
|
||||
InitialiseInDesignMode();
|
||||
InitConfiguration();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,31 +143,34 @@ public static class ConfigControlHelper{
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class ComplexUnitConfigControl : StackPanel, IConfigControl
|
||||
public sealed class ComplexUnitConfigControl : Border, IConfigControl
|
||||
{
|
||||
private List<(PropertyInfo, IConfigControl)> _units = [];
|
||||
private readonly List<(PropertyInfo, IConfigControl)> _units = [];
|
||||
|
||||
private Type _objectType = typeof(object);
|
||||
|
||||
private readonly StackPanel _panel = new();
|
||||
|
||||
public string ConfigName { get; }
|
||||
public bool Dirty => _units.Any(dirty => dirty.Item2.Dirty);
|
||||
|
||||
public ComplexUnitConfigControl(string name, object obj)
|
||||
{
|
||||
Orientation = Orientation.Vertical;
|
||||
Margin = new Thickness(5);
|
||||
Spacing = 2f;
|
||||
Classes.Add("ConfigBorder");
|
||||
_panel.Orientation = Orientation.Vertical;
|
||||
_panel.Spacing = 4f;
|
||||
ConfigName = name;
|
||||
Child = _panel;
|
||||
SetValue(obj);
|
||||
}
|
||||
|
||||
public void SetValue(object value)
|
||||
{
|
||||
_units.Clear();
|
||||
Children.Clear();
|
||||
_panel.Children.Clear();
|
||||
_objectType = value.GetType();
|
||||
|
||||
Children.Add(new Label()
|
||||
_panel.Children.Add(new Label()
|
||||
{
|
||||
Content = ConfigName
|
||||
});
|
||||
@@ -141,7 +184,8 @@ public sealed class ComplexUnitConfigControl : StackPanel, IConfigControl
|
||||
|
||||
var control = ConfigControlHelper.GetConfigControl(propInfo.Name, propValue);
|
||||
|
||||
Children.Add(control as Control);
|
||||
((Control)control).Margin = new Thickness(5);
|
||||
_panel.Children.Add((Control)control);
|
||||
_units.Add((propInfo,control));
|
||||
}
|
||||
}
|
||||
@@ -158,48 +202,51 @@ public sealed class ComplexUnitConfigControl : StackPanel, IConfigControl
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class ArrayUnitConfigControl : StackPanel, IConfigControl
|
||||
public sealed class ArrayUnitConfigControl : Border, IConfigControl
|
||||
{
|
||||
private readonly List<IConfigControl> _itemControls = [];
|
||||
private readonly StackPanel _itemsPanel = new StackPanel() { Orientation = Orientation.Vertical };
|
||||
private readonly Button _addButton = new Button() { Content = "Add Item" };
|
||||
private int oldCount;
|
||||
private readonly Button _addButton = new Button() { Content = "Add Item", Classes = { "ConfigBorder" }};
|
||||
private readonly int _oldCount;
|
||||
private readonly Type _elementType;
|
||||
private readonly StackPanel _panel = new();
|
||||
|
||||
public string ConfigName { get; }
|
||||
public bool Dirty => _itemControls.Any(dirty => dirty.Dirty) || _itemControls.Count != oldCount;
|
||||
public bool Dirty => _itemControls.Any(dirty => dirty.Dirty) || _itemControls.Count != _oldCount;
|
||||
|
||||
public ArrayUnitConfigControl(string name, object value)
|
||||
{
|
||||
_elementType = value.GetType().GetElementType();
|
||||
Classes.Add("ConfigBorder");
|
||||
_elementType = value.GetType().GetElementType()!;
|
||||
|
||||
ConfigName = name;
|
||||
Orientation = Orientation.Vertical;
|
||||
Margin = new Thickness(5);
|
||||
Spacing = 2f;
|
||||
_panel.Orientation = Orientation.Vertical;
|
||||
_panel.Spacing = 4f;
|
||||
_itemsPanel.Spacing = 4f;
|
||||
|
||||
Children.Add(new Label { Content = name });
|
||||
Children.Add(_itemsPanel);
|
||||
Children.Add(_addButton);
|
||||
|
||||
_addButton.Click += (_, _) => AddItem(ConfigControlHelper.CreateDefaultValue(_elementType));
|
||||
_panel.Children.Add(new Label { Content = name });
|
||||
_panel.Children.Add(_itemsPanel);
|
||||
_panel.Children.Add(_addButton);
|
||||
|
||||
_addButton.Click += (_, _) => AddItem(ConfigControlHelper.CreateDefaultValue(_elementType)!);
|
||||
Child = _panel;
|
||||
SetValue(value);
|
||||
oldCount = _itemControls.Count;
|
||||
_oldCount = _itemControls.Count;
|
||||
}
|
||||
|
||||
private void AddItem(object value)
|
||||
{
|
||||
var itemPanel = new StackPanel { Orientation = Orientation.Horizontal, Spacing = 2 };
|
||||
var control = ConfigControlHelper.GetConfigControl(_itemControls.Count.ToString(), value);
|
||||
var removeButton = new Button { Content = "Remove" };
|
||||
var removeButton = new Button { Content = "Remove", Classes = { "ConfigBorder" }};
|
||||
|
||||
removeButton.Click += (_, _) =>
|
||||
{
|
||||
_itemControls.Remove(control);
|
||||
_itemsPanel.Children.Remove(itemPanel);
|
||||
};
|
||||
|
||||
|
||||
((Control)control).Margin = new Thickness(5);
|
||||
itemPanel.Children.Add((Control)control);
|
||||
itemPanel.Children.Add(removeButton);
|
||||
|
||||
@@ -242,37 +289,35 @@ public sealed class ArrayUnitConfigControl : StackPanel, IConfigControl
|
||||
}
|
||||
}
|
||||
|
||||
public abstract class UnitConfigControl<T> : StackPanel, IConfigControl where T : notnull
|
||||
public abstract class UnitConfigControl<T> : Border, IConfigControl where T : notnull
|
||||
{
|
||||
private readonly Label _nameLabel = new Label();
|
||||
private readonly TextBox _valueLabel = new TextBox();
|
||||
private readonly Label _nameLabel = new();
|
||||
private readonly TextBox _valueLabel = new();
|
||||
private string _originalValue;
|
||||
|
||||
public string ConfigName { get; private set;}
|
||||
|
||||
public bool Dirty
|
||||
{
|
||||
get
|
||||
{
|
||||
return _originalValue != ConfigValue;
|
||||
}
|
||||
}
|
||||
|
||||
protected string? ConfigValue
|
||||
private StackPanel _panel = new();
|
||||
|
||||
public string ConfigName { get; }
|
||||
|
||||
public bool Dirty => _originalValue != ConfigValue;
|
||||
|
||||
protected string ConfigValue
|
||||
{
|
||||
get => _valueLabel.Text;
|
||||
get => _valueLabel.Text ?? string.Empty;
|
||||
set => _valueLabel.Text = value;
|
||||
}
|
||||
|
||||
public UnitConfigControl(string name, T value)
|
||||
{
|
||||
Classes.Add("ConfigBorder");
|
||||
ConfigName = name;
|
||||
Orientation = Orientation.Horizontal;
|
||||
Children.Add(_nameLabel);
|
||||
Children.Add(_valueLabel);
|
||||
_panel.Orientation = Orientation.Horizontal;
|
||||
_panel.Children.Add(_nameLabel);
|
||||
_panel.Children.Add(_valueLabel);
|
||||
|
||||
_nameLabel.Content = name;
|
||||
_nameLabel.VerticalAlignment = VerticalAlignment.Center;
|
||||
Child = _panel;
|
||||
|
||||
SetConfValue(value);
|
||||
_originalValue = ConfigValue;
|
||||
@@ -302,7 +347,7 @@ public sealed class StringUnitConfigControl(string name, string value) : UnitCon
|
||||
|
||||
public override string GetConfValue()
|
||||
{
|
||||
return ConfigValue ?? string.Empty;
|
||||
return ConfigValue;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -315,8 +360,6 @@ public sealed class IntUnitConfigControl(string name, int value) : UnitConfigCon
|
||||
|
||||
public override int GetConfValue()
|
||||
{
|
||||
Debug.Assert(ConfigValue != null, nameof(ConfigValue) + " != null");
|
||||
|
||||
return int.Parse(ConfigValue);
|
||||
}
|
||||
}
|
||||
@@ -333,8 +376,6 @@ public sealed class FloatUnitConfigControl(string name, float value) : UnitConfi
|
||||
|
||||
public override float GetConfValue()
|
||||
{
|
||||
Debug.Assert(ConfigValue != null, nameof(ConfigValue) + " != null");
|
||||
|
||||
return float.Parse(ConfigValue, CultureInfo);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,12 +59,7 @@ public sealed partial class ContentBrowserViewModel : ViewModelBase, IContentHol
|
||||
PopupService.Popup(loading);
|
||||
|
||||
Task.Run(() => ContentService.Unpack(serverEntry.FileApi, myTempDir, loading));
|
||||
var startInfo = new ProcessStartInfo(){
|
||||
FileName = "explorer.exe",
|
||||
Arguments = tmpDir,
|
||||
};
|
||||
|
||||
Process.Start(startInfo);
|
||||
ExplorerHelper.OpenFolder(tmpDir);
|
||||
}
|
||||
|
||||
public void OnGoEnter()
|
||||
|
||||
@@ -57,9 +57,15 @@ public partial class ServerOverviewModel : ViewModelBase
|
||||
|
||||
//real think
|
||||
protected override void Initialise()
|
||||
{
|
||||
ConfigurationService.SubscribeVarChanged(LauncherConVar.Hub, OnHubListChanged, true);
|
||||
}
|
||||
|
||||
private void OnHubListChanged(ServerHubRecord[]? value)
|
||||
{
|
||||
var tempItems = new List<ServerListTabTemplate>();
|
||||
foreach (var record in ConfigurationService.GetConfigValue(LauncherConVar.Hub) ?? [])
|
||||
|
||||
foreach (var record in value ?? [])
|
||||
{
|
||||
tempItems.Add(new ServerListTabTemplate(ServiceProvider.GetService<HubServerListProvider>()!.With(record.MainUrl), record.Name));
|
||||
}
|
||||
@@ -125,17 +131,32 @@ public partial class ServerOverviewModel : ViewModelBase
|
||||
public class ServerViewContainer
|
||||
{
|
||||
private readonly ViewHelperService _viewHelperService;
|
||||
private List<string> favorites = [];
|
||||
|
||||
public ServerViewContainer()
|
||||
{
|
||||
_viewHelperService = new ViewHelperService();
|
||||
}
|
||||
|
||||
public ServerViewContainer(ViewHelperService viewHelperService)
|
||||
public ServerViewContainer(ViewHelperService viewHelperService, ConfigurationService configurationService)
|
||||
{
|
||||
_viewHelperService = viewHelperService;
|
||||
configurationService.SubscribeVarChanged(LauncherConVar.Favorites, OnFavoritesChange, true);
|
||||
}
|
||||
|
||||
|
||||
private void OnFavoritesChange(string[]? value)
|
||||
{
|
||||
favorites = new List<string>(value ?? []);
|
||||
|
||||
foreach (var favorite in favorites)
|
||||
{
|
||||
if (_entries.TryGetValue(favorite, out var entry))
|
||||
{
|
||||
entry.IsFavorite = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private readonly Dictionary<string, ServerEntryModelView> _entries = new();
|
||||
|
||||
public ICollection<ServerEntryModelView> Items => _entries.Values;
|
||||
@@ -158,6 +179,8 @@ public class ServerViewContainer
|
||||
|
||||
entry = _viewHelperService.GetViewModel<ServerEntryModelView>().WithData(url, serverStatus);
|
||||
|
||||
if(favorites.Contains(url.ToString())) entry.IsFavorite = true;
|
||||
|
||||
_entries.Add(url.ToString(), entry);
|
||||
}
|
||||
|
||||
|
||||
@@ -134,17 +134,10 @@ public partial class ServerEntryModelView : ViewModelBase, IFilterConsumer
|
||||
SetStatus(serverStatus!);
|
||||
else
|
||||
FetchStatus();
|
||||
|
||||
IsFavorite = GetFavoriteEntries().Contains(Address.ToString());
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
private List<string> GetFavoriteEntries()
|
||||
{
|
||||
return ConfigurationService.GetConfigValue(LauncherConVar.Favorites)?.ToList() ?? [];
|
||||
}
|
||||
|
||||
|
||||
private async void FetchStatus()
|
||||
{
|
||||
try
|
||||
|
||||
@@ -21,14 +21,45 @@
|
||||
</ItemsPanelTemplate>
|
||||
</ItemsControl.ItemsPanel>
|
||||
</ItemsControl>
|
||||
<Button
|
||||
VerticalAlignment="Bottom"
|
||||
HorizontalAlignment="Stretch"
|
||||
Padding="5"
|
||||
Margin="5"
|
||||
Command="{Binding InvokeUpdateConfiguration}">
|
||||
Save
|
||||
</Button>
|
||||
<StackPanel Orientation="Horizontal" Spacing="5">
|
||||
<Button
|
||||
Classes="ConfigBorder"
|
||||
VerticalAlignment="Bottom"
|
||||
HorizontalAlignment="Stretch"
|
||||
Padding="5"
|
||||
Margin="5"
|
||||
Command="{Binding InvokeUpdateConfiguration}">
|
||||
Save
|
||||
</Button>
|
||||
<Button
|
||||
Classes="ConfigBorder"
|
||||
VerticalAlignment="Bottom"
|
||||
HorizontalAlignment="Stretch"
|
||||
Padding="5"
|
||||
Margin="5"
|
||||
Command="{Binding ResetConfig}">
|
||||
Reset to default
|
||||
</Button>
|
||||
<Button
|
||||
Classes="ConfigBorder"
|
||||
VerticalAlignment="Bottom"
|
||||
HorizontalAlignment="Stretch"
|
||||
Padding="5"
|
||||
Margin="5"
|
||||
Command="{Binding OpenDataFolder}">
|
||||
Open Data path
|
||||
</Button>
|
||||
|
||||
<Button
|
||||
Classes="ConfigBorder"
|
||||
VerticalAlignment="Bottom"
|
||||
HorizontalAlignment="Stretch"
|
||||
Padding="5"
|
||||
Margin="5"
|
||||
Command="{Binding ExportLogs}">
|
||||
Export logs
|
||||
</Button>
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
</ScrollViewer>
|
||||
</UserControl>
|
||||
|
||||
@@ -8,6 +8,8 @@ namespace Nebula.Shared.Services;
|
||||
|
||||
public class ConVar<T>
|
||||
{
|
||||
internal ConfigurationService.OnConfigurationChangedDelegate<T?>? OnValueChanged;
|
||||
|
||||
public ConVar(string name, T? defaultValue = default)
|
||||
{
|
||||
Name = name ?? throw new ArgumentNullException(nameof(name));
|
||||
@@ -45,11 +47,16 @@ public class ConfigurationService
|
||||
ConfigurationApi = fileService.CreateFileApi("config");
|
||||
}
|
||||
|
||||
private void SubscribeVarChanged<T>(ConVar<T> convar, OnConfigurationChangedDelegate<T> @delegate)
|
||||
public ConfigChangeSubscriberDisposable<T> SubscribeVarChanged<T>(ConVar<T> convar, OnConfigurationChangedDelegate<T?> @delegate, bool invokeNow = false)
|
||||
{
|
||||
convar.OnValueChanged += @delegate;
|
||||
if (invokeNow)
|
||||
{
|
||||
@delegate(GetConfigValue(convar));
|
||||
}
|
||||
|
||||
return new ConfigChangeSubscriberDisposable<T>(convar, @delegate);
|
||||
}
|
||||
|
||||
|
||||
public T? GetConfigValue<T>(ConVar<T> conVar)
|
||||
{
|
||||
@@ -107,8 +114,12 @@ public class ConfigurationService
|
||||
|
||||
public void SetConfigValue<T>(ConVar<T> conVar, T value)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(conVar);
|
||||
if (value == null) throw new ArgumentNullException(nameof(value));
|
||||
if (value == null)
|
||||
{
|
||||
ConfigurationApi.Remove(GetFileName(conVar));
|
||||
conVar.OnValueChanged?.Invoke(conVar.DefaultValue);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!conVar.Type.IsInstanceOfType(value))
|
||||
{
|
||||
@@ -129,6 +140,7 @@ public class ConfigurationService
|
||||
stream.Seek(0, SeekOrigin.Begin);
|
||||
|
||||
ConfigurationApi.Save(GetFileName(conVar), stream);
|
||||
conVar.OnValueChanged?.Invoke(value);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@@ -140,4 +152,20 @@ public class ConfigurationService
|
||||
{
|
||||
return $"{conVar.Name}.json";
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class ConfigChangeSubscriberDisposable<T> : IDisposable
|
||||
{
|
||||
private readonly ConVar<T> _convar;
|
||||
private readonly ConfigurationService.OnConfigurationChangedDelegate<T> _delegate;
|
||||
|
||||
public ConfigChangeSubscriberDisposable(ConVar<T> convar, ConfigurationService.OnConfigurationChangedDelegate<T> @delegate)
|
||||
{
|
||||
_convar = convar;
|
||||
_delegate = @delegate;
|
||||
}
|
||||
public void Dispose()
|
||||
{
|
||||
_convar.OnValueChanged -= _delegate;
|
||||
}
|
||||
}
|
||||
@@ -72,17 +72,19 @@ internal class ServiceLogger : ILogger
|
||||
if (!DebugService.DoFileLog) return;
|
||||
|
||||
if(!Directory.Exists(directory)) Directory.CreateDirectory(directory);
|
||||
|
||||
_path = Path.Combine(directory, $"{Category}.log");
|
||||
|
||||
_fileStream = File.Open(Path.Combine(directory,$"{Category}.log"), FileMode.Create, FileAccess.Write, FileShare.Read);
|
||||
_streamWriter = new StreamWriter(_fileStream);
|
||||
File.Create(_path).Dispose();
|
||||
}
|
||||
|
||||
public string Category { get; init; }
|
||||
|
||||
private Dictionary<string, ServiceLogger> Childs { get; init; } = new();
|
||||
|
||||
private readonly FileStream _fileStream;
|
||||
private readonly StreamWriter _streamWriter;
|
||||
private FileStream? _fileStream;
|
||||
private StreamWriter? _streamWriter;
|
||||
private readonly string _path;
|
||||
|
||||
public ServiceLogger GetLogger(string category)
|
||||
{
|
||||
@@ -109,17 +111,25 @@ internal class ServiceLogger : ILogger
|
||||
private void LogToFile(string output)
|
||||
{
|
||||
if(!DebugService.DoFileLog) return;
|
||||
_fileStream = File.Open(_path, FileMode.Append, FileAccess.Write, FileShare.ReadWrite);
|
||||
_streamWriter = new StreamWriter(_fileStream);
|
||||
Root?.LogToFile(output);
|
||||
_streamWriter.WriteLine(output);
|
||||
_streamWriter.Flush();
|
||||
|
||||
_streamWriter.Dispose();
|
||||
_fileStream.Dispose();
|
||||
|
||||
_fileStream = null;
|
||||
_streamWriter = null;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (!DebugService.DoFileLog) return;
|
||||
|
||||
_streamWriter.Dispose();
|
||||
_fileStream.Dispose();
|
||||
_streamWriter?.Dispose();
|
||||
_fileStream?.Dispose();
|
||||
foreach (var (_, child) in Childs)
|
||||
{
|
||||
child.Dispose();
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AArchiving_002EUtils_002EWindows_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003FUsers_003FCinka_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003F27e9f12ad1e4318b9b02849ec3e6a502fa3ee761c4f0522ba756ab30cde1c_003FArchiving_002EUtils_002EWindows_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AAvaloniaXamlLoader_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003FUsers_003FCinka_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003F80462644bd1cc7e0b229dc4f5752b48c01cb67b46ae563b1b5078cc2556b98_003FAvaloniaXamlLoader_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ABorder_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003FUsers_003FCinka_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003F5fda7f1253ea19edc15f91b94a33322b857f1a9319fbffea8d26e9d304178_003FBorder_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ABrushes_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003FUsers_003FCinka_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003F86e7f7d5cebacb8f8e37f52cb9a1f6a4b8933239631e3d969a4bc881ae92f9_003FBrushes_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AButton_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003FUsers_003FCinka_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003Fcc84c38d8785b88e166e6741b6a4c0dfa09eaf6e41eb151b255817e11f27570_003FButton_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ACancellationToken_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003FUsers_003FCinka_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003F2565b9d99fdde488bc7801b84387b2cc864959cfb63212e1ff576fc9c6bb7e_003FCancellationToken_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ACollection_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003FUsers_003FCinka_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003F50341a469131fa51e5443b9bd96c4ca1c96bfa709f7f41fd15941ff6296a8dc_003FCollection_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
@@ -9,6 +11,8 @@
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ADecorator_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003FUsers_003FCinka_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003Feecfe7fcb95caaf3978fdce4ae36e346b34986d1d844b0dce2fcb67e5952c_003FDecorator_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ADrawingContext_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003FUsers_003FCinka_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003F7f67edd2b798d6c80b015913cde68b729bfe416b62cf075ea3953ffeff639c_003FDrawingContext_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AEnumerable_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003FUsers_003FCinka_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Fcae7ff14a5884c649c9045d4ef4f987ea0928_003Fa6_003F6011c781_003FEnumerable_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AFileShare_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003FUsers_003FCinka_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Fa6b7f037ba7b44df80b8d3aa7e58eeb2e8e938_003F54_003Fc3f4f140_003FFileShare_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AFile_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003FUsers_003FCinka_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003F3f31e7e8aa33de883c2ccfa62a9c81bfc246c36e825b489476f9472032e512_003FFile_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AFrozenDictionary_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003FUsers_003FCinka_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003F89dff9063ddb01ff8125b579122b88bf4de94526490d77bcbbef7d0ee662a_003FFrozenDictionary_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AFuture_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003FUsers_003FCinka_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003Fb3575a2f41d7c2dbfaa36e866b8a361e11dd7223ff82bc574c1d5d4b7522f735_003FFuture_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AHttpClient_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003FUsers_003FCinka_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003Fc439425da351c75ac7d966a1cc8324b51a9c471865af79d2f2f3fcb65e392_003FHttpClient_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
@@ -31,6 +35,9 @@
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AServiceProviderServiceExtensions_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003FUsers_003FCinka_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F4f1fdec7cbfe4433a7ec3a6d1bd0e54210118_003F04_003Fe2f5322d_003FServiceProviderServiceExtensions_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ASingle_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003FUsers_003FCinka_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003Fe27543f11ad92fdb62cde92eebaa1afb3de86a016ad85f76d1554b0389cd3f3_003FSingle_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AString_002EManipulation_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003FUsers_003FCinka_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003Fe75a5575ba872c8ea754c015cb363850e6c661f39569712d5b74aaca67263c_003FString_002EManipulation_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AStyle_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003FUsers_003FCinka_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003Fcfbd5689fdab68d1c02f6a9b3c5921abcc409b8743dcc958da77cc1cfcb8e_003FStyle_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AUri_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003FUsers_003FCinka_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003F6a1fb5a19c4883d19f63515be2d0cce5e0e9929bb30469a912a58ad2e1e6152_003FUri_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AValuePrinter_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003FUsers_003FCinka_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F80d1676fb411442983574149e0b6aebc72e00_003F2f_003F26a40f58_003FValuePrinter_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AZipFileExtensions_002EZipArchive_002ECreate_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003FUsers_003FCinka_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003F1dd11f63b66adf34b6a6d76e1e0c0fd1df69d78b5fbfdcdf31c67b6bb40e9e4_003FZipFileExtensions_002EZipArchive_002ECreate_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AZipFile_002ECreate_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003FUsers_003FCinka_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003F5161553fb4bfeb0f7caff73da46449e1fb0d343789e21ff4d481db57d521976_003FZipFile_002ECreate_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/PencilsConfiguration/ActualSeverity/@EntryValue">INFO</s:String></wpf:ResourceDictionary>
|
||||
Reference in New Issue
Block a user