Compare commits
21 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 6eead05308 | |||
| 673a972598 | |||
| f44589454c | |||
| fd06729035 | |||
| a09ace0d39 | |||
| 56c373134f | |||
| fa68b4bcd5 | |||
| b86b65fd66 | |||
| 6c967efd85 | |||
| 6a6bb4f27c | |||
| f6a15e9c45 | |||
| c148f6ed34 | |||
| a475148543 | |||
| 34fd4ebf4c | |||
| 83d116003b | |||
| a3c96174b2 | |||
| 3bfae32c25 | |||
| ae17ff2d89 | |||
| 517fadaab8 | |||
| 9e95d68c4a | |||
| 01ebe3219d |
2
.idea/.idea.Nebula/.idea/avalonia.xml
generated
2
.idea/.idea.Nebula/.idea/avalonia.xml
generated
@@ -33,6 +33,7 @@
|
||||
<entry key="Nebula.Launcher/Views/Popup/ExceptionListView.axaml" value="Nebula.Launcher/Nebula.Launcher.csproj" />
|
||||
<entry key="Nebula.Launcher/Views/Popup/ExceptionView.axaml" value="Nebula.Launcher/Nebula.Launcher.csproj" />
|
||||
<entry key="Nebula.Launcher/Views/Popup/InfoPopupView.axaml" value="Nebula.Launcher/Nebula.Launcher.csproj" />
|
||||
<entry key="Nebula.Launcher/Views/Popup/IsLoginCredentialsNullPopupView.axaml" value="Nebula.Launcher/Nebula.Launcher.csproj" />
|
||||
<entry key="Nebula.Launcher/Views/Popup/LoadingContextView.axaml" value="Nebula.Launcher/Nebula.Launcher.csproj" />
|
||||
<entry key="Nebula.Launcher/Views/Popup/LogPopupView.axaml" value="Nebula.Launcher/Nebula.Launcher.csproj" />
|
||||
<entry key="Nebula.Launcher/Views/Popup/MessagePopupView.axaml" value="Nebula.Launcher/Nebula.Launcher.csproj" />
|
||||
@@ -44,6 +45,7 @@
|
||||
<entry key="Nebula.Launcher/Views/ServerListView.axaml" value="Nebula.Launcher/Nebula.Launcher.csproj" />
|
||||
<entry key="Nebula.Launcher/Views/Tabs/AccountInfoTab.axaml" value="Nebula.Launcher/Nebula.Launcher.csproj" />
|
||||
<entry key="Nebula.Launcher/Views/Tabs/ServerListTab.axaml" value="Nebula.Launcher/Nebula.Launcher.csproj" />
|
||||
<entry key="Nebula.Launcher/Views/VisualErrorView.axaml" value="Nebula.Launcher/Nebula.Launcher.csproj" />
|
||||
<entry key="Nebula.UpdateResolver/App.axaml" value="Nebula.UpdateResolver/Nebula.UpdateResolver.csproj" />
|
||||
<entry key="Nebula.UpdateResolver/MainWindow.axaml" value="Nebula.UpdateResolver/Nebula.UpdateResolver.csproj" />
|
||||
</map>
|
||||
|
||||
@@ -28,14 +28,16 @@ public class App : Application
|
||||
{
|
||||
case IClassicDesktopStyleApplicationLifetime desktop:
|
||||
DisableAvaloniaDataAnnotationValidation();
|
||||
desktop.MainWindow = new MessageWindow(out provider);
|
||||
desktop.MainWindow = (Window)(provider = new MessageWindow());
|
||||
break;
|
||||
case ISingleViewApplicationLifetime singleViewPlatform:
|
||||
singleViewPlatform.MainView = new MessageView(out provider);
|
||||
singleViewPlatform.MainView = (Control)(provider = new MessageView());
|
||||
break;
|
||||
}
|
||||
|
||||
provider?.ShowMessage("Launcher is already running.","hey shithead!");
|
||||
provider?.ShowMessage(
|
||||
"Error: An instance of the application is already running. Please close the existing instance before launching a new one.",
|
||||
"Duplicate instance detected.");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -107,10 +107,10 @@
|
||||
pages|StringUnitConfigControl.ConfigBorder,
|
||||
pages|IntUnitConfigControl.ConfigBorder,
|
||||
pages|FloatUnitConfigControl.ConfigBorder">
|
||||
<Setter Property="Background" Value="#333333" />
|
||||
<Setter Property="CornerRadius" Value="5"/>
|
||||
<Setter Property="BorderThickness" Value="1,0,1,2" />
|
||||
<Setter Property="BorderBrush" Value="Azure" />
|
||||
<Setter Property="Background" Value="#33333355" />
|
||||
<Setter Property="CornerRadius" Value="0"/>
|
||||
<Setter Property="BorderThickness" Value="1,0,0,2" />
|
||||
<Setter Property="BorderBrush" Value="#3f3f3f5f" />
|
||||
</Style>
|
||||
|
||||
</Styles>
|
||||
BIN
Nebula.Launcher/Assets/error_presentation/Cinka.png
Normal file
BIN
Nebula.Launcher/Assets/error_presentation/Cinka.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 150 KiB |
BIN
Nebula.Launcher/Assets/error_presentation/alex.png
Normal file
BIN
Nebula.Launcher/Assets/error_presentation/alex.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 158 KiB |
@@ -24,7 +24,10 @@ account-auth-server = Authentication Server
|
||||
account-auth-button = Authenticate
|
||||
account-auth-save = Save Profile
|
||||
account-auth-hello = Hello,
|
||||
account-auth-current-server = Current server auth:
|
||||
account-auth-logout = Log out
|
||||
auth-current-login-name = Current login {$auth_server}: {$login}
|
||||
auth-current-login-no-name = Profile not selected
|
||||
|
||||
auth-processing = Processing authentication request...
|
||||
auth-error = An authentication error has occurred.
|
||||
@@ -35,16 +38,20 @@ auth-name-resolution-error = Failed to resolve server address. Check your networ
|
||||
auth-secure-error = Failed to cinnect to the server using SSL
|
||||
auth-config-read = Reading authentication configuration...
|
||||
auth-try-auth-config = Attempting to authenticate using saved configuration.
|
||||
auth-try-auth-profile = Attempting to authenticate using profile
|
||||
|
||||
config-export-logs = Export logs
|
||||
config-open-data = Open data path
|
||||
config-reset = Reset to default
|
||||
config-save = Save changes
|
||||
config-remove-content-all = Remove all content
|
||||
|
||||
filter-roleplay = Roleplay
|
||||
filter-language = Language
|
||||
favorite-add = Add to favorites
|
||||
popup-add-favorite-invalid-ip = Please enter a valid IP
|
||||
servername-set = Set server name
|
||||
servername-clear = Clear server name
|
||||
twofa-enabled = You have two-factor authentication enabled. Please enter the code.
|
||||
twofa-set = Proceed
|
||||
|
||||
@@ -54,4 +61,12 @@ serverentry-map = Map
|
||||
serverentry-preset = Preset
|
||||
|
||||
content-view-server = Server url
|
||||
content-view-path = Path
|
||||
content-view-path = Path
|
||||
|
||||
popup-login-credentials-warning = Warning! No credentials provided!
|
||||
popup-login-credentials-warning-label = Warning! No credentials provided! The servers will not be able to let you in due to lack of authorization. Please keep this in mind.
|
||||
popup-login-credentials-warning-go-auth = Go to auth page
|
||||
popup-login-credentials-warning-cancel = Cancel
|
||||
popup-login-credentials-warning-proceed = Proceed
|
||||
|
||||
goto-path-home = Root folder
|
||||
|
||||
@@ -24,7 +24,10 @@ account-auth-server = Сервер аутентификации
|
||||
account-auth-button = Аутентифицировать
|
||||
account-auth-save = Сохранить профиль
|
||||
account-auth-hello = Привет,
|
||||
account-auth-current-server = Текущий сервер авторизации:
|
||||
account-auth-logout = Выйти
|
||||
auth-current-login-name = Текущий профиль {$auth_server}: {$login}
|
||||
auth-current-login-no-name = Профиль не выбран
|
||||
|
||||
auth-processing = Обработка запроса аутентификации...
|
||||
auth-error = Произошла ошибка аутентификации.
|
||||
@@ -35,16 +38,20 @@ auth-name-resolution-error = Не удалось разрешить адрес
|
||||
auth-secure-error = Не удалось подключиться к серверу по SSL. Проверьте сетевые настройки.
|
||||
auth-config-read = Чтение конфигурации аутентификации...
|
||||
auth-try-auth-config = Попытка аутентификации с использованием сохраненной конфигурации.
|
||||
auth-try-auth-profile = Попытка аутентификации с использованием профиля
|
||||
|
||||
config-export-logs = Экспортировать логи
|
||||
config-open-data = Открыть путь данных
|
||||
config-reset = Сбросить к значениям по умолчанию
|
||||
config-save = Сохранить изменения
|
||||
config-remove-content-all = Удалить весь контент
|
||||
|
||||
filter-roleplay = Ролевая игра
|
||||
filter-language = Язык
|
||||
favorite-add = Добавить в избранное
|
||||
popup-add-favorite-invalid-ip = Пожалуйста, введите валидный адрес
|
||||
servername-set = Установить имя сервера
|
||||
servername-clear = Очистить
|
||||
twofa-enabled = У вас включена двухфакторная аутентификация. Введите код.
|
||||
twofa-set = Продолжить
|
||||
|
||||
@@ -54,4 +61,12 @@ serverentry-map = Карта
|
||||
serverentry-preset = Режим
|
||||
|
||||
content-view-server = Сервер
|
||||
content-view-path = Путь
|
||||
content-view-path = Путь
|
||||
|
||||
popup-login-credentials-warning = Предупреждение! Учетные данные не указаны!
|
||||
popup-login-credentials-warning-label = Предупреждение! Учетные данные не указаны! Серверы не смогут пропустить вас из-за отсутствия авторизации. Пожалуйста, имейте это в виду.
|
||||
popup-login-credentials-warning-go-auth = Перейти на страницу авторизации
|
||||
popup-login-credentials-warning-cancel = Отмена
|
||||
popup-login-credentials-warning-proceed = Продолжить
|
||||
|
||||
goto-path-home = Корн. папка
|
||||
20
Nebula.Launcher/ColorUtils.cs
Normal file
20
Nebula.Launcher/ColorUtils.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using Avalonia.Media;
|
||||
|
||||
namespace Nebula.Launcher.ViewModels.Pages;
|
||||
|
||||
public static class ColorUtils
|
||||
{
|
||||
public static Color GetColorFromString(string input)
|
||||
{
|
||||
var hash = MD5.HashData(Encoding.UTF8.GetBytes(input));
|
||||
|
||||
var r = byte.Clamp(hash[0], 10, 200);
|
||||
var g = byte.Clamp(hash[1], 10, 100);
|
||||
var b = byte.Clamp(hash[2], 10, 100);
|
||||
|
||||
return Color.FromArgb(Byte.MaxValue, r, g, b);
|
||||
}
|
||||
}
|
||||
99
Nebula.Launcher/Configurations/ArrayUnitConfigControl.cs
Normal file
99
Nebula.Launcher/Configurations/ArrayUnitConfigControl.cs
Normal file
@@ -0,0 +1,99 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Layout;
|
||||
|
||||
namespace Nebula.Launcher.ViewModels.Pages;
|
||||
|
||||
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 = new Label()
|
||||
{
|
||||
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 ArrayUnitConfigControl(string name, object value)
|
||||
{
|
||||
Classes.Add("ConfigBorder");
|
||||
_elementType = value.GetType().GetElementType()!;
|
||||
|
||||
ConfigName = name;
|
||||
_panel.Orientation = Orientation.Vertical;
|
||||
_panel.Spacing = 4f;
|
||||
_itemsPanel.Spacing = 4f;
|
||||
|
||||
_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;
|
||||
}
|
||||
|
||||
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 = new Label(){ 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);
|
||||
|
||||
_itemsPanel.Children.Add(itemPanel);
|
||||
_itemControls.Add(control);
|
||||
}
|
||||
|
||||
public void SetValue(object value)
|
||||
{
|
||||
_itemControls.Clear();
|
||||
_itemsPanel.Children.Clear();
|
||||
|
||||
if (value is IEnumerable list)
|
||||
{
|
||||
foreach (var item in list)
|
||||
{
|
||||
AddItem(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public object GetValue()
|
||||
{
|
||||
return ConvertArray(_itemControls.Select(c => c.GetValue()).ToArray(), _elementType);
|
||||
}
|
||||
|
||||
public static Array ConvertArray(Array sourceArray, Type targetType)
|
||||
{
|
||||
int length = sourceArray.Length;
|
||||
var newArray = Array.CreateInstance(targetType, length);
|
||||
|
||||
for (int i = 0; i < length; i++)
|
||||
{
|
||||
var value = sourceArray.GetValue(i);
|
||||
var converted = Convert.ChangeType(value, targetType);
|
||||
newArray.SetValue(converted, i);
|
||||
}
|
||||
|
||||
return newArray;
|
||||
}
|
||||
}
|
||||
86
Nebula.Launcher/Configurations/ComplexConVarBinder.cs
Normal file
86
Nebula.Launcher/Configurations/ComplexConVarBinder.cs
Normal file
@@ -0,0 +1,86 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Nebula.Shared.Configurations;
|
||||
|
||||
namespace Nebula.Launcher.Configurations;
|
||||
|
||||
public abstract class ComplexConVarBinder<T> : INotifyPropertyChanged, INotifyPropertyChanging
|
||||
{
|
||||
private readonly ConVarObserver<T> _baseConVar;
|
||||
private readonly Lock _lock = new();
|
||||
private readonly SemaphoreSlim _valueChangeSemaphore = new(1, 1);
|
||||
|
||||
public T? Value
|
||||
{
|
||||
get
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
return _baseConVar.Value;
|
||||
}
|
||||
}
|
||||
set
|
||||
{
|
||||
_ = SetValueAsync(value);
|
||||
}
|
||||
}
|
||||
|
||||
public bool HasValue
|
||||
{
|
||||
get
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
return _baseConVar.HasValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected ComplexConVarBinder(ConVarObserver<T> baseConVar)
|
||||
{
|
||||
_baseConVar = baseConVar ?? throw new ArgumentNullException(nameof(baseConVar));
|
||||
_baseConVar.PropertyChanged += BaseConVarOnPropertyChanged;
|
||||
_baseConVar.PropertyChanging += BaseConVarOnPropertyChanging;
|
||||
}
|
||||
|
||||
|
||||
private async Task SetValueAsync(T? value)
|
||||
{
|
||||
await _valueChangeSemaphore.WaitAsync().ConfigureAwait(false);
|
||||
|
||||
try
|
||||
{
|
||||
var newValue = await OnValueChange(value).ConfigureAwait(false);
|
||||
|
||||
lock (_lock)
|
||||
{
|
||||
_baseConVar.Value = newValue;
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
_valueChangeSemaphore.Release();
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract Task<T?> OnValueChange(T? newValue);
|
||||
|
||||
private void BaseConVarOnPropertyChanged(object? sender, PropertyChangedEventArgs e)
|
||||
{
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(HasValue)));
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Value)));
|
||||
}
|
||||
|
||||
private void BaseConVarOnPropertyChanging(object? sender, PropertyChangingEventArgs e)
|
||||
{
|
||||
PropertyChanging?.Invoke(this, new PropertyChangingEventArgs(nameof(HasValue)));
|
||||
PropertyChanging?.Invoke(this, new PropertyChangingEventArgs(nameof(Value)));
|
||||
}
|
||||
|
||||
|
||||
public event PropertyChangedEventHandler? PropertyChanged;
|
||||
|
||||
public event PropertyChangingEventHandler? PropertyChanging;
|
||||
}
|
||||
68
Nebula.Launcher/Configurations/ComplexUnitConfigControl.cs
Normal file
68
Nebula.Launcher/Configurations/ComplexUnitConfigControl.cs
Normal file
@@ -0,0 +1,68 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Layout;
|
||||
|
||||
namespace Nebula.Launcher.ViewModels.Pages;
|
||||
|
||||
public sealed class ComplexUnitConfigControl : Border, IConfigControl
|
||||
{
|
||||
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)
|
||||
{
|
||||
Classes.Add("ConfigBorder");
|
||||
_panel.Orientation = Orientation.Vertical;
|
||||
_panel.Spacing = 4f;
|
||||
ConfigName = name;
|
||||
Child = _panel;
|
||||
SetValue(obj);
|
||||
}
|
||||
|
||||
public void SetValue(object value)
|
||||
{
|
||||
_units.Clear();
|
||||
_panel.Children.Clear();
|
||||
_objectType = value.GetType();
|
||||
|
||||
_panel.Children.Add(new Label()
|
||||
{
|
||||
Content = ConfigName
|
||||
});
|
||||
|
||||
foreach (var propInfo in _objectType.GetProperties())
|
||||
{
|
||||
if(propInfo.PropertyType.IsInterface)
|
||||
continue;
|
||||
|
||||
var propValue = propInfo.GetValue(value);
|
||||
|
||||
var control = ConfigControlHelper.GetConfigControl(propInfo.Name, propValue!);
|
||||
|
||||
((Control)control).Margin = new Thickness(5);
|
||||
_panel.Children.Add((Control)control);
|
||||
_units.Add((propInfo,control));
|
||||
}
|
||||
}
|
||||
|
||||
public object GetValue()
|
||||
{
|
||||
var obj = ConfigControlHelper.CreateDefaultValue(_objectType);
|
||||
foreach (var (fieldInfo, configControl) in _units)
|
||||
{
|
||||
fieldInfo.SetValue(obj, configControl.GetValue());
|
||||
}
|
||||
|
||||
return obj!;
|
||||
}
|
||||
}
|
||||
39
Nebula.Launcher/Configurations/ConfigControlHelper.cs
Normal file
39
Nebula.Launcher/Configurations/ConfigControlHelper.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace Nebula.Launcher.ViewModels.Pages;
|
||||
|
||||
public static class ConfigControlHelper{
|
||||
public static IConfigControl GetConfigControl(string name,object value)
|
||||
{
|
||||
switch (value)
|
||||
{
|
||||
case string stringValue:
|
||||
return new StringUnitConfigControl(name, stringValue);
|
||||
case int intValue:
|
||||
return new IntUnitConfigControl(name, intValue);
|
||||
case float floatValue:
|
||||
return new FloatUnitConfigControl(name, floatValue);
|
||||
}
|
||||
|
||||
var valueType = value.GetType();
|
||||
|
||||
if (valueType.IsArray)
|
||||
return new ArrayUnitConfigControl(name, value);
|
||||
|
||||
return new ComplexUnitConfigControl(name, value);
|
||||
}
|
||||
|
||||
public static object? CreateDefaultValue(Type type)
|
||||
{
|
||||
if(type.IsValueType)
|
||||
return Activator.CreateInstance(type);
|
||||
|
||||
var ctor = type.GetConstructors().First();
|
||||
var parameters = ctor.GetParameters()
|
||||
.Select(p => CreateDefaultValue(p.ParameterType))
|
||||
.ToArray();
|
||||
|
||||
return ctor.Invoke(parameters);
|
||||
}
|
||||
}
|
||||
19
Nebula.Launcher/Configurations/FloatUnitConfigControl.cs
Normal file
19
Nebula.Launcher/Configurations/FloatUnitConfigControl.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using System.Globalization;
|
||||
|
||||
namespace Nebula.Launcher.ViewModels.Pages;
|
||||
|
||||
public sealed class FloatUnitConfigControl(string name, float value) : UnitConfigControl<float>(name, value)
|
||||
{
|
||||
|
||||
public CultureInfo CultureInfo = CultureInfo.InvariantCulture;
|
||||
|
||||
public override void SetConfValue(float value)
|
||||
{
|
||||
ConfigValue = value.ToString(CultureInfo);
|
||||
}
|
||||
|
||||
public override float GetConfValue()
|
||||
{
|
||||
return float.Parse(ConfigValue, CultureInfo);
|
||||
}
|
||||
}
|
||||
9
Nebula.Launcher/Configurations/IConfigControl.cs
Normal file
9
Nebula.Launcher/Configurations/IConfigControl.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
namespace Nebula.Launcher.ViewModels.Pages;
|
||||
|
||||
public interface IConfigControl
|
||||
{
|
||||
public string ConfigName { get; }
|
||||
public bool Dirty {get;}
|
||||
public abstract void SetValue(object value);
|
||||
public abstract object GetValue();
|
||||
}
|
||||
14
Nebula.Launcher/Configurations/IntUnitConfigControl.cs
Normal file
14
Nebula.Launcher/Configurations/IntUnitConfigControl.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
namespace Nebula.Launcher.ViewModels.Pages;
|
||||
|
||||
public sealed class IntUnitConfigControl(string name, int value) : UnitConfigControl<int>(name, value)
|
||||
{
|
||||
public override void SetConfValue(int value)
|
||||
{
|
||||
ConfigValue = value.ToString();
|
||||
}
|
||||
|
||||
public override int GetConfValue()
|
||||
{
|
||||
return int.Parse(ConfigValue);
|
||||
}
|
||||
}
|
||||
14
Nebula.Launcher/Configurations/StringUnitConfigControl.cs
Normal file
14
Nebula.Launcher/Configurations/StringUnitConfigControl.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
namespace Nebula.Launcher.ViewModels.Pages;
|
||||
|
||||
public sealed class StringUnitConfigControl(string name, string value) : UnitConfigControl<string>(name, value)
|
||||
{
|
||||
public override void SetConfValue(string value)
|
||||
{
|
||||
ConfigValue = value;
|
||||
}
|
||||
|
||||
public override string GetConfValue()
|
||||
{
|
||||
return ConfigValue;
|
||||
}
|
||||
}
|
||||
53
Nebula.Launcher/Configurations/UnitConfigControl.cs
Normal file
53
Nebula.Launcher/Configurations/UnitConfigControl.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Layout;
|
||||
|
||||
namespace Nebula.Launcher.ViewModels.Pages;
|
||||
|
||||
public abstract class UnitConfigControl<T> : Border, IConfigControl where T : notnull
|
||||
{
|
||||
private readonly Label _nameLabel = new();
|
||||
private readonly TextBox _valueLabel = new();
|
||||
private string _originalValue;
|
||||
|
||||
private StackPanel _panel = new();
|
||||
|
||||
public string ConfigName { get; }
|
||||
|
||||
public bool Dirty => _originalValue != ConfigValue;
|
||||
|
||||
protected string ConfigValue
|
||||
{
|
||||
get => _valueLabel.Text ?? string.Empty;
|
||||
set => _valueLabel.Text = value;
|
||||
}
|
||||
|
||||
public UnitConfigControl(string name, T value)
|
||||
{
|
||||
Classes.Add("ConfigBorder");
|
||||
ConfigName = name;
|
||||
_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;
|
||||
}
|
||||
|
||||
public abstract void SetConfValue(T value);
|
||||
|
||||
public abstract T GetConfValue();
|
||||
|
||||
public void SetValue(object value)
|
||||
{
|
||||
SetConfValue((T)value);
|
||||
}
|
||||
|
||||
public object GetValue()
|
||||
{
|
||||
return GetConfValue()!;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using Avalonia.Controls;
|
||||
using Nebula.Launcher.Models;
|
||||
using Nebula.Launcher.ServerListProviders;
|
||||
using Nebula.Launcher.ViewModels;
|
||||
using Nebula.Launcher.ViewModels.Pages;
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using System;
|
||||
using Avalonia.Data.Converters;
|
||||
using Avalonia.Media;
|
||||
using Avalonia.Platform;
|
||||
using Nebula.Launcher.ViewModels.Pages;
|
||||
using Color = System.Drawing.Color;
|
||||
|
||||
namespace Nebula.Launcher.Converters;
|
||||
|
||||
public class TypeConverters
|
||||
public static class TypeConverters
|
||||
{
|
||||
public static FuncValueConverter<string, string?> IconConverter { get; } =
|
||||
new(iconKey =>
|
||||
@@ -13,4 +15,17 @@ public class TypeConverters
|
||||
if (iconKey == null) return null;
|
||||
return $"/Assets/svg/{iconKey}.svg";
|
||||
});
|
||||
|
||||
public static FuncValueConverter<string, IImage?> ImageConverter { get; } =
|
||||
new(iconKey =>
|
||||
{
|
||||
if (iconKey == null) return null;
|
||||
return new Avalonia.Media.Imaging.Bitmap(AssetLoader.Open(new Uri($"avares://Nebula.Launcher/Assets/error_presentation/{iconKey}.png")));
|
||||
});
|
||||
|
||||
public static FuncValueConverter<string, Avalonia.Media.Color> NameColorRepresentation { get; } =
|
||||
new((str)=>ColorUtils.GetColorFromString(str ?? throw new ArgumentNullException(nameof(str),"Name of color is null!")));
|
||||
|
||||
public static FuncValueConverter<string, bool> StringIsNotEmpty { get; } =
|
||||
new(iconKey => !string.IsNullOrEmpty(iconKey));
|
||||
}
|
||||
@@ -1,2 +1 @@
|
||||
global using Nebula.Shared.Attributes;
|
||||
global using Nebula.Launcher.ViewHelper;
|
||||
global using Nebula.Shared.Attributes;
|
||||
@@ -1,7 +1,10 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using Nebula.Launcher.Models;
|
||||
using Nebula.Launcher.ViewModels.Pages;
|
||||
using Nebula.Launcher.Models.Auth;
|
||||
using Nebula.Shared.ConfigMigrations;
|
||||
using Nebula.Shared.Configurations;
|
||||
using Nebula.Shared.Configurations.Migrations;
|
||||
using Nebula.Shared.Services;
|
||||
|
||||
namespace Nebula.Launcher;
|
||||
@@ -10,11 +13,17 @@ public static class LauncherConVar
|
||||
{
|
||||
public static readonly ConVar<bool> DoMigration =
|
||||
ConVarBuilder.Build("migration.doMigrate", true);
|
||||
public static readonly ConVar<ProfileAuthCredentials[]> AuthProfiles =
|
||||
ConVarBuilder.Build<ProfileAuthCredentials[]>("auth.profiles.v2", []);
|
||||
|
||||
public static readonly ConVar<string[]> AuthProfiles =
|
||||
ConVarBuilder.BuildWithMigration<string[]>("auth.profiles.v4",
|
||||
MigrationQueueBuilder.Instance
|
||||
.With(new ProfileMigrationV2("auth.profiles.v2","auth.profiles.v4"))
|
||||
.With(new ProfileMigrationV3V4("auth.profiles.v3","auth.profiles.v4"))
|
||||
.Build(),
|
||||
[]);
|
||||
|
||||
public static readonly ConVar<CurrentAuthInfo?> AuthCurrent =
|
||||
ConVarBuilder.Build<CurrentAuthInfo?>("auth.current.v2");
|
||||
public static readonly ConVar<AuthTokenCredentials?> AuthCurrent =
|
||||
ConVarBuilder.Build<AuthTokenCredentials?>("auth.current.v2");
|
||||
|
||||
public static readonly ConVar<string[]> Favorites =
|
||||
ConVarBuilder.Build<string[]>("server.favorites", []);
|
||||
@@ -28,18 +37,22 @@ public static class LauncherConVar
|
||||
"WizDen",
|
||||
[
|
||||
"https://harpy.durenko.tatar/auth-api/",
|
||||
"https://auth.spacestation14.com/",
|
||||
"https://auth.fallback.spacestation14.com/",
|
||||
]),
|
||||
new AuthServerCredentials(
|
||||
"SimpleStation",
|
||||
[
|
||||
"https://auth.simplestation.org/",
|
||||
])
|
||||
]);
|
||||
|
||||
public static readonly ConVar<ServerHubRecord[]> Hub = ConVarBuilder.Build<ServerHubRecord[]>("launcher.hub.v2", [
|
||||
new ServerHubRecord("WizDen", "https://harpy.durenko.tatar/hub-api/api/servers"),
|
||||
new ServerHubRecord("AltHub","https://web.networkgamez.com/api/servers")
|
||||
new ServerHubRecord("AltHub","https://hub.singularity14.co.uk/api/servers")
|
||||
]);
|
||||
|
||||
public static readonly ConVar<string> CurrentLang = ConVarBuilder.Build<string>("launcher.language", CultureInfo.CurrentCulture.Name);
|
||||
public static readonly ConVar<string> ILSpyUrl = ConVarBuilder.Build<string>("decompiler.url",
|
||||
"https://github.com/icsharpcode/ILSpy/releases/download/v9.0/ILSpy_binaries_9.0.0.7889-x64.zip");
|
||||
|
||||
|
||||
}
|
||||
@@ -2,16 +2,9 @@
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:views="clr-namespace:Nebula.Launcher.Views"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
Width="600"
|
||||
Height="400"
|
||||
|
||||
x:Class="Nebula.Launcher.MessageBox.MessageView">
|
||||
<Grid RowDefinitions="50,*" ColumnDefinitions="*">
|
||||
<Border Grid.Column="0" Background="#222222" Padding="10" BorderBrush="#444444" BorderThickness="0,0,0,3">
|
||||
<Label VerticalAlignment="Center" x:Name="Title">Text</Label>
|
||||
</Border>
|
||||
<Panel Margin="5" Grid.Row="1">
|
||||
<Label x:Name="Message">Message</Label>
|
||||
</Panel>
|
||||
</Grid>
|
||||
<views:VisualErrorView x:Name="ErrorView"/>
|
||||
</UserControl>
|
||||
|
||||
@@ -1,21 +1,22 @@
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Markup.Xaml;
|
||||
using Nebula.Launcher.ViewModels;
|
||||
|
||||
namespace Nebula.Launcher.MessageBox;
|
||||
|
||||
public partial class MessageView : UserControl, IMessageContainerProvider
|
||||
{
|
||||
public MessageView(out IMessageContainerProvider provider)
|
||||
private readonly VisualErrorViewModel _context;
|
||||
public MessageView()
|
||||
{
|
||||
InitializeComponent();
|
||||
provider = this;
|
||||
_context = new VisualErrorViewModel();
|
||||
ErrorView.Content = _context;
|
||||
}
|
||||
|
||||
public void ShowMessage(string message, string title)
|
||||
{
|
||||
Title.Content = title;
|
||||
Message.Content = message;
|
||||
_context.Title = title;
|
||||
_context.Description = message;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,10 +3,52 @@
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:messageBox="clr-namespace:Nebula.Launcher.MessageBox"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
SystemDecorations="BorderOnly"
|
||||
mc:Ignorable="d" d:DesignWidth="600" d:DesignHeight="260"
|
||||
Width="600"
|
||||
Height="400"
|
||||
Height="260"
|
||||
CanResize="False"
|
||||
x:Class="Nebula.Launcher.MessageBox.MessageWindow"
|
||||
Title="MessageWindow">
|
||||
|
||||
<Grid ColumnDefinitions="*" RowDefinitions="30,*">
|
||||
<messageBox:MessageView
|
||||
Grid.Column="0"
|
||||
Grid.Row="0"
|
||||
Grid.RowSpan="2"
|
||||
x:Name="MessageView" />
|
||||
<Border
|
||||
|
||||
BorderThickness="0,0,0,2"
|
||||
CornerRadius="0"
|
||||
Grid.Column="0"
|
||||
Grid.Row="0">
|
||||
<Border.BorderBrush>
|
||||
<LinearGradientBrush EndPoint="100%,50%" StartPoint="0%,50%">
|
||||
<GradientStop Color="#222222" Offset="0.0" />
|
||||
<GradientStop Color="#442222" Offset="1.0" />
|
||||
</LinearGradientBrush>
|
||||
</Border.BorderBrush>
|
||||
<Panel
|
||||
Height="30"
|
||||
PointerPressed="InputElement_OnPointerPressed">
|
||||
<TextBlock
|
||||
FontSize="10"
|
||||
Foreground="White"
|
||||
IsVisible="False"
|
||||
Margin="15,0"
|
||||
Text="Nebula Launcher"
|
||||
VerticalAlignment="Center" />
|
||||
<StackPanel
|
||||
HorizontalAlignment="Right"
|
||||
Margin="5,0,5,0"
|
||||
Orientation="Horizontal"
|
||||
Spacing="8">
|
||||
<Button
|
||||
Click="Close_Click"
|
||||
Content="🗙"
|
||||
Foreground="Azure" />
|
||||
</StackPanel>
|
||||
</Panel>
|
||||
</Border>
|
||||
</Grid>
|
||||
</Window>
|
||||
|
||||
@@ -1,12 +1,28 @@
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Input;
|
||||
using Avalonia.Interactivity;
|
||||
|
||||
namespace Nebula.Launcher.MessageBox;
|
||||
|
||||
public partial class MessageWindow : Window
|
||||
public partial class MessageWindow : Window, IMessageContainerProvider
|
||||
{
|
||||
public MessageWindow(out IMessageContainerProvider provider)
|
||||
public MessageWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
Content = new MessageView(out provider);
|
||||
}
|
||||
|
||||
public void ShowMessage(string message, string title)
|
||||
{
|
||||
MessageView.ShowMessage(message, title);
|
||||
}
|
||||
|
||||
private void Close_Click(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
Close();
|
||||
}
|
||||
|
||||
private void InputElement_OnPointerPressed(object? sender, PointerPressedEventArgs e)
|
||||
{
|
||||
BeginMoveDrag(e);
|
||||
}
|
||||
}
|
||||
6
Nebula.Launcher/Models/Auth/AuthServerCredentials.cs
Normal file
6
Nebula.Launcher/Models/Auth/AuthServerCredentials.cs
Normal file
@@ -0,0 +1,6 @@
|
||||
namespace Nebula.Launcher.Models.Auth;
|
||||
|
||||
public sealed record AuthServerCredentials(
|
||||
string Name,
|
||||
string[] Servers
|
||||
);
|
||||
12
Nebula.Launcher/Models/Auth/ProfileAuthCredentials.cs
Normal file
12
Nebula.Launcher/Models/Auth/ProfileAuthCredentials.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Windows.Input;
|
||||
using Avalonia.Media;
|
||||
using Nebula.Shared.Services;
|
||||
|
||||
namespace Nebula.Launcher.Models.Auth;
|
||||
|
||||
public sealed record ProfileEntry(
|
||||
ProfileAuthCredentials Credentials,
|
||||
string AuthName,
|
||||
[property: JsonIgnore] ICommand OnSelect = default!,
|
||||
[property: JsonIgnore] ICommand OnDelete = default!);
|
||||
32
Nebula.Launcher/Models/ContentLogConsumer.cs
Normal file
32
Nebula.Launcher/Models/ContentLogConsumer.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using Nebula.Launcher.ProcessHelper;
|
||||
using Nebula.Launcher.ViewModels.Popup;
|
||||
using Nebula.Shared.Services;
|
||||
|
||||
namespace Nebula.Launcher.Models;
|
||||
|
||||
public sealed class ContentLogConsumer : IProcessLogConsumer
|
||||
{
|
||||
private readonly LogPopupModelView _currLog;
|
||||
private readonly PopupMessageService _popupMessageService;
|
||||
|
||||
public ContentLogConsumer(LogPopupModelView currLog, PopupMessageService popupMessageService)
|
||||
{
|
||||
_currLog = currLog;
|
||||
_popupMessageService = popupMessageService;
|
||||
}
|
||||
|
||||
public void Out(string text)
|
||||
{
|
||||
_currLog.Append(text);
|
||||
}
|
||||
|
||||
public void Error(string text)
|
||||
{
|
||||
_currLog.Append(text);
|
||||
}
|
||||
|
||||
public void Fatal(string text)
|
||||
{
|
||||
_popupMessageService.Popup("Fatal error while stop instance:" + text);
|
||||
}
|
||||
}
|
||||
8
Nebula.Launcher/Models/IFilterConsumer.cs
Normal file
8
Nebula.Launcher/Models/IFilterConsumer.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
using Nebula.Launcher.ViewModels.Pages;
|
||||
|
||||
namespace Nebula.Launcher.Models;
|
||||
|
||||
public interface IFilterConsumer
|
||||
{
|
||||
public void ProcessFilter(ServerFilter? serverFilter);
|
||||
}
|
||||
40
Nebula.Launcher/Models/LogInfo.cs
Normal file
40
Nebula.Launcher/Models/LogInfo.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using System.Text.RegularExpressions;
|
||||
using Avalonia.Media;
|
||||
|
||||
namespace Nebula.Launcher.Models;
|
||||
|
||||
public sealed class LogInfo
|
||||
{
|
||||
public string Category { get; set; } = "LOG";
|
||||
public IBrush CategoryColor { get; set; } = Brush.Parse("#424242");
|
||||
public string Message { get; set; } = "";
|
||||
|
||||
public static LogInfo FromString(string input)
|
||||
{
|
||||
var matches = Regex.Matches(input, @"(\[(?<c>.*)\] (?<m>.*))|(?<m>.*)");
|
||||
var category = "All";
|
||||
|
||||
if (matches[0].Groups.TryGetValue("c", out var c)) category = c.Value;
|
||||
|
||||
var color = Brush.Parse("#444444");
|
||||
|
||||
switch (category)
|
||||
{
|
||||
case "DEBG":
|
||||
color = Brush.Parse("#2436d4");
|
||||
break;
|
||||
case "ERRO":
|
||||
color = Brush.Parse("#d42436");
|
||||
break;
|
||||
case "INFO":
|
||||
color = Brush.Parse("#0ab3c9");
|
||||
break;
|
||||
}
|
||||
|
||||
var message = matches[0].Groups["m"].Value;
|
||||
return new LogInfo
|
||||
{
|
||||
Category = category, Message = message, CategoryColor = color
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -31,7 +31,7 @@
|
||||
<PackageReference Include="JetBrains.Annotations" Version="2024.3.0"/>
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.0"/>
|
||||
<PackageReference Include="libsodium" Version="1.0.20"/>
|
||||
<PackageReference Include="Robust.Natives" Version="0.1.1" />
|
||||
<PackageReference Include="Robust.Natives" Version="0.2.3" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
@@ -54,6 +54,8 @@
|
||||
<Copy SourceFiles="..\Nebula.Runner\bin\$(Configuration)\$(TargetFramework)\Nebula.Runner.pdb" DestinationFolder="$(OutDir)"/>
|
||||
<Copy SourceFiles="..\Nebula.Runner\bin\$(Configuration)\$(TargetFramework)\Nebula.Runner.deps.json" DestinationFolder="$(OutDir)"/>
|
||||
<Copy SourceFiles="..\Nebula.Runner\bin\$(Configuration)\$(TargetFramework)\Nebula.Runner.runtimeconfig.json" DestinationFolder="$(OutDir)"/>
|
||||
|
||||
<Copy SourceFiles="..\Nebula.Runner\bin\$(Configuration)\$(TargetFramework)\0Harmony.dll" DestinationFolder="$(OutDir)"/>
|
||||
</Target>
|
||||
|
||||
<Target Name="PublishCheck" AfterTargets="Publish">
|
||||
@@ -61,6 +63,8 @@
|
||||
<Copy SourceFiles="..\Nebula.Runner\bin\$(Configuration)\$(TargetFramework)\Nebula.Runner.pdb" DestinationFolder="$(PublishDir)"/>
|
||||
<Copy SourceFiles="..\Nebula.Runner\bin\$(Configuration)\$(TargetFramework)\Nebula.Runner.deps.json" DestinationFolder="$(PublishDir)"/>
|
||||
<Copy SourceFiles="..\Nebula.Runner\bin\$(Configuration)\$(TargetFramework)\Nebula.Runner.runtimeconfig.json" DestinationFolder="$(PublishDir)"/>
|
||||
|
||||
<Copy SourceFiles="..\Nebula.Runner\bin\$(Configuration)\$(TargetFramework)\0Harmony.dll" DestinationFolder="$(PublishDir)"/>
|
||||
</Target>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Threading.Tasks;
|
||||
using Nebula.Launcher.ViewModels.Pages;
|
||||
using Nebula.Shared;
|
||||
using Nebula.Shared.Models;
|
||||
using Nebula.Shared.Services;
|
||||
@@ -10,7 +11,7 @@ using Nebula.Shared.Services;
|
||||
namespace Nebula.Launcher.ProcessHelper;
|
||||
|
||||
[ServiceRegister(isSingleton:false)]
|
||||
public sealed class GameProcessStartInfoProvider(DotnetResolverService resolverService, AuthService authService) :
|
||||
public sealed class GameProcessStartInfoProvider(DotnetResolverService resolverService, AccountInfoViewModel accountInfoViewModel) :
|
||||
DotnetProcessStartInfoProviderBase(resolverService)
|
||||
{
|
||||
private string? _publicKey;
|
||||
@@ -34,7 +35,7 @@ public sealed class GameProcessStartInfoProvider(DotnetResolverService resolverS
|
||||
{
|
||||
var baseStart = await base.GetProcessStartInfo();
|
||||
|
||||
var authProv = authService.SelectedAuth;
|
||||
var authProv = accountInfoViewModel.Credentials.Value;
|
||||
if(authProv is null)
|
||||
throw new Exception("Client is without selected auth");
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ using Nebula.Shared.Services;
|
||||
namespace Nebula.Launcher.ProcessHelper;
|
||||
|
||||
[ServiceRegister]
|
||||
public sealed class GameRunnerPreparer(IServiceProvider provider, ContentService contentService, EngineService engineService, DebugService debugService)
|
||||
public sealed class GameRunnerPreparer(IServiceProvider provider, ContentService contentService, EngineService engineService)
|
||||
{
|
||||
public async Task<ProcessRunHandler<GameProcessStartInfoProvider>> GetGameProcessStartInfoProvider(RobustUrl address, ILoadingHandler loadingHandler, CancellationToken cancellationToken = default)
|
||||
{
|
||||
|
||||
@@ -74,6 +74,7 @@ public sealed partial class HubServerListProvider : IServerListProvider
|
||||
catch (Exception e)
|
||||
{
|
||||
_errors.Add(new Exception($"Some error while loading server list from {HubUrl}. See inner exception", e));
|
||||
_errors.Add(e);
|
||||
}
|
||||
|
||||
IsLoaded = true;
|
||||
|
||||
@@ -7,6 +7,7 @@ using Avalonia.Controls.ApplicationLifetimes;
|
||||
using Avalonia.Threading;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Nebula.Launcher.Views;
|
||||
using Nebula.Shared.ViewHelper;
|
||||
|
||||
namespace Nebula.Launcher;
|
||||
|
||||
|
||||
@@ -14,7 +14,8 @@ namespace Nebula.Launcher.Services;
|
||||
public partial class LocalisationService
|
||||
{
|
||||
[GenerateProperty] private ConfigurationService ConfigurationService { get; }
|
||||
|
||||
[GenerateProperty] private DebugService DebugService { get; }
|
||||
|
||||
private CultureInfo _currentCultureInfo = CultureInfo.CurrentCulture;
|
||||
private static MessageContext? _currentMessageContext;
|
||||
|
||||
@@ -42,6 +43,7 @@ public partial class LocalisationService
|
||||
|
||||
_currentMessageContext = mc;
|
||||
} catch (Exception e) {
|
||||
DebugService.GetLogger("localisationService").Error(e);
|
||||
LoadLanguage(CultureInfo.GetCultureInfo("en-US"));
|
||||
}
|
||||
}
|
||||
@@ -51,28 +53,27 @@ public partial class LocalisationService
|
||||
Initialise();
|
||||
}
|
||||
|
||||
public static string GetString(string locale)
|
||||
public static string GetString(string locale, Dictionary<string, object>? options = null)
|
||||
{
|
||||
if (_currentMessageContext is null)
|
||||
{
|
||||
Console.WriteLine("ERROR SHIT BITHC!");
|
||||
return locale;
|
||||
}
|
||||
var message = _currentMessageContext.GetMessage(locale);
|
||||
if (message == null) return locale;
|
||||
return _currentMessageContext.Format(message, new Dictionary<string, object>());
|
||||
return _currentMessageContext.Format(message, options ?? []);
|
||||
}
|
||||
}
|
||||
|
||||
public class LocaledText : MarkupExtension
|
||||
{
|
||||
public string Key { get; set; }
|
||||
public Dictionary<string, object>? Options { get; set; }
|
||||
|
||||
public LocaledText(string key) => Key = key;
|
||||
|
||||
public override object ProvideValue(IServiceProvider serviceProvider)
|
||||
{
|
||||
// Fetch the localized string using the key
|
||||
return LocalisationService.GetString(Key);
|
||||
return LocalisationService.GetString(Key, Options);
|
||||
}
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
using System;
|
||||
|
||||
namespace Nebula.Launcher.ViewHelper;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Class)]
|
||||
public class ViewModelRegisterAttribute : Attribute
|
||||
{
|
||||
public ViewModelRegisterAttribute(Type? type = null, bool isSingleton = true)
|
||||
{
|
||||
Type = type;
|
||||
IsSingleton = isSingleton;
|
||||
}
|
||||
|
||||
public Type? Type { get; }
|
||||
public bool IsSingleton { get; }
|
||||
}
|
||||
@@ -4,6 +4,7 @@ using Avalonia.Controls;
|
||||
using Avalonia.Controls.Templates;
|
||||
using Nebula.Launcher.ViewModels;
|
||||
using Nebula.Launcher.Views;
|
||||
using Nebula.Shared.ViewHelper;
|
||||
|
||||
namespace Nebula.Launcher;
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Avalonia.Logging;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using Nebula.Launcher.Models;
|
||||
@@ -10,10 +11,10 @@ using Nebula.Launcher.Services;
|
||||
using Nebula.Launcher.ViewModels.Pages;
|
||||
using Nebula.Launcher.ViewModels.Popup;
|
||||
using Nebula.Launcher.Views;
|
||||
using Nebula.Shared.Models;
|
||||
using Nebula.Shared.Services;
|
||||
using Nebula.Shared.Services.Logging;
|
||||
using Nebula.Shared.Utils;
|
||||
using Nebula.Shared.ViewHelper;
|
||||
|
||||
namespace Nebula.Launcher.ViewModels;
|
||||
|
||||
@@ -40,8 +41,10 @@ public partial class MainViewModel : ViewModelBase
|
||||
[ObservableProperty] private bool _isPopupClosable = true;
|
||||
[ObservableProperty] private bool _popup;
|
||||
[ObservableProperty] private ListItemTemplate? _selectedListItem;
|
||||
|
||||
[GenerateProperty] private LocalisationService LocalisationService { get; }
|
||||
[ObservableProperty] private string? _loginText = LocalisationService.GetString("auth-current-login-no-name");
|
||||
|
||||
[GenerateProperty] private LocalisationService LocalisationService { get; } // Не убирать! Без этой хуйни вся локализация идет в пизду!
|
||||
[GenerateProperty] private AccountInfoViewModel AccountInfoViewModel { get; }
|
||||
[GenerateProperty] private DebugService DebugService { get; } = default!;
|
||||
[GenerateProperty] private PopupMessageService PopupMessageService { get; } = default!;
|
||||
[GenerateProperty] private ContentService ContentService { get; } = default!;
|
||||
@@ -56,7 +59,7 @@ public partial class MainViewModel : ViewModelBase
|
||||
{
|
||||
Items = new ObservableCollection<ListItemTemplate>(_templates.Select(a=>
|
||||
{
|
||||
return new ListItemTemplate(a.ModelType, a.IconKey, LocalisationService.GetString(a.Label));
|
||||
return a with { Label = LocalisationService.GetString(a.Label) };
|
||||
}
|
||||
));
|
||||
RequirePage<AccountInfoViewModel>();
|
||||
@@ -64,6 +67,15 @@ public partial class MainViewModel : ViewModelBase
|
||||
|
||||
protected override void Initialise()
|
||||
{
|
||||
AccountInfoViewModel.Credentials.PropertyChanged += (_, args) =>
|
||||
{
|
||||
if (args.PropertyName is not nameof(AccountInfoViewModel.Credentials.Value))
|
||||
return;
|
||||
UpdateCredentialsInfo();
|
||||
};
|
||||
|
||||
UpdateCredentialsInfo();
|
||||
|
||||
_logger = DebugService.GetLogger(this);
|
||||
|
||||
using var stream = typeof(MainViewModel).Assembly
|
||||
@@ -79,6 +91,11 @@ public partial class MainViewModel : ViewModelBase
|
||||
|
||||
CheckMigration();
|
||||
|
||||
var loadingHandler = ViewHelperService.GetViewModel<LoadingContextViewModel>();
|
||||
loadingHandler.LoadingName = LocalisationService.GetString("migration-config-task");
|
||||
loadingHandler.IsCancellable = false;
|
||||
ConfigurationService.MigrateConfigs(loadingHandler);
|
||||
|
||||
if (!VCRuntimeDllChecker.AreVCRuntimeDllsPresent())
|
||||
{
|
||||
OnPopupRequired(LocalisationService.GetString("vcruntime-check-error"));
|
||||
@@ -86,6 +103,27 @@ public partial class MainViewModel : ViewModelBase
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateCredentialsInfo()
|
||||
{
|
||||
if(AccountInfoViewModel.Credentials.HasValue)
|
||||
{
|
||||
LoginText =
|
||||
LocalisationService.GetString("auth-current-login-name",
|
||||
new Dictionary<string, object>
|
||||
{
|
||||
{ "login", AccountInfoViewModel.Credentials.Value?.Login ?? "" },
|
||||
{
|
||||
"auth_server",
|
||||
AccountInfoViewModel.GetServerAuthName(AccountInfoViewModel.Credentials.Value?.AuthServer) ?? ""
|
||||
}
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
LoginText = LocalisationService.GetString("auth-current-login-no-name");
|
||||
}
|
||||
}
|
||||
|
||||
private void CheckMigration()
|
||||
{
|
||||
if (!ConfigurationService.GetConfigValue(LauncherConVar.DoMigration))
|
||||
@@ -163,6 +201,16 @@ public partial class MainViewModel : ViewModelBase
|
||||
Popup = true;
|
||||
}
|
||||
|
||||
public void OpenAuthPage()
|
||||
{
|
||||
RequirePage<AccountInfoViewModel>();
|
||||
}
|
||||
|
||||
public void OpenRootPath()
|
||||
{
|
||||
ExplorerHelper.OpenFolder(FileService.RootPath);
|
||||
}
|
||||
|
||||
public void OpenLink()
|
||||
{
|
||||
Helper.OpenBrowser("https://durenko.tatar/nebula");
|
||||
|
||||
@@ -3,17 +3,19 @@ using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Input;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using Nebula.Launcher.Configurations;
|
||||
using Nebula.Launcher.Models.Auth;
|
||||
using Nebula.Launcher.Services;
|
||||
using Nebula.Launcher.ViewModels.Popup;
|
||||
using Nebula.Launcher.Views.Pages;
|
||||
using Nebula.Shared.Configurations;
|
||||
using Nebula.Shared.Models.Auth;
|
||||
using Nebula.Shared.Services;
|
||||
using Nebula.Shared.Services.Logging;
|
||||
using Nebula.Shared.Utils;
|
||||
using Nebula.Shared.ViewHelper;
|
||||
|
||||
namespace Nebula.Launcher.ViewModels.Pages;
|
||||
|
||||
@@ -22,60 +24,47 @@ namespace Nebula.Launcher.ViewModels.Pages;
|
||||
public partial class AccountInfoViewModel : ViewModelBase
|
||||
{
|
||||
[ObservableProperty] private bool _authMenuExpand;
|
||||
|
||||
[ObservableProperty] private bool _authUrlConfigExpand;
|
||||
|
||||
[ObservableProperty] private int _authViewSpan = 1;
|
||||
|
||||
[ObservableProperty] private string _currentAuthServer = string.Empty;
|
||||
|
||||
[ObservableProperty] private string _currentLogin = string.Empty;
|
||||
|
||||
[ObservableProperty] private string _currentPassword = string.Empty;
|
||||
|
||||
[ObservableProperty] private bool _isLogged;
|
||||
[ObservableProperty] private bool _doRetryAuth;
|
||||
|
||||
private bool _isProfilesEmpty;
|
||||
[GenerateProperty] private LocalisationService LocalisationService { get; }
|
||||
[GenerateProperty] private PopupMessageService PopupMessageService { get; } = default!;
|
||||
[GenerateProperty] private ConfigurationService ConfigurationService { get; } = default!;
|
||||
[GenerateProperty] private DebugService DebugService { get; }
|
||||
[GenerateProperty] private AuthService AuthService { get; } = default!;
|
||||
[GenerateProperty, DesignConstruct] private ViewHelperService ViewHelperService { get; } = default!;
|
||||
|
||||
public ObservableCollection<ProfileAuthCredentials> Accounts { get; } = new();
|
||||
public ObservableCollection<AuthServerCredentials> AuthUrls { get; } = new();
|
||||
|
||||
[ObservableProperty] private AuthServerCredentials _authItemSelect;
|
||||
|
||||
private ILogger _logger;
|
||||
private bool _isProfilesEmpty;
|
||||
[GenerateProperty] private PopupMessageService PopupMessageService { get; }
|
||||
[GenerateProperty] private ConfigurationService ConfigurationService { get; }
|
||||
[GenerateProperty] private DebugService DebugService { get; }
|
||||
[GenerateProperty] private AuthService AuthService { get; }
|
||||
[GenerateProperty, DesignConstruct] private ViewHelperService ViewHelperService { get; }
|
||||
|
||||
public ObservableCollection<ProfileEntry> Accounts { get; } = new();
|
||||
public ObservableCollection<AuthServerCredentials> AuthUrls { get; } = new();
|
||||
|
||||
public ComplexConVarBinder<AuthTokenCredentials?> Credentials { get; private set; }
|
||||
|
||||
private ILogger _logger;
|
||||
|
||||
//Design think
|
||||
protected override void InitialiseInDesignMode()
|
||||
{
|
||||
AddAccount(new AuthLoginPassword("Binka", "12341", ""));
|
||||
AddAccount(new AuthLoginPassword("Binka", "12341", ""));
|
||||
AuthUrls.Add(new AuthServerCredentials("Test",["example.com","variant.lab"]));
|
||||
|
||||
AuthUrls.Add(new AuthServerCredentials("Test",["example.com"]));
|
||||
AddAccount(new ProfileAuthCredentials("Binka", "","example.com"));
|
||||
AddAccount(new ProfileAuthCredentials("Vilka","", "variant.lab"));
|
||||
}
|
||||
|
||||
|
||||
//Real think
|
||||
protected override void Initialise()
|
||||
{
|
||||
_logger = DebugService.GetLogger(this);
|
||||
Credentials = new AuthTokenCredentialsVar(this);
|
||||
Task.Run(ReadAuthConfig);
|
||||
Credentials.Value = Credentials.Value;
|
||||
}
|
||||
|
||||
public void AuthByProfile(ProfileAuthCredentials credentials)
|
||||
{
|
||||
CurrentLogin = credentials.Login;
|
||||
CurrentPassword = credentials.Password;
|
||||
CurrentAuthServer = credentials.AuthServer;
|
||||
|
||||
DoAuth();
|
||||
}
|
||||
|
||||
|
||||
public void DoAuth(string? code = null)
|
||||
{
|
||||
var message = ViewHelperService.GetViewModel<InfoPopupViewModel>();
|
||||
@@ -93,48 +82,32 @@ public partial class AccountInfoViewModel : ViewModelBase
|
||||
Task.Run(async () =>
|
||||
{
|
||||
Exception? exception = null;
|
||||
|
||||
foreach (var server in serverCandidates)
|
||||
{
|
||||
try
|
||||
{
|
||||
await CatchAuthError(async () => await TryAuth(CurrentLogin, CurrentPassword, server, code), ()=> message.Dispose());
|
||||
await CatchAuthError(async() =>
|
||||
{
|
||||
Credentials.Value = await AuthService.Auth(CurrentLogin, CurrentPassword, server, code);
|
||||
}, ()=> message.Dispose());
|
||||
break;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
var unexpectedError = new Exception(LocalisationService.GetString("auth-error"), ex);
|
||||
_logger.Error(unexpectedError);
|
||||
PopupMessageService.Popup(unexpectedError);
|
||||
exception = new Exception(LocalisationService.GetString("auth-error"), ex);
|
||||
}
|
||||
}
|
||||
|
||||
message.Dispose();
|
||||
|
||||
if (!IsLogged)
|
||||
if (exception != null)
|
||||
{
|
||||
PopupMessageService.Popup(exception ?? new Exception(LocalisationService.GetString("auth-error")));
|
||||
PopupMessageService.Popup(new Exception("Error while auth", exception));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private async Task TryAuth(CurrentAuthInfo currentAuthInfo)
|
||||
{
|
||||
CurrentLogin = currentAuthInfo.Login;
|
||||
CurrentAuthServer = currentAuthInfo.AuthServer;
|
||||
await AuthService.SetAuth(currentAuthInfo);
|
||||
IsLogged = true;
|
||||
}
|
||||
|
||||
private async Task TryAuth(string login, string password, string authServer, string? code)
|
||||
{
|
||||
await AuthService.Auth(new AuthLoginPassword(login, password, authServer), code);
|
||||
CurrentLogin = login;
|
||||
CurrentPassword = password;
|
||||
CurrentAuthServer = authServer;
|
||||
IsLogged = true;
|
||||
ConfigurationService.SetConfigValue(LauncherConVar.AuthCurrent, AuthService.SelectedAuth);
|
||||
}
|
||||
|
||||
private async Task CatchAuthError(Func<Task> a, Action? onError)
|
||||
{
|
||||
DoRetryAuth = false;
|
||||
@@ -151,15 +124,24 @@ public partial class AccountInfoViewModel : ViewModelBase
|
||||
case AuthenticateDenyCode.TfaRequired:
|
||||
case AuthenticateDenyCode.TfaInvalid:
|
||||
var p = ViewHelperService.GetViewModel<TfaViewModel>();
|
||||
p.OnTfaEntered += OnTfaEntered;
|
||||
PopupMessageService.Popup(p);
|
||||
_logger.Log("TFA required");
|
||||
break;
|
||||
case AuthenticateDenyCode.InvalidCredentials:
|
||||
PopupError(LocalisationService.GetString("auth-invalid-credentials"), e);
|
||||
break;
|
||||
case AuthenticateDenyCode.AccountLocked:
|
||||
PopupError(LocalisationService.GetString("auth-account-locked"), e);
|
||||
break;
|
||||
case AuthenticateDenyCode.AccountUnconfirmed:
|
||||
PopupError(LocalisationService.GetString("auth-account-unconfirmed"), e);
|
||||
break;
|
||||
case AuthenticateDenyCode.None:
|
||||
PopupError(LocalisationService.GetString("auth-none"),e);
|
||||
break;
|
||||
default:
|
||||
throw;
|
||||
PopupError(LocalisationService.GetString("auth-error-fuck"), e);
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch (HttpRequestException e)
|
||||
@@ -171,17 +153,41 @@ public partial class AccountInfoViewModel : ViewModelBase
|
||||
PopupError(LocalisationService.GetString("auth-connection-error"), e);
|
||||
DoRetryAuth = true;
|
||||
break;
|
||||
|
||||
case HttpRequestError.NameResolutionError:
|
||||
PopupError(LocalisationService.GetString("auth-name-resolution-error"), e);
|
||||
DoRetryAuth = true;
|
||||
break;
|
||||
|
||||
case HttpRequestError.SecureConnectionError:
|
||||
PopupError(LocalisationService.GetString("auth-secure-error"), e);
|
||||
DoRetryAuth = true;
|
||||
break;
|
||||
|
||||
case HttpRequestError.UserAuthenticationError:
|
||||
PopupError(LocalisationService.GetString("auth-user-authentication-error"), e);
|
||||
break;
|
||||
case HttpRequestError.Unknown:
|
||||
PopupError(LocalisationService.GetString("auth-unknown"), e);
|
||||
break;
|
||||
case HttpRequestError.HttpProtocolError:
|
||||
PopupError(LocalisationService.GetString("auth-http-protocol-error"), e);
|
||||
break;
|
||||
case HttpRequestError.ExtendedConnectNotSupported:
|
||||
PopupError(LocalisationService.GetString("auth-extended-connect-not-support"), e);
|
||||
break;
|
||||
case HttpRequestError.VersionNegotiationError:
|
||||
PopupError(LocalisationService.GetString("auth-version-negotiation-error"), e);
|
||||
break;
|
||||
case HttpRequestError.ProxyTunnelError:
|
||||
PopupError(LocalisationService.GetString("auth-proxy-tunnel-error"), e);
|
||||
break;
|
||||
case HttpRequestError.InvalidResponse:
|
||||
PopupError(LocalisationService.GetString("auth-invalid-response"), e);
|
||||
break;
|
||||
case HttpRequestError.ResponseEnded:
|
||||
PopupError(LocalisationService.GetString("auth-response-ended"), e);
|
||||
break;
|
||||
case HttpRequestError.ConfigurationLimitExceeded:
|
||||
PopupError(LocalisationService.GetString("auth-configuration-limit-exceeded"), e);
|
||||
break;
|
||||
default:
|
||||
var authError = new Exception(LocalisationService.GetString("auth-error"), e);
|
||||
_logger.Error(authError);
|
||||
@@ -191,15 +197,16 @@ public partial class AccountInfoViewModel : ViewModelBase
|
||||
}
|
||||
}
|
||||
|
||||
private void OnTfaEntered(string code)
|
||||
{
|
||||
DoAuth(code);
|
||||
}
|
||||
|
||||
public void Logout()
|
||||
{
|
||||
IsLogged = false;
|
||||
AuthService.ClearAuth();
|
||||
Credentials.Value = null;
|
||||
CurrentAuthServer = "";
|
||||
}
|
||||
|
||||
public string GetServerAuthName(string? url)
|
||||
{
|
||||
if (url is null) return "";
|
||||
return AuthUrls.FirstOrDefault(p => p.Servers.Contains(url))?.Name ?? "CustomAuth";
|
||||
}
|
||||
|
||||
private void UpdateAuthMenu()
|
||||
@@ -210,15 +217,22 @@ public partial class AccountInfoViewModel : ViewModelBase
|
||||
AuthViewSpan = 1;
|
||||
}
|
||||
|
||||
private void AddAccount(AuthLoginPassword authLoginPassword)
|
||||
private void AddAccount(ProfileAuthCredentials credentials)
|
||||
{
|
||||
var onDelete = new DelegateCommand<ProfileAuthCredentials>(OnDeleteProfile);
|
||||
var onSelect = new DelegateCommand<ProfileAuthCredentials>(AuthByProfile);
|
||||
var onDelete = new DelegateCommand<ProfileEntry>(OnDeleteProfile);
|
||||
var onSelect = new DelegateCommand<ProfileEntry>((p) =>
|
||||
{
|
||||
CurrentLogin = p.Credentials.Login;
|
||||
CurrentPassword = p.Credentials.Password;
|
||||
CurrentAuthServer = p.Credentials.AuthServer;
|
||||
DoAuth();
|
||||
});
|
||||
|
||||
var serverName = GetServerAuthName(credentials.AuthServer);
|
||||
|
||||
var alpm = new ProfileAuthCredentials(
|
||||
authLoginPassword.Login,
|
||||
authLoginPassword.Password,
|
||||
authLoginPassword.AuthServer,
|
||||
var alpm = new ProfileEntry(
|
||||
credentials,
|
||||
serverName,
|
||||
onSelect,
|
||||
onDelete);
|
||||
|
||||
@@ -228,64 +242,100 @@ public partial class AccountInfoViewModel : ViewModelBase
|
||||
Accounts.Add(alpm);
|
||||
}
|
||||
|
||||
private void ReadAuthConfig()
|
||||
private async Task ReadAuthConfig()
|
||||
{
|
||||
var message = ViewHelperService.GetViewModel<InfoPopupViewModel>();
|
||||
message.InfoText = LocalisationService.GetString("auth-config-read");
|
||||
message.IsInfoClosable = false;
|
||||
PopupMessageService.Popup(message);
|
||||
foreach (var profile in
|
||||
ConfigurationService.GetConfigValue(LauncherConVar.AuthProfiles)!)
|
||||
AddAccount(new AuthLoginPassword(profile.Login, profile.Password, profile.AuthServer));
|
||||
|
||||
if (Accounts.Count == 0) UpdateAuthMenu();
|
||||
|
||||
|
||||
_logger.Log("Reading auth config");
|
||||
|
||||
AuthUrls.Clear();
|
||||
var authUrls = ConfigurationService.GetConfigValue(LauncherConVar.AuthServers)!;
|
||||
foreach (var url in authUrls) AuthUrls.Add(url);
|
||||
if(authUrls.Length > 0) AuthItemSelect = authUrls[0];
|
||||
message.Dispose();
|
||||
|
||||
var profileCandidates = new List<string>();
|
||||
|
||||
DoCurrentAuth();
|
||||
}
|
||||
|
||||
public async void DoCurrentAuth()
|
||||
{
|
||||
var message = ViewHelperService.GetViewModel<InfoPopupViewModel>();
|
||||
message.InfoText = LocalisationService.GetString("auth-try-auth-config");
|
||||
message.IsInfoClosable = false;
|
||||
PopupMessageService.Popup(message);
|
||||
|
||||
var currProfile = ConfigurationService.GetConfigValue(LauncherConVar.AuthCurrent);
|
||||
|
||||
if (currProfile != null)
|
||||
foreach (var profileRaw in
|
||||
ConfigurationService.GetConfigValue(LauncherConVar.AuthProfiles)!)
|
||||
{
|
||||
_logger.Log($"Decrypting profile...");
|
||||
try
|
||||
{
|
||||
await CatchAuthError(async () => await TryAuth(currProfile), () => message.Dispose());
|
||||
var decoded =
|
||||
await CryptographicStore.Decrypt<ProfileAuthCredentials>(profileRaw,
|
||||
CryptographicStore.GetComputerKey());
|
||||
|
||||
_logger.Log($"Decrypted profile: {decoded.Login}");
|
||||
|
||||
profileCandidates.Add(profileRaw);
|
||||
AddAccount(decoded);
|
||||
}
|
||||
catch (Exception ex)
|
||||
catch (Exception e)
|
||||
{
|
||||
var unexpectedError = new Exception(LocalisationService.GetString("auth-error"), ex);
|
||||
_logger.Error(unexpectedError);
|
||||
PopupMessageService.Popup(unexpectedError);
|
||||
return;
|
||||
_logger.Error("Error while decrypting profile");
|
||||
_logger.Error(e);
|
||||
}
|
||||
}
|
||||
|
||||
ConfigurationService.SetConfigValue(LauncherConVar.AuthProfiles, profileCandidates.ToArray());
|
||||
|
||||
if (Accounts.Count == 0) UpdateAuthMenu();
|
||||
|
||||
message.Dispose();
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void OnSaveProfile()
|
||||
public void DoCurrentAuth()
|
||||
{
|
||||
AddAccount(new AuthLoginPassword(CurrentLogin, CurrentPassword, CurrentAuthServer));
|
||||
DoAuth();
|
||||
}
|
||||
|
||||
private async Task<AuthTokenCredentials?> CheckOrRenewToken(AuthTokenCredentials? authTokenCredentials)
|
||||
{
|
||||
if(authTokenCredentials is null)
|
||||
return null;
|
||||
|
||||
var daysLeft = (int)(authTokenCredentials.Token.ExpireTime - DateTime.Now).TotalDays;
|
||||
|
||||
if(daysLeft >= 4)
|
||||
{
|
||||
_logger.Log("Token " + authTokenCredentials.Login + " is active, "+daysLeft+" days left, undo renewing!");
|
||||
return authTokenCredentials;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
_logger.Log($"Renewing token for {authTokenCredentials.Login}");
|
||||
return await ExceptionHelper.TryRun(() => AuthService.Refresh(authTokenCredentials), 3,
|
||||
(attempt, e) => { _logger.Error(new Exception("Error while renewing, attempts: " + attempt, e)); });
|
||||
}
|
||||
catch (AuthTokenExpiredException e)
|
||||
{
|
||||
_logger.Error(e);
|
||||
return null;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
var unexpectedError = new Exception(LocalisationService.GetString("auth-error"), e);
|
||||
_logger.Error(unexpectedError);
|
||||
return authTokenCredentials;
|
||||
}
|
||||
}
|
||||
|
||||
public void OnSaveProfile()
|
||||
{
|
||||
if(Credentials.Value is null ||
|
||||
string.IsNullOrEmpty(CurrentPassword)) return;
|
||||
|
||||
AddAccount(new ProfileAuthCredentials(CurrentLogin, CurrentPassword, Credentials.Value.AuthServer));
|
||||
_isProfilesEmpty = Accounts.Count == 0;
|
||||
UpdateAuthMenu();
|
||||
DirtyProfile();
|
||||
}
|
||||
|
||||
private void OnDeleteProfile(ProfileAuthCredentials account)
|
||||
private void OnDeleteProfile(ProfileEntry account)
|
||||
{
|
||||
Accounts.Remove(account);
|
||||
_isProfilesEmpty = Accounts.Count == 0;
|
||||
@@ -303,15 +353,13 @@ public partial class AccountInfoViewModel : ViewModelBase
|
||||
messageView.IsInfoClosable = true;
|
||||
PopupMessageService.Popup(messageView);
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void OnExpandAuthUrl()
|
||||
|
||||
public void OnExpandAuthUrl()
|
||||
{
|
||||
AuthUrlConfigExpand = !AuthUrlConfigExpand;
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void OnExpandAuthView()
|
||||
|
||||
public void OnExpandAuthView()
|
||||
{
|
||||
AuthMenuExpand = !AuthMenuExpand;
|
||||
UpdateAuthMenu();
|
||||
@@ -320,18 +368,77 @@ public partial class AccountInfoViewModel : ViewModelBase
|
||||
private void DirtyProfile()
|
||||
{
|
||||
ConfigurationService.SetConfigValue(LauncherConVar.AuthProfiles,
|
||||
Accounts.ToArray());
|
||||
Accounts.Select(a => CryptographicStore.Encrypt(a.Credentials, CryptographicStore.GetComputerKey())).ToArray());
|
||||
}
|
||||
|
||||
public sealed class AuthTokenCredentialsVar(AccountInfoViewModel accountInfoViewModel)
|
||||
: ComplexConVarBinder<AuthTokenCredentials?>(
|
||||
accountInfoViewModel.ConfigurationService.SubscribeVarChanged(LauncherConVar.AuthCurrent))
|
||||
{
|
||||
protected override async Task<AuthTokenCredentials?> OnValueChange(AuthTokenCredentials? currProfile)
|
||||
{
|
||||
if (currProfile is null)
|
||||
{
|
||||
accountInfoViewModel.IsLogged = false;
|
||||
accountInfoViewModel._logger.Log("clearing credentials");
|
||||
return null;
|
||||
}
|
||||
|
||||
var message = accountInfoViewModel.ViewHelperService.GetViewModel<InfoPopupViewModel>();
|
||||
message.InfoText = LocalisationService.GetString("auth-try-auth-config");
|
||||
message.IsInfoClosable = false;
|
||||
accountInfoViewModel.PopupMessageService.Popup(message);
|
||||
|
||||
accountInfoViewModel._logger.Log($"trying auth with {currProfile.Login}");
|
||||
|
||||
var errorRun = false;
|
||||
|
||||
currProfile = await accountInfoViewModel.CheckOrRenewToken(currProfile);
|
||||
|
||||
if (currProfile is null)
|
||||
{
|
||||
message.Dispose();
|
||||
|
||||
accountInfoViewModel._logger.Log("profile credentials update required!");
|
||||
|
||||
accountInfoViewModel.PopupMessageService.Popup("profile credentials update required!");
|
||||
|
||||
accountInfoViewModel.IsLogged = false;
|
||||
return null;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
await accountInfoViewModel.CatchAuthError(async () =>
|
||||
{
|
||||
await accountInfoViewModel.AuthService.EnsureToken(currProfile);
|
||||
}, () =>
|
||||
{
|
||||
message.Dispose();
|
||||
errorRun = true;
|
||||
});
|
||||
message.Dispose();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
accountInfoViewModel.CurrentLogin = currProfile.Login;
|
||||
accountInfoViewModel.CurrentAuthServer = currProfile.AuthServer;
|
||||
var unexpectedError = new Exception(LocalisationService.GetString("auth-error"), ex);
|
||||
accountInfoViewModel._logger.Error(unexpectedError);
|
||||
accountInfoViewModel.PopupMessageService.Popup(unexpectedError);
|
||||
errorRun = true;
|
||||
}
|
||||
|
||||
if (errorRun)
|
||||
{
|
||||
accountInfoViewModel.IsLogged = false;
|
||||
return null;
|
||||
}
|
||||
|
||||
accountInfoViewModel.IsLogged = true;
|
||||
|
||||
return currProfile;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public sealed record ProfileAuthCredentials(
|
||||
string Login,
|
||||
string Password,
|
||||
string AuthServer,
|
||||
[property: JsonIgnore] ICommand OnSelect = default!,
|
||||
[property: JsonIgnore] ICommand OnDelete = default!);
|
||||
|
||||
public sealed record AuthServerCredentials(
|
||||
string Name,
|
||||
string[] Servers
|
||||
);
|
||||
@@ -1,19 +1,16 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
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 System.Threading.Tasks;
|
||||
using Nebula.Launcher.Services;
|
||||
using Nebula.Launcher.ViewModels.Popup;
|
||||
using Nebula.Launcher.Views.Pages;
|
||||
using Nebula.Shared;
|
||||
using Nebula.Shared.Configurations;
|
||||
using Nebula.Shared.Services;
|
||||
using Nebula.Shared.ViewHelper;
|
||||
|
||||
namespace Nebula.Launcher.ViewModels.Pages;
|
||||
|
||||
@@ -26,14 +23,18 @@ public partial class ConfigurationViewModel : ViewModelBase
|
||||
[GenerateProperty] private ConfigurationService ConfigurationService { get; } = default!;
|
||||
[GenerateProperty] private PopupMessageService PopupService { get; } = default!;
|
||||
[GenerateProperty] private FileService FileService { get; set; } = default!;
|
||||
[GenerateProperty] private ContentService ContentService { get; set; } = default!;
|
||||
[GenerateProperty] private CancellationService CancellationService { get; set; } = default!;
|
||||
[GenerateProperty] private ViewHelperService ViewHelperService { get; set; } = default!;
|
||||
|
||||
public List<(object, Type)> ConVarList = new();
|
||||
|
||||
private readonly List<(object, Type)> _conVarList = new();
|
||||
|
||||
public void AddCvarConf<T>(ConVar<T> cvar)
|
||||
{
|
||||
ConfigurationVerbose.Add(
|
||||
ConfigControlHelper.GetConfigControl(cvar.Name, ConfigurationService.GetConfigValue(cvar)));
|
||||
ConVarList.Add((cvar, cvar.Type));
|
||||
ConfigControlHelper.GetConfigControl(cvar.Name, ConfigurationService.GetConfigValue(cvar)!));
|
||||
_conVarList.Add((cvar, cvar.Type));
|
||||
}
|
||||
|
||||
public void InvokeUpdateConfiguration()
|
||||
@@ -44,7 +45,7 @@ public partial class ConfigurationViewModel : ViewModelBase
|
||||
if(!conVarControl.Dirty)
|
||||
continue;
|
||||
|
||||
var conVar = ConVarList[i];
|
||||
var conVar = _conVarList[i];
|
||||
var methodInfo = ConfigurationService.GetType().GetMethod("SetConfigValue")!.MakeGenericMethod(conVar.Item2);
|
||||
methodInfo.Invoke(ConfigurationService, [conVar.Item1, conVarControl.GetValue()]);
|
||||
}
|
||||
@@ -52,13 +53,13 @@ public partial class ConfigurationViewModel : ViewModelBase
|
||||
|
||||
public void ResetConfig()
|
||||
{
|
||||
foreach (var conVar in ConVarList)
|
||||
foreach (var conVar in _conVarList)
|
||||
{
|
||||
var methodInfo = ConfigurationService.GetType().GetMethod("SetConfigValue")!.MakeGenericMethod(conVar.Item2);
|
||||
methodInfo.Invoke(ConfigurationService, [conVar.Item1, null]);
|
||||
}
|
||||
|
||||
ConVarList.Clear();
|
||||
_conVarList.Clear();
|
||||
ConfigurationVerbose.Clear();
|
||||
|
||||
InitConfiguration();
|
||||
@@ -80,7 +81,18 @@ public partial class ConfigurationViewModel : ViewModelBase
|
||||
ZipFile.CreateFromDirectory(logPath, Path.Join(path, DateTime.Now.ToString("yyyy-MM-dd") + ".zip"));
|
||||
ExplorerHelper.OpenFolder(path);
|
||||
}
|
||||
|
||||
|
||||
public void RemoveAllContent()
|
||||
{
|
||||
Task.Run(() =>
|
||||
{
|
||||
using var loader = ViewHelperService.GetViewModel<LoadingContextViewModel>();
|
||||
loader.LoadingName = "Removing content";
|
||||
PopupService.Popup(loader);
|
||||
ContentService.RemoveAllContent(loader, CancellationService.Token);
|
||||
});
|
||||
}
|
||||
|
||||
private void InitConfiguration()
|
||||
{
|
||||
AddCvarConf(LauncherConVar.ILSpyUrl);
|
||||
@@ -100,288 +112,4 @@ public partial class ConfigurationViewModel : ViewModelBase
|
||||
{
|
||||
InitConfiguration();
|
||||
}
|
||||
}
|
||||
|
||||
public static class ConfigControlHelper{
|
||||
public static IConfigControl GetConfigControl(string name,object value)
|
||||
{
|
||||
switch (value)
|
||||
{
|
||||
case string stringValue:
|
||||
return new StringUnitConfigControl(name, stringValue);
|
||||
case int intValue:
|
||||
return new IntUnitConfigControl(name, intValue);
|
||||
case float floatValue:
|
||||
return new FloatUnitConfigControl(name, floatValue);
|
||||
}
|
||||
|
||||
var valueType = value.GetType();
|
||||
|
||||
if (valueType.IsArray)
|
||||
return new ArrayUnitConfigControl(name, value);
|
||||
|
||||
return new ComplexUnitConfigControl(name, value);
|
||||
}
|
||||
|
||||
public static object? CreateDefaultValue(Type type)
|
||||
{
|
||||
if(type.IsValueType)
|
||||
return Activator.CreateInstance(type);
|
||||
|
||||
var ctor = type.GetConstructors().First();
|
||||
var parameters = ctor.GetParameters()
|
||||
.Select(p => CreateDefaultValue(p.ParameterType))
|
||||
.ToArray();
|
||||
|
||||
return ctor.Invoke(parameters);
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class ComplexUnitConfigControl : Border, IConfigControl
|
||||
{
|
||||
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)
|
||||
{
|
||||
Classes.Add("ConfigBorder");
|
||||
_panel.Orientation = Orientation.Vertical;
|
||||
_panel.Spacing = 4f;
|
||||
ConfigName = name;
|
||||
Child = _panel;
|
||||
SetValue(obj);
|
||||
}
|
||||
|
||||
public void SetValue(object value)
|
||||
{
|
||||
_units.Clear();
|
||||
_panel.Children.Clear();
|
||||
_objectType = value.GetType();
|
||||
|
||||
_panel.Children.Add(new Label()
|
||||
{
|
||||
Content = ConfigName
|
||||
});
|
||||
|
||||
foreach (var propInfo in _objectType.GetProperties())
|
||||
{
|
||||
if(propInfo.PropertyType.IsInterface)
|
||||
continue;
|
||||
|
||||
var propValue = propInfo.GetValue(value);
|
||||
|
||||
var control = ConfigControlHelper.GetConfigControl(propInfo.Name, propValue);
|
||||
|
||||
((Control)control).Margin = new Thickness(5);
|
||||
_panel.Children.Add((Control)control);
|
||||
_units.Add((propInfo,control));
|
||||
}
|
||||
}
|
||||
|
||||
public object GetValue()
|
||||
{
|
||||
var obj = ConfigControlHelper.CreateDefaultValue(_objectType);
|
||||
foreach (var (fieldInfo, configControl) in _units)
|
||||
{
|
||||
fieldInfo.SetValue(obj, configControl.GetValue());
|
||||
}
|
||||
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
|
||||
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 = new Label()
|
||||
{
|
||||
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 ArrayUnitConfigControl(string name, object value)
|
||||
{
|
||||
Classes.Add("ConfigBorder");
|
||||
_elementType = value.GetType().GetElementType()!;
|
||||
|
||||
ConfigName = name;
|
||||
_panel.Orientation = Orientation.Vertical;
|
||||
_panel.Spacing = 4f;
|
||||
_itemsPanel.Spacing = 4f;
|
||||
|
||||
_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;
|
||||
}
|
||||
|
||||
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 = new Label(){ 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);
|
||||
|
||||
_itemsPanel.Children.Add(itemPanel);
|
||||
_itemControls.Add(control);
|
||||
}
|
||||
|
||||
public void SetValue(object value)
|
||||
{
|
||||
_itemControls.Clear();
|
||||
_itemsPanel.Children.Clear();
|
||||
|
||||
if (value is IEnumerable list)
|
||||
{
|
||||
foreach (var item in list)
|
||||
{
|
||||
AddItem(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public object GetValue()
|
||||
{
|
||||
return ConvertArray(_itemControls.Select(c => c.GetValue()).ToArray(), _elementType);
|
||||
}
|
||||
|
||||
public static Array ConvertArray(Array sourceArray, Type targetType)
|
||||
{
|
||||
int length = sourceArray.Length;
|
||||
var newArray = Array.CreateInstance(targetType, length);
|
||||
|
||||
for (int i = 0; i < length; i++)
|
||||
{
|
||||
var value = sourceArray.GetValue(i);
|
||||
var converted = Convert.ChangeType(value, targetType);
|
||||
newArray.SetValue(converted, i);
|
||||
}
|
||||
|
||||
return newArray;
|
||||
}
|
||||
}
|
||||
|
||||
public abstract class UnitConfigControl<T> : Border, IConfigControl where T : notnull
|
||||
{
|
||||
private readonly Label _nameLabel = new();
|
||||
private readonly TextBox _valueLabel = new();
|
||||
private string _originalValue;
|
||||
|
||||
private StackPanel _panel = new();
|
||||
|
||||
public string ConfigName { get; }
|
||||
|
||||
public bool Dirty => _originalValue != ConfigValue;
|
||||
|
||||
protected string ConfigValue
|
||||
{
|
||||
get => _valueLabel.Text ?? string.Empty;
|
||||
set => _valueLabel.Text = value;
|
||||
}
|
||||
|
||||
public UnitConfigControl(string name, T value)
|
||||
{
|
||||
Classes.Add("ConfigBorder");
|
||||
ConfigName = name;
|
||||
_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;
|
||||
}
|
||||
|
||||
public abstract void SetConfValue(T value);
|
||||
|
||||
public abstract T GetConfValue();
|
||||
|
||||
public void SetValue(object value)
|
||||
{
|
||||
SetConfValue((T)value);
|
||||
}
|
||||
|
||||
public object GetValue()
|
||||
{
|
||||
return GetConfValue()!;
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class StringUnitConfigControl(string name, string value) : UnitConfigControl<string>(name, value)
|
||||
{
|
||||
public override void SetConfValue(string value)
|
||||
{
|
||||
ConfigValue = value;
|
||||
}
|
||||
|
||||
public override string GetConfValue()
|
||||
{
|
||||
return ConfigValue;
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class IntUnitConfigControl(string name, int value) : UnitConfigControl<int>(name, value)
|
||||
{
|
||||
public override void SetConfValue(int value)
|
||||
{
|
||||
ConfigValue = value.ToString();
|
||||
}
|
||||
|
||||
public override int GetConfValue()
|
||||
{
|
||||
return int.Parse(ConfigValue);
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class FloatUnitConfigControl(string name, float value) : UnitConfigControl<float>(name, value)
|
||||
{
|
||||
|
||||
public CultureInfo CultureInfo = CultureInfo.InvariantCulture;
|
||||
|
||||
public override void SetConfValue(float value)
|
||||
{
|
||||
ConfigValue = value.ToString(CultureInfo);
|
||||
}
|
||||
|
||||
public override float GetConfValue()
|
||||
{
|
||||
return float.Parse(ConfigValue, CultureInfo);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public interface IConfigControl
|
||||
{
|
||||
public string ConfigName { get; }
|
||||
public bool Dirty {get;}
|
||||
public abstract void SetValue(object value);
|
||||
public abstract object GetValue();
|
||||
}
|
||||
@@ -18,6 +18,7 @@ using Nebula.Shared.FileApis;
|
||||
using Nebula.Shared.Models;
|
||||
using Nebula.Shared.Services;
|
||||
using Nebula.Shared.Utils;
|
||||
using Nebula.Shared.ViewHelper;
|
||||
|
||||
namespace Nebula.Launcher.ViewModels.Pages;
|
||||
|
||||
@@ -415,7 +416,20 @@ public abstract class BaseFolderContentEntry : ViewModelBase, IContentEntry
|
||||
private Dictionary<string, IContentEntry> _childs = [];
|
||||
|
||||
public string IconPath => "/Assets/svg/folder.svg";
|
||||
public IContentHolder Holder { get; private set; }
|
||||
|
||||
private IContentHolder? _holder = null;
|
||||
public IContentHolder Holder
|
||||
{
|
||||
get
|
||||
{
|
||||
if(_holder == null)
|
||||
throw new InvalidOperationException(
|
||||
GetType().Name + " was not initialised! Call Init(IContentHolder holder, string? name = null) before using it.");
|
||||
|
||||
return _holder;
|
||||
}
|
||||
}
|
||||
|
||||
public IContentEntry? Parent { get; set; }
|
||||
public string? Name { get; private set; }
|
||||
|
||||
@@ -431,7 +445,7 @@ public abstract class BaseFolderContentEntry : ViewModelBase, IContentEntry
|
||||
public void Init(IContentHolder holder, string? name = null)
|
||||
{
|
||||
Name = name;
|
||||
Holder = holder;
|
||||
_holder = holder;
|
||||
}
|
||||
|
||||
public T AddChild<T>(T child) where T: IContentEntry
|
||||
|
||||
@@ -14,6 +14,7 @@ using Nebula.Launcher.Views.Pages;
|
||||
using Nebula.Shared;
|
||||
using Nebula.Shared.Models;
|
||||
using Nebula.Shared.Services;
|
||||
using Nebula.Shared.ViewHelper;
|
||||
|
||||
namespace Nebula.Launcher.ViewModels.Pages;
|
||||
|
||||
@@ -28,8 +29,7 @@ public partial class ServerOverviewModel : ViewModelBase
|
||||
[ObservableProperty] private ServerListView _currentServerList = new();
|
||||
|
||||
public readonly ServerFilter CurrentFilter = new();
|
||||
|
||||
public Action? OnSearchChange;
|
||||
|
||||
[GenerateProperty] private IServiceProvider ServiceProvider { get; }
|
||||
[GenerateProperty] private ConfigurationService ConfigurationService { get; }
|
||||
[GenerateProperty] private FavoriteServerListProvider FavoriteServerListProvider { get; }
|
||||
@@ -71,13 +71,11 @@ public partial class ServerOverviewModel : ViewModelBase
|
||||
Items = new ObservableCollection<ServerListTabTemplate>(tempItems);
|
||||
|
||||
SelectedItem = Items[0];
|
||||
|
||||
OnSearchChange += SearchChangeEvent;
|
||||
}
|
||||
|
||||
private void SearchChangeEvent()
|
||||
partial void OnSearchTextChanged(string value)
|
||||
{
|
||||
CurrentFilter.SearchText = SearchText;
|
||||
CurrentFilter.SearchText = value;
|
||||
ApplyFilter();
|
||||
}
|
||||
|
||||
@@ -318,6 +316,4 @@ public sealed class ServerFilter
|
||||
{
|
||||
return IsMatchByName(name) && IsMatchByTags(itemTags);
|
||||
}
|
||||
}
|
||||
|
||||
public sealed record ServerCustomNameEntry(string Url, string Name);
|
||||
}
|
||||
@@ -7,6 +7,7 @@ using Nebula.Launcher.Views.Pages;
|
||||
using Nebula.Shared.Services;
|
||||
using Nebula.Shared.Services.Logging;
|
||||
using Nebula.Shared.Utils;
|
||||
using Nebula.Shared.ViewHelper;
|
||||
using AddFavoriteView = Nebula.Launcher.Views.Popup.AddFavoriteView;
|
||||
|
||||
namespace Nebula.Launcher.ViewModels.Popup;
|
||||
@@ -41,6 +42,9 @@ public partial class AddFavoriteViewModel : PopupViewModelBase
|
||||
{
|
||||
try
|
||||
{
|
||||
if(string.IsNullOrWhiteSpace(IpInput))
|
||||
throw new Exception(LocalisationService.GetString("popup-add-favorite-invalid-ip"));
|
||||
|
||||
var uri = IpInput.ToRobustUrl();
|
||||
FavoriteServerListProvider.AddFavorite(uri);
|
||||
Dispose();
|
||||
|
||||
@@ -2,6 +2,7 @@ using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using Nebula.Launcher.Services;
|
||||
using Nebula.Launcher.Views.Popup;
|
||||
using Nebula.Shared.Services;
|
||||
using Nebula.Shared.ViewHelper;
|
||||
|
||||
namespace Nebula.Launcher.ViewModels.Popup;
|
||||
|
||||
@@ -24,8 +25,7 @@ public sealed partial class EditServerNameViewModel : PopupViewModelBase
|
||||
|
||||
if (string.IsNullOrWhiteSpace(NameInput))
|
||||
{
|
||||
RemoveServerName();
|
||||
Dispose();
|
||||
OnClear();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -33,6 +33,12 @@ public sealed partial class EditServerNameViewModel : PopupViewModelBase
|
||||
Dispose();
|
||||
}
|
||||
|
||||
public void OnClear()
|
||||
{
|
||||
RemoveServerName();
|
||||
Dispose();
|
||||
}
|
||||
|
||||
private void AddServerName()
|
||||
{
|
||||
var currentNames = ConfigurationService.GetConfigValue(LauncherConVar.ServerCustomNames)!;
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.Collections.ObjectModel;
|
||||
using Nebula.Launcher.Services;
|
||||
using Nebula.Launcher.Views.Popup;
|
||||
using Nebula.Shared.Services;
|
||||
using Nebula.Shared.ViewHelper;
|
||||
|
||||
namespace Nebula.Launcher.ViewModels.Popup;
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using Nebula.Launcher.Services;
|
||||
using Nebula.Launcher.Views.Popup;
|
||||
using Nebula.Shared.Services;
|
||||
using Nebula.Shared.ViewHelper;
|
||||
|
||||
namespace Nebula.Launcher.ViewModels.Popup;
|
||||
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
using Nebula.Launcher.Services;
|
||||
using Nebula.Launcher.ViewModels.Pages;
|
||||
using Nebula.Launcher.Views.Popup;
|
||||
using Nebula.Shared.Services;
|
||||
using Nebula.Shared.ViewHelper;
|
||||
|
||||
namespace Nebula.Launcher.ViewModels.Popup;
|
||||
|
||||
[ConstructGenerator, ViewModelRegister(typeof(IsLoginCredentialsNullPopupView))]
|
||||
public partial class IsLoginCredentialsNullPopupViewModel : PopupViewModelBase
|
||||
{
|
||||
private ServerEntryModelView _entry;
|
||||
|
||||
[GenerateProperty] public override PopupMessageService PopupMessageService { get; }
|
||||
[GenerateProperty, DesignConstruct] private ViewHelperService ViewHelperService { get; }
|
||||
|
||||
protected override void InitialiseInDesignMode()
|
||||
{
|
||||
}
|
||||
|
||||
protected override void Initialise()
|
||||
{
|
||||
}
|
||||
|
||||
public IsLoginCredentialsNullPopupViewModel WithServerEntry(ServerEntryModelView entryModelView)
|
||||
{
|
||||
_entry = entryModelView;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void Proceed()
|
||||
{
|
||||
_entry.RunInstanceIgnoreAuth();
|
||||
Dispose();
|
||||
}
|
||||
|
||||
public void Cancel()
|
||||
{
|
||||
Dispose();
|
||||
}
|
||||
|
||||
public void GotoAuthPage()
|
||||
{
|
||||
ViewHelperService.GetViewModel<MainViewModel>().RequirePage<AccountInfoViewModel>();
|
||||
Dispose();
|
||||
}
|
||||
|
||||
public override string Title => LocalisationService.GetString("popup-login-credentials-warning");
|
||||
public override bool IsClosable => true;
|
||||
}
|
||||
@@ -3,6 +3,7 @@ using Nebula.Launcher.Services;
|
||||
using Nebula.Launcher.Views.Popup;
|
||||
using Nebula.Shared.Models;
|
||||
using Nebula.Shared.Services;
|
||||
using Nebula.Shared.ViewHelper;
|
||||
|
||||
namespace Nebula.Launcher.ViewModels.Popup;
|
||||
|
||||
@@ -14,8 +15,8 @@ public sealed partial class LoadingContextViewModel : PopupViewModelBase, ILoadi
|
||||
[GenerateProperty] public CancellationService CancellationService { get; }
|
||||
|
||||
[ObservableProperty] private int _currJobs;
|
||||
|
||||
[ObservableProperty] private int _resolvedJobs;
|
||||
[ObservableProperty] private string _message = string.Empty;
|
||||
|
||||
public string LoadingName { get; set; } = LocalisationService.GetString("popup-loading");
|
||||
public bool IsCancellable { get; set; } = true;
|
||||
@@ -43,6 +44,11 @@ public sealed partial class LoadingContextViewModel : PopupViewModelBase, ILoadi
|
||||
return ResolvedJobs;
|
||||
}
|
||||
|
||||
public void SetLoadingMessage(string message)
|
||||
{
|
||||
Message = message + "\n" + Message;
|
||||
}
|
||||
|
||||
public void Cancel(){
|
||||
if(!IsCancellable) return;
|
||||
CancellationService.Cancel();
|
||||
@@ -55,5 +61,30 @@ public sealed partial class LoadingContextViewModel : PopupViewModelBase, ILoadi
|
||||
|
||||
protected override void InitialiseInDesignMode()
|
||||
{
|
||||
SetJobsCount(5);
|
||||
SetResolvedJobsCount(2);
|
||||
string[] debugMessages = {
|
||||
"Debug: Starting phase 1...",
|
||||
"Debug: Loading assets...",
|
||||
"Debug: Connecting to server...",
|
||||
"Debug: Fetching user data...",
|
||||
"Debug: Applying configurations...",
|
||||
"Debug: Starting phase 2...",
|
||||
"Debug: Rendering UI...",
|
||||
"Debug: Preparing scene...",
|
||||
"Debug: Initializing components...",
|
||||
"Debug: Running diagnostics...",
|
||||
"Debug: Checking dependencies...",
|
||||
"Debug: Verifying files...",
|
||||
"Debug: Cleaning up cache...",
|
||||
"Debug: Finalizing setup...",
|
||||
"Debug: Setup complete.",
|
||||
"Debug: Ready for launch."
|
||||
};
|
||||
|
||||
foreach (string message in debugMessages)
|
||||
{
|
||||
SetLoadingMessage(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Text.RegularExpressions;
|
||||
using Avalonia.Media;
|
||||
using Nebula.Launcher.Models;
|
||||
using Nebula.Launcher.Views.Popup;
|
||||
using Nebula.Shared.Services;
|
||||
using Nebula.Shared.ViewHelper;
|
||||
|
||||
namespace Nebula.Launcher.ViewModels.Popup;
|
||||
|
||||
@@ -42,40 +42,4 @@ public sealed partial class LogPopupModelView : PopupViewModelBase
|
||||
{
|
||||
Logs.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class LogInfo
|
||||
{
|
||||
public string Category { get; set; } = "LOG";
|
||||
public IBrush CategoryColor { get; set; } = Brush.Parse("#424242");
|
||||
public string Message { get; set; } = "";
|
||||
|
||||
public static LogInfo FromString(string input)
|
||||
{
|
||||
var matches = Regex.Matches(input, @"(\[(?<c>.*)\] (?<m>.*))|(?<m>.*)");
|
||||
var category = "All";
|
||||
|
||||
if (matches[0].Groups.TryGetValue("c", out var c)) category = c.Value;
|
||||
|
||||
var color = Brush.Parse("#444444");
|
||||
|
||||
switch (category)
|
||||
{
|
||||
case "DEBG":
|
||||
color = Brush.Parse("#2436d4");
|
||||
break;
|
||||
case "ERRO":
|
||||
color = Brush.Parse("#d42436");
|
||||
break;
|
||||
case "INFO":
|
||||
color = Brush.Parse("#0ab3c9");
|
||||
break;
|
||||
}
|
||||
|
||||
var message = matches[0].Groups["m"].Value;
|
||||
return new LogInfo
|
||||
{
|
||||
Category = category, Message = message, CategoryColor = color
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,9 @@ public abstract class PopupViewModelBase : ViewModelBase, IDisposable
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
OnDispose();
|
||||
PopupMessageService.ClosePopup(this);
|
||||
}
|
||||
|
||||
protected virtual void OnDispose(){}
|
||||
}
|
||||
@@ -1,14 +1,19 @@
|
||||
using System;
|
||||
using Nebula.Launcher.Services;
|
||||
using Nebula.Launcher.ViewModels.Pages;
|
||||
using Nebula.Launcher.Views.Popup;
|
||||
using Nebula.Shared.Services;
|
||||
using Nebula.Shared.ViewHelper;
|
||||
|
||||
namespace Nebula.Launcher.ViewModels.Popup;
|
||||
|
||||
[ConstructGenerator, ViewModelRegister(typeof(TfaView))]
|
||||
public partial class TfaViewModel : PopupViewModelBase
|
||||
{
|
||||
public Action<string>? OnTfaEntered;
|
||||
[GenerateProperty] public override PopupMessageService PopupMessageService { get; }
|
||||
[GenerateProperty] public AccountInfoViewModel AccountInfo { get; }
|
||||
public override string Title => LocalisationService.GetString("popup-twofa");
|
||||
public override bool IsClosable => true;
|
||||
|
||||
protected override void InitialiseInDesignMode()
|
||||
{
|
||||
@@ -20,11 +25,7 @@ public partial class TfaViewModel : PopupViewModelBase
|
||||
|
||||
public void OnTfaEnter(string code)
|
||||
{
|
||||
OnTfaEntered?.Invoke(code);
|
||||
AccountInfo.DoAuth(code);
|
||||
Dispose();
|
||||
}
|
||||
|
||||
[GenerateProperty] public override PopupMessageService PopupMessageService { get; }
|
||||
public override string Title => LocalisationService.GetString("popup-twofa");
|
||||
public override bool IsClosable => true;
|
||||
}
|
||||
@@ -6,11 +6,13 @@ using Avalonia.Media;
|
||||
using Avalonia.Threading;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Nebula.Launcher.Models;
|
||||
using Nebula.Launcher.ServerListProviders;
|
||||
using Nebula.Launcher.ViewModels.Pages;
|
||||
using Nebula.Launcher.Views;
|
||||
using Nebula.Shared.Models;
|
||||
using Nebula.Shared.Services;
|
||||
using Nebula.Shared.ViewHelper;
|
||||
using BindingFlags = System.Reflection.BindingFlags;
|
||||
|
||||
namespace Nebula.Launcher.ViewModels;
|
||||
@@ -27,6 +29,8 @@ public sealed partial class ServerCompoundEntryViewModel :
|
||||
[ObservableProperty] private bool _loading = true;
|
||||
|
||||
private string? _name;
|
||||
private RobustUrl? _url;
|
||||
private ServerFilter? _currentFilter;
|
||||
|
||||
public string? Name
|
||||
{
|
||||
@@ -58,14 +62,16 @@ public sealed partial class ServerCompoundEntryViewModel :
|
||||
{
|
||||
Task.Run(async () =>
|
||||
{
|
||||
_url = url;
|
||||
try
|
||||
{
|
||||
Message = "Loading server entry...";
|
||||
var status = await RestService.GetAsync<ServerStatus>(url.StatusUri, cancellationToken);
|
||||
var status = await RestService.GetAsync<ServerStatus>(_url.StatusUri, cancellationToken);
|
||||
|
||||
CurrentEntry = ServiceProvider.GetService<ServerEntryModelView>()!.WithData(url,name, status);
|
||||
CurrentEntry = ServiceProvider.GetService<ServerEntryModelView>()!.WithData(_url,name, status);
|
||||
CurrentEntry.IsFavorite = IsFavorite;
|
||||
CurrentEntry.Loading = false;
|
||||
CurrentEntry.ProcessFilter(_currentFilter);
|
||||
Loading = false;
|
||||
}
|
||||
catch (Exception e)
|
||||
@@ -79,12 +85,20 @@ public sealed partial class ServerCompoundEntryViewModel :
|
||||
|
||||
public void ToggleFavorites()
|
||||
{
|
||||
if (CurrentEntry is null && _url is not null)
|
||||
{
|
||||
IsFavorite = !IsFavorite;
|
||||
if(IsFavorite) FavoriteServerListProvider.AddFavorite(_url);
|
||||
else FavoriteServerListProvider.RemoveFavorite(_url);
|
||||
}
|
||||
|
||||
CurrentEntry?.ToggleFavorites();
|
||||
}
|
||||
|
||||
|
||||
public void ProcessFilter(ServerFilter? serverFilter)
|
||||
{
|
||||
_currentFilter = serverFilter;
|
||||
if(CurrentEntry is IFilterConsumer filterConsumer)
|
||||
filterConsumer.ProcessFilter(serverFilter);
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ using System.Threading.Tasks;
|
||||
using System.Windows.Input;
|
||||
using Avalonia.Controls;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using Nebula.Launcher.Models;
|
||||
using Nebula.Launcher.ProcessHelper;
|
||||
using Nebula.Launcher.ServerListProviders;
|
||||
using Nebula.Launcher.Services;
|
||||
@@ -16,6 +17,7 @@ using Nebula.Shared.Models;
|
||||
using Nebula.Shared.Services;
|
||||
using Nebula.Shared.Services.Logging;
|
||||
using Nebula.Shared.Utils;
|
||||
using Nebula.Shared.ViewHelper;
|
||||
|
||||
namespace Nebula.Launcher.ViewModels;
|
||||
|
||||
@@ -45,7 +47,7 @@ public partial class ServerEntryModelView : ViewModelBase, IFilterConsumer, ILis
|
||||
|
||||
public LogPopupModelView CurrLog;
|
||||
public RobustUrl Address { get; private set; }
|
||||
[GenerateProperty] private ConfigurationService ConfigurationService { get; } = default!;
|
||||
[GenerateProperty] private AccountInfoViewModel AccountInfoViewModel { get; }
|
||||
[GenerateProperty] private CancellationService CancellationService { get; } = default!;
|
||||
[GenerateProperty] private DebugService DebugService { get; } = default!;
|
||||
[GenerateProperty] private PopupMessageService PopupMessageService { get; } = default!;
|
||||
@@ -161,24 +163,51 @@ public partial class ServerEntryModelView : ViewModelBase, IFilterConsumer, ILis
|
||||
public void RunInstance()
|
||||
{
|
||||
CurrLog.Clear();
|
||||
Task.Run(RunInstanceAsync);
|
||||
Task.Run(async ()=> await RunInstanceAsync());
|
||||
}
|
||||
|
||||
private async void RunInstanceAsync()
|
||||
public void RunInstanceIgnoreAuth()
|
||||
{
|
||||
using var loadingContext = ViewHelperService.GetViewModel<LoadingContextViewModel>();
|
||||
loadingContext.LoadingName = "Loading instance...";
|
||||
((ILoadingHandler)loadingContext).AppendJob();
|
||||
CurrLog.Clear();
|
||||
Task.Run(async ()=> await RunInstanceAsync(true));
|
||||
}
|
||||
|
||||
PopupMessageService.Popup(loadingContext);
|
||||
_currentInstance =
|
||||
await GameRunnerPreparer.GetGameProcessStartInfoProvider(Address, loadingContext, CancellationService.Token);
|
||||
private async Task RunInstanceAsync(bool ignoreLoginCredentials = false)
|
||||
{
|
||||
_logger.Log("Running instance..." + RealName);
|
||||
if (!ignoreLoginCredentials && AccountInfoViewModel.Credentials.Value is null)
|
||||
{
|
||||
var warningContext = ViewHelperService.GetViewModel<IsLoginCredentialsNullPopupViewModel>()
|
||||
.WithServerEntry(this);
|
||||
|
||||
_currentInstance.RegisterLogger(_currentContentLogConsumer);
|
||||
_currentInstance.RegisterLogger(new DebugLoggerBridge(DebugService.GetLogger($"PROCESS_{Random.Shared.Next(65535)}")));
|
||||
_currentInstance.OnProcessExited += OnProcessExited;
|
||||
RunVisible = false;
|
||||
_currentInstance.Start();
|
||||
PopupMessageService.Popup(warningContext);
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
using var loadingContext = ViewHelperService.GetViewModel<LoadingContextViewModel>();
|
||||
loadingContext.LoadingName = "Loading instance...";
|
||||
((ILoadingHandler)loadingContext).AppendJob();
|
||||
|
||||
PopupMessageService.Popup(loadingContext);
|
||||
_currentInstance =
|
||||
await GameRunnerPreparer.GetGameProcessStartInfoProvider(Address, loadingContext, CancellationService.Token);
|
||||
_logger.Log("Preparing instance...");
|
||||
_currentInstance.RegisterLogger(_currentContentLogConsumer);
|
||||
_currentInstance.RegisterLogger(new DebugLoggerBridge(DebugService.GetLogger($"PROCESS_{Random.Shared.Next(65535)}")));
|
||||
_currentInstance.OnProcessExited += OnProcessExited;
|
||||
RunVisible = false;
|
||||
_currentInstance.Start();
|
||||
_logger.Log("Starting instance..." + RealName);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
var error = new Exception("Error while attempt run instance", e);
|
||||
_logger.Error(error);
|
||||
PopupMessageService.Popup(error);
|
||||
RunVisible = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnProcessExited(ProcessRunHandler<GameProcessStartInfoProvider> obj)
|
||||
@@ -217,35 +246,6 @@ public partial class ServerEntryModelView : ViewModelBase, IFilterConsumer, ILis
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class ContentLogConsumer : IProcessLogConsumer
|
||||
{
|
||||
private readonly LogPopupModelView _currLog;
|
||||
private readonly PopupMessageService _popupMessageService;
|
||||
|
||||
public ContentLogConsumer(LogPopupModelView currLog, PopupMessageService popupMessageService)
|
||||
{
|
||||
_currLog = currLog;
|
||||
_popupMessageService = popupMessageService;
|
||||
}
|
||||
|
||||
public void Out(string text)
|
||||
{
|
||||
_currLog.Append(text);
|
||||
}
|
||||
|
||||
public void Error(string text)
|
||||
{
|
||||
_currLog.Append(text);
|
||||
}
|
||||
|
||||
public void Fatal(string text)
|
||||
{
|
||||
_popupMessageService.Popup("Fatal error while stop instance:" + text);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public class LinkGoCommand : ICommand
|
||||
{
|
||||
public LinkGoCommand()
|
||||
@@ -265,9 +265,4 @@ public class LinkGoCommand : ICommand
|
||||
}
|
||||
|
||||
public event EventHandler? CanExecuteChanged;
|
||||
}
|
||||
|
||||
public interface IFilterConsumer
|
||||
{
|
||||
public void ProcessFilter(ServerFilter? serverFilter);
|
||||
}
|
||||
22
Nebula.Launcher/ViewModels/VisualErrorViewModel.cs
Normal file
22
Nebula.Launcher/ViewModels/VisualErrorViewModel.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using Nebula.Launcher.Views;
|
||||
using Nebula.Shared.ViewHelper;
|
||||
|
||||
namespace Nebula.Launcher.ViewModels;
|
||||
|
||||
|
||||
[ViewModelRegister(typeof(VisualErrorView))]
|
||||
public partial class VisualErrorViewModel : ViewModelBase
|
||||
{
|
||||
[ObservableProperty] private string _imgPath = "cinka";
|
||||
[ObservableProperty] private string _title = "Error";
|
||||
[ObservableProperty] private string _description = "This is an error.";
|
||||
|
||||
protected override void InitialiseInDesignMode()
|
||||
{
|
||||
}
|
||||
|
||||
protected override void Initialise()
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -1,22 +1,11 @@
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Markup.Xaml;
|
||||
using Nebula.Launcher.ViewModels.Pages;
|
||||
|
||||
namespace Nebula.Launcher.Views;
|
||||
|
||||
public partial class FileContentEntryView : UserControl
|
||||
{
|
||||
// This constructor is used when the view is created by the XAML Previewer
|
||||
public FileContentEntryView()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
// This constructor is used when the view is created via dependency injection
|
||||
public FileContentEntryView(FolderContentEntry viewModel)
|
||||
: this()
|
||||
{
|
||||
DataContext = viewModel;
|
||||
}
|
||||
}
|
||||
@@ -8,10 +8,10 @@
|
||||
xmlns:converters="clr-namespace:Nebula.Launcher.Converters"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:models="clr-namespace:Nebula.Shared.Models;assembly=Nebula.Shared"
|
||||
xmlns:viewModels="clr-namespace:Nebula.Launcher.ViewModels"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:models1="clr-namespace:Nebula.Launcher.Models">
|
||||
xmlns:models1="clr-namespace:Nebula.Launcher.Models"
|
||||
xmlns:services="clr-namespace:Nebula.Launcher.Services">
|
||||
<Design.DataContext>
|
||||
<viewModels:MainViewModel />
|
||||
</Design.DataContext>
|
||||
@@ -121,7 +121,41 @@
|
||||
https://durenko.tatar/nebula/
|
||||
</TextBlock>
|
||||
</Button>
|
||||
<TextBlock HorizontalAlignment="Right" VerticalAlignment="Center" Text="{Binding VersionInfo}"/>
|
||||
<StackPanel Spacing="5" HorizontalAlignment="Right" VerticalAlignment="Center" Orientation="Horizontal">
|
||||
<Button
|
||||
Margin="0"
|
||||
Padding="0"
|
||||
CornerRadius="0"
|
||||
Command="{Binding OpenAuthPage}">
|
||||
<StackPanel Spacing="5" Orientation="Horizontal">
|
||||
<Svg
|
||||
Height="40"
|
||||
Path="/Assets/svg/user.svg"
|
||||
Width="10" />
|
||||
<Panel>
|
||||
<TextBlock
|
||||
Foreground="#777777"
|
||||
Text="{Binding LoginText}"/>
|
||||
</Panel>
|
||||
</StackPanel>
|
||||
</Button>
|
||||
<TextBlock>|</TextBlock>
|
||||
<Button
|
||||
Margin="0"
|
||||
Padding="0"
|
||||
CornerRadius="0"
|
||||
Command="{Binding OpenRootPath}">
|
||||
<StackPanel Orientation="Horizontal" Spacing="5">
|
||||
<Svg
|
||||
Height="40"
|
||||
Path="/Assets/svg/folder.svg"
|
||||
Width="10" />
|
||||
<TextBlock Foreground="#777777" Text="{services:LocaledText goto-path-home}"/>
|
||||
</StackPanel>
|
||||
</Button>
|
||||
<TextBlock>|</TextBlock>
|
||||
<TextBlock Text="{Binding VersionInfo}"/>
|
||||
</StackPanel>
|
||||
</Panel>
|
||||
</Label>
|
||||
</Border>
|
||||
|
||||
@@ -1,20 +1,11 @@
|
||||
using Avalonia.Controls;
|
||||
using Nebula.Launcher.ViewModels;
|
||||
|
||||
namespace Nebula.Launcher.Views;
|
||||
|
||||
public partial class MainView : UserControl
|
||||
{
|
||||
// This constructor is used when the view is created by the XAML Previewer
|
||||
public MainView()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
// This constructor is used when the view is created via dependency injection
|
||||
public MainView(MainViewModel viewModel)
|
||||
: this()
|
||||
{
|
||||
DataContext = viewModel;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<UserControl
|
||||
d:DesignHeight="450"
|
||||
d:DesignWidth="800"
|
||||
d:DesignWidth="1000"
|
||||
mc:Ignorable="d"
|
||||
x:Class="Nebula.Launcher.Views.Pages.AccountInfoView"
|
||||
x:DataType="pages:AccountInfoViewModel"
|
||||
@@ -9,7 +9,9 @@
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:pages="clr-namespace:Nebula.Launcher.ViewModels.Pages"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:auth="clr-namespace:Nebula.Launcher.Models.Auth"
|
||||
xmlns:converters="clr-namespace:Nebula.Launcher.Converters">
|
||||
<Design.DataContext>
|
||||
<pages:AccountInfoViewModel />
|
||||
</Design.DataContext>
|
||||
@@ -37,40 +39,58 @@
|
||||
ItemsSource="{Binding Accounts}"
|
||||
Padding="0">
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate DataType="{x:Type pages:ProfileAuthCredentials}">
|
||||
<Border
|
||||
BoxShadow="0 1 15 -2 #121212"
|
||||
CornerRadius="0,10,0,10"
|
||||
Margin="5,5,5,0"
|
||||
VerticalAlignment="Center">
|
||||
<Border.Background>
|
||||
<LinearGradientBrush EndPoint="50%,100%" StartPoint="50%,0%">
|
||||
<GradientStop Color="#292222" Offset="0.0" />
|
||||
<GradientStop Color="#222222" Offset="1.0" />
|
||||
</LinearGradientBrush>
|
||||
</Border.Background>
|
||||
<Panel>
|
||||
<StackPanel Margin="10,5,5,5" Orientation="Horizontal">
|
||||
<DataTemplate DataType="{x:Type auth:ProfileEntry}">
|
||||
<Grid ColumnDefinitions="4*,*">
|
||||
<Border
|
||||
BoxShadow="0 1 15 -2 #121212"
|
||||
CornerRadius="0,10,0,10"
|
||||
Margin="5,5,5,0">
|
||||
<Border.Background>
|
||||
<LinearGradientBrush EndPoint="100%,50%" StartPoint="20%,50%">
|
||||
<GradientStop Color="{Binding Credentials.AuthServer,
|
||||
Converter={x:Static converters:TypeConverters.NameColorRepresentation}}" Offset="0.0" />
|
||||
<GradientStop Color="#222222" Offset="1.0" />
|
||||
</LinearGradientBrush>
|
||||
</Border.Background>
|
||||
<Label>
|
||||
<TextBlock Text="{Binding AuthName}" Margin="5"/>
|
||||
</Label>
|
||||
</Border>
|
||||
<Border Grid.Column="0"
|
||||
CornerRadius="0,10,0,10"
|
||||
Margin="5,5,5,0">
|
||||
<Border.Background>
|
||||
<LinearGradientBrush EndPoint="100%,50%" StartPoint="20%,50%">
|
||||
<GradientStop Color="#aa222222" Offset="0.0" />
|
||||
<GradientStop Color="#222222" Offset="0.4" />
|
||||
</LinearGradientBrush>
|
||||
</Border.Background>
|
||||
<Button
|
||||
HorizontalAlignment="Stretch"
|
||||
Command="{Binding OnSelect}">
|
||||
<Label>
|
||||
<TextBlock Text="{Binding Login}" />
|
||||
<TextBlock Text="{Binding Credentials.Login}" HorizontalAlignment="Right" VerticalAlignment="Center" Margin="0,0,5,0"/>
|
||||
</Label>
|
||||
</StackPanel>
|
||||
<StackPanel HorizontalAlignment="Right" Orientation="Horizontal">
|
||||
<Button
|
||||
Command="{Binding OnSelect}"
|
||||
CornerRadius="0,0,0,10"
|
||||
Padding="5">
|
||||
<customControls:LocalizedLabel LocalId="account-profile-select"/>
|
||||
</Button>
|
||||
<Button
|
||||
Command="{Binding OnDelete}"
|
||||
CornerRadius="0,10,0,0"
|
||||
Padding="5">
|
||||
<customControls:LocalizedLabel LocalId="account-profile-delete"/>
|
||||
</Button>
|
||||
</StackPanel>
|
||||
</Panel>
|
||||
</Border>
|
||||
</Button>
|
||||
</Border>
|
||||
<Border
|
||||
BoxShadow="0 1 15 -2 #121212"
|
||||
CornerRadius="0,10,0,10"
|
||||
Margin="0,5,5,0" Grid.Column="1" Padding="0">
|
||||
<Border.Background>
|
||||
<LinearGradientBrush EndPoint="100%,50%" StartPoint="20%,50%">
|
||||
<GradientStop Color="#292222" Offset="1.0" />
|
||||
<GradientStop Color="#222222" Offset="1.0" />
|
||||
</LinearGradientBrush>
|
||||
</Border.Background>
|
||||
<Button Command="{Binding OnDelete}" CornerRadius="0,10,0,10" HorizontalAlignment="Stretch">
|
||||
<Svg
|
||||
Height="15"
|
||||
Path="/Assets/svg/delete.svg"
|
||||
Width="15" />
|
||||
</Button>
|
||||
</Border>
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
@@ -120,7 +140,7 @@
|
||||
</StackPanel>
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<customControls:LocalizedLabel VerticalAlignment="Center" LocalId="account-auth-server"/>
|
||||
<Button Command="{Binding ExpandAuthUrlCommand}" VerticalAlignment="Stretch">
|
||||
<Button Command="{Binding OnExpandAuthUrl}" VerticalAlignment="Stretch">
|
||||
<Label>+</Label>
|
||||
</Button>
|
||||
</StackPanel>
|
||||
@@ -155,15 +175,7 @@
|
||||
<customControls:LocalizedLabel LocalId="account-auth-button"/>
|
||||
</Button>
|
||||
</Border>
|
||||
<Border BoxShadow="{StaticResource DefaultShadow}">
|
||||
<Button
|
||||
Command="{Binding SaveProfileCommand}"
|
||||
HorizontalAlignment="Stretch"
|
||||
HorizontalContentAlignment="Center">
|
||||
<customControls:LocalizedLabel LocalId="account-auth-save"/>
|
||||
</Button>
|
||||
</Border>
|
||||
<Button Command="{Binding ExpandAuthViewCommand}" HorizontalAlignment="Right">
|
||||
<Button Command="{Binding OnExpandAuthView}" HorizontalAlignment="Right">
|
||||
<Label>
|
||||
>
|
||||
</Label>
|
||||
@@ -176,9 +188,15 @@
|
||||
Margin="0,0,0,20"
|
||||
Path="/Assets/svg/user.svg" />
|
||||
<Label>
|
||||
<StackPanel HorizontalAlignment="Center" Orientation="Horizontal">
|
||||
<customControls:LocalizedLabel LocalId="account-auth-hello"/>
|
||||
<TextBlock Text="{Binding CurrentLogin}" />
|
||||
<StackPanel>
|
||||
<StackPanel HorizontalAlignment="Center" Orientation="Horizontal" Spacing="5">
|
||||
<customControls:LocalizedLabel LocalId="account-auth-hello"/>
|
||||
<TextBlock Text="{Binding Credentials.Value.Login}" />
|
||||
</StackPanel>
|
||||
<StackPanel HorizontalAlignment="Center" Orientation="Horizontal" Spacing="5">
|
||||
<customControls:LocalizedLabel LocalId="account-auth-current-server"/>
|
||||
<TextBlock Text="{Binding Credentials.Value.AuthServer}" />
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
</Label>
|
||||
<StackPanel
|
||||
@@ -191,8 +209,10 @@
|
||||
<customControls:LocalizedLabel LocalId="account-auth-logout"/>
|
||||
</Button>
|
||||
</Border>
|
||||
<Border BoxShadow="{StaticResource DefaultShadow}">
|
||||
<Button Command="{Binding SaveProfileCommand}">
|
||||
<Border BoxShadow="{StaticResource DefaultShadow}"
|
||||
IsVisible="{Binding CurrentPassword,
|
||||
Converter={x:Static converters:TypeConverters.StringIsNotEmpty}}">
|
||||
<Button Command="{Binding OnSaveProfile}">
|
||||
<customControls:LocalizedLabel LocalId="account-auth-save"/>
|
||||
</Button>
|
||||
</Border>
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using Avalonia.Controls;
|
||||
using AccountInfoViewModel = Nebula.Launcher.ViewModels.Pages.AccountInfoViewModel;
|
||||
|
||||
namespace Nebula.Launcher.Views.Pages;
|
||||
|
||||
@@ -9,10 +8,4 @@ public partial class AccountInfoView : UserControl
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public AccountInfoView(AccountInfoViewModel viewModel)
|
||||
: this()
|
||||
{
|
||||
DataContext = viewModel;
|
||||
}
|
||||
}
|
||||
@@ -22,7 +22,8 @@
|
||||
</ItemsPanelTemplate>
|
||||
</ItemsControl.ItemsPanel>
|
||||
</ItemsControl>
|
||||
<StackPanel Orientation="Horizontal" Spacing="5">
|
||||
|
||||
<WrapPanel Orientation="Horizontal">
|
||||
<Button
|
||||
Classes="ConfigBorder"
|
||||
VerticalAlignment="Bottom"
|
||||
@@ -60,7 +61,17 @@
|
||||
Command="{Binding ExportLogs}">
|
||||
<customControls:LocalizedLabel LocalId="config-export-logs"/>
|
||||
</Button>
|
||||
</StackPanel>
|
||||
|
||||
<Button
|
||||
Classes="ConfigBorder"
|
||||
VerticalAlignment="Bottom"
|
||||
HorizontalAlignment="Stretch"
|
||||
Padding="5"
|
||||
Margin="5"
|
||||
Command="{Binding RemoveAllContent}">
|
||||
<customControls:LocalizedLabel LocalId="config-remove-content-all"/>
|
||||
</Button>
|
||||
</WrapPanel>
|
||||
</StackPanel>
|
||||
</ScrollViewer>
|
||||
</UserControl>
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Markup.Xaml;
|
||||
using Nebula.Launcher.ViewModels.Pages;
|
||||
|
||||
namespace Nebula.Launcher.Views.Pages;
|
||||
|
||||
@@ -11,10 +8,4 @@ public partial class ConfigurationView : UserControl
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public ConfigurationView(ConfigurationViewModel viewModel)
|
||||
: this()
|
||||
{
|
||||
DataContext = viewModel;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
using Avalonia.Controls;
|
||||
using ContentBrowserViewModel = Nebula.Launcher.ViewModels.Pages.ContentBrowserViewModel;
|
||||
|
||||
namespace Nebula.Launcher.Views.Pages;
|
||||
|
||||
@@ -9,10 +8,4 @@ public partial class ContentBrowserView : UserControl
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public ContentBrowserView(ContentBrowserViewModel viewModel)
|
||||
: this()
|
||||
{
|
||||
DataContext = viewModel;
|
||||
}
|
||||
}
|
||||
@@ -71,7 +71,6 @@
|
||||
<TextBox
|
||||
Margin="25,0,0,0"
|
||||
Text="{Binding SearchText}"
|
||||
TextChanged="TextBox_OnTextChanged"
|
||||
VerticalAlignment="Center"
|
||||
Watermark="{services:LocaledText 'server-search'}" />
|
||||
<Button
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
using Avalonia.Controls;
|
||||
using Nebula.Launcher.ViewModels.Pages;
|
||||
|
||||
namespace Nebula.Launcher.Views.Pages;
|
||||
|
||||
public partial class ServerOverviewView : UserControl
|
||||
{
|
||||
// This constructor is used when the view is created by the XAML Previewer
|
||||
public ServerOverviewView()
|
||||
{
|
||||
InitializeComponent();
|
||||
@@ -19,17 +17,4 @@ public partial class ServerOverviewView : UserControl
|
||||
LanguageFilters.AddFilter("RU","lang:ru");
|
||||
LanguageFilters.AddFilter("EN","lang:en");
|
||||
}
|
||||
|
||||
// This constructor is used when the view is created via dependency injection
|
||||
public ServerOverviewView(ServerOverviewModel viewModel)
|
||||
: this()
|
||||
{
|
||||
DataContext = viewModel;
|
||||
}
|
||||
|
||||
private void TextBox_OnTextChanged(object? sender, TextChangedEventArgs e)
|
||||
{
|
||||
var context = (ServerOverviewModel?)DataContext;
|
||||
context?.OnSearchChange?.Invoke();
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
using Avalonia.Controls;
|
||||
using Nebula.Launcher.ViewModels.Popup;
|
||||
|
||||
namespace Nebula.Launcher.Views.Popup;
|
||||
|
||||
@@ -9,10 +8,4 @@ public partial class AddFavoriteView : UserControl
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public AddFavoriteView(AddFavoriteViewModel viewModel)
|
||||
: this()
|
||||
{
|
||||
DataContext = viewModel;
|
||||
}
|
||||
}
|
||||
@@ -23,5 +23,10 @@
|
||||
<customControls:LocalizedLabel HorizontalAlignment="Center" LocalId="servername-set"/>
|
||||
</Button>
|
||||
</Border>
|
||||
<Border Background="{StaticResource DefaultSelected}" BoxShadow="{StaticResource DefaultShadow}">
|
||||
<Button Command="{Binding OnClear}" HorizontalAlignment="Stretch">
|
||||
<customControls:LocalizedLabel HorizontalAlignment="Center" LocalId="servername-clear"/>
|
||||
</Button>
|
||||
</Border>
|
||||
</StackPanel>
|
||||
</UserControl>
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Markup.Xaml;
|
||||
using Nebula.Launcher.ViewModels.Popup;
|
||||
|
||||
namespace Nebula.Launcher.Views.Popup;
|
||||
|
||||
@@ -11,10 +8,4 @@ public partial class EditServerNameView : UserControl
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public EditServerNameView(EditServerNameViewModel viewModel)
|
||||
: this()
|
||||
{
|
||||
DataContext = viewModel;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
using Avalonia.Controls;
|
||||
using Nebula.Launcher.ViewModels.Popup;
|
||||
|
||||
namespace Nebula.Launcher.Views.Popup;
|
||||
|
||||
@@ -9,9 +8,4 @@ public partial class ExceptionListView : UserControl
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public ExceptionListView(ExceptionListViewModel listViewModel) : this()
|
||||
{
|
||||
DataContext = listViewModel;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
using Avalonia.Controls;
|
||||
using InfoPopupViewModel = Nebula.Launcher.ViewModels.Popup.InfoPopupViewModel;
|
||||
|
||||
namespace Nebula.Launcher.Views.Popup;
|
||||
|
||||
@@ -9,9 +8,4 @@ public partial class InfoPopupView : UserControl
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public InfoPopupView(InfoPopupViewModel viewModel) : this()
|
||||
{
|
||||
DataContext = viewModel;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<UserControl xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:popup="clr-namespace:Nebula.Launcher.ViewModels.Popup"
|
||||
xmlns:controls="clr-namespace:Nebula.Launcher.Controls"
|
||||
xmlns:services="clr-namespace:Nebula.Launcher.Services"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
x:Class="Nebula.Launcher.Views.Popup.IsLoginCredentialsNullPopupView"
|
||||
x:DataType="popup:IsLoginCredentialsNullPopupViewModel">
|
||||
<Design.DataContext>
|
||||
<popup:IsLoginCredentialsNullPopupViewModel />
|
||||
</Design.DataContext>
|
||||
|
||||
<StackPanel Margin="15" Orientation="Vertical" Spacing="15">
|
||||
<TextBlock HorizontalAlignment="Center" Text="{services:LocaledText popup-login-credentials-warning-label}" TextWrapping="Wrap"/>
|
||||
<StackPanel HorizontalAlignment="Center" Orientation="Horizontal" Spacing="5">
|
||||
<Border Background="{StaticResource DefaultSelected}" BoxShadow="{StaticResource DefaultShadow}">
|
||||
<Button Command="{Binding GotoAuthPage}">
|
||||
<TextBlock Text="{services:LocaledText popup-login-credentials-warning-go-auth}"/>
|
||||
</Button>
|
||||
</Border>
|
||||
<Border Background="{StaticResource DefaultSelected}" BoxShadow="{StaticResource DefaultShadow}">
|
||||
<Button Command="{Binding Cancel}">
|
||||
<TextBlock Text="{services:LocaledText popup-login-credentials-warning-cancel}"/>
|
||||
</Button>
|
||||
</Border>
|
||||
<Border Background="{StaticResource DefaultSelected}" BoxShadow="{StaticResource DefaultShadow}">
|
||||
<Button Command="{Binding Proceed}">
|
||||
<TextBlock Text="{services:LocaledText popup-login-credentials-warning-proceed}"/>
|
||||
</Button>
|
||||
</Border>
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,11 @@
|
||||
using Avalonia.Controls;
|
||||
|
||||
namespace Nebula.Launcher.Views.Popup;
|
||||
|
||||
public partial class IsLoginCredentialsNullPopupView : UserControl
|
||||
{
|
||||
public IsLoginCredentialsNullPopupView()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
@@ -33,5 +33,10 @@
|
||||
<customControls:LocalizedLabel LocalId="task-cancel"/>
|
||||
</Button>
|
||||
</Panel>
|
||||
<Panel>
|
||||
<Border Background="{StaticResource DefaultForeground}" MinHeight="210">
|
||||
<TextBlock TextWrapping="Wrap" Text="{Binding Message}" MaxLines="10" Margin="15"/>
|
||||
</Border>
|
||||
</Panel>
|
||||
</StackPanel>
|
||||
</UserControl>
|
||||
@@ -1,5 +1,4 @@
|
||||
using Avalonia.Controls;
|
||||
using LoadingContextViewModel = Nebula.Launcher.ViewModels.Popup.LoadingContextViewModel;
|
||||
|
||||
namespace Nebula.Launcher.Views.Popup;
|
||||
|
||||
@@ -9,9 +8,4 @@ public partial class LoadingContextView : UserControl
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public LoadingContextView(LoadingContextViewModel viewModel) : this()
|
||||
{
|
||||
DataContext = viewModel;
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:viewModels="clr-namespace:Nebula.Launcher.ViewModels"
|
||||
xmlns:popup="clr-namespace:Nebula.Launcher.ViewModels.Popup"
|
||||
xmlns:models="clr-namespace:Nebula.Launcher.Models"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
x:Class="Nebula.Launcher.Views.Popup.LogPopupView"
|
||||
x:DataType="popup:LogPopupModelView">
|
||||
@@ -17,7 +18,7 @@
|
||||
ItemsSource="{Binding Logs}"
|
||||
Padding="0">
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate DataType="{x:Type popup:LogInfo}">
|
||||
<DataTemplate DataType="{x:Type models:LogInfo}">
|
||||
<Border CornerRadius="5" Margin="0,0,0,5">
|
||||
<StackPanel Orientation="Horizontal" Spacing="5" Margin="0">
|
||||
<Border MinWidth="100"
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using Avalonia.Controls;
|
||||
using Nebula.Launcher.ViewModels.Popup;
|
||||
|
||||
namespace Nebula.Launcher.Views.Popup;
|
||||
|
||||
@@ -9,9 +8,4 @@ public partial class LogPopupView : UserControl
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public LogPopupView(LogPopupModelView viewModel) : this()
|
||||
{
|
||||
DataContext = viewModel;
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Input;
|
||||
using Avalonia.Interactivity;
|
||||
using Avalonia.Markup.Xaml;
|
||||
using Nebula.Launcher.ViewModels.Popup;
|
||||
|
||||
namespace Nebula.Launcher.Views.Popup;
|
||||
@@ -88,11 +85,6 @@ public partial class TfaView : UserControl
|
||||
return (TextBox)box.Child!;
|
||||
}
|
||||
|
||||
public TfaView(TfaViewModel tfaViewModel) : this()
|
||||
{
|
||||
DataContext = tfaViewModel;
|
||||
}
|
||||
|
||||
private void Button_OnClick(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
CheckupCode();
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using Avalonia.Controls;
|
||||
using Nebula.Launcher.ViewModels;
|
||||
|
||||
namespace Nebula.Launcher.Views;
|
||||
|
||||
@@ -9,9 +8,4 @@ public partial class ServerCompoundEntryView : UserControl
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public ServerCompoundEntryView(ServerCompoundEntryViewModel viewModel) : this()
|
||||
{
|
||||
DataContext = viewModel;
|
||||
}
|
||||
}
|
||||
@@ -22,10 +22,7 @@ public partial class ServerEntryView : UserControl
|
||||
StartAutoScrolling();
|
||||
}
|
||||
|
||||
public ServerEntryView(ServerEntryModelView modelView) : this()
|
||||
{
|
||||
DataContext = modelView;
|
||||
}
|
||||
|
||||
|
||||
private void StartAutoScrolling()
|
||||
{
|
||||
|
||||
39
Nebula.Launcher/Views/VisualErrorView.axaml
Normal file
39
Nebula.Launcher/Views/VisualErrorView.axaml
Normal file
@@ -0,0 +1,39 @@
|
||||
<UserControl xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:viewModels="clr-namespace:Nebula.Launcher.ViewModels"
|
||||
xmlns:converters="clr-namespace:Nebula.Launcher.Converters"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
x:DataType="viewModels:VisualErrorViewModel"
|
||||
x:Class="Nebula.Launcher.Views.VisualErrorView">
|
||||
<Design.DataContext>
|
||||
<viewModels:VisualErrorViewModel />
|
||||
</Design.DataContext>
|
||||
<Grid RowDefinitions="30,*" ColumnDefinitions="200,*">
|
||||
<Border Grid.Row="1" Grid.Column="0"
|
||||
CornerRadius="10,0,0,10"
|
||||
BorderThickness="0,0,2,0"
|
||||
BorderBrush="{StaticResource DefaultForeground}">
|
||||
<Image Source="{Binding ImgPath, Converter={x:Static converters:TypeConverters.ImageConverter}}" Width="200" Height="200"/>
|
||||
</Border>
|
||||
<Border Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" CornerRadius="10,10,0,0">
|
||||
<Border.Background>
|
||||
<LinearGradientBrush EndPoint="100%,50%" StartPoint="10%,20%">
|
||||
<GradientStop Color="#FF6B6B" Offset="0.0" />
|
||||
<GradientStop Color="#FF8E53" Offset="0.3" />
|
||||
<GradientStop Color="#FF5E3A" Offset="0.6" />
|
||||
<GradientStop Color="#FF5e5e" Offset="1.0" />
|
||||
</LinearGradientBrush>
|
||||
</Border.Background>
|
||||
<Label HorizontalAlignment="Center"><TextBlock Text="{Binding Title}"/></Label>
|
||||
</Border>
|
||||
<TextBlock
|
||||
Grid.Row="1"
|
||||
Grid.Column="1"
|
||||
Margin="15"
|
||||
HorizontalAlignment="Center"
|
||||
TextWrapping="Wrap"
|
||||
Text="{Binding Description}"/>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
11
Nebula.Launcher/Views/VisualErrorView.axaml.cs
Normal file
11
Nebula.Launcher/Views/VisualErrorView.axaml.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
using Avalonia.Controls;
|
||||
|
||||
namespace Nebula.Launcher.Views;
|
||||
|
||||
public partial class VisualErrorView : UserControl
|
||||
{
|
||||
public VisualErrorView()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,19 @@
|
||||
using Nebula.Runner.Services;
|
||||
using Nebula.Shared;
|
||||
using Nebula.Shared.Models;
|
||||
using Nebula.Shared.Services;
|
||||
using Nebula.Shared.Services.Logging;
|
||||
using Nebula.Shared.Utils;
|
||||
using Robust.LoaderApi;
|
||||
|
||||
namespace Nebula.Runner;
|
||||
|
||||
[ServiceRegister]
|
||||
public sealed class App(RunnerService runnerService, ContentService contentService)
|
||||
public sealed class App(RunnerService runnerService, ContentService contentService, DebugService debugService)
|
||||
: IRedialApi
|
||||
{
|
||||
public ILogger logger = debugService.GetLogger("Runner");
|
||||
|
||||
public void Redial(Uri uri, string text = "")
|
||||
{
|
||||
}
|
||||
@@ -20,98 +24,37 @@ public sealed class App(RunnerService runnerService, ContentService contentServi
|
||||
var urlraw = Environment.GetEnvironmentVariable("GAME_URL") ?? "ss14://localhost";
|
||||
|
||||
var url = urlraw.ToRobustUrl();
|
||||
|
||||
using var cancelTokenSource = new CancellationTokenSource();
|
||||
var buildInfo = await contentService.GetBuildInfo(url, cancelTokenSource.Token);
|
||||
|
||||
|
||||
var args = new List<string>
|
||||
|
||||
try
|
||||
{
|
||||
// Pass username to launched client.
|
||||
// We don't load username from client_config.toml when launched via launcher.
|
||||
"--username", login,
|
||||
using var cancelTokenSource = new CancellationTokenSource();
|
||||
var buildInfo = await contentService.GetBuildInfo(url, cancelTokenSource.Token);
|
||||
|
||||
// Tell game we are launcher
|
||||
"--cvar", "launch.launcher=true"
|
||||
};
|
||||
|
||||
var connectionString = url.ToString();
|
||||
if (!string.IsNullOrEmpty(buildInfo.BuildInfo.ConnectAddress))
|
||||
connectionString = buildInfo.BuildInfo.ConnectAddress;
|
||||
var args = new List<string>
|
||||
{
|
||||
"--username", login,
|
||||
"--cvar", "launch.launcher=true"
|
||||
};
|
||||
|
||||
// We are using the launcher. Don't show main menu etc..
|
||||
// Note: --launcher also implied --connect.
|
||||
// For this reason, content bundles do not set --launcher.
|
||||
args.Add("--launcher");
|
||||
var connectionString = url.ToString();
|
||||
if (!string.IsNullOrEmpty(buildInfo.BuildInfo.ConnectAddress))
|
||||
connectionString = buildInfo.BuildInfo.ConnectAddress;
|
||||
|
||||
args.Add("--launcher");
|
||||
|
||||
args.Add("--connect-address");
|
||||
args.Add(connectionString);
|
||||
args.Add("--connect-address");
|
||||
args.Add(connectionString);
|
||||
|
||||
args.Add("--ss14-address");
|
||||
args.Add(url.ToString());
|
||||
args.Add("--ss14-address");
|
||||
args.Add(url.ToString());
|
||||
|
||||
await runnerService.Run(args.ToArray(), buildInfo, this, new ConsoleLoadingHandler(), cancelTokenSource.Token);
|
||||
await runnerService.Run(args.ToArray(), buildInfo, this, new ConsoleLoadingHandler(), cancelTokenSource.Token);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
logger.Error(e);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class ConsoleLoadingHandler : ILoadingHandler
|
||||
{
|
||||
private int _currJobs;
|
||||
|
||||
private float _percent;
|
||||
private int _resolvedJobs;
|
||||
|
||||
public void SetJobsCount(int count)
|
||||
{
|
||||
_currJobs = count;
|
||||
|
||||
UpdatePercent();
|
||||
Draw();
|
||||
}
|
||||
|
||||
public int GetJobsCount()
|
||||
{
|
||||
return _currJobs;
|
||||
}
|
||||
|
||||
public void SetResolvedJobsCount(int count)
|
||||
{
|
||||
_resolvedJobs = count;
|
||||
|
||||
UpdatePercent();
|
||||
Draw();
|
||||
}
|
||||
|
||||
public int GetResolvedJobsCount()
|
||||
{
|
||||
return _resolvedJobs;
|
||||
}
|
||||
|
||||
private void UpdatePercent()
|
||||
{
|
||||
if (_currJobs == 0)
|
||||
{
|
||||
_percent = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
if (_resolvedJobs > _currJobs) return;
|
||||
|
||||
_percent = _resolvedJobs / (float)_currJobs;
|
||||
}
|
||||
|
||||
private void Draw()
|
||||
{
|
||||
var barCount = 10;
|
||||
var fullCount = (int)(barCount * _percent);
|
||||
var emptyCount = barCount - fullCount;
|
||||
|
||||
Console.Write("\r");
|
||||
|
||||
for (var i = 0; i < fullCount; i++) Console.Write("#");
|
||||
|
||||
for (var i = 0; i < emptyCount; i++) Console.Write(" ");
|
||||
|
||||
Console.Write($"\t {_resolvedJobs}/{_currJobs}");
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,7 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Lib.Harmony" Version="2.3.6" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.0"/>
|
||||
<PackageReference Include="SharpZstd.Interop" Version="1.5.6"/>
|
||||
</ItemGroup>
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Nebula.Shared;
|
||||
using Nebula.Shared.Services;
|
||||
|
||||
namespace Nebula.Runner;
|
||||
|
||||
|
||||
54
Nebula.Runner/Services/HarmonyService.cs
Normal file
54
Nebula.Runner/Services/HarmonyService.cs
Normal file
@@ -0,0 +1,54 @@
|
||||
using System.Data;
|
||||
using HarmonyLib;
|
||||
using Nebula.Shared;
|
||||
|
||||
namespace Nebula.Runner.Services;
|
||||
|
||||
[ServiceRegister]
|
||||
public class HarmonyService(ReflectionService reflectionService)
|
||||
{
|
||||
private HarmonyInstance? _instance;
|
||||
|
||||
public HarmonyInstance Instance
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_instance is null)
|
||||
CreateInstance();
|
||||
return _instance!;
|
||||
}
|
||||
}
|
||||
|
||||
public void CreateInstance()
|
||||
{
|
||||
if (_instance is not null)
|
||||
throw new Exception();
|
||||
|
||||
_instance = new HarmonyInstance();
|
||||
UnShittyWizard();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Я помню пенис большой,Я помню пенис большой, Я помню пенис большой, я помню....
|
||||
/// </summary>
|
||||
private void UnShittyWizard()
|
||||
{
|
||||
var method = reflectionService.GetType("Robust.Client.GameController").TypeInitializer;
|
||||
_instance!.Harmony.Patch(method, new HarmonyMethod(Prefix));
|
||||
}
|
||||
|
||||
static bool Prefix()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public class HarmonyInstance
|
||||
{
|
||||
public readonly Harmony Harmony;
|
||||
|
||||
internal HarmonyInstance()
|
||||
{
|
||||
Harmony = new Harmony("ru.cinka.patch");
|
||||
}
|
||||
}
|
||||
59
Nebula.Runner/Services/ReflectionService.cs
Normal file
59
Nebula.Runner/Services/ReflectionService.cs
Normal file
@@ -0,0 +1,59 @@
|
||||
using System.Reflection;
|
||||
using Nebula.Shared;
|
||||
using Nebula.Shared.FileApis;
|
||||
using Nebula.Shared.Services;
|
||||
|
||||
namespace Nebula.Runner.Services;
|
||||
|
||||
[ServiceRegister]
|
||||
public class ReflectionService(AssemblyService assemblyService)
|
||||
{
|
||||
private Dictionary<string, Assembly> _typeCache = new();
|
||||
|
||||
public void RegisterAssembly(Assembly robustAssembly)
|
||||
{
|
||||
_typeCache.Add(robustAssembly.GetName().Name!, robustAssembly);
|
||||
}
|
||||
|
||||
public void RegisterRobustAssemblies(AssemblyApi engine)
|
||||
{
|
||||
RegisterAssembly(GetRobustAssembly("Robust.Shared", engine));
|
||||
RegisterAssembly(GetRobustAssembly("Robust.Client", engine));
|
||||
}
|
||||
|
||||
private Assembly GetRobustAssembly(string assemblyName, AssemblyApi engine)
|
||||
{
|
||||
if(!assemblyService.TryOpenAssembly(assemblyName, engine, out var assembly))
|
||||
throw new Exception($"Unable to locate {assemblyName}.dll in engine build!");
|
||||
return assembly;
|
||||
}
|
||||
|
||||
public Type? GetTypeImp(string name)
|
||||
{
|
||||
foreach (var (prefix,assembly) in _typeCache)
|
||||
{
|
||||
string appendedName = prefix + name;
|
||||
var theType = assembly.GetType(appendedName);
|
||||
if (theType != null)
|
||||
{
|
||||
return theType;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public Type GetType(string name)
|
||||
{
|
||||
var prefix = ExtrackPrefix(name);
|
||||
return !_typeCache.TryGetValue(prefix, out var assembly)
|
||||
? GetTypeImp(name)!
|
||||
: assembly.GetType(name)!;
|
||||
}
|
||||
|
||||
private string ExtrackPrefix(string path)
|
||||
{
|
||||
var sp = path.Split(".");
|
||||
return sp[0] + "." + sp[1];
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,14 @@
|
||||
using Nebula.Shared.Models;
|
||||
using System.Globalization;
|
||||
using System.Reflection;
|
||||
using System.Reflection.Emit;
|
||||
using HarmonyLib;
|
||||
using Nebula.Shared;
|
||||
using Nebula.Shared.Models;
|
||||
using Nebula.Shared.Services;
|
||||
using Nebula.Shared.Services.Logging;
|
||||
using Robust.LoaderApi;
|
||||
|
||||
namespace Nebula.Shared.Services;
|
||||
namespace Nebula.Runner.Services;
|
||||
|
||||
[ServiceRegister]
|
||||
public sealed class RunnerService(
|
||||
@@ -10,9 +16,12 @@ public sealed class RunnerService(
|
||||
DebugService debugService,
|
||||
ConfigurationService varService,
|
||||
EngineService engineService,
|
||||
AssemblyService assemblyService)
|
||||
AssemblyService assemblyService,
|
||||
ReflectionService reflectionService,
|
||||
HarmonyService harmonyService)
|
||||
{
|
||||
private ILogger _logger = debugService.GetLogger("RunnerService");
|
||||
private bool MetricEnabled = false; //TODO: ADD METRIC THINKS LATER
|
||||
|
||||
public async Task Run(string[] runArgs, RobustBuildInfo buildInfo, IRedialApi redialApi,
|
||||
ILoadingHandler loadingHandler,
|
||||
@@ -52,11 +61,82 @@ public sealed class RunnerService(
|
||||
if (!assemblyService.TryOpenAssembly(varService.GetConfigValue(CurrentConVar.RobustAssemblyName)!, engine,
|
||||
out var clientAssembly))
|
||||
throw new Exception("Unable to locate Robust.Client.dll in engine build!");
|
||||
|
||||
|
||||
if (!assemblyService.TryGetLoader(clientAssembly, out var loader))
|
||||
return;
|
||||
|
||||
if(!assemblyService.TryOpenAssembly("Prometheus.NetStandard", engine, out var prometheusAssembly))
|
||||
return;
|
||||
|
||||
reflectionService.RegisterRobustAssemblies(engine);
|
||||
harmonyService.CreateInstance();
|
||||
|
||||
IDisposable? metricServer = null;
|
||||
|
||||
if (MetricEnabled)
|
||||
{
|
||||
MetricsEnabledPatcher.ApplyPatch(reflectionService, harmonyService);
|
||||
metricServer = RunHelper.RunMetric(prometheusAssembly);
|
||||
}
|
||||
|
||||
|
||||
await Task.Run(() => loader.Main(args), cancellationToken);
|
||||
|
||||
metricServer?.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
public static class MetricsEnabledPatcher
|
||||
{
|
||||
public static void ApplyPatch(ReflectionService reflectionService, HarmonyService harmonyService)
|
||||
{
|
||||
var harmony = harmonyService.Instance.Harmony;
|
||||
|
||||
var targetType = reflectionService.GetType("Robust.Shared.GameObjects.EntitySystemManager");
|
||||
var targetMethod = targetType.GetProperty("MetricsEnabled")?.GetGetMethod() ??
|
||||
throw new Exception("target method is null.. huh.. do we have patch a right think?");
|
||||
|
||||
var prefix = typeof(MetricsEnabledPatcher).GetMethod(nameof(MetricsEnabledGetterPrefix),
|
||||
BindingFlags.Static | BindingFlags.NonPublic);
|
||||
|
||||
var prefixMethod = new HarmonyMethod(prefix);
|
||||
|
||||
harmony.Patch(targetMethod, prefix: prefixMethod);
|
||||
}
|
||||
|
||||
private static bool MetricsEnabledGetterPrefix(ref bool __result)
|
||||
{
|
||||
__result = true;
|
||||
return false; // Skip original method
|
||||
}
|
||||
}
|
||||
|
||||
public static class RunHelper
|
||||
{
|
||||
public static IDisposable RunMetric(Assembly prometheusAssembly)
|
||||
{
|
||||
var metricServerType = prometheusAssembly.GetType("Prometheus.MetricServer");
|
||||
var collectorRegistryType = prometheusAssembly.GetType("Prometheus.CollectorRegistry");
|
||||
|
||||
var ctor = metricServerType!.GetConstructor(new Type[]
|
||||
{
|
||||
typeof(string),
|
||||
typeof(int),
|
||||
typeof(string),
|
||||
collectorRegistryType!,
|
||||
typeof(bool)
|
||||
});
|
||||
|
||||
var hostname = "localhost";
|
||||
var port = 51235;
|
||||
var url = "metrics/";
|
||||
object? registry = null;
|
||||
var useHttps = false;
|
||||
|
||||
var metricServerInstance = ctor!.Invoke(new object[] { hostname, port, url, registry!, useHttps });
|
||||
metricServerType.GetMethod("Start")!.Invoke(metricServerInstance, BindingFlags.Default, null, null, CultureInfo.CurrentCulture);
|
||||
|
||||
return (IDisposable)metricServerInstance;
|
||||
}
|
||||
}
|
||||
|
||||
47
Nebula.Shared/ConfigMigrations/ProfileMigration.cs
Normal file
47
Nebula.Shared/ConfigMigrations/ProfileMigration.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Nebula.Shared.Configurations.Migrations;
|
||||
using Nebula.Shared.Models;
|
||||
using Nebula.Shared.Services;
|
||||
using Nebula.Shared.Utils;
|
||||
|
||||
namespace Nebula.Shared.ConfigMigrations;
|
||||
|
||||
public class ProfileMigrationV2(string oldName, string newName)
|
||||
: BaseConfigurationMigration<ProfileAuthCredentials[], string[]>(oldName, newName)
|
||||
{
|
||||
protected override async Task<string[]> Migrate(IServiceProvider serviceProvider, ProfileAuthCredentials[] oldValue, ILoadingHandler loadingHandler)
|
||||
{
|
||||
loadingHandler.SetLoadingMessage("Migrating Profile V2 -> V4");
|
||||
var list = new List<string>();
|
||||
var authService = serviceProvider.GetRequiredService<AuthService>();
|
||||
var logger = serviceProvider.GetRequiredService<DebugService>().GetLogger("ProfileMigrationV2");
|
||||
foreach (var oldCredentials in oldValue)
|
||||
{
|
||||
try
|
||||
{
|
||||
loadingHandler.SetLoadingMessage($"Migrating {oldCredentials.Login}");
|
||||
await authService.Auth(oldCredentials.Login, oldCredentials.Password, oldCredentials.AuthServer);
|
||||
list.Add(CryptographicStore.Encrypt(oldCredentials, CryptographicStore.GetComputerKey()));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
logger.Error(e);
|
||||
loadingHandler.SetLoadingMessage(e.Message);
|
||||
}
|
||||
}
|
||||
|
||||
loadingHandler.SetLoadingMessage("Migration done!");
|
||||
return list.ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
public class ProfileMigrationV3V4(string oldName, string newName)
|
||||
: BaseConfigurationMigration<AuthTokenCredentials[], string[]>(oldName, newName)
|
||||
{
|
||||
protected override Task<string[]> Migrate(IServiceProvider serviceProvider, AuthTokenCredentials[] oldValue, ILoadingHandler loadingHandler)
|
||||
{
|
||||
Console.WriteLine("Removing profile v3 because no password is provided");
|
||||
return Task.FromResult(Array.Empty<string>());
|
||||
}
|
||||
}
|
||||
|
||||
18
Nebula.Shared/Configurations/ConVar.cs
Normal file
18
Nebula.Shared/Configurations/ConVar.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using Nebula.Shared.Services;
|
||||
|
||||
namespace Nebula.Shared.Configurations;
|
||||
|
||||
public class ConVar<T>
|
||||
{
|
||||
internal ConfigurationService.OnConfigurationChangedDelegate<T?>? OnValueChanged;
|
||||
|
||||
public ConVar(string name, T? defaultValue = default)
|
||||
{
|
||||
Name = name ?? throw new ArgumentNullException(nameof(name));
|
||||
DefaultValue = defaultValue;
|
||||
}
|
||||
|
||||
public string Name { get; }
|
||||
public Type Type => typeof(T);
|
||||
public T? DefaultValue { get; }
|
||||
}
|
||||
25
Nebula.Shared/Configurations/ConVarBuilder.cs
Normal file
25
Nebula.Shared/Configurations/ConVarBuilder.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using Nebula.Shared.Configurations.Migrations;
|
||||
using Nebula.Shared.Services;
|
||||
|
||||
namespace Nebula.Shared.Configurations;
|
||||
|
||||
public static class ConVarBuilder
|
||||
{
|
||||
public static ConVar<T> Build<T>(string name, T? defaultValue = default)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(name))
|
||||
throw new ArgumentException("ConVar name cannot be null or whitespace.", nameof(name));
|
||||
|
||||
return new ConVar<T>(name, defaultValue);
|
||||
}
|
||||
|
||||
public static ConVar<T> BuildWithMigration<T>(string name, IConfigurationMigration migration, T? defaultValue = default)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(name))
|
||||
throw new ArgumentException("ConVar name cannot be null or whitespace.", nameof(name));
|
||||
|
||||
ConfigurationService.AddConfigurationMigration(migration);
|
||||
|
||||
return new ConVar<T>(name, defaultValue);
|
||||
}
|
||||
}
|
||||
67
Nebula.Shared/Configurations/ConVarObserver.cs
Normal file
67
Nebula.Shared/Configurations/ConVarObserver.cs
Normal file
@@ -0,0 +1,67 @@
|
||||
using System.ComponentModel;
|
||||
using System.Runtime.CompilerServices;
|
||||
using Nebula.Shared.Services;
|
||||
|
||||
namespace Nebula.Shared.Configurations;
|
||||
|
||||
public sealed class ConVarObserver<T> : IDisposable, INotifyPropertyChanged, INotifyPropertyChanging
|
||||
{
|
||||
private readonly ConVar<T> _convar;
|
||||
private readonly ConfigurationService _configurationService;
|
||||
|
||||
private T? _value;
|
||||
private ConfigurationService.OnConfigurationChangedDelegate<T> _delegate;
|
||||
|
||||
public bool HasValue => Value != null;
|
||||
|
||||
public T? Value
|
||||
{
|
||||
get => _value;
|
||||
set => _configurationService.SetConfigValue(_convar, value);
|
||||
}
|
||||
|
||||
public ConVarObserver(ConVar<T> convar, ConfigurationService configurationService)
|
||||
{
|
||||
_convar = convar;
|
||||
_convar.OnValueChanged += OnValueChanged;
|
||||
_configurationService = configurationService;
|
||||
_delegate += OnValueChanged;
|
||||
|
||||
OnValueChanged(configurationService.GetConfigValue(_convar));
|
||||
}
|
||||
|
||||
private void OnValueChanged(T? value)
|
||||
{
|
||||
OnPropertyChanging(nameof(Value));
|
||||
OnPropertyChanging(nameof(HasValue));
|
||||
|
||||
if(value is null && _value is null)
|
||||
return;
|
||||
if (_value is not null && _value.Equals(value))
|
||||
return;
|
||||
|
||||
_value = value;
|
||||
OnPropertyChanged(nameof(Value));
|
||||
OnPropertyChanged(nameof(HasValue));
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_convar.OnValueChanged -= OnValueChanged;
|
||||
}
|
||||
|
||||
public static implicit operator T? (ConVarObserver<T> convar) => convar.Value;
|
||||
|
||||
public event PropertyChangingEventHandler? PropertyChanging;
|
||||
public event PropertyChangedEventHandler? PropertyChanged;
|
||||
|
||||
private void OnPropertyChanged([CallerMemberName] string? propertyName = null)
|
||||
{
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
private void OnPropertyChanging([CallerMemberName] string? propertyName = null)
|
||||
{
|
||||
PropertyChanging?.Invoke(this, new PropertyChangingEventArgs(propertyName));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
using Nebula.Shared.Models;
|
||||
using Nebula.Shared.Services;
|
||||
|
||||
namespace Nebula.Shared.Configurations.Migrations;
|
||||
|
||||
public abstract class BaseConfigurationMigration<T1,T2> : IConfigurationMigration
|
||||
{
|
||||
protected ConVar<T1> OldConVar;
|
||||
protected ConVar<T2> NewConVar;
|
||||
|
||||
public BaseConfigurationMigration(string oldName, string newName)
|
||||
{
|
||||
OldConVar = ConVarBuilder.Build<T1>(oldName);
|
||||
NewConVar = ConVarBuilder.Build<T2>(newName);
|
||||
}
|
||||
|
||||
public async Task DoMigrate(ConfigurationService configurationService, IServiceProvider serviceProvider, ILoadingHandler loadingHandler)
|
||||
{
|
||||
var oldValue = configurationService.GetConfigValue(OldConVar);
|
||||
if(oldValue == null) return;
|
||||
|
||||
var newValue = await Migrate(serviceProvider, oldValue, loadingHandler);
|
||||
configurationService.SetConfigValue(NewConVar, newValue);
|
||||
configurationService.ClearConfigValue(OldConVar);
|
||||
}
|
||||
|
||||
protected abstract Task<T2> Migrate(IServiceProvider serviceProvider, T1 oldValue, ILoadingHandler loadingHandler);
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
using Nebula.Shared.Models;
|
||||
using Nebula.Shared.Services;
|
||||
|
||||
namespace Nebula.Shared.Configurations.Migrations;
|
||||
|
||||
public interface IConfigurationMigration
|
||||
{
|
||||
public Task DoMigrate(ConfigurationService configurationService, IServiceProvider serviceProvider, ILoadingHandler loadingHandler);
|
||||
}
|
||||
15
Nebula.Shared/Configurations/Migrations/MigrationQueue.cs
Normal file
15
Nebula.Shared/Configurations/Migrations/MigrationQueue.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using Nebula.Shared.Models;
|
||||
using Nebula.Shared.Services;
|
||||
|
||||
namespace Nebula.Shared.Configurations.Migrations;
|
||||
|
||||
public class MigrationQueue(List<IConfigurationMigration> migrations) : IConfigurationMigration
|
||||
{
|
||||
public async Task DoMigrate(ConfigurationService configurationService, IServiceProvider serviceProvider , ILoadingHandler loadingHandler)
|
||||
{
|
||||
foreach (var migration in migrations)
|
||||
{
|
||||
await migration.DoMigrate(configurationService, serviceProvider, loadingHandler);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
namespace Nebula.Shared.Configurations.Migrations;
|
||||
|
||||
public class MigrationQueueBuilder
|
||||
{
|
||||
public static MigrationQueueBuilder Instance => new();
|
||||
|
||||
private readonly List<IConfigurationMigration> _migrations = [];
|
||||
|
||||
public MigrationQueueBuilder With(IConfigurationMigration migration)
|
||||
{
|
||||
_migrations.Add(migration);
|
||||
return this;
|
||||
}
|
||||
|
||||
public MigrationQueue Build()
|
||||
{
|
||||
return new MigrationQueue(_migrations);
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
using Nebula.Shared.Configurations;
|
||||
using Nebula.Shared.Models;
|
||||
using Nebula.Shared.Services;
|
||||
|
||||
@@ -28,6 +29,8 @@ public static class CurrentConVar
|
||||
ConVarBuilder.Build<Dictionary<string, EngineVersionInfo>>("engine.manifest.backup");
|
||||
public static readonly ConVar<ModulesInfo> ModuleManifestBackup =
|
||||
ConVarBuilder.Build<ModulesInfo>("module.manifest.backup");
|
||||
public static readonly ConVar<Dictionary<string, string>> ServerManifestHash =
|
||||
ConVarBuilder.Build<Dictionary<string, string>>("server.manifest.hash",[]);
|
||||
|
||||
public static readonly ConVar<Dictionary<string,string>> DotnetUrl = ConVarBuilder.Build<Dictionary<string,string>>("dotnet.url",
|
||||
new(){
|
||||
|
||||
@@ -1,74 +0,0 @@
|
||||
using System.Net;
|
||||
using FluentFTP;
|
||||
using Nebula.Shared.FileApis.Interfaces;
|
||||
|
||||
namespace Nebula.Shared.FileApis;
|
||||
|
||||
public class FtpFileApi : IWriteFileApi, IDisposable
|
||||
{
|
||||
private readonly string _ftpHost;
|
||||
private readonly string _username;
|
||||
private readonly string _password;
|
||||
|
||||
private readonly FtpClient Client;
|
||||
|
||||
public FtpFileApi(string ftpHost, string username, string password)
|
||||
{
|
||||
_ftpHost = ftpHost;
|
||||
_username = username;
|
||||
_password = password;
|
||||
Client = CreateClient();
|
||||
Client.AutoConnect();
|
||||
}
|
||||
|
||||
public bool Save(string path, Stream input)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = Client.UploadStream(input, path, FtpRemoteExists.Overwrite, true);
|
||||
return result == FtpStatus.Success;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public bool Remove(string path)
|
||||
{
|
||||
try
|
||||
{
|
||||
Client.DeleteFile(path);
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public bool Has(string path)
|
||||
{
|
||||
try
|
||||
{
|
||||
return Client.FileExists(path);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private FtpClient CreateClient()
|
||||
{
|
||||
var client = new FtpClient(_ftpHost, _username, _password);
|
||||
client.Config.EncryptionMode = FtpEncryptionMode.None;
|
||||
client.Config.ValidateAnyCertificate = true;
|
||||
return client;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Client.Dispose();
|
||||
}
|
||||
}
|
||||
@@ -55,6 +55,11 @@ public class HashApi : IFileApi
|
||||
return _fileApi.Has(GetManifestPath(item));
|
||||
}
|
||||
|
||||
public bool Remove(RobustManifestItem item)
|
||||
{
|
||||
return _fileApi.Remove(GetManifestPath(item));
|
||||
}
|
||||
|
||||
private string GetManifestPath(RobustManifestItem item){
|
||||
return GetManifestPath(item.Hash);
|
||||
}
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
namespace Nebula.Shared.Models.Auth;
|
||||
|
||||
public sealed record LoginToken(string Token, DateTimeOffset ExpireTime);
|
||||
public sealed record LoginToken(string Token, DateTimeOffset ExpireTime)
|
||||
{
|
||||
public static LoginToken Empty = new(string.Empty, DateTimeOffset.Now);
|
||||
}
|
||||
@@ -7,6 +7,7 @@ public interface ILoadingHandler
|
||||
|
||||
public void SetResolvedJobsCount(int count);
|
||||
public int GetResolvedJobsCount();
|
||||
public void SetLoadingMessage(string message);
|
||||
|
||||
public void AppendJob(int count = 1)
|
||||
{
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user