Compare commits
12 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 138b769f81 | |||
| a475148543 | |||
| 34fd4ebf4c | |||
| 83d116003b | |||
| a3c96174b2 | |||
| 3bfae32c25 | |||
| ae17ff2d89 | |||
| 517fadaab8 | |||
| 9e95d68c4a | |||
| 01ebe3219d | |||
| 147915f684 | |||
| 0a2fe55c7f |
1
.idea/.idea.Nebula/.idea/avalonia.xml
generated
1
.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/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/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/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/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/LogPopupView.axaml" value="Nebula.Launcher/Nebula.Launcher.csproj" />
|
||||||
<entry key="Nebula.Launcher/Views/Popup/MessagePopupView.axaml" value="Nebula.Launcher/Nebula.Launcher.csproj" />
|
<entry key="Nebula.Launcher/Views/Popup/MessagePopupView.axaml" value="Nebula.Launcher/Nebula.Launcher.csproj" />
|
||||||
|
|||||||
2
.vscode/launch.json
vendored
2
.vscode/launch.json
vendored
@@ -10,7 +10,7 @@
|
|||||||
"request": "launch",
|
"request": "launch",
|
||||||
"preLaunchTask": "build",
|
"preLaunchTask": "build",
|
||||||
// If you have changed target frameworks, make sure to update the program path.
|
// If you have changed target frameworks, make sure to update the program path.
|
||||||
"program": "${workspaceFolder}/Nebula.Launcher/bin/Debug/net9.0/Nebula.Launcher.dll",
|
"program": "${workspaceFolder}/Nebula.Launcher/bin/Debug/Nebula.Launcher.dll",
|
||||||
"args": [],
|
"args": [],
|
||||||
"cwd": "${workspaceFolder}/Nebula.Launcher",
|
"cwd": "${workspaceFolder}/Nebula.Launcher",
|
||||||
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
|
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
|
||||||
|
|||||||
@@ -107,10 +107,10 @@
|
|||||||
pages|StringUnitConfigControl.ConfigBorder,
|
pages|StringUnitConfigControl.ConfigBorder,
|
||||||
pages|IntUnitConfigControl.ConfigBorder,
|
pages|IntUnitConfigControl.ConfigBorder,
|
||||||
pages|FloatUnitConfigControl.ConfigBorder">
|
pages|FloatUnitConfigControl.ConfigBorder">
|
||||||
<Setter Property="Background" Value="#333333" />
|
<Setter Property="Background" Value="#33333355" />
|
||||||
<Setter Property="CornerRadius" Value="5"/>
|
<Setter Property="CornerRadius" Value="0"/>
|
||||||
<Setter Property="BorderThickness" Value="1,0,1,2" />
|
<Setter Property="BorderThickness" Value="1,0,0,2" />
|
||||||
<Setter Property="BorderBrush" Value="Azure" />
|
<Setter Property="BorderBrush" Value="#3f3f3f5f" />
|
||||||
</Style>
|
</Style>
|
||||||
|
|
||||||
</Styles>
|
</Styles>
|
||||||
@@ -0,0 +1,70 @@
|
|||||||
|
tab-account = Account
|
||||||
|
tab-servers = Servers
|
||||||
|
tab-content = Content
|
||||||
|
tab-settings = Settings
|
||||||
|
vcruntime-check-error = VC runtime dlls are not present on this computer. Install VC runtime dlls.
|
||||||
|
migration-label-task = Migration task, please wait...
|
||||||
|
task-cancel = Cancel
|
||||||
|
|
||||||
|
popup-edit-name = Edit server name
|
||||||
|
popup-add-favorite = Add favorite
|
||||||
|
popup-exception = Exception was thrown
|
||||||
|
popup-information = Information
|
||||||
|
popup-loading = Loading...
|
||||||
|
popup-twofa = 2fa
|
||||||
|
|
||||||
|
account-profiles = Profiles
|
||||||
|
account-profile-select = Select
|
||||||
|
account-profile-delete = Delete
|
||||||
|
account-auth-retry = Retry Authentication
|
||||||
|
account-auth-try-another = Or try another account
|
||||||
|
account-auth-login = Enter your login
|
||||||
|
account-auth-password = Enter your password
|
||||||
|
account-auth-server = Authentication Server
|
||||||
|
account-auth-button = Authenticate
|
||||||
|
account-auth-save = Save Profile
|
||||||
|
account-auth-hello = Hello,
|
||||||
|
account-auth-logout = Log out
|
||||||
|
auth-current-login-name = Current login: {$login}
|
||||||
|
auth-current-login-no-name = Profile not selected
|
||||||
|
|
||||||
|
auth-processing = Processing authentication request...
|
||||||
|
auth-error = An authentication error has occurred.
|
||||||
|
auth-error-occured = An error occurred during the authentication process.
|
||||||
|
auth-invalid-credentials = Invalid username or password. Please try again.
|
||||||
|
auth-connection-error = Unable to connect to the authentication server.
|
||||||
|
auth-name-resolution-error = Failed to resolve server address. Check your network or server configuration.
|
||||||
|
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.
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
server-search = Server search
|
||||||
|
serverentry-tag = Tag
|
||||||
|
serverentry-map = Map
|
||||||
|
serverentry-preset = Preset
|
||||||
|
|
||||||
|
content-view-server = Server url
|
||||||
|
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
|
||||||
|
|||||||
@@ -0,0 +1,70 @@
|
|||||||
|
tab-account = Аккаунт
|
||||||
|
tab-servers = Серверы
|
||||||
|
tab-content = Контент
|
||||||
|
tab-settings = Настройки
|
||||||
|
vcruntime-check-error = VC runtime dll-библиотеки отсутствуют на этом компьютере. Установите VC runtime dll.
|
||||||
|
migration-label-task = Задача миграции, подождите...
|
||||||
|
task-cancel = Отмена
|
||||||
|
|
||||||
|
popup-edit-name = Изменить имя сервера
|
||||||
|
popup-add-favorite = Добавить в избранное
|
||||||
|
popup-exception = Произошло исключение
|
||||||
|
popup-information = Информация
|
||||||
|
popup-loading = Загрузка...
|
||||||
|
popup-twofa = 2FA
|
||||||
|
|
||||||
|
account-profiles = Профили
|
||||||
|
account-profile-select = Выбрать
|
||||||
|
account-profile-delete = Удалить
|
||||||
|
account-auth-retry = Повторить аутентификацию
|
||||||
|
account-auth-try-another = Или попробуйте другой аккаунт
|
||||||
|
account-auth-login = Введите логин
|
||||||
|
account-auth-password = Введите пароль
|
||||||
|
account-auth-server = Сервер аутентификации
|
||||||
|
account-auth-button = Аутентифицировать
|
||||||
|
account-auth-save = Сохранить профиль
|
||||||
|
account-auth-hello = Привет,
|
||||||
|
account-auth-logout = Выйти
|
||||||
|
auth-current-login-name = Текущий профиль: {$login}
|
||||||
|
auth-current-login-no-name = Профиль не выбран
|
||||||
|
|
||||||
|
auth-processing = Обработка запроса аутентификации...
|
||||||
|
auth-error = Произошла ошибка аутентификации.
|
||||||
|
auth-error-occured = Во время аутентификации произошла ошибка.
|
||||||
|
auth-invalid-credentials = Неверное имя пользователя или пароль. Попробуйте еще раз.
|
||||||
|
auth-connection-error = Не удается подключиться к серверу аутентификации.
|
||||||
|
auth-name-resolution-error = Не удалось разрешить адрес сервера. Проверьте сетевые настройки или конфигурацию сервера.
|
||||||
|
auth-secure-error = Не удалось подключиться к серверу по SSL. Проверьте сетевые настройки.
|
||||||
|
auth-config-read = Чтение конфигурации аутентификации...
|
||||||
|
auth-try-auth-config = Попытка аутентификации с использованием сохраненной конфигурации.
|
||||||
|
|
||||||
|
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 = Продолжить
|
||||||
|
|
||||||
|
server-search = Поиск сервера
|
||||||
|
serverentry-tag = Тэги
|
||||||
|
serverentry-map = Карта
|
||||||
|
serverentry-preset = Режим
|
||||||
|
|
||||||
|
content-view-server = Сервер
|
||||||
|
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 = Корн. папка
|
||||||
@@ -19,13 +19,16 @@ public class FilterBox : UserControl
|
|||||||
|
|
||||||
public Action<FilterBoxChangedEventArgs>? OnFilterChanged {get; set;}
|
public Action<FilterBoxChangedEventArgs>? OnFilterChanged {get; set;}
|
||||||
|
|
||||||
public string? FilterBoxName {
|
public string FilterBoxName {
|
||||||
set => filterName.Text = value;
|
set => filterName.LocalId = value;
|
||||||
get => filterName.Text;
|
get => filterName.LocalId;
|
||||||
}
|
}
|
||||||
|
|
||||||
private StackPanel filterPanel;
|
private StackPanel filterPanel;
|
||||||
private TextBox filterName = new TextBox();
|
private LocalizedLabel filterName = new LocalizedLabel()
|
||||||
|
{
|
||||||
|
VerticalAlignment = VerticalAlignment.Center
|
||||||
|
};
|
||||||
|
|
||||||
public FilterBox()
|
public FilterBox()
|
||||||
{
|
{
|
||||||
@@ -35,6 +38,8 @@ public class FilterBox : UserControl
|
|||||||
Spacing = 5,
|
Spacing = 5,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
filterPanel.Children.Add(filterName);
|
||||||
|
|
||||||
Content = filterPanel;
|
Content = filterPanel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
20
Nebula.Launcher/Controls/LocalizedLabel.cs
Normal file
20
Nebula.Launcher/Controls/LocalizedLabel.cs
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
using Avalonia;
|
||||||
|
using Avalonia.Controls;
|
||||||
|
using Nebula.Launcher.Services;
|
||||||
|
|
||||||
|
namespace Nebula.Launcher.Controls;
|
||||||
|
|
||||||
|
public class LocalizedLabel : Label
|
||||||
|
{
|
||||||
|
public static readonly StyledProperty<string> LocalIdProperty = AvaloniaProperty.Register<LocalizedLabel, string>(nameof(LocalId));
|
||||||
|
|
||||||
|
public string LocalId
|
||||||
|
{
|
||||||
|
get => GetValue(LocalIdProperty);
|
||||||
|
set
|
||||||
|
{
|
||||||
|
SetValue(LocalIdProperty, value);
|
||||||
|
Content = LocalisationService.GetString(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
|
using Nebula.Launcher.Models;
|
||||||
using Nebula.Launcher.ServerListProviders;
|
using Nebula.Launcher.ServerListProviders;
|
||||||
using Nebula.Launcher.ViewModels;
|
using Nebula.Launcher.ViewModels;
|
||||||
using Nebula.Launcher.ViewModels.Pages;
|
using Nebula.Launcher.ViewModels.Pages;
|
||||||
|
|||||||
@@ -1,2 +1 @@
|
|||||||
global using Nebula.Shared.Attributes;
|
global using Nebula.Shared.Attributes;
|
||||||
global using Nebula.Launcher.ViewHelper;
|
|
||||||
@@ -1,6 +1,8 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Globalization;
|
||||||
using Nebula.Launcher.Models;
|
using Nebula.Launcher.Models;
|
||||||
using Nebula.Launcher.ViewModels.Pages;
|
using Nebula.Launcher.Models.Auth;
|
||||||
|
using Nebula.Shared.ConfigMigrations;
|
||||||
using Nebula.Shared.Services;
|
using Nebula.Shared.Services;
|
||||||
|
|
||||||
namespace Nebula.Launcher;
|
namespace Nebula.Launcher;
|
||||||
@@ -9,11 +11,16 @@ public static class LauncherConVar
|
|||||||
{
|
{
|
||||||
public static readonly ConVar<bool> DoMigration =
|
public static readonly ConVar<bool> DoMigration =
|
||||||
ConVarBuilder.Build("migration.doMigrate", true);
|
ConVarBuilder.Build("migration.doMigrate", true);
|
||||||
public static readonly ConVar<ProfileAuthCredentials[]> AuthProfiles =
|
|
||||||
ConVarBuilder.Build<ProfileAuthCredentials[]>("auth.profiles.v2", []);
|
|
||||||
|
|
||||||
public static readonly ConVar<CurrentAuthInfo?> AuthCurrent =
|
public static readonly ConVar<AuthTokenCredentials[]> AuthProfiles =
|
||||||
ConVarBuilder.Build<CurrentAuthInfo?>("auth.current.v2");
|
ConVarBuilder.BuildWithMigration<AuthTokenCredentials[]>("auth.profiles.v3",
|
||||||
|
MigrationQueueBuilder.Instance
|
||||||
|
.With(new ProfileMigrationV2("auth.profiles.v2","auth.profiles.v3"))
|
||||||
|
.Build(),
|
||||||
|
[]);
|
||||||
|
|
||||||
|
public static readonly ConVar<AuthTokenCredentials?> AuthCurrent =
|
||||||
|
ConVarBuilder.Build<AuthTokenCredentials?>("auth.current.v2");
|
||||||
|
|
||||||
public static readonly ConVar<string[]> Favorites =
|
public static readonly ConVar<string[]> Favorites =
|
||||||
ConVarBuilder.Build<string[]>("server.favorites", []);
|
ConVarBuilder.Build<string[]>("server.favorites", []);
|
||||||
@@ -36,7 +43,7 @@ public static class LauncherConVar
|
|||||||
new ServerHubRecord("AltHub","https://web.networkgamez.com/api/servers")
|
new ServerHubRecord("AltHub","https://web.networkgamez.com/api/servers")
|
||||||
]);
|
]);
|
||||||
|
|
||||||
public static readonly ConVar<string> CurrentLang = ConVarBuilder.Build<string>("launcher.language", "en-US");
|
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",
|
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");
|
"https://github.com/icsharpcode/ILSpy/releases/download/v9.0/ILSpy_binaries_9.0.0.7889-x64.zip");
|
||||||
|
|
||||||
|
|||||||
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
|
||||||
|
);
|
||||||
10
Nebula.Launcher/Models/Auth/ProfileAuthCredentials.cs
Normal file
10
Nebula.Launcher/Models/Auth/ProfileAuthCredentials.cs
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
using System.Text.Json.Serialization;
|
||||||
|
using System.Windows.Input;
|
||||||
|
using Nebula.Shared.Services;
|
||||||
|
|
||||||
|
namespace Nebula.Launcher.Models.Auth;
|
||||||
|
|
||||||
|
public sealed record ProfileAuthCredentials(
|
||||||
|
AuthTokenCredentials Credentials,
|
||||||
|
[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
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -32,6 +32,7 @@
|
|||||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.0"/>
|
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.0"/>
|
||||||
<PackageReference Include="libsodium" Version="1.0.20"/>
|
<PackageReference Include="libsodium" Version="1.0.20"/>
|
||||||
<PackageReference Include="Robust.Natives" Version="0.1.1" />
|
<PackageReference Include="Robust.Natives" Version="0.1.1" />
|
||||||
|
<PackageReference Include="NLua" Version="1.7.5" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
@@ -54,6 +55,8 @@
|
|||||||
<Copy SourceFiles="..\Nebula.Runner\bin\$(Configuration)\$(TargetFramework)\Nebula.Runner.pdb" DestinationFolder="$(OutDir)"/>
|
<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.deps.json" DestinationFolder="$(OutDir)"/>
|
||||||
<Copy SourceFiles="..\Nebula.Runner\bin\$(Configuration)\$(TargetFramework)\Nebula.Runner.runtimeconfig.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>
|
||||||
|
|
||||||
<Target Name="PublishCheck" AfterTargets="Publish">
|
<Target Name="PublishCheck" AfterTargets="Publish">
|
||||||
@@ -61,6 +64,8 @@
|
|||||||
<Copy SourceFiles="..\Nebula.Runner\bin\$(Configuration)\$(TargetFramework)\Nebula.Runner.pdb" DestinationFolder="$(PublishDir)"/>
|
<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.deps.json" DestinationFolder="$(PublishDir)"/>
|
||||||
<Copy SourceFiles="..\Nebula.Runner\bin\$(Configuration)\$(TargetFramework)\Nebula.Runner.runtimeconfig.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>
|
</Target>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ using System.Diagnostics;
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Nebula.Launcher.ViewModels.Pages;
|
||||||
using Nebula.Shared;
|
using Nebula.Shared;
|
||||||
using Nebula.Shared.Models;
|
using Nebula.Shared.Models;
|
||||||
using Nebula.Shared.Services;
|
using Nebula.Shared.Services;
|
||||||
@@ -10,7 +11,7 @@ using Nebula.Shared.Services;
|
|||||||
namespace Nebula.Launcher.ProcessHelper;
|
namespace Nebula.Launcher.ProcessHelper;
|
||||||
|
|
||||||
[ServiceRegister(isSingleton:false)]
|
[ServiceRegister(isSingleton:false)]
|
||||||
public sealed class GameProcessStartInfoProvider(DotnetResolverService resolverService, AuthService authService) :
|
public sealed class GameProcessStartInfoProvider(DotnetResolverService resolverService, AccountInfoViewModel accountInfoViewModel) :
|
||||||
DotnetProcessStartInfoProviderBase(resolverService)
|
DotnetProcessStartInfoProviderBase(resolverService)
|
||||||
{
|
{
|
||||||
private string? _publicKey;
|
private string? _publicKey;
|
||||||
@@ -34,7 +35,7 @@ public sealed class GameProcessStartInfoProvider(DotnetResolverService resolverS
|
|||||||
{
|
{
|
||||||
var baseStart = await base.GetProcessStartInfo();
|
var baseStart = await base.GetProcessStartInfo();
|
||||||
|
|
||||||
var authProv = authService.SelectedAuth;
|
var authProv = accountInfoViewModel.Credentials;
|
||||||
if(authProv is null)
|
if(authProv is null)
|
||||||
throw new Exception("Client is without selected auth");
|
throw new Exception("Client is without selected auth");
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ using Nebula.Shared.Services;
|
|||||||
namespace Nebula.Launcher.ProcessHelper;
|
namespace Nebula.Launcher.ProcessHelper;
|
||||||
|
|
||||||
[ServiceRegister]
|
[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)
|
public async Task<ProcessRunHandler<GameProcessStartInfoProvider>> GetGameProcessStartInfoProvider(RobustUrl address, ILoadingHandler loadingHandler, CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ using Avalonia.Controls.ApplicationLifetimes;
|
|||||||
using Avalonia.Threading;
|
using Avalonia.Threading;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Nebula.Launcher.Views;
|
using Nebula.Launcher.Views;
|
||||||
|
using Nebula.Shared.ViewHelper;
|
||||||
|
|
||||||
namespace Nebula.Launcher;
|
namespace Nebula.Launcher;
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using Avalonia.Markup.Xaml;
|
||||||
using Avalonia.Platform;
|
using Avalonia.Platform;
|
||||||
using Fluent.Net;
|
using Fluent.Net;
|
||||||
using Nebula.Shared;
|
using Nebula.Shared;
|
||||||
@@ -12,35 +14,66 @@ namespace Nebula.Launcher.Services;
|
|||||||
public partial class LocalisationService
|
public partial class LocalisationService
|
||||||
{
|
{
|
||||||
[GenerateProperty] private ConfigurationService ConfigurationService { get; }
|
[GenerateProperty] private ConfigurationService ConfigurationService { get; }
|
||||||
|
[GenerateProperty] private DebugService DebugService { get; }
|
||||||
|
|
||||||
private CultureInfo _currentCultureInfo = CultureInfo.CurrentCulture;
|
private CultureInfo _currentCultureInfo = CultureInfo.CurrentCulture;
|
||||||
private MessageContext _currentMessageContext;
|
private static MessageContext? _currentMessageContext;
|
||||||
|
|
||||||
private void Initialise()
|
private void Initialise()
|
||||||
{
|
{
|
||||||
// LoadLanguage(CultureInfo.GetCultureInfo(ConfigurationService.GetConfigValue(LauncherConVar.CurrentLang)!));
|
LoadLanguage(CultureInfo.GetCultureInfo(ConfigurationService.GetConfigValue(LauncherConVar.CurrentLang)!));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void LoadLanguage(CultureInfo cultureInfo)
|
public void LoadLanguage(CultureInfo cultureInfo)
|
||||||
{
|
{
|
||||||
_currentCultureInfo = cultureInfo;
|
try
|
||||||
using var fs = AssetLoader.Open(new Uri($@"Assets/lang/{_currentCultureInfo.EnglishName}.ftl"));
|
|
||||||
using var sr = new StreamReader(fs);
|
|
||||||
|
|
||||||
var options = new MessageContextOptions { UseIsolating = false };
|
|
||||||
var mc = new MessageContext(cultureInfo.EnglishName, options);
|
|
||||||
var errors = mc.AddMessages(sr);
|
|
||||||
foreach (var error in errors)
|
|
||||||
{
|
{
|
||||||
Console.WriteLine(error);
|
_currentCultureInfo = cultureInfo;
|
||||||
}
|
using var fs = AssetLoader.Open(new Uri($@"avares://Nebula.Launcher/Assets/lang/{_currentCultureInfo.Name}.ftl"));
|
||||||
|
using var sr = new StreamReader(fs);
|
||||||
|
|
||||||
_currentMessageContext = mc;
|
var options = new MessageContextOptions { UseIsolating = false };
|
||||||
|
var mc = new MessageContext(cultureInfo.Name, options);
|
||||||
|
var errors = mc.AddMessages(sr);
|
||||||
|
foreach (var error in errors)
|
||||||
|
{
|
||||||
|
Console.WriteLine(error);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
_currentMessageContext = mc;
|
||||||
|
} catch (Exception e) {
|
||||||
|
DebugService.GetLogger("localisationService").Error(e);
|
||||||
|
LoadLanguage(CultureInfo.GetCultureInfo("en-US"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void InitialiseInDesignMode()
|
private void InitialiseInDesignMode()
|
||||||
{
|
{
|
||||||
Initialise();
|
Initialise();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static string GetString(string locale, Dictionary<string, object>? options = null)
|
||||||
|
{
|
||||||
|
if (_currentMessageContext is null)
|
||||||
|
{
|
||||||
|
return locale;
|
||||||
|
}
|
||||||
|
var message = _currentMessageContext.GetMessage(locale);
|
||||||
|
if (message == null) return locale;
|
||||||
|
return _currentMessageContext.Format(message, options ?? []);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class LocaledText : MarkupExtension
|
||||||
|
{
|
||||||
|
public string Key { 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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 Avalonia.Controls.Templates;
|
||||||
using Nebula.Launcher.ViewModels;
|
using Nebula.Launcher.ViewModels;
|
||||||
using Nebula.Launcher.Views;
|
using Nebula.Launcher.Views;
|
||||||
|
using Nebula.Shared.ViewHelper;
|
||||||
|
|
||||||
namespace Nebula.Launcher;
|
namespace Nebula.Launcher;
|
||||||
|
|
||||||
|
|||||||
@@ -10,10 +10,10 @@ using Nebula.Launcher.Services;
|
|||||||
using Nebula.Launcher.ViewModels.Pages;
|
using Nebula.Launcher.ViewModels.Pages;
|
||||||
using Nebula.Launcher.ViewModels.Popup;
|
using Nebula.Launcher.ViewModels.Popup;
|
||||||
using Nebula.Launcher.Views;
|
using Nebula.Launcher.Views;
|
||||||
using Nebula.Shared.Models;
|
|
||||||
using Nebula.Shared.Services;
|
using Nebula.Shared.Services;
|
||||||
using Nebula.Shared.Services.Logging;
|
using Nebula.Shared.Services.Logging;
|
||||||
using Nebula.Shared.Utils;
|
using Nebula.Shared.Utils;
|
||||||
|
using Nebula.Shared.ViewHelper;
|
||||||
|
|
||||||
namespace Nebula.Launcher.ViewModels;
|
namespace Nebula.Launcher.ViewModels;
|
||||||
|
|
||||||
@@ -23,10 +23,10 @@ public partial class MainViewModel : ViewModelBase
|
|||||||
{
|
{
|
||||||
private readonly List<ListItemTemplate> _templates =
|
private readonly List<ListItemTemplate> _templates =
|
||||||
[
|
[
|
||||||
new ListItemTemplate(typeof(AccountInfoViewModel), "user", "Account"),
|
new ListItemTemplate(typeof(AccountInfoViewModel), "user", "tab-account"),
|
||||||
new ListItemTemplate(typeof(ServerOverviewModel), "file", "Servers"),
|
new ListItemTemplate(typeof(ServerOverviewModel), "file", "tab-servers"),
|
||||||
new ListItemTemplate(typeof(ContentBrowserViewModel), "folder", "Content"),
|
new ListItemTemplate(typeof(ContentBrowserViewModel), "folder", "tab-content"),
|
||||||
new ListItemTemplate(typeof(ConfigurationViewModel), "settings", "Settings")
|
new ListItemTemplate(typeof(ConfigurationViewModel), "settings", "tab-settings")
|
||||||
];
|
];
|
||||||
|
|
||||||
private readonly List<PopupViewModelBase> _viewQueue = new();
|
private readonly List<PopupViewModelBase> _viewQueue = new();
|
||||||
@@ -41,6 +41,17 @@ public partial class MainViewModel : ViewModelBase
|
|||||||
[ObservableProperty] private bool _popup;
|
[ObservableProperty] private bool _popup;
|
||||||
[ObservableProperty] private ListItemTemplate? _selectedListItem;
|
[ObservableProperty] private ListItemTemplate? _selectedListItem;
|
||||||
|
|
||||||
|
public bool IsLoggedIn => AccountInfoViewModel.Credentials is not null;
|
||||||
|
public string LoginName => AccountInfoViewModel.Credentials?.Login ?? string.Empty;
|
||||||
|
|
||||||
|
public string LoginText => LocalisationService.GetString("auth-current-login-name",
|
||||||
|
new Dictionary<string, object>
|
||||||
|
{
|
||||||
|
{ "login", LoginName }
|
||||||
|
});
|
||||||
|
|
||||||
|
[GenerateProperty] private LocalisationService LocalisationService { get; } // Не убирать! Без этой хуйни вся локализация идет в пизду!
|
||||||
|
[GenerateProperty] private AccountInfoViewModel AccountInfoViewModel { get; }
|
||||||
[GenerateProperty] private DebugService DebugService { get; } = default!;
|
[GenerateProperty] private DebugService DebugService { get; } = default!;
|
||||||
[GenerateProperty] private PopupMessageService PopupMessageService { get; } = default!;
|
[GenerateProperty] private PopupMessageService PopupMessageService { get; } = default!;
|
||||||
[GenerateProperty] private ContentService ContentService { get; } = default!;
|
[GenerateProperty] private ContentService ContentService { get; } = default!;
|
||||||
@@ -53,12 +64,25 @@ public partial class MainViewModel : ViewModelBase
|
|||||||
|
|
||||||
protected override void InitialiseInDesignMode()
|
protected override void InitialiseInDesignMode()
|
||||||
{
|
{
|
||||||
Items = new ObservableCollection<ListItemTemplate>(_templates);
|
Items = new ObservableCollection<ListItemTemplate>(_templates.Select(a=>
|
||||||
|
{
|
||||||
|
return a with { Label = LocalisationService.GetString(a.Label) };
|
||||||
|
}
|
||||||
|
));
|
||||||
RequirePage<AccountInfoViewModel>();
|
RequirePage<AccountInfoViewModel>();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void Initialise()
|
protected override void Initialise()
|
||||||
{
|
{
|
||||||
|
AccountInfoViewModel.PropertyChanged += (sender, args) =>
|
||||||
|
{
|
||||||
|
if (args.PropertyName != nameof(AccountInfoViewModel.Credentials))
|
||||||
|
return;
|
||||||
|
|
||||||
|
OnPropertyChanged(nameof(LoginText));
|
||||||
|
OnPropertyChanged(nameof(IsLoggedIn));
|
||||||
|
};
|
||||||
|
|
||||||
_logger = DebugService.GetLogger(this);
|
_logger = DebugService.GetLogger(this);
|
||||||
|
|
||||||
using var stream = typeof(MainViewModel).Assembly
|
using var stream = typeof(MainViewModel).Assembly
|
||||||
@@ -74,9 +98,14 @@ public partial class MainViewModel : ViewModelBase
|
|||||||
|
|
||||||
CheckMigration();
|
CheckMigration();
|
||||||
|
|
||||||
|
var loadingHandler = ViewHelperService.GetViewModel<LoadingContextViewModel>();
|
||||||
|
loadingHandler.LoadingName = LocalisationService.GetString("migration-config-task");
|
||||||
|
loadingHandler.IsCancellable = false;
|
||||||
|
ConfigurationService.MigrateConfigs(loadingHandler);
|
||||||
|
|
||||||
if (!VCRuntimeDllChecker.AreVCRuntimeDllsPresent())
|
if (!VCRuntimeDllChecker.AreVCRuntimeDllsPresent())
|
||||||
{
|
{
|
||||||
OnPopupRequired("VC runtime dlls are not present on this computer. Install VC runtime dlls.");
|
OnPopupRequired(LocalisationService.GetString("vcruntime-check-error"));
|
||||||
Helper.OpenBrowser("https://learn.microsoft.com/en-us/cpp/windows/latest-supported-vc-redist?view=msvc-170");
|
Helper.OpenBrowser("https://learn.microsoft.com/en-us/cpp/windows/latest-supported-vc-redist?view=msvc-170");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -87,7 +116,7 @@ public partial class MainViewModel : ViewModelBase
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
var loadingHandler = ViewHelperService.GetViewModel<LoadingContextViewModel>();
|
var loadingHandler = ViewHelperService.GetViewModel<LoadingContextViewModel>();
|
||||||
loadingHandler.LoadingName = "Migration task, please wait...";
|
loadingHandler.LoadingName = LocalisationService.GetString("migration-label-task");
|
||||||
loadingHandler.IsCancellable = false;
|
loadingHandler.IsCancellable = false;
|
||||||
|
|
||||||
if (!ContentService.CheckMigration(loadingHandler))
|
if (!ContentService.CheckMigration(loadingHandler))
|
||||||
@@ -158,6 +187,16 @@ public partial class MainViewModel : ViewModelBase
|
|||||||
Popup = true;
|
Popup = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void OpenAuthPage()
|
||||||
|
{
|
||||||
|
RequirePage<AccountInfoViewModel>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OpenRootPath()
|
||||||
|
{
|
||||||
|
ExplorerHelper.OpenFolder(FileService.RootPath);
|
||||||
|
}
|
||||||
|
|
||||||
public void OpenLink()
|
public void OpenLink()
|
||||||
{
|
{
|
||||||
Helper.OpenBrowser("https://durenko.tatar/nebula");
|
Helper.OpenBrowser("https://durenko.tatar/nebula");
|
||||||
|
|||||||
@@ -3,18 +3,18 @@ using System.Collections.Generic;
|
|||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
using System.Text.Json.Serialization;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows.Input;
|
|
||||||
using CommunityToolkit.Mvvm.ComponentModel;
|
using CommunityToolkit.Mvvm.ComponentModel;
|
||||||
using CommunityToolkit.Mvvm.Input;
|
using CommunityToolkit.Mvvm.Input;
|
||||||
|
using Nebula.Launcher.Models.Auth;
|
||||||
using Nebula.Launcher.Services;
|
using Nebula.Launcher.Services;
|
||||||
using Nebula.Launcher.ViewModels.Popup;
|
using Nebula.Launcher.ViewModels.Popup;
|
||||||
using Nebula.Launcher.Views.Pages;
|
using Nebula.Launcher.Views.Pages;
|
||||||
using Nebula.Shared;
|
using Nebula.Shared.Models.Auth;
|
||||||
using Nebula.Shared.Services;
|
using Nebula.Shared.Services;
|
||||||
using Nebula.Shared.Services.Logging;
|
using Nebula.Shared.Services.Logging;
|
||||||
using Nebula.Shared.Utils;
|
using Nebula.Shared.Utils;
|
||||||
|
using Nebula.Shared.ViewHelper;
|
||||||
|
|
||||||
namespace Nebula.Launcher.ViewModels.Pages;
|
namespace Nebula.Launcher.ViewModels.Pages;
|
||||||
|
|
||||||
@@ -36,6 +36,7 @@ public partial class AccountInfoViewModel : ViewModelBase
|
|||||||
|
|
||||||
[ObservableProperty] private bool _isLogged;
|
[ObservableProperty] private bool _isLogged;
|
||||||
[ObservableProperty] private bool _doRetryAuth;
|
[ObservableProperty] private bool _doRetryAuth;
|
||||||
|
[ObservableProperty] private AuthTokenCredentials? _credentials;
|
||||||
|
|
||||||
private bool _isProfilesEmpty;
|
private bool _isProfilesEmpty;
|
||||||
[GenerateProperty] private PopupMessageService PopupMessageService { get; } = default!;
|
[GenerateProperty] private PopupMessageService PopupMessageService { get; } = default!;
|
||||||
@@ -54,8 +55,8 @@ public partial class AccountInfoViewModel : ViewModelBase
|
|||||||
//Design think
|
//Design think
|
||||||
protected override void InitialiseInDesignMode()
|
protected override void InitialiseInDesignMode()
|
||||||
{
|
{
|
||||||
AddAccount(new AuthLoginPassword("Binka", "12341", ""));
|
AddAccount(new AuthTokenCredentials(Guid.Empty, LoginToken.Empty, "Binka", ""));
|
||||||
AddAccount(new AuthLoginPassword("Binka", "12341", ""));
|
AddAccount(new AuthTokenCredentials(Guid.Empty, LoginToken.Empty, "Binka", ""));
|
||||||
|
|
||||||
AuthUrls.Add(new AuthServerCredentials("Test",["example.com"]));
|
AuthUrls.Add(new AuthServerCredentials("Test",["example.com"]));
|
||||||
}
|
}
|
||||||
@@ -67,19 +68,37 @@ public partial class AccountInfoViewModel : ViewModelBase
|
|||||||
Task.Run(ReadAuthConfig);
|
Task.Run(ReadAuthConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AuthByProfile(ProfileAuthCredentials credentials)
|
public async void AuthByProfile(ProfileAuthCredentials credentials)
|
||||||
{
|
{
|
||||||
CurrentLogin = credentials.Login;
|
var message = ViewHelperService.GetViewModel<InfoPopupViewModel>();
|
||||||
CurrentPassword = credentials.Password;
|
message.InfoText = LocalisationService.GetString("auth-try-auth-profile");
|
||||||
CurrentAuthServer = credentials.AuthServer;
|
message.IsInfoClosable = false;
|
||||||
|
PopupMessageService.Popup(message);
|
||||||
|
|
||||||
DoAuth();
|
try
|
||||||
|
{
|
||||||
|
await CatchAuthError(async () => await TryAuth(credentials.Credentials), () => message.Dispose());
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
CurrentLogin = credentials.Credentials.Login;
|
||||||
|
CurrentAuthServer = credentials.Credentials.AuthServer;
|
||||||
|
|
||||||
|
var unexpectedError = new Exception(LocalisationService.GetString("auth-error"), ex);
|
||||||
|
_logger.Error(unexpectedError);
|
||||||
|
PopupMessageService.Popup(unexpectedError);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ConfigurationService.SetConfigValue(LauncherConVar.AuthCurrent, Credentials);
|
||||||
|
|
||||||
|
message.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DoAuth(string? code = null)
|
public void DoAuth(string? code = null)
|
||||||
{
|
{
|
||||||
var message = ViewHelperService.GetViewModel<InfoPopupViewModel>();
|
var message = ViewHelperService.GetViewModel<InfoPopupViewModel>();
|
||||||
message.InfoText = "Auth think, please wait...";
|
message.InfoText = LocalisationService.GetString("auth-processing");
|
||||||
message.IsInfoClosable = false;
|
message.IsInfoClosable = false;
|
||||||
PopupMessageService.Popup(message);
|
PopupMessageService.Popup(message);
|
||||||
|
|
||||||
@@ -102,7 +121,7 @@ public partial class AccountInfoViewModel : ViewModelBase
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
var unexpectedError = new Exception("An unexpected error occurred during authentication.", ex);
|
var unexpectedError = new Exception(LocalisationService.GetString("auth-error"), ex);
|
||||||
_logger.Error(unexpectedError);
|
_logger.Error(unexpectedError);
|
||||||
PopupMessageService.Popup(unexpectedError);
|
PopupMessageService.Popup(unexpectedError);
|
||||||
}
|
}
|
||||||
@@ -112,27 +131,33 @@ public partial class AccountInfoViewModel : ViewModelBase
|
|||||||
|
|
||||||
if (!IsLogged)
|
if (!IsLogged)
|
||||||
{
|
{
|
||||||
PopupMessageService.Popup(new Exception("No one of auth server is available.", exception));
|
PopupMessageService.Popup(exception ?? new Exception(LocalisationService.GetString("auth-error")));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task TryAuth(CurrentAuthInfo currentAuthInfo)
|
private async Task TryAuth(AuthTokenCredentials authTokenCredentials)
|
||||||
{
|
{
|
||||||
CurrentLogin = currentAuthInfo.Login;
|
CurrentLogin = authTokenCredentials.Login;
|
||||||
CurrentAuthServer = currentAuthInfo.AuthServer;
|
CurrentAuthServer = authTokenCredentials.AuthServer;
|
||||||
await AuthService.SetAuth(currentAuthInfo);
|
await SetAuth(authTokenCredentials);
|
||||||
IsLogged = true;
|
IsLogged = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async Task SetAuth(AuthTokenCredentials authTokenCredentials)
|
||||||
|
{
|
||||||
|
await AuthService.EnsureToken(authTokenCredentials);
|
||||||
|
Credentials = authTokenCredentials;
|
||||||
|
}
|
||||||
|
|
||||||
private async Task TryAuth(string login, string password, string authServer, string? code)
|
private async Task TryAuth(string login, string password, string authServer, string? code)
|
||||||
{
|
{
|
||||||
await AuthService.Auth(new AuthLoginPassword(login, password, authServer), code);
|
Credentials = await AuthService.Auth(login, password, authServer, code);
|
||||||
CurrentLogin = login;
|
CurrentLogin = login;
|
||||||
CurrentPassword = password;
|
CurrentPassword = password;
|
||||||
CurrentAuthServer = authServer;
|
CurrentAuthServer = authServer;
|
||||||
IsLogged = true;
|
IsLogged = true;
|
||||||
ConfigurationService.SetConfigValue(LauncherConVar.AuthCurrent, AuthService.SelectedAuth);
|
ConfigurationService.SetConfigValue(LauncherConVar.AuthCurrent, Credentials);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task CatchAuthError(Func<Task> a, Action? onError)
|
private async Task CatchAuthError(Func<Task> a, Action? onError)
|
||||||
@@ -156,7 +181,7 @@ public partial class AccountInfoViewModel : ViewModelBase
|
|||||||
_logger.Log("TFA required");
|
_logger.Log("TFA required");
|
||||||
break;
|
break;
|
||||||
case AuthenticateDenyCode.InvalidCredentials:
|
case AuthenticateDenyCode.InvalidCredentials:
|
||||||
PopupError("Invalid Credentials! Please, try another password or login!", e);
|
PopupError(LocalisationService.GetString("auth-invalid-credentials"), e);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw;
|
throw;
|
||||||
@@ -168,17 +193,22 @@ public partial class AccountInfoViewModel : ViewModelBase
|
|||||||
switch (e.HttpRequestError)
|
switch (e.HttpRequestError)
|
||||||
{
|
{
|
||||||
case HttpRequestError.ConnectionError:
|
case HttpRequestError.ConnectionError:
|
||||||
PopupError("Failed to connect to the authentication server.", e);
|
PopupError(LocalisationService.GetString("auth-connection-error"), e);
|
||||||
DoRetryAuth = true;
|
DoRetryAuth = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case HttpRequestError.NameResolutionError:
|
case HttpRequestError.NameResolutionError:
|
||||||
PopupError("Unable to resolve the server address.", e);
|
PopupError(LocalisationService.GetString("auth-name-resolution-error"), e);
|
||||||
|
DoRetryAuth = true;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case HttpRequestError.SecureConnectionError:
|
||||||
|
PopupError(LocalisationService.GetString("auth-secure-error"), e);
|
||||||
DoRetryAuth = true;
|
DoRetryAuth = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
var authError = new Exception("An error occurred during authentication.", e);
|
var authError = new Exception(LocalisationService.GetString("auth-error"), e);
|
||||||
_logger.Error(authError);
|
_logger.Error(authError);
|
||||||
PopupMessageService.Popup(authError);
|
PopupMessageService.Popup(authError);
|
||||||
break;
|
break;
|
||||||
@@ -194,7 +224,7 @@ public partial class AccountInfoViewModel : ViewModelBase
|
|||||||
public void Logout()
|
public void Logout()
|
||||||
{
|
{
|
||||||
IsLogged = false;
|
IsLogged = false;
|
||||||
AuthService.ClearAuth();
|
Credentials = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateAuthMenu()
|
private void UpdateAuthMenu()
|
||||||
@@ -205,15 +235,13 @@ public partial class AccountInfoViewModel : ViewModelBase
|
|||||||
AuthViewSpan = 1;
|
AuthViewSpan = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void AddAccount(AuthLoginPassword authLoginPassword)
|
private void AddAccount(AuthTokenCredentials credentials)
|
||||||
{
|
{
|
||||||
var onDelete = new DelegateCommand<ProfileAuthCredentials>(OnDeleteProfile);
|
var onDelete = new DelegateCommand<ProfileAuthCredentials>(OnDeleteProfile);
|
||||||
var onSelect = new DelegateCommand<ProfileAuthCredentials>(AuthByProfile);
|
var onSelect = new DelegateCommand<ProfileAuthCredentials>(AuthByProfile);
|
||||||
|
|
||||||
var alpm = new ProfileAuthCredentials(
|
var alpm = new ProfileAuthCredentials(
|
||||||
authLoginPassword.Login,
|
credentials,
|
||||||
authLoginPassword.Password,
|
|
||||||
authLoginPassword.AuthServer,
|
|
||||||
onSelect,
|
onSelect,
|
||||||
onDelete);
|
onDelete);
|
||||||
|
|
||||||
@@ -223,15 +251,15 @@ public partial class AccountInfoViewModel : ViewModelBase
|
|||||||
Accounts.Add(alpm);
|
Accounts.Add(alpm);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task ReadAuthConfig()
|
private void ReadAuthConfig()
|
||||||
{
|
{
|
||||||
var message = ViewHelperService.GetViewModel<InfoPopupViewModel>();
|
var message = ViewHelperService.GetViewModel<InfoPopupViewModel>();
|
||||||
message.InfoText = "Read configuration file, please wait...";
|
message.InfoText = LocalisationService.GetString("auth-config-read");
|
||||||
message.IsInfoClosable = false;
|
message.IsInfoClosable = false;
|
||||||
PopupMessageService.Popup(message);
|
PopupMessageService.Popup(message);
|
||||||
foreach (var profile in
|
foreach (var profile in
|
||||||
ConfigurationService.GetConfigValue(LauncherConVar.AuthProfiles)!)
|
ConfigurationService.GetConfigValue(LauncherConVar.AuthProfiles)!)
|
||||||
AddAccount(new AuthLoginPassword(profile.Login, profile.Password, profile.AuthServer));
|
AddAccount(profile);
|
||||||
|
|
||||||
if (Accounts.Count == 0) UpdateAuthMenu();
|
if (Accounts.Count == 0) UpdateAuthMenu();
|
||||||
|
|
||||||
@@ -247,7 +275,7 @@ public partial class AccountInfoViewModel : ViewModelBase
|
|||||||
public async void DoCurrentAuth()
|
public async void DoCurrentAuth()
|
||||||
{
|
{
|
||||||
var message = ViewHelperService.GetViewModel<InfoPopupViewModel>();
|
var message = ViewHelperService.GetViewModel<InfoPopupViewModel>();
|
||||||
message.InfoText = "Trying to auth with saved data...";
|
message.InfoText = LocalisationService.GetString("auth-try-auth-config");
|
||||||
message.IsInfoClosable = false;
|
message.IsInfoClosable = false;
|
||||||
PopupMessageService.Popup(message);
|
PopupMessageService.Popup(message);
|
||||||
|
|
||||||
@@ -261,7 +289,7 @@ public partial class AccountInfoViewModel : ViewModelBase
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
var unexpectedError = new Exception("An unexpected error occurred during authentication.", ex);
|
var unexpectedError = new Exception(LocalisationService.GetString("auth-error"), ex);
|
||||||
_logger.Error(unexpectedError);
|
_logger.Error(unexpectedError);
|
||||||
PopupMessageService.Popup(unexpectedError);
|
PopupMessageService.Popup(unexpectedError);
|
||||||
return;
|
return;
|
||||||
@@ -274,7 +302,9 @@ public partial class AccountInfoViewModel : ViewModelBase
|
|||||||
[RelayCommand]
|
[RelayCommand]
|
||||||
private void OnSaveProfile()
|
private void OnSaveProfile()
|
||||||
{
|
{
|
||||||
AddAccount(new AuthLoginPassword(CurrentLogin, CurrentPassword, CurrentAuthServer));
|
if(Credentials is null) return;
|
||||||
|
|
||||||
|
AddAccount(Credentials);
|
||||||
_isProfilesEmpty = Accounts.Count == 0;
|
_isProfilesEmpty = Accounts.Count == 0;
|
||||||
UpdateAuthMenu();
|
UpdateAuthMenu();
|
||||||
DirtyProfile();
|
DirtyProfile();
|
||||||
@@ -290,7 +320,7 @@ public partial class AccountInfoViewModel : ViewModelBase
|
|||||||
|
|
||||||
private void PopupError(string message, Exception e)
|
private void PopupError(string message, Exception e)
|
||||||
{
|
{
|
||||||
message = "An error occurred during authentication: " + message;
|
message = LocalisationService.GetString("auth-error-occured") + message;
|
||||||
_logger.Error(new Exception(message, e));
|
_logger.Error(new Exception(message, e));
|
||||||
|
|
||||||
var messageView = ViewHelperService.GetViewModel<InfoPopupViewModel>();
|
var messageView = ViewHelperService.GetViewModel<InfoPopupViewModel>();
|
||||||
@@ -315,18 +345,6 @@ public partial class AccountInfoViewModel : ViewModelBase
|
|||||||
private void DirtyProfile()
|
private void DirtyProfile()
|
||||||
{
|
{
|
||||||
ConfigurationService.SetConfigValue(LauncherConVar.AuthProfiles,
|
ConfigurationService.SetConfigValue(LauncherConVar.AuthProfiles,
|
||||||
Accounts.ToArray());
|
Accounts.Select(a => a.Credentials).ToArray());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
|
||||||
);
|
|
||||||
@@ -7,13 +7,16 @@ using System.IO;
|
|||||||
using System.IO.Compression;
|
using System.IO.Compression;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using Avalonia;
|
using Avalonia;
|
||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
using Avalonia.Layout;
|
using Avalonia.Layout;
|
||||||
using Nebula.Launcher.Services;
|
using Nebula.Launcher.Services;
|
||||||
|
using Nebula.Launcher.ViewModels.Popup;
|
||||||
using Nebula.Launcher.Views.Pages;
|
using Nebula.Launcher.Views.Pages;
|
||||||
using Nebula.Shared;
|
using Nebula.Shared;
|
||||||
using Nebula.Shared.Services;
|
using Nebula.Shared.Services;
|
||||||
|
using Nebula.Shared.ViewHelper;
|
||||||
|
|
||||||
namespace Nebula.Launcher.ViewModels.Pages;
|
namespace Nebula.Launcher.ViewModels.Pages;
|
||||||
|
|
||||||
@@ -26,14 +29,18 @@ public partial class ConfigurationViewModel : ViewModelBase
|
|||||||
[GenerateProperty] private ConfigurationService ConfigurationService { get; } = default!;
|
[GenerateProperty] private ConfigurationService ConfigurationService { get; } = default!;
|
||||||
[GenerateProperty] private PopupMessageService PopupService { get; } = default!;
|
[GenerateProperty] private PopupMessageService PopupService { get; } = default!;
|
||||||
[GenerateProperty] private FileService FileService { get; set; } = 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)
|
public void AddCvarConf<T>(ConVar<T> cvar)
|
||||||
{
|
{
|
||||||
ConfigurationVerbose.Add(
|
ConfigurationVerbose.Add(
|
||||||
ConfigControlHelper.GetConfigControl(cvar.Name, ConfigurationService.GetConfigValue(cvar)));
|
ConfigControlHelper.GetConfigControl(cvar.Name, ConfigurationService.GetConfigValue(cvar)!));
|
||||||
ConVarList.Add((cvar, cvar.Type));
|
_conVarList.Add((cvar, cvar.Type));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void InvokeUpdateConfiguration()
|
public void InvokeUpdateConfiguration()
|
||||||
@@ -44,7 +51,7 @@ public partial class ConfigurationViewModel : ViewModelBase
|
|||||||
if(!conVarControl.Dirty)
|
if(!conVarControl.Dirty)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
var conVar = ConVarList[i];
|
var conVar = _conVarList[i];
|
||||||
var methodInfo = ConfigurationService.GetType().GetMethod("SetConfigValue")!.MakeGenericMethod(conVar.Item2);
|
var methodInfo = ConfigurationService.GetType().GetMethod("SetConfigValue")!.MakeGenericMethod(conVar.Item2);
|
||||||
methodInfo.Invoke(ConfigurationService, [conVar.Item1, conVarControl.GetValue()]);
|
methodInfo.Invoke(ConfigurationService, [conVar.Item1, conVarControl.GetValue()]);
|
||||||
}
|
}
|
||||||
@@ -52,13 +59,13 @@ public partial class ConfigurationViewModel : ViewModelBase
|
|||||||
|
|
||||||
public void ResetConfig()
|
public void ResetConfig()
|
||||||
{
|
{
|
||||||
foreach (var conVar in ConVarList)
|
foreach (var conVar in _conVarList)
|
||||||
{
|
{
|
||||||
var methodInfo = ConfigurationService.GetType().GetMethod("SetConfigValue")!.MakeGenericMethod(conVar.Item2);
|
var methodInfo = ConfigurationService.GetType().GetMethod("SetConfigValue")!.MakeGenericMethod(conVar.Item2);
|
||||||
methodInfo.Invoke(ConfigurationService, [conVar.Item1, null]);
|
methodInfo.Invoke(ConfigurationService, [conVar.Item1, null]);
|
||||||
}
|
}
|
||||||
|
|
||||||
ConVarList.Clear();
|
_conVarList.Clear();
|
||||||
ConfigurationVerbose.Clear();
|
ConfigurationVerbose.Clear();
|
||||||
|
|
||||||
InitConfiguration();
|
InitConfiguration();
|
||||||
@@ -81,6 +88,17 @@ public partial class ConfigurationViewModel : ViewModelBase
|
|||||||
ExplorerHelper.OpenFolder(path);
|
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()
|
private void InitConfiguration()
|
||||||
{
|
{
|
||||||
AddCvarConf(LauncherConVar.ILSpyUrl);
|
AddCvarConf(LauncherConVar.ILSpyUrl);
|
||||||
@@ -176,7 +194,7 @@ public sealed class ComplexUnitConfigControl : Border, IConfigControl
|
|||||||
|
|
||||||
var propValue = propInfo.GetValue(value);
|
var propValue = propInfo.GetValue(value);
|
||||||
|
|
||||||
var control = ConfigControlHelper.GetConfigControl(propInfo.Name, propValue);
|
var control = ConfigControlHelper.GetConfigControl(propInfo.Name, propValue!);
|
||||||
|
|
||||||
((Control)control).Margin = new Thickness(5);
|
((Control)control).Margin = new Thickness(5);
|
||||||
_panel.Children.Add((Control)control);
|
_panel.Children.Add((Control)control);
|
||||||
@@ -192,7 +210,7 @@ public sealed class ComplexUnitConfigControl : Border, IConfigControl
|
|||||||
fieldInfo.SetValue(obj, configControl.GetValue());
|
fieldInfo.SetValue(obj, configControl.GetValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
return obj;
|
return obj!;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -200,7 +218,10 @@ public sealed class ArrayUnitConfigControl : Border, IConfigControl
|
|||||||
{
|
{
|
||||||
private readonly List<IConfigControl> _itemControls = [];
|
private readonly List<IConfigControl> _itemControls = [];
|
||||||
private readonly StackPanel _itemsPanel = new StackPanel() { Orientation = Orientation.Vertical };
|
private readonly StackPanel _itemsPanel = new StackPanel() { Orientation = Orientation.Vertical };
|
||||||
private readonly Button _addButton = new Button() { Content = "Add Item", Classes = { "ConfigBorder" }};
|
private readonly Button _addButton = new Button() { Content = new Label()
|
||||||
|
{
|
||||||
|
Content = "Add Item"
|
||||||
|
}, Classes = { "ConfigBorder" }};
|
||||||
private readonly int _oldCount;
|
private readonly int _oldCount;
|
||||||
private readonly Type _elementType;
|
private readonly Type _elementType;
|
||||||
private readonly StackPanel _panel = new();
|
private readonly StackPanel _panel = new();
|
||||||
@@ -232,7 +253,7 @@ public sealed class ArrayUnitConfigControl : Border, IConfigControl
|
|||||||
{
|
{
|
||||||
var itemPanel = new StackPanel { Orientation = Orientation.Horizontal, Spacing = 2 };
|
var itemPanel = new StackPanel { Orientation = Orientation.Horizontal, Spacing = 2 };
|
||||||
var control = ConfigControlHelper.GetConfigControl(_itemControls.Count.ToString(), value);
|
var control = ConfigControlHelper.GetConfigControl(_itemControls.Count.ToString(), value);
|
||||||
var removeButton = new Button { Content = "Remove", Classes = { "ConfigBorder" }};
|
var removeButton = new Button { Content = new Label(){ Content = "Remove" }, Classes = { "ConfigBorder" }};
|
||||||
|
|
||||||
removeButton.Click += (_, _) =>
|
removeButton.Click += (_, _) =>
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ using Nebula.Shared.FileApis;
|
|||||||
using Nebula.Shared.Models;
|
using Nebula.Shared.Models;
|
||||||
using Nebula.Shared.Services;
|
using Nebula.Shared.Services;
|
||||||
using Nebula.Shared.Utils;
|
using Nebula.Shared.Utils;
|
||||||
|
using Nebula.Shared.ViewHelper;
|
||||||
|
|
||||||
namespace Nebula.Launcher.ViewModels.Pages;
|
namespace Nebula.Launcher.ViewModels.Pages;
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ using Nebula.Launcher.Views.Pages;
|
|||||||
using Nebula.Shared;
|
using Nebula.Shared;
|
||||||
using Nebula.Shared.Models;
|
using Nebula.Shared.Models;
|
||||||
using Nebula.Shared.Services;
|
using Nebula.Shared.Services;
|
||||||
|
using Nebula.Shared.ViewHelper;
|
||||||
|
|
||||||
namespace Nebula.Launcher.ViewModels.Pages;
|
namespace Nebula.Launcher.ViewModels.Pages;
|
||||||
|
|
||||||
@@ -29,7 +30,6 @@ public partial class ServerOverviewModel : ViewModelBase
|
|||||||
|
|
||||||
public readonly ServerFilter CurrentFilter = new();
|
public readonly ServerFilter CurrentFilter = new();
|
||||||
|
|
||||||
public Action? OnSearchChange;
|
|
||||||
[GenerateProperty] private IServiceProvider ServiceProvider { get; }
|
[GenerateProperty] private IServiceProvider ServiceProvider { get; }
|
||||||
[GenerateProperty] private ConfigurationService ConfigurationService { get; }
|
[GenerateProperty] private ConfigurationService ConfigurationService { get; }
|
||||||
[GenerateProperty] private FavoriteServerListProvider FavoriteServerListProvider { get; }
|
[GenerateProperty] private FavoriteServerListProvider FavoriteServerListProvider { get; }
|
||||||
@@ -71,13 +71,11 @@ public partial class ServerOverviewModel : ViewModelBase
|
|||||||
Items = new ObservableCollection<ServerListTabTemplate>(tempItems);
|
Items = new ObservableCollection<ServerListTabTemplate>(tempItems);
|
||||||
|
|
||||||
SelectedItem = Items[0];
|
SelectedItem = Items[0];
|
||||||
|
|
||||||
OnSearchChange += SearchChangeEvent;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SearchChangeEvent()
|
partial void OnSearchTextChanged(string value)
|
||||||
{
|
{
|
||||||
CurrentFilter.SearchText = SearchText;
|
CurrentFilter.SearchText = value;
|
||||||
ApplyFilter();
|
ApplyFilter();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -319,5 +317,3 @@ public sealed class ServerFilter
|
|||||||
return IsMatchByName(name) && IsMatchByTags(itemTags);
|
return IsMatchByName(name) && IsMatchByTags(itemTags);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public sealed record ServerCustomNameEntry(string Url, string Name);
|
|
||||||
@@ -1,11 +1,13 @@
|
|||||||
using System;
|
using System;
|
||||||
using CommunityToolkit.Mvvm.ComponentModel;
|
using CommunityToolkit.Mvvm.ComponentModel;
|
||||||
using Nebula.Launcher.ServerListProviders;
|
using Nebula.Launcher.ServerListProviders;
|
||||||
|
using Nebula.Launcher.Services;
|
||||||
using Nebula.Launcher.ViewModels.Pages;
|
using Nebula.Launcher.ViewModels.Pages;
|
||||||
using Nebula.Launcher.Views.Pages;
|
using Nebula.Launcher.Views.Pages;
|
||||||
using Nebula.Shared.Services;
|
using Nebula.Shared.Services;
|
||||||
using Nebula.Shared.Services.Logging;
|
using Nebula.Shared.Services.Logging;
|
||||||
using Nebula.Shared.Utils;
|
using Nebula.Shared.Utils;
|
||||||
|
using Nebula.Shared.ViewHelper;
|
||||||
using AddFavoriteView = Nebula.Launcher.Views.Popup.AddFavoriteView;
|
using AddFavoriteView = Nebula.Launcher.Views.Popup.AddFavoriteView;
|
||||||
|
|
||||||
namespace Nebula.Launcher.ViewModels.Popup;
|
namespace Nebula.Launcher.ViewModels.Popup;
|
||||||
@@ -30,7 +32,7 @@ public partial class AddFavoriteViewModel : PopupViewModelBase
|
|||||||
[GenerateProperty] private ServerOverviewModel ServerOverviewModel { get; }
|
[GenerateProperty] private ServerOverviewModel ServerOverviewModel { get; }
|
||||||
[GenerateProperty] private DebugService DebugService { get; }
|
[GenerateProperty] private DebugService DebugService { get; }
|
||||||
[GenerateProperty] private FavoriteServerListProvider FavoriteServerListProvider { get; }
|
[GenerateProperty] private FavoriteServerListProvider FavoriteServerListProvider { get; }
|
||||||
public override string Title => "Add to favorite";
|
public override string Title => LocalisationService.GetString("popup-add-favorite");
|
||||||
public override bool IsClosable => true;
|
public override bool IsClosable => true;
|
||||||
|
|
||||||
[ObservableProperty] private string _ipInput;
|
[ObservableProperty] private string _ipInput;
|
||||||
@@ -40,6 +42,9 @@ public partial class AddFavoriteViewModel : PopupViewModelBase
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
if(string.IsNullOrWhiteSpace(IpInput))
|
||||||
|
throw new Exception(LocalisationService.GetString("popup-add-favorite-invalid-ip"));
|
||||||
|
|
||||||
var uri = IpInput.ToRobustUrl();
|
var uri = IpInput.ToRobustUrl();
|
||||||
FavoriteServerListProvider.AddFavorite(uri);
|
FavoriteServerListProvider.AddFavorite(uri);
|
||||||
Dispose();
|
Dispose();
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
using CommunityToolkit.Mvvm.ComponentModel;
|
using CommunityToolkit.Mvvm.ComponentModel;
|
||||||
|
using Nebula.Launcher.Services;
|
||||||
using Nebula.Launcher.Views.Popup;
|
using Nebula.Launcher.Views.Popup;
|
||||||
using Nebula.Shared.Services;
|
using Nebula.Shared.Services;
|
||||||
|
using Nebula.Shared.ViewHelper;
|
||||||
|
|
||||||
namespace Nebula.Launcher.ViewModels.Popup;
|
namespace Nebula.Launcher.ViewModels.Popup;
|
||||||
|
|
||||||
@@ -10,7 +12,7 @@ public sealed partial class EditServerNameViewModel : PopupViewModelBase
|
|||||||
{
|
{
|
||||||
[GenerateProperty] public override PopupMessageService PopupMessageService { get; }
|
[GenerateProperty] public override PopupMessageService PopupMessageService { get; }
|
||||||
[GenerateProperty] public ConfigurationService ConfigurationService { get; }
|
[GenerateProperty] public ConfigurationService ConfigurationService { get; }
|
||||||
public override string Title => "Edit server name";
|
public override string Title => LocalisationService.GetString("popup-edit-name");
|
||||||
public override bool IsClosable => true;
|
public override bool IsClosable => true;
|
||||||
|
|
||||||
[ObservableProperty] private string _ipInput;
|
[ObservableProperty] private string _ipInput;
|
||||||
@@ -23,8 +25,7 @@ public sealed partial class EditServerNameViewModel : PopupViewModelBase
|
|||||||
|
|
||||||
if (string.IsNullOrWhiteSpace(NameInput))
|
if (string.IsNullOrWhiteSpace(NameInput))
|
||||||
{
|
{
|
||||||
RemoveServerName();
|
OnClear();
|
||||||
Dispose();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -32,6 +33,12 @@ public sealed partial class EditServerNameViewModel : PopupViewModelBase
|
|||||||
Dispose();
|
Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void OnClear()
|
||||||
|
{
|
||||||
|
RemoveServerName();
|
||||||
|
Dispose();
|
||||||
|
}
|
||||||
|
|
||||||
private void AddServerName()
|
private void AddServerName()
|
||||||
{
|
{
|
||||||
var currentNames = ConfigurationService.GetConfigValue(LauncherConVar.ServerCustomNames)!;
|
var currentNames = ConfigurationService.GetConfigValue(LauncherConVar.ServerCustomNames)!;
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
|
using Nebula.Launcher.Services;
|
||||||
using Nebula.Launcher.Views.Popup;
|
using Nebula.Launcher.Views.Popup;
|
||||||
using Nebula.Shared.Services;
|
using Nebula.Shared.Services;
|
||||||
|
using Nebula.Shared.ViewHelper;
|
||||||
|
|
||||||
namespace Nebula.Launcher.ViewModels.Popup;
|
namespace Nebula.Launcher.ViewModels.Popup;
|
||||||
|
|
||||||
@@ -10,7 +12,7 @@ namespace Nebula.Launcher.ViewModels.Popup;
|
|||||||
public sealed partial class ExceptionListViewModel : PopupViewModelBase
|
public sealed partial class ExceptionListViewModel : PopupViewModelBase
|
||||||
{
|
{
|
||||||
[GenerateProperty] public override PopupMessageService PopupMessageService { get; }
|
[GenerateProperty] public override PopupMessageService PopupMessageService { get; }
|
||||||
public override string Title => "Exception was thrown";
|
public override string Title => LocalisationService.GetString("popup-exception");
|
||||||
public override bool IsClosable => true;
|
public override bool IsClosable => true;
|
||||||
|
|
||||||
public ObservableCollection<Exception> Errors { get; } = new();
|
public ObservableCollection<Exception> Errors { get; } = new();
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
using CommunityToolkit.Mvvm.ComponentModel;
|
using CommunityToolkit.Mvvm.ComponentModel;
|
||||||
|
using Nebula.Launcher.Services;
|
||||||
using Nebula.Launcher.Views.Popup;
|
using Nebula.Launcher.Views.Popup;
|
||||||
using Nebula.Shared.Services;
|
using Nebula.Shared.Services;
|
||||||
|
using Nebula.Shared.ViewHelper;
|
||||||
|
|
||||||
namespace Nebula.Launcher.ViewModels.Popup;
|
namespace Nebula.Launcher.ViewModels.Popup;
|
||||||
|
|
||||||
@@ -12,7 +14,7 @@ public partial class InfoPopupViewModel : PopupViewModelBase
|
|||||||
|
|
||||||
[ObservableProperty] private string _infoText = "Test";
|
[ObservableProperty] private string _infoText = "Test";
|
||||||
|
|
||||||
public override string Title => "Info";
|
public override string Title => LocalisationService.GetString("popup-information");
|
||||||
public bool IsInfoClosable { get; set; } = true;
|
public bool IsInfoClosable { get; set; } = true;
|
||||||
public override bool IsClosable => IsInfoClosable;
|
public override bool IsClosable => IsInfoClosable;
|
||||||
|
|
||||||
|
|||||||
@@ -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;
|
||||||
|
}
|
||||||
@@ -1,7 +1,9 @@
|
|||||||
using CommunityToolkit.Mvvm.ComponentModel;
|
using CommunityToolkit.Mvvm.ComponentModel;
|
||||||
|
using Nebula.Launcher.Services;
|
||||||
using Nebula.Launcher.Views.Popup;
|
using Nebula.Launcher.Views.Popup;
|
||||||
using Nebula.Shared.Models;
|
using Nebula.Shared.Models;
|
||||||
using Nebula.Shared.Services;
|
using Nebula.Shared.Services;
|
||||||
|
using Nebula.Shared.ViewHelper;
|
||||||
|
|
||||||
namespace Nebula.Launcher.ViewModels.Popup;
|
namespace Nebula.Launcher.ViewModels.Popup;
|
||||||
|
|
||||||
@@ -13,10 +15,10 @@ public sealed partial class LoadingContextViewModel : PopupViewModelBase, ILoadi
|
|||||||
[GenerateProperty] public CancellationService CancellationService { get; }
|
[GenerateProperty] public CancellationService CancellationService { get; }
|
||||||
|
|
||||||
[ObservableProperty] private int _currJobs;
|
[ObservableProperty] private int _currJobs;
|
||||||
|
|
||||||
[ObservableProperty] private int _resolvedJobs;
|
[ObservableProperty] private int _resolvedJobs;
|
||||||
|
[ObservableProperty] private string _message = string.Empty;
|
||||||
|
|
||||||
public string LoadingName { get; set; } = "Loading...";
|
public string LoadingName { get; set; } = LocalisationService.GetString("popup-loading");
|
||||||
public bool IsCancellable { get; set; } = true;
|
public bool IsCancellable { get; set; } = true;
|
||||||
public override bool IsClosable => false;
|
public override bool IsClosable => false;
|
||||||
|
|
||||||
@@ -42,6 +44,11 @@ public sealed partial class LoadingContextViewModel : PopupViewModelBase, ILoadi
|
|||||||
return ResolvedJobs;
|
return ResolvedJobs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void SetLoadingMessage(string message)
|
||||||
|
{
|
||||||
|
Message = message + "\n" + Message;
|
||||||
|
}
|
||||||
|
|
||||||
public void Cancel(){
|
public void Cancel(){
|
||||||
if(!IsCancellable) return;
|
if(!IsCancellable) return;
|
||||||
CancellationService.Cancel();
|
CancellationService.Cancel();
|
||||||
@@ -54,5 +61,30 @@ public sealed partial class LoadingContextViewModel : PopupViewModelBase, ILoadi
|
|||||||
|
|
||||||
protected override void InitialiseInDesignMode()
|
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.Collections.ObjectModel;
|
||||||
using System.Text.RegularExpressions;
|
using Nebula.Launcher.Models;
|
||||||
using Avalonia.Media;
|
|
||||||
using Nebula.Launcher.Views.Popup;
|
using Nebula.Launcher.Views.Popup;
|
||||||
using Nebula.Shared.Services;
|
using Nebula.Shared.Services;
|
||||||
|
using Nebula.Shared.ViewHelper;
|
||||||
|
|
||||||
namespace Nebula.Launcher.ViewModels.Popup;
|
namespace Nebula.Launcher.ViewModels.Popup;
|
||||||
|
|
||||||
@@ -43,39 +43,3 @@ public sealed partial class LogPopupModelView : PopupViewModelBase
|
|||||||
Logs.Clear();
|
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
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,6 +1,8 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using Nebula.Launcher.Services;
|
||||||
using Nebula.Launcher.Views.Popup;
|
using Nebula.Launcher.Views.Popup;
|
||||||
using Nebula.Shared.Services;
|
using Nebula.Shared.Services;
|
||||||
|
using Nebula.Shared.ViewHelper;
|
||||||
|
|
||||||
namespace Nebula.Launcher.ViewModels.Popup;
|
namespace Nebula.Launcher.ViewModels.Popup;
|
||||||
|
|
||||||
@@ -24,6 +26,6 @@ public partial class TfaViewModel : PopupViewModelBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
[GenerateProperty] public override PopupMessageService PopupMessageService { get; }
|
[GenerateProperty] public override PopupMessageService PopupMessageService { get; }
|
||||||
public override string Title => "2fa";
|
public override string Title => LocalisationService.GetString("popup-twofa");
|
||||||
public override bool IsClosable => true;
|
public override bool IsClosable => true;
|
||||||
}
|
}
|
||||||
@@ -6,11 +6,13 @@ using Avalonia.Media;
|
|||||||
using Avalonia.Threading;
|
using Avalonia.Threading;
|
||||||
using CommunityToolkit.Mvvm.ComponentModel;
|
using CommunityToolkit.Mvvm.ComponentModel;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Nebula.Launcher.Models;
|
||||||
using Nebula.Launcher.ServerListProviders;
|
using Nebula.Launcher.ServerListProviders;
|
||||||
using Nebula.Launcher.ViewModels.Pages;
|
using Nebula.Launcher.ViewModels.Pages;
|
||||||
using Nebula.Launcher.Views;
|
using Nebula.Launcher.Views;
|
||||||
using Nebula.Shared.Models;
|
using Nebula.Shared.Models;
|
||||||
using Nebula.Shared.Services;
|
using Nebula.Shared.Services;
|
||||||
|
using Nebula.Shared.ViewHelper;
|
||||||
using BindingFlags = System.Reflection.BindingFlags;
|
using BindingFlags = System.Reflection.BindingFlags;
|
||||||
|
|
||||||
namespace Nebula.Launcher.ViewModels;
|
namespace Nebula.Launcher.ViewModels;
|
||||||
@@ -27,6 +29,8 @@ public sealed partial class ServerCompoundEntryViewModel :
|
|||||||
[ObservableProperty] private bool _loading = true;
|
[ObservableProperty] private bool _loading = true;
|
||||||
|
|
||||||
private string? _name;
|
private string? _name;
|
||||||
|
private RobustUrl? _url;
|
||||||
|
private ServerFilter? _currentFilter;
|
||||||
|
|
||||||
public string? Name
|
public string? Name
|
||||||
{
|
{
|
||||||
@@ -58,14 +62,16 @@ public sealed partial class ServerCompoundEntryViewModel :
|
|||||||
{
|
{
|
||||||
Task.Run(async () =>
|
Task.Run(async () =>
|
||||||
{
|
{
|
||||||
|
_url = url;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Message = "Loading server entry...";
|
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.IsFavorite = IsFavorite;
|
||||||
CurrentEntry.Loading = false;
|
CurrentEntry.Loading = false;
|
||||||
|
CurrentEntry.ProcessFilter(_currentFilter);
|
||||||
Loading = false;
|
Loading = false;
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
@@ -79,12 +85,20 @@ public sealed partial class ServerCompoundEntryViewModel :
|
|||||||
|
|
||||||
public void ToggleFavorites()
|
public void ToggleFavorites()
|
||||||
{
|
{
|
||||||
|
if (CurrentEntry is null && _url is not null)
|
||||||
|
{
|
||||||
|
IsFavorite = !IsFavorite;
|
||||||
|
if(IsFavorite) FavoriteServerListProvider.AddFavorite(_url);
|
||||||
|
else FavoriteServerListProvider.RemoveFavorite(_url);
|
||||||
|
}
|
||||||
|
|
||||||
CurrentEntry?.ToggleFavorites();
|
CurrentEntry?.ToggleFavorites();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void ProcessFilter(ServerFilter? serverFilter)
|
public void ProcessFilter(ServerFilter? serverFilter)
|
||||||
{
|
{
|
||||||
|
_currentFilter = serverFilter;
|
||||||
if(CurrentEntry is IFilterConsumer filterConsumer)
|
if(CurrentEntry is IFilterConsumer filterConsumer)
|
||||||
filterConsumer.ProcessFilter(serverFilter);
|
filterConsumer.ProcessFilter(serverFilter);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ using System.Threading.Tasks;
|
|||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
using CommunityToolkit.Mvvm.ComponentModel;
|
using CommunityToolkit.Mvvm.ComponentModel;
|
||||||
|
using Nebula.Launcher.Models;
|
||||||
using Nebula.Launcher.ProcessHelper;
|
using Nebula.Launcher.ProcessHelper;
|
||||||
using Nebula.Launcher.ServerListProviders;
|
using Nebula.Launcher.ServerListProviders;
|
||||||
using Nebula.Launcher.Services;
|
using Nebula.Launcher.Services;
|
||||||
@@ -16,6 +17,7 @@ using Nebula.Shared.Models;
|
|||||||
using Nebula.Shared.Services;
|
using Nebula.Shared.Services;
|
||||||
using Nebula.Shared.Services.Logging;
|
using Nebula.Shared.Services.Logging;
|
||||||
using Nebula.Shared.Utils;
|
using Nebula.Shared.Utils;
|
||||||
|
using Nebula.Shared.ViewHelper;
|
||||||
|
|
||||||
namespace Nebula.Launcher.ViewModels;
|
namespace Nebula.Launcher.ViewModels;
|
||||||
|
|
||||||
@@ -45,7 +47,7 @@ public partial class ServerEntryModelView : ViewModelBase, IFilterConsumer, ILis
|
|||||||
|
|
||||||
public LogPopupModelView CurrLog;
|
public LogPopupModelView CurrLog;
|
||||||
public RobustUrl Address { get; private set; }
|
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 CancellationService CancellationService { get; } = default!;
|
||||||
[GenerateProperty] private DebugService DebugService { get; } = default!;
|
[GenerateProperty] private DebugService DebugService { get; } = default!;
|
||||||
[GenerateProperty] private PopupMessageService PopupMessageService { get; } = default!;
|
[GenerateProperty] private PopupMessageService PopupMessageService { get; } = default!;
|
||||||
@@ -161,11 +163,26 @@ public partial class ServerEntryModelView : ViewModelBase, IFilterConsumer, ILis
|
|||||||
public void RunInstance()
|
public void RunInstance()
|
||||||
{
|
{
|
||||||
CurrLog.Clear();
|
CurrLog.Clear();
|
||||||
Task.Run(RunInstanceAsync);
|
Task.Run(async ()=> await RunInstanceAsync());
|
||||||
}
|
}
|
||||||
|
|
||||||
private async void RunInstanceAsync()
|
public void RunInstanceIgnoreAuth()
|
||||||
{
|
{
|
||||||
|
CurrLog.Clear();
|
||||||
|
Task.Run(async ()=> await RunInstanceAsync(true));
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task RunInstanceAsync(bool ignoreLoginCredentials = false)
|
||||||
|
{
|
||||||
|
if (!ignoreLoginCredentials && AccountInfoViewModel.Credentials is null)
|
||||||
|
{
|
||||||
|
var warningContext = ViewHelperService.GetViewModel<IsLoginCredentialsNullPopupViewModel>()
|
||||||
|
.WithServerEntry(this);
|
||||||
|
|
||||||
|
PopupMessageService.Popup(warningContext);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
using var loadingContext = ViewHelperService.GetViewModel<LoadingContextViewModel>();
|
using var loadingContext = ViewHelperService.GetViewModel<LoadingContextViewModel>();
|
||||||
loadingContext.LoadingName = "Loading instance...";
|
loadingContext.LoadingName = "Loading instance...";
|
||||||
((ILoadingHandler)loadingContext).AppendJob();
|
((ILoadingHandler)loadingContext).AppendJob();
|
||||||
@@ -217,35 +234,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 class LinkGoCommand : ICommand
|
||||||
{
|
{
|
||||||
public LinkGoCommand()
|
public LinkGoCommand()
|
||||||
@@ -266,8 +254,3 @@ public class LinkGoCommand : ICommand
|
|||||||
|
|
||||||
public event EventHandler? CanExecuteChanged;
|
public event EventHandler? CanExecuteChanged;
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface IFilterConsumer
|
|
||||||
{
|
|
||||||
public void ProcessFilter(ServerFilter? serverFilter);
|
|
||||||
}
|
|
||||||
@@ -1,22 +1,11 @@
|
|||||||
using Avalonia;
|
|
||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
using Avalonia.Markup.Xaml;
|
|
||||||
using Nebula.Launcher.ViewModels.Pages;
|
|
||||||
|
|
||||||
namespace Nebula.Launcher.Views;
|
namespace Nebula.Launcher.Views;
|
||||||
|
|
||||||
public partial class FileContentEntryView : UserControl
|
public partial class FileContentEntryView : UserControl
|
||||||
{
|
{
|
||||||
// This constructor is used when the view is created by the XAML Previewer
|
|
||||||
public FileContentEntryView()
|
public FileContentEntryView()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
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:converters="clr-namespace:Nebula.Launcher.Converters"
|
||||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
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:viewModels="clr-namespace:Nebula.Launcher.ViewModels"
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
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>
|
<Design.DataContext>
|
||||||
<viewModels:MainViewModel />
|
<viewModels:MainViewModel />
|
||||||
</Design.DataContext>
|
</Design.DataContext>
|
||||||
@@ -121,7 +121,40 @@
|
|||||||
https://durenko.tatar/nebula/
|
https://durenko.tatar/nebula/
|
||||||
</TextBlock>
|
</TextBlock>
|
||||||
</Button>
|
</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" IsVisible="{Binding IsLoggedIn}" Text="{Binding LoginText}"/>
|
||||||
|
<TextBlock Foreground="#777777" IsVisible="{Binding !IsLoggedIn}" Text="{services:LocaledText auth-current-login-no-name}"/>
|
||||||
|
</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>
|
</Panel>
|
||||||
</Label>
|
</Label>
|
||||||
</Border>
|
</Border>
|
||||||
|
|||||||
@@ -1,20 +1,11 @@
|
|||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
using Nebula.Launcher.ViewModels;
|
|
||||||
|
|
||||||
namespace Nebula.Launcher.Views;
|
namespace Nebula.Launcher.Views;
|
||||||
|
|
||||||
public partial class MainView : UserControl
|
public partial class MainView : UserControl
|
||||||
{
|
{
|
||||||
// This constructor is used when the view is created by the XAML Previewer
|
|
||||||
public MainView()
|
public MainView()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
}
|
}
|
||||||
|
|
||||||
// This constructor is used when the view is created via dependency injection
|
|
||||||
public MainView(MainViewModel viewModel)
|
|
||||||
: this()
|
|
||||||
{
|
|
||||||
DataContext = viewModel;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -5,10 +5,12 @@
|
|||||||
x:Class="Nebula.Launcher.Views.Pages.AccountInfoView"
|
x:Class="Nebula.Launcher.Views.Pages.AccountInfoView"
|
||||||
x:DataType="pages:AccountInfoViewModel"
|
x:DataType="pages:AccountInfoViewModel"
|
||||||
xmlns="https://github.com/avaloniaui"
|
xmlns="https://github.com/avaloniaui"
|
||||||
|
xmlns:customControls="clr-namespace:Nebula.Launcher.Controls"
|
||||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
xmlns:pages="clr-namespace:Nebula.Launcher.ViewModels.Pages"
|
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">
|
||||||
<Design.DataContext>
|
<Design.DataContext>
|
||||||
<pages:AccountInfoViewModel />
|
<pages:AccountInfoViewModel />
|
||||||
</Design.DataContext>
|
</Design.DataContext>
|
||||||
@@ -28,7 +30,7 @@
|
|||||||
<GradientStop Color="#292222" Offset="1.0" />
|
<GradientStop Color="#292222" Offset="1.0" />
|
||||||
</LinearGradientBrush>
|
</LinearGradientBrush>
|
||||||
</Border.Background>
|
</Border.Background>
|
||||||
<Label HorizontalAlignment="Center">Profiles:</Label>
|
<customControls:LocalizedLabel HorizontalAlignment="Center" LocalId="account-profiles"/>
|
||||||
</Border>
|
</Border>
|
||||||
<ScrollViewer HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto">
|
<ScrollViewer HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto">
|
||||||
<ItemsControl
|
<ItemsControl
|
||||||
@@ -36,7 +38,7 @@
|
|||||||
ItemsSource="{Binding Accounts}"
|
ItemsSource="{Binding Accounts}"
|
||||||
Padding="0">
|
Padding="0">
|
||||||
<ItemsControl.ItemTemplate>
|
<ItemsControl.ItemTemplate>
|
||||||
<DataTemplate DataType="{x:Type pages:ProfileAuthCredentials}">
|
<DataTemplate DataType="{x:Type auth:ProfileAuthCredentials}">
|
||||||
<Border
|
<Border
|
||||||
BoxShadow="0 1 15 -2 #121212"
|
BoxShadow="0 1 15 -2 #121212"
|
||||||
CornerRadius="0,10,0,10"
|
CornerRadius="0,10,0,10"
|
||||||
@@ -51,7 +53,7 @@
|
|||||||
<Panel>
|
<Panel>
|
||||||
<StackPanel Margin="10,5,5,5" Orientation="Horizontal">
|
<StackPanel Margin="10,5,5,5" Orientation="Horizontal">
|
||||||
<Label>
|
<Label>
|
||||||
<TextBlock Text="{Binding Login}" />
|
<TextBlock Text="{Binding Credentials.Login}" />
|
||||||
</Label>
|
</Label>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
<StackPanel HorizontalAlignment="Right" Orientation="Horizontal">
|
<StackPanel HorizontalAlignment="Right" Orientation="Horizontal">
|
||||||
@@ -59,17 +61,13 @@
|
|||||||
Command="{Binding OnSelect}"
|
Command="{Binding OnSelect}"
|
||||||
CornerRadius="0,0,0,10"
|
CornerRadius="0,0,0,10"
|
||||||
Padding="5">
|
Padding="5">
|
||||||
<Label>
|
<customControls:LocalizedLabel LocalId="account-profile-select"/>
|
||||||
Select
|
|
||||||
</Label>
|
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
Command="{Binding OnDelete}"
|
Command="{Binding OnDelete}"
|
||||||
CornerRadius="0,10,0,0"
|
CornerRadius="0,10,0,0"
|
||||||
Padding="5">
|
Padding="5">
|
||||||
<Label>
|
<customControls:LocalizedLabel LocalId="account-profile-delete"/>
|
||||||
Delete
|
|
||||||
</Label>
|
|
||||||
</Button>
|
</Button>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</Panel>
|
</Panel>
|
||||||
@@ -108,27 +106,21 @@
|
|||||||
Command="{Binding DoCurrentAuth}"
|
Command="{Binding DoCurrentAuth}"
|
||||||
HorizontalAlignment="Stretch"
|
HorizontalAlignment="Stretch"
|
||||||
HorizontalContentAlignment="Center">
|
HorizontalContentAlignment="Center">
|
||||||
<Label>Retry previous auth</Label>
|
<customControls:LocalizedLabel LocalId="account-auth-retry"/>
|
||||||
</Button>
|
</Button>
|
||||||
</Border>
|
</Border>
|
||||||
<Label HorizontalAlignment="Center">Or try another account</Label>
|
<customControls:LocalizedLabel HorizontalAlignment="Center" LocalId="account-auth-try-another"/>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
<StackPanel Orientation="Horizontal">
|
<StackPanel Orientation="Horizontal">
|
||||||
<Label VerticalAlignment="Center">
|
<customControls:LocalizedLabel VerticalAlignment="Center" LocalId="account-auth-login"/>
|
||||||
Login:
|
|
||||||
</Label>
|
|
||||||
<TextBox Text="{Binding CurrentLogin}" MinWidth="200" />
|
<TextBox Text="{Binding CurrentLogin}" MinWidth="200" />
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
<StackPanel Orientation="Horizontal">
|
<StackPanel Orientation="Horizontal">
|
||||||
<Label HorizontalAlignment="Left" VerticalAlignment="Center">
|
<customControls:LocalizedLabel HorizontalAlignment="Left" VerticalAlignment="Center" LocalId="account-auth-password"/>
|
||||||
Password:
|
|
||||||
</Label>
|
|
||||||
<TextBox PasswordChar="#" MinWidth="200" Text="{Binding CurrentPassword}" />
|
<TextBox PasswordChar="#" MinWidth="200" Text="{Binding CurrentPassword}" />
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
<StackPanel Orientation="Horizontal">
|
<StackPanel Orientation="Horizontal">
|
||||||
<Label VerticalAlignment="Center">
|
<customControls:LocalizedLabel VerticalAlignment="Center" LocalId="account-auth-server"/>
|
||||||
Auth server:
|
|
||||||
</Label>
|
|
||||||
<Button Command="{Binding ExpandAuthUrlCommand}" VerticalAlignment="Stretch">
|
<Button Command="{Binding ExpandAuthUrlCommand}" VerticalAlignment="Stretch">
|
||||||
<Label>+</Label>
|
<Label>+</Label>
|
||||||
</Button>
|
</Button>
|
||||||
@@ -161,15 +153,7 @@
|
|||||||
Command="{Binding DoAuth}"
|
Command="{Binding DoAuth}"
|
||||||
HorizontalAlignment="Stretch"
|
HorizontalAlignment="Stretch"
|
||||||
HorizontalContentAlignment="Center">
|
HorizontalContentAlignment="Center">
|
||||||
<Label>Auth</Label>
|
<customControls:LocalizedLabel LocalId="account-auth-button"/>
|
||||||
</Button>
|
|
||||||
</Border>
|
|
||||||
<Border BoxShadow="{StaticResource DefaultShadow}">
|
|
||||||
<Button
|
|
||||||
Command="{Binding SaveProfileCommand}"
|
|
||||||
HorizontalAlignment="Stretch"
|
|
||||||
HorizontalContentAlignment="Center">
|
|
||||||
<Label>Save profile</Label>
|
|
||||||
</Button>
|
</Button>
|
||||||
</Border>
|
</Border>
|
||||||
<Button Command="{Binding ExpandAuthViewCommand}" HorizontalAlignment="Right">
|
<Button Command="{Binding ExpandAuthViewCommand}" HorizontalAlignment="Right">
|
||||||
@@ -186,7 +170,7 @@
|
|||||||
Path="/Assets/svg/user.svg" />
|
Path="/Assets/svg/user.svg" />
|
||||||
<Label>
|
<Label>
|
||||||
<StackPanel HorizontalAlignment="Center" Orientation="Horizontal">
|
<StackPanel HorizontalAlignment="Center" Orientation="Horizontal">
|
||||||
<TextBlock>Hello,</TextBlock>
|
<customControls:LocalizedLabel LocalId="account-auth-hello"/>
|
||||||
<TextBlock Text="{Binding CurrentLogin}" />
|
<TextBlock Text="{Binding CurrentLogin}" />
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</Label>
|
</Label>
|
||||||
@@ -197,12 +181,12 @@
|
|||||||
Spacing="5">
|
Spacing="5">
|
||||||
<Border BoxShadow="{StaticResource DefaultShadow}">
|
<Border BoxShadow="{StaticResource DefaultShadow}">
|
||||||
<Button Command="{Binding Logout}">
|
<Button Command="{Binding Logout}">
|
||||||
<Label>Logout</Label>
|
<customControls:LocalizedLabel LocalId="account-auth-logout"/>
|
||||||
</Button>
|
</Button>
|
||||||
</Border>
|
</Border>
|
||||||
<Border BoxShadow="{StaticResource DefaultShadow}">
|
<Border BoxShadow="{StaticResource DefaultShadow}">
|
||||||
<Button Command="{Binding SaveProfileCommand}">
|
<Button Command="{Binding SaveProfileCommand}">
|
||||||
<Label>Save profile</Label>
|
<customControls:LocalizedLabel LocalId="account-auth-save"/>
|
||||||
</Button>
|
</Button>
|
||||||
</Border>
|
</Border>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
using AccountInfoViewModel = Nebula.Launcher.ViewModels.Pages.AccountInfoViewModel;
|
|
||||||
|
|
||||||
namespace Nebula.Launcher.Views.Pages;
|
namespace Nebula.Launcher.Views.Pages;
|
||||||
|
|
||||||
@@ -9,10 +8,4 @@ public partial class AccountInfoView : UserControl
|
|||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
}
|
}
|
||||||
|
|
||||||
public AccountInfoView(AccountInfoViewModel viewModel)
|
|
||||||
: this()
|
|
||||||
{
|
|
||||||
DataContext = viewModel;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -3,6 +3,7 @@
|
|||||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
xmlns:pages="clr-namespace:Nebula.Launcher.ViewModels.Pages"
|
xmlns:pages="clr-namespace:Nebula.Launcher.ViewModels.Pages"
|
||||||
|
xmlns:customControls="clr-namespace:Nebula.Launcher.Controls"
|
||||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||||
x:Class="Nebula.Launcher.Views.Pages.ConfigurationView"
|
x:Class="Nebula.Launcher.Views.Pages.ConfigurationView"
|
||||||
x:DataType="pages:ConfigurationViewModel">
|
x:DataType="pages:ConfigurationViewModel">
|
||||||
@@ -21,7 +22,8 @@
|
|||||||
</ItemsPanelTemplate>
|
</ItemsPanelTemplate>
|
||||||
</ItemsControl.ItemsPanel>
|
</ItemsControl.ItemsPanel>
|
||||||
</ItemsControl>
|
</ItemsControl>
|
||||||
<StackPanel Orientation="Horizontal" Spacing="5">
|
|
||||||
|
<WrapPanel Orientation="Horizontal">
|
||||||
<Button
|
<Button
|
||||||
Classes="ConfigBorder"
|
Classes="ConfigBorder"
|
||||||
VerticalAlignment="Bottom"
|
VerticalAlignment="Bottom"
|
||||||
@@ -29,7 +31,7 @@
|
|||||||
Padding="5"
|
Padding="5"
|
||||||
Margin="5"
|
Margin="5"
|
||||||
Command="{Binding InvokeUpdateConfiguration}">
|
Command="{Binding InvokeUpdateConfiguration}">
|
||||||
Save
|
<customControls:LocalizedLabel LocalId="config-save"/>
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
Classes="ConfigBorder"
|
Classes="ConfigBorder"
|
||||||
@@ -38,7 +40,7 @@
|
|||||||
Padding="5"
|
Padding="5"
|
||||||
Margin="5"
|
Margin="5"
|
||||||
Command="{Binding ResetConfig}">
|
Command="{Binding ResetConfig}">
|
||||||
Reset to default
|
<customControls:LocalizedLabel LocalId="config-reset"/>
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
Classes="ConfigBorder"
|
Classes="ConfigBorder"
|
||||||
@@ -47,7 +49,7 @@
|
|||||||
Padding="5"
|
Padding="5"
|
||||||
Margin="5"
|
Margin="5"
|
||||||
Command="{Binding OpenDataFolder}">
|
Command="{Binding OpenDataFolder}">
|
||||||
Open Data path
|
<customControls:LocalizedLabel LocalId="config-open-data"/>
|
||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
@@ -57,9 +59,19 @@
|
|||||||
Padding="5"
|
Padding="5"
|
||||||
Margin="5"
|
Margin="5"
|
||||||
Command="{Binding ExportLogs}">
|
Command="{Binding ExportLogs}">
|
||||||
Export logs
|
<customControls:LocalizedLabel LocalId="config-export-logs"/>
|
||||||
</Button>
|
</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>
|
</StackPanel>
|
||||||
</ScrollViewer>
|
</ScrollViewer>
|
||||||
</UserControl>
|
</UserControl>
|
||||||
|
|||||||
@@ -1,7 +1,4 @@
|
|||||||
using Avalonia;
|
|
||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
using Avalonia.Markup.Xaml;
|
|
||||||
using Nebula.Launcher.ViewModels.Pages;
|
|
||||||
|
|
||||||
namespace Nebula.Launcher.Views.Pages;
|
namespace Nebula.Launcher.Views.Pages;
|
||||||
|
|
||||||
@@ -11,10 +8,4 @@ public partial class ConfigurationView : UserControl
|
|||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConfigurationView(ConfigurationViewModel viewModel)
|
|
||||||
: this()
|
|
||||||
{
|
|
||||||
DataContext = viewModel;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -8,7 +8,8 @@
|
|||||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
xmlns:pages="clr-namespace:Nebula.Launcher.ViewModels.Pages"
|
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:services="clr-namespace:Nebula.Launcher.Services">
|
||||||
<Design.DataContext>
|
<Design.DataContext>
|
||||||
<pages:ContentBrowserViewModel />
|
<pages:ContentBrowserViewModel />
|
||||||
</Design.DataContext>
|
</Design.DataContext>
|
||||||
@@ -31,14 +32,14 @@
|
|||||||
Margin="5"
|
Margin="5"
|
||||||
Text="{Binding ServerText}"
|
Text="{Binding ServerText}"
|
||||||
VerticalAlignment="Center"
|
VerticalAlignment="Center"
|
||||||
Watermark="Server Url..." />
|
Watermark="{services:LocaledText content-view-server}" />
|
||||||
<TextBox
|
<TextBox
|
||||||
Grid.Column="1"
|
Grid.Column="1"
|
||||||
Grid.Row="0"
|
Grid.Row="0"
|
||||||
Margin="5"
|
Margin="5"
|
||||||
Text="{Binding SearchText}"
|
Text="{Binding SearchText}"
|
||||||
VerticalAlignment="Center"
|
VerticalAlignment="Center"
|
||||||
Watermark="Path..." />
|
Watermark="{services:LocaledText content-view-path}" />
|
||||||
<Button
|
<Button
|
||||||
Command="{Binding OnBackEnter}"
|
Command="{Binding OnBackEnter}"
|
||||||
Grid.Column="2"
|
Grid.Column="2"
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
using ContentBrowserViewModel = Nebula.Launcher.ViewModels.Pages.ContentBrowserViewModel;
|
|
||||||
|
|
||||||
namespace Nebula.Launcher.Views.Pages;
|
namespace Nebula.Launcher.Views.Pages;
|
||||||
|
|
||||||
@@ -9,10 +8,4 @@ public partial class ContentBrowserView : UserControl
|
|||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ContentBrowserView(ContentBrowserViewModel viewModel)
|
|
||||||
: this()
|
|
||||||
{
|
|
||||||
DataContext = viewModel;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -10,7 +10,8 @@
|
|||||||
xmlns:pages="clr-namespace:Nebula.Launcher.ViewModels.Pages"
|
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:controls="clr-namespace:Nebula.Launcher.Controls"
|
xmlns:controls="clr-namespace:Nebula.Launcher.Controls"
|
||||||
xmlns:models="clr-namespace:Nebula.Launcher.Models">
|
xmlns:models="clr-namespace:Nebula.Launcher.Models"
|
||||||
|
xmlns:services="clr-namespace:Nebula.Launcher.Services">
|
||||||
|
|
||||||
<Design.DataContext>
|
<Design.DataContext>
|
||||||
<pages:ServerOverviewModel />
|
<pages:ServerOverviewModel />
|
||||||
@@ -51,8 +52,8 @@
|
|||||||
VerticalAlignment="Bottom"
|
VerticalAlignment="Bottom"
|
||||||
IsVisible="{Binding IsFilterVisible}">
|
IsVisible="{Binding IsFilterVisible}">
|
||||||
<StackPanel Orientation="Vertical" Spacing="2" Margin="15">
|
<StackPanel Orientation="Vertical" Spacing="2" Margin="15">
|
||||||
<controls:FilterBox Name="EssentialFilters" FilterBoxName="Roleplay" FilterCommand="{Binding OnFilterChanged}"/>
|
<controls:FilterBox Name="EssentialFilters" FilterBoxName="filter-roleplay" FilterCommand="{Binding OnFilterChanged}"/>
|
||||||
<controls:FilterBox Name="LanguageFilters" FilterBoxName="Language" FilterCommand="{Binding OnFilterChanged}"/>
|
<controls:FilterBox Name="LanguageFilters" FilterBoxName="filter-language" FilterCommand="{Binding OnFilterChanged}"/>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</Border>
|
</Border>
|
||||||
|
|
||||||
@@ -70,9 +71,8 @@
|
|||||||
<TextBox
|
<TextBox
|
||||||
Margin="25,0,0,0"
|
Margin="25,0,0,0"
|
||||||
Text="{Binding SearchText}"
|
Text="{Binding SearchText}"
|
||||||
TextChanged="TextBox_OnTextChanged"
|
|
||||||
VerticalAlignment="Center"
|
VerticalAlignment="Center"
|
||||||
Watermark="Server name..." />
|
Watermark="{services:LocaledText 'server-search'}" />
|
||||||
<Button
|
<Button
|
||||||
Command="{Binding FilterRequired}"
|
Command="{Binding FilterRequired}"
|
||||||
Grid.Column="2"
|
Grid.Column="2"
|
||||||
|
|||||||
@@ -1,11 +1,9 @@
|
|||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
using Nebula.Launcher.ViewModels.Pages;
|
|
||||||
|
|
||||||
namespace Nebula.Launcher.Views.Pages;
|
namespace Nebula.Launcher.Views.Pages;
|
||||||
|
|
||||||
public partial class ServerOverviewView : UserControl
|
public partial class ServerOverviewView : UserControl
|
||||||
{
|
{
|
||||||
// This constructor is used when the view is created by the XAML Previewer
|
|
||||||
public ServerOverviewView()
|
public ServerOverviewView()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
@@ -19,17 +17,4 @@ public partial class ServerOverviewView : UserControl
|
|||||||
LanguageFilters.AddFilter("RU","lang:ru");
|
LanguageFilters.AddFilter("RU","lang:ru");
|
||||||
LanguageFilters.AddFilter("EN","lang:en");
|
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();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -8,6 +8,7 @@
|
|||||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
xmlns:popup="clr-namespace:Nebula.Launcher.ViewModels.Popup"
|
xmlns:popup="clr-namespace:Nebula.Launcher.ViewModels.Popup"
|
||||||
|
xmlns:customControls="clr-namespace:Nebula.Launcher.Controls"
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
|
||||||
<Design.DataContext>
|
<Design.DataContext>
|
||||||
<popup:AddFavoriteViewModel />
|
<popup:AddFavoriteViewModel />
|
||||||
@@ -18,7 +19,7 @@
|
|||||||
</Border>
|
</Border>
|
||||||
<Border Background="{StaticResource DefaultSelected}" BoxShadow="{StaticResource DefaultShadow}">
|
<Border Background="{StaticResource DefaultSelected}" BoxShadow="{StaticResource DefaultShadow}">
|
||||||
<Button Command="{Binding OnEnter}" HorizontalAlignment="Stretch">
|
<Button Command="{Binding OnEnter}" HorizontalAlignment="Stretch">
|
||||||
<Label HorizontalAlignment="Center">Add</Label>
|
<customControls:LocalizedLabel HorizontalAlignment="Center" LocalId="favorite-add"/>
|
||||||
</Button>
|
</Button>
|
||||||
</Border>
|
</Border>
|
||||||
<Label>
|
<Label>
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
using Nebula.Launcher.ViewModels.Popup;
|
|
||||||
|
|
||||||
namespace Nebula.Launcher.Views.Popup;
|
namespace Nebula.Launcher.Views.Popup;
|
||||||
|
|
||||||
@@ -9,10 +8,4 @@ public partial class AddFavoriteView : UserControl
|
|||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
}
|
}
|
||||||
|
|
||||||
public AddFavoriteView(AddFavoriteViewModel viewModel)
|
|
||||||
: this()
|
|
||||||
{
|
|
||||||
DataContext = viewModel;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -3,6 +3,7 @@
|
|||||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
xmlns:popup="clr-namespace:Nebula.Launcher.ViewModels.Popup"
|
xmlns:popup="clr-namespace:Nebula.Launcher.ViewModels.Popup"
|
||||||
|
xmlns:customControls="clr-namespace:Nebula.Launcher.Controls"
|
||||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||||
x:Class="Nebula.Launcher.Views.Popup.EditServerNameView"
|
x:Class="Nebula.Launcher.Views.Popup.EditServerNameView"
|
||||||
x:DataType="popup:EditServerNameViewModel">
|
x:DataType="popup:EditServerNameViewModel">
|
||||||
@@ -19,7 +20,12 @@
|
|||||||
</Border>
|
</Border>
|
||||||
<Border Background="{StaticResource DefaultSelected}" BoxShadow="{StaticResource DefaultShadow}">
|
<Border Background="{StaticResource DefaultSelected}" BoxShadow="{StaticResource DefaultShadow}">
|
||||||
<Button Command="{Binding OnEnter}" HorizontalAlignment="Stretch">
|
<Button Command="{Binding OnEnter}" HorizontalAlignment="Stretch">
|
||||||
<Label HorizontalAlignment="Center">Set name</Label>
|
<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>
|
</Button>
|
||||||
</Border>
|
</Border>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
|
|||||||
@@ -1,7 +1,4 @@
|
|||||||
using Avalonia;
|
|
||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
using Avalonia.Markup.Xaml;
|
|
||||||
using Nebula.Launcher.ViewModels.Popup;
|
|
||||||
|
|
||||||
namespace Nebula.Launcher.Views.Popup;
|
namespace Nebula.Launcher.Views.Popup;
|
||||||
|
|
||||||
@@ -11,10 +8,4 @@ public partial class EditServerNameView : UserControl
|
|||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
}
|
}
|
||||||
|
|
||||||
public EditServerNameView(EditServerNameViewModel viewModel)
|
|
||||||
: this()
|
|
||||||
{
|
|
||||||
DataContext = viewModel;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
using Nebula.Launcher.ViewModels.Popup;
|
|
||||||
|
|
||||||
namespace Nebula.Launcher.Views.Popup;
|
namespace Nebula.Launcher.Views.Popup;
|
||||||
|
|
||||||
@@ -9,9 +8,4 @@ public partial class ExceptionListView : UserControl
|
|||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ExceptionListView(ExceptionListViewModel listViewModel) : this()
|
|
||||||
{
|
|
||||||
DataContext = listViewModel;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -15,7 +15,7 @@
|
|||||||
|
|
||||||
<Panel HorizontalAlignment="Center" VerticalAlignment="Center">
|
<Panel HorizontalAlignment="Center" VerticalAlignment="Center">
|
||||||
<Label>
|
<Label>
|
||||||
<TextBlock Text="{Binding InfoText}" />
|
<TextBlock Text="{Binding InfoText}" TextWrapping="Wrap"/>
|
||||||
</Label>
|
</Label>
|
||||||
</Panel>
|
</Panel>
|
||||||
</UserControl>
|
</UserControl>
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
using InfoPopupViewModel = Nebula.Launcher.ViewModels.Popup.InfoPopupViewModel;
|
|
||||||
|
|
||||||
namespace Nebula.Launcher.Views.Popup;
|
namespace Nebula.Launcher.Views.Popup;
|
||||||
|
|
||||||
@@ -9,9 +8,4 @@ public partial class InfoPopupView : UserControl
|
|||||||
{
|
{
|
||||||
InitializeComponent();
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
|
xmlns:customControls="clr-namespace:Nebula.Launcher.Controls"
|
||||||
xmlns:popup="clr-namespace:Nebula.Launcher.ViewModels.Popup"
|
xmlns:popup="clr-namespace:Nebula.Launcher.ViewModels.Popup"
|
||||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||||
x:Class="Nebula.Launcher.Views.Popup.LoadingContextView"
|
x:Class="Nebula.Launcher.Views.Popup.LoadingContextView"
|
||||||
@@ -29,8 +30,13 @@
|
|||||||
VerticalAlignment="Center"
|
VerticalAlignment="Center"
|
||||||
Command="{Binding Cancel}"
|
Command="{Binding Cancel}"
|
||||||
IsVisible="{Binding IsCancellable}">
|
IsVisible="{Binding IsCancellable}">
|
||||||
<Label>Cancel</Label>
|
<customControls:LocalizedLabel LocalId="task-cancel"/>
|
||||||
</Button>
|
</Button>
|
||||||
</Panel>
|
</Panel>
|
||||||
|
<Panel>
|
||||||
|
<Border Background="{StaticResource DefaultForeground}" MinHeight="210">
|
||||||
|
<TextBlock TextWrapping="Wrap" Text="{Binding Message}" MaxLines="10" Margin="15"/>
|
||||||
|
</Border>
|
||||||
|
</Panel>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</UserControl>
|
</UserControl>
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
using LoadingContextViewModel = Nebula.Launcher.ViewModels.Popup.LoadingContextViewModel;
|
|
||||||
|
|
||||||
namespace Nebula.Launcher.Views.Popup;
|
namespace Nebula.Launcher.Views.Popup;
|
||||||
|
|
||||||
@@ -9,9 +8,4 @@ public partial class LoadingContextView : UserControl
|
|||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
}
|
}
|
||||||
|
|
||||||
public LoadingContextView(LoadingContextViewModel viewModel) : this()
|
|
||||||
{
|
|
||||||
DataContext = viewModel;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -4,6 +4,7 @@
|
|||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
xmlns:viewModels="clr-namespace:Nebula.Launcher.ViewModels"
|
xmlns:viewModels="clr-namespace:Nebula.Launcher.ViewModels"
|
||||||
xmlns:popup="clr-namespace:Nebula.Launcher.ViewModels.Popup"
|
xmlns:popup="clr-namespace:Nebula.Launcher.ViewModels.Popup"
|
||||||
|
xmlns:models="clr-namespace:Nebula.Launcher.Models"
|
||||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||||
x:Class="Nebula.Launcher.Views.Popup.LogPopupView"
|
x:Class="Nebula.Launcher.Views.Popup.LogPopupView"
|
||||||
x:DataType="popup:LogPopupModelView">
|
x:DataType="popup:LogPopupModelView">
|
||||||
@@ -17,7 +18,7 @@
|
|||||||
ItemsSource="{Binding Logs}"
|
ItemsSource="{Binding Logs}"
|
||||||
Padding="0">
|
Padding="0">
|
||||||
<ItemsControl.ItemTemplate>
|
<ItemsControl.ItemTemplate>
|
||||||
<DataTemplate DataType="{x:Type popup:LogInfo}">
|
<DataTemplate DataType="{x:Type models:LogInfo}">
|
||||||
<Border CornerRadius="5" Margin="0,0,0,5">
|
<Border CornerRadius="5" Margin="0,0,0,5">
|
||||||
<StackPanel Orientation="Horizontal" Spacing="5" Margin="0">
|
<StackPanel Orientation="Horizontal" Spacing="5" Margin="0">
|
||||||
<Border MinWidth="100"
|
<Border MinWidth="100"
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
using Nebula.Launcher.ViewModels.Popup;
|
|
||||||
|
|
||||||
namespace Nebula.Launcher.Views.Popup;
|
namespace Nebula.Launcher.Views.Popup;
|
||||||
|
|
||||||
@@ -9,9 +8,4 @@ public partial class LogPopupView : UserControl
|
|||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
}
|
}
|
||||||
|
|
||||||
public LogPopupView(LogPopupModelView viewModel) : this()
|
|
||||||
{
|
|
||||||
DataContext = viewModel;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
|
xmlns:customControls="clr-namespace:Nebula.Launcher.Controls"
|
||||||
xmlns:popup="clr-namespace:Nebula.Launcher.ViewModels.Popup"
|
xmlns:popup="clr-namespace:Nebula.Launcher.ViewModels.Popup"
|
||||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||||
x:Class="Nebula.Launcher.Views.Popup.TfaView">
|
x:Class="Nebula.Launcher.Views.Popup.TfaView">
|
||||||
@@ -9,7 +10,7 @@
|
|||||||
<popup:TfaViewModel />
|
<popup:TfaViewModel />
|
||||||
</Design.DataContext>
|
</Design.DataContext>
|
||||||
<StackPanel HorizontalAlignment="Stretch" Spacing="25" VerticalAlignment="Center">
|
<StackPanel HorizontalAlignment="Stretch" Spacing="25" VerticalAlignment="Center">
|
||||||
<Label HorizontalAlignment="Center">You have two-factor authentication enabled. Please enter the code.</Label>
|
<customControls:LocalizedLabel HorizontalAlignment="Center" LocalId="twofa-enabled"/>
|
||||||
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Spacing="10" x:Name="TContainer">
|
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Spacing="10" x:Name="TContainer">
|
||||||
<Border BoxShadow="{StaticResource DefaultShadow}">
|
<Border BoxShadow="{StaticResource DefaultShadow}">
|
||||||
<TextBox MaxLength="1"/>
|
<TextBox MaxLength="1"/>
|
||||||
@@ -32,7 +33,7 @@
|
|||||||
</StackPanel>
|
</StackPanel>
|
||||||
<Border BoxShadow="{StaticResource DefaultShadow}" Background="{StaticResource DefaultSelected}" HorizontalAlignment="Center">
|
<Border BoxShadow="{StaticResource DefaultShadow}" Background="{StaticResource DefaultSelected}" HorizontalAlignment="Center">
|
||||||
<Button Click="Button_OnClick">
|
<Button Click="Button_OnClick">
|
||||||
<Label HorizontalAlignment="Center" Margin="15,5,15,5">OK</Label>
|
<customControls:LocalizedLabel HorizontalAlignment="Center" Margin="15,5,15,5" LocalId="twofa-set"/>
|
||||||
</Button>
|
</Button>
|
||||||
</Border>
|
</Border>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
|
|||||||
@@ -1,11 +1,8 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Avalonia;
|
|
||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
using Avalonia.Input;
|
using Avalonia.Input;
|
||||||
using Avalonia.Interactivity;
|
using Avalonia.Interactivity;
|
||||||
using Avalonia.Markup.Xaml;
|
|
||||||
using Nebula.Launcher.ViewModels.Popup;
|
using Nebula.Launcher.ViewModels.Popup;
|
||||||
|
|
||||||
namespace Nebula.Launcher.Views.Popup;
|
namespace Nebula.Launcher.Views.Popup;
|
||||||
@@ -88,11 +85,6 @@ public partial class TfaView : UserControl
|
|||||||
return (TextBox)box.Child!;
|
return (TextBox)box.Child!;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TfaView(TfaViewModel tfaViewModel) : this()
|
|
||||||
{
|
|
||||||
DataContext = tfaViewModel;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void Button_OnClick(object? sender, RoutedEventArgs e)
|
private void Button_OnClick(object? sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
CheckupCode();
|
CheckupCode();
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
using Nebula.Launcher.ViewModels;
|
|
||||||
|
|
||||||
namespace Nebula.Launcher.Views;
|
namespace Nebula.Launcher.Views;
|
||||||
|
|
||||||
@@ -9,9 +8,4 @@ public partial class ServerCompoundEntryView : UserControl
|
|||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ServerCompoundEntryView(ServerCompoundEntryViewModel viewModel) : this()
|
|
||||||
{
|
|
||||||
DataContext = viewModel;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -13,6 +13,7 @@
|
|||||||
xmlns:viewModels="clr-namespace:Nebula.Launcher.ViewModels"
|
xmlns:viewModels="clr-namespace:Nebula.Launcher.ViewModels"
|
||||||
xmlns:views="clr-namespace:Nebula.Launcher.Views"
|
xmlns:views="clr-namespace:Nebula.Launcher.Views"
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:services="clr-namespace:Nebula.Launcher.Services"
|
||||||
IsVisible="{Binding IsVisible}">
|
IsVisible="{Binding IsVisible}">
|
||||||
<Design.DataContext>
|
<Design.DataContext>
|
||||||
<viewModels:ServerEntryModelView />
|
<viewModels:ServerEntryModelView />
|
||||||
@@ -144,7 +145,7 @@
|
|||||||
Margin="5">
|
Margin="5">
|
||||||
<StackPanel Margin="5" Spacing="5">
|
<StackPanel Margin="5" Spacing="5">
|
||||||
<StackPanel Orientation="Horizontal">
|
<StackPanel Orientation="Horizontal">
|
||||||
<Label FontSize="10" VerticalAlignment="Center">Tags:</Label>
|
<Label FontSize="10" VerticalAlignment="Center" Content="{services:LocaledText serverentry-tag}"/>
|
||||||
<ItemsControl ItemsSource="{Binding Tags}">
|
<ItemsControl ItemsSource="{Binding Tags}">
|
||||||
<ItemsControl.ItemTemplate>
|
<ItemsControl.ItemTemplate>
|
||||||
<DataTemplate DataType="{x:Type system:String}">
|
<DataTemplate DataType="{x:Type system:String}">
|
||||||
@@ -175,7 +176,7 @@
|
|||||||
</StackPanel>
|
</StackPanel>
|
||||||
|
|
||||||
<StackPanel Orientation="Horizontal">
|
<StackPanel Orientation="Horizontal">
|
||||||
<Label FontSize="10" VerticalAlignment="Center">Map:</Label>
|
<Label FontSize="10" VerticalAlignment="Center" Content="{services:LocaledText serverentry-map}"/>
|
||||||
<Border
|
<Border
|
||||||
Background="{StaticResource DefaultForeground}"
|
Background="{StaticResource DefaultForeground}"
|
||||||
BorderThickness="0"
|
BorderThickness="0"
|
||||||
@@ -190,7 +191,7 @@
|
|||||||
</StackPanel>
|
</StackPanel>
|
||||||
|
|
||||||
<StackPanel Orientation="Horizontal">
|
<StackPanel Orientation="Horizontal">
|
||||||
<Label FontSize="10" VerticalAlignment="Center">Preset:</Label>
|
<Label FontSize="10" VerticalAlignment="Center" Content="{services:LocaledText serverentry-preset}"/>
|
||||||
<Border
|
<Border
|
||||||
Background="{StaticResource DefaultForeground}"
|
Background="{StaticResource DefaultForeground}"
|
||||||
BorderThickness="0"
|
BorderThickness="0"
|
||||||
|
|||||||
@@ -22,10 +22,7 @@ public partial class ServerEntryView : UserControl
|
|||||||
StartAutoScrolling();
|
StartAutoScrolling();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ServerEntryView(ServerEntryModelView modelView) : this()
|
|
||||||
{
|
|
||||||
DataContext = modelView;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void StartAutoScrolling()
|
private void StartAutoScrolling()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
using Nebula.Runner.Services;
|
||||||
using Nebula.Shared;
|
using Nebula.Shared;
|
||||||
using Nebula.Shared.Models;
|
using Nebula.Shared.Models;
|
||||||
using Nebula.Shared.Services;
|
using Nebula.Shared.Services;
|
||||||
@@ -27,11 +28,7 @@ public sealed class App(RunnerService runnerService, ContentService contentServi
|
|||||||
|
|
||||||
var args = new List<string>
|
var args = new List<string>
|
||||||
{
|
{
|
||||||
// Pass username to launched client.
|
|
||||||
// We don't load username from client_config.toml when launched via launcher.
|
|
||||||
"--username", login,
|
"--username", login,
|
||||||
|
|
||||||
// Tell game we are launcher
|
|
||||||
"--cvar", "launch.launcher=true"
|
"--cvar", "launch.launcher=true"
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -39,9 +36,6 @@ public sealed class App(RunnerService runnerService, ContentService contentServi
|
|||||||
if (!string.IsNullOrEmpty(buildInfo.BuildInfo.ConnectAddress))
|
if (!string.IsNullOrEmpty(buildInfo.BuildInfo.ConnectAddress))
|
||||||
connectionString = buildInfo.BuildInfo.ConnectAddress;
|
connectionString = buildInfo.BuildInfo.ConnectAddress;
|
||||||
|
|
||||||
// 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");
|
args.Add("--launcher");
|
||||||
|
|
||||||
args.Add("--connect-address");
|
args.Add("--connect-address");
|
||||||
@@ -53,65 +47,3 @@ public sealed class App(RunnerService runnerService, ContentService contentServi
|
|||||||
await runnerService.Run(args.ToArray(), buildInfo, this, new ConsoleLoadingHandler(), cancelTokenSource.Token);
|
await runnerService.Run(args.ToArray(), buildInfo, this, new ConsoleLoadingHandler(), cancelTokenSource.Token);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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,7 +12,9 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Lib.Harmony" Version="2.3.6" />
|
||||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.0"/>
|
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.0"/>
|
||||||
|
<PackageReference Include="NLua" Version="1.7.5" />
|
||||||
<PackageReference Include="SharpZstd.Interop" Version="1.5.6"/>
|
<PackageReference Include="SharpZstd.Interop" Version="1.5.6"/>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Nebula.Shared;
|
using Nebula.Shared;
|
||||||
using Nebula.Shared.Services;
|
|
||||||
|
|
||||||
namespace Nebula.Runner;
|
namespace Nebula.Runner;
|
||||||
|
|
||||||
|
|||||||
38
Nebula.Runner/Services/HarmonyService.cs
Normal file
38
Nebula.Runner/Services/HarmonyService.cs
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
using HarmonyLib;
|
||||||
|
using Nebula.Shared;
|
||||||
|
|
||||||
|
namespace Nebula.Runner.Services;
|
||||||
|
|
||||||
|
[ServiceRegister]
|
||||||
|
public class HarmonyService
|
||||||
|
{
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class HarmonyInstance
|
||||||
|
{
|
||||||
|
public readonly Harmony Harmony;
|
||||||
|
|
||||||
|
internal HarmonyInstance()
|
||||||
|
{
|
||||||
|
Harmony = new Harmony("ru.cinka.patch");
|
||||||
|
}
|
||||||
|
}
|
||||||
55
Nebula.Runner/Services/ReflectionService.cs
Normal file
55
Nebula.Runner/Services/ReflectionService.cs
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
using System.Reflection;
|
||||||
|
using Nebula.Shared;
|
||||||
|
using Nebula.Shared.Services;
|
||||||
|
|
||||||
|
namespace Nebula.Runner.Services;
|
||||||
|
|
||||||
|
[ServiceRegister]
|
||||||
|
public class ReflectionService
|
||||||
|
{
|
||||||
|
private readonly Dictionary<string, Assembly> _typeCache = new();
|
||||||
|
|
||||||
|
public ReflectionService(AssemblyService assemblyService)
|
||||||
|
{
|
||||||
|
assemblyService.OnAssemblyLoaded += OnAssemblyLoaded;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnAssemblyLoaded(Assembly obj)
|
||||||
|
{
|
||||||
|
RegisterAssembly(obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void RegisterAssembly(Assembly robustAssembly)
|
||||||
|
{
|
||||||
|
_typeCache.Add(robustAssembly.GetName().Name!, robustAssembly);
|
||||||
|
}
|
||||||
|
|
||||||
|
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)!;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string ExtrackPrefix(string path)
|
||||||
|
{
|
||||||
|
var sp = path.Split(".");
|
||||||
|
return sp[0] + "." + sp[1];
|
||||||
|
}
|
||||||
|
}
|
||||||
205
Nebula.Runner/Services/RunnerService.cs
Normal file
205
Nebula.Runner/Services/RunnerService.cs
Normal file
@@ -0,0 +1,205 @@
|
|||||||
|
using System.Globalization;
|
||||||
|
using System.Reflection;
|
||||||
|
using HarmonyLib;
|
||||||
|
using Nebula.Shared;
|
||||||
|
using Nebula.Shared.Models;
|
||||||
|
using Nebula.Shared.Services;
|
||||||
|
using Nebula.Shared.Services.Logging;
|
||||||
|
using Robust.LoaderApi;
|
||||||
|
|
||||||
|
namespace Nebula.Runner.Services;
|
||||||
|
|
||||||
|
[ServiceRegister]
|
||||||
|
public sealed class RunnerService(
|
||||||
|
ContentService contentService,
|
||||||
|
DebugService debugService,
|
||||||
|
ConfigurationService varService,
|
||||||
|
EngineService engineService,
|
||||||
|
AssemblyService assemblyService,
|
||||||
|
ReflectionService reflectionService,
|
||||||
|
HarmonyService harmonyService,
|
||||||
|
ScriptService scriptService)
|
||||||
|
{
|
||||||
|
private readonly 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,
|
||||||
|
CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
_logger.Log("Start Content!");
|
||||||
|
|
||||||
|
var engine = await engineService.EnsureEngine(buildInfo.BuildInfo.Build.EngineVersion);
|
||||||
|
|
||||||
|
if (engine is null)
|
||||||
|
throw new Exception("Engine version not found: " + buildInfo.BuildInfo.Build.EngineVersion);
|
||||||
|
|
||||||
|
var hashApi = await contentService.EnsureItems(buildInfo.RobustManifestInfo, loadingHandler, cancellationToken);
|
||||||
|
|
||||||
|
var extraMounts = new List<ApiMount>
|
||||||
|
{
|
||||||
|
new(hashApi, "/")
|
||||||
|
};
|
||||||
|
|
||||||
|
if (hashApi.TryOpen("manifest.yml", out var stream))
|
||||||
|
{
|
||||||
|
var modules = ContentManifestParser.ExtractModules(stream);
|
||||||
|
|
||||||
|
foreach (var moduleStr in modules)
|
||||||
|
{
|
||||||
|
var module =
|
||||||
|
await engineService.EnsureEngineModules(moduleStr, buildInfo.BuildInfo.Build.EngineVersion);
|
||||||
|
if (module is not null)
|
||||||
|
extraMounts.Add(new ApiMount(module, "/"));
|
||||||
|
}
|
||||||
|
|
||||||
|
await stream.DisposeAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
var args = new MainArgs(runArgs, engine, redialApi, extraMounts);
|
||||||
|
|
||||||
|
|
||||||
|
var assemblyManifest = hashApi.Manifest.Where(p =>
|
||||||
|
p.Key.StartsWith("Assemblies/"))
|
||||||
|
.Select(p =>
|
||||||
|
{
|
||||||
|
return p.Value with { Path = Path.GetFileNameWithoutExtension(p.Key) };
|
||||||
|
}).ToList();
|
||||||
|
|
||||||
|
var assembliesHash = contentService.CreateHashApi(assemblyManifest);
|
||||||
|
|
||||||
|
var contentAssemblyApi = assemblyService.Mount(assembliesHash);
|
||||||
|
|
||||||
|
foreach (var file in contentAssemblyApi.AllFiles.Where(p => Path.GetExtension(p) == ".dll"))
|
||||||
|
{
|
||||||
|
var newExt = Path.GetFileNameWithoutExtension(file);
|
||||||
|
if(!assemblyService.TryOpenAssembly(newExt, contentAssemblyApi, out _)) throw new Exception("Assembly not found: " + newExt);
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
harmonyService.CreateInstance();
|
||||||
|
|
||||||
|
IDisposable? metricServer = null;
|
||||||
|
|
||||||
|
if (MetricEnabled)
|
||||||
|
{
|
||||||
|
MetricsEnabledPatcher.ApplyPatch(reflectionService, harmonyService);
|
||||||
|
metricServer = RunHelper.RunMetric(prometheusAssembly);
|
||||||
|
}
|
||||||
|
|
||||||
|
scriptService.LoadScripts();
|
||||||
|
|
||||||
|
await Task.Run(() => loader.Main(args), cancellationToken);
|
||||||
|
|
||||||
|
metricServer?.Dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void CacheAssembly()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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();
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class ContentManifestParser
|
||||||
|
{
|
||||||
|
public static List<string> ExtractModules(Stream manifestStream)
|
||||||
|
{
|
||||||
|
using var reader = new StreamReader(manifestStream);
|
||||||
|
return ExtractModules(reader.ReadToEnd());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<string> ExtractModules(string manifestContent)
|
||||||
|
{
|
||||||
|
var modules = new List<string>();
|
||||||
|
var lines = manifestContent.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
|
||||||
|
|
||||||
|
bool inModulesSection = false;
|
||||||
|
|
||||||
|
foreach (var rawLine in lines)
|
||||||
|
{
|
||||||
|
var line = rawLine.Trim();
|
||||||
|
|
||||||
|
if (line.StartsWith("modules:"))
|
||||||
|
{
|
||||||
|
inModulesSection = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (inModulesSection)
|
||||||
|
{
|
||||||
|
if (line.StartsWith("- "))
|
||||||
|
{
|
||||||
|
modules.Add(line.Substring(2).Trim());
|
||||||
|
}
|
||||||
|
else if (!line.StartsWith(" "))
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return modules;
|
||||||
|
}
|
||||||
|
}
|
||||||
181
Nebula.Runner/Services/ScriptService.cs
Normal file
181
Nebula.Runner/Services/ScriptService.cs
Normal file
@@ -0,0 +1,181 @@
|
|||||||
|
using System.Reflection;
|
||||||
|
using System.Text.Json;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
|
using HarmonyLib;
|
||||||
|
using Nebula.Shared;
|
||||||
|
using Nebula.Shared.FileApis;
|
||||||
|
using Nebula.Shared.Services;
|
||||||
|
using NLua;
|
||||||
|
|
||||||
|
namespace Nebula.Runner.Services;
|
||||||
|
|
||||||
|
[ServiceRegister]
|
||||||
|
public class ScriptService
|
||||||
|
{
|
||||||
|
private readonly HarmonyService _harmonyService;
|
||||||
|
private readonly ReflectionService _reflectionService;
|
||||||
|
private readonly AssemblyService _assemblyService;
|
||||||
|
|
||||||
|
private readonly FileApi _scriptFileApi;
|
||||||
|
|
||||||
|
private static Dictionary<MethodBase, ScriptManifestDict> _scriptCache = [];
|
||||||
|
private static Dictionary<string, Action> _assemblyLoadingQuery = [];
|
||||||
|
|
||||||
|
public ScriptService(HarmonyService harmonyService, ReflectionService reflectionService, FileService fileService, AssemblyService assemblyService)
|
||||||
|
{
|
||||||
|
_harmonyService = harmonyService;
|
||||||
|
_reflectionService = reflectionService;
|
||||||
|
_assemblyService = assemblyService;
|
||||||
|
|
||||||
|
_scriptFileApi = fileService.CreateFileApi("scripts");
|
||||||
|
_assemblyService.OnAssemblyLoaded += OnAssemblyLoaded;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnAssemblyLoaded(Assembly obj)
|
||||||
|
{
|
||||||
|
var objName = obj.GetName().Name ?? string.Empty;
|
||||||
|
if (!_assemblyLoadingQuery.TryGetValue(objName, out var a)) return;
|
||||||
|
Console.WriteLine("Inject assembly: " + objName);
|
||||||
|
a();
|
||||||
|
_assemblyLoadingQuery.Remove(objName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void LoadScripts()
|
||||||
|
{
|
||||||
|
Console.WriteLine("Loading scripts... " + _scriptFileApi.EnumerateDirectories("").Count());
|
||||||
|
foreach (var dir in _scriptFileApi.EnumerateDirectories(""))
|
||||||
|
{
|
||||||
|
LoadScript(dir);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void LoadScript(string name)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"Reading script {name}");
|
||||||
|
var manifests = ReadManifest(name);
|
||||||
|
|
||||||
|
foreach (var entry in manifests)
|
||||||
|
{
|
||||||
|
if (entry.TypeInitializer.HasValue) LoadTypeInitializer(entry.TypeInitializer.Value, name);
|
||||||
|
if (entry.Method.HasValue) LoadMethod(entry.Method.Value, name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void LoadTypeInitializer(ScriptMethodInjectItem item, string name)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"Loading Initializer injection {name}...");
|
||||||
|
var assemblyName = _reflectionService.ExtrackPrefix(item.Method.Class);
|
||||||
|
|
||||||
|
if (!_assemblyService.Assemblies.Select(a => a.GetName().Name).Contains(assemblyName))
|
||||||
|
{
|
||||||
|
_assemblyLoadingQuery.Add(assemblyName, () => LoadTypeInitializer(item, name));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var targetType = _reflectionService.GetType(item.Method.Class);
|
||||||
|
var method = targetType.TypeInitializer;
|
||||||
|
InitialiseShared(method!, name, item);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void LoadMethod(ScriptMethodInjectItem item, string name)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"Loading method injection {name}...");
|
||||||
|
var assemblyName = _reflectionService.ExtrackPrefix(item.Method.Class);
|
||||||
|
|
||||||
|
if (!_assemblyService.Assemblies.Select(a => a.GetName().Name).Contains(assemblyName))
|
||||||
|
{
|
||||||
|
_assemblyLoadingQuery.Add(assemblyName, () => LoadMethod(item, name));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var targetType = _reflectionService.GetType(item.Method.Class);
|
||||||
|
var method = targetType.GetMethod(item.Method.Method, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static);
|
||||||
|
InitialiseShared(method!, name, item);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void InitialiseShared(MethodBase method, string scriptName, ScriptMethodInjectItem item)
|
||||||
|
{
|
||||||
|
var scriptCode = File.ReadAllText(Path.Combine(_scriptFileApi.RootPath, scriptName, item.Script.LuaFile));
|
||||||
|
|
||||||
|
var methodInfo = method as MethodInfo;
|
||||||
|
HarmonyMethod dynamicPatch;
|
||||||
|
|
||||||
|
if (methodInfo == null || methodInfo.ReturnType == typeof(void))
|
||||||
|
dynamicPatch = new HarmonyMethod(typeof(ScriptService).GetMethod(nameof(LuaPrefix), BindingFlags.Static | BindingFlags.NonPublic));
|
||||||
|
else
|
||||||
|
dynamicPatch = new HarmonyMethod(typeof(ScriptService).GetMethod(nameof(LuaPrefixResult), BindingFlags.Static | BindingFlags.NonPublic));
|
||||||
|
|
||||||
|
_scriptCache[method] = new ScriptManifestDict(scriptCode, item);
|
||||||
|
|
||||||
|
_harmonyService.Instance.Harmony.Patch(method, prefix: dynamicPatch);
|
||||||
|
Console.WriteLine($"Injected {scriptName}");
|
||||||
|
}
|
||||||
|
|
||||||
|
private ScriptEntry[] ReadManifest(string scriptName)
|
||||||
|
{
|
||||||
|
if(!_scriptFileApi.TryOpen(Path.Join(scriptName, "MANIFEST.json"), out var stream))
|
||||||
|
throw new FileNotFoundException(Path.Join(scriptName, "MANIFEST.json") + " not found manifest!");
|
||||||
|
|
||||||
|
return JsonSerializer.Deserialize<ScriptEntry[]>(stream) ?? [];
|
||||||
|
}
|
||||||
|
|
||||||
|
private static bool LuaPrefix(MethodBase __originalMethod, object __instance)
|
||||||
|
{
|
||||||
|
if (!_scriptCache.TryGetValue(__originalMethod, out var luaCode))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
using var lua = new Lua();
|
||||||
|
|
||||||
|
lua["this"] = __instance;
|
||||||
|
|
||||||
|
var results = lua.DoString(luaCode.Code);
|
||||||
|
|
||||||
|
if (results is { Length: > 0 } && results[0] is bool b)
|
||||||
|
return b;
|
||||||
|
|
||||||
|
return luaCode.ScriptMethodInjectItem.ContinueAfterInject;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static bool LuaPrefixResult(MethodBase __originalMethod, object __instance, ref object __result)
|
||||||
|
{
|
||||||
|
if (!_scriptCache.TryGetValue(__originalMethod, out var luaCode))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
using var lua = new Lua();
|
||||||
|
|
||||||
|
lua["this"] = __instance;
|
||||||
|
lua["result"] = __result;
|
||||||
|
|
||||||
|
var results = lua.DoString(luaCode.Code);
|
||||||
|
|
||||||
|
if (lua["result"] != null)
|
||||||
|
__result = lua["result"];
|
||||||
|
|
||||||
|
if (results is { Length: > 0 } && results[0] is bool b)
|
||||||
|
return b;
|
||||||
|
|
||||||
|
return luaCode.ScriptMethodInjectItem.ContinueAfterInject;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public record struct ScriptManifestDict(string Code, ScriptMethodInjectItem ScriptMethodInjectItem);
|
||||||
|
|
||||||
|
public record struct ScriptEntry(
|
||||||
|
[property: JsonPropertyName("method")] ScriptMethodInjectItem? Method,
|
||||||
|
[property: JsonPropertyName("type_initializer")] ScriptMethodInjectItem? TypeInitializer
|
||||||
|
);
|
||||||
|
|
||||||
|
public record struct ScriptMethodInjectItem(
|
||||||
|
[property: JsonPropertyName("method")] ScriptMethodInfo Method,
|
||||||
|
[property: JsonPropertyName("continue")] bool ContinueAfterInject,
|
||||||
|
[property: JsonPropertyName("script")] LuaMethodEntry Script
|
||||||
|
);
|
||||||
|
|
||||||
|
public record struct ScriptMethodInfo(
|
||||||
|
[property: JsonPropertyName("class")] string Class,
|
||||||
|
[property: JsonPropertyName("method")] string Method
|
||||||
|
);
|
||||||
|
|
||||||
|
public record struct LuaMethodEntry(
|
||||||
|
[property: JsonPropertyName("lua_file")] string LuaFile
|
||||||
|
);
|
||||||
39
Nebula.Shared/ConfigMigrations/ProfileMigration.cs
Normal file
39
Nebula.Shared/ConfigMigrations/ProfileMigration.cs
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Nebula.Shared.Models;
|
||||||
|
using Nebula.Shared.Services;
|
||||||
|
|
||||||
|
namespace Nebula.Shared.ConfigMigrations;
|
||||||
|
|
||||||
|
public class ProfileMigrationV2(string oldName, string newName)
|
||||||
|
: BaseConfigurationMigration<ProfileAuthCredentialsV2[], AuthTokenCredentials[]>(oldName, newName)
|
||||||
|
{
|
||||||
|
protected override async Task<AuthTokenCredentials[]> Migrate(IServiceProvider serviceProvider, ProfileAuthCredentialsV2[] oldValue, ILoadingHandler loadingHandler)
|
||||||
|
{
|
||||||
|
loadingHandler.SetLoadingMessage("Migrating Profile V2 -> V3");
|
||||||
|
var list = new List<AuthTokenCredentials>();
|
||||||
|
var authService = serviceProvider.GetRequiredService<AuthService>();
|
||||||
|
var logger = serviceProvider.GetRequiredService<DebugService>().GetLogger("ProfileMigrationV2");
|
||||||
|
foreach (var oldCredentials in oldValue)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
loadingHandler.SetLoadingMessage($"Migrating {oldCredentials.Login}");
|
||||||
|
var newCred = await authService.Auth(oldCredentials.Login, oldCredentials.Password, oldCredentials.AuthServer);
|
||||||
|
list.Add(newCred);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
logger.Error(e);
|
||||||
|
loadingHandler.SetLoadingMessage(e.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
loadingHandler.SetLoadingMessage("Migration done!");
|
||||||
|
return list.ToArray();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public sealed record ProfileAuthCredentialsV2(
|
||||||
|
string Login,
|
||||||
|
string Password,
|
||||||
|
string AuthServer);
|
||||||
@@ -28,6 +28,8 @@ public static class CurrentConVar
|
|||||||
ConVarBuilder.Build<Dictionary<string, EngineVersionInfo>>("engine.manifest.backup");
|
ConVarBuilder.Build<Dictionary<string, EngineVersionInfo>>("engine.manifest.backup");
|
||||||
public static readonly ConVar<ModulesInfo> ModuleManifestBackup =
|
public static readonly ConVar<ModulesInfo> ModuleManifestBackup =
|
||||||
ConVarBuilder.Build<ModulesInfo>("module.manifest.backup");
|
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",
|
public static readonly ConVar<Dictionary<string,string>> DotnetUrl = ConVarBuilder.Build<Dictionary<string,string>>("dotnet.url",
|
||||||
new(){
|
new(){
|
||||||
|
|||||||
@@ -75,6 +75,11 @@ public sealed class FileApi : IReadWriteFileApi
|
|||||||
return File.Exists(fullPath);
|
return File.Exists(fullPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IEnumerable<string> EnumerateDirectories(string path)
|
||||||
|
{
|
||||||
|
return Directory.GetDirectories(Path.Join(RootPath, path)).Select(p=>p.Replace(RootPath,"").Substring(1));
|
||||||
|
}
|
||||||
|
|
||||||
private IEnumerable<string> GetAllFiles(){
|
private IEnumerable<string> GetAllFiles(){
|
||||||
|
|
||||||
if(!Directory.Exists(RootPath)) return [];
|
if(!Directory.Exists(RootPath)) return [];
|
||||||
|
|||||||
@@ -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));
|
return _fileApi.Has(GetManifestPath(item));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool Remove(RobustManifestItem item)
|
||||||
|
{
|
||||||
|
return _fileApi.Remove(GetManifestPath(item));
|
||||||
|
}
|
||||||
|
|
||||||
private string GetManifestPath(RobustManifestItem item){
|
private string GetManifestPath(RobustManifestItem item){
|
||||||
return GetManifestPath(item.Hash);
|
return GetManifestPath(item.Hash);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
namespace Nebula.Shared.Models.Auth;
|
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 void SetResolvedJobsCount(int count);
|
||||||
public int GetResolvedJobsCount();
|
public int GetResolvedJobsCount();
|
||||||
|
public void SetLoadingMessage(string message);
|
||||||
|
|
||||||
public void AppendJob(int count = 1)
|
public void AppendJob(int count = 1)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ public sealed record ServerInfo(
|
|||||||
[property: JsonPropertyName("auth")] AuthInfo Auth,
|
[property: JsonPropertyName("auth")] AuthInfo Auth,
|
||||||
[property: JsonPropertyName("build")] BuildInfo Build,
|
[property: JsonPropertyName("build")] BuildInfo Build,
|
||||||
[property: JsonPropertyName("desc")] string Desc,
|
[property: JsonPropertyName("desc")] string Desc,
|
||||||
[property: JsonPropertyName("links")] List<ServerLink> Links);
|
[property: JsonPropertyName("links")] List<ServerLink>? Links);
|
||||||
|
|
||||||
public sealed record EngineVersionInfo(
|
public sealed record EngineVersionInfo(
|
||||||
[property: JsonPropertyName("insecure")]
|
[property: JsonPropertyName("insecure")]
|
||||||
|
|||||||
@@ -11,7 +11,6 @@
|
|||||||
<EmbeddedResource Include="Utils\runtime.json">
|
<EmbeddedResource Include="Utils\runtime.json">
|
||||||
<LogicalName>Utility.runtime.json</LogicalName>
|
<LogicalName>Utility.runtime.json</LogicalName>
|
||||||
</EmbeddedResource>
|
</EmbeddedResource>
|
||||||
<PackageReference Include="FluentFTP" Version="52.1.0" />
|
|
||||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="9.0.0" />
|
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="9.0.0" />
|
||||||
<PackageReference Include="Robust.Natives" Version="0.1.1" />
|
<PackageReference Include="Robust.Natives" Version="0.1.1" />
|
||||||
<PackageReference Include="SharpZstd.Interop" Version="1.5.6" />
|
<PackageReference Include="SharpZstd.Interop" Version="1.5.6" />
|
||||||
|
|||||||
@@ -12,15 +12,23 @@ namespace Nebula.Shared.Services;
|
|||||||
[ServiceRegister]
|
[ServiceRegister]
|
||||||
public class AssemblyService
|
public class AssemblyService
|
||||||
{
|
{
|
||||||
private readonly List<Assembly> _assemblies = new();
|
private readonly Dictionary<string, Assembly> _assemblyCache = new();
|
||||||
private readonly ILogger _logger;
|
private readonly ILogger _logger;
|
||||||
|
|
||||||
private readonly HashSet<string> _resolvingAssemblies = new();
|
private readonly HashSet<string> _resolvingAssemblies = new();
|
||||||
|
|
||||||
|
private List<AssemblyApi> _mountedApis = [];
|
||||||
|
|
||||||
|
public Action<Assembly>? OnAssemblyLoaded;
|
||||||
|
public IReadOnlyList<Assembly> Assemblies => _assemblyCache.Values.ToList().AsReadOnly();
|
||||||
|
|
||||||
public AssemblyService(DebugService debugService)
|
public AssemblyService(DebugService debugService)
|
||||||
{
|
{
|
||||||
_logger = debugService.GetLogger(this);
|
_logger = debugService.GetLogger(this);
|
||||||
|
|
||||||
|
AssemblyLoadContext.Default.ResolvingUnmanagedDll += LoadContextOnResolvingUnmanaged;
|
||||||
|
AssemblyLoadContext.Default.Resolving += (context, name) => OnAssemblyResolving(context, name);
|
||||||
|
|
||||||
ZstdImportResolver.ResolveLibrary += (name, assembly1, path) =>
|
ZstdImportResolver.ResolveLibrary += (name, assembly1, path) =>
|
||||||
{
|
{
|
||||||
if (name.Equals("SharpZstd.Native"))
|
if (name.Equals("SharpZstd.Native"))
|
||||||
@@ -36,21 +44,41 @@ public class AssemblyService
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public IReadOnlyList<Assembly> Assemblies => _assemblies;
|
private Assembly? OnAssemblyResolving(AssemblyLoadContext context, AssemblyName name)
|
||||||
|
{
|
||||||
|
if (_resolvingAssemblies.Contains(name.FullName))
|
||||||
|
{
|
||||||
|
_logger.Debug($"Already resolving {name.Name}, skipping.");
|
||||||
|
return null; // Prevent recursive resolution
|
||||||
|
}
|
||||||
|
|
||||||
|
Assembly? assembly;
|
||||||
|
|
||||||
|
if (_assemblyCache.TryGetValue(name.Name ?? "", out assembly))
|
||||||
|
{
|
||||||
|
return assembly;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var api in _mountedApis)
|
||||||
|
{
|
||||||
|
if((assembly = OnAssemblyResolving(context, name, api)) != null)
|
||||||
|
return assembly;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public AssemblyApi Mount(IFileApi fileApi)
|
public AssemblyApi Mount(IFileApi fileApi)
|
||||||
{
|
{
|
||||||
var asmApi = new AssemblyApi(fileApi);
|
var asmApi = new AssemblyApi(fileApi);
|
||||||
AssemblyLoadContext.Default.Resolving += (context, name) => OnAssemblyResolving(context, name, asmApi);
|
_mountedApis.Add(asmApi);
|
||||||
AssemblyLoadContext.Default.ResolvingUnmanagedDll += LoadContextOnResolvingUnmanaged;
|
|
||||||
|
|
||||||
return asmApi;
|
return asmApi;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool TryGetLoader(Assembly clientAssembly, [NotNullWhen(true)] out ILoaderEntryPoint? loader)
|
public bool TryGetLoader(Assembly clientAssembly, [NotNullWhen(true)] out ILoaderEntryPoint? loader)
|
||||||
{
|
{
|
||||||
loader = null;
|
loader = null;
|
||||||
// Find ILoaderEntryPoint with the LoaderEntryPointAttribute
|
|
||||||
var attrib = clientAssembly.GetCustomAttribute<LoaderEntryPointAttribute>();
|
var attrib = clientAssembly.GetCustomAttribute<LoaderEntryPointAttribute>();
|
||||||
if (attrib == null)
|
if (attrib == null)
|
||||||
{
|
{
|
||||||
@@ -80,8 +108,10 @@ public class AssemblyService
|
|||||||
assembly = AssemblyLoadContext.Default.LoadFromStream(asm, pdb);
|
assembly = AssemblyLoadContext.Default.LoadFromStream(asm, pdb);
|
||||||
_logger.Log("LOADED ASSEMBLY " + name);
|
_logger.Log("LOADED ASSEMBLY " + name);
|
||||||
|
|
||||||
|
if (_assemblyCache.TryAdd(name, assembly))
|
||||||
if (!_assemblies.Contains(assembly)) _assemblies.Add(assembly);
|
{
|
||||||
|
OnAssemblyLoaded?.Invoke(assembly);
|
||||||
|
}
|
||||||
|
|
||||||
asm.Dispose();
|
asm.Dispose();
|
||||||
pdb?.Dispose();
|
pdb?.Dispose();
|
||||||
@@ -103,21 +133,18 @@ public class AssemblyService
|
|||||||
|
|
||||||
private Assembly? OnAssemblyResolving(AssemblyLoadContext context, AssemblyName name, AssemblyApi assemblyApi)
|
private Assembly? OnAssemblyResolving(AssemblyLoadContext context, AssemblyName name, AssemblyApi assemblyApi)
|
||||||
{
|
{
|
||||||
if (_resolvingAssemblies.Contains(name.FullName))
|
lock (_resolvingAssemblies)
|
||||||
{
|
{
|
||||||
_logger.Debug($"Already resolving {name.Name}, skipping.");
|
try
|
||||||
return null; // Prevent recursive resolution
|
{
|
||||||
}
|
_resolvingAssemblies.Add(name.FullName);
|
||||||
|
_logger.Debug($"Resolving assembly from FileAPI: {name.Name}");
|
||||||
try
|
return TryOpenAssembly(name.Name!, assemblyApi, out var assembly) ? assembly : null;
|
||||||
{
|
}
|
||||||
_resolvingAssemblies.Add(name.FullName);
|
finally
|
||||||
_logger.Debug($"Resolving assembly from FileAPI: {name.Name}");
|
{
|
||||||
return TryOpenAssembly(name.Name!, assemblyApi, out var assembly) ? assembly : null;
|
_resolvingAssemblies.Remove(name.FullName);
|
||||||
}
|
}
|
||||||
finally
|
|
||||||
{
|
|
||||||
_resolvingAssemblies.Remove(name.FullName);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Net.Http.Headers;
|
using System.Net.Http.Headers;
|
||||||
using System.Text.Json;
|
|
||||||
using System.Text.Json.Serialization;
|
using System.Text.Json.Serialization;
|
||||||
using Nebula.Shared.Models.Auth;
|
using Nebula.Shared.Models.Auth;
|
||||||
using Nebula.Shared.Services.Logging;
|
using Nebula.Shared.Services.Logging;
|
||||||
@@ -15,15 +14,10 @@ public class AuthService(
|
|||||||
CancellationService cancellationService)
|
CancellationService cancellationService)
|
||||||
{
|
{
|
||||||
private readonly HttpClient _httpClient = new();
|
private readonly HttpClient _httpClient = new();
|
||||||
public CurrentAuthInfo? SelectedAuth { get; private set; }
|
|
||||||
private readonly ILogger _logger = debugService.GetLogger("AuthService");
|
private readonly ILogger _logger = debugService.GetLogger("AuthService");
|
||||||
|
|
||||||
public async Task Auth(AuthLoginPassword authLoginPassword, string? code = null)
|
public async Task<AuthTokenCredentials> Auth(string login, string password, string authServer, string? code = null)
|
||||||
{
|
{
|
||||||
var authServer = authLoginPassword.AuthServer;
|
|
||||||
var login = authLoginPassword.Login;
|
|
||||||
var password = authLoginPassword.Password;
|
|
||||||
|
|
||||||
_logger.Debug($"Auth to {authServer}api/auth/authenticate {login}");
|
_logger.Debug($"Auth to {authServer}api/auth/authenticate {login}");
|
||||||
|
|
||||||
var authUrl = new Uri($"{authServer}api/auth/authenticate");
|
var authUrl = new Uri($"{authServer}api/auth/authenticate");
|
||||||
@@ -34,8 +28,8 @@ public class AuthService(
|
|||||||
await restService.PostAsync<AuthenticateResponse, AuthenticateRequest>(
|
await restService.PostAsync<AuthenticateResponse, AuthenticateRequest>(
|
||||||
new AuthenticateRequest(login, null, password, code), authUrl, cancellationService.Token);
|
new AuthenticateRequest(login, null, password, code), authUrl, cancellationService.Token);
|
||||||
|
|
||||||
SelectedAuth = new CurrentAuthInfo(result.UserId,
|
return new AuthTokenCredentials(result.UserId,
|
||||||
new LoginToken(result.Token, result.ExpireTime), authLoginPassword.Login, authLoginPassword.AuthServer);
|
new LoginToken(result.Token, result.ExpireTime), login, authServer);
|
||||||
}
|
}
|
||||||
catch (RestRequestException e)
|
catch (RestRequestException e)
|
||||||
{
|
{
|
||||||
@@ -48,32 +42,17 @@ public class AuthService(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ClearAuth()
|
public async Task EnsureToken(AuthTokenCredentials tokenCredentials)
|
||||||
{
|
{
|
||||||
SelectedAuth = null;
|
var authUrl = new Uri($"{tokenCredentials.AuthServer}api/auth/ping");
|
||||||
}
|
|
||||||
|
|
||||||
public async Task SetAuth(CurrentAuthInfo info)
|
|
||||||
{
|
|
||||||
SelectedAuth = info;
|
|
||||||
await EnsureToken();
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task EnsureToken()
|
|
||||||
{
|
|
||||||
if (SelectedAuth is null) throw new Exception("Auth info is not set!");
|
|
||||||
|
|
||||||
var authUrl = new Uri($"{SelectedAuth.AuthServer}api/auth/ping");
|
|
||||||
|
|
||||||
using var requestMessage = new HttpRequestMessage(HttpMethod.Get, authUrl);
|
using var requestMessage = new HttpRequestMessage(HttpMethod.Get, authUrl);
|
||||||
requestMessage.Headers.Authorization = new AuthenticationHeaderValue("SS14Auth", SelectedAuth.Token.Token);
|
requestMessage.Headers.Authorization = new AuthenticationHeaderValue("SS14Auth", tokenCredentials.Token.Token);
|
||||||
using var resp = await _httpClient.SendAsync(requestMessage, cancellationService.Token);
|
using var resp = await _httpClient.SendAsync(requestMessage, cancellationService.Token);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public sealed record CurrentAuthInfo(Guid UserId, LoginToken Token, string Login, string AuthServer);
|
public sealed record AuthTokenCredentials(Guid UserId, LoginToken Token, string Login, string AuthServer);
|
||||||
|
|
||||||
public record AuthLoginPassword(string Login, string Password, string AuthServer);
|
|
||||||
|
|
||||||
public sealed record AuthDenyError(string[] Errors, AuthenticateDenyCode Code);
|
public sealed record AuthDenyError(string[] Errors, AuthenticateDenyCode Code);
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Nebula.Shared.FileApis.Interfaces;
|
using Nebula.Shared.FileApis.Interfaces;
|
||||||
|
using Nebula.Shared.Models;
|
||||||
using Nebula.Shared.Services.Logging;
|
using Nebula.Shared.Services.Logging;
|
||||||
using Robust.LoaderApi;
|
using Robust.LoaderApi;
|
||||||
|
|
||||||
@@ -30,23 +32,116 @@ public static class ConVarBuilder
|
|||||||
|
|
||||||
return new ConVar<T>(name, defaultValue);
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface IConfigurationMigration
|
||||||
|
{
|
||||||
|
public Task DoMigrate(ConfigurationService configurationService, IServiceProvider serviceProvider, ILoadingHandler loadingHandler);
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[ServiceRegister]
|
[ServiceRegister]
|
||||||
public class ConfigurationService
|
public class ConfigurationService
|
||||||
{
|
{
|
||||||
|
private readonly IServiceProvider _serviceProvider;
|
||||||
|
private static List<IConfigurationMigration> _migrations = [];
|
||||||
|
|
||||||
|
public static void AddConfigurationMigration(IConfigurationMigration configurationMigration)
|
||||||
|
{
|
||||||
|
_migrations.Add(configurationMigration);
|
||||||
|
}
|
||||||
|
|
||||||
public delegate void OnConfigurationChangedDelegate<in T>(T value);
|
public delegate void OnConfigurationChangedDelegate<in T>(T value);
|
||||||
|
|
||||||
public IReadWriteFileApi ConfigurationApi { get; init; }
|
public IReadWriteFileApi ConfigurationApi { get; }
|
||||||
|
|
||||||
private readonly ILogger _logger;
|
private readonly ILogger _logger;
|
||||||
|
|
||||||
public ConfigurationService(FileService fileService, DebugService debugService)
|
public ConfigurationService(FileService fileService, DebugService debugService, IServiceProvider serviceProvider)
|
||||||
{
|
{
|
||||||
|
_serviceProvider = serviceProvider;
|
||||||
_logger = debugService.GetLogger(this);
|
_logger = debugService.GetLogger(this);
|
||||||
ConfigurationApi = fileService.CreateFileApi("config");
|
ConfigurationApi = fileService.CreateFileApi("config");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void MigrateConfigs(ILoadingHandler loadingHandler)
|
||||||
|
{
|
||||||
|
Task.Run(async () =>
|
||||||
|
{
|
||||||
|
foreach (var migration in _migrations)
|
||||||
|
{
|
||||||
|
await migration.DoMigrate(this, _serviceProvider, loadingHandler);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (loadingHandler is IDisposable disposable)
|
||||||
|
{
|
||||||
|
disposable.Dispose();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public ConfigChangeSubscriberDisposable<T> SubscribeVarChanged<T>(ConVar<T> convar, OnConfigurationChangedDelegate<T?> @delegate, bool invokeNow = false)
|
public ConfigChangeSubscriberDisposable<T> SubscribeVarChanged<T>(ConVar<T> convar, OnConfigurationChangedDelegate<T?> @delegate, bool invokeNow = false)
|
||||||
{
|
{
|
||||||
convar.OnValueChanged += @delegate;
|
convar.OnValueChanged += @delegate;
|
||||||
@@ -112,12 +207,17 @@ public class ConfigurationService
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetConfigValue<T>(ConVar<T> conVar, T value)
|
public void ClearConfigValue<T>(ConVar<T> conVar)
|
||||||
|
{
|
||||||
|
ConfigurationApi.Remove(GetFileName(conVar));
|
||||||
|
conVar.OnValueChanged?.Invoke(conVar.DefaultValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetConfigValue<T>(ConVar<T> conVar, T? value)
|
||||||
{
|
{
|
||||||
if (value == null)
|
if (value == null)
|
||||||
{
|
{
|
||||||
ConfigurationApi.Remove(GetFileName(conVar));
|
ClearConfigValue(conVar);
|
||||||
conVar.OnValueChanged?.Invoke(conVar.DefaultValue);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,9 +14,23 @@ public partial class ContentService
|
|||||||
public readonly IReadWriteFileApi ContentFileApi = fileService.CreateFileApi("content");
|
public readonly IReadWriteFileApi ContentFileApi = fileService.CreateFileApi("content");
|
||||||
public readonly IReadWriteFileApi ManifestFileApi = fileService.CreateFileApi("manifest");
|
public readonly IReadWriteFileApi ManifestFileApi = fileService.CreateFileApi("manifest");
|
||||||
|
|
||||||
public bool CheckManifestExist(RobustManifestItem item)
|
public void SetServerHash(string address, string hash)
|
||||||
{
|
{
|
||||||
return ContentFileApi.Has(item.Hash);
|
var dict = varService.GetConfigValue(CurrentConVar.ServerManifestHash)!;
|
||||||
|
if (dict.TryGetValue(address, out var oldHash))
|
||||||
|
{
|
||||||
|
if(oldHash == hash) return;
|
||||||
|
|
||||||
|
ManifestFileApi.Remove(oldHash);
|
||||||
|
}
|
||||||
|
|
||||||
|
dict[address] = hash;
|
||||||
|
varService.SetConfigValue(CurrentConVar.ServerManifestHash, dict);
|
||||||
|
}
|
||||||
|
|
||||||
|
public HashApi CreateHashApi(List<RobustManifestItem> manifestItems)
|
||||||
|
{
|
||||||
|
return new HashApi(manifestItems, ContentFileApi);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<HashApi> EnsureItems(ManifestReader manifestReader, Uri downloadUri,
|
public async Task<HashApi> EnsureItems(ManifestReader manifestReader, Uri downloadUri,
|
||||||
@@ -34,10 +48,11 @@ public partial class ContentService
|
|||||||
allItems.Add(item.Value);
|
allItems.Add(item.Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
var hashApi = new HashApi(allItems, ContentFileApi);
|
var hashApi = CreateHashApi(allItems);
|
||||||
|
|
||||||
items = allItems.Where(a=> !hashApi.Has(a)).ToList();
|
items = allItems.Where(a=> !hashApi.Has(a)).ToList();
|
||||||
|
|
||||||
|
loadingHandler.SetLoadingMessage("Download Count:" + items.Count);
|
||||||
_logger.Log("Download Count:" + items.Count);
|
_logger.Log("Download Count:" + items.Count);
|
||||||
await Download(downloadUri, items, hashApi, loadingHandler, cancellationToken);
|
await Download(downloadUri, items, hashApi, loadingHandler, cancellationToken);
|
||||||
|
|
||||||
@@ -48,6 +63,7 @@ public partial class ContentService
|
|||||||
CancellationToken cancellationToken)
|
CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
_logger.Log("Getting manifest: " + info.Hash);
|
_logger.Log("Getting manifest: " + info.Hash);
|
||||||
|
loadingHandler.SetLoadingMessage("Getting manifest: " + info.Hash);
|
||||||
|
|
||||||
if (ManifestFileApi.TryOpen(info.Hash, out var stream))
|
if (ManifestFileApi.TryOpen(info.Hash, out var stream))
|
||||||
{
|
{
|
||||||
@@ -55,7 +71,10 @@ public partial class ContentService
|
|||||||
return await EnsureItems(new ManifestReader(stream), info.DownloadUri, loadingHandler, cancellationToken);
|
return await EnsureItems(new ManifestReader(stream), info.DownloadUri, loadingHandler, cancellationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SetServerHash(info.ManifestUri.ToString(), info.Hash);
|
||||||
|
|
||||||
_logger.Log("Fetching manifest from: " + info.ManifestUri);
|
_logger.Log("Fetching manifest from: " + info.ManifestUri);
|
||||||
|
loadingHandler.SetLoadingMessage("Fetching manifest from: " + info.ManifestUri);
|
||||||
|
|
||||||
var response = await _http.GetAsync(info.ManifestUri, cancellationToken);
|
var response = await _http.GetAsync(info.ManifestUri, cancellationToken);
|
||||||
if (!response.IsSuccessStatusCode) throw new Exception();
|
if (!response.IsSuccessStatusCode) throw new Exception();
|
||||||
@@ -111,6 +130,7 @@ public partial class ContentService
|
|||||||
|
|
||||||
var downloadJobWatch = loadingHandler.GetQueryJob();
|
var downloadJobWatch = loadingHandler.GetQueryJob();
|
||||||
|
|
||||||
|
loadingHandler.SetLoadingMessage("Downloading from: " + contentCdn);
|
||||||
_logger.Log("Downloading from: " + contentCdn);
|
_logger.Log("Downloading from: " + contentCdn);
|
||||||
|
|
||||||
var requestBody = new byte[toDownload.Count * 4];
|
var requestBody = new byte[toDownload.Count * 4];
|
||||||
@@ -135,7 +155,7 @@ public partial class ContentService
|
|||||||
|
|
||||||
if (cancellationToken.IsCancellationRequested)
|
if (cancellationToken.IsCancellationRequested)
|
||||||
{
|
{
|
||||||
_logger.Log("Downloading is cancelled!");
|
_logger.Log("Downloading cancelled!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -185,7 +205,7 @@ public partial class ContentService
|
|||||||
{
|
{
|
||||||
if (cancellationToken.IsCancellationRequested)
|
if (cancellationToken.IsCancellationRequested)
|
||||||
{
|
{
|
||||||
_logger.Log("Downloading is cancelled!");
|
_logger.Log("Downloading cancelled!");
|
||||||
decompressContext?.Dispose();
|
decompressContext?.Dispose();
|
||||||
compressContext?.Dispose();
|
compressContext?.Dispose();
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ public partial class ContentService
|
|||||||
{
|
{
|
||||||
_logger.Log("Checking migration...");
|
_logger.Log("Checking migration...");
|
||||||
|
|
||||||
var migrationList = ContentFileApi.AllFiles.Where(f => !f.Contains("\\")).ToList();
|
var migrationList = ContentFileApi.AllFiles.Where(f => !f.Contains('\\')).ToList();
|
||||||
if(migrationList.Count == 0) return false;
|
if(migrationList.Count == 0) return false;
|
||||||
|
|
||||||
_logger.Log($"Found {migrationList.Count} migration files. Starting migration...");
|
_logger.Log($"Found {migrationList.Count} migration files. Starting migration...");
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
using System.Data;
|
using Nebula.Shared.Models;
|
||||||
using Nebula.Shared.Models;
|
|
||||||
using Nebula.Shared.Services.Logging;
|
using Nebula.Shared.Services.Logging;
|
||||||
|
|
||||||
namespace Nebula.Shared.Services;
|
namespace Nebula.Shared.Services;
|
||||||
@@ -28,4 +27,10 @@ public partial class ContentService(
|
|||||||
|
|
||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void RemoveAllContent(ILoadingHandler loadingHandler, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
fileService.RemoveAllFiles("content", loadingHandler, cancellationToken);
|
||||||
|
fileService.RemoveAllFiles("manifest", loadingHandler, cancellationToken);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
using System.IO.Compression;
|
using System.IO.Compression;
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
using Nebula.Shared.FileApis;
|
using Nebula.Shared.FileApis;
|
||||||
using Nebula.Shared.FileApis.Interfaces;
|
using Nebula.Shared.FileApis.Interfaces;
|
||||||
using Nebula.Shared.Models;
|
using Nebula.Shared.Models;
|
||||||
|
using Nebula.Shared.Services.Logging;
|
||||||
using Robust.LoaderApi;
|
using Robust.LoaderApi;
|
||||||
|
|
||||||
namespace Nebula.Shared.Services;
|
namespace Nebula.Shared.Services;
|
||||||
@@ -10,21 +10,22 @@ namespace Nebula.Shared.Services;
|
|||||||
[ServiceRegister]
|
[ServiceRegister]
|
||||||
public class FileService
|
public class FileService
|
||||||
{
|
{
|
||||||
public static readonly string RootPath = Path.Join(Environment.GetFolderPath(
|
public static string RootPath = Path.Join(Environment.GetFolderPath(
|
||||||
Environment.SpecialFolder.ApplicationData), "Datum");
|
Environment.SpecialFolder.ApplicationData), "Datum");
|
||||||
|
|
||||||
private readonly DebugService _debugService;
|
private readonly ILogger _logger;
|
||||||
|
|
||||||
public FileService(DebugService debugService)
|
public FileService(DebugService debugService)
|
||||||
{
|
{
|
||||||
_debugService = debugService;
|
_logger = debugService.GetLogger(this);
|
||||||
|
|
||||||
if(!Directory.Exists(RootPath))
|
if(!Directory.Exists(RootPath))
|
||||||
Directory.CreateDirectory(RootPath);
|
Directory.CreateDirectory(RootPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IReadWriteFileApi CreateFileApi(string path)
|
public FileApi CreateFileApi(string path)
|
||||||
{
|
{
|
||||||
|
_logger.Debug($"Creating file api for {path}");
|
||||||
return new FileApi(Path.Join(RootPath, path));
|
return new FileApi(Path.Join(RootPath, path));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -32,6 +33,7 @@ public class FileService
|
|||||||
{
|
{
|
||||||
path = Path.Combine(Path.GetTempPath(), "tempThink"+Path.GetRandomFileName());
|
path = Path.Combine(Path.GetTempPath(), "tempThink"+Path.GetRandomFileName());
|
||||||
Directory.CreateDirectory(path);
|
Directory.CreateDirectory(path);
|
||||||
|
_logger.Debug($"Ensuring temp directory for {path}");
|
||||||
return new FileApi(path);
|
return new FileApi(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -53,6 +55,38 @@ public class FileService
|
|||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void RemoveAllFiles(string fileApiName,ILoadingHandler loadingHandler, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
_logger.Debug($"Deleting files from {fileApiName}");
|
||||||
|
var path = Path.Combine(RootPath, fileApiName);
|
||||||
|
|
||||||
|
var di = new DirectoryInfo(path);
|
||||||
|
|
||||||
|
var files = di.GetFiles();
|
||||||
|
var dirs = di.GetDirectories();
|
||||||
|
|
||||||
|
loadingHandler.AppendJob(files.Length);
|
||||||
|
loadingHandler.AppendJob(dirs.Length);
|
||||||
|
|
||||||
|
if(cancellationToken.IsCancellationRequested)
|
||||||
|
return;
|
||||||
|
|
||||||
|
foreach (var file in files)
|
||||||
|
{
|
||||||
|
if(cancellationToken.IsCancellationRequested)
|
||||||
|
return;
|
||||||
|
file.Delete();
|
||||||
|
loadingHandler.AppendResolvedJob();
|
||||||
|
}
|
||||||
|
foreach (var dir in dirs)
|
||||||
|
{
|
||||||
|
if(cancellationToken.IsCancellationRequested)
|
||||||
|
return;
|
||||||
|
dir.Delete(true);
|
||||||
|
loadingHandler.AppendResolvedJob();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public sealed class ConsoleLoadingHandler : ILoadingHandler
|
public sealed class ConsoleLoadingHandler : ILoadingHandler
|
||||||
@@ -88,6 +122,11 @@ public sealed class ConsoleLoadingHandler : ILoadingHandler
|
|||||||
return _resolvedJobs;
|
return _resolvedJobs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void SetLoadingMessage(string message)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
private void UpdatePercent()
|
private void UpdatePercent()
|
||||||
{
|
{
|
||||||
if (_currJobs == 0)
|
if (_currJobs == 0)
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ namespace Nebula.Shared.Services;
|
|||||||
[ServiceRegister]
|
[ServiceRegister]
|
||||||
public class RestService
|
public class RestService
|
||||||
{
|
{
|
||||||
private readonly HttpClient _client = new();
|
private readonly HttpClient _client;
|
||||||
private readonly ILogger _logger;
|
private readonly ILogger _logger;
|
||||||
|
|
||||||
private readonly JsonSerializerOptions _serializerOptions = new()
|
private readonly JsonSerializerOptions _serializerOptions = new()
|
||||||
@@ -20,8 +20,9 @@ public class RestService
|
|||||||
WriteIndented = true
|
WriteIndented = true
|
||||||
};
|
};
|
||||||
|
|
||||||
public RestService(DebugService debug)
|
public RestService(DebugService debug, HttpClient? client = null)
|
||||||
{
|
{
|
||||||
|
_client = client ?? new HttpClient();
|
||||||
_logger = debug.GetLogger(this);
|
_logger = debug.GetLogger(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,103 +0,0 @@
|
|||||||
using Nebula.Shared.Models;
|
|
||||||
using Nebula.Shared.Services.Logging;
|
|
||||||
using Robust.LoaderApi;
|
|
||||||
|
|
||||||
namespace Nebula.Shared.Services;
|
|
||||||
|
|
||||||
[ServiceRegister]
|
|
||||||
public sealed class RunnerService(
|
|
||||||
ContentService contentService,
|
|
||||||
DebugService debugService,
|
|
||||||
ConfigurationService varService,
|
|
||||||
EngineService engineService,
|
|
||||||
AssemblyService assemblyService)
|
|
||||||
{
|
|
||||||
private ILogger _logger = debugService.GetLogger("RunnerService");
|
|
||||||
|
|
||||||
public async Task Run(string[] runArgs, RobustBuildInfo buildInfo, IRedialApi redialApi,
|
|
||||||
ILoadingHandler loadingHandler,
|
|
||||||
CancellationToken cancellationToken)
|
|
||||||
{
|
|
||||||
_logger.Log("Start Content!");
|
|
||||||
|
|
||||||
var engine = await engineService.EnsureEngine(buildInfo.BuildInfo.Build.EngineVersion);
|
|
||||||
|
|
||||||
if (engine is null)
|
|
||||||
throw new Exception("Engine version not found: " + buildInfo.BuildInfo.Build.EngineVersion);
|
|
||||||
|
|
||||||
var hashApi = await contentService.EnsureItems(buildInfo.RobustManifestInfo, loadingHandler, cancellationToken);
|
|
||||||
|
|
||||||
var extraMounts = new List<ApiMount>
|
|
||||||
{
|
|
||||||
new(hashApi, "/")
|
|
||||||
};
|
|
||||||
|
|
||||||
if (hashApi.TryOpen("manifest.yml", out var stream))
|
|
||||||
{
|
|
||||||
var modules = ContentManifestParser.ExtractModules(stream);
|
|
||||||
|
|
||||||
foreach (var moduleStr in modules)
|
|
||||||
{
|
|
||||||
var module =
|
|
||||||
await engineService.EnsureEngineModules(moduleStr, buildInfo.BuildInfo.Build.EngineVersion);
|
|
||||||
if (module is not null)
|
|
||||||
extraMounts.Add(new ApiMount(module, "/"));
|
|
||||||
}
|
|
||||||
|
|
||||||
await stream.DisposeAsync();
|
|
||||||
}
|
|
||||||
|
|
||||||
var args = new MainArgs(runArgs, engine, redialApi, extraMounts);
|
|
||||||
|
|
||||||
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;
|
|
||||||
|
|
||||||
await Task.Run(() => loader.Main(args), cancellationToken);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class ContentManifestParser
|
|
||||||
{
|
|
||||||
public static List<string> ExtractModules(Stream manifestStream)
|
|
||||||
{
|
|
||||||
using var reader = new StreamReader(manifestStream);
|
|
||||||
return ExtractModules(reader.ReadToEnd());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static List<string> ExtractModules(string manifestContent)
|
|
||||||
{
|
|
||||||
var modules = new List<string>();
|
|
||||||
var lines = manifestContent.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
|
|
||||||
|
|
||||||
bool inModulesSection = false;
|
|
||||||
|
|
||||||
foreach (var rawLine in lines)
|
|
||||||
{
|
|
||||||
var line = rawLine.Trim();
|
|
||||||
|
|
||||||
if (line.StartsWith("modules:"))
|
|
||||||
{
|
|
||||||
inModulesSection = true;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (inModulesSection)
|
|
||||||
{
|
|
||||||
if (line.StartsWith("- "))
|
|
||||||
{
|
|
||||||
modules.Add(line.Substring(2).Trim());
|
|
||||||
}
|
|
||||||
else if (!line.StartsWith(" "))
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return modules;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -94,8 +94,16 @@ public class ManifestReader : StreamReader
|
|||||||
{
|
{
|
||||||
var line = ReadLine();
|
var line = ReadLine();
|
||||||
if (line == null) return null;
|
if (line == null) return null;
|
||||||
var splited = line.Split(" ");
|
|
||||||
return new RobustManifestItem(splited[0], line.Substring(splited[0].Length + 1), CurrentId++);
|
var firstSpaceIndex = line.IndexOf(' ');
|
||||||
|
if (firstSpaceIndex == -1)
|
||||||
|
return new RobustManifestItem(line, string.Empty, CurrentId++);
|
||||||
|
|
||||||
|
var span = line.AsSpan();
|
||||||
|
var firstPart = span.Slice(0, firstSpaceIndex);
|
||||||
|
var secondPart = span.Slice(firstSpaceIndex + 1);
|
||||||
|
|
||||||
|
return new RobustManifestItem(firstPart.ToString(), secondPart.ToString(), CurrentId++);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool TryReadItem([NotNullWhen(true)] out RobustManifestItem? item)
|
public bool TryReadItem([NotNullWhen(true)] out RobustManifestItem? item)
|
||||||
|
|||||||
8
Nebula.Shared/ViewHelper/ViewModelRegisterAttribute.cs
Normal file
8
Nebula.Shared/ViewHelper/ViewModelRegisterAttribute.cs
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
namespace Nebula.Shared.ViewHelper;
|
||||||
|
|
||||||
|
[AttributeUsage(AttributeTargets.Class)]
|
||||||
|
public class ViewModelRegisterAttribute(Type? type = null, bool isSingleton = true) : Attribute
|
||||||
|
{
|
||||||
|
public Type? Type { get; } = type;
|
||||||
|
public bool IsSingleton { get; } = isSingleton;
|
||||||
|
}
|
||||||
@@ -71,7 +71,7 @@ partial class {className}
|
|||||||
";
|
";
|
||||||
|
|
||||||
// Add the source code to the compilation.
|
// Add the source code to the compilation.
|
||||||
context.AddSource($"{className}.g.cs", SourceText.From(code, Encoding.UTF8));
|
context.AddSource($"{className}_dependencyAuto.g.cs", SourceText.From(code, Encoding.UTF8));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,24 +7,6 @@ namespace Nebula.SourceGenerators;
|
|||||||
|
|
||||||
public static class SourceHelper
|
public static class SourceHelper
|
||||||
{
|
{
|
||||||
public static void GenerateAttribute(string attributeName, string usage,
|
|
||||||
IncrementalGeneratorInitializationContext context)
|
|
||||||
{
|
|
||||||
var attributeSourceCode = $@"// <auto-generated/>
|
|
||||||
|
|
||||||
namespace SourceGen
|
|
||||||
{{
|
|
||||||
[System.AttributeUsage(System.AttributeTargets.{usage})]
|
|
||||||
public class {attributeName} : System.Attribute
|
|
||||||
{{
|
|
||||||
}}
|
|
||||||
}}";
|
|
||||||
|
|
||||||
context.RegisterPostInitializationOutput(ctx => ctx.AddSource(
|
|
||||||
$"{attributeName}.g.cs",
|
|
||||||
SourceText.From(attributeSourceCode, Encoding.UTF8)));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static bool HasAttribute(ISymbol type, string attributeName)
|
public static bool HasAttribute(ISymbol type, string attributeName)
|
||||||
{
|
{
|
||||||
foreach (var attribute in type.GetAttributes())
|
foreach (var attribute in type.GetAttributes())
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
|
using System;
|
||||||
using System.Collections.Immutable;
|
using System.Collections.Immutable;
|
||||||
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using Microsoft.CodeAnalysis;
|
using Microsoft.CodeAnalysis;
|
||||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||||
@@ -6,53 +8,82 @@ using Microsoft.CodeAnalysis.Text;
|
|||||||
|
|
||||||
namespace Nebula.SourceGenerators;
|
namespace Nebula.SourceGenerators;
|
||||||
|
|
||||||
//[Generator]
|
|
||||||
public class ViewConstructGenerator : IIncrementalGenerator
|
|
||||||
{
|
|
||||||
public static string ViewForModelAttributeName = "ViewForModelAttribute";
|
|
||||||
|
|
||||||
|
[Generator]
|
||||||
|
public class ViewConstructorGenerator : IIncrementalGenerator
|
||||||
|
{
|
||||||
|
private static readonly string ViewModelAttribute = "Nebula.Shared.ViewHelper.ViewModelRegisterAttribute";
|
||||||
public void Initialize(IncrementalGeneratorInitializationContext context)
|
public void Initialize(IncrementalGeneratorInitializationContext context)
|
||||||
{
|
{
|
||||||
var provider = context.SyntaxProvider
|
var provider = context.SyntaxProvider
|
||||||
.CreateSyntaxProvider(
|
.CreateSyntaxProvider(
|
||||||
(s, _) => s is ClassDeclarationSyntax, (ctx, _) =>
|
(s, _) => s is ClassDeclarationSyntax,
|
||||||
SourceHelper.GetClassDeclarationForSourceGen(ctx,ViewForModelAttributeName)
|
(ctx, _) => SourceHelper.GetClassDeclarationForSourceGen(ctx,ViewModelAttribute))
|
||||||
)
|
|
||||||
.Where(t => t.reportAttributeFound)
|
.Where(t => t.reportAttributeFound)
|
||||||
.Select((t,_) => t.Item1);
|
.Select((t, _) => t.Item1);
|
||||||
|
|
||||||
context.RegisterSourceOutput(context.CompilationProvider.Combine(provider.Collect()), (ctx,t)=> GenerateCode(ctx, t.Left, t.Right));
|
context.RegisterSourceOutput(context.CompilationProvider.Combine(provider.Collect()),
|
||||||
|
(ctx, t) => GenerateCode(ctx, t.Left, t.Right));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void GenerateCode(SourceProductionContext context, Compilation compilation, ImmutableArray<ClassDeclarationSyntax> syntaxes)
|
private void GenerateCode(SourceProductionContext context, Compilation compilation,
|
||||||
|
ImmutableArray<ClassDeclarationSyntax> classDeclarations)
|
||||||
{
|
{
|
||||||
foreach (var classDeclarationSyntax in syntaxes)
|
foreach (var classDeclarationSyntax in classDeclarations)
|
||||||
{
|
{
|
||||||
var semanticModel = compilation.GetSemanticModel(classDeclarationSyntax.SyntaxTree);
|
var semanticModel = compilation.GetSemanticModel(classDeclarationSyntax.SyntaxTree);
|
||||||
if(semanticModel.GetDeclaredSymbol(classDeclarationSyntax) is not INamedTypeSymbol classSymbol)
|
if (semanticModel.GetDeclaredSymbol(classDeclarationSyntax) is not INamedTypeSymbol classSymbol)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
var namespaceName = classSymbol.ContainingNamespace.ToDisplayString();
|
var viewModelName = classSymbol.Name;
|
||||||
var className = classDeclarationSyntax.Identifier.Text;
|
var viewModelNamespace = classSymbol.ContainingNamespace.ToDisplayString();
|
||||||
|
|
||||||
var code = $@"// <auto-generated/>
|
var viewModelRegisterAttr = classSymbol.GetAttributes()
|
||||||
|
.FirstOrDefault(attr => attr.AttributeClass?.ToDisplayString() == ViewModelAttribute);
|
||||||
|
|
||||||
using System;
|
var viewTypeArg = viewModelRegisterAttr?.ConstructorArguments.FirstOrDefault();
|
||||||
using System.Collections.Generic;
|
if (viewTypeArg?.Value is not INamedTypeSymbol viewTypeSymbol)
|
||||||
|
continue;
|
||||||
|
|
||||||
namespace {namespaceName};
|
try
|
||||||
|
{
|
||||||
|
var viewName = viewTypeSymbol.Name;
|
||||||
|
var viewNamespace = viewTypeSymbol.ContainingNamespace.ToDisplayString();
|
||||||
|
|
||||||
partial class {className}
|
var code = $@"
|
||||||
|
namespace {viewNamespace}
|
||||||
{{
|
{{
|
||||||
public {className}() : base(){{
|
public partial class {viewName}
|
||||||
|
{{
|
||||||
|
public {viewName}({viewModelNamespace}.{viewModelName} viewModel)
|
||||||
|
: this()
|
||||||
|
{{
|
||||||
|
DataContext = viewModel;
|
||||||
|
}}
|
||||||
}}
|
}}
|
||||||
}}
|
}}";
|
||||||
";
|
|
||||||
|
|
||||||
// Add the source code to the compilation.
|
// Add the source code to the compilation.
|
||||||
context.AddSource($"{className}.g.cs", SourceText.From(code, Encoding.UTF8));
|
context.AddSource($"{viewName}_viewConstructAuto.g.cs", SourceText.From(code, Encoding.UTF8));
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
var coder1 = $@"
|
||||||
|
// <auto-generated/>
|
||||||
|
// Error!
|
||||||
|
namespace {viewModelNamespace}
|
||||||
|
{{
|
||||||
|
public partial class {viewModelName}
|
||||||
|
{{
|
||||||
|
// {e.Message}
|
||||||
|
}}
|
||||||
|
}}";
|
||||||
|
|
||||||
|
// Add the source code to the compilation.
|
||||||
|
context.AddSource($"{viewModelName}_viewError.g.cs", SourceText.From(coder1, Encoding.UTF8));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
31
Nebula.UnitTest/Nebula.UnitTest.csproj
Normal file
31
Nebula.UnitTest/Nebula.UnitTest.csproj
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net9.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
|
||||||
|
<IsPackable>false</IsPackable>
|
||||||
|
<IsTestProject>true</IsTestProject>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="coverlet.collector" Version="6.0.0"/>
|
||||||
|
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.6" />
|
||||||
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0"/>
|
||||||
|
<PackageReference Include="Moq" Version="4.20.72" />
|
||||||
|
<PackageReference Include="NUnit" Version="3.14.0"/>
|
||||||
|
<PackageReference Include="NUnit.Analyzers" Version="3.9.0"/>
|
||||||
|
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0"/>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Using Include="NUnit.Framework"/>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\Nebula.Packager\Nebula.Packager.csproj" />
|
||||||
|
<ProjectReference Include="..\Nebula.Shared\Nebula.Shared.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
16
Nebula.UnitTest/NebulaSharedTests/BaseSharedTest.cs
Normal file
16
Nebula.UnitTest/NebulaSharedTests/BaseSharedTest.cs
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
|
||||||
|
namespace Nebula.UnitTest.NebulaSharedTests;
|
||||||
|
|
||||||
|
public abstract class BaseSharedTest
|
||||||
|
{
|
||||||
|
protected SharedUnit _sharedUnit = default!;
|
||||||
|
|
||||||
|
public abstract void BeforeServiceBuild(IServiceCollection services);
|
||||||
|
|
||||||
|
public virtual void Setup()
|
||||||
|
{
|
||||||
|
_sharedUnit = TestServiceHelper.GetSharedUnit(BeforeServiceBuild);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,90 @@
|
|||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Nebula.Shared.Services;
|
||||||
|
|
||||||
|
namespace Nebula.UnitTest.NebulaSharedTests;
|
||||||
|
|
||||||
|
[TestFixture]
|
||||||
|
[TestOf(typeof(ConfigurationService))]
|
||||||
|
public sealed class ConfigurationServiceTests: BaseSharedTest
|
||||||
|
{
|
||||||
|
private ConfigurationService _conVarService;
|
||||||
|
|
||||||
|
public override void BeforeServiceBuild(IServiceCollection services)
|
||||||
|
{
|
||||||
|
TestServiceHelper.InitFileServiceTest();
|
||||||
|
}
|
||||||
|
|
||||||
|
[SetUp]
|
||||||
|
public override void Setup()
|
||||||
|
{
|
||||||
|
base.Setup();
|
||||||
|
_conVarService = _sharedUnit.GetService<ConfigurationService>();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void GetDefaultConVarTest()
|
||||||
|
{
|
||||||
|
var value = _conVarService.GetConfigValue(TestConVar.SimpleConvar);
|
||||||
|
Assert.NotNull(value);
|
||||||
|
Assert.That(value, Is.EqualTo(TestConVar.SimpleConvar.DefaultValue));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void GetNullConVarTest()
|
||||||
|
{
|
||||||
|
var value = _conVarService.GetConfigValue(TestConVar.NullConvar);
|
||||||
|
Assert.Null(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void WriteConVarTest()
|
||||||
|
{
|
||||||
|
var value = _conVarService.GetConfigValue(TestConVar.SimpleConvar);
|
||||||
|
Assert.That(value, Is.EqualTo(TestConVar.SimpleConvar.DefaultValue));
|
||||||
|
|
||||||
|
_conVarService.SetConfigValue(TestConVar.SimpleConvar, "notdefault");
|
||||||
|
value = _conVarService.GetConfigValue(TestConVar.SimpleConvar);
|
||||||
|
Assert.That(value, Is.Not.EqualTo(TestConVar.SimpleConvar.DefaultValue));
|
||||||
|
Assert.That(value, Is.EqualTo("notdefault"));
|
||||||
|
|
||||||
|
_conVarService.SetConfigValue(TestConVar.SimpleConvar, null);
|
||||||
|
|
||||||
|
value = _conVarService.GetConfigValue(TestConVar.SimpleConvar);
|
||||||
|
Assert.That(value, Is.EqualTo(TestConVar.SimpleConvar.DefaultValue));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void WriteComplexConvarTest()
|
||||||
|
{
|
||||||
|
var testVar = new TestVarObject("Alex", 2);
|
||||||
|
_conVarService.SetConfigValue(TestConVar.TestVarObject, testVar);
|
||||||
|
var value = _conVarService.GetConfigValue(TestConVar.TestVarObject);
|
||||||
|
Assert.That(value, Is.EqualTo(testVar));
|
||||||
|
|
||||||
|
_conVarService.SetConfigValue(TestConVar.TestVarObject, default);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void WriteArrayConvarTest()
|
||||||
|
{
|
||||||
|
var testVarArr = new[] { new TestVarObject("Alex", 2), new TestVarObject("Vitya", 3) };
|
||||||
|
_conVarService.SetConfigValue(TestConVar.TestVarArray, testVarArr);
|
||||||
|
var value = _conVarService.GetConfigValue(TestConVar.TestVarArray);
|
||||||
|
Assert.NotNull(value);
|
||||||
|
Assert.That(testVarArr.SequenceEqual(value));
|
||||||
|
_conVarService.SetConfigValue(TestConVar.TestVarArray, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class TestConVar
|
||||||
|
{
|
||||||
|
public static ConVar<string> SimpleConvar = ConVarBuilder.Build("test.convarsimple", "test");
|
||||||
|
public static ConVar<string?> NullConvar = ConVarBuilder.Build<string?>("test.convarsimplenull");
|
||||||
|
|
||||||
|
public static ConVar<TestVarObject> TestVarObject = ConVarBuilder.Build<TestVarObject>("test.convarobject", default);
|
||||||
|
public static ConVar<TestVarObject[]> TestVarArray = ConVarBuilder.Build<TestVarObject[]>("test.convarobject.array");
|
||||||
|
}
|
||||||
|
|
||||||
|
public record struct TestVarObject(string Name, int Count);
|
||||||
123
Nebula.UnitTest/NebulaSharedTests/FileServiceTests.cs
Normal file
123
Nebula.UnitTest/NebulaSharedTests/FileServiceTests.cs
Normal file
@@ -0,0 +1,123 @@
|
|||||||
|
using System.IO.Compression;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Moq;
|
||||||
|
using Nebula.Shared.Models;
|
||||||
|
using Nebula.Shared.Services;
|
||||||
|
using Robust.LoaderApi;
|
||||||
|
|
||||||
|
namespace Nebula.UnitTest.NebulaSharedTests;
|
||||||
|
|
||||||
|
[TestFixture]
|
||||||
|
[TestOf(typeof(FileService))]
|
||||||
|
public class FileServiceTests : BaseSharedTest
|
||||||
|
{
|
||||||
|
private FileService _fileService = default!;
|
||||||
|
|
||||||
|
public override void BeforeServiceBuild(IServiceCollection services)
|
||||||
|
{
|
||||||
|
TestServiceHelper.InitFileServiceTest();
|
||||||
|
}
|
||||||
|
|
||||||
|
[SetUp]
|
||||||
|
public override void Setup()
|
||||||
|
{
|
||||||
|
base.Setup();
|
||||||
|
_fileService = _sharedUnit.GetService<FileService>();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void CreateFileApi_CreatesCorrectPath()
|
||||||
|
{
|
||||||
|
var subPath = "test-folder";
|
||||||
|
var fileApi = _fileService.CreateFileApi(subPath);
|
||||||
|
|
||||||
|
using (var stream = new MemoryStream("test"u8.ToArray()))
|
||||||
|
{
|
||||||
|
fileApi.Save("test.txt", stream);
|
||||||
|
}
|
||||||
|
|
||||||
|
var expectedPath = Path.Combine(FileService.RootPath, subPath);
|
||||||
|
|
||||||
|
Assert.That(Directory.Exists(expectedPath), Is.True, $"Expected path to be created: {expectedPath}");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void EnsureTempDir_CreatesDirectoryAndReturnsApi()
|
||||||
|
{
|
||||||
|
var api = _fileService.EnsureTempDir(out var path);
|
||||||
|
|
||||||
|
Assert.That(Directory.Exists(path), Is.True);
|
||||||
|
Assert.That(api, Is.Not.Null);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void OpenZip_ReturnsZipFileApi_WhenValid()
|
||||||
|
{
|
||||||
|
var testZipPath = Path.Combine(FileService.RootPath, "test.zip");
|
||||||
|
using (var archive = ZipFile.Open(testZipPath, ZipArchiveMode.Create))
|
||||||
|
{
|
||||||
|
var entry = archive.CreateEntry("test.txt");
|
||||||
|
using var streamWriter = new StreamWriter(entry.Open());
|
||||||
|
streamWriter.Write(testZipPath);
|
||||||
|
streamWriter.Flush();
|
||||||
|
}
|
||||||
|
|
||||||
|
IDisposable? streamDisposable = null;
|
||||||
|
|
||||||
|
var mockFileApi = new Mock<IFileApi>();
|
||||||
|
mockFileApi
|
||||||
|
.Setup(x => x.TryOpen(testZipPath, out It.Ref<Stream>.IsAny))
|
||||||
|
.Returns((string _, out Stream stream) =>
|
||||||
|
{
|
||||||
|
stream = File.OpenRead(testZipPath);
|
||||||
|
streamDisposable = stream;
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
|
var zipApi = _fileService.OpenZip(testZipPath, mockFileApi.Object);
|
||||||
|
Assert.That(zipApi, Is.Not.Null);
|
||||||
|
|
||||||
|
Assert.That(zipApi.TryOpen("test.txt", out var textStream), Is.True);
|
||||||
|
|
||||||
|
using (var reader = new StreamReader(textStream!))
|
||||||
|
{
|
||||||
|
Assert.That(reader.ReadToEnd(), Is.EqualTo(testZipPath));
|
||||||
|
}
|
||||||
|
|
||||||
|
textStream!.Dispose();
|
||||||
|
streamDisposable?.Dispose();
|
||||||
|
|
||||||
|
File.Delete(testZipPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void RemoveAllFiles_DeletesAllFilesAndDirectories()
|
||||||
|
{
|
||||||
|
var testDir = Path.Combine(FileService.RootPath, "cleanup-test");
|
||||||
|
Directory.CreateDirectory(testDir);
|
||||||
|
|
||||||
|
File.WriteAllText(Path.Combine(testDir, "test1.txt"), "data");
|
||||||
|
Directory.CreateDirectory(Path.Combine(testDir, "subdir"));
|
||||||
|
|
||||||
|
var mockHandler = new Mock<ILoadingHandler>();
|
||||||
|
mockHandler.Setup(x => x.AppendJob(It.IsAny<int>())).Verifiable();
|
||||||
|
mockHandler.Setup(x => x.AppendResolvedJob(It.IsAny<int>())).Verifiable();
|
||||||
|
|
||||||
|
_fileService.RemoveAllFiles("cleanup-test", mockHandler.Object, CancellationToken.None);
|
||||||
|
|
||||||
|
Assert.That(Directory.Exists(testDir), Is.True);
|
||||||
|
Assert.That(Directory.GetFiles(testDir).Length, Is.EqualTo(0));
|
||||||
|
Assert.That(Directory.GetDirectories(testDir).Length, Is.EqualTo(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void OpenZip_ThrowsException_WhenFileApiFails()
|
||||||
|
{
|
||||||
|
var mockFileApi = new Mock<IFileApi>();
|
||||||
|
mockFileApi.Setup(x => x.TryOpen(It.IsAny<string>(), out It.Ref<Stream>.IsAny))
|
||||||
|
.Returns(false);
|
||||||
|
|
||||||
|
var result = _fileService.OpenZip("invalid.zip", mockFileApi.Object);
|
||||||
|
Assert.That(result, Is.Null);
|
||||||
|
}
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user