- tweak: file managment
This commit is contained in:
@@ -80,18 +80,19 @@ public partial class AccountInfoViewModel : ViewModelBase
|
||||
|
||||
public async void DoAuth()
|
||||
{
|
||||
_popupMessageService.Popup("Auth think, please wait...");
|
||||
var message = GetViewModel<InfoPopupViewModel>();
|
||||
message.InfoText = "Auth think, please wait...";
|
||||
_popupMessageService.Popup(message);
|
||||
|
||||
if(await _authService.Auth(CurrentAlp))
|
||||
{
|
||||
_popupMessageService.ClosePopup();
|
||||
_popupMessageService.Popup("Hello, " + _authService.SelectedAuth!.AuthLoginPassword.Login);
|
||||
message.Dispose();
|
||||
IsLogged = true;
|
||||
_configurationService.SetConfigValue(CurrentConVar.AuthCurrent, CurrentAlp);
|
||||
}
|
||||
else
|
||||
{
|
||||
_popupMessageService.ClosePopup();
|
||||
message.Dispose();
|
||||
Logout();
|
||||
_popupMessageService.Popup("Well, shit is happened: " + _authService.Reason);
|
||||
}
|
||||
@@ -100,7 +101,7 @@ public partial class AccountInfoViewModel : ViewModelBase
|
||||
public void Logout()
|
||||
{
|
||||
IsLogged = false;
|
||||
CurrentAlp = new AuthLoginPassword("", "", "");
|
||||
//CurrentAlp = new AuthLoginPassword("", "", "");
|
||||
_authService.ClearAuth();
|
||||
}
|
||||
|
||||
|
||||
30
Nebula.Launcher/ViewModels/ExceptionViewModel.cs
Normal file
30
Nebula.Launcher/ViewModels/ExceptionViewModel.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using Nebula.Launcher.ViewHelper;
|
||||
using Nebula.Launcher.Views.Popup;
|
||||
|
||||
namespace Nebula.Launcher.ViewModels;
|
||||
|
||||
[ViewModelRegister(typeof(ExceptionView), false)]
|
||||
public class ExceptionViewModel : PopupViewModelBase
|
||||
{
|
||||
public ExceptionViewModel() : base()
|
||||
{
|
||||
var e = new Exception("TEST");
|
||||
|
||||
AppendError(e);
|
||||
}
|
||||
|
||||
public ExceptionViewModel(IServiceProvider serviceProvider) : base(serviceProvider){}
|
||||
|
||||
public override string Title => "Oopsie! Some shit is happened now!";
|
||||
|
||||
public ObservableCollection<Exception> Errors { get; } = new();
|
||||
|
||||
public void AppendError(Exception exception)
|
||||
{
|
||||
Errors.Add(exception);
|
||||
if(exception.InnerException != null)
|
||||
AppendError(exception.InnerException);
|
||||
}
|
||||
}
|
||||
44
Nebula.Launcher/ViewModels/LoadingContextViewModel.cs
Normal file
44
Nebula.Launcher/ViewModels/LoadingContextViewModel.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
using System;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using Nebula.Launcher.ViewHelper;
|
||||
using Nebula.Launcher.Views.Popup;
|
||||
using Nebula.Shared.Models;
|
||||
|
||||
namespace Nebula.Launcher.ViewModels;
|
||||
|
||||
[ViewModelRegister(typeof(LoadingContextView), false)]
|
||||
public sealed partial class LoadingContextViewModel : PopupViewModelBase, ILoadingHandler
|
||||
{
|
||||
public LoadingContextViewModel() :base(){}
|
||||
public LoadingContextViewModel(IServiceProvider provider) : base(provider){}
|
||||
|
||||
public string LoadingName { get; set; } = "Loading...";
|
||||
|
||||
public override string Title => LoadingName;
|
||||
|
||||
[ObservableProperty]
|
||||
private int _currJobs;
|
||||
[ObservableProperty]
|
||||
private int _resolvedJobs;
|
||||
|
||||
public void SetJobsCount(int count)
|
||||
{
|
||||
CurrJobs = count;
|
||||
}
|
||||
|
||||
public int GetJobsCount()
|
||||
{
|
||||
return CurrJobs;
|
||||
}
|
||||
|
||||
public void SetResolvedJobsCount(int count)
|
||||
{
|
||||
ResolvedJobs = count;
|
||||
|
||||
}
|
||||
|
||||
public int GetResolvedJobsCount()
|
||||
{
|
||||
return ResolvedJobs;
|
||||
}
|
||||
}
|
||||
@@ -27,19 +27,20 @@ public partial class MainViewModel : ViewModelBase
|
||||
}
|
||||
|
||||
[UsedImplicitly]
|
||||
public MainViewModel(AccountInfoViewModel accountInfoViewModel, PopupMessageService popupMessageService,
|
||||
public MainViewModel(AccountInfoViewModel accountInfoViewModel,DebugService debugService, PopupMessageService popupMessageService,
|
||||
IServiceProvider serviceProvider): base(serviceProvider)
|
||||
{
|
||||
_currentPage = accountInfoViewModel;
|
||||
_popupMessageService = popupMessageService;
|
||||
_debugService = debugService;
|
||||
Items = new ObservableCollection<ListItemTemplate>(_templates);
|
||||
|
||||
_popupMessageService.OnPopupRequired += OnPopupRequired;
|
||||
popupMessageService.OnPopupRequired += OnPopupRequired;
|
||||
popupMessageService.OnCloseRequired += OnPopupCloseRequired;
|
||||
|
||||
SelectedListItem = Items.First(vm => vm.ModelType == typeof(AccountInfoViewModel));
|
||||
}
|
||||
|
||||
private readonly Queue<PopupViewModelBase> _viewQueue = new();
|
||||
|
||||
private readonly List<PopupViewModelBase> _viewQueue = new();
|
||||
|
||||
private readonly List<ListItemTemplate> _templates =
|
||||
[
|
||||
@@ -53,7 +54,7 @@ public partial class MainViewModel : ViewModelBase
|
||||
[ObservableProperty]
|
||||
private ViewModelBase _currentPage;
|
||||
|
||||
private readonly PopupMessageService _popupMessageService;
|
||||
private readonly DebugService _debugService;
|
||||
|
||||
[ObservableProperty] private bool _isEnabled = true;
|
||||
[ObservableProperty] private bool _popup;
|
||||
@@ -90,7 +91,7 @@ public partial class MainViewModel : ViewModelBase
|
||||
}
|
||||
else
|
||||
{
|
||||
_viewQueue.Enqueue(viewModelBase);
|
||||
_viewQueue.Add(viewModelBase);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -111,13 +112,10 @@ public partial class MainViewModel : ViewModelBase
|
||||
Helper.OpenBrowser("https://cinka.ru/nebula-launcher/");
|
||||
}
|
||||
|
||||
private void OnPopupRequired(object? viewModelBase)
|
||||
private void OnPopupRequired(object viewModelBase)
|
||||
{
|
||||
switch (viewModelBase)
|
||||
{
|
||||
case null:
|
||||
ClosePopup();
|
||||
break;
|
||||
case string str:
|
||||
{
|
||||
var view = GetViewModel<InfoPopupViewModel>();
|
||||
@@ -128,8 +126,28 @@ public partial class MainViewModel : ViewModelBase
|
||||
case PopupViewModelBase @base:
|
||||
PopupMessage(@base);
|
||||
break;
|
||||
case Exception error:
|
||||
var err = GetViewModel<ExceptionViewModel>();
|
||||
_debugService.Error(error);
|
||||
err.AppendError(error);
|
||||
PopupMessage(err);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnPopupCloseRequired(object obj)
|
||||
{
|
||||
if(obj is not PopupViewModelBase viewModelBase)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (obj == CurrentPopup)
|
||||
ClosePopup();
|
||||
else
|
||||
_viewQueue.Remove(viewModelBase);
|
||||
}
|
||||
|
||||
|
||||
[RelayCommand]
|
||||
private void TriggerPane()
|
||||
@@ -140,10 +158,14 @@ public partial class MainViewModel : ViewModelBase
|
||||
[RelayCommand]
|
||||
public void ClosePopup()
|
||||
{
|
||||
if (!_viewQueue.TryDequeue(out var viewModelBase))
|
||||
var viewModelBase = _viewQueue.FirstOrDefault();
|
||||
if (viewModelBase is null)
|
||||
OnCloseRequired();
|
||||
else
|
||||
{
|
||||
CurrentTitle = viewModelBase.Title;
|
||||
_viewQueue.RemoveAt(0);
|
||||
}
|
||||
|
||||
CurrentPopup = viewModelBase;
|
||||
}
|
||||
|
||||
@@ -1,16 +1,25 @@
|
||||
using System;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Nebula.Shared.Services;
|
||||
|
||||
namespace Nebula.Launcher.ViewModels;
|
||||
|
||||
public abstract class PopupViewModelBase : ViewModelBase
|
||||
public abstract class PopupViewModelBase : ViewModelBase, IDisposable
|
||||
{
|
||||
private readonly IServiceProvider _serviceProvider;
|
||||
|
||||
public PopupViewModelBase()
|
||||
{
|
||||
}
|
||||
|
||||
public PopupViewModelBase(IServiceProvider serviceProvider) : base(serviceProvider)
|
||||
{
|
||||
_serviceProvider = serviceProvider;
|
||||
}
|
||||
|
||||
public abstract string Title { get; }
|
||||
public abstract string Title { get; }
|
||||
public void Dispose()
|
||||
{
|
||||
_serviceProvider.GetService<PopupMessageService>()?.ClosePopup(this);
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ using System.Collections.ObjectModel;
|
||||
using System.Diagnostics;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
using Avalonia.Media;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using Nebula.Launcher.ViewHelper;
|
||||
@@ -22,12 +23,23 @@ public partial class ServerEntryModelView : ViewModelBase
|
||||
private readonly RunnerService _runnerService = default!;
|
||||
private readonly PopupMessageService _popupMessageService;
|
||||
|
||||
[ObservableProperty] private bool _runVisible = true;
|
||||
public bool RunVisible => Process == null;
|
||||
|
||||
public ServerHubInfo ServerHubInfo { get; set; } = default!;
|
||||
|
||||
|
||||
private Process? _process;
|
||||
|
||||
|
||||
private Process? _p;
|
||||
private Process? Process
|
||||
{
|
||||
get { return _p; }
|
||||
set
|
||||
{
|
||||
_p = value;
|
||||
OnPropertyChanged(nameof(RunVisible));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public LogPopupModelView CurrLog;
|
||||
|
||||
@@ -55,65 +67,93 @@ public partial class ServerEntryModelView : ViewModelBase
|
||||
CurrLog = GetViewModel<LogPopupModelView>();
|
||||
}
|
||||
|
||||
public async void RunInstance()
|
||||
public void RunInstance()
|
||||
{
|
||||
var authProv = _authService.SelectedAuth;
|
||||
|
||||
var buildInfo = await _contentService.GetBuildInfo(new RobustUrl(ServerHubInfo.Address), _cancellationService.Token);
|
||||
Task.Run(RunAsync);
|
||||
}
|
||||
|
||||
await _runnerService.PrepareRun(buildInfo, _cancellationService.Token);
|
||||
|
||||
_process = Process.Start(new ProcessStartInfo()
|
||||
{
|
||||
FileName = "dotnet.exe",
|
||||
Arguments = "./Nebula.Runner.dll",
|
||||
Environment = {
|
||||
{ "ROBUST_AUTH_USERID", authProv?.UserId.ToString() } ,
|
||||
{ "ROBUST_AUTH_TOKEN", authProv?.Token.Token } ,
|
||||
{ "ROBUST_AUTH_SERVER", authProv?.AuthLoginPassword.AuthServer } ,
|
||||
{ "ROBUST_AUTH_PUBKEY", buildInfo.BuildInfo.Auth.PublicKey } ,
|
||||
{ "GAME_URL", ServerHubInfo.Address } ,
|
||||
{ "AUTH_LOGIN", authProv?.AuthLoginPassword.Login } ,
|
||||
},
|
||||
CreateNoWindow = true,
|
||||
UseShellExecute = false,
|
||||
RedirectStandardOutput = true,
|
||||
RedirectStandardError = true, StandardOutputEncoding = Encoding.UTF8
|
||||
});
|
||||
|
||||
|
||||
if (_process is null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_process.BeginOutputReadLine();
|
||||
_process.BeginErrorReadLine();
|
||||
|
||||
RunVisible = false;
|
||||
|
||||
_process.OutputDataReceived += OnOutputDataReceived;
|
||||
_process.ErrorDataReceived += OnErrorDataReceived;
|
||||
|
||||
_process.Exited += OnExited;
|
||||
public async Task RunAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
var authProv = _authService.SelectedAuth;
|
||||
|
||||
var buildInfo =
|
||||
await _contentService.GetBuildInfo(new RobustUrl(ServerHubInfo.Address), _cancellationService.Token);
|
||||
|
||||
using (var loadingContext = GetViewModel<LoadingContextViewModel>())
|
||||
{
|
||||
loadingContext.LoadingName = "Loading instance...";
|
||||
((ILoadingHandler)loadingContext).AppendJob();
|
||||
|
||||
_popupMessageService.Popup(loadingContext);
|
||||
|
||||
|
||||
await _runnerService.PrepareRun(buildInfo, loadingContext, _cancellationService.Token);
|
||||
|
||||
Process = Process.Start(new ProcessStartInfo()
|
||||
{
|
||||
FileName = "dotnet.exe",
|
||||
Arguments = "./Nebula.Runner.dll",
|
||||
Environment =
|
||||
{
|
||||
{ "ROBUST_AUTH_USERID", authProv?.UserId.ToString() },
|
||||
{ "ROBUST_AUTH_TOKEN", authProv?.Token.Token },
|
||||
{ "ROBUST_AUTH_SERVER", authProv?.AuthLoginPassword.AuthServer },
|
||||
{ "ROBUST_AUTH_PUBKEY", buildInfo.BuildInfo.Auth.PublicKey },
|
||||
{ "GAME_URL", ServerHubInfo.Address },
|
||||
{ "AUTH_LOGIN", authProv?.AuthLoginPassword.Login },
|
||||
},
|
||||
CreateNoWindow = true,
|
||||
UseShellExecute = false,
|
||||
RedirectStandardOutput = true,
|
||||
RedirectStandardError = true,
|
||||
StandardOutputEncoding = Encoding.UTF8
|
||||
});
|
||||
|
||||
((ILoadingHandler)loadingContext).AppendResolvedJob();
|
||||
}
|
||||
|
||||
if (Process is null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Process.EnableRaisingEvents = true;
|
||||
|
||||
Process.BeginOutputReadLine();
|
||||
Process.BeginErrorReadLine();
|
||||
|
||||
Process.OutputDataReceived += OnOutputDataReceived;
|
||||
Process.ErrorDataReceived += OnErrorDataReceived;
|
||||
|
||||
Process.Exited += OnExited;
|
||||
}
|
||||
catch (TaskCanceledException e)
|
||||
{
|
||||
_popupMessageService.Popup("Task canceled");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_popupMessageService.Popup(e);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnExited(object? sender, EventArgs e)
|
||||
{
|
||||
if (_process is null)
|
||||
if (Process is null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_process.OutputDataReceived -= OnOutputDataReceived;
|
||||
_process.ErrorDataReceived -= OnErrorDataReceived;
|
||||
_process.Exited -= OnExited;
|
||||
Process.OutputDataReceived -= OnOutputDataReceived;
|
||||
Process.ErrorDataReceived -= OnErrorDataReceived;
|
||||
Process.Exited -= OnExited;
|
||||
|
||||
_debugService.Log("PROCESS EXIT WITH CODE " + _process.ExitCode);
|
||||
_debugService.Log("PROCESS EXIT WITH CODE " + Process.ExitCode);
|
||||
|
||||
_process.Dispose();
|
||||
_process = null;
|
||||
RunVisible = true;
|
||||
Process.Dispose();
|
||||
Process = null;
|
||||
}
|
||||
|
||||
private void OnErrorDataReceived(object sender, DataReceivedEventArgs e)
|
||||
@@ -142,7 +182,7 @@ public partial class ServerEntryModelView : ViewModelBase
|
||||
|
||||
public void StopInstance()
|
||||
{
|
||||
_process?.Close();
|
||||
Process?.CloseMainWindow();
|
||||
}
|
||||
|
||||
static string FindDotnetPath()
|
||||
|
||||
Reference in New Issue
Block a user