- tweak: open content
This commit is contained in:
@@ -2,7 +2,9 @@ using System;
|
||||
using System.Collections.Frozen;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Diagnostics;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Avalonia.Media;
|
||||
@@ -25,6 +27,7 @@ public sealed partial class ContentBrowserViewModel : ViewModelBase
|
||||
private readonly IServiceProvider _provider;
|
||||
private readonly ContentService _contentService;
|
||||
private readonly CancellationService _cancellationService;
|
||||
private readonly FileService _fileService;
|
||||
private readonly DebugService _debugService;
|
||||
private readonly PopupMessageService _popupService;
|
||||
public ObservableCollection<ContentEntry> Entries { get; } = new();
|
||||
@@ -42,14 +45,36 @@ public sealed partial class ContentBrowserViewModel : ViewModelBase
|
||||
get => _selectedEntry;
|
||||
set
|
||||
{
|
||||
_selectedEntry = value;
|
||||
if (value is { Item: not null })
|
||||
{
|
||||
if (_fileService.ContentFileApi.TryOpen(value.Item.Value.Hash, out var stream))
|
||||
{
|
||||
var ext = Path.GetExtension(value.Item.Value.Path);
|
||||
|
||||
var myTempFile = Path.Combine(Path.GetTempPath(), "tempie"+ ext);
|
||||
|
||||
using(var sw = new FileStream(myTempFile, FileMode.Create, FileAccess.Write, FileShare.None))
|
||||
{
|
||||
stream.CopyTo(sw);
|
||||
}
|
||||
stream.Dispose();
|
||||
|
||||
var startInfo = new ProcessStartInfo(myTempFile)
|
||||
{
|
||||
UseShellExecute = true
|
||||
};
|
||||
|
||||
Process.Start(startInfo);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
Entries.Clear();
|
||||
_selectedEntry = value;
|
||||
|
||||
if (value == null) return;
|
||||
|
||||
Console.WriteLine("Entries clear!");
|
||||
|
||||
if(value == null) return;
|
||||
|
||||
foreach (var (_,entryCh) in value.Childs)
|
||||
foreach (var (_, entryCh) in value.Childs)
|
||||
{
|
||||
Entries.Add(entryCh);
|
||||
}
|
||||
@@ -71,11 +96,22 @@ public sealed partial class ContentBrowserViewModel : ViewModelBase
|
||||
_provider = provider;
|
||||
_contentService = contentService;
|
||||
_cancellationService = cancellationService;
|
||||
_fileService = fileService;
|
||||
_debugService = debugService;
|
||||
_popupService = popupService;
|
||||
|
||||
foreach (var info in hubService.ServerList)
|
||||
{
|
||||
_root.Add(new ContentEntry(this, ToContentUrl(info.Address.ToRobustUrl()),info.Address));
|
||||
}
|
||||
|
||||
hubService.HubServerChangedEventArgs += HubServerChangedEventArgs;
|
||||
hubService.HubServerLoaded += GoHome;
|
||||
|
||||
if (!hubService.IsUpdating)
|
||||
{
|
||||
GoHome();
|
||||
}
|
||||
}
|
||||
|
||||
private void GoHome()
|
||||
@@ -99,9 +135,9 @@ public sealed partial class ContentBrowserViewModel : ViewModelBase
|
||||
};
|
||||
}
|
||||
|
||||
public async void Go(ContentPath path)
|
||||
public async void Go(ContentPath path, bool appendHistory = true)
|
||||
{
|
||||
if (path.Pathes.Count == 0)
|
||||
if (path.Pathes.Count <= 1)
|
||||
{
|
||||
SearchText = "";
|
||||
GoHome();
|
||||
@@ -112,8 +148,8 @@ public sealed partial class ContentBrowserViewModel : ViewModelBase
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
SearchText = path.Path;
|
||||
|
||||
var oriPath = path.Clone();
|
||||
|
||||
path.Pathes.RemoveAt(0);
|
||||
path.Pathes.RemoveAt(0);
|
||||
@@ -136,21 +172,26 @@ public sealed partial class ContentBrowserViewModel : ViewModelBase
|
||||
throw new Exception("Not found!");
|
||||
}
|
||||
|
||||
SelectedEntry = centry;
|
||||
if (appendHistory)
|
||||
{
|
||||
AppendHistory(SearchText);
|
||||
}
|
||||
SearchText = oriPath.Path;
|
||||
|
||||
SelectedEntry = centry;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e);
|
||||
SearchText = oriPath.Path;
|
||||
_popupService.Popup(e);
|
||||
//throw;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void OnBackEnter()
|
||||
{
|
||||
Go(new ContentPath(GetHistory()));
|
||||
Go(new ContentPath(GetHistory()), false);
|
||||
}
|
||||
|
||||
public void OnGoEnter()
|
||||
@@ -347,5 +388,10 @@ public struct ContentPath
|
||||
return Pathes.Last();
|
||||
}
|
||||
|
||||
public ContentPath Clone()
|
||||
{
|
||||
return new ContentPath(Pathes.ToList());
|
||||
}
|
||||
|
||||
public string Path => string.Join("/", Pathes);
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ public class ExceptionViewModel : PopupViewModelBase
|
||||
public ExceptionViewModel(IServiceProvider serviceProvider) : base(serviceProvider){}
|
||||
|
||||
public override string Title => "Oopsie! Some shit is happened now!";
|
||||
public override bool IsClosable => true;
|
||||
|
||||
public ObservableCollection<Exception> Errors { get; } = new();
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ public partial class InfoPopupViewModel : PopupViewModelBase
|
||||
}
|
||||
|
||||
public override string Title => "Info";
|
||||
public override bool IsClosable => true;
|
||||
|
||||
[ObservableProperty]
|
||||
private string _infoText = "Test";
|
||||
|
||||
@@ -13,6 +13,7 @@ public sealed partial class LoadingContextViewModel : PopupViewModelBase, ILoadi
|
||||
public LoadingContextViewModel(IServiceProvider provider) : base(provider){}
|
||||
|
||||
public string LoadingName { get; set; } = "Loading...";
|
||||
public override bool IsClosable => false;
|
||||
|
||||
public override string Title => LoadingName;
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ public partial class MainViewModel : ViewModelBase
|
||||
[
|
||||
new ListItemTemplate(typeof(AccountInfoViewModel), "Account", "Account"),
|
||||
new ListItemTemplate(typeof(ServerListViewModel), "HomeRegular", "Servers"),
|
||||
new ListItemTemplate(typeof(ContentBrowserViewModel), "HomeRegular", "Content")
|
||||
new ListItemTemplate(typeof(ContentBrowserViewModel), "GridRegular", "Content")
|
||||
];
|
||||
|
||||
[ObservableProperty]
|
||||
@@ -65,6 +65,8 @@ public partial class MainViewModel : ViewModelBase
|
||||
[ObservableProperty]
|
||||
private string _currentTitle = "Default";
|
||||
|
||||
[ObservableProperty] private bool _isPopupClosable = true;
|
||||
|
||||
[ObservableProperty]
|
||||
private ListItemTemplate? _selectedListItem;
|
||||
|
||||
@@ -88,6 +90,7 @@ public partial class MainViewModel : ViewModelBase
|
||||
{
|
||||
CurrentPopup = viewModelBase;
|
||||
CurrentTitle = viewModelBase.Title;
|
||||
IsPopupClosable = viewModelBase.IsClosable;
|
||||
OnOpenRequired();
|
||||
}
|
||||
else
|
||||
|
||||
@@ -7,6 +7,8 @@ namespace Nebula.Launcher.ViewModels;
|
||||
public abstract class PopupViewModelBase : ViewModelBase, IDisposable
|
||||
{
|
||||
private readonly IServiceProvider _serviceProvider;
|
||||
public abstract string Title { get; }
|
||||
public abstract bool IsClosable { get; }
|
||||
|
||||
public PopupViewModelBase()
|
||||
{
|
||||
@@ -17,7 +19,6 @@ public abstract class PopupViewModelBase : ViewModelBase, IDisposable
|
||||
_serviceProvider = serviceProvider;
|
||||
}
|
||||
|
||||
public abstract string Title { get; }
|
||||
public void Dispose()
|
||||
{
|
||||
_serviceProvider.GetService<PopupMessageService>()?.ClosePopup(this);
|
||||
|
||||
@@ -265,6 +265,7 @@ public sealed class LogPopupModelView : PopupViewModelBase
|
||||
}
|
||||
|
||||
public override string Title => "LOG";
|
||||
public override bool IsClosable => true;
|
||||
|
||||
public ObservableCollection<LogInfo> Logs { get; } = new();
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using Nebula.Launcher.ViewHelper;
|
||||
using Nebula.Launcher.Views.Pages;
|
||||
@@ -33,9 +34,20 @@ public partial class ServerListViewModel : ViewModelBase
|
||||
{
|
||||
_serviceProvider = serviceProvider;
|
||||
_hubService = hubService;
|
||||
|
||||
foreach (var info in _hubService.ServerList)
|
||||
{
|
||||
UnsortedServers.Add(info);
|
||||
}
|
||||
|
||||
hubService.HubServerChangedEventArgs += HubServerChangedEventArgs;
|
||||
hubService.HubServerLoaded += HubServerLoaded;
|
||||
OnSearchChange += OnChangeSearch;
|
||||
|
||||
if (!hubService.IsUpdating)
|
||||
{
|
||||
SortServers();
|
||||
}
|
||||
}
|
||||
|
||||
private void HubServerLoaded()
|
||||
@@ -72,12 +84,15 @@ public partial class ServerListViewModel : ViewModelBase
|
||||
|
||||
private void SortServers()
|
||||
{
|
||||
ServerInfos.Clear();
|
||||
UnsortedServers.Sort(new ServerComparer());
|
||||
foreach (var server in UnsortedServers.Where(CheckServerThink))
|
||||
Task.Run(() =>
|
||||
{
|
||||
ServerInfos.Add(CreateServerView(server));
|
||||
}
|
||||
ServerInfos.Clear();
|
||||
UnsortedServers.Sort(new ServerComparer());
|
||||
foreach (var server in UnsortedServers.Where(CheckServerThink))
|
||||
{
|
||||
ServerInfos.Add(CreateServerView(server));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private bool CheckServerThink(ServerHubInfo hubInfo)
|
||||
@@ -100,7 +115,7 @@ public partial class ServerListViewModel : ViewModelBase
|
||||
|
||||
public void UpdateRequired()
|
||||
{
|
||||
_hubService.UpdateHub();
|
||||
Task.Run(_hubService.UpdateHub);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -110,6 +110,7 @@
|
||||
</StackPanel>
|
||||
<Button
|
||||
Command="{Binding ClosePopupCommand}"
|
||||
IsVisible="{Binding IsPopupClosable}"
|
||||
Content="X"
|
||||
CornerRadius="0,10,0,0"
|
||||
HorizontalAlignment="Right"
|
||||
|
||||
@@ -10,8 +10,8 @@ namespace Nebula.Shared.Services;
|
||||
[ServiceRegister]
|
||||
public class FileService
|
||||
{
|
||||
public static string RootPath = Path.Join(Environment.GetFolderPath(
|
||||
Environment.SpecialFolder.ApplicationData), "./Datum/");
|
||||
public static readonly string RootPath = Path.Join(Environment.GetFolderPath(
|
||||
Environment.SpecialFolder.ApplicationData), "Datum");
|
||||
|
||||
private readonly DebugService _debugService;
|
||||
|
||||
@@ -25,10 +25,10 @@ public class FileService
|
||||
public FileService(DebugService debugService)
|
||||
{
|
||||
_debugService = debugService;
|
||||
ContentFileApi = CreateFileApi("content/");
|
||||
EngineFileApi = CreateFileApi("engine/");
|
||||
ManifestFileApi = CreateFileApi("manifest/");
|
||||
ConfigurationApi = CreateFileApi("config/");
|
||||
ContentFileApi = CreateFileApi("content");
|
||||
EngineFileApi = CreateFileApi("engine");
|
||||
ManifestFileApi = CreateFileApi("manifest");
|
||||
ConfigurationApi = CreateFileApi("config");
|
||||
}
|
||||
|
||||
public List<RobustManifestItem> ManifestItems
|
||||
|
||||
@@ -10,8 +10,12 @@ public class HubService
|
||||
|
||||
public Action<HubServerChangedEventArgs>? HubServerChangedEventArgs;
|
||||
public Action? HubServerLoaded;
|
||||
|
||||
private readonly List<ServerHubInfo> _serverList = new();
|
||||
public IReadOnlyList<ServerHubInfo> ServerList => _serverList;
|
||||
|
||||
private bool _isUpdating = false;
|
||||
public bool IsUpdating => _isUpdating;
|
||||
public HubService(ConfigurationService configurationService, RestService restService)
|
||||
{
|
||||
_configurationService = configurationService;
|
||||
@@ -23,6 +27,10 @@ public class HubService
|
||||
public async void UpdateHub()
|
||||
{
|
||||
if(_isUpdating) return;
|
||||
|
||||
|
||||
|
||||
_serverList.Clear();
|
||||
|
||||
_isUpdating = true;
|
||||
|
||||
@@ -32,6 +40,7 @@ public class HubService
|
||||
foreach (var urlStr in _configurationService.GetConfigValue(CurrentConVar.Hub)!)
|
||||
{
|
||||
var servers = await _restService.GetAsyncDefault<List<ServerHubInfo>>(new Uri(urlStr), [], CancellationToken.None);
|
||||
_serverList.AddRange(servers);
|
||||
HubServerChangedEventArgs?.Invoke(new HubServerChangedEventArgs(servers, HubServerChangeAction.Add));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user