Compare commits
19 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| a3c96174b2 | |||
| 3bfae32c25 | |||
| ae17ff2d89 | |||
| 517fadaab8 | |||
| 9e95d68c4a | |||
| 01ebe3219d | |||
| 147915f684 | |||
| 0a2fe55c7f | |||
| 02e1a14571 | |||
| 37ca8fecf3 | |||
| 875dacaa18 | |||
| 10d317c867 | |||
| 73682acbab | |||
| a7943adb76 | |||
| eb188321af | |||
| 030f680b96 | |||
| ba8153e6b4 | |||
| c4ff903c57 | |||
| 2d8c1b4d96 |
6
.idea/.idea.Nebula/.idea/avalonia.xml
generated
6
.idea/.idea.Nebula/.idea/avalonia.xml
generated
@@ -12,6 +12,7 @@
|
||||
<entry key="Nebula.Launcher/MessageBox/MessageView.axaml" value="Nebula.Launcher/Nebula.Launcher.csproj" />
|
||||
<entry key="Nebula.Launcher/MessageBox/MessageWindow.axaml" value="Nebula.Launcher/Nebula.Launcher.csproj" />
|
||||
<entry key="Nebula.Launcher/ViewModels/Styles1.axaml" value="Nebula.Launcher/Nebula.Launcher.csproj" />
|
||||
<entry key="Nebula.Launcher/Views/Config/StringConfigurationView.axaml" value="Nebula.Launcher/Nebula.Launcher.csproj" />
|
||||
<entry key="Nebula.Launcher/Views/Controls/PlayerContainerControl.axaml" value="Nebula.Launcher/Nebula.Launcher.csproj" />
|
||||
<entry key="Nebula.Launcher/Views/Controls/ServerContainerControl.axaml" value="Nebula.Launcher/Nebula.Launcher.csproj" />
|
||||
<entry key="Nebula.Launcher/Views/ExceptionView.axaml" value="Nebula.Launcher/Nebula.Launcher.csproj" />
|
||||
@@ -21,18 +22,23 @@
|
||||
<entry key="Nebula.Launcher/Views/Pages/AccountInfoPage.axaml" value="Nebula.Launcher/Nebula.Launcher.csproj" />
|
||||
<entry key="Nebula.Launcher/Views/Pages/AccountInfoView.axaml" value="Nebula.Launcher/Nebula.Launcher.csproj" />
|
||||
<entry key="Nebula.Launcher/Views/Pages/AddFavoriteView.axaml" value="Nebula.Launcher/Nebula.Launcher.csproj" />
|
||||
<entry key="Nebula.Launcher/Views/Pages/ConfigurationView.axaml" value="Nebula.Launcher/Nebula.Launcher.csproj" />
|
||||
<entry key="Nebula.Launcher/Views/Pages/ContentBrowserView.axaml" value="Nebula.Launcher/Nebula.Launcher.csproj" />
|
||||
<entry key="Nebula.Launcher/Views/Pages/FavoriteServerListView.axaml" value="Nebula.Launcher/Nebula.Launcher.csproj" />
|
||||
<entry key="Nebula.Launcher/Views/Pages/ServerListPage.axaml" value="Nebula.Launcher/Nebula.Launcher.csproj" />
|
||||
<entry key="Nebula.Launcher/Views/Pages/ServerListView.axaml" value="Nebula.Launcher/Nebula.Launcher.csproj" />
|
||||
<entry key="Nebula.Launcher/Views/Pages/ServerOverviewView.axaml" value="Nebula.Launcher/Nebula.Launcher.csproj" />
|
||||
<entry key="Nebula.Launcher/Views/Popup/AddFavoriteView.axaml" value="Nebula.Launcher/Nebula.Launcher.csproj" />
|
||||
<entry key="Nebula.Launcher/Views/Popup/EditServerNameView.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/InfoPopupView.axaml" value="Nebula.Launcher/Nebula.Launcher.csproj" />
|
||||
<entry key="Nebula.Launcher/Views/Popup/IsLoginCredentialsNullPopupView.axaml" value="Nebula.Launcher/Nebula.Launcher.csproj" />
|
||||
<entry key="Nebula.Launcher/Views/Popup/LoadingContextView.axaml" value="Nebula.Launcher/Nebula.Launcher.csproj" />
|
||||
<entry key="Nebula.Launcher/Views/Popup/LogPopupView.axaml" value="Nebula.Launcher/Nebula.Launcher.csproj" />
|
||||
<entry key="Nebula.Launcher/Views/Popup/MessagePopupView.axaml" value="Nebula.Launcher/Nebula.Launcher.csproj" />
|
||||
<entry key="Nebula.Launcher/Views/Popup/TfaView.axaml" value="Nebula.Launcher/Nebula.Launcher.csproj" />
|
||||
<entry key="Nebula.Launcher/Views/ServerCompoundEntryView.axaml" value="Nebula.Launcher/Nebula.Launcher.csproj" />
|
||||
<entry key="Nebula.Launcher/Views/ServerContainer.axaml" value="Nebula.Launcher/Nebula.Launcher.csproj" />
|
||||
<entry key="Nebula.Launcher/Views/ServerEntryView.axaml" value="Nebula.Launcher/Nebula.Launcher.csproj" />
|
||||
<entry key="Nebula.Launcher/Views/ServerList.axaml" value="Nebula.Launcher/Nebula.Launcher.csproj" />
|
||||
|
||||
2
.vscode/launch.json
vendored
2
.vscode/launch.json
vendored
@@ -10,7 +10,7 @@
|
||||
"request": "launch",
|
||||
"preLaunchTask": "build",
|
||||
// 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": [],
|
||||
"cwd": "${workspaceFolder}/Nebula.Launcher",
|
||||
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
|
||||
|
||||
@@ -1,16 +1,28 @@
|
||||
<Styles xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
|
||||
<Styles xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:pages="clr-namespace:Nebula.Launcher.ViewModels.Pages">
|
||||
|
||||
<!-- Base Window Style -->
|
||||
<Style Selector="Window">
|
||||
<Setter Property="Background" Value="{StaticResource DefaultBackground}" />
|
||||
</Style>
|
||||
|
||||
<!-- Common Border Style -->
|
||||
<Style Selector="Border">
|
||||
<Setter Property="CornerRadius" Value="10" />
|
||||
</Style>
|
||||
|
||||
<!-- Common Label Style -->
|
||||
<Style Selector="Label">
|
||||
<Setter Property="Foreground" Value="#f7f7ff" />
|
||||
</Style>
|
||||
|
||||
<!-- Common ItemsControl Style -->
|
||||
<Style Selector="ItemsControl">
|
||||
<Setter Property="Background" Value="Transparent" />
|
||||
</Style>
|
||||
|
||||
<!-- General Button Style -->
|
||||
<Style Selector="Button">
|
||||
<Setter Property="BorderBrush" Value="#343334" />
|
||||
<Setter Property="BorderThickness" Value="0" />
|
||||
@@ -19,6 +31,7 @@
|
||||
<Setter Property="Background" Value="Transparent" />
|
||||
</Style>
|
||||
|
||||
<!-- Button State Overrides -->
|
||||
<Style Selector="Button:pressed">
|
||||
<Setter Property="RenderTransform" Value="{x:Null}" />
|
||||
<Setter Property="BorderThickness" Value="0,0,0,2" />
|
||||
@@ -30,26 +43,33 @@
|
||||
<Setter Property="BorderThickness" Value="0,0,0,0" />
|
||||
</Style>
|
||||
|
||||
<!-- ViewSelectButton Specialization -->
|
||||
<Style Selector="Button.ViewSelectButton">
|
||||
<Setter Property="CornerRadius" Value="0,8,8,0" />
|
||||
<Setter Property="Margin" Value="0,0,0,5" />
|
||||
<Setter Property="Padding" Value="8" />
|
||||
<Setter Property="Background" Value="Transparent" />
|
||||
</Style>
|
||||
|
||||
<Style Selector="Button.ViewSelectButton:pressed">
|
||||
<Setter Property="BorderThickness" Value="0,0,0,0" />
|
||||
</Style>
|
||||
|
||||
<!-- TextBox Styles -->
|
||||
<Style Selector="TextBox">
|
||||
<Setter Property="Foreground" Value="#f7f7ff" />
|
||||
<Setter Property="SelectionForegroundBrush" Value="#f7f7ff" />
|
||||
<Setter Property="BorderThickness" Value="0,0,0,0" />
|
||||
<Setter Property="BorderThickness" Value="0" />
|
||||
<Setter Property="BorderBrush" Value="#f7f7ff" />
|
||||
<Setter Property="Background" Value="Transparent" />
|
||||
</Style>
|
||||
<Style Selector="TextBox" />
|
||||
|
||||
<Style Selector="TextBox:focus /template/ Border#PART_BorderElement">
|
||||
<Setter Property="BorderBrush" Value="White" />
|
||||
<Setter Property="Background" Value="Transparent" />
|
||||
<Setter Property="BorderThickness" Value="0,0,0,1" />
|
||||
</Style>
|
||||
|
||||
<!-- ListBoxItem Styles -->
|
||||
<Style Selector="ListBoxItem /template/ ContentPresenter">
|
||||
<Setter Property="CornerRadius" Value="0,8,8,0" />
|
||||
<Setter Property="Margin" Value="0,0,0,5" />
|
||||
@@ -60,29 +80,37 @@
|
||||
<Style Selector="ListBoxItem:selected /template/ ContentPresenter">
|
||||
<Setter Property="CornerRadius" Value="0,8,8,0" />
|
||||
<Setter Property="Background">
|
||||
<LinearGradientBrush EndPoint="100%,50%" StartPoint="0%,50%">
|
||||
<GradientStop Color="#ae4c47" Offset="0.0" />
|
||||
<GradientStop Color="#D95F59" Offset="0.2" />
|
||||
<GradientStop Color="#D95F59" Offset="1.0" />
|
||||
</LinearGradientBrush>
|
||||
<Setter.Value>
|
||||
<LinearGradientBrush EndPoint="100%,50%" StartPoint="0%,50%">
|
||||
<GradientStop Color="#ae4c47" Offset="0.0" />
|
||||
<GradientStop Color="#D95F59" Offset="0.2" />
|
||||
<GradientStop Color="#D95F59" Offset="1.0" />
|
||||
</LinearGradientBrush>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
<Setter Property="BoxShadow" Value="0 0 15 1 #1212" />
|
||||
</Style>
|
||||
|
||||
<Style Selector="ListBoxItem:pointerover">
|
||||
<Setter Property="CornerRadius" Value="0,8,8,0" />
|
||||
<Setter Property="Margin" Value="0,0,5,0" />
|
||||
</Style>
|
||||
|
||||
<Style Selector="ListBoxItem:pressed /template/ ContentPresenter">
|
||||
<Setter Property="CornerRadius" Value="0,8,8,0" />
|
||||
<Setter Property="Background" Value="{StaticResource DefaultSelected}" />
|
||||
</Style>
|
||||
|
||||
<Style Selector="TextBox">
|
||||
<Setter Property="Background" Value="Transparent" />
|
||||
</Style>
|
||||
<Style Selector="TextBox:focus /template/ Border#PART_BorderElement">
|
||||
<Setter Property="BorderBrush" Value="White" />
|
||||
<Setter Property="Background" Value="Transparent" />
|
||||
<Setter Property="BorderThickness" Value="0,0,0,1" />
|
||||
</Style>
|
||||
<!-- Combined ConfigBorder Styles -->
|
||||
<Style Selector="pages|ComplexUnitConfigControl.ConfigBorder,
|
||||
pages|ArrayUnitConfigControl.ConfigBorder,
|
||||
pages|StringUnitConfigControl.ConfigBorder,
|
||||
pages|IntUnitConfigControl.ConfigBorder,
|
||||
pages|FloatUnitConfigControl.ConfigBorder">
|
||||
<Setter Property="Background" Value="#33333355" />
|
||||
<Setter Property="CornerRadius" Value="0"/>
|
||||
<Setter Property="BorderThickness" Value="1,0,0,2" />
|
||||
<Setter Property="BorderBrush" Value="#3f3f3f5f" />
|
||||
</Style>
|
||||
|
||||
</Styles>
|
||||
@@ -0,0 +1,68 @@
|
||||
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
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
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 = Продолжить
|
||||
7
Nebula.Launcher/Assets/svg/pencil.svg
Normal file
7
Nebula.Launcher/Assets/svg/pencil.svg
Normal file
@@ -0,0 +1,7 @@
|
||||
<!-- License: Apache. Made by Remix Design: https://github.com/Remix-Design/remixicon -->
|
||||
<svg width="24px" height="24px" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
|
||||
<g>
|
||||
<path fill="none" d="M0 0h24v24H0z"/>
|
||||
<path fill="white" d="M15.728 9.686l-1.414-1.414L5 17.586V19h1.414l9.314-9.314zm1.414-1.414l1.414-1.414-1.414-1.414-1.414 1.414 1.414 1.414zM7.242 21H3v-4.243L16.435 3.322a1 1 0 0 1 1.414 0l2.829 2.829a1 1 0 0 1 0 1.414L7.243 21z"/>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 489 B |
@@ -19,13 +19,16 @@ public class FilterBox : UserControl
|
||||
|
||||
public Action<FilterBoxChangedEventArgs>? OnFilterChanged {get; set;}
|
||||
|
||||
public string? FilterBoxName {
|
||||
set => filterName.Text = value;
|
||||
get => filterName.Text;
|
||||
public string FilterBoxName {
|
||||
set => filterName.LocalId = value;
|
||||
get => filterName.LocalId;
|
||||
}
|
||||
|
||||
private StackPanel filterPanel;
|
||||
private TextBox filterName = new TextBox();
|
||||
private LocalizedLabel filterName = new LocalizedLabel()
|
||||
{
|
||||
VerticalAlignment = VerticalAlignment.Center
|
||||
};
|
||||
|
||||
public FilterBox()
|
||||
{
|
||||
@@ -35,6 +38,8 @@ public class FilterBox : UserControl
|
||||
Spacing = 5,
|
||||
};
|
||||
|
||||
filterPanel.Children.Add(filterName);
|
||||
|
||||
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 Nebula.Launcher.Models;
|
||||
using Nebula.Launcher.ServerListProviders;
|
||||
using Nebula.Launcher.ViewModels;
|
||||
using Nebula.Launcher.ViewModels.Pages;
|
||||
@@ -43,6 +44,17 @@ public partial class ServerListView : UserControl
|
||||
else _provider.OnLoaded += RefreshRequired;
|
||||
}
|
||||
|
||||
public void RequireStatusUpdate()
|
||||
{
|
||||
foreach (var rawView in ServerList.Items)
|
||||
{
|
||||
if (rawView is ServerEntryModelView serverEntryModelView)
|
||||
{
|
||||
//serverEntryModelView.UpdateStatusIfNecessary();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void ApplyFilter(ServerFilter? filter)
|
||||
{
|
||||
_currentFilter = filter;
|
||||
@@ -50,9 +62,10 @@ public partial class ServerListView : UserControl
|
||||
if(IsLoading)
|
||||
return;
|
||||
|
||||
foreach (IFilterConsumer? serverView in ServerList.Items)
|
||||
foreach (var serverView in ServerList.Items)
|
||||
{
|
||||
serverView?.ProcessFilter(filter);
|
||||
if(serverView is IFilterConsumer filterConsumer)
|
||||
filterConsumer.ProcessFilter(filter);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,7 +85,8 @@ public partial class ServerListView : UserControl
|
||||
foreach (var serverEntry in _provider.GetServers())
|
||||
{
|
||||
ServerList.Items.Add(serverEntry);
|
||||
serverEntry.ProcessFilter(_currentFilter);
|
||||
if(serverEntry is IFilterConsumer serverFilter)
|
||||
serverFilter.ProcessFilter(_currentFilter);
|
||||
}
|
||||
|
||||
foreach (var error in _provider.GetErrors())
|
||||
|
||||
@@ -1,2 +1 @@
|
||||
global using Nebula.Shared.Attributes;
|
||||
global using Nebula.Launcher.ViewHelper;
|
||||
@@ -1,5 +1,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using Nebula.Launcher.Models;
|
||||
using Nebula.Launcher.Models.Auth;
|
||||
using Nebula.Launcher.ViewModels.Pages;
|
||||
using Nebula.Shared.Services;
|
||||
|
||||
@@ -7,6 +9,8 @@ namespace Nebula.Launcher;
|
||||
|
||||
public static class LauncherConVar
|
||||
{
|
||||
public static readonly ConVar<bool> DoMigration =
|
||||
ConVarBuilder.Build("migration.doMigrate", true);
|
||||
public static readonly ConVar<ProfileAuthCredentials[]> AuthProfiles =
|
||||
ConVarBuilder.Build<ProfileAuthCredentials[]>("auth.profiles.v2", []);
|
||||
|
||||
@@ -16,21 +20,25 @@ public static class LauncherConVar
|
||||
public static readonly ConVar<string[]> Favorites =
|
||||
ConVarBuilder.Build<string[]>("server.favorites", []);
|
||||
|
||||
public static readonly ConVar<AuthServerCredentials[]> AuthServers = ConVarBuilder.Build<AuthServerCredentials[]>("launcher.authServers", [
|
||||
public static readonly ConVar<Dictionary<string,string>> ServerCustomNames =
|
||||
ConVarBuilder.Build<Dictionary<string,string>>("server.names", []);
|
||||
|
||||
public static readonly ConVar<AuthServerCredentials[]> AuthServers =
|
||||
ConVarBuilder.Build<AuthServerCredentials[]>("launcher.authServers", [
|
||||
new AuthServerCredentials(
|
||||
"WizDen",
|
||||
[
|
||||
"https://auth.spacestation14.com/",
|
||||
"https://auth.fallback.spacestation14.com/"
|
||||
"https://harpy.durenko.tatar/auth-api/",
|
||||
"https://auth.fallback.spacestation14.com/",
|
||||
])
|
||||
]);
|
||||
|
||||
public static readonly ConVar<ServerHubRecord[]> Hub = ConVarBuilder.Build<ServerHubRecord[]>("launcher.hub.v2", [
|
||||
new ServerHubRecord("WizDen", "https://hub.spacestation14.com/api/servers", null),
|
||||
new ServerHubRecord("AltHub","https://web.networkgamez.com/api/servers",null)
|
||||
new ServerHubRecord("WizDen", "https://harpy.durenko.tatar/hub-api/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",
|
||||
"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
|
||||
);
|
||||
11
Nebula.Launcher/Models/Auth/ProfileAuthCredentials.cs
Normal file
11
Nebula.Launcher/Models/Auth/ProfileAuthCredentials.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace Nebula.Launcher.Models.Auth;
|
||||
|
||||
public sealed record ProfileAuthCredentials(
|
||||
string Login,
|
||||
string Password,
|
||||
string AuthServer,
|
||||
[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);
|
||||
}
|
||||
@@ -8,5 +8,4 @@ public record ListItemTemplate(Type ModelType, string IconKey, string Label);
|
||||
public record ServerListTabTemplate(IServerListProvider ServerListProvider, string TabName);
|
||||
public record ServerHubRecord(
|
||||
[property:JsonPropertyName("name")] string Name,
|
||||
[property:JsonPropertyName("url")] string MainUrl,
|
||||
[property:JsonPropertyName("fallback")] string? Fallback);
|
||||
[property:JsonPropertyName("url")] string MainUrl);
|
||||
40
Nebula.Launcher/Models/LogInfo.cs
Normal file
40
Nebula.Launcher/Models/LogInfo.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using System.Text.RegularExpressions;
|
||||
using Avalonia.Media;
|
||||
|
||||
namespace Nebula.Launcher.Models;
|
||||
|
||||
public sealed class LogInfo
|
||||
{
|
||||
public string Category { get; set; } = "LOG";
|
||||
public IBrush CategoryColor { get; set; } = Brush.Parse("#424242");
|
||||
public string Message { get; set; } = "";
|
||||
|
||||
public static LogInfo FromString(string input)
|
||||
{
|
||||
var matches = Regex.Matches(input, @"(\[(?<c>.*)\] (?<m>.*))|(?<m>.*)");
|
||||
var category = "All";
|
||||
|
||||
if (matches[0].Groups.TryGetValue("c", out var c)) category = c.Value;
|
||||
|
||||
var color = Brush.Parse("#444444");
|
||||
|
||||
switch (category)
|
||||
{
|
||||
case "DEBG":
|
||||
color = Brush.Parse("#2436d4");
|
||||
break;
|
||||
case "ERRO":
|
||||
color = Brush.Parse("#d42436");
|
||||
break;
|
||||
case "INFO":
|
||||
color = Brush.Parse("#0ab3c9");
|
||||
break;
|
||||
}
|
||||
|
||||
var message = matches[0].Groups["m"].Value;
|
||||
return new LogInfo
|
||||
{
|
||||
Category = category, Message = message, CategoryColor = color
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -31,6 +31,7 @@
|
||||
<PackageReference Include="JetBrains.Annotations" Version="2024.3.0"/>
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.0"/>
|
||||
<PackageReference Include="libsodium" Version="1.0.20"/>
|
||||
<PackageReference Include="Robust.Natives" Version="0.1.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
@@ -53,6 +54,8 @@
|
||||
<Copy SourceFiles="..\Nebula.Runner\bin\$(Configuration)\$(TargetFramework)\Nebula.Runner.pdb" DestinationFolder="$(OutDir)"/>
|
||||
<Copy SourceFiles="..\Nebula.Runner\bin\$(Configuration)\$(TargetFramework)\Nebula.Runner.deps.json" DestinationFolder="$(OutDir)"/>
|
||||
<Copy SourceFiles="..\Nebula.Runner\bin\$(Configuration)\$(TargetFramework)\Nebula.Runner.runtimeconfig.json" DestinationFolder="$(OutDir)"/>
|
||||
|
||||
<Copy SourceFiles="..\Nebula.Runner\bin\$(Configuration)\$(TargetFramework)\0Harmony.dll" DestinationFolder="$(OutDir)"/>
|
||||
</Target>
|
||||
|
||||
<Target Name="PublishCheck" AfterTargets="Publish">
|
||||
@@ -60,6 +63,8 @@
|
||||
<Copy SourceFiles="..\Nebula.Runner\bin\$(Configuration)\$(TargetFramework)\Nebula.Runner.pdb" DestinationFolder="$(PublishDir)"/>
|
||||
<Copy SourceFiles="..\Nebula.Runner\bin\$(Configuration)\$(TargetFramework)\Nebula.Runner.deps.json" DestinationFolder="$(PublishDir)"/>
|
||||
<Copy SourceFiles="..\Nebula.Runner\bin\$(Configuration)\$(TargetFramework)\Nebula.Runner.runtimeconfig.json" DestinationFolder="$(PublishDir)"/>
|
||||
|
||||
<Copy SourceFiles="..\Nebula.Runner\bin\$(Configuration)\$(TargetFramework)\0Harmony.dll" DestinationFolder="$(PublishDir)"/>
|
||||
</Target>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
using System.Diagnostics;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Nebula.Shared.Services;
|
||||
|
||||
namespace Nebula.Launcher.ProcessHelper;
|
||||
|
||||
public abstract class DotnetProcessStartInfoProviderBase(DotnetResolverService resolverService) : IProcessStartInfoProvider
|
||||
{
|
||||
protected abstract string GetDllPath();
|
||||
|
||||
public virtual async Task<ProcessStartInfo> GetProcessStartInfo()
|
||||
{
|
||||
return new ProcessStartInfo
|
||||
{
|
||||
FileName = await resolverService.EnsureDotnet(),
|
||||
Arguments = GetDllPath(),
|
||||
CreateNoWindow = true,
|
||||
UseShellExecute = false,
|
||||
RedirectStandardOutput = true,
|
||||
RedirectStandardError = true,
|
||||
StandardOutputEncoding = Encoding.UTF8
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Threading.Tasks;
|
||||
using Nebula.Shared;
|
||||
using Nebula.Shared.Models;
|
||||
using Nebula.Shared.Services;
|
||||
|
||||
namespace Nebula.Launcher.ProcessHelper;
|
||||
|
||||
[ServiceRegister(isSingleton:false)]
|
||||
public sealed class GameProcessStartInfoProvider(DotnetResolverService resolverService, AuthService authService) :
|
||||
DotnetProcessStartInfoProviderBase(resolverService)
|
||||
{
|
||||
private string? _publicKey;
|
||||
private RobustUrl _address = default!;
|
||||
|
||||
protected override string GetDllPath()
|
||||
{
|
||||
var path = Path.GetDirectoryName(Assembly.GetEntryAssembly()?.Location);
|
||||
return Path.Join(path, "Nebula.Runner.dll");
|
||||
}
|
||||
|
||||
public GameProcessStartInfoProvider WithBuildInfo(string publicKey, RobustUrl address)
|
||||
{
|
||||
_publicKey = publicKey;
|
||||
_address = address;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public override async Task<ProcessStartInfo> GetProcessStartInfo()
|
||||
{
|
||||
var baseStart = await base.GetProcessStartInfo();
|
||||
|
||||
var authProv = authService.SelectedAuth;
|
||||
if(authProv is null)
|
||||
throw new Exception("Client is without selected auth");
|
||||
|
||||
baseStart.EnvironmentVariables["ROBUST_AUTH_USERID"] = authProv.UserId.ToString();
|
||||
baseStart.EnvironmentVariables["ROBUST_AUTH_TOKEN"] = authProv.Token.Token;
|
||||
baseStart.EnvironmentVariables["ROBUST_AUTH_SERVER"] = authProv.AuthServer;
|
||||
baseStart.EnvironmentVariables["AUTH_LOGIN"] = authProv.Login;
|
||||
baseStart.EnvironmentVariables["ROBUST_AUTH_PUBKEY"] = _publicKey;
|
||||
baseStart.EnvironmentVariables["GAME_URL"] = _address.ToString();
|
||||
|
||||
return baseStart;
|
||||
}
|
||||
}
|
||||
33
Nebula.Launcher/ProcessHelper/GameRunnerPreparer.cs
Normal file
33
Nebula.Launcher/ProcessHelper/GameRunnerPreparer.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Nebula.Shared;
|
||||
using Nebula.Shared.Models;
|
||||
using Nebula.Shared.Services;
|
||||
|
||||
namespace Nebula.Launcher.ProcessHelper;
|
||||
|
||||
[ServiceRegister]
|
||||
public sealed class GameRunnerPreparer(IServiceProvider provider, ContentService contentService, EngineService engineService, DebugService debugService)
|
||||
{
|
||||
public async Task<ProcessRunHandler<GameProcessStartInfoProvider>> GetGameProcessStartInfoProvider(RobustUrl address, ILoadingHandler loadingHandler, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var buildInfo = await contentService.GetBuildInfo(address, cancellationToken);
|
||||
|
||||
var engine = await engineService.EnsureEngine(buildInfo.BuildInfo.Build.EngineVersion);
|
||||
|
||||
if (engine is null)
|
||||
throw new Exception("Engine version not found: " + buildInfo.BuildInfo.Build.EngineVersion);
|
||||
|
||||
await contentService.EnsureItems(buildInfo.RobustManifestInfo, loadingHandler, cancellationToken);
|
||||
await engineService.EnsureEngineModules("Robust.Client.WebView", buildInfo.BuildInfo.Build.EngineVersion);
|
||||
|
||||
var gameInfo =
|
||||
provider.GetService<GameProcessStartInfoProvider>()!.WithBuildInfo(buildInfo.BuildInfo.Auth.PublicKey,
|
||||
address);
|
||||
var gameProcessRunHandler = new ProcessRunHandler<GameProcessStartInfoProvider>(gameInfo);
|
||||
|
||||
return gameProcessRunHandler;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace Nebula.Launcher.ProcessHelper;
|
||||
|
||||
public interface IProcessConsumerCollection
|
||||
{
|
||||
public void RegisterLogger(IProcessLogConsumer consumer);
|
||||
}
|
||||
8
Nebula.Launcher/ProcessHelper/IProcessLogConsumer.cs
Normal file
8
Nebula.Launcher/ProcessHelper/IProcessLogConsumer.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
namespace Nebula.Launcher.ProcessHelper;
|
||||
|
||||
public interface IProcessLogConsumer
|
||||
{
|
||||
public void Out(string text);
|
||||
public void Error(string text);
|
||||
public void Fatal(string text);
|
||||
}
|
||||
9
Nebula.Launcher/ProcessHelper/IProcessRunner.cs
Normal file
9
Nebula.Launcher/ProcessHelper/IProcessRunner.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
using System.Diagnostics;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Nebula.Launcher.ProcessHelper;
|
||||
|
||||
public interface IProcessStartInfoProvider
|
||||
{
|
||||
public Task<ProcessStartInfo> GetProcessStartInfo();
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Nebula.Launcher.ProcessHelper;
|
||||
|
||||
public sealed class ProcessLogConsumerCollection: IProcessLogConsumer, IProcessConsumerCollection
|
||||
{
|
||||
private readonly List<IProcessLogConsumer> _consumers = [];
|
||||
|
||||
public void RegisterLogger(IProcessLogConsumer consumer)
|
||||
{
|
||||
_consumers.Add(consumer);
|
||||
}
|
||||
|
||||
public void Out(string text)
|
||||
{
|
||||
foreach (var consumer in _consumers)
|
||||
{
|
||||
consumer.Out(text);
|
||||
}
|
||||
}
|
||||
|
||||
public void Error(string text)
|
||||
{
|
||||
foreach (var consumer in _consumers)
|
||||
{
|
||||
consumer.Error(text);
|
||||
}
|
||||
}
|
||||
|
||||
public void Fatal(string text)
|
||||
{
|
||||
foreach (var consumer in _consumers)
|
||||
{
|
||||
consumer.Fatal(text);
|
||||
}
|
||||
}
|
||||
}
|
||||
137
Nebula.Launcher/ProcessHelper/ProcessRunHandler.cs
Normal file
137
Nebula.Launcher/ProcessHelper/ProcessRunHandler.cs
Normal file
@@ -0,0 +1,137 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Threading.Tasks;
|
||||
using Nebula.Shared.Services;
|
||||
using Nebula.Shared.Services.Logging;
|
||||
|
||||
namespace Nebula.Launcher.ProcessHelper;
|
||||
|
||||
public class ProcessRunHandler<T> : IProcessConsumerCollection, IDisposable where T: IProcessStartInfoProvider
|
||||
{
|
||||
private ProcessStartInfo? _processInfo;
|
||||
private Task<ProcessStartInfo>? _processInfoTask;
|
||||
|
||||
private Process? _process;
|
||||
private ProcessLogConsumerCollection _consumerCollection = new();
|
||||
|
||||
private string _lastError = string.Empty;
|
||||
private readonly T _currentProcessStartInfoProvider;
|
||||
|
||||
public T GetCurrentProcessStartInfo() => _currentProcessStartInfoProvider;
|
||||
public bool IsRunning => _processInfo is not null;
|
||||
public Action<ProcessRunHandler<T>>? OnProcessExited;
|
||||
|
||||
public void RegisterLogger(IProcessLogConsumer consumer)
|
||||
{
|
||||
_consumerCollection.RegisterLogger(consumer);
|
||||
}
|
||||
|
||||
public ProcessRunHandler(T processStartInfoProvider)
|
||||
{
|
||||
_currentProcessStartInfoProvider = processStartInfoProvider;
|
||||
_processInfoTask = _currentProcessStartInfoProvider.GetProcessStartInfo();
|
||||
_processInfoTask.GetAwaiter().OnCompleted(OnInfoProvided);
|
||||
}
|
||||
|
||||
private void OnInfoProvided()
|
||||
{
|
||||
if (_processInfoTask == null)
|
||||
return;
|
||||
|
||||
_processInfo = _processInfoTask.GetAwaiter().GetResult();
|
||||
_processInfoTask = null;
|
||||
}
|
||||
|
||||
public void Start()
|
||||
{
|
||||
if (_processInfoTask != null)
|
||||
{
|
||||
_processInfoTask.Wait();
|
||||
}
|
||||
|
||||
_process = Process.Start(_processInfo!);
|
||||
|
||||
if (_process is null) return;
|
||||
|
||||
_process.EnableRaisingEvents = true;
|
||||
|
||||
_process.BeginOutputReadLine();
|
||||
_process.BeginErrorReadLine();
|
||||
|
||||
_process.OutputDataReceived += OnOutputDataReceived;
|
||||
_process.ErrorDataReceived += OnErrorDataReceived;
|
||||
|
||||
_process.Exited += OnExited;
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
{
|
||||
_process?.CloseMainWindow();
|
||||
}
|
||||
|
||||
private void OnExited(object? sender, EventArgs e)
|
||||
{
|
||||
if (_process is null) return;
|
||||
|
||||
_process.OutputDataReceived -= OnOutputDataReceived;
|
||||
_process.ErrorDataReceived -= OnErrorDataReceived;
|
||||
_process.Exited -= OnExited;
|
||||
|
||||
|
||||
if (_process.ExitCode != 0)
|
||||
_consumerCollection.Fatal(_lastError);
|
||||
|
||||
_process.Dispose();
|
||||
_process = null;
|
||||
|
||||
OnProcessExited?.Invoke(this);
|
||||
}
|
||||
|
||||
private void OnErrorDataReceived(object sender, DataReceivedEventArgs e)
|
||||
{
|
||||
if (e.Data != null)
|
||||
{
|
||||
_lastError = e.Data;
|
||||
_consumerCollection.Error(e.Data);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnOutputDataReceived(object sender, DataReceivedEventArgs e)
|
||||
{
|
||||
if (e.Data != null)
|
||||
{
|
||||
_consumerCollection.Out(e.Data);
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_processInfoTask?.Dispose();
|
||||
_process?.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class DebugLoggerBridge : IProcessLogConsumer
|
||||
{
|
||||
private ILogger _logger;
|
||||
|
||||
public DebugLoggerBridge(ILogger logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public void Out(string text)
|
||||
{
|
||||
_logger.Log(LoggerCategory.Log, text);
|
||||
}
|
||||
|
||||
public void Error(string text)
|
||||
{
|
||||
_logger.Log(LoggerCategory.Error, text);
|
||||
}
|
||||
|
||||
public void Fatal(string text)
|
||||
{
|
||||
_logger.Log(LoggerCategory.Error, text);
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Layout;
|
||||
using Avalonia.Media;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Nebula.Launcher.ViewModels;
|
||||
using Nebula.Launcher.ViewModels.Pages;
|
||||
using Nebula.Launcher.ViewModels.Popup;
|
||||
using Nebula.Shared;
|
||||
using Nebula.Shared.Models;
|
||||
using Nebula.Shared.Services;
|
||||
@@ -11,19 +16,20 @@ using Nebula.Shared.Utils;
|
||||
|
||||
namespace Nebula.Launcher.ServerListProviders;
|
||||
|
||||
[ServiceRegister(), ConstructGenerator]
|
||||
[ServiceRegister, ConstructGenerator]
|
||||
public sealed partial class FavoriteServerListProvider : IServerListProvider, IServerListDirtyInvoker
|
||||
{
|
||||
[GenerateProperty] private ConfigurationService ConfigurationService { get; }
|
||||
[GenerateProperty] private RestService RestService { get; }
|
||||
[GenerateProperty] private IServiceProvider ServiceProvider { get; }
|
||||
[GenerateProperty] private ServerViewContainer ServerViewContainer { get; }
|
||||
|
||||
private List<IFilterConsumer> _serverLists = [];
|
||||
private List<IListEntryModelView> _serverLists = [];
|
||||
private string[] rawServerLists = [];
|
||||
|
||||
public bool IsLoaded { get; private set; }
|
||||
public Action? OnLoaded { get; set; }
|
||||
public Action? Dirty { get; set; }
|
||||
public IEnumerable<IFilterConsumer> GetServers()
|
||||
public IEnumerable<IListEntryModelView> GetServers()
|
||||
{
|
||||
return _serverLists;
|
||||
}
|
||||
@@ -39,18 +45,20 @@ public sealed partial class FavoriteServerListProvider : IServerListProvider, IS
|
||||
_serverLists.Clear();
|
||||
var servers = GetFavoriteEntries();
|
||||
|
||||
_serverLists.AddRange(
|
||||
servers.Select(s =>
|
||||
ServerViewContainer.Get(s.ToRobustUrl())
|
||||
)
|
||||
var serverEntries = servers.Select(s =>
|
||||
ServerViewContainer.Get(s.ToRobustUrl())
|
||||
);
|
||||
|
||||
_serverLists.AddRange(serverEntries);
|
||||
|
||||
_serverLists.Add(new AddFavoriteButton(ServiceProvider));
|
||||
|
||||
IsLoaded = true;
|
||||
OnLoaded?.Invoke();
|
||||
}
|
||||
|
||||
public void AddFavorite(ServerEntryModelView entryModelView)
|
||||
{
|
||||
entryModelView.IsFavorite = true;
|
||||
AddFavorite(entryModelView.Address);
|
||||
}
|
||||
|
||||
@@ -59,7 +67,7 @@ public sealed partial class FavoriteServerListProvider : IServerListProvider, IS
|
||||
var servers = GetFavoriteEntries();
|
||||
servers.Add(robustUrl.ToString());
|
||||
ConfigurationService.SetConfigValue(LauncherConVar.Favorites, servers.ToArray());
|
||||
Dirty?.Invoke();
|
||||
if(ServerViewContainer.Get(robustUrl) is IFavoriteEntryModelView favoriteView) favoriteView.IsFavorite = true;
|
||||
}
|
||||
|
||||
public void RemoveFavorite(ServerEntryModelView entryModelView)
|
||||
@@ -67,14 +75,57 @@ public sealed partial class FavoriteServerListProvider : IServerListProvider, IS
|
||||
var servers = GetFavoriteEntries();
|
||||
servers.Remove(entryModelView.Address.ToString());
|
||||
ConfigurationService.SetConfigValue(LauncherConVar.Favorites, servers.ToArray());
|
||||
Dirty?.Invoke();
|
||||
}
|
||||
|
||||
public void RemoveFavorite(RobustUrl url)
|
||||
{
|
||||
var servers = GetFavoriteEntries();
|
||||
servers.Remove(url.ToString());
|
||||
ConfigurationService.SetConfigValue(LauncherConVar.Favorites, servers.ToArray());
|
||||
}
|
||||
|
||||
private List<string> GetFavoriteEntries()
|
||||
{
|
||||
return ConfigurationService.GetConfigValue(LauncherConVar.Favorites)?.ToList() ?? [];
|
||||
return rawServerLists.ToList();
|
||||
}
|
||||
|
||||
private void Initialise()
|
||||
{
|
||||
ConfigurationService.SubscribeVarChanged(LauncherConVar.Favorites, OnVarChanged, true);
|
||||
}
|
||||
|
||||
private void OnVarChanged(string[]? value)
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
rawServerLists = [];
|
||||
Dirty?.Invoke();
|
||||
return;
|
||||
}
|
||||
|
||||
rawServerLists = value;
|
||||
Dirty?.Invoke();
|
||||
}
|
||||
|
||||
private void Initialise(){}
|
||||
private void InitialiseInDesignMode(){}
|
||||
}
|
||||
|
||||
public class AddFavoriteButton: Border, IListEntryModelView{
|
||||
|
||||
private Button _addFavoriteButton = new Button();
|
||||
public AddFavoriteButton(IServiceProvider serviceProvider)
|
||||
{
|
||||
Margin = new Thickness(5, 5, 5, 20);
|
||||
Background = new SolidColorBrush(Color.Parse("#222222"));
|
||||
CornerRadius = new CornerRadius(20f);
|
||||
_addFavoriteButton.HorizontalAlignment = HorizontalAlignment.Center;
|
||||
_addFavoriteButton.Click += (sender, args) =>
|
||||
{
|
||||
serviceProvider.GetService<PopupMessageService>()!.Popup(
|
||||
serviceProvider.GetService<AddFavoriteViewModel>()!);
|
||||
};
|
||||
_addFavoriteButton.Content = "Add Favorite";
|
||||
Child = _addFavoriteButton;
|
||||
}
|
||||
public bool IsFavorite { get; set; }
|
||||
}
|
||||
@@ -24,7 +24,7 @@ public sealed partial class HubServerListProvider : IServerListProvider
|
||||
public Action? OnLoaded { get; set; }
|
||||
|
||||
private CancellationTokenSource? _cts;
|
||||
private readonly List<ServerEntryModelView> _servers = [];
|
||||
private readonly List<IListEntryModelView> _servers = [];
|
||||
private readonly List<Exception> _errors = [];
|
||||
|
||||
public HubServerListProvider With(string hubUrl)
|
||||
@@ -33,7 +33,7 @@ public sealed partial class HubServerListProvider : IServerListProvider
|
||||
return this;
|
||||
}
|
||||
|
||||
public IEnumerable<IFilterConsumer> GetServers()
|
||||
public IEnumerable<IListEntryModelView> GetServers()
|
||||
{
|
||||
return _servers;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Nebula.Launcher.ViewModels;
|
||||
using Nebula.Launcher.ViewModels.Pages;
|
||||
|
||||
namespace Nebula.Launcher.ServerListProviders;
|
||||
|
||||
@@ -9,7 +10,7 @@ public interface IServerListProvider
|
||||
public bool IsLoaded { get; }
|
||||
public Action? OnLoaded { get; set; }
|
||||
|
||||
public IEnumerable<IFilterConsumer> GetServers();
|
||||
public IEnumerable<IListEntryModelView> GetServers();
|
||||
public IEnumerable<Exception> GetErrors();
|
||||
|
||||
public void LoadServerList();
|
||||
|
||||
@@ -2,6 +2,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using Nebula.Launcher.Controls;
|
||||
using Nebula.Launcher.ViewModels;
|
||||
using Nebula.Launcher.ViewModels.Pages;
|
||||
|
||||
namespace Nebula.Launcher.ServerListProviders;
|
||||
|
||||
@@ -9,7 +10,7 @@ public sealed class TestServerList : IServerListProvider
|
||||
{
|
||||
public bool IsLoaded => true;
|
||||
public Action? OnLoaded { get; set; }
|
||||
public IEnumerable<IFilterConsumer> GetServers()
|
||||
public IEnumerable<IListEntryModelView> GetServers()
|
||||
{
|
||||
return [new ServerEntryModelView(),new ServerEntryModelView()];
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ using Avalonia.Controls.ApplicationLifetimes;
|
||||
using Avalonia.Threading;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Nebula.Launcher.Views;
|
||||
using Nebula.Shared.ViewHelper;
|
||||
|
||||
namespace Nebula.Launcher;
|
||||
|
||||
|
||||
34
Nebula.Launcher/Services/ExplorerService.cs
Normal file
34
Nebula.Launcher/Services/ExplorerService.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.InteropServices;
|
||||
using Nebula.Shared;
|
||||
|
||||
namespace Nebula.Launcher.Services;
|
||||
|
||||
|
||||
public static class ExplorerHelper
|
||||
{
|
||||
public static void OpenFolder(string path)
|
||||
{
|
||||
string command;
|
||||
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||
command = "explorer.exe";
|
||||
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
||||
command = "xdg-open";
|
||||
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
|
||||
command = "open";
|
||||
else
|
||||
throw new PlatformNotSupportedException("Unsupported OS platform");
|
||||
|
||||
|
||||
var startInfo = new ProcessStartInfo
|
||||
{
|
||||
FileName = command,
|
||||
Arguments = path,
|
||||
UseShellExecute = false
|
||||
};
|
||||
|
||||
Process.Start(startInfo);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using Avalonia.Markup.Xaml;
|
||||
using Avalonia.Platform;
|
||||
using Fluent.Net;
|
||||
using Nebula.Shared;
|
||||
@@ -14,33 +16,62 @@ public partial class LocalisationService
|
||||
[GenerateProperty] private ConfigurationService ConfigurationService { get; }
|
||||
|
||||
private CultureInfo _currentCultureInfo = CultureInfo.CurrentCulture;
|
||||
private MessageContext _currentMessageContext;
|
||||
private static MessageContext? _currentMessageContext;
|
||||
|
||||
private void Initialise()
|
||||
{
|
||||
// LoadLanguage(CultureInfo.GetCultureInfo(ConfigurationService.GetConfigValue(LauncherConVar.CurrentLang)!));
|
||||
LoadLanguage(CultureInfo.GetCultureInfo(ConfigurationService.GetConfigValue(LauncherConVar.CurrentLang)!));
|
||||
}
|
||||
|
||||
public void LoadLanguage(CultureInfo cultureInfo)
|
||||
{
|
||||
_currentCultureInfo = cultureInfo;
|
||||
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)
|
||||
try
|
||||
{
|
||||
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) {
|
||||
LoadLanguage(CultureInfo.GetCultureInfo("en-US"));
|
||||
}
|
||||
}
|
||||
|
||||
private void InitialiseInDesignMode()
|
||||
{
|
||||
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 Nebula.Launcher.ViewModels;
|
||||
using Nebula.Launcher.Views;
|
||||
using Nebula.Shared.ViewHelper;
|
||||
|
||||
namespace Nebula.Launcher;
|
||||
|
||||
|
||||
@@ -10,10 +10,10 @@ using Nebula.Launcher.Services;
|
||||
using Nebula.Launcher.ViewModels.Pages;
|
||||
using Nebula.Launcher.ViewModels.Popup;
|
||||
using Nebula.Launcher.Views;
|
||||
using Nebula.Shared.Models;
|
||||
using Nebula.Shared.Services;
|
||||
using Nebula.Shared.Services.Logging;
|
||||
using Nebula.Shared.Utils;
|
||||
using Nebula.Shared.ViewHelper;
|
||||
|
||||
namespace Nebula.Launcher.ViewModels;
|
||||
|
||||
@@ -23,10 +23,10 @@ public partial class MainViewModel : ViewModelBase
|
||||
{
|
||||
private readonly List<ListItemTemplate> _templates =
|
||||
[
|
||||
new ListItemTemplate(typeof(AccountInfoViewModel), "user", "Account"),
|
||||
new ListItemTemplate(typeof(ServerOverviewModel), "file", "Servers"),
|
||||
new ListItemTemplate(typeof(ContentBrowserViewModel), "folder", "Content"),
|
||||
new ListItemTemplate(typeof(ConfigurationViewModel), "settings", "Settings")
|
||||
new ListItemTemplate(typeof(AccountInfoViewModel), "user", "tab-account"),
|
||||
new ListItemTemplate(typeof(ServerOverviewModel), "file", "tab-servers"),
|
||||
new ListItemTemplate(typeof(ContentBrowserViewModel), "folder", "tab-content"),
|
||||
new ListItemTemplate(typeof(ConfigurationViewModel), "settings", "tab-settings")
|
||||
];
|
||||
|
||||
private readonly List<PopupViewModelBase> _viewQueue = new();
|
||||
@@ -41,11 +41,22 @@ public partial class MainViewModel : ViewModelBase
|
||||
[ObservableProperty] private bool _popup;
|
||||
[ObservableProperty] private ListItemTemplate? _selectedListItem;
|
||||
|
||||
public bool IsLoggedIn => AuthService.SelectedAuth is not null;
|
||||
public string LoginName => AuthService.SelectedAuth?.Login ?? string.Empty;
|
||||
|
||||
public string LoginText => Services.LocalisationService.GetString("auth-current-login-name",
|
||||
new Dictionary<string, object>
|
||||
{
|
||||
{ "login", LoginName }
|
||||
});
|
||||
|
||||
[GenerateProperty] private LocalisationService LocalisationService { get; }
|
||||
[GenerateProperty] private AuthService AuthService { get; }
|
||||
[GenerateProperty] private DebugService DebugService { get; } = default!;
|
||||
[GenerateProperty] private PopupMessageService PopupMessageService { get; } = default!;
|
||||
[GenerateProperty] private ContentService ContentService { get; } = default!;
|
||||
[GenerateProperty, DesignConstruct] private ViewHelperService ViewHelperService { get; } = default!;
|
||||
[GenerateProperty] private FileService FileService { get; } = default!;
|
||||
[GenerateProperty] private ConfigurationService ConfigurationService { get; } = default!;
|
||||
|
||||
private ILogger _logger;
|
||||
|
||||
@@ -53,7 +64,11 @@ public partial class MainViewModel : ViewModelBase
|
||||
|
||||
protected override void InitialiseInDesignMode()
|
||||
{
|
||||
Items = new ObservableCollection<ListItemTemplate>(_templates);
|
||||
Items = new ObservableCollection<ListItemTemplate>(_templates.Select(a=>
|
||||
{
|
||||
return new ListItemTemplate(a.ModelType, a.IconKey, LocalisationService.GetString(a.Label));
|
||||
}
|
||||
));
|
||||
RequirePage<AccountInfoViewModel>();
|
||||
}
|
||||
|
||||
@@ -73,18 +88,28 @@ public partial class MainViewModel : ViewModelBase
|
||||
PopupMessageService.OnCloseRequired += OnPopupCloseRequired;
|
||||
|
||||
CheckMigration();
|
||||
|
||||
if (!VCRuntimeDllChecker.AreVCRuntimeDllsPresent())
|
||||
{
|
||||
OnPopupRequired(LocalisationService.GetString("vcruntime-check-error"));
|
||||
Helper.OpenBrowser("https://learn.microsoft.com/en-us/cpp/windows/latest-supported-vc-redist?view=msvc-170");
|
||||
}
|
||||
}
|
||||
|
||||
private void CheckMigration()
|
||||
{
|
||||
if (!ConfigurationService.GetConfigValue(LauncherConVar.DoMigration))
|
||||
return;
|
||||
|
||||
var loadingHandler = ViewHelperService.GetViewModel<LoadingContextViewModel>();
|
||||
loadingHandler.LoadingName = "Migration task, please wait...";
|
||||
loadingHandler.LoadingName = LocalisationService.GetString("migration-label-task");
|
||||
loadingHandler.IsCancellable = false;
|
||||
|
||||
if (!ContentService.CheckMigration(loadingHandler))
|
||||
return;
|
||||
|
||||
OnPopupRequired(loadingHandler);
|
||||
ConfigurationService.SetConfigValue(LauncherConVar.DoMigration, false);
|
||||
}
|
||||
|
||||
partial void OnSelectedListItemChanged(ListItemTemplate? value)
|
||||
@@ -121,6 +146,12 @@ public partial class MainViewModel : ViewModelBase
|
||||
CurrentPage = obj;
|
||||
}
|
||||
|
||||
public void InvokeChangeAuth()
|
||||
{
|
||||
OnPropertyChanged(nameof(IsLoggedIn));
|
||||
OnPropertyChanged(nameof(LoginText));
|
||||
}
|
||||
|
||||
public void PopupMessage(PopupViewModelBase viewModelBase)
|
||||
{
|
||||
if (CurrentPopup == null)
|
||||
@@ -148,6 +179,11 @@ public partial class MainViewModel : ViewModelBase
|
||||
Popup = true;
|
||||
}
|
||||
|
||||
public void OpenAuthPage()
|
||||
{
|
||||
RequirePage<AccountInfoViewModel>();
|
||||
}
|
||||
|
||||
public void OpenLink()
|
||||
{
|
||||
Helper.OpenBrowser("https://durenko.tatar/nebula");
|
||||
@@ -210,3 +246,28 @@ public partial class MainViewModel : ViewModelBase
|
||||
CurrentPopup = viewModelBase;
|
||||
}
|
||||
}
|
||||
|
||||
public static class VCRuntimeDllChecker
|
||||
{
|
||||
public static bool AreVCRuntimeDllsPresent()
|
||||
{
|
||||
if (!OperatingSystem.IsWindows()) return true;
|
||||
|
||||
string systemDir = Environment.SystemDirectory;
|
||||
string[] requiredDlls = {
|
||||
"msvcp140.dll",
|
||||
"vcruntime140.dll"
|
||||
};
|
||||
|
||||
foreach (var dll in requiredDlls)
|
||||
{
|
||||
var path = Path.Combine(systemDir, dll);
|
||||
if (!File.Exists(path))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -2,18 +2,18 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Input;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using Nebula.Launcher.Models.Auth;
|
||||
using Nebula.Launcher.Services;
|
||||
using Nebula.Launcher.ViewModels.Popup;
|
||||
using Nebula.Launcher.Views.Pages;
|
||||
using Nebula.Shared;
|
||||
using Nebula.Shared.Services;
|
||||
using Nebula.Shared.Services.Logging;
|
||||
using Nebula.Shared.Utils;
|
||||
using Nebula.Shared.ViewHelper;
|
||||
|
||||
namespace Nebula.Launcher.ViewModels.Pages;
|
||||
|
||||
@@ -34,8 +34,10 @@ public partial class AccountInfoViewModel : ViewModelBase
|
||||
[ObservableProperty] private string _currentPassword = string.Empty;
|
||||
|
||||
[ObservableProperty] private bool _isLogged;
|
||||
[ObservableProperty] private bool _doRetryAuth;
|
||||
|
||||
private bool _isProfilesEmpty;
|
||||
[GenerateProperty] private LocalisationService LocalisationService { get; }
|
||||
[GenerateProperty] private PopupMessageService PopupMessageService { get; } = default!;
|
||||
[GenerateProperty] private ConfigurationService ConfigurationService { get; } = default!;
|
||||
[GenerateProperty] private DebugService DebugService { get; }
|
||||
@@ -62,7 +64,7 @@ public partial class AccountInfoViewModel : ViewModelBase
|
||||
protected override void Initialise()
|
||||
{
|
||||
_logger = DebugService.GetLogger(this);
|
||||
ReadAuthConfig();
|
||||
Task.Run(ReadAuthConfig);
|
||||
}
|
||||
|
||||
public void AuthByProfile(ProfileAuthCredentials credentials)
|
||||
@@ -77,7 +79,7 @@ public partial class AccountInfoViewModel : ViewModelBase
|
||||
public void DoAuth(string? code = null)
|
||||
{
|
||||
var message = ViewHelperService.GetViewModel<InfoPopupViewModel>();
|
||||
message.InfoText = "Auth think, please wait...";
|
||||
message.InfoText = LocalisationService.GetString("auth-processing");
|
||||
message.IsInfoClosable = false;
|
||||
PopupMessageService.Popup(message);
|
||||
|
||||
@@ -95,12 +97,14 @@ public partial class AccountInfoViewModel : ViewModelBase
|
||||
{
|
||||
try
|
||||
{
|
||||
await TryAuth(CurrentLogin, CurrentPassword, server,code);
|
||||
await CatchAuthError(async () => await TryAuth(CurrentLogin, CurrentPassword, server, code), ()=> message.Dispose());
|
||||
break;
|
||||
}
|
||||
catch (Exception e)
|
||||
catch (Exception ex)
|
||||
{
|
||||
exception = e;
|
||||
var unexpectedError = new Exception(LocalisationService.GetString("auth-error"), ex);
|
||||
_logger.Error(unexpectedError);
|
||||
PopupMessageService.Popup(unexpectedError);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -108,24 +112,41 @@ public partial class AccountInfoViewModel : ViewModelBase
|
||||
|
||||
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(string login, string password, string authServer,string? code)
|
||||
private async Task TryAuth(CurrentAuthInfo currentAuthInfo)
|
||||
{
|
||||
CurrentLogin = currentAuthInfo.Login;
|
||||
CurrentAuthServer = currentAuthInfo.AuthServer;
|
||||
await AuthService.SetAuth(currentAuthInfo);
|
||||
IsLogged = true;
|
||||
}
|
||||
|
||||
private async Task TryAuth(string login, string password, string authServer, string? code)
|
||||
{
|
||||
await AuthService.Auth(new AuthLoginPassword(login, password, authServer), code);
|
||||
CurrentLogin = login;
|
||||
CurrentPassword = password;
|
||||
CurrentAuthServer = authServer;
|
||||
IsLogged = true;
|
||||
ConfigurationService.SetConfigValue(LauncherConVar.AuthCurrent, AuthService.SelectedAuth);
|
||||
}
|
||||
|
||||
private async Task CatchAuthError(Func<Task> a, Action? onError)
|
||||
{
|
||||
DoRetryAuth = false;
|
||||
|
||||
try
|
||||
{
|
||||
await AuthService.Auth(new AuthLoginPassword(login, password, authServer), code);
|
||||
CurrentLogin = login;
|
||||
CurrentPassword = password;
|
||||
CurrentAuthServer = authServer;
|
||||
IsLogged = true;
|
||||
ConfigurationService.SetConfigValue(LauncherConVar.AuthCurrent, AuthService.SelectedAuth);
|
||||
await a();
|
||||
ViewHelperService.GetViewModel<MainViewModel>().InvokeChangeAuth();
|
||||
}
|
||||
catch (AuthException e)
|
||||
{
|
||||
onError?.Invoke();
|
||||
switch (e.Error.Code)
|
||||
{
|
||||
case AuthenticateDenyCode.TfaRequired:
|
||||
@@ -136,13 +157,39 @@ public partial class AccountInfoViewModel : ViewModelBase
|
||||
_logger.Log("TFA required");
|
||||
break;
|
||||
case AuthenticateDenyCode.InvalidCredentials:
|
||||
PopupMessageService.Popup("Invalid Credentials!");
|
||||
_logger.Error($"Invalid credentials");
|
||||
PopupError(LocalisationService.GetString("auth-invalid-credentials"), e);
|
||||
break;
|
||||
default:
|
||||
throw;
|
||||
}
|
||||
}
|
||||
catch (HttpRequestException e)
|
||||
{
|
||||
onError?.Invoke();
|
||||
switch (e.HttpRequestError)
|
||||
{
|
||||
case HttpRequestError.ConnectionError:
|
||||
PopupError(LocalisationService.GetString("auth-connection-error"), e);
|
||||
DoRetryAuth = true;
|
||||
break;
|
||||
|
||||
case HttpRequestError.NameResolutionError:
|
||||
PopupError(LocalisationService.GetString("auth-name-resolution-error"), e);
|
||||
DoRetryAuth = true;
|
||||
break;
|
||||
|
||||
case HttpRequestError.SecureConnectionError:
|
||||
PopupError(LocalisationService.GetString("auth-secure-error"), e);
|
||||
DoRetryAuth = true;
|
||||
break;
|
||||
|
||||
default:
|
||||
var authError = new Exception(LocalisationService.GetString("auth-error"), e);
|
||||
_logger.Error(authError);
|
||||
PopupMessageService.Popup(authError);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnTfaEntered(string code)
|
||||
@@ -154,6 +201,7 @@ public partial class AccountInfoViewModel : ViewModelBase
|
||||
{
|
||||
IsLogged = false;
|
||||
AuthService.ClearAuth();
|
||||
ViewHelperService.GetViewModel<MainViewModel>().InvokeChangeAuth();
|
||||
}
|
||||
|
||||
private void UpdateAuthMenu()
|
||||
@@ -182,10 +230,10 @@ public partial class AccountInfoViewModel : ViewModelBase
|
||||
Accounts.Add(alpm);
|
||||
}
|
||||
|
||||
private async void ReadAuthConfig()
|
||||
private void ReadAuthConfig()
|
||||
{
|
||||
var message = ViewHelperService.GetViewModel<InfoPopupViewModel>();
|
||||
message.InfoText = "Read configuration file, please wait...";
|
||||
message.InfoText = LocalisationService.GetString("auth-config-read");
|
||||
message.IsInfoClosable = false;
|
||||
PopupMessageService.Popup(message);
|
||||
foreach (var profile in
|
||||
@@ -198,6 +246,17 @@ public partial class AccountInfoViewModel : ViewModelBase
|
||||
var authUrls = ConfigurationService.GetConfigValue(LauncherConVar.AuthServers)!;
|
||||
foreach (var url in authUrls) AuthUrls.Add(url);
|
||||
if(authUrls.Length > 0) AuthItemSelect = authUrls[0];
|
||||
message.Dispose();
|
||||
|
||||
DoCurrentAuth();
|
||||
}
|
||||
|
||||
public async void DoCurrentAuth()
|
||||
{
|
||||
var message = ViewHelperService.GetViewModel<InfoPopupViewModel>();
|
||||
message.InfoText = LocalisationService.GetString("auth-try-auth-config");
|
||||
message.IsInfoClosable = false;
|
||||
PopupMessageService.Popup(message);
|
||||
|
||||
var currProfile = ConfigurationService.GetConfigValue(LauncherConVar.AuthCurrent);
|
||||
|
||||
@@ -205,15 +264,14 @@ public partial class AccountInfoViewModel : ViewModelBase
|
||||
{
|
||||
try
|
||||
{
|
||||
CurrentLogin = currProfile.Login;
|
||||
CurrentAuthServer = currProfile.AuthServer;
|
||||
|
||||
IsLogged = await AuthService.SetAuth(currProfile);
|
||||
await CatchAuthError(async () => await TryAuth(currProfile), () => message.Dispose());
|
||||
}
|
||||
catch (Exception e)
|
||||
catch (Exception ex)
|
||||
{
|
||||
message.Dispose();
|
||||
PopupMessageService.Popup(e);
|
||||
var unexpectedError = new Exception(LocalisationService.GetString("auth-error"), ex);
|
||||
_logger.Error(unexpectedError);
|
||||
PopupMessageService.Popup(unexpectedError);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -237,6 +295,17 @@ public partial class AccountInfoViewModel : ViewModelBase
|
||||
DirtyProfile();
|
||||
}
|
||||
|
||||
private void PopupError(string message, Exception e)
|
||||
{
|
||||
message = LocalisationService.GetString("auth-error-occured") + message;
|
||||
_logger.Error(new Exception(message, e));
|
||||
|
||||
var messageView = ViewHelperService.GetViewModel<InfoPopupViewModel>();
|
||||
messageView.InfoText = message;
|
||||
messageView.IsInfoClosable = true;
|
||||
PopupMessageService.Popup(messageView);
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void OnExpandAuthUrl()
|
||||
{
|
||||
@@ -256,16 +325,3 @@ public partial class AccountInfoViewModel : ViewModelBase
|
||||
Accounts.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
|
||||
);
|
||||
@@ -1,142 +1,406 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.ComponentModel;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Nebula.Launcher.Views.Config;
|
||||
using System.Reflection;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Layout;
|
||||
using Nebula.Launcher.Services;
|
||||
using Nebula.Launcher.ViewModels.Popup;
|
||||
using Nebula.Launcher.Views.Pages;
|
||||
using Nebula.Shared;
|
||||
using Nebula.Shared.Services;
|
||||
using BindingFlags = System.Reflection.BindingFlags;
|
||||
using Nebula.Shared.ViewHelper;
|
||||
|
||||
namespace Nebula.Launcher.ViewModels.Pages;
|
||||
|
||||
[ViewModelRegister(typeof(ConfigurationView))]
|
||||
[ConstructGenerator]
|
||||
public partial class ConfigurationViewModel : ViewModelBase, IConfigContext
|
||||
public partial class ConfigurationViewModel : ViewModelBase
|
||||
{
|
||||
public ObservableCollection<ViewModelBase> ConfigurationVerbose { get; } = new();
|
||||
public ObservableCollection<IConfigControl> ConfigurationVerbose { get; } = new();
|
||||
|
||||
[GenerateProperty] private ConfigurationService ConfigurationService { get; } = default!;
|
||||
[GenerateProperty] private IServiceProvider ServiceProvider { get; } = default!;
|
||||
[GenerateProperty] private PopupMessageService PopupService { get; } = default!;
|
||||
[GenerateProperty] private FileService FileService { get; set; } = default!;
|
||||
[GenerateProperty] private ContentService ContentService { get; set; } = default!;
|
||||
[GenerateProperty] private CancellationService CancellationService { get; set; } = default!;
|
||||
[GenerateProperty] private ViewHelperService ViewHelperService { get; set; } = default!;
|
||||
|
||||
|
||||
public void AddConfiguration<T,T1>(ConVar<T> convar) where T1: ViewModelBase, IConfigurationVerbose<T>
|
||||
private readonly List<(object, Type)> _conVarList = new();
|
||||
|
||||
public void AddCvarConf<T>(ConVar<T> cvar)
|
||||
{
|
||||
var configurationVerbose = ServiceProvider.GetService<T1>()!;
|
||||
configurationVerbose.Context = new ConfigContext<T>(convar, this);
|
||||
configurationVerbose.InitializeConfig();
|
||||
ConfigurationVerbose.Add(configurationVerbose);
|
||||
ConfigurationVerbose.Add(
|
||||
ConfigControlHelper.GetConfigControl(cvar.Name, ConfigurationService.GetConfigValue(cvar)!));
|
||||
_conVarList.Add((cvar, cvar.Type));
|
||||
}
|
||||
|
||||
public void InvokeUpdateConfiguration()
|
||||
{
|
||||
foreach (var verbose in ConfigurationVerbose)
|
||||
for (int i = 0; i < ConfigurationVerbose.Count; i++)
|
||||
{
|
||||
if(verbose is not IUpdateInvoker invoker) continue;
|
||||
invoker.UpdateConfiguration();
|
||||
var conVarControl = ConfigurationVerbose[i];
|
||||
if(!conVarControl.Dirty)
|
||||
continue;
|
||||
|
||||
var conVar = _conVarList[i];
|
||||
var methodInfo = ConfigurationService.GetType().GetMethod("SetConfigValue")!.MakeGenericMethod(conVar.Item2);
|
||||
methodInfo.Invoke(ConfigurationService, [conVar.Item1, conVarControl.GetValue()]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected override void InitialiseInDesignMode()
|
||||
public void ResetConfig()
|
||||
{
|
||||
AddConfiguration<string, StringConfigurationViewModel>(LauncherConVar.ILSpyUrl);
|
||||
foreach (var conVar in _conVarList)
|
||||
{
|
||||
var methodInfo = ConfigurationService.GetType().GetMethod("SetConfigValue")!.MakeGenericMethod(conVar.Item2);
|
||||
methodInfo.Invoke(ConfigurationService, [conVar.Item1, null]);
|
||||
}
|
||||
|
||||
_conVarList.Clear();
|
||||
ConfigurationVerbose.Clear();
|
||||
|
||||
InitConfiguration();
|
||||
|
||||
PopupService.Popup("Configuration has been reset.");
|
||||
}
|
||||
|
||||
protected override void Initialise()
|
||||
public void OpenDataFolder()
|
||||
{
|
||||
InitialiseInDesignMode();
|
||||
ExplorerHelper.OpenFolder(FileService.RootPath);
|
||||
}
|
||||
|
||||
public void SetValue<T>(ConVar<T> conVar, T value)
|
||||
public void ExportLogs()
|
||||
{
|
||||
ConfigurationService.SetConfigValue(conVar, value);
|
||||
var logPath = Path.Join(FileService.RootPath, "log");
|
||||
var path = Path.Combine(Path.GetTempPath(), "tempThink"+Path.GetRandomFileName());
|
||||
Directory.CreateDirectory(path);
|
||||
|
||||
ZipFile.CreateFromDirectory(logPath, Path.Join(path, DateTime.Now.ToString("yyyy-MM-dd") + ".zip"));
|
||||
ExplorerHelper.OpenFolder(path);
|
||||
}
|
||||
|
||||
public T? GetValue<T>(ConVar<T> convar)
|
||||
public void RemoveAllContent()
|
||||
{
|
||||
return ConfigurationService.GetConfigValue<T>(convar);
|
||||
}
|
||||
}
|
||||
|
||||
public interface IConfigContext
|
||||
{
|
||||
public void SetValue<T>(ConVar<T> conVar, T value);
|
||||
public T? GetValue<T>(ConVar<T> convar);
|
||||
}
|
||||
|
||||
public class ConfigContext<T> : IConfigContext
|
||||
{
|
||||
public ConfigContext(ConVar<T> conVar, IConfigContext parent)
|
||||
{
|
||||
ConVar = conVar;
|
||||
Parent = parent;
|
||||
Task.Run(() =>
|
||||
{
|
||||
using var loader = ViewHelperService.GetViewModel<LoadingContextViewModel>();
|
||||
loader.LoadingName = "Removing content";
|
||||
PopupService.Popup(loader);
|
||||
ContentService.RemoveAllContent(loader, CancellationService.Token);
|
||||
});
|
||||
}
|
||||
|
||||
public ConVar<T> ConVar { get; }
|
||||
public IConfigContext Parent { get; }
|
||||
|
||||
public T? GetValue()
|
||||
private void InitConfiguration()
|
||||
{
|
||||
return GetValue(ConVar);
|
||||
}
|
||||
|
||||
public void SetValue(T? value)
|
||||
{
|
||||
SetValue(ConVar!, value);
|
||||
}
|
||||
|
||||
public void SetValue<T1>(ConVar<T1> conVar, T1 value)
|
||||
{
|
||||
Parent.SetValue(conVar, value);
|
||||
}
|
||||
|
||||
public T1? GetValue<T1>(ConVar<T1> convar)
|
||||
{
|
||||
return Parent.GetValue(convar);
|
||||
}
|
||||
}
|
||||
|
||||
public interface IConfigurationVerbose<T>
|
||||
{
|
||||
public ConfigContext<T> Context { get; set; }
|
||||
public void InitializeConfig();
|
||||
}
|
||||
|
||||
public interface IUpdateInvoker
|
||||
{
|
||||
public void UpdateConfiguration();
|
||||
}
|
||||
|
||||
[ViewModelRegister(typeof(StringConfigurationView))]
|
||||
public partial class StringConfigurationViewModel : ViewModelBase , IConfigurationVerbose<string>, IUpdateInvoker
|
||||
{
|
||||
[ObservableProperty] private string _configText = string.Empty;
|
||||
[ObservableProperty] private string? _configName = string.Empty;
|
||||
|
||||
private string _oldText = string.Empty;
|
||||
|
||||
public required ConfigContext<string> Context { get; set; }
|
||||
public void InitializeConfig()
|
||||
{
|
||||
ConfigName = Context.ConVar.Name;
|
||||
_oldText = Context.GetValue() ?? string.Empty;
|
||||
ConfigText = _oldText;
|
||||
}
|
||||
public void UpdateConfiguration()
|
||||
{
|
||||
if (_oldText == ConfigText) return;
|
||||
Context.SetValue(ConfigText);
|
||||
AddCvarConf(LauncherConVar.ILSpyUrl);
|
||||
AddCvarConf(LauncherConVar.Hub);
|
||||
AddCvarConf(LauncherConVar.AuthServers);
|
||||
AddCvarConf(CurrentConVar.EngineManifestUrl);
|
||||
AddCvarConf(CurrentConVar.RobustAssemblyName);
|
||||
AddCvarConf(CurrentConVar.ManifestDownloadProtocolVersion);
|
||||
}
|
||||
|
||||
protected override void InitialiseInDesignMode()
|
||||
{
|
||||
InitConfiguration();
|
||||
}
|
||||
|
||||
protected override void Initialise()
|
||||
{
|
||||
InitConfiguration();
|
||||
}
|
||||
}
|
||||
|
||||
public static class ConfigControlHelper{
|
||||
public static IConfigControl GetConfigControl(string name,object value)
|
||||
{
|
||||
switch (value)
|
||||
{
|
||||
case string stringValue:
|
||||
return new StringUnitConfigControl(name, stringValue);
|
||||
case int intValue:
|
||||
return new IntUnitConfigControl(name, intValue);
|
||||
case float floatValue:
|
||||
return new FloatUnitConfigControl(name, floatValue);
|
||||
}
|
||||
|
||||
var valueType = value.GetType();
|
||||
|
||||
if (valueType.IsArray)
|
||||
return new ArrayUnitConfigControl(name, value);
|
||||
|
||||
return new ComplexUnitConfigControl(name, value);
|
||||
}
|
||||
|
||||
public static object? CreateDefaultValue(Type type)
|
||||
{
|
||||
if(type.IsValueType)
|
||||
return Activator.CreateInstance(type);
|
||||
|
||||
var ctor = type.GetConstructors().First();
|
||||
var parameters = ctor.GetParameters()
|
||||
.Select(p => CreateDefaultValue(p.ParameterType))
|
||||
.ToArray();
|
||||
|
||||
return ctor.Invoke(parameters);
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class ComplexUnitConfigControl : Border, IConfigControl
|
||||
{
|
||||
private readonly List<(PropertyInfo, IConfigControl)> _units = [];
|
||||
|
||||
private Type _objectType = typeof(object);
|
||||
|
||||
private readonly StackPanel _panel = new();
|
||||
|
||||
public string ConfigName { get; }
|
||||
public bool Dirty => _units.Any(dirty => dirty.Item2.Dirty);
|
||||
|
||||
public ComplexUnitConfigControl(string name, object obj)
|
||||
{
|
||||
Classes.Add("ConfigBorder");
|
||||
_panel.Orientation = Orientation.Vertical;
|
||||
_panel.Spacing = 4f;
|
||||
ConfigName = name;
|
||||
Child = _panel;
|
||||
SetValue(obj);
|
||||
}
|
||||
|
||||
public void SetValue(object value)
|
||||
{
|
||||
_units.Clear();
|
||||
_panel.Children.Clear();
|
||||
_objectType = value.GetType();
|
||||
|
||||
_panel.Children.Add(new Label()
|
||||
{
|
||||
Content = ConfigName
|
||||
});
|
||||
|
||||
foreach (var propInfo in _objectType.GetProperties())
|
||||
{
|
||||
if(propInfo.PropertyType.IsInterface)
|
||||
continue;
|
||||
|
||||
var propValue = propInfo.GetValue(value);
|
||||
|
||||
var control = ConfigControlHelper.GetConfigControl(propInfo.Name, propValue);
|
||||
|
||||
((Control)control).Margin = new Thickness(5);
|
||||
_panel.Children.Add((Control)control);
|
||||
_units.Add((propInfo,control));
|
||||
}
|
||||
}
|
||||
|
||||
public object GetValue()
|
||||
{
|
||||
var obj = ConfigControlHelper.CreateDefaultValue(_objectType);
|
||||
foreach (var (fieldInfo, configControl) in _units)
|
||||
{
|
||||
fieldInfo.SetValue(obj, configControl.GetValue());
|
||||
}
|
||||
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class ArrayUnitConfigControl : Border, IConfigControl
|
||||
{
|
||||
private readonly List<IConfigControl> _itemControls = [];
|
||||
private readonly StackPanel _itemsPanel = new StackPanel() { Orientation = Orientation.Vertical };
|
||||
private readonly Button _addButton = new Button() { Content = new Label()
|
||||
{
|
||||
Content = "Add Item"
|
||||
}, Classes = { "ConfigBorder" }};
|
||||
private readonly int _oldCount;
|
||||
private readonly Type _elementType;
|
||||
private readonly StackPanel _panel = new();
|
||||
|
||||
public string ConfigName { get; }
|
||||
public bool Dirty => _itemControls.Any(dirty => dirty.Dirty) || _itemControls.Count != _oldCount;
|
||||
|
||||
public ArrayUnitConfigControl(string name, object value)
|
||||
{
|
||||
Classes.Add("ConfigBorder");
|
||||
_elementType = value.GetType().GetElementType()!;
|
||||
|
||||
ConfigName = name;
|
||||
_panel.Orientation = Orientation.Vertical;
|
||||
_panel.Spacing = 4f;
|
||||
_itemsPanel.Spacing = 4f;
|
||||
|
||||
_panel.Children.Add(new Label { Content = name });
|
||||
_panel.Children.Add(_itemsPanel);
|
||||
_panel.Children.Add(_addButton);
|
||||
|
||||
_addButton.Click += (_, _) => AddItem(ConfigControlHelper.CreateDefaultValue(_elementType)!);
|
||||
Child = _panel;
|
||||
SetValue(value);
|
||||
_oldCount = _itemControls.Count;
|
||||
}
|
||||
|
||||
private void AddItem(object value)
|
||||
{
|
||||
var itemPanel = new StackPanel { Orientation = Orientation.Horizontal, Spacing = 2 };
|
||||
var control = ConfigControlHelper.GetConfigControl(_itemControls.Count.ToString(), value);
|
||||
var removeButton = new Button { Content = new Label(){ Content = "Remove" }, Classes = { "ConfigBorder" }};
|
||||
|
||||
removeButton.Click += (_, _) =>
|
||||
{
|
||||
_itemControls.Remove(control);
|
||||
_itemsPanel.Children.Remove(itemPanel);
|
||||
};
|
||||
|
||||
((Control)control).Margin = new Thickness(5);
|
||||
itemPanel.Children.Add((Control)control);
|
||||
itemPanel.Children.Add(removeButton);
|
||||
|
||||
_itemsPanel.Children.Add(itemPanel);
|
||||
_itemControls.Add(control);
|
||||
}
|
||||
|
||||
public void SetValue(object value)
|
||||
{
|
||||
_itemControls.Clear();
|
||||
_itemsPanel.Children.Clear();
|
||||
|
||||
if (value is IEnumerable list)
|
||||
{
|
||||
foreach (var item in list)
|
||||
{
|
||||
AddItem(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public object GetValue()
|
||||
{
|
||||
return ConvertArray(_itemControls.Select(c => c.GetValue()).ToArray(), _elementType);
|
||||
}
|
||||
|
||||
public static Array ConvertArray(Array sourceArray, Type targetType)
|
||||
{
|
||||
int length = sourceArray.Length;
|
||||
var newArray = Array.CreateInstance(targetType, length);
|
||||
|
||||
for (int i = 0; i < length; i++)
|
||||
{
|
||||
var value = sourceArray.GetValue(i);
|
||||
var converted = Convert.ChangeType(value, targetType);
|
||||
newArray.SetValue(converted, i);
|
||||
}
|
||||
|
||||
return newArray;
|
||||
}
|
||||
}
|
||||
|
||||
public abstract class UnitConfigControl<T> : Border, IConfigControl where T : notnull
|
||||
{
|
||||
private readonly Label _nameLabel = new();
|
||||
private readonly TextBox _valueLabel = new();
|
||||
private string _originalValue;
|
||||
|
||||
private StackPanel _panel = new();
|
||||
|
||||
public string ConfigName { get; }
|
||||
|
||||
public bool Dirty => _originalValue != ConfigValue;
|
||||
|
||||
protected string ConfigValue
|
||||
{
|
||||
get => _valueLabel.Text ?? string.Empty;
|
||||
set => _valueLabel.Text = value;
|
||||
}
|
||||
|
||||
public UnitConfigControl(string name, T value)
|
||||
{
|
||||
Classes.Add("ConfigBorder");
|
||||
ConfigName = name;
|
||||
_panel.Orientation = Orientation.Horizontal;
|
||||
_panel.Children.Add(_nameLabel);
|
||||
_panel.Children.Add(_valueLabel);
|
||||
|
||||
_nameLabel.Content = name;
|
||||
_nameLabel.VerticalAlignment = VerticalAlignment.Center;
|
||||
Child = _panel;
|
||||
|
||||
SetConfValue(value);
|
||||
_originalValue = ConfigValue;
|
||||
}
|
||||
|
||||
public abstract void SetConfValue(T value);
|
||||
|
||||
public abstract T GetConfValue();
|
||||
|
||||
public void SetValue(object value)
|
||||
{
|
||||
SetConfValue((T)value);
|
||||
}
|
||||
|
||||
public object GetValue()
|
||||
{
|
||||
return GetConfValue()!;
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class StringUnitConfigControl(string name, string value) : UnitConfigControl<string>(name, value)
|
||||
{
|
||||
public override void SetConfValue(string value)
|
||||
{
|
||||
ConfigValue = value;
|
||||
}
|
||||
|
||||
public override string GetConfValue()
|
||||
{
|
||||
return ConfigValue;
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class IntUnitConfigControl(string name, int value) : UnitConfigControl<int>(name, value)
|
||||
{
|
||||
public override void SetConfValue(int value)
|
||||
{
|
||||
ConfigValue = value.ToString();
|
||||
}
|
||||
|
||||
public override int GetConfValue()
|
||||
{
|
||||
return int.Parse(ConfigValue);
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class FloatUnitConfigControl(string name, float value) : UnitConfigControl<float>(name, value)
|
||||
{
|
||||
|
||||
public CultureInfo CultureInfo = CultureInfo.InvariantCulture;
|
||||
|
||||
public override void SetConfValue(float value)
|
||||
{
|
||||
ConfigValue = value.ToString(CultureInfo);
|
||||
}
|
||||
|
||||
public override float GetConfValue()
|
||||
{
|
||||
return float.Parse(ConfigValue, CultureInfo);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public interface IConfigControl
|
||||
{
|
||||
public string ConfigName { get; }
|
||||
public bool Dirty {get;}
|
||||
public abstract void SetValue(object value);
|
||||
public abstract object GetValue();
|
||||
}
|
||||
@@ -18,6 +18,7 @@ using Nebula.Shared.FileApis;
|
||||
using Nebula.Shared.Models;
|
||||
using Nebula.Shared.Services;
|
||||
using Nebula.Shared.Utils;
|
||||
using Nebula.Shared.ViewHelper;
|
||||
|
||||
namespace Nebula.Launcher.ViewModels.Pages;
|
||||
|
||||
@@ -29,9 +30,7 @@ public sealed partial class ContentBrowserViewModel : ViewModelBase, IContentHol
|
||||
[ObservableProperty] private string _serverText = "";
|
||||
[ObservableProperty] private string _searchText = "";
|
||||
[GenerateProperty] private ContentService ContentService { get; } = default!;
|
||||
[GenerateProperty] private CancellationService CancellationService { get; } = default!;
|
||||
[GenerateProperty] private FileService FileService { get; } = default!;
|
||||
[GenerateProperty] private DebugService DebugService { get; } = default!;
|
||||
[GenerateProperty] private PopupMessageService PopupService { get; } = default!;
|
||||
[GenerateProperty] private IServiceProvider ServiceProvider { get; }
|
||||
[GenerateProperty, DesignConstruct] private ViewHelperService ViewHelperService { get; } = default!;
|
||||
@@ -59,12 +58,7 @@ public sealed partial class ContentBrowserViewModel : ViewModelBase, IContentHol
|
||||
PopupService.Popup(loading);
|
||||
|
||||
Task.Run(() => ContentService.Unpack(serverEntry.FileApi, myTempDir, loading));
|
||||
var startInfo = new ProcessStartInfo(){
|
||||
FileName = "explorer.exe",
|
||||
Arguments = tmpDir,
|
||||
};
|
||||
|
||||
Process.Start(startInfo);
|
||||
ExplorerHelper.OpenFolder(tmpDir);
|
||||
}
|
||||
|
||||
public void OnGoEnter()
|
||||
|
||||
@@ -2,7 +2,9 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using JetBrains.Annotations;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Nebula.Launcher.Controls;
|
||||
using Nebula.Launcher.Models;
|
||||
@@ -12,6 +14,7 @@ using Nebula.Launcher.Views.Pages;
|
||||
using Nebula.Shared;
|
||||
using Nebula.Shared.Models;
|
||||
using Nebula.Shared.Services;
|
||||
using Nebula.Shared.ViewHelper;
|
||||
|
||||
namespace Nebula.Launcher.ViewModels.Pages;
|
||||
|
||||
@@ -23,24 +26,17 @@ public partial class ServerOverviewModel : ViewModelBase
|
||||
|
||||
[ObservableProperty] private bool _isFilterVisible;
|
||||
|
||||
[ObservableProperty] private ServerListView _currentServerList = new ServerListView();
|
||||
[ObservableProperty] private ServerListView _currentServerList = new();
|
||||
|
||||
public readonly ServerFilter CurrentFilter = new ServerFilter();
|
||||
public readonly ServerFilter CurrentFilter = new();
|
||||
|
||||
public Action? OnSearchChange;
|
||||
|
||||
[GenerateProperty] private PopupMessageService PopupMessageService { get; }
|
||||
[GenerateProperty] private CancellationService CancellationService { get; }
|
||||
[GenerateProperty] private DebugService DebugService { get; }
|
||||
[GenerateProperty] private IServiceProvider ServiceProvider { get; }
|
||||
[GenerateProperty] private ConfigurationService ConfigurationService { get; }
|
||||
[GenerateProperty] private FavoriteServerListProvider FavoriteServerListProvider { get; }
|
||||
[GenerateProperty, DesignConstruct] private ViewHelperService ViewHelperService { get; }
|
||||
|
||||
public ObservableCollection<ServerListTabTemplate> Items { get; private set; }
|
||||
[ObservableProperty] private ServerListTabTemplate _selectedItem;
|
||||
|
||||
[GenerateProperty, DesignConstruct] private ServerViewContainer ServerViewContainer { get; set; }
|
||||
[GenerateProperty, DesignConstruct] private ServerViewContainer ServerViewContainer { get; }
|
||||
|
||||
private Dictionary<string, ServerListView> _viewCache = [];
|
||||
|
||||
@@ -57,9 +53,15 @@ public partial class ServerOverviewModel : ViewModelBase
|
||||
|
||||
//real think
|
||||
protected override void Initialise()
|
||||
{
|
||||
ConfigurationService.SubscribeVarChanged(LauncherConVar.Hub, OnHubListChanged, true);
|
||||
}
|
||||
|
||||
private void OnHubListChanged(ServerHubRecord[]? value)
|
||||
{
|
||||
var tempItems = new List<ServerListTabTemplate>();
|
||||
foreach (var record in ConfigurationService.GetConfigValue(LauncherConVar.Hub) ?? [])
|
||||
|
||||
foreach (var record in value ?? [])
|
||||
{
|
||||
tempItems.Add(new ServerListTabTemplate(ServiceProvider.GetService<HubServerListProvider>()!.With(record.MainUrl), record.Name));
|
||||
}
|
||||
@@ -71,11 +73,18 @@ public partial class ServerOverviewModel : ViewModelBase
|
||||
SelectedItem = Items[0];
|
||||
}
|
||||
|
||||
partial void OnSearchTextChanged(string value)
|
||||
{
|
||||
CurrentFilter.SearchText = value;
|
||||
ApplyFilter();
|
||||
}
|
||||
|
||||
public void ApplyFilter()
|
||||
{
|
||||
foreach (var entry in ServerViewContainer.Items)
|
||||
{
|
||||
entry.ProcessFilter(CurrentFilter);
|
||||
if(entry is IFilterConsumer filterConsumer)
|
||||
filterConsumer.ProcessFilter(CurrentFilter);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,7 +104,10 @@ public partial class ServerOverviewModel : ViewModelBase
|
||||
|
||||
public void UpdateRequired()
|
||||
{
|
||||
ServerViewContainer.Clear();
|
||||
CurrentServerList.RefreshFromProvider();
|
||||
CurrentServerList.RequireStatusUpdate();
|
||||
CurrentServerList.ApplyFilter(CurrentFilter);
|
||||
}
|
||||
|
||||
partial void OnSelectedItemChanged(ServerListTabTemplate value)
|
||||
@@ -107,6 +119,7 @@ public partial class ServerOverviewModel : ViewModelBase
|
||||
}
|
||||
|
||||
CurrentServerList = view;
|
||||
ApplyFilter();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -115,38 +128,114 @@ public partial class ServerOverviewModel : ViewModelBase
|
||||
public class ServerViewContainer
|
||||
{
|
||||
private readonly ViewHelperService _viewHelperService;
|
||||
private readonly List<string> _favorites = [];
|
||||
private readonly Dictionary<string, string> _customNames = [];
|
||||
|
||||
public ServerViewContainer()
|
||||
{
|
||||
_viewHelperService = new ViewHelperService();
|
||||
}
|
||||
|
||||
public ServerViewContainer(ViewHelperService viewHelperService)
|
||||
[UsedImplicitly]
|
||||
public ServerViewContainer(ViewHelperService viewHelperService, ConfigurationService configurationService)
|
||||
{
|
||||
_viewHelperService = viewHelperService;
|
||||
configurationService.SubscribeVarChanged(LauncherConVar.Favorites, OnFavoritesChange, true);
|
||||
configurationService.SubscribeVarChanged(LauncherConVar.ServerCustomNames, OnCustomNamesChanged, true);
|
||||
}
|
||||
|
||||
private readonly Dictionary<string, ServerEntryModelView> _entries = new();
|
||||
private void OnCustomNamesChanged(Dictionary<string,string>? value)
|
||||
{
|
||||
var oldNames =
|
||||
_customNames.ToDictionary(k => k.Key, v => v.Value); //Clone think
|
||||
|
||||
public ICollection<ServerEntryModelView> Items => _entries.Values;
|
||||
_customNames.Clear();
|
||||
|
||||
if(value == null)
|
||||
{
|
||||
foreach (var (ip,_) in oldNames)
|
||||
{
|
||||
if(!_entries.TryGetValue(ip, out var listEntry) || listEntry is not IEntryNameHolder entryNameHolder)
|
||||
continue;
|
||||
|
||||
entryNameHolder.Name = null;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var (oldIp, oldName) in oldNames)
|
||||
{
|
||||
if(value.TryGetValue(oldIp, out var newName))
|
||||
{
|
||||
if (oldName == newName)
|
||||
value.Remove(newName);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if(!_entries.TryGetValue(oldIp, out var listEntry) ||
|
||||
listEntry is not IEntryNameHolder entryNameHolder)
|
||||
continue;
|
||||
|
||||
entryNameHolder.Name = null;
|
||||
}
|
||||
|
||||
foreach (var (ip, name) in value)
|
||||
{
|
||||
_customNames.Add(ip, name);
|
||||
if(!_entries.TryGetValue(ip, out var listEntry) || listEntry is not IEntryNameHolder entryNameHolder)
|
||||
continue;
|
||||
|
||||
entryNameHolder.Name = name;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnFavoritesChange(string[]? value)
|
||||
{
|
||||
_favorites.Clear();
|
||||
if(value == null) return;
|
||||
|
||||
foreach (var favorite in value)
|
||||
{
|
||||
_favorites.Add(favorite);
|
||||
if (_entries.TryGetValue(favorite, out var entry) && entry is IFavoriteEntryModelView favoriteView)
|
||||
{
|
||||
favoriteView.IsFavorite = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private readonly Dictionary<string, IListEntryModelView> _entries = new();
|
||||
|
||||
public ICollection<IListEntryModelView> Items => _entries.Values;
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
_entries.Clear();
|
||||
}
|
||||
|
||||
public ServerEntryModelView Get(RobustUrl url, ServerStatus? serverStatus = null)
|
||||
public IListEntryModelView Get(RobustUrl url, ServerStatus? serverStatus = null)
|
||||
{
|
||||
ServerEntryModelView? entry;
|
||||
IListEntryModelView? entry;
|
||||
|
||||
lock (_entries)
|
||||
{
|
||||
_customNames.TryGetValue(url.ToString(), out var customName);
|
||||
|
||||
if (_entries.TryGetValue(url.ToString(), out entry))
|
||||
{
|
||||
return entry;
|
||||
}
|
||||
|
||||
entry = _viewHelperService.GetViewModel<ServerEntryModelView>().WithData(url, serverStatus);
|
||||
if (serverStatus is not null)
|
||||
entry = _viewHelperService.GetViewModel<ServerEntryModelView>().WithData(url, customName, serverStatus);
|
||||
else
|
||||
entry = _viewHelperService.GetViewModel<ServerCompoundEntryViewModel>().LoadServerEntry(url, customName, CancellationToken.None);
|
||||
|
||||
if(_favorites.Contains(url.ToString()) &&
|
||||
entry is IFavoriteEntryModelView favoriteEntryModelView)
|
||||
favoriteEntryModelView.IsFavorite = true;
|
||||
|
||||
_entries.Add(url.ToString(), entry);
|
||||
}
|
||||
@@ -155,6 +244,21 @@ public class ServerViewContainer
|
||||
}
|
||||
}
|
||||
|
||||
public interface IListEntryModelView
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public interface IFavoriteEntryModelView
|
||||
{
|
||||
public bool IsFavorite { get; set; }
|
||||
}
|
||||
|
||||
public interface IEntryNameHolder
|
||||
{
|
||||
public string? Name { get; set; }
|
||||
}
|
||||
|
||||
public class ServerComparer : IComparer<ServerHubInfo>, IComparer<ServerStatus>, IComparer<(RobustUrl,ServerStatus)>
|
||||
{
|
||||
public int Compare(ServerHubInfo? x, ServerHubInfo? y)
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
using System;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using Nebula.Launcher.ServerListProviders;
|
||||
using Nebula.Launcher.Services;
|
||||
using Nebula.Launcher.ViewModels.Pages;
|
||||
using Nebula.Launcher.Views.Pages;
|
||||
using Nebula.Shared.Services;
|
||||
using Nebula.Shared.Services.Logging;
|
||||
using Nebula.Shared.Utils;
|
||||
using Nebula.Shared.ViewHelper;
|
||||
using AddFavoriteView = Nebula.Launcher.Views.Popup.AddFavoriteView;
|
||||
|
||||
namespace Nebula.Launcher.ViewModels.Popup;
|
||||
@@ -28,7 +31,8 @@ public partial class AddFavoriteViewModel : PopupViewModelBase
|
||||
public override PopupMessageService PopupMessageService { get; }
|
||||
[GenerateProperty] private ServerOverviewModel ServerOverviewModel { get; }
|
||||
[GenerateProperty] private DebugService DebugService { get; }
|
||||
public override string Title => "Add to favorite";
|
||||
[GenerateProperty] private FavoriteServerListProvider FavoriteServerListProvider { get; }
|
||||
public override string Title => LocalisationService.GetString("popup-add-favorite");
|
||||
public override bool IsClosable => true;
|
||||
|
||||
[ObservableProperty] private string _ipInput;
|
||||
@@ -38,7 +42,11 @@ public partial class AddFavoriteViewModel : PopupViewModelBase
|
||||
{
|
||||
try
|
||||
{
|
||||
if(string.IsNullOrWhiteSpace(IpInput))
|
||||
throw new Exception(LocalisationService.GetString("popup-add-favorite-invalid-ip"));
|
||||
|
||||
var uri = IpInput.ToRobustUrl();
|
||||
FavoriteServerListProvider.AddFavorite(uri);
|
||||
Dispose();
|
||||
}
|
||||
catch (Exception e)
|
||||
|
||||
63
Nebula.Launcher/ViewModels/Popup/EditServerNameViewModel.cs
Normal file
63
Nebula.Launcher/ViewModels/Popup/EditServerNameViewModel.cs
Normal file
@@ -0,0 +1,63 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using Nebula.Launcher.Services;
|
||||
using Nebula.Launcher.Views.Popup;
|
||||
using Nebula.Shared.Services;
|
||||
using Nebula.Shared.ViewHelper;
|
||||
|
||||
namespace Nebula.Launcher.ViewModels.Popup;
|
||||
|
||||
[ViewModelRegister(typeof(EditServerNameView), false)]
|
||||
[ConstructGenerator]
|
||||
public sealed partial class EditServerNameViewModel : PopupViewModelBase
|
||||
{
|
||||
[GenerateProperty] public override PopupMessageService PopupMessageService { get; }
|
||||
[GenerateProperty] public ConfigurationService ConfigurationService { get; }
|
||||
public override string Title => LocalisationService.GetString("popup-edit-name");
|
||||
public override bool IsClosable => true;
|
||||
|
||||
[ObservableProperty] private string _ipInput;
|
||||
[ObservableProperty] private string _nameInput;
|
||||
|
||||
public void OnEnter()
|
||||
{
|
||||
if(string.IsNullOrWhiteSpace(IpInput))
|
||||
return;
|
||||
|
||||
if (string.IsNullOrWhiteSpace(NameInput))
|
||||
{
|
||||
OnClear();
|
||||
return;
|
||||
}
|
||||
|
||||
AddServerName();
|
||||
Dispose();
|
||||
}
|
||||
|
||||
public void OnClear()
|
||||
{
|
||||
RemoveServerName();
|
||||
Dispose();
|
||||
}
|
||||
|
||||
private void AddServerName()
|
||||
{
|
||||
var currentNames = ConfigurationService.GetConfigValue(LauncherConVar.ServerCustomNames)!;
|
||||
currentNames.Add(IpInput, NameInput);
|
||||
ConfigurationService.SetConfigValue(LauncherConVar.ServerCustomNames, currentNames);
|
||||
}
|
||||
|
||||
private void RemoveServerName()
|
||||
{
|
||||
var currentNames = ConfigurationService.GetConfigValue(LauncherConVar.ServerCustomNames)!;
|
||||
currentNames.Remove(IpInput);
|
||||
ConfigurationService.SetConfigValue(LauncherConVar.ServerCustomNames, currentNames);
|
||||
}
|
||||
|
||||
protected override void InitialiseInDesignMode()
|
||||
{
|
||||
}
|
||||
|
||||
protected override void Initialise()
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,9 @@
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using Nebula.Launcher.Services;
|
||||
using Nebula.Launcher.Views.Popup;
|
||||
using Nebula.Shared.Services;
|
||||
using Nebula.Shared.ViewHelper;
|
||||
|
||||
namespace Nebula.Launcher.ViewModels.Popup;
|
||||
|
||||
@@ -10,7 +12,7 @@ namespace Nebula.Launcher.ViewModels.Popup;
|
||||
public sealed partial class ExceptionListViewModel : PopupViewModelBase
|
||||
{
|
||||
[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 ObservableCollection<Exception> Errors { get; } = new();
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using Nebula.Launcher.Services;
|
||||
using Nebula.Launcher.Views.Popup;
|
||||
using Nebula.Shared.Services;
|
||||
using Nebula.Shared.ViewHelper;
|
||||
|
||||
namespace Nebula.Launcher.ViewModels.Popup;
|
||||
|
||||
@@ -12,7 +14,7 @@ public partial class InfoPopupViewModel : PopupViewModelBase
|
||||
|
||||
[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 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 Nebula.Launcher.Services;
|
||||
using Nebula.Launcher.Views.Popup;
|
||||
using Nebula.Shared.Models;
|
||||
using Nebula.Shared.Services;
|
||||
using Nebula.Shared.ViewHelper;
|
||||
|
||||
namespace Nebula.Launcher.ViewModels.Popup;
|
||||
|
||||
@@ -16,7 +18,7 @@ public sealed partial class LoadingContextViewModel : PopupViewModelBase, ILoadi
|
||||
|
||||
[ObservableProperty] private int _resolvedJobs;
|
||||
|
||||
public string LoadingName { get; set; } = "Loading...";
|
||||
public string LoadingName { get; set; } = LocalisationService.GetString("popup-loading");
|
||||
public bool IsCancellable { get; set; } = true;
|
||||
public override bool IsClosable => false;
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using Nebula.Launcher.Models;
|
||||
using Nebula.Launcher.Views.Popup;
|
||||
using Nebula.Shared.Services;
|
||||
using Nebula.Shared.ViewHelper;
|
||||
|
||||
namespace Nebula.Launcher.ViewModels.Popup;
|
||||
|
||||
@@ -35,4 +37,9 @@ public sealed partial class LogPopupModelView : PopupViewModelBase
|
||||
{
|
||||
Logs.Add(LogInfo.FromString(str));
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
Logs.Clear();
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
using System;
|
||||
using Nebula.Launcher.Services;
|
||||
using Nebula.Launcher.Views.Popup;
|
||||
using Nebula.Shared.Services;
|
||||
using Nebula.Shared.ViewHelper;
|
||||
|
||||
namespace Nebula.Launcher.ViewModels.Popup;
|
||||
|
||||
@@ -24,6 +26,6 @@ public partial class TfaViewModel : PopupViewModelBase
|
||||
}
|
||||
|
||||
[GenerateProperty] public override PopupMessageService PopupMessageService { get; }
|
||||
public override string Title => "2fa";
|
||||
public override string Title => LocalisationService.GetString("popup-twofa");
|
||||
public override bool IsClosable => true;
|
||||
}
|
||||
105
Nebula.Launcher/ViewModels/ServerCompoundEntryModelView.cs
Normal file
105
Nebula.Launcher/ViewModels/ServerCompoundEntryModelView.cs
Normal file
@@ -0,0 +1,105 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Media;
|
||||
using Avalonia.Threading;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Nebula.Launcher.Models;
|
||||
using Nebula.Launcher.ServerListProviders;
|
||||
using Nebula.Launcher.ViewModels.Pages;
|
||||
using Nebula.Launcher.Views;
|
||||
using Nebula.Shared.Models;
|
||||
using Nebula.Shared.Services;
|
||||
using Nebula.Shared.ViewHelper;
|
||||
using BindingFlags = System.Reflection.BindingFlags;
|
||||
|
||||
namespace Nebula.Launcher.ViewModels;
|
||||
|
||||
[ViewModelRegister(typeof(ServerCompoundEntryView), false)]
|
||||
[ConstructGenerator]
|
||||
public sealed partial class ServerCompoundEntryViewModel :
|
||||
ViewModelBase, IFavoriteEntryModelView, IFilterConsumer, IListEntryModelView, IEntryNameHolder
|
||||
{
|
||||
[ObservableProperty] private ServerEntryModelView? _currentEntry;
|
||||
[ObservableProperty] private Control? _entryControl;
|
||||
[ObservableProperty] private string _message = "Loading server entry...";
|
||||
[ObservableProperty] private bool _isFavorite;
|
||||
[ObservableProperty] private bool _loading = true;
|
||||
|
||||
private string? _name;
|
||||
private RobustUrl? _url;
|
||||
private ServerFilter? _currentFilter;
|
||||
|
||||
public string? Name
|
||||
{
|
||||
get => _name;
|
||||
set
|
||||
{
|
||||
_name = value;
|
||||
OnPropertyChanged();
|
||||
|
||||
if (CurrentEntry != null)
|
||||
CurrentEntry.Name = value;
|
||||
}
|
||||
}
|
||||
|
||||
[GenerateProperty] private RestService RestService { get; }
|
||||
[GenerateProperty] private IServiceProvider ServiceProvider{ get; }
|
||||
[GenerateProperty] private FavoriteServerListProvider FavoriteServerListProvider { get; }
|
||||
|
||||
protected override void InitialiseInDesignMode()
|
||||
{
|
||||
Name = "TEST.TEST";
|
||||
}
|
||||
|
||||
protected override void Initialise()
|
||||
{
|
||||
}
|
||||
|
||||
public ServerCompoundEntryViewModel LoadServerEntry(RobustUrl url,string? name, CancellationToken cancellationToken)
|
||||
{
|
||||
Task.Run(async () =>
|
||||
{
|
||||
_url = url;
|
||||
try
|
||||
{
|
||||
Message = "Loading server entry...";
|
||||
var status = await RestService.GetAsync<ServerStatus>(_url.StatusUri, cancellationToken);
|
||||
|
||||
CurrentEntry = ServiceProvider.GetService<ServerEntryModelView>()!.WithData(_url,name, status);
|
||||
CurrentEntry.IsFavorite = IsFavorite;
|
||||
CurrentEntry.Loading = false;
|
||||
CurrentEntry.ProcessFilter(_currentFilter);
|
||||
Loading = false;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Message = e.Message;
|
||||
}
|
||||
}, cancellationToken);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public void ToggleFavorites()
|
||||
{
|
||||
if (CurrentEntry is null && _url is not null)
|
||||
{
|
||||
IsFavorite = !IsFavorite;
|
||||
if(IsFavorite) FavoriteServerListProvider.AddFavorite(_url);
|
||||
else FavoriteServerListProvider.RemoveFavorite(_url);
|
||||
}
|
||||
|
||||
CurrentEntry?.ToggleFavorites();
|
||||
}
|
||||
|
||||
|
||||
public void ProcessFilter(ServerFilter? serverFilter)
|
||||
{
|
||||
_currentFilter = serverFilter;
|
||||
if(CurrentEntry is IFilterConsumer filterConsumer)
|
||||
filterConsumer.ProcessFilter(serverFilter);
|
||||
}
|
||||
}
|
||||
@@ -1,17 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Input;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Media;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using Nebula.Launcher.Models;
|
||||
using Nebula.Launcher.ProcessHelper;
|
||||
using Nebula.Launcher.ServerListProviders;
|
||||
using Nebula.Launcher.Services;
|
||||
using Nebula.Launcher.ViewModels.Pages;
|
||||
@@ -21,41 +17,45 @@ using Nebula.Shared.Models;
|
||||
using Nebula.Shared.Services;
|
||||
using Nebula.Shared.Services.Logging;
|
||||
using Nebula.Shared.Utils;
|
||||
using Nebula.Shared.ViewHelper;
|
||||
|
||||
namespace Nebula.Launcher.ViewModels;
|
||||
|
||||
[ViewModelRegister(typeof(ServerEntryView), false)]
|
||||
[ConstructGenerator]
|
||||
public partial class ServerEntryModelView : ViewModelBase, IFilterConsumer
|
||||
public partial class ServerEntryModelView : ViewModelBase, IFilterConsumer, IListEntryModelView, IFavoriteEntryModelView, IEntryNameHolder
|
||||
{
|
||||
[ObservableProperty] private string _description = "Fetching info...";
|
||||
[ObservableProperty] private bool _expandInfo;
|
||||
[ObservableProperty] private bool _isFavorite;
|
||||
[ObservableProperty] private bool _isVisible;
|
||||
|
||||
private string _lastError = "";
|
||||
private Process? _p;
|
||||
private ILogger _logger;
|
||||
private ILogger? _processLogger;
|
||||
|
||||
private ServerInfo? _serverInfo;
|
||||
[ObservableProperty] private bool _runVisible = true;
|
||||
[ObservableProperty] private bool _tagDataVisible;
|
||||
[ObservableProperty] private bool _loading;
|
||||
[ObservableProperty] private string _realName;
|
||||
|
||||
public string? Name
|
||||
{
|
||||
get => RealName;
|
||||
set => RealName = value ?? Status.Name;
|
||||
}
|
||||
|
||||
private ILogger _logger;
|
||||
private ServerInfo? _serverInfo;
|
||||
private ContentLogConsumer _currentContentLogConsumer;
|
||||
private ProcessRunHandler<GameProcessStartInfoProvider>? _currentInstance;
|
||||
|
||||
public LogPopupModelView CurrLog;
|
||||
public RobustUrl Address { get; private set; }
|
||||
|
||||
[GenerateProperty] private AuthService AuthService { get; } = default!;
|
||||
[GenerateProperty] private ContentService ContentService { get; } = default!;
|
||||
[GenerateProperty] private ConfigurationService ConfigurationService { get; } = default!;
|
||||
[GenerateProperty] private AuthService AuthService { get; }
|
||||
[GenerateProperty] private CancellationService CancellationService { get; } = default!;
|
||||
[GenerateProperty] private DebugService DebugService { get; } = default!;
|
||||
[GenerateProperty] private RunnerService RunnerService { get; } = default!;
|
||||
[GenerateProperty] private PopupMessageService PopupMessageService { get; } = default!;
|
||||
[GenerateProperty] private ViewHelperService ViewHelperService { get; } = default!;
|
||||
[GenerateProperty] private RestService RestService { get; } = default!;
|
||||
[GenerateProperty] private MainViewModel MainViewModel { get; } = default!;
|
||||
[GenerateProperty] private FavoriteServerListProvider FavoriteServerListProvider { get; } = default!;
|
||||
[GenerateProperty] private DotnetResolverService DotnetResolverService { get; } = default!;
|
||||
[GenerateProperty] private GameRunnerPreparer GameRunnerPreparer { get; } = default!;
|
||||
|
||||
public ServerStatus Status { get; private set; } =
|
||||
new(
|
||||
@@ -71,22 +71,9 @@ public partial class ServerEntryModelView : ViewModelBase, IFilterConsumer
|
||||
);
|
||||
|
||||
public ObservableCollection<ServerLink> Links { get; } = new();
|
||||
public bool RunVisible => Process == null;
|
||||
|
||||
public ObservableCollection<string> Tags { get; } = [];
|
||||
|
||||
public ICommand OnLinkGo { get; } = new LinkGoCommand();
|
||||
|
||||
private Process? Process
|
||||
{
|
||||
get => _p;
|
||||
set
|
||||
{
|
||||
_p = value;
|
||||
OnPropertyChanged(nameof(RunVisible));
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<ServerInfo?> GetServerInfo()
|
||||
{
|
||||
if (_serverInfo == null)
|
||||
@@ -105,6 +92,8 @@ public partial class ServerEntryModelView : ViewModelBase, IFilterConsumer
|
||||
|
||||
protected override void InitialiseInDesignMode()
|
||||
{
|
||||
IsVisible = true;
|
||||
RealName = "TEST.TEST";
|
||||
Description = "Server of meow girls! Nya~ \nNyaMeow\nOOOINK!!";
|
||||
Links.Add(new ServerLink("Discord", "discord", "https://cinka.ru"));
|
||||
Status = new ServerStatus("Ameba",
|
||||
@@ -119,6 +108,7 @@ public partial class ServerEntryModelView : ViewModelBase, IFilterConsumer
|
||||
{
|
||||
_logger = DebugService.GetLogger(this);
|
||||
CurrLog = ViewHelperService.GetViewModel<LogPopupModelView>();
|
||||
_currentContentLogConsumer = new(CurrLog, PopupMessageService);
|
||||
}
|
||||
|
||||
public void ProcessFilter(ServerFilter? serverFilter)
|
||||
@@ -140,37 +130,20 @@ public partial class ServerEntryModelView : ViewModelBase, IFilterConsumer
|
||||
OnPropertyChanged(nameof(Status));
|
||||
}
|
||||
|
||||
public ServerEntryModelView WithData(RobustUrl url, ServerStatus? serverStatus)
|
||||
public ServerEntryModelView WithData(RobustUrl url, string? name,ServerStatus serverStatus)
|
||||
{
|
||||
Address = url;
|
||||
if (serverStatus is not null)
|
||||
SetStatus(serverStatus);
|
||||
else
|
||||
FetchStatus();
|
||||
|
||||
IsFavorite = GetFavoriteEntries().Contains(Address.ToString());
|
||||
|
||||
SetStatus(serverStatus);
|
||||
Name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
private List<string> GetFavoriteEntries()
|
||||
public void EditName()
|
||||
{
|
||||
return ConfigurationService.GetConfigValue(LauncherConVar.Favorites)?.ToList() ?? [];
|
||||
}
|
||||
|
||||
private async void FetchStatus()
|
||||
{
|
||||
try
|
||||
{
|
||||
SetStatus(await RestService.GetAsync<ServerStatus>(Address.StatusUri, CancellationService.Token));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_logger.Error(e);
|
||||
Status = new ServerStatus("ErrorLand", $"ERROR: {e.Message}", [], "", -1, -1, -1, false,
|
||||
DateTime.Now,
|
||||
-1);
|
||||
}
|
||||
var popup = ViewHelperService.GetViewModel<EditServerNameViewModel>();
|
||||
popup.IpInput = Address.ToString();
|
||||
popup.NameInput = Name ?? string.Empty;
|
||||
PopupMessageService.Popup(popup);
|
||||
}
|
||||
|
||||
public void OpenContentViewer()
|
||||
@@ -189,114 +162,55 @@ public partial class ServerEntryModelView : ViewModelBase, IFilterConsumer
|
||||
|
||||
public void RunInstance()
|
||||
{
|
||||
Task.Run(RunAsync);
|
||||
CurrLog.Clear();
|
||||
Task.Run(async ()=> await RunInstanceAsync());
|
||||
}
|
||||
|
||||
public async Task RunAsync()
|
||||
public void RunInstanceIgnoreAuth()
|
||||
{
|
||||
try
|
||||
{
|
||||
var authProv = AuthService.SelectedAuth;
|
||||
|
||||
var buildInfo =
|
||||
await ContentService.GetBuildInfo(Address, CancellationService.Token);
|
||||
|
||||
using (var loadingContext = ViewHelperService.GetViewModel<LoadingContextViewModel>())
|
||||
{
|
||||
loadingContext.LoadingName = "Loading instance...";
|
||||
((ILoadingHandler)loadingContext).AppendJob();
|
||||
|
||||
PopupMessageService.Popup(loadingContext);
|
||||
|
||||
await RunnerService.PrepareRun(buildInfo, loadingContext, CancellationService.Token);
|
||||
|
||||
var path = Path.GetDirectoryName(Assembly.GetEntryAssembly()?.Location);
|
||||
|
||||
Process = Process.Start(new ProcessStartInfo
|
||||
{
|
||||
FileName = await DotnetResolverService.EnsureDotnet(),
|
||||
Arguments = Path.Join(path, "Nebula.Runner.dll"),
|
||||
Environment =
|
||||
{
|
||||
{ "ROBUST_AUTH_USERID", authProv?.UserId.ToString() },
|
||||
{ "ROBUST_AUTH_TOKEN", authProv?.Token.Token },
|
||||
{ "ROBUST_AUTH_SERVER", authProv?.AuthServer },
|
||||
{ "ROBUST_AUTH_PUBKEY", buildInfo.BuildInfo.Auth.PublicKey },
|
||||
{ "GAME_URL", Address.ToString() },
|
||||
{ "AUTH_LOGIN", authProv?.Login }
|
||||
},
|
||||
CreateNoWindow = true,
|
||||
UseShellExecute = false,
|
||||
RedirectStandardOutput = true,
|
||||
RedirectStandardError = true,
|
||||
StandardOutputEncoding = Encoding.UTF8
|
||||
});
|
||||
|
||||
((ILoadingHandler)loadingContext).AppendResolvedJob();
|
||||
}
|
||||
|
||||
if (Process is null) return;
|
||||
|
||||
_processLogger = DebugService.GetLogger($"PROCESS_{Process.Id}");
|
||||
|
||||
Process.EnableRaisingEvents = true;
|
||||
|
||||
Process.BeginOutputReadLine();
|
||||
Process.BeginErrorReadLine();
|
||||
|
||||
Process.OutputDataReceived += OnOutputDataReceived;
|
||||
Process.ErrorDataReceived += OnErrorDataReceived;
|
||||
|
||||
Process.Exited += OnExited;
|
||||
}
|
||||
catch (TaskCanceledException e)
|
||||
{
|
||||
PopupMessageService.Popup("Task canceled: " + e.Message);
|
||||
_logger.Error("Task canceled");
|
||||
_logger.Error(e);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
PopupMessageService.Popup(e);
|
||||
}
|
||||
CurrLog.Clear();
|
||||
Task.Run(async ()=> await RunInstanceAsync(true));
|
||||
}
|
||||
|
||||
private void OnExited(object? sender, EventArgs e)
|
||||
private async Task RunInstanceAsync(bool ignoreLoginCredentials = false)
|
||||
{
|
||||
if (Process is null) return;
|
||||
if (!ignoreLoginCredentials && AuthService.SelectedAuth is null)
|
||||
{
|
||||
var warningContext = ViewHelperService.GetViewModel<IsLoginCredentialsNullPopupViewModel>()
|
||||
.WithServerEntry(this);
|
||||
|
||||
Process.OutputDataReceived -= OnOutputDataReceived;
|
||||
Process.ErrorDataReceived -= OnErrorDataReceived;
|
||||
Process.Exited -= OnExited;
|
||||
PopupMessageService.Popup(warningContext);
|
||||
return;
|
||||
}
|
||||
|
||||
_processLogger?.Log("PROCESS EXIT WITH CODE " + Process.ExitCode);
|
||||
using var loadingContext = ViewHelperService.GetViewModel<LoadingContextViewModel>();
|
||||
loadingContext.LoadingName = "Loading instance...";
|
||||
((ILoadingHandler)loadingContext).AppendJob();
|
||||
|
||||
if (Process.ExitCode != 0)
|
||||
PopupMessageService.Popup($"Game exit with code {Process.ExitCode}.\nReason: {_lastError}");
|
||||
PopupMessageService.Popup(loadingContext);
|
||||
_currentInstance =
|
||||
await GameRunnerPreparer.GetGameProcessStartInfoProvider(Address, loadingContext, CancellationService.Token);
|
||||
|
||||
_processLogger?.Dispose();
|
||||
|
||||
Process.Dispose();
|
||||
Process = null;
|
||||
_currentInstance.RegisterLogger(_currentContentLogConsumer);
|
||||
_currentInstance.RegisterLogger(new DebugLoggerBridge(DebugService.GetLogger($"PROCESS_{Random.Shared.Next(65535)}")));
|
||||
_currentInstance.OnProcessExited += OnProcessExited;
|
||||
RunVisible = false;
|
||||
_currentInstance.Start();
|
||||
}
|
||||
|
||||
private void OnErrorDataReceived(object sender, DataReceivedEventArgs e)
|
||||
private void OnProcessExited(ProcessRunHandler<GameProcessStartInfoProvider> obj)
|
||||
{
|
||||
if (e.Data != null)
|
||||
{
|
||||
_lastError = e.Data;
|
||||
_processLogger?.Error(e.Data);
|
||||
CurrLog.Append(e.Data);
|
||||
}
|
||||
RunVisible = true;
|
||||
if (_currentInstance == null) return;
|
||||
|
||||
_currentInstance.OnProcessExited -= OnProcessExited;
|
||||
_currentInstance.Dispose();
|
||||
_currentInstance = null;
|
||||
}
|
||||
|
||||
private void OnOutputDataReceived(object sender, DataReceivedEventArgs e)
|
||||
public void StopInstance()
|
||||
{
|
||||
if (e.Data != null)
|
||||
{
|
||||
_processLogger?.Log(e.Data);
|
||||
CurrLog.Append(e.Data);
|
||||
}
|
||||
_currentInstance?.Stop();
|
||||
}
|
||||
|
||||
public void ReadLog()
|
||||
@@ -304,11 +218,6 @@ public partial class ServerEntryModelView : ViewModelBase, IFilterConsumer
|
||||
PopupMessageService.Popup(CurrLog);
|
||||
}
|
||||
|
||||
public void StopInstance()
|
||||
{
|
||||
Process?.CloseMainWindow();
|
||||
}
|
||||
|
||||
public async void ExpandInfoRequired()
|
||||
{
|
||||
ExpandInfo = !ExpandInfo;
|
||||
@@ -323,56 +232,6 @@ public partial class ServerEntryModelView : ViewModelBase, IFilterConsumer
|
||||
if (info.Links is null) return;
|
||||
foreach (var link in info.Links) Links.Add(link);
|
||||
}
|
||||
|
||||
private static string FindDotnetPath()
|
||||
{
|
||||
var pathEnv = Environment.GetEnvironmentVariable("PATH");
|
||||
var paths = pathEnv?.Split(Path.PathSeparator);
|
||||
if (paths != null)
|
||||
foreach (var path in paths)
|
||||
{
|
||||
var dotnetPath = Path.Combine(path, "dotnet");
|
||||
if (File.Exists(dotnetPath)) return dotnetPath;
|
||||
}
|
||||
|
||||
return "dotnet";
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public class LinkGoCommand : ICommand
|
||||
@@ -395,8 +254,3 @@ public class LinkGoCommand : ICommand
|
||||
|
||||
public event EventHandler? CanExecuteChanged;
|
||||
}
|
||||
|
||||
public interface IFilterConsumer
|
||||
{
|
||||
public void ProcessFilter(ServerFilter? serverFilter);
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
<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:pages="clr-namespace:Nebula.Launcher.ViewModels.Pages"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
x:Class="Nebula.Launcher.Views.Config.StringConfigurationView"
|
||||
x:DataType="pages:StringConfigurationViewModel">
|
||||
<Design.DataContext>
|
||||
<pages:StringConfigurationViewModel />
|
||||
</Design.DataContext>
|
||||
<StackPanel Orientation="Horizontal" Spacing="5" Margin="5">
|
||||
<TextBlock VerticalAlignment="Center" Text="{Binding ConfigName}"/>
|
||||
<TextBlock VerticalAlignment="Center" Text=":"/>
|
||||
<TextBox Text="{Binding ConfigText}"/>
|
||||
</StackPanel>
|
||||
</UserControl>
|
||||
@@ -1,20 +0,0 @@
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Markup.Xaml;
|
||||
using Nebula.Launcher.ViewModels.Pages;
|
||||
|
||||
namespace Nebula.Launcher.Views.Config;
|
||||
|
||||
public partial class StringConfigurationView : UserControl
|
||||
{
|
||||
public StringConfigurationView()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public StringConfigurationView(StringConfigurationViewModel viewModel)
|
||||
: this()
|
||||
{
|
||||
DataContext = viewModel;
|
||||
}
|
||||
}
|
||||
@@ -1,22 +1,11 @@
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Markup.Xaml;
|
||||
using Nebula.Launcher.ViewModels.Pages;
|
||||
|
||||
namespace Nebula.Launcher.Views;
|
||||
|
||||
public partial class FileContentEntryView : UserControl
|
||||
{
|
||||
// This constructor is used when the view is created by the XAML Previewer
|
||||
public FileContentEntryView()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
// This constructor is used when the view is created via dependency injection
|
||||
public FileContentEntryView(FolderContentEntry viewModel)
|
||||
: this()
|
||||
{
|
||||
DataContext = viewModel;
|
||||
}
|
||||
}
|
||||
@@ -8,10 +8,10 @@
|
||||
xmlns:converters="clr-namespace:Nebula.Launcher.Converters"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:models="clr-namespace:Nebula.Shared.Models;assembly=Nebula.Shared"
|
||||
xmlns:viewModels="clr-namespace:Nebula.Launcher.ViewModels"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:models1="clr-namespace:Nebula.Launcher.Models">
|
||||
xmlns:models1="clr-namespace:Nebula.Launcher.Models"
|
||||
xmlns:services="clr-namespace:Nebula.Launcher.Services">
|
||||
<Design.DataContext>
|
||||
<viewModels:MainViewModel />
|
||||
</Design.DataContext>
|
||||
@@ -121,7 +121,20 @@
|
||||
https://durenko.tatar/nebula/
|
||||
</TextBlock>
|
||||
</Button>
|
||||
<TextBlock HorizontalAlignment="Right" VerticalAlignment="Center" Text="{Binding VersionInfo}"/>
|
||||
<StackPanel Spacing="5" HorizontalAlignment="Right" VerticalAlignment="Center" Orientation="Horizontal">
|
||||
<Button
|
||||
Margin="0"
|
||||
Padding="0"
|
||||
CornerRadius="0"
|
||||
Command="{Binding OpenAuthPage}">
|
||||
<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>
|
||||
</Button>
|
||||
<TextBlock>|</TextBlock>
|
||||
<TextBlock Text="{Binding VersionInfo}"/>
|
||||
</StackPanel>
|
||||
</Panel>
|
||||
</Label>
|
||||
</Border>
|
||||
|
||||
@@ -1,20 +1,11 @@
|
||||
using Avalonia.Controls;
|
||||
using Nebula.Launcher.ViewModels;
|
||||
|
||||
namespace Nebula.Launcher.Views;
|
||||
|
||||
public partial class MainView : UserControl
|
||||
{
|
||||
// This constructor is used when the view is created by the XAML Previewer
|
||||
public MainView()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
// This constructor is used when the view is created via dependency injection
|
||||
public MainView(MainViewModel viewModel)
|
||||
: this()
|
||||
{
|
||||
DataContext = viewModel;
|
||||
}
|
||||
}
|
||||
@@ -5,10 +5,12 @@
|
||||
x:Class="Nebula.Launcher.Views.Pages.AccountInfoView"
|
||||
x:DataType="pages:AccountInfoViewModel"
|
||||
xmlns="https://github.com/avaloniaui"
|
||||
xmlns:customControls="clr-namespace:Nebula.Launcher.Controls"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:pages="clr-namespace:Nebula.Launcher.ViewModels.Pages"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:auth="clr-namespace:Nebula.Launcher.Models.Auth">
|
||||
<Design.DataContext>
|
||||
<pages:AccountInfoViewModel />
|
||||
</Design.DataContext>
|
||||
@@ -28,7 +30,7 @@
|
||||
<GradientStop Color="#292222" Offset="1.0" />
|
||||
</LinearGradientBrush>
|
||||
</Border.Background>
|
||||
<Label HorizontalAlignment="Center">Profiles:</Label>
|
||||
<customControls:LocalizedLabel HorizontalAlignment="Center" LocalId="account-profiles"/>
|
||||
</Border>
|
||||
<ScrollViewer HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto">
|
||||
<ItemsControl
|
||||
@@ -36,7 +38,7 @@
|
||||
ItemsSource="{Binding Accounts}"
|
||||
Padding="0">
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate DataType="{x:Type pages:ProfileAuthCredentials}">
|
||||
<DataTemplate DataType="{x:Type auth:ProfileAuthCredentials}">
|
||||
<Border
|
||||
BoxShadow="0 1 15 -2 #121212"
|
||||
CornerRadius="0,10,0,10"
|
||||
@@ -59,17 +61,13 @@
|
||||
Command="{Binding OnSelect}"
|
||||
CornerRadius="0,0,0,10"
|
||||
Padding="5">
|
||||
<Label>
|
||||
Select
|
||||
</Label>
|
||||
<customControls:LocalizedLabel LocalId="account-profile-select"/>
|
||||
</Button>
|
||||
<Button
|
||||
Command="{Binding OnDelete}"
|
||||
CornerRadius="0,10,0,0"
|
||||
Padding="5">
|
||||
<Label>
|
||||
Delete
|
||||
</Label>
|
||||
<customControls:LocalizedLabel LocalId="account-profile-delete"/>
|
||||
</Button>
|
||||
</StackPanel>
|
||||
</Panel>
|
||||
@@ -102,22 +100,27 @@
|
||||
Margin="0,0,0,20"
|
||||
Path="/Assets/svg/user.svg" />
|
||||
<StackPanel HorizontalAlignment="Center">
|
||||
<StackPanel IsVisible="{Binding DoRetryAuth}">
|
||||
<Border Background="{StaticResource DefaultSelected}" BoxShadow="{StaticResource DefaultShadow}">
|
||||
<Button
|
||||
Command="{Binding DoCurrentAuth}"
|
||||
HorizontalAlignment="Stretch"
|
||||
HorizontalContentAlignment="Center">
|
||||
<customControls:LocalizedLabel LocalId="account-auth-retry"/>
|
||||
</Button>
|
||||
</Border>
|
||||
<customControls:LocalizedLabel HorizontalAlignment="Center" LocalId="account-auth-try-another"/>
|
||||
</StackPanel>
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<Label VerticalAlignment="Center">
|
||||
Login:
|
||||
</Label>
|
||||
<customControls:LocalizedLabel VerticalAlignment="Center" LocalId="account-auth-login"/>
|
||||
<TextBox Text="{Binding CurrentLogin}" MinWidth="200" />
|
||||
</StackPanel>
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<Label HorizontalAlignment="Left" VerticalAlignment="Center">
|
||||
Password:
|
||||
</Label>
|
||||
<customControls:LocalizedLabel HorizontalAlignment="Left" VerticalAlignment="Center" LocalId="account-auth-password"/>
|
||||
<TextBox PasswordChar="#" MinWidth="200" Text="{Binding CurrentPassword}" />
|
||||
</StackPanel>
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<Label VerticalAlignment="Center">
|
||||
Auth server:
|
||||
</Label>
|
||||
<customControls:LocalizedLabel VerticalAlignment="Center" LocalId="account-auth-server"/>
|
||||
<Button Command="{Binding ExpandAuthUrlCommand}" VerticalAlignment="Stretch">
|
||||
<Label>+</Label>
|
||||
</Button>
|
||||
@@ -150,7 +153,7 @@
|
||||
Command="{Binding DoAuth}"
|
||||
HorizontalAlignment="Stretch"
|
||||
HorizontalContentAlignment="Center">
|
||||
<Label>Auth</Label>
|
||||
<customControls:LocalizedLabel LocalId="account-auth-button"/>
|
||||
</Button>
|
||||
</Border>
|
||||
<Border BoxShadow="{StaticResource DefaultShadow}">
|
||||
@@ -158,7 +161,7 @@
|
||||
Command="{Binding SaveProfileCommand}"
|
||||
HorizontalAlignment="Stretch"
|
||||
HorizontalContentAlignment="Center">
|
||||
<Label>Save profile</Label>
|
||||
<customControls:LocalizedLabel LocalId="account-auth-save"/>
|
||||
</Button>
|
||||
</Border>
|
||||
<Button Command="{Binding ExpandAuthViewCommand}" HorizontalAlignment="Right">
|
||||
@@ -175,7 +178,7 @@
|
||||
Path="/Assets/svg/user.svg" />
|
||||
<Label>
|
||||
<StackPanel HorizontalAlignment="Center" Orientation="Horizontal">
|
||||
<TextBlock>Hello,</TextBlock>
|
||||
<customControls:LocalizedLabel LocalId="account-auth-hello"/>
|
||||
<TextBlock Text="{Binding CurrentLogin}" />
|
||||
</StackPanel>
|
||||
</Label>
|
||||
@@ -186,12 +189,12 @@
|
||||
Spacing="5">
|
||||
<Border BoxShadow="{StaticResource DefaultShadow}">
|
||||
<Button Command="{Binding Logout}">
|
||||
<Label>Logout</Label>
|
||||
<customControls:LocalizedLabel LocalId="account-auth-logout"/>
|
||||
</Button>
|
||||
</Border>
|
||||
<Border BoxShadow="{StaticResource DefaultShadow}">
|
||||
<Button Command="{Binding SaveProfileCommand}">
|
||||
<Label>Save profile</Label>
|
||||
<customControls:LocalizedLabel LocalId="account-auth-save"/>
|
||||
</Button>
|
||||
</Border>
|
||||
</StackPanel>
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using Avalonia.Controls;
|
||||
using AccountInfoViewModel = Nebula.Launcher.ViewModels.Pages.AccountInfoViewModel;
|
||||
|
||||
namespace Nebula.Launcher.Views.Pages;
|
||||
|
||||
@@ -9,10 +8,4 @@ public partial class AccountInfoView : UserControl
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public AccountInfoView(AccountInfoViewModel viewModel)
|
||||
: this()
|
||||
{
|
||||
DataContext = viewModel;
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:pages="clr-namespace:Nebula.Launcher.ViewModels.Pages"
|
||||
xmlns:customControls="clr-namespace:Nebula.Launcher.Controls"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
x:Class="Nebula.Launcher.Views.Pages.ConfigurationView"
|
||||
x:DataType="pages:ConfigurationViewModel">
|
||||
@@ -10,31 +11,67 @@
|
||||
<pages:ConfigurationViewModel />
|
||||
</Design.DataContext>
|
||||
|
||||
<Panel>
|
||||
<Border
|
||||
VerticalAlignment="Top"
|
||||
Margin="5" Padding="5,2,5,2">
|
||||
<Border.Background>
|
||||
<LinearGradientBrush EndPoint="50%,100%" StartPoint="50%,0%">
|
||||
<GradientStop Color="#222222" Offset="0.0" />
|
||||
<GradientStop Color="#292222" Offset="1.0" />
|
||||
</LinearGradientBrush>
|
||||
</Border.Background>
|
||||
<ScrollViewer >
|
||||
<StackPanel>
|
||||
<ItemsControl
|
||||
ItemsSource="{Binding ConfigurationVerbose}"
|
||||
Padding="0" />
|
||||
</StackPanel>
|
||||
</ScrollViewer>
|
||||
</Border>
|
||||
<Button
|
||||
VerticalAlignment="Bottom"
|
||||
HorizontalAlignment="Stretch"
|
||||
Padding="5"
|
||||
Margin="5"
|
||||
Command="{Binding InvokeUpdateConfiguration}"
|
||||
>Save
|
||||
</Button>
|
||||
</Panel>
|
||||
<ScrollViewer>
|
||||
<StackPanel Spacing="10" Margin="10">
|
||||
<ItemsControl
|
||||
ItemsSource="{Binding ConfigurationVerbose}"
|
||||
Padding="0" >
|
||||
<ItemsControl.ItemsPanel>
|
||||
<ItemsPanelTemplate>
|
||||
<StackPanel Spacing="10" />
|
||||
</ItemsPanelTemplate>
|
||||
</ItemsControl.ItemsPanel>
|
||||
</ItemsControl>
|
||||
|
||||
<WrapPanel Orientation="Horizontal">
|
||||
<Button
|
||||
Classes="ConfigBorder"
|
||||
VerticalAlignment="Bottom"
|
||||
HorizontalAlignment="Stretch"
|
||||
Padding="5"
|
||||
Margin="5"
|
||||
Command="{Binding InvokeUpdateConfiguration}">
|
||||
<customControls:LocalizedLabel LocalId="config-save"/>
|
||||
</Button>
|
||||
<Button
|
||||
Classes="ConfigBorder"
|
||||
VerticalAlignment="Bottom"
|
||||
HorizontalAlignment="Stretch"
|
||||
Padding="5"
|
||||
Margin="5"
|
||||
Command="{Binding ResetConfig}">
|
||||
<customControls:LocalizedLabel LocalId="config-reset"/>
|
||||
</Button>
|
||||
<Button
|
||||
Classes="ConfigBorder"
|
||||
VerticalAlignment="Bottom"
|
||||
HorizontalAlignment="Stretch"
|
||||
Padding="5"
|
||||
Margin="5"
|
||||
Command="{Binding OpenDataFolder}">
|
||||
<customControls:LocalizedLabel LocalId="config-open-data"/>
|
||||
</Button>
|
||||
|
||||
<Button
|
||||
Classes="ConfigBorder"
|
||||
VerticalAlignment="Bottom"
|
||||
HorizontalAlignment="Stretch"
|
||||
Padding="5"
|
||||
Margin="5"
|
||||
Command="{Binding ExportLogs}">
|
||||
<customControls:LocalizedLabel LocalId="config-export-logs"/>
|
||||
</Button>
|
||||
|
||||
<Button
|
||||
Classes="ConfigBorder"
|
||||
VerticalAlignment="Bottom"
|
||||
HorizontalAlignment="Stretch"
|
||||
Padding="5"
|
||||
Margin="5"
|
||||
Command="{Binding RemoveAllContent}">
|
||||
<customControls:LocalizedLabel LocalId="config-remove-content-all"/>
|
||||
</Button>
|
||||
</WrapPanel>
|
||||
</StackPanel>
|
||||
</ScrollViewer>
|
||||
</UserControl>
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Markup.Xaml;
|
||||
using Nebula.Launcher.ViewModels.Pages;
|
||||
|
||||
namespace Nebula.Launcher.Views.Pages;
|
||||
|
||||
@@ -11,10 +8,4 @@ public partial class ConfigurationView : UserControl
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public ConfigurationView(ConfigurationViewModel viewModel)
|
||||
: this()
|
||||
{
|
||||
DataContext = viewModel;
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,8 @@
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:pages="clr-namespace:Nebula.Launcher.ViewModels.Pages"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:services="clr-namespace:Nebula.Launcher.Services">
|
||||
<Design.DataContext>
|
||||
<pages:ContentBrowserViewModel />
|
||||
</Design.DataContext>
|
||||
@@ -31,14 +32,14 @@
|
||||
Margin="5"
|
||||
Text="{Binding ServerText}"
|
||||
VerticalAlignment="Center"
|
||||
Watermark="Server Url..." />
|
||||
Watermark="{services:LocaledText content-view-server}" />
|
||||
<TextBox
|
||||
Grid.Column="1"
|
||||
Grid.Row="0"
|
||||
Margin="5"
|
||||
Text="{Binding SearchText}"
|
||||
VerticalAlignment="Center"
|
||||
Watermark="Path..." />
|
||||
Watermark="{services:LocaledText content-view-path}" />
|
||||
<Button
|
||||
Command="{Binding OnBackEnter}"
|
||||
Grid.Column="2"
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using Avalonia.Controls;
|
||||
using ContentBrowserViewModel = Nebula.Launcher.ViewModels.Pages.ContentBrowserViewModel;
|
||||
|
||||
namespace Nebula.Launcher.Views.Pages;
|
||||
|
||||
@@ -9,10 +8,4 @@ public partial class ContentBrowserView : UserControl
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public ContentBrowserView(ContentBrowserViewModel viewModel)
|
||||
: this()
|
||||
{
|
||||
DataContext = viewModel;
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,8 @@
|
||||
xmlns:pages="clr-namespace:Nebula.Launcher.ViewModels.Pages"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
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>
|
||||
<pages:ServerOverviewModel />
|
||||
@@ -51,8 +52,8 @@
|
||||
VerticalAlignment="Bottom"
|
||||
IsVisible="{Binding IsFilterVisible}">
|
||||
<StackPanel Orientation="Vertical" Spacing="2" Margin="15">
|
||||
<controls:FilterBox Name="EssentialFilters" FilterBoxName="Roleplay" FilterCommand="{Binding OnFilterChanged}"/>
|
||||
<controls:FilterBox Name="LanguageFilters" FilterBoxName="Language" FilterCommand="{Binding OnFilterChanged}"/>
|
||||
<controls:FilterBox Name="EssentialFilters" FilterBoxName="filter-roleplay" FilterCommand="{Binding OnFilterChanged}"/>
|
||||
<controls:FilterBox Name="LanguageFilters" FilterBoxName="filter-language" FilterCommand="{Binding OnFilterChanged}"/>
|
||||
</StackPanel>
|
||||
</Border>
|
||||
|
||||
@@ -70,9 +71,8 @@
|
||||
<TextBox
|
||||
Margin="25,0,0,0"
|
||||
Text="{Binding SearchText}"
|
||||
TextChanged="TextBox_OnTextChanged"
|
||||
VerticalAlignment="Center"
|
||||
Watermark="Server name..." />
|
||||
Watermark="{services:LocaledText 'server-search'}" />
|
||||
<Button
|
||||
Command="{Binding FilterRequired}"
|
||||
Grid.Column="2"
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
using Avalonia.Controls;
|
||||
using Nebula.Launcher.ViewModels.Pages;
|
||||
|
||||
namespace Nebula.Launcher.Views.Pages;
|
||||
|
||||
public partial class ServerOverviewView : UserControl
|
||||
{
|
||||
// This constructor is used when the view is created by the XAML Previewer
|
||||
public ServerOverviewView()
|
||||
{
|
||||
InitializeComponent();
|
||||
@@ -19,17 +17,4 @@ public partial class ServerOverviewView : UserControl
|
||||
LanguageFilters.AddFilter("RU","lang:ru");
|
||||
LanguageFilters.AddFilter("EN","lang:en");
|
||||
}
|
||||
|
||||
// This constructor is used when the view is created via dependency injection
|
||||
public ServerOverviewView(ServerOverviewModel viewModel)
|
||||
: this()
|
||||
{
|
||||
DataContext = viewModel;
|
||||
}
|
||||
|
||||
private void TextBox_OnTextChanged(object? sender, TextChangedEventArgs e)
|
||||
{
|
||||
var context = (ServerOverviewModel?)DataContext;
|
||||
context?.OnSearchChange?.Invoke();
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,7 @@
|
||||
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:customControls="clr-namespace:Nebula.Launcher.Controls"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
|
||||
<Design.DataContext>
|
||||
<popup:AddFavoriteViewModel />
|
||||
@@ -18,7 +19,7 @@
|
||||
</Border>
|
||||
<Border Background="{StaticResource DefaultSelected}" BoxShadow="{StaticResource DefaultShadow}">
|
||||
<Button Command="{Binding OnEnter}" HorizontalAlignment="Stretch">
|
||||
<Label HorizontalAlignment="Center">Add</Label>
|
||||
<customControls:LocalizedLabel HorizontalAlignment="Center" LocalId="favorite-add"/>
|
||||
</Button>
|
||||
</Border>
|
||||
<Label>
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using Avalonia.Controls;
|
||||
using Nebula.Launcher.ViewModels.Popup;
|
||||
|
||||
namespace Nebula.Launcher.Views.Popup;
|
||||
|
||||
@@ -9,10 +8,4 @@ public partial class AddFavoriteView : UserControl
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public AddFavoriteView(AddFavoriteViewModel viewModel)
|
||||
: this()
|
||||
{
|
||||
DataContext = viewModel;
|
||||
}
|
||||
}
|
||||
32
Nebula.Launcher/Views/Popup/EditServerNameView.axaml
Normal file
32
Nebula.Launcher/Views/Popup/EditServerNameView.axaml
Normal file
@@ -0,0 +1,32 @@
|
||||
<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:customControls="clr-namespace:Nebula.Launcher.Controls"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
x:Class="Nebula.Launcher.Views.Popup.EditServerNameView"
|
||||
x:DataType="popup:EditServerNameViewModel">
|
||||
<Design.DataContext>
|
||||
<popup:EditServerNameViewModel />
|
||||
</Design.DataContext>
|
||||
|
||||
<StackPanel Margin="15" Spacing="10">
|
||||
<Border BoxShadow="{StaticResource DefaultShadow}">
|
||||
<TextBlock Text="{Binding IpInput}" Margin="10,8,10,8"/>
|
||||
</Border>
|
||||
<Border BoxShadow="{StaticResource DefaultShadow}">
|
||||
<TextBox Text="{Binding NameInput}" Watermark="custom server name" />
|
||||
</Border>
|
||||
<Border Background="{StaticResource DefaultSelected}" BoxShadow="{StaticResource DefaultShadow}">
|
||||
<Button Command="{Binding OnEnter}" HorizontalAlignment="Stretch">
|
||||
<customControls:LocalizedLabel HorizontalAlignment="Center" LocalId="servername-set"/>
|
||||
</Button>
|
||||
</Border>
|
||||
<Border Background="{StaticResource DefaultSelected}" BoxShadow="{StaticResource DefaultShadow}">
|
||||
<Button Command="{Binding OnClear}" HorizontalAlignment="Stretch">
|
||||
<customControls:LocalizedLabel HorizontalAlignment="Center" LocalId="servername-clear"/>
|
||||
</Button>
|
||||
</Border>
|
||||
</StackPanel>
|
||||
</UserControl>
|
||||
11
Nebula.Launcher/Views/Popup/EditServerNameView.axaml.cs
Normal file
11
Nebula.Launcher/Views/Popup/EditServerNameView.axaml.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
using Avalonia.Controls;
|
||||
|
||||
namespace Nebula.Launcher.Views.Popup;
|
||||
|
||||
public partial class EditServerNameView : UserControl
|
||||
{
|
||||
public EditServerNameView()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
using Avalonia.Controls;
|
||||
using Nebula.Launcher.ViewModels.Popup;
|
||||
|
||||
namespace Nebula.Launcher.Views.Popup;
|
||||
|
||||
@@ -9,9 +8,4 @@ public partial class ExceptionListView : UserControl
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public ExceptionListView(ExceptionListViewModel listViewModel) : this()
|
||||
{
|
||||
DataContext = listViewModel;
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,7 @@
|
||||
|
||||
<Panel HorizontalAlignment="Center" VerticalAlignment="Center">
|
||||
<Label>
|
||||
<TextBlock Text="{Binding InfoText}" />
|
||||
<TextBlock Text="{Binding InfoText}" TextWrapping="Wrap"/>
|
||||
</Label>
|
||||
</Panel>
|
||||
</UserControl>
|
||||
@@ -1,5 +1,4 @@
|
||||
using Avalonia.Controls;
|
||||
using InfoPopupViewModel = Nebula.Launcher.ViewModels.Popup.InfoPopupViewModel;
|
||||
|
||||
namespace Nebula.Launcher.Views.Popup;
|
||||
|
||||
@@ -9,9 +8,4 @@ public partial class InfoPopupView : UserControl
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public InfoPopupView(InfoPopupViewModel viewModel) : this()
|
||||
{
|
||||
DataContext = viewModel;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<UserControl xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:popup="clr-namespace:Nebula.Launcher.ViewModels.Popup"
|
||||
xmlns:controls="clr-namespace:Nebula.Launcher.Controls"
|
||||
xmlns:services="clr-namespace:Nebula.Launcher.Services"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
x:Class="Nebula.Launcher.Views.Popup.IsLoginCredentialsNullPopupView"
|
||||
x:DataType="popup:IsLoginCredentialsNullPopupViewModel">
|
||||
<Design.DataContext>
|
||||
<popup:IsLoginCredentialsNullPopupViewModel />
|
||||
</Design.DataContext>
|
||||
|
||||
<StackPanel Margin="15" Orientation="Vertical" Spacing="15">
|
||||
<TextBlock HorizontalAlignment="Center" Text="{services:LocaledText popup-login-credentials-warning-label}" TextWrapping="Wrap"/>
|
||||
<StackPanel HorizontalAlignment="Center" Orientation="Horizontal" Spacing="5">
|
||||
<Border Background="{StaticResource DefaultSelected}" BoxShadow="{StaticResource DefaultShadow}">
|
||||
<Button Command="{Binding GotoAuthPage}">
|
||||
<TextBlock Text="{services:LocaledText popup-login-credentials-warning-go-auth}"/>
|
||||
</Button>
|
||||
</Border>
|
||||
<Border Background="{StaticResource DefaultSelected}" BoxShadow="{StaticResource DefaultShadow}">
|
||||
<Button Command="{Binding Cancel}">
|
||||
<TextBlock Text="{services:LocaledText popup-login-credentials-warning-cancel}"/>
|
||||
</Button>
|
||||
</Border>
|
||||
<Border Background="{StaticResource DefaultSelected}" BoxShadow="{StaticResource DefaultShadow}">
|
||||
<Button Command="{Binding Proceed}">
|
||||
<TextBlock Text="{services:LocaledText popup-login-credentials-warning-proceed}"/>
|
||||
</Button>
|
||||
</Border>
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,11 @@
|
||||
using Avalonia.Controls;
|
||||
|
||||
namespace Nebula.Launcher.Views.Popup;
|
||||
|
||||
public partial class IsLoginCredentialsNullPopupView : UserControl
|
||||
{
|
||||
public IsLoginCredentialsNullPopupView()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
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:customControls="clr-namespace:Nebula.Launcher.Controls"
|
||||
xmlns:popup="clr-namespace:Nebula.Launcher.ViewModels.Popup"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
x:Class="Nebula.Launcher.Views.Popup.LoadingContextView"
|
||||
@@ -29,7 +30,7 @@
|
||||
VerticalAlignment="Center"
|
||||
Command="{Binding Cancel}"
|
||||
IsVisible="{Binding IsCancellable}">
|
||||
<Label>Cancel</Label>
|
||||
<customControls:LocalizedLabel LocalId="task-cancel"/>
|
||||
</Button>
|
||||
</Panel>
|
||||
</StackPanel>
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using Avalonia.Controls;
|
||||
using LoadingContextViewModel = Nebula.Launcher.ViewModels.Popup.LoadingContextViewModel;
|
||||
|
||||
namespace Nebula.Launcher.Views.Popup;
|
||||
|
||||
@@ -9,9 +8,4 @@ public partial class LoadingContextView : UserControl
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public LoadingContextView(LoadingContextViewModel viewModel) : this()
|
||||
{
|
||||
DataContext = viewModel;
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:viewModels="clr-namespace:Nebula.Launcher.ViewModels"
|
||||
xmlns:popup="clr-namespace:Nebula.Launcher.ViewModels.Popup"
|
||||
xmlns:models="clr-namespace:Nebula.Launcher.Models"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
x:Class="Nebula.Launcher.Views.Popup.LogPopupView"
|
||||
x:DataType="popup:LogPopupModelView">
|
||||
@@ -17,7 +18,7 @@
|
||||
ItemsSource="{Binding Logs}"
|
||||
Padding="0">
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate DataType="{x:Type viewModels:LogInfo}">
|
||||
<DataTemplate DataType="{x:Type models:LogInfo}">
|
||||
<Border CornerRadius="5" Margin="0,0,0,5">
|
||||
<StackPanel Orientation="Horizontal" Spacing="5" Margin="0">
|
||||
<Border MinWidth="100"
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using Avalonia.Controls;
|
||||
using Nebula.Launcher.ViewModels.Popup;
|
||||
|
||||
namespace Nebula.Launcher.Views.Popup;
|
||||
|
||||
@@ -9,9 +8,4 @@ public partial class LogPopupView : UserControl
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public LogPopupView(LogPopupModelView viewModel) : this()
|
||||
{
|
||||
DataContext = viewModel;
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
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:customControls="clr-namespace:Nebula.Launcher.Controls"
|
||||
xmlns:popup="clr-namespace:Nebula.Launcher.ViewModels.Popup"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
x:Class="Nebula.Launcher.Views.Popup.TfaView">
|
||||
@@ -9,7 +10,7 @@
|
||||
<popup:TfaViewModel />
|
||||
</Design.DataContext>
|
||||
<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">
|
||||
<Border BoxShadow="{StaticResource DefaultShadow}">
|
||||
<TextBox MaxLength="1"/>
|
||||
@@ -32,7 +33,7 @@
|
||||
</StackPanel>
|
||||
<Border BoxShadow="{StaticResource DefaultShadow}" Background="{StaticResource DefaultSelected}" HorizontalAlignment="Center">
|
||||
<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>
|
||||
</Border>
|
||||
</StackPanel>
|
||||
|
||||
@@ -1,11 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Input;
|
||||
using Avalonia.Interactivity;
|
||||
using Avalonia.Markup.Xaml;
|
||||
using Nebula.Launcher.ViewModels.Popup;
|
||||
|
||||
namespace Nebula.Launcher.Views.Popup;
|
||||
@@ -88,11 +85,6 @@ public partial class TfaView : UserControl
|
||||
return (TextBox)box.Child!;
|
||||
}
|
||||
|
||||
public TfaView(TfaViewModel tfaViewModel) : this()
|
||||
{
|
||||
DataContext = tfaViewModel;
|
||||
}
|
||||
|
||||
private void Button_OnClick(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
CheckupCode();
|
||||
|
||||
78
Nebula.Launcher/Views/ServerCompoundEntryView.axaml
Normal file
78
Nebula.Launcher/Views/ServerCompoundEntryView.axaml
Normal file
@@ -0,0 +1,78 @@
|
||||
<UserControl xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:viewModels="clr-namespace:Nebula.Launcher.ViewModels"
|
||||
xmlns:views="clr-namespace:Nebula.Launcher.Views"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
x:Class="Nebula.Launcher.Views.ServerCompoundEntryView"
|
||||
x:DataType="viewModels:ServerCompoundEntryViewModel">
|
||||
<Design.DataContext>
|
||||
<viewModels:ServerCompoundEntryViewModel />
|
||||
</Design.DataContext>
|
||||
|
||||
<Panel>
|
||||
<Border IsVisible="{Binding Loading}"
|
||||
Background="{StaticResource DefaultGrad}"
|
||||
BoxShadow="-2 0 5 -1 #121212"
|
||||
CornerRadius="10"
|
||||
Margin="5">
|
||||
|
||||
<Grid ColumnDefinitions="*,80,50,50" RowDefinitions="35,*,*">
|
||||
<Border
|
||||
Background="Transparent"
|
||||
BoxShadow="0 3 3 -2 #121212"
|
||||
CornerRadius="10"
|
||||
Grid.Column="0"
|
||||
Grid.ColumnSpan="2"
|
||||
Grid.Row="0"/>
|
||||
|
||||
<ScrollViewer
|
||||
Grid.Column="0"
|
||||
Grid.Row="0"
|
||||
HorizontalAlignment="Stretch"
|
||||
VerticalAlignment="Stretch"
|
||||
HorizontalScrollBarVisibility="Hidden"
|
||||
Margin="10,0,0,0"
|
||||
VerticalScrollBarVisibility="Disabled"
|
||||
x:Name="AutoScrollViewer">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<Label VerticalAlignment="Center">
|
||||
<TextBlock Text="{Binding Name}" />
|
||||
</Label>
|
||||
<Label VerticalAlignment="Center">
|
||||
<TextBlock Text="{Binding Message}" />
|
||||
</Label>
|
||||
</StackPanel>
|
||||
</ScrollViewer>
|
||||
|
||||
<Panel
|
||||
Grid.Column="2"
|
||||
Grid.Row="0"
|
||||
Margin="5,0,0,0">
|
||||
<Button
|
||||
Command="{Binding ToggleFavorites}"
|
||||
CornerRadius="10,10,10,10"
|
||||
HorizontalAlignment="Stretch"
|
||||
IsVisible="{Binding !IsFavorite}"
|
||||
VerticalAlignment="Stretch">
|
||||
<Svg Margin="4" Path="/Assets/svg/star.svg" />
|
||||
</Button>
|
||||
<Button
|
||||
Command="{Binding ToggleFavorites}"
|
||||
CornerRadius="10,10,10,10"
|
||||
HorizontalAlignment="Stretch"
|
||||
IsVisible="{Binding IsFavorite}"
|
||||
VerticalAlignment="Stretch">
|
||||
<Svg Margin="4" Path="/Assets/svg/starfull.svg" />
|
||||
</Button>
|
||||
</Panel>
|
||||
</Grid>
|
||||
</Border>
|
||||
|
||||
<Panel IsVisible="{Binding !Loading}">
|
||||
<views:ServerEntryView IsVisible="{Binding !Loading}" DataContext="{Binding CurrentEntry}"/>
|
||||
</Panel>
|
||||
|
||||
</Panel>
|
||||
</UserControl>
|
||||
11
Nebula.Launcher/Views/ServerCompoundEntryView.axaml.cs
Normal file
11
Nebula.Launcher/Views/ServerCompoundEntryView.axaml.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
using Avalonia.Controls;
|
||||
|
||||
namespace Nebula.Launcher.Views;
|
||||
|
||||
public partial class ServerCompoundEntryView : UserControl
|
||||
{
|
||||
public ServerCompoundEntryView()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,7 @@
|
||||
xmlns:viewModels="clr-namespace:Nebula.Launcher.ViewModels"
|
||||
xmlns:views="clr-namespace:Nebula.Launcher.Views"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:services="clr-namespace:Nebula.Launcher.Services"
|
||||
IsVisible="{Binding IsVisible}">
|
||||
<Design.DataContext>
|
||||
<viewModels:ServerEntryModelView />
|
||||
@@ -24,7 +25,7 @@
|
||||
CornerRadius="10"
|
||||
Margin="5">
|
||||
|
||||
<Grid ColumnDefinitions="*,80,50,50" RowDefinitions="35,*,*">
|
||||
<Grid ColumnDefinitions="*,80,50,50,50" RowDefinitions="35,*,*">
|
||||
<Border
|
||||
Background="Transparent"
|
||||
BoxShadow="0 3 3 -2 #121212"
|
||||
@@ -47,7 +48,7 @@
|
||||
VerticalScrollBarVisibility="Disabled"
|
||||
x:Name="AutoScrollViewer">
|
||||
<Label VerticalAlignment="Center">
|
||||
<TextBlock Text="{Binding Status.Name}" />
|
||||
<TextBlock Text="{Binding RealName}" />
|
||||
</Label>
|
||||
</ScrollViewer>
|
||||
</Button>
|
||||
@@ -67,9 +68,19 @@
|
||||
</Label>
|
||||
</StackPanel>
|
||||
|
||||
<Panel
|
||||
<Button
|
||||
Grid.Column="2"
|
||||
Grid.Row="0"
|
||||
Command="{Binding EditName}"
|
||||
CornerRadius="10,10,10,10"
|
||||
HorizontalAlignment="Stretch"
|
||||
VerticalAlignment="Stretch">
|
||||
<Svg Margin="4" Path="/Assets/svg/pencil.svg" />
|
||||
</Button>
|
||||
|
||||
<Panel
|
||||
Grid.Column="3"
|
||||
Grid.Row="0"
|
||||
Margin="5,0,0,0">
|
||||
<Button
|
||||
Command="{Binding ToggleFavorites}"
|
||||
@@ -90,7 +101,7 @@
|
||||
</Panel>
|
||||
|
||||
<Panel
|
||||
Grid.Column="3"
|
||||
Grid.Column="4"
|
||||
Grid.Row="0"
|
||||
Margin="5,0,0,0">
|
||||
<Button
|
||||
@@ -134,7 +145,7 @@
|
||||
Margin="5">
|
||||
<StackPanel Margin="5" Spacing="5">
|
||||
<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.ItemTemplate>
|
||||
<DataTemplate DataType="{x:Type system:String}">
|
||||
@@ -165,7 +176,7 @@
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<Label FontSize="10" VerticalAlignment="Center">Map:</Label>
|
||||
<Label FontSize="10" VerticalAlignment="Center" Content="{services:LocaledText serverentry-map}"/>
|
||||
<Border
|
||||
Background="{StaticResource DefaultForeground}"
|
||||
BorderThickness="0"
|
||||
@@ -180,7 +191,7 @@
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<Label FontSize="10" VerticalAlignment="Center">Preset:</Label>
|
||||
<Label FontSize="10" VerticalAlignment="Center" Content="{services:LocaledText serverentry-preset}"/>
|
||||
<Border
|
||||
Background="{StaticResource DefaultForeground}"
|
||||
BorderThickness="0"
|
||||
|
||||
@@ -22,10 +22,7 @@ public partial class ServerEntryView : UserControl
|
||||
StartAutoScrolling();
|
||||
}
|
||||
|
||||
public ServerEntryView(ServerEntryModelView modelView) : this()
|
||||
{
|
||||
DataContext = modelView;
|
||||
}
|
||||
|
||||
|
||||
private void StartAutoScrolling()
|
||||
{
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using Nebula.Runner.Services;
|
||||
using Nebula.Shared;
|
||||
using Nebula.Shared.Models;
|
||||
using Nebula.Shared.Services;
|
||||
@@ -27,11 +28,7 @@ public sealed class App(RunnerService runnerService, ContentService contentServi
|
||||
|
||||
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,
|
||||
|
||||
// Tell game we are launcher
|
||||
"--cvar", "launch.launcher=true"
|
||||
};
|
||||
|
||||
@@ -39,9 +36,6 @@ public sealed class App(RunnerService runnerService, ContentService contentServi
|
||||
if (!string.IsNullOrEmpty(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("--connect-address");
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Lib.Harmony" Version="2.3.6" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.0"/>
|
||||
<PackageReference Include="SharpZstd.Interop" Version="1.5.6"/>
|
||||
</ItemGroup>
|
||||
|
||||
54
Nebula.Runner/Services/HarmonyService.cs
Normal file
54
Nebula.Runner/Services/HarmonyService.cs
Normal file
@@ -0,0 +1,54 @@
|
||||
using System.Data;
|
||||
using HarmonyLib;
|
||||
using Nebula.Shared;
|
||||
|
||||
namespace Nebula.Runner.Services;
|
||||
|
||||
[ServiceRegister]
|
||||
public class HarmonyService(ReflectionService reflectionService)
|
||||
{
|
||||
private HarmonyInstance? _instance;
|
||||
|
||||
public HarmonyInstance Instance
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_instance is null)
|
||||
CreateInstance();
|
||||
return _instance!;
|
||||
}
|
||||
}
|
||||
|
||||
public void CreateInstance()
|
||||
{
|
||||
if (_instance is not null)
|
||||
throw new Exception();
|
||||
|
||||
_instance = new HarmonyInstance();
|
||||
UnShittyWizard();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Я помню пенис большой,Я помню пенис большой, Я помню пенис большой, я помню....
|
||||
/// </summary>
|
||||
private void UnShittyWizard()
|
||||
{
|
||||
var method = reflectionService.GetType("Robust.Client.GameController").TypeInitializer;
|
||||
_instance!.Harmony.Patch(method, new HarmonyMethod(Prefix));
|
||||
}
|
||||
|
||||
static bool Prefix()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public class HarmonyInstance
|
||||
{
|
||||
public readonly Harmony Harmony;
|
||||
|
||||
internal HarmonyInstance()
|
||||
{
|
||||
Harmony = new Harmony("ru.cinka.patch");
|
||||
}
|
||||
}
|
||||
59
Nebula.Runner/Services/ReflectionService.cs
Normal file
59
Nebula.Runner/Services/ReflectionService.cs
Normal file
@@ -0,0 +1,59 @@
|
||||
using System.Reflection;
|
||||
using Nebula.Shared;
|
||||
using Nebula.Shared.FileApis;
|
||||
using Nebula.Shared.Services;
|
||||
|
||||
namespace Nebula.Runner.Services;
|
||||
|
||||
[ServiceRegister]
|
||||
public class ReflectionService(AssemblyService assemblyService)
|
||||
{
|
||||
private Dictionary<string, Assembly> _typeCache = new();
|
||||
|
||||
public void RegisterAssembly(Assembly robustAssembly)
|
||||
{
|
||||
_typeCache.Add(robustAssembly.GetName().Name!, robustAssembly);
|
||||
}
|
||||
|
||||
public void RegisterRobustAssemblies(AssemblyApi engine)
|
||||
{
|
||||
RegisterAssembly(GetRobustAssembly("Robust.Shared", engine));
|
||||
RegisterAssembly(GetRobustAssembly("Robust.Client", engine));
|
||||
}
|
||||
|
||||
private Assembly GetRobustAssembly(string assemblyName, AssemblyApi engine)
|
||||
{
|
||||
if(!assemblyService.TryOpenAssembly(assemblyName, engine, out var assembly))
|
||||
throw new Exception($"Unable to locate {assemblyName}.dll in engine build!");
|
||||
return assembly;
|
||||
}
|
||||
|
||||
public Type? GetTypeImp(string name)
|
||||
{
|
||||
foreach (var (prefix,assembly) in _typeCache)
|
||||
{
|
||||
string appendedName = prefix + name;
|
||||
var theType = assembly.GetType(appendedName);
|
||||
if (theType != null)
|
||||
{
|
||||
return theType;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public Type GetType(string name)
|
||||
{
|
||||
var prefix = ExtrackPrefix(name);
|
||||
return !_typeCache.TryGetValue(prefix, out var assembly)
|
||||
? GetTypeImp(name)!
|
||||
: assembly.GetType(name)!;
|
||||
}
|
||||
|
||||
private string ExtrackPrefix(string path)
|
||||
{
|
||||
var sp = path.Split(".");
|
||||
return sp[0] + "." + sp[1];
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,14 @@
|
||||
using Nebula.Shared.Models;
|
||||
using System.Globalization;
|
||||
using System.Reflection;
|
||||
using System.Reflection.Emit;
|
||||
using HarmonyLib;
|
||||
using Nebula.Shared;
|
||||
using Nebula.Shared.Models;
|
||||
using Nebula.Shared.Services;
|
||||
using Nebula.Shared.Services.Logging;
|
||||
using Robust.LoaderApi;
|
||||
|
||||
namespace Nebula.Shared.Services;
|
||||
namespace Nebula.Runner.Services;
|
||||
|
||||
[ServiceRegister]
|
||||
public sealed class RunnerService(
|
||||
@@ -10,23 +16,12 @@ public sealed class RunnerService(
|
||||
DebugService debugService,
|
||||
ConfigurationService varService,
|
||||
EngineService engineService,
|
||||
AssemblyService assemblyService)
|
||||
AssemblyService assemblyService,
|
||||
ReflectionService reflectionService,
|
||||
HarmonyService harmonyService)
|
||||
{
|
||||
private ILogger _logger = debugService.GetLogger("RunnerService");
|
||||
|
||||
public async Task PrepareRun(RobustBuildInfo buildInfo, ILoadingHandler loadingHandler,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
_logger.Log("Prepare 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);
|
||||
|
||||
await contentService.EnsureItems(buildInfo.RobustManifestInfo, loadingHandler, cancellationToken);
|
||||
await engineService.EnsureEngineModules("Robust.Client.WebView", buildInfo.BuildInfo.Build.EngineVersion);
|
||||
}
|
||||
private bool MetricEnabled = false; //TODO: ADD METRIC THINKS LATER
|
||||
|
||||
public async Task Run(string[] runArgs, RobustBuildInfo buildInfo, IRedialApi redialApi,
|
||||
ILoadingHandler loadingHandler,
|
||||
@@ -70,7 +65,77 @@ public sealed class RunnerService(
|
||||
if (!assemblyService.TryGetLoader(clientAssembly, out var loader))
|
||||
return;
|
||||
|
||||
if(!assemblyService.TryOpenAssembly("Prometheus.NetStandard", engine, out var prometheusAssembly))
|
||||
return;
|
||||
|
||||
reflectionService.RegisterRobustAssemblies(engine);
|
||||
harmonyService.CreateInstance();
|
||||
|
||||
IDisposable? metricServer = null;
|
||||
|
||||
if (MetricEnabled)
|
||||
{
|
||||
MetricsEnabledPatcher.ApplyPatch(reflectionService, harmonyService);
|
||||
metricServer = RunHelper.RunMetric(prometheusAssembly);
|
||||
}
|
||||
|
||||
|
||||
await Task.Run(() => loader.Main(args), cancellationToken);
|
||||
|
||||
metricServer?.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
public static class MetricsEnabledPatcher
|
||||
{
|
||||
public static void ApplyPatch(ReflectionService reflectionService, HarmonyService harmonyService)
|
||||
{
|
||||
var harmony = harmonyService.Instance.Harmony;
|
||||
|
||||
var targetType = reflectionService.GetType("Robust.Shared.GameObjects.EntitySystemManager");
|
||||
var targetMethod = targetType.GetProperty("MetricsEnabled").GetGetMethod();
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,14 +7,14 @@ public static class CurrentConVar
|
||||
{
|
||||
public static readonly ConVar<string[]> EngineManifestUrl =
|
||||
ConVarBuilder.Build<string[]>("engine.manifestUrl", [
|
||||
"https://robust-builds.cdn.spacestation14.com/manifest.json",
|
||||
"https://harpy.durenko.tatar/manifests/manifest",
|
||||
"https://robust-builds.fallback.cdn.spacestation14.com/manifest.json"
|
||||
]);
|
||||
|
||||
public static readonly ConVar<string[]> EngineModuleManifestUrl =
|
||||
ConVarBuilder.Build<string[]>("engine.moduleManifestUrl",
|
||||
[
|
||||
"https://robust-builds.cdn.spacestation14.com/modules.json",
|
||||
"https://harpy.durenko.tatar/manifests/modules",
|
||||
"https://robust-builds.fallback.cdn.spacestation14.com/modules.json"
|
||||
]);
|
||||
|
||||
@@ -28,6 +28,8 @@ public static class CurrentConVar
|
||||
ConVarBuilder.Build<Dictionary<string, EngineVersionInfo>>("engine.manifest.backup");
|
||||
public static readonly ConVar<ModulesInfo> ModuleManifestBackup =
|
||||
ConVarBuilder.Build<ModulesInfo>("module.manifest.backup");
|
||||
public static readonly ConVar<Dictionary<string, string>> ServerManifestHash =
|
||||
ConVarBuilder.Build<Dictionary<string, string>>("server.manifest.hash",[]);
|
||||
|
||||
public static readonly ConVar<Dictionary<string,string>> DotnetUrl = ConVarBuilder.Build<Dictionary<string,string>>("dotnet.url",
|
||||
new(){
|
||||
|
||||
@@ -1,74 +0,0 @@
|
||||
using System.Net;
|
||||
using FluentFTP;
|
||||
using Nebula.Shared.FileApis.Interfaces;
|
||||
|
||||
namespace Nebula.Shared.FileApis;
|
||||
|
||||
public class FtpFileApi : IWriteFileApi, IDisposable
|
||||
{
|
||||
private readonly string _ftpHost;
|
||||
private readonly string _username;
|
||||
private readonly string _password;
|
||||
|
||||
private readonly FtpClient Client;
|
||||
|
||||
public FtpFileApi(string ftpHost, string username, string password)
|
||||
{
|
||||
_ftpHost = ftpHost;
|
||||
_username = username;
|
||||
_password = password;
|
||||
Client = CreateClient();
|
||||
Client.AutoConnect();
|
||||
}
|
||||
|
||||
public bool Save(string path, Stream input)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = Client.UploadStream(input, path, FtpRemoteExists.Overwrite, true);
|
||||
return result == FtpStatus.Success;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public bool Remove(string path)
|
||||
{
|
||||
try
|
||||
{
|
||||
Client.DeleteFile(path);
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public bool Has(string path)
|
||||
{
|
||||
try
|
||||
{
|
||||
return Client.FileExists(path);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private FtpClient CreateClient()
|
||||
{
|
||||
var client = new FtpClient(_ftpHost, _username, _password);
|
||||
client.Config.EncryptionMode = FtpEncryptionMode.None;
|
||||
client.Config.ValidateAnyCertificate = true;
|
||||
return client;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Client.Dispose();
|
||||
}
|
||||
}
|
||||
@@ -55,6 +55,11 @@ public class HashApi : IFileApi
|
||||
return _fileApi.Has(GetManifestPath(item));
|
||||
}
|
||||
|
||||
public bool Remove(RobustManifestItem item)
|
||||
{
|
||||
return _fileApi.Remove(GetManifestPath(item));
|
||||
}
|
||||
|
||||
private string GetManifestPath(RobustManifestItem item){
|
||||
return GetManifestPath(item.Hash);
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ public sealed record ServerInfo(
|
||||
[property: JsonPropertyName("auth")] AuthInfo Auth,
|
||||
[property: JsonPropertyName("build")] BuildInfo Build,
|
||||
[property: JsonPropertyName("desc")] string Desc,
|
||||
[property: JsonPropertyName("links")] List<ServerLink> Links);
|
||||
[property: JsonPropertyName("links")] List<ServerLink>? Links);
|
||||
|
||||
public sealed record EngineVersionInfo(
|
||||
[property: JsonPropertyName("insecure")]
|
||||
|
||||
@@ -11,7 +11,6 @@
|
||||
<EmbeddedResource Include="Utils\runtime.json">
|
||||
<LogicalName>Utility.runtime.json</LogicalName>
|
||||
</EmbeddedResource>
|
||||
<PackageReference Include="FluentFTP" Version="52.1.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="9.0.0" />
|
||||
<PackageReference Include="Robust.Natives" Version="0.1.1" />
|
||||
<PackageReference Include="SharpZstd.Interop" Version="1.5.6" />
|
||||
|
||||
@@ -53,25 +53,21 @@ public class AuthService(
|
||||
SelectedAuth = null;
|
||||
}
|
||||
|
||||
public async Task<bool> SetAuth(CurrentAuthInfo info)
|
||||
public async Task SetAuth(CurrentAuthInfo info)
|
||||
{
|
||||
SelectedAuth = info;
|
||||
return await EnsureToken();
|
||||
await EnsureToken();
|
||||
}
|
||||
|
||||
public async Task<bool> EnsureToken()
|
||||
public async Task EnsureToken()
|
||||
{
|
||||
if (SelectedAuth is null) return false;
|
||||
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);
|
||||
requestMessage.Headers.Authorization = new AuthenticationHeaderValue("SS14Auth", SelectedAuth.Token.Token);
|
||||
using var resp = await _httpClient.SendAsync(requestMessage, cancellationService.Token);
|
||||
|
||||
if (!resp.IsSuccessStatusCode) SelectedAuth = null;
|
||||
|
||||
return resp.IsSuccessStatusCode;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,8 @@ namespace Nebula.Shared.Services;
|
||||
|
||||
public class ConVar<T>
|
||||
{
|
||||
internal ConfigurationService.OnConfigurationChangedDelegate<T?>? OnValueChanged;
|
||||
|
||||
public ConVar(string name, T? defaultValue = default)
|
||||
{
|
||||
Name = name ?? throw new ArgumentNullException(nameof(name));
|
||||
@@ -45,12 +47,17 @@ public class ConfigurationService
|
||||
ConfigurationApi = fileService.CreateFileApi("config");
|
||||
}
|
||||
|
||||
private void SubscribeVarChanged<T>(ConVar<T> convar, OnConfigurationChangedDelegate<T> @delegate)
|
||||
public ConfigChangeSubscriberDisposable<T> SubscribeVarChanged<T>(ConVar<T> convar, OnConfigurationChangedDelegate<T?> @delegate, bool invokeNow = false)
|
||||
{
|
||||
convar.OnValueChanged += @delegate;
|
||||
if (invokeNow)
|
||||
{
|
||||
@delegate(GetConfigValue(convar));
|
||||
}
|
||||
|
||||
return new ConfigChangeSubscriberDisposable<T>(convar, @delegate);
|
||||
}
|
||||
|
||||
|
||||
public T? GetConfigValue<T>(ConVar<T> conVar)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(conVar);
|
||||
@@ -105,10 +112,14 @@ public class ConfigurationService
|
||||
return false;
|
||||
}
|
||||
|
||||
public void SetConfigValue<T>(ConVar<T> conVar, T value)
|
||||
public void SetConfigValue<T>(ConVar<T> conVar, T? value)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(conVar);
|
||||
if (value == null) throw new ArgumentNullException(nameof(value));
|
||||
if (value == null)
|
||||
{
|
||||
ConfigurationApi.Remove(GetFileName(conVar));
|
||||
conVar.OnValueChanged?.Invoke(conVar.DefaultValue);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!conVar.Type.IsInstanceOfType(value))
|
||||
{
|
||||
@@ -129,6 +140,7 @@ public class ConfigurationService
|
||||
stream.Seek(0, SeekOrigin.Begin);
|
||||
|
||||
ConfigurationApi.Save(GetFileName(conVar), stream);
|
||||
conVar.OnValueChanged?.Invoke(value);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@@ -141,3 +153,19 @@ public class ConfigurationService
|
||||
return $"{conVar.Name}.json";
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class ConfigChangeSubscriberDisposable<T> : IDisposable
|
||||
{
|
||||
private readonly ConVar<T> _convar;
|
||||
private readonly ConfigurationService.OnConfigurationChangedDelegate<T> _delegate;
|
||||
|
||||
public ConfigChangeSubscriberDisposable(ConVar<T> convar, ConfigurationService.OnConfigurationChangedDelegate<T> @delegate)
|
||||
{
|
||||
_convar = convar;
|
||||
_delegate = @delegate;
|
||||
}
|
||||
public void Dispose()
|
||||
{
|
||||
_convar.OnValueChanged -= _delegate;
|
||||
}
|
||||
}
|
||||
@@ -14,9 +14,23 @@ public partial class ContentService
|
||||
public readonly IReadWriteFileApi ContentFileApi = fileService.CreateFileApi("content");
|
||||
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,
|
||||
@@ -34,7 +48,7 @@ public partial class ContentService
|
||||
allItems.Add(item.Value);
|
||||
}
|
||||
|
||||
var hashApi = new HashApi(allItems, ContentFileApi);
|
||||
var hashApi = CreateHashApi(allItems);
|
||||
|
||||
items = allItems.Where(a=> !hashApi.Has(a)).ToList();
|
||||
|
||||
@@ -55,6 +69,8 @@ public partial class ContentService
|
||||
return await EnsureItems(new ManifestReader(stream), info.DownloadUri, loadingHandler, cancellationToken);
|
||||
}
|
||||
|
||||
SetServerHash(info.ManifestUri.ToString(), info.Hash);
|
||||
|
||||
_logger.Log("Fetching manifest from: " + info.ManifestUri);
|
||||
|
||||
var response = await _http.GetAsync(info.ManifestUri, cancellationToken);
|
||||
|
||||
@@ -9,7 +9,7 @@ public partial class ContentService
|
||||
{
|
||||
_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;
|
||||
|
||||
_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;
|
||||
|
||||
namespace Nebula.Shared.Services;
|
||||
@@ -28,4 +27,10 @@ public partial class ContentService(
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
public void RemoveAllContent(ILoadingHandler loadingHandler, CancellationToken cancellationToken)
|
||||
{
|
||||
fileService.RemoveAllFiles("content", loadingHandler, cancellationToken);
|
||||
fileService.RemoveAllFiles("manifest", loadingHandler, cancellationToken);
|
||||
}
|
||||
}
|
||||
@@ -73,16 +73,18 @@ internal class ServiceLogger : ILogger
|
||||
|
||||
if(!Directory.Exists(directory)) Directory.CreateDirectory(directory);
|
||||
|
||||
_fileStream = File.Open(Path.Combine(directory,$"{Category}.log"), FileMode.Create, FileAccess.Write, FileShare.Read);
|
||||
_streamWriter = new StreamWriter(_fileStream);
|
||||
_path = Path.Combine(directory, $"{Category}.log");
|
||||
|
||||
File.Create(_path).Dispose();
|
||||
}
|
||||
|
||||
public string Category { get; init; }
|
||||
|
||||
private Dictionary<string, ServiceLogger> Childs { get; init; } = new();
|
||||
|
||||
private readonly FileStream _fileStream;
|
||||
private readonly StreamWriter _streamWriter;
|
||||
private FileStream? _fileStream;
|
||||
private StreamWriter? _streamWriter;
|
||||
private readonly string _path;
|
||||
|
||||
public ServiceLogger GetLogger(string category)
|
||||
{
|
||||
@@ -109,17 +111,25 @@ internal class ServiceLogger : ILogger
|
||||
private void LogToFile(string output)
|
||||
{
|
||||
if(!DebugService.DoFileLog) return;
|
||||
_fileStream = File.Open(_path, FileMode.Append, FileAccess.Write, FileShare.ReadWrite);
|
||||
_streamWriter = new StreamWriter(_fileStream);
|
||||
Root?.LogToFile(output);
|
||||
_streamWriter.WriteLine(output);
|
||||
_streamWriter.Flush();
|
||||
|
||||
_streamWriter.Dispose();
|
||||
_fileStream.Dispose();
|
||||
|
||||
_fileStream = null;
|
||||
_streamWriter = null;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (!DebugService.DoFileLog) return;
|
||||
|
||||
_streamWriter.Dispose();
|
||||
_fileStream.Dispose();
|
||||
_streamWriter?.Dispose();
|
||||
_fileStream?.Dispose();
|
||||
foreach (var (_, child) in Childs)
|
||||
{
|
||||
child.Dispose();
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
using System.IO.Compression;
|
||||
using System.Runtime.InteropServices;
|
||||
using Nebula.Shared.FileApis;
|
||||
using Nebula.Shared.FileApis.Interfaces;
|
||||
using Nebula.Shared.Models;
|
||||
using Nebula.Shared.Services.Logging;
|
||||
using Robust.LoaderApi;
|
||||
|
||||
namespace Nebula.Shared.Services;
|
||||
@@ -10,14 +10,14 @@ namespace Nebula.Shared.Services;
|
||||
[ServiceRegister]
|
||||
public class FileService
|
||||
{
|
||||
public static readonly string RootPath = Path.Join(Environment.GetFolderPath(
|
||||
public static string RootPath = Path.Join(Environment.GetFolderPath(
|
||||
Environment.SpecialFolder.ApplicationData), "Datum");
|
||||
|
||||
private readonly DebugService _debugService;
|
||||
private readonly ILogger _logger;
|
||||
|
||||
public FileService(DebugService debugService)
|
||||
{
|
||||
_debugService = debugService;
|
||||
_logger = debugService.GetLogger(this);
|
||||
|
||||
if(!Directory.Exists(RootPath))
|
||||
Directory.CreateDirectory(RootPath);
|
||||
@@ -25,6 +25,7 @@ public class FileService
|
||||
|
||||
public IReadWriteFileApi CreateFileApi(string path)
|
||||
{
|
||||
_logger.Debug($"Creating file api for {path}");
|
||||
return new FileApi(Path.Join(RootPath, path));
|
||||
}
|
||||
|
||||
@@ -32,6 +33,7 @@ public class FileService
|
||||
{
|
||||
path = Path.Combine(Path.GetTempPath(), "tempThink"+Path.GetRandomFileName());
|
||||
Directory.CreateDirectory(path);
|
||||
_logger.Debug($"Ensuring temp directory for {path}");
|
||||
return new FileApi(path);
|
||||
}
|
||||
|
||||
@@ -53,6 +55,38 @@ public class FileService
|
||||
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
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using System.Diagnostics.Contracts;
|
||||
using System.Globalization;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
@@ -10,7 +11,7 @@ namespace Nebula.Shared.Services;
|
||||
[ServiceRegister]
|
||||
public class RestService
|
||||
{
|
||||
private readonly HttpClient _client = new();
|
||||
private readonly HttpClient _client;
|
||||
private readonly ILogger _logger;
|
||||
|
||||
private readonly JsonSerializerOptions _serializerOptions = new()
|
||||
@@ -19,17 +20,20 @@ public class RestService
|
||||
WriteIndented = true
|
||||
};
|
||||
|
||||
public RestService(DebugService debug)
|
||||
public RestService(DebugService debug, HttpClient? client = null)
|
||||
{
|
||||
_client = client ?? new HttpClient();
|
||||
_logger = debug.GetLogger(this);
|
||||
}
|
||||
|
||||
[Pure]
|
||||
public async Task<T> GetAsync<T>(Uri uri, CancellationToken cancellationToken) where T : notnull
|
||||
{
|
||||
var response = await _client.GetAsync(uri, cancellationToken);
|
||||
return await ReadResult<T>(response, cancellationToken, uri);
|
||||
}
|
||||
|
||||
[Pure]
|
||||
public async Task<T> GetAsyncDefault<T>(Uri uri, T defaultValue, CancellationToken cancellationToken) where T : notnull
|
||||
{
|
||||
try
|
||||
@@ -43,6 +47,7 @@ public class RestService
|
||||
}
|
||||
}
|
||||
|
||||
[Pure]
|
||||
public async Task<K> PostAsync<K, T>(T information, Uri uri, CancellationToken cancellationToken) where K : notnull
|
||||
{
|
||||
var json = JsonSerializer.Serialize(information, _serializerOptions);
|
||||
@@ -51,6 +56,7 @@ public class RestService
|
||||
return await ReadResult<K>(response, cancellationToken, uri);
|
||||
}
|
||||
|
||||
[Pure]
|
||||
public async Task<T> PostAsync<T>(Stream stream, Uri uri, CancellationToken cancellationToken) where T : notnull
|
||||
{
|
||||
using var multipartFormContent =
|
||||
@@ -60,12 +66,14 @@ public class RestService
|
||||
return await ReadResult<T>(response, cancellationToken, uri);
|
||||
}
|
||||
|
||||
[Pure]
|
||||
public async Task<T> DeleteAsync<T>(Uri uri, CancellationToken cancellationToken) where T : notnull
|
||||
{
|
||||
var response = await _client.DeleteAsync(uri, cancellationToken);
|
||||
return await ReadResult<T>(response, cancellationToken, uri);
|
||||
}
|
||||
|
||||
[Pure]
|
||||
private async Task<T> ReadResult<T>(HttpResponseMessage response, CancellationToken cancellationToken, Uri uri) where T : notnull
|
||||
{
|
||||
var content = await response.Content.ReadAsStringAsync(cancellationToken);
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user