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