- tweak: View autogenerator
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using Avalonia.Controls;
|
||||
using Nebula.Launcher.Models;
|
||||
using Nebula.Launcher.ServerListProviders;
|
||||
using Nebula.Launcher.ViewModels;
|
||||
using Nebula.Launcher.ViewModels.Pages;
|
||||
|
||||
@@ -1,2 +1 @@
|
||||
global using Nebula.Shared.Attributes;
|
||||
global using Nebula.Launcher.ViewHelper;
|
||||
global using Nebula.Shared.Attributes;
|
||||
@@ -1,6 +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;
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
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
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -3,17 +3,17 @@ using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Text.Json.Serialization;
|
||||
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.Services;
|
||||
using Nebula.Shared.Services.Logging;
|
||||
using Nebula.Shared.Utils;
|
||||
using Nebula.Shared.ViewHelper;
|
||||
|
||||
namespace Nebula.Launcher.ViewModels.Pages;
|
||||
|
||||
@@ -322,16 +322,4 @@ public partial class AccountInfoViewModel : ViewModelBase
|
||||
ConfigurationService.SetConfigValue(LauncherConVar.AuthProfiles,
|
||||
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
|
||||
);
|
||||
}
|
||||
@@ -7,13 +7,17 @@ using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Linq;
|
||||
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 Nebula.Shared.ViewHelper;
|
||||
|
||||
namespace Nebula.Launcher.ViewModels.Pages;
|
||||
|
||||
@@ -26,13 +30,17 @@ public partial class ConfigurationViewModel : ViewModelBase
|
||||
[GenerateProperty] private ConfigurationService ConfigurationService { 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 List<(object, Type)> ConVarList = new();
|
||||
|
||||
public void AddCvarConf<T>(ConVar<T> cvar)
|
||||
{
|
||||
ConfigurationVerbose.Add(
|
||||
ConfigControlHelper.GetConfigControl(cvar.Name, ConfigurationService.GetConfigValue(cvar)));
|
||||
ConfigControlHelper.GetConfigControl(cvar.Name, ConfigurationService.GetConfigValue(cvar)!));
|
||||
ConVarList.Add((cvar, cvar.Type));
|
||||
}
|
||||
|
||||
@@ -80,7 +88,18 @@ public partial class ConfigurationViewModel : ViewModelBase
|
||||
ZipFile.CreateFromDirectory(logPath, Path.Join(path, DateTime.Now.ToString("yyyy-MM-dd") + ".zip"));
|
||||
ExplorerHelper.OpenFolder(path);
|
||||
}
|
||||
|
||||
|
||||
public void RemoveAllContent()
|
||||
{
|
||||
Task.Run(() =>
|
||||
{
|
||||
using var loader = ViewHelperService.GetViewModel<LoadingContextViewModel>();
|
||||
loader.LoadingName = "Removing content";
|
||||
PopupService.Popup(loader);
|
||||
ContentService.RemoveAllContent(loader, CancellationService.Token);
|
||||
});
|
||||
}
|
||||
|
||||
private void InitConfiguration()
|
||||
{
|
||||
AddCvarConf(LauncherConVar.ILSpyUrl);
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -14,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;
|
||||
|
||||
@@ -315,6 +316,4 @@ public sealed class ServerFilter
|
||||
{
|
||||
return IsMatchByName(name) && IsMatchByTags(itemTags);
|
||||
}
|
||||
}
|
||||
|
||||
public sealed record ServerCustomNameEntry(string Url, string Name);
|
||||
}
|
||||
@@ -7,6 +7,7 @@ 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;
|
||||
|
||||
@@ -2,6 +2,7 @@ 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;
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ 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;
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ 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;
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ 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;
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Text.RegularExpressions;
|
||||
using Avalonia.Media;
|
||||
using Nebula.Launcher.Models;
|
||||
using Nebula.Launcher.Views.Popup;
|
||||
using Nebula.Shared.Services;
|
||||
using Nebula.Shared.ViewHelper;
|
||||
|
||||
namespace Nebula.Launcher.ViewModels.Popup;
|
||||
|
||||
@@ -42,40 +42,4 @@ public sealed partial class LogPopupModelView : PopupViewModelBase
|
||||
{
|
||||
Logs.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class LogInfo
|
||||
{
|
||||
public string Category { get; set; } = "LOG";
|
||||
public IBrush CategoryColor { get; set; } = Brush.Parse("#424242");
|
||||
public string Message { get; set; } = "";
|
||||
|
||||
public static LogInfo FromString(string input)
|
||||
{
|
||||
var matches = Regex.Matches(input, @"(\[(?<c>.*)\] (?<m>.*))|(?<m>.*)");
|
||||
var category = "All";
|
||||
|
||||
if (matches[0].Groups.TryGetValue("c", out var c)) category = c.Value;
|
||||
|
||||
var color = Brush.Parse("#444444");
|
||||
|
||||
switch (category)
|
||||
{
|
||||
case "DEBG":
|
||||
color = Brush.Parse("#2436d4");
|
||||
break;
|
||||
case "ERRO":
|
||||
color = Brush.Parse("#d42436");
|
||||
break;
|
||||
case "INFO":
|
||||
color = Brush.Parse("#0ab3c9");
|
||||
break;
|
||||
}
|
||||
|
||||
var message = matches[0].Groups["m"].Value;
|
||||
return new LogInfo
|
||||
{
|
||||
Category = category, Message = message, CategoryColor = color
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ using System;
|
||||
using Nebula.Launcher.Services;
|
||||
using Nebula.Launcher.Views.Popup;
|
||||
using Nebula.Shared.Services;
|
||||
using Nebula.Shared.ViewHelper;
|
||||
|
||||
namespace Nebula.Launcher.ViewModels.Popup;
|
||||
|
||||
|
||||
@@ -6,11 +6,13 @@ 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;
|
||||
|
||||
@@ -6,6 +6,7 @@ using System.Threading.Tasks;
|
||||
using System.Windows.Input;
|
||||
using Avalonia.Controls;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using Nebula.Launcher.Models;
|
||||
using Nebula.Launcher.ProcessHelper;
|
||||
using Nebula.Launcher.ServerListProviders;
|
||||
using Nebula.Launcher.Services;
|
||||
@@ -16,6 +17,7 @@ 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;
|
||||
|
||||
@@ -217,35 +219,6 @@ public partial class ServerEntryModelView : ViewModelBase, IFilterConsumer, ILis
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class ContentLogConsumer : IProcessLogConsumer
|
||||
{
|
||||
private readonly LogPopupModelView _currLog;
|
||||
private readonly PopupMessageService _popupMessageService;
|
||||
|
||||
public ContentLogConsumer(LogPopupModelView currLog, PopupMessageService popupMessageService)
|
||||
{
|
||||
_currLog = currLog;
|
||||
_popupMessageService = popupMessageService;
|
||||
}
|
||||
|
||||
public void Out(string text)
|
||||
{
|
||||
_currLog.Append(text);
|
||||
}
|
||||
|
||||
public void Error(string text)
|
||||
{
|
||||
_currLog.Append(text);
|
||||
}
|
||||
|
||||
public void Fatal(string text)
|
||||
{
|
||||
_popupMessageService.Popup("Fatal error while stop instance:" + text);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public class LinkGoCommand : ICommand
|
||||
{
|
||||
public LinkGoCommand()
|
||||
@@ -265,9 +238,4 @@ public class LinkGoCommand : ICommand
|
||||
}
|
||||
|
||||
public event EventHandler? CanExecuteChanged;
|
||||
}
|
||||
|
||||
public interface IFilterConsumer
|
||||
{
|
||||
public void ProcessFilter(ServerFilter? serverFilter);
|
||||
}
|
||||
@@ -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,7 +8,6 @@
|
||||
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">
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,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:auth="clr-namespace:Nebula.Launcher.Models.Auth">
|
||||
<Design.DataContext>
|
||||
<pages:AccountInfoViewModel />
|
||||
</Design.DataContext>
|
||||
@@ -37,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"
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -22,7 +22,8 @@
|
||||
</ItemsPanelTemplate>
|
||||
</ItemsControl.ItemsPanel>
|
||||
</ItemsControl>
|
||||
<StackPanel Orientation="Horizontal" Spacing="5">
|
||||
|
||||
<WrapPanel Orientation="Horizontal">
|
||||
<Button
|
||||
Classes="ConfigBorder"
|
||||
VerticalAlignment="Bottom"
|
||||
@@ -60,7 +61,17 @@
|
||||
Command="{Binding ExportLogs}">
|
||||
<customControls:LocalizedLabel LocalId="config-export-logs"/>
|
||||
</Button>
|
||||
</StackPanel>
|
||||
|
||||
<Button
|
||||
Classes="ConfigBorder"
|
||||
VerticalAlignment="Bottom"
|
||||
HorizontalAlignment="Stretch"
|
||||
Padding="5"
|
||||
Margin="5"
|
||||
Command="{Binding RemoveAllContent}">
|
||||
<customControls:LocalizedLabel LocalId="config-remove-content-all"/>
|
||||
</Button>
|
||||
</WrapPanel>
|
||||
</StackPanel>
|
||||
</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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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,11 +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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,4 @@
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Markup.Xaml;
|
||||
using Nebula.Launcher.ViewModels.Popup;
|
||||
|
||||
namespace Nebula.Launcher.Views.Popup;
|
||||
|
||||
@@ -11,10 +8,4 @@ public partial class EditServerNameView : UserControl
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public EditServerNameView(EditServerNameViewModel viewModel)
|
||||
: this()
|
||||
{
|
||||
DataContext = viewModel;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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 popup: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;
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using Avalonia.Controls;
|
||||
using Nebula.Launcher.ViewModels;
|
||||
|
||||
namespace Nebula.Launcher.Views;
|
||||
|
||||
@@ -9,9 +8,4 @@ public partial class ServerCompoundEntryView : UserControl
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public ServerCompoundEntryView(ServerCompoundEntryViewModel viewModel) : this()
|
||||
{
|
||||
DataContext = viewModel;
|
||||
}
|
||||
}
|
||||
@@ -22,10 +22,7 @@ public partial class ServerEntryView : UserControl
|
||||
StartAutoScrolling();
|
||||
}
|
||||
|
||||
public ServerEntryView(ServerEntryModelView modelView) : this()
|
||||
{
|
||||
DataContext = modelView;
|
||||
}
|
||||
|
||||
|
||||
private void StartAutoScrolling()
|
||||
{
|
||||
|
||||
@@ -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(){
|
||||
|
||||
@@ -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")]
|
||||
|
||||
@@ -13,10 +13,24 @@ 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();
|
||||
|
||||
@@ -54,6 +68,8 @@ public partial class ContentService
|
||||
_logger.Log("Loading manifest from: " + info.Hash);
|
||||
return await EnsureItems(new ManifestReader(stream), info.DownloadUri, loadingHandler, cancellationToken);
|
||||
}
|
||||
|
||||
SetServerHash(info.ManifestUri.ToString(), info.Hash);
|
||||
|
||||
_logger.Log("Fetching manifest from: " + info.ManifestUri);
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ 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;
|
||||
@@ -13,11 +14,11 @@ public class FileService
|
||||
public static readonly 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 +26,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 +34,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 +56,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
|
||||
|
||||
@@ -94,8 +94,16 @@ public class ManifestReader : StreamReader
|
||||
{
|
||||
var line = ReadLine();
|
||||
if (line == null) return null;
|
||||
var splited = line.Split(" ");
|
||||
return new RobustManifestItem(splited[0], line.Substring(splited[0].Length + 1), CurrentId++);
|
||||
|
||||
var firstSpaceIndex = line.IndexOf(' ');
|
||||
if (firstSpaceIndex == -1)
|
||||
return new RobustManifestItem(line, string.Empty, CurrentId++);
|
||||
|
||||
var span = line.AsSpan();
|
||||
var firstPart = span.Slice(0, firstSpaceIndex);
|
||||
var secondPart = span.Slice(firstSpaceIndex + 1);
|
||||
|
||||
return new RobustManifestItem(firstPart.ToString(), secondPart.ToString(), CurrentId++);
|
||||
}
|
||||
|
||||
public bool TryReadItem([NotNullWhen(true)] out RobustManifestItem? item)
|
||||
|
||||
8
Nebula.Shared/ViewHelper/ViewModelRegisterAttribute.cs
Normal file
8
Nebula.Shared/ViewHelper/ViewModelRegisterAttribute.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
namespace Nebula.Shared.ViewHelper;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Class)]
|
||||
public class ViewModelRegisterAttribute(Type? type = null, bool isSingleton = true) : Attribute
|
||||
{
|
||||
public Type? Type { get; } = type;
|
||||
public bool IsSingleton { get; } = isSingleton;
|
||||
}
|
||||
@@ -71,7 +71,7 @@ partial class {className}
|
||||
";
|
||||
|
||||
// Add the source code to the compilation.
|
||||
context.AddSource($"{className}.g.cs", SourceText.From(code, Encoding.UTF8));
|
||||
context.AddSource($"{className}_dependencyAuto.g.cs", SourceText.From(code, Encoding.UTF8));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,24 +7,6 @@ namespace Nebula.SourceGenerators;
|
||||
|
||||
public static class SourceHelper
|
||||
{
|
||||
public static void GenerateAttribute(string attributeName, string usage,
|
||||
IncrementalGeneratorInitializationContext context)
|
||||
{
|
||||
var attributeSourceCode = $@"// <auto-generated/>
|
||||
|
||||
namespace SourceGen
|
||||
{{
|
||||
[System.AttributeUsage(System.AttributeTargets.{usage})]
|
||||
public class {attributeName} : System.Attribute
|
||||
{{
|
||||
}}
|
||||
}}";
|
||||
|
||||
context.RegisterPostInitializationOutput(ctx => ctx.AddSource(
|
||||
$"{attributeName}.g.cs",
|
||||
SourceText.From(attributeSourceCode, Encoding.UTF8)));
|
||||
}
|
||||
|
||||
public static bool HasAttribute(ISymbol type, string attributeName)
|
||||
{
|
||||
foreach (var attribute in type.GetAttributes())
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Immutable;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Microsoft.CodeAnalysis;
|
||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
@@ -6,53 +8,82 @@ using Microsoft.CodeAnalysis.Text;
|
||||
|
||||
namespace Nebula.SourceGenerators;
|
||||
|
||||
//[Generator]
|
||||
public class ViewConstructGenerator : IIncrementalGenerator
|
||||
|
||||
[Generator]
|
||||
public class ViewConstructorGenerator : IIncrementalGenerator
|
||||
{
|
||||
public static string ViewForModelAttributeName = "ViewForModelAttribute";
|
||||
|
||||
private static readonly string ViewModelAttribute = "Nebula.Shared.ViewHelper.ViewModelRegisterAttribute";
|
||||
public void Initialize(IncrementalGeneratorInitializationContext context)
|
||||
{
|
||||
var provider = context.SyntaxProvider
|
||||
.CreateSyntaxProvider(
|
||||
(s, _) => s is ClassDeclarationSyntax, (ctx, _) =>
|
||||
SourceHelper.GetClassDeclarationForSourceGen(ctx,ViewForModelAttributeName)
|
||||
)
|
||||
(s, _) => s is ClassDeclarationSyntax,
|
||||
(ctx, _) => SourceHelper.GetClassDeclarationForSourceGen(ctx,ViewModelAttribute))
|
||||
.Where(t => t.reportAttributeFound)
|
||||
.Select((t,_) => t.Item1);
|
||||
|
||||
context.RegisterSourceOutput(context.CompilationProvider.Combine(provider.Collect()), (ctx,t)=> GenerateCode(ctx, t.Left, t.Right));
|
||||
.Select((t, _) => t.Item1);
|
||||
|
||||
context.RegisterSourceOutput(context.CompilationProvider.Combine(provider.Collect()),
|
||||
(ctx, t) => GenerateCode(ctx, t.Left, t.Right));
|
||||
}
|
||||
|
||||
private void GenerateCode(SourceProductionContext context, Compilation compilation, ImmutableArray<ClassDeclarationSyntax> syntaxes)
|
||||
private void GenerateCode(SourceProductionContext context, Compilation compilation,
|
||||
ImmutableArray<ClassDeclarationSyntax> classDeclarations)
|
||||
{
|
||||
foreach (var classDeclarationSyntax in syntaxes)
|
||||
foreach (var classDeclarationSyntax in classDeclarations)
|
||||
{
|
||||
var semanticModel = compilation.GetSemanticModel(classDeclarationSyntax.SyntaxTree);
|
||||
if(semanticModel.GetDeclaredSymbol(classDeclarationSyntax) is not INamedTypeSymbol classSymbol)
|
||||
if (semanticModel.GetDeclaredSymbol(classDeclarationSyntax) is not INamedTypeSymbol classSymbol)
|
||||
continue;
|
||||
|
||||
var namespaceName = classSymbol.ContainingNamespace.ToDisplayString();
|
||||
var className = classDeclarationSyntax.Identifier.Text;
|
||||
var viewModelName = classSymbol.Name;
|
||||
var viewModelNamespace = classSymbol.ContainingNamespace.ToDisplayString();
|
||||
|
||||
var code = $@"// <auto-generated/>
|
||||
var viewModelRegisterAttr = classSymbol.GetAttributes()
|
||||
.FirstOrDefault(attr => attr.AttributeClass?.ToDisplayString() == ViewModelAttribute);
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
var viewTypeArg = viewModelRegisterAttr?.ConstructorArguments.FirstOrDefault();
|
||||
if (viewTypeArg?.Value is not INamedTypeSymbol viewTypeSymbol)
|
||||
continue;
|
||||
|
||||
namespace {namespaceName};
|
||||
|
||||
partial class {className}
|
||||
try
|
||||
{
|
||||
var viewName = viewTypeSymbol.Name;
|
||||
var viewNamespace = viewTypeSymbol.ContainingNamespace.ToDisplayString();
|
||||
|
||||
var code = $@"
|
||||
namespace {viewNamespace}
|
||||
{{
|
||||
public {className}() : base(){{
|
||||
|
||||
|
||||
public partial class {viewName}
|
||||
{{
|
||||
public {viewName}({viewModelNamespace}.{viewModelName} viewModel)
|
||||
: this()
|
||||
{{
|
||||
DataContext = viewModel;
|
||||
}}
|
||||
}}
|
||||
}}
|
||||
";
|
||||
}}";
|
||||
|
||||
// Add the source code to the compilation.
|
||||
context.AddSource($"{viewName}_viewConstructAuto.g.cs", SourceText.From(code, Encoding.UTF8));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
var coder1 = $@"
|
||||
// <auto-generated/>
|
||||
// Error!
|
||||
namespace {viewModelNamespace}
|
||||
{{
|
||||
public partial class {viewModelName}
|
||||
{{
|
||||
// {e.Message}
|
||||
}}
|
||||
}}";
|
||||
|
||||
// Add the source code to the compilation.
|
||||
context.AddSource($"{className}.g.cs", SourceText.From(code, Encoding.UTF8));
|
||||
// Add the source code to the compilation.
|
||||
context.AddSource($"{viewModelName}_viewError.g.cs", SourceText.From(coder1, Encoding.UTF8));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -39,6 +39,7 @@
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ANativeLibrary_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003FUsers_003FCinka_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003F49393f3cda2f9a5c2fa811fc9179dcbaf5bd94d9dc8afc76aaff2bc23287f3_003FNativeLibrary_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AObservableCollection_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003FUsers_003FCinka_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003F3e2c48e6b3ec8b39cf721287f93972c7f3df25d306753bcc539eaad73126c68_003FObservableCollection_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003APanel_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003FUsers_003FCinka_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003F9b699722324e3615b57977447b25bf953fccb2d6e912ae584f16b7e691ad9d3_003FPanel_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AParallel_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003FUsers_003FCinka_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003F36fd1a9641998bb3afbf2091e26eafa6aaafabcb494bc746c0ba7471db513143_003FParallel_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AParallel_002EForEachAsync_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003FUsers_003FCinka_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003Fc1d1ed6be2d5d4de542b4af5b36e82f6d1d1a389a35a4e4f9748d137d1c651_003FParallel_002EForEachAsync_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003APerfCounterCollector_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003FUsers_003FCinka_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Fb07ddb833489431aae882d295a4e94797e00_003F4f_003F4c0b90e8_003FPerfCounterCollector_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AProcessStartInfo_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003FUsers_003FCinka_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003Fc5ffb8c166be164bc221db4c64e826a1e8ff54f2f1c9ee8e7f9cfabce707fa4_003FProcessStartInfo_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
@@ -48,11 +49,13 @@
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AServiceProviderServiceExtensions_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003FUsers_003FCinka_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F4f1fdec7cbfe4433a7ec3a6d1bd0e54210118_003F04_003Fe2f5322d_003FServiceProviderServiceExtensions_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ASingle_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003FUsers_003FCinka_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003Fe27543f11ad92fdb62cde92eebaa1afb3de86a016ad85f76d1554b0389cd3f3_003FSingle_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ASR_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003FUsers_003FCinka_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Fc4d71b51722245ae8cde97bfd996e68386928_003F4d_003F9372fe61_003FSR_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AStreamReader_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003FUsers_003FCinka_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003F6a802af2346a87e430fb66291f320aa22871259d47c2bc928a59f14b42aa34_003FStreamReader_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AString_002EManipulation_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003FUsers_003FCinka_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003Fe75a5575ba872c8ea754c015cb363850e6c661f39569712d5b74aaca67263c_003FString_002EManipulation_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AStyle_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003FUsers_003FCinka_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003Fcfbd5689fdab68d1c02f6a9b3c5921abcc409b8743dcc958da77cc1cfcb8e_003FStyle_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ATextBox_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003FUsers_003FCinka_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003F43273dba3ac6a4e11aefe78fbbccf5d36f07542ca37ecebffb25c95d1a1c16b_003FTextBox_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AType_002ECoreCLR_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003FUsers_003FCinka_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003F5cde391207de75962d7bacb899ca2bd3985c86911b152d185b58999a422bf0_003FType_002ECoreCLR_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AUri_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003FUsers_003FCinka_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003F6a1fb5a19c4883d19f63515be2d0cce5e0e9929bb30469a912a58ad2e1e6152_003FUri_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AUserControl_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003FUsers_003FCinka_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F0ceaca09f3944680b668dee8e1e0370b100a00_003F76_003F1f1e9043_003FUserControl_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AValuePrinter_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003FUsers_003FCinka_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F80d1676fb411442983574149e0b6aebc72e00_003F2f_003F26a40f58_003FValuePrinter_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AZipFileExtensions_002EZipArchive_002ECreate_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003FUsers_003FCinka_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003F1dd11f63b66adf34b6a6d76e1e0c0fd1df69d78b5fbfdcdf31c67b6bb40e9e4_003FZipFileExtensions_002EZipArchive_002ECreate_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AZipFile_002ECreate_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003FUsers_003FCinka_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003F5161553fb4bfeb0f7caff73da46449e1fb0d343789e21ff4d481db57d521976_003FZipFile_002ECreate_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
@@ -62,4 +65,5 @@
|
||||
<Assembly Path="C:\Program Files\dotnet\shared\Microsoft.NETCore.App\9.0.2\System.Net.Http.dll" />
|
||||
<Assembly Path="C:\Users\Cinka\.nuget\packages\prometheus-net\0.0.2\lib\net40\prometheus-net.dll" />
|
||||
<Assembly Path="C:\Users\Cinka\.nuget\packages\microsoft.extensions.objectpool\7.0.0\lib\net7.0\Microsoft.Extensions.ObjectPool.dll" />
|
||||
<Assembly Path="C:\Users\Cinka\.nuget\packages\netstandard.library\2.0.3\build\netstandard2.0\ref\netstandard.dll" />
|
||||
</AssemblyExplorer></s:String></wpf:ResourceDictionary>
|
||||
Reference in New Issue
Block a user