Compare commits
10 Commits
93847820ce
...
1e83a02905
| Author | SHA1 | Date | |
|---|---|---|---|
| 1e83a02905 | |||
| 518ac74dc7 | |||
| e3a3fb5e5e | |||
| e31df8e029 | |||
| 89ddbc19d9 | |||
| 0eab3ba8f3 | |||
| 9e0f9ad1a6 | |||
| 27746cbddd | |||
| a5b7e0479d | |||
| 87f17669c3 |
1
.gitignore
vendored
@ -8,6 +8,7 @@
|
||||
[Oo]ut/
|
||||
[Ll]og/
|
||||
[Ll]ogs/
|
||||
[Pp]ublish/
|
||||
|
||||
# IDE files
|
||||
.vs/
|
||||
|
||||
@ -0,0 +1,6 @@
|
||||
<component name="ProjectRunConfigurationManager">
|
||||
<configuration default="false" name="launcher-client-avalonia-win64" type="DotNetFolderPublish" factoryName="Publish to folder">
|
||||
<riderPublish configuration="Release" delete_existing_files="true" platform="Any CPU" produce_single_file="true" runtime="win-x64" target_folder="$PROJECT_DIR$/launcher-client-avalonia/publish/win-x64" target_framework="net6.0" uuid_high="-4890976677488079081" uuid_low="-5731196012681532756" />
|
||||
<method v="2" />
|
||||
</configuration>
|
||||
</component>
|
||||
30
Launcher.Client.Avalonia/GUI/App.axaml
Normal file
@ -0,0 +1,30 @@
|
||||
<Application x:Class="Launcher.Client.Avalonia.GUI.App"
|
||||
xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
|
||||
<Application.Resources>
|
||||
<SolidColorBrush x:Key="MyBackgroundColor" Color="#232328" />
|
||||
<SolidColorBrush x:Key="MyDarkTr"
|
||||
Opacity="0.8"
|
||||
Color="#141419" />
|
||||
<SolidColorBrush x:Key="MyGray" Color="#46464B" />
|
||||
<SolidColorBrush x:Key="MyWhite" Color="#F0F0F0" />
|
||||
<SolidColorBrush x:Key="MyGreen" Color="#28C311" />
|
||||
<SolidColorBrush x:Key="MyRed" Color="#E5160A" />
|
||||
<SolidColorBrush x:Key="MySelectionColor" Color="#B7800A" />
|
||||
</Application.Resources>
|
||||
|
||||
<Application.Styles>
|
||||
<FluentTheme Mode="Dark" />
|
||||
|
||||
<Style Selector="TextBox.MyTextBoxStyle" />
|
||||
<Style Selector="Label.MyLabelStyle" />
|
||||
<Style Selector="Button.MyButtonStyle" >
|
||||
<Setter Property="Background" Value="Transparent"/>
|
||||
<Setter Property="HorizontalAlignment" Value="Stretch"/>
|
||||
<Setter Property="VerticalAlignment" Value="Stretch"/>
|
||||
<Setter Property="HorizontalContentAlignment" Value="Center"/>
|
||||
<Setter Property="VerticalContentAlignment" Value="Center"/>
|
||||
</Style>
|
||||
|
||||
</Application.Styles>
|
||||
</Application>
|
||||
38
Launcher.Client.Avalonia/GUI/App.axaml.cs
Normal file
@ -0,0 +1,38 @@
|
||||
global using Avalonia;
|
||||
global using Avalonia.Controls;
|
||||
global using Avalonia.Media;
|
||||
global using Avalonia.Media.Imaging;
|
||||
global using Avalonia.Markup.Xaml;
|
||||
using Avalonia.Controls.ApplicationLifetimes;
|
||||
|
||||
namespace Launcher.Client.Avalonia.GUI
|
||||
{
|
||||
public partial class App : Application
|
||||
{
|
||||
public static SolidColorBrush MyDark, MySoftDark, MyWhite, MyGreen, MyOrange, MySelectionColor;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
AvaloniaXamlLoader.Load(this);
|
||||
MyDark = (SolidColorBrush)Resources["MyDarkTr"];
|
||||
MySoftDark = (SolidColorBrush)Resources["MyGray"];
|
||||
MyWhite = (SolidColorBrush)Resources["MyWhite"];
|
||||
MyGreen = (SolidColorBrush)Resources["MyGreen"];
|
||||
MyOrange = (SolidColorBrush)Resources["MySelectionColor"];
|
||||
MySelectionColor = (SolidColorBrush)Resources["MySelectionColor"];
|
||||
}
|
||||
|
||||
|
||||
public override void OnFrameworkInitializationCompleted()
|
||||
{
|
||||
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
|
||||
{
|
||||
CurrentLauncherWindow = new LauncherWindow();
|
||||
desktop.MainWindow = CurrentLauncherWindow;
|
||||
CurrentLauncherWindow.Show();
|
||||
}
|
||||
|
||||
base.OnFrameworkInitializationCompleted();
|
||||
}
|
||||
}
|
||||
}
|
||||
180
Launcher.Client.Avalonia/GUI/LauncherWindow.axaml
Normal file
@ -0,0 +1,180 @@
|
||||
<Window x:Class="Launcher.Client.Avalonia.GUI.LauncherWindow"
|
||||
xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:local="clr-namespace:Launcher.Client.Avalonia.GUI"
|
||||
Title="Launcher"
|
||||
Width="800"
|
||||
Height="500"
|
||||
MinWidth="800"
|
||||
MinHeight="500"
|
||||
Background="{DynamicResource MyBackgroundColor}">
|
||||
<Grid ColumnDefinitions="5,*,5" RowDefinitions="5,35,5,*,5">
|
||||
<Image x:Name="BackgroundImage"
|
||||
Grid.RowSpan="5"
|
||||
Grid.ColumnSpan="3"
|
||||
HorizontalAlignment="Center"
|
||||
Stretch="UniformToFill" />
|
||||
|
||||
<Grid x:Name="TopPanelGrid"
|
||||
Grid.Row="1"
|
||||
Grid.Column="1"
|
||||
ColumnDefinitions="*,5,*,5,*,5,*">
|
||||
<local:TabButton x:Name="LibraryButton"
|
||||
Grid.Column="0"
|
||||
Classes="MyButtonStyle"
|
||||
Content="Library"
|
||||
FontSize="18" />
|
||||
<local:TabButton x:Name="DownloadsButton"
|
||||
Grid.Column="2"
|
||||
Classes="MyButtonStyle"
|
||||
Content="Downloads"
|
||||
FontSize="18" />
|
||||
<local:TabButton x:Name="LogButton"
|
||||
Grid.Column="4"
|
||||
Classes="MyButtonStyle"
|
||||
Content="Log"
|
||||
FontSize="18" />
|
||||
<local:TabButton x:Name="SettingsButton"
|
||||
Grid.Column="6"
|
||||
Classes="MyButtonStyle"
|
||||
Content="Settings"
|
||||
FontSize="18" />
|
||||
|
||||
</Grid>
|
||||
|
||||
<Grid x:Name="LibraryGrid"
|
||||
Grid.Row="3"
|
||||
Grid.Column="1"
|
||||
ColumnDefinitions="220,5,*,5,220"
|
||||
IsVisible="true">
|
||||
<ScrollViewer Grid.Column="0"
|
||||
HorizontalAlignment="Stretch"
|
||||
VerticalAlignment="Stretch"
|
||||
Template="{DynamicResource myScrollViewer}"
|
||||
VerticalScrollBarVisibility="Auto">
|
||||
<StackPanel x:Name="ProgramsPanel" />
|
||||
</ScrollViewer>
|
||||
<Grid x:Name="ProgramGrid"
|
||||
Grid.Column="2"
|
||||
RowDefinitions="35,5,35,5,70,5,*">
|
||||
<Label x:Name="NameLabel"
|
||||
Grid.Row="0"
|
||||
Classes="MyLabelStyle"
|
||||
Content="name"
|
||||
FontSize="19"
|
||||
FontWeight="Bold" />
|
||||
<StackPanel Grid.Row="2"
|
||||
HorizontalAlignment="Right"
|
||||
ClipToBounds="True"
|
||||
Orientation="Horizontal">
|
||||
<Button x:Name="RemoveButton"
|
||||
Width="100"
|
||||
Margin="2,0"
|
||||
Background="{DynamicResource MyRed}"
|
||||
Classes="MyButtonStyle"
|
||||
Content="Remove" />
|
||||
<Button x:Name="InstallButton"
|
||||
Width="100"
|
||||
Margin="2,0"
|
||||
Classes="MyButtonStyle"
|
||||
Content="Install" />
|
||||
<Button x:Name="UpdateButton"
|
||||
Width="100"
|
||||
Margin="2,0"
|
||||
Classes="MyButtonStyle"
|
||||
Content="Update" />
|
||||
<Button x:Name="LaunchButton"
|
||||
Width="100"
|
||||
Margin="2,0"
|
||||
Background="{DynamicResource MyGreen}"
|
||||
Classes="MyButtonStyle"
|
||||
Content="Launch" />
|
||||
</StackPanel>
|
||||
<TextBox x:Name="DescriptionBox"
|
||||
Grid.Row="4"
|
||||
Classes="MyTextBoxStyle"
|
||||
ScrollViewer.VerticalScrollBarVisibility="Auto" />
|
||||
<TextBox x:Name="ProgramLogBox"
|
||||
Grid.Row="6"
|
||||
Classes="MyTextBoxStyle"
|
||||
ScrollViewer.VerticalScrollBarVisibility="Auto" />
|
||||
</Grid>
|
||||
<Grid Grid.Row="0"
|
||||
Grid.Column="4"
|
||||
RowDefinitions="95,*">
|
||||
<Grid Grid.Row="0"
|
||||
ColumnDefinitions="*,*"
|
||||
RowDefinitions="30,30,30">
|
||||
|
||||
<Label Grid.Row="0"
|
||||
Grid.Column="0"
|
||||
Classes="MyLabelStyle"
|
||||
Content="version:" />
|
||||
<ComboBox Grid.Row="0"
|
||||
Grid.Column="1"
|
||||
Background="{DynamicResource MyDarkTr}"
|
||||
Template="{DynamicResource MyComboBox}">
|
||||
<ComboBoxItem IsSelected="True">
|
||||
<Label Background="Transparent"
|
||||
Classes="MyLabelStyle"
|
||||
Content="v1" />
|
||||
</ComboBoxItem>
|
||||
</ComboBox>
|
||||
<Label Grid.Row="1"
|
||||
Grid.Column="0"
|
||||
Classes="MyLabelStyle"
|
||||
Content="directory:" />
|
||||
<Label Name="ProgramDirectoryLabel"
|
||||
Grid.Row="1"
|
||||
Grid.Column="1"
|
||||
Classes="MyLabelStyle"
|
||||
Content="0" />
|
||||
<Label Grid.Row="2"
|
||||
Grid.Column="0"
|
||||
Classes="MyLabelStyle"
|
||||
Content="size:" />
|
||||
<Label Name="ProgramSizeLabel"
|
||||
Grid.Row="2"
|
||||
Grid.Column="1"
|
||||
Classes="MyLabelStyle"
|
||||
Content="0" />
|
||||
</Grid>
|
||||
<ScrollViewer Name="ProgramSettingsViever"
|
||||
Grid.Row="1"
|
||||
HorizontalAlignment="Stretch"
|
||||
VerticalAlignment="Stretch"
|
||||
VerticalContentAlignment="Top"
|
||||
Template="{DynamicResource myScrollViewer}" />
|
||||
</Grid>
|
||||
</Grid>
|
||||
|
||||
|
||||
<Grid x:Name="DownloadsGrid"
|
||||
Grid.Row="3"
|
||||
Grid.Column="1"
|
||||
IsVisible="false" />
|
||||
|
||||
<Grid x:Name="LogGrid"
|
||||
Grid.Row="3"
|
||||
Grid.Column="1"
|
||||
IsVisible="false"
|
||||
RowDefinitions="30,*">
|
||||
<Label x:Name="LogfileLabel"
|
||||
Grid.Row="0"
|
||||
Grid.Column="0"
|
||||
Classes="MyLabelStyle"
|
||||
Content="logfile"
|
||||
FontStyle="Italic" />
|
||||
<TextBox x:Name="LogBox"
|
||||
Grid.Row="1"
|
||||
Grid.Column="0"
|
||||
Classes="MyTextBoxStyle"
|
||||
ScrollViewer.VerticalScrollBarVisibility="Auto" />
|
||||
</Grid>
|
||||
|
||||
<Grid x:Name="SettingsGrid"
|
||||
Grid.Row="3"
|
||||
Grid.Column="1"
|
||||
IsVisible="false" />
|
||||
</Grid>
|
||||
</Window>
|
||||
103
Launcher.Client.Avalonia/GUI/LauncherWindow.axaml.cs
Normal file
@ -0,0 +1,103 @@
|
||||
using Avalonia.Interactivity;
|
||||
using Avalonia.Threading;
|
||||
using DTLib.Logging;
|
||||
|
||||
namespace Launcher.Client.Avalonia.GUI;
|
||||
|
||||
public partial class LauncherWindow : Window
|
||||
{
|
||||
public LauncherWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
LogBox.Text = Logger.Buffer;
|
||||
Logger.MessageSent += LogHandler;
|
||||
LogfileLabel.Content = Logger.LogfileName.Remove(0,Logger.LogfileName.LastIndexOf(Path.Sep)+1);
|
||||
LogfileLabel.PointerPressed += (_,_)=>
|
||||
Process.Start("explorer.exe", LauncherLogger.LogfileDir.ToString()!);
|
||||
LogfileLabel.PointerEnter += (_,_)=>LogfileLabel.Foreground=App.MySelectionColor;
|
||||
LogfileLabel.PointerLeave += (_,_)=>LogfileLabel.Foreground=App.MyWhite;
|
||||
LibraryButton.TabGrid = LibraryGrid;
|
||||
DownloadsButton.TabGrid = DownloadsGrid;
|
||||
LogButton.TabGrid = LogGrid;
|
||||
SettingsButton.TabGrid = SettingsGrid;
|
||||
LibraryButton.Click += SelectTab;
|
||||
DownloadsButton.Click += SelectTab;
|
||||
LogButton.Click += SelectTab;
|
||||
SettingsButton.Click += SelectTab;
|
||||
ProgramGrid.IsVisible = false;
|
||||
SelectTab(LibraryButton, null);
|
||||
FillProgramsPanel();
|
||||
Logger.LogInfo(nameof(LauncherWindow),"launcher started");
|
||||
try
|
||||
{
|
||||
throw new Exception("aaa");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogError(nameof(LauncherWindow), ex);
|
||||
}
|
||||
}
|
||||
|
||||
void LogHandler(string m) => Dispatcher.UIThread.InvokeAsync(()=>LogBox.Text += m);
|
||||
|
||||
|
||||
private TabButton CurrentTab;
|
||||
void SelectTab(object sender, RoutedEventArgs _)
|
||||
{
|
||||
if(CurrentTab!=null)
|
||||
{
|
||||
CurrentTab.Background = App.MyDark;
|
||||
CurrentTab.TabGrid.IsVisible = false;
|
||||
}
|
||||
var selected = (TabButton)sender;
|
||||
selected.Background = App.MySelectionColor;
|
||||
selected.TabGrid.IsVisible = true;
|
||||
CurrentTab = selected;
|
||||
}
|
||||
|
||||
public Program[] Programs;
|
||||
|
||||
private void FillProgramsPanel()
|
||||
{
|
||||
Logger.LogInfo(nameof(LauncherWindow),"reading descriptors...");
|
||||
var descriptors = Directory.GetFiles("descriptors");
|
||||
Programs = new Program[descriptors.Length];
|
||||
for (ushort i = 0; i < descriptors.Length; i++)
|
||||
{
|
||||
var descriptor = descriptors[i];
|
||||
if(descriptor.EndsWith(".descriptor"))
|
||||
{
|
||||
Logger.LogInfo(nameof(LauncherWindow), descriptor.ToString());
|
||||
Programs[i] = new Program(descriptors[i]);
|
||||
ProgramsPanel.Children.Add(Programs[i].ProgramLabel);
|
||||
Programs[i].ProgramSelectedEvent += SelectProgram;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Program DisplayingProgram;
|
||||
public void SelectProgram(Program selectedProg)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (DisplayingProgram != null)
|
||||
{
|
||||
DisplayingProgram.ProgramLabel.Foreground = App.MyWhite;
|
||||
DisplayingProgram.ProgramLabel.FontWeight = FontWeight.Normal;
|
||||
}
|
||||
else ProgramGrid.IsVisible = true;
|
||||
|
||||
selectedProg.ProgramLabel.Foreground = App.MySelectionColor;
|
||||
selectedProg.ProgramLabel.FontWeight = FontWeight.Bold;
|
||||
|
||||
NameLabel.Content = selectedProg.Name;
|
||||
DescriptionBox.Text = selectedProg.Description;
|
||||
BackgroundImage.Source = new Bitmap(
|
||||
$"{Directory.GetCurrent()}{Path.Sep}backgrounds{Path.Sep}{selectedProg.BackgroundFile}");
|
||||
ProgramSettingsViever.Content = selectedProg.SettingsPanel;
|
||||
DisplayingProgram = selectedProg;
|
||||
}
|
||||
catch(Exception ex)
|
||||
{ LogError("SelectProgram()",ex); }
|
||||
}
|
||||
}
|
||||
25
Launcher.Client.Avalonia/GUI/MessageBox.axaml
Normal file
@ -0,0 +1,25 @@
|
||||
<Window x:Class="Launcher.Client.Avalonia.GUI.MessageBox"
|
||||
xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
mc:Ignorable="d"
|
||||
Height="100"
|
||||
Width="200"
|
||||
Background="{DynamicResource MyBackgroundColor}">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>* 30</Grid.RowDefinitions>
|
||||
<TextBox Name="TextBlock" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
|
||||
Foreground="{DynamicResource MyWhite}"
|
||||
|
||||
ScrollViewer.VerticalScrollBarVisibility="Auto"
|
||||
IsReadOnly="True" TextWrapping="Wrap"
|
||||
FontSize="14"/>
|
||||
<Button Grid.Row="1" Click="Button_OnClick"
|
||||
HorizontalAlignment="Center" VerticalAlignment="Bottom"
|
||||
Foreground="{DynamicResource MyWhite}"
|
||||
FontSize="16">
|
||||
OK
|
||||
</Button>
|
||||
</Grid>
|
||||
</Window>
|
||||
25
Launcher.Client.Avalonia/GUI/MessageBox.axaml.cs
Normal file
@ -0,0 +1,25 @@
|
||||
using Avalonia.Interactivity;
|
||||
|
||||
namespace Launcher.Client.Avalonia.GUI;
|
||||
|
||||
public partial class MessageBox : Window
|
||||
{
|
||||
public MessageBox()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public static void Show(string title, string text)
|
||||
{
|
||||
var mb = new MessageBox();
|
||||
mb.Title = title;
|
||||
mb.TextBlock.Text = text;
|
||||
mb.Topmost = true;
|
||||
mb.Show();
|
||||
}
|
||||
|
||||
private void Button_OnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
this.Close();
|
||||
}
|
||||
}
|
||||
30
Launcher.Client.Avalonia/GUI/ProgramLabel.axaml
Normal file
@ -0,0 +1,30 @@
|
||||
<UserControl x:Class="Launcher.Client.Avalonia.GUI.ProgramLabel"
|
||||
xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:local="clr-namespace:Launcher.Client.Avalonia.GUI"
|
||||
Height="50"
|
||||
Background="{DynamicResource MyDarkTr}"
|
||||
BorderBrush="{Binding Foreground, RelativeSource={RelativeSource Self}}"
|
||||
BorderThickness="3"
|
||||
Foreground="{DynamicResource MyWhite}">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="{Binding $parent[local:ProgramLabel].Height}" />
|
||||
<ColumnDefinition />
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<Image x:Name="IconImage"
|
||||
Grid.Column="0"
|
||||
Margin="3,3,3,3"
|
||||
Stretch="Fill" />
|
||||
|
||||
<Label Name="NameLabel"
|
||||
Grid.Column="1"
|
||||
VerticalContentAlignment="Center"
|
||||
Content="label"
|
||||
FontFamily="Unispace"
|
||||
FontSize="15"
|
||||
FontWeight="Normal"
|
||||
Foreground="{Binding $parent[local:ProgramLabel].Foreground}" />
|
||||
</Grid>
|
||||
</UserControl>
|
||||
14
Launcher.Client.Avalonia/GUI/ProgramLabel.axaml.cs
Normal file
@ -0,0 +1,14 @@
|
||||
namespace Launcher.Client.Avalonia.GUI;
|
||||
|
||||
public partial class ProgramLabel : UserControl
|
||||
{
|
||||
public ProgramLabel() => InitializeComponent();
|
||||
|
||||
public ProgramLabel(string label, string icon)
|
||||
{
|
||||
InitializeComponent();
|
||||
NameLabel.Content = label;
|
||||
IconImage.Source = new Bitmap(
|
||||
$"{Directory.GetCurrent()}{Path.Sep}icons{Path.Sep}{icon}");
|
||||
}
|
||||
}
|
||||
22
Launcher.Client.Avalonia/GUI/ProgramSettingsPanelItem.axaml
Normal file
@ -0,0 +1,22 @@
|
||||
<UserControl x:Class="Launcher.Client.Avalonia.GUI.ProgramSettingsPanelItem"
|
||||
xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:local="clr-namespace:Launcher.Client.Avalonia.GUI"
|
||||
Background="Transparent">
|
||||
<Grid ColumnDefinitions="*,*">
|
||||
<Label Name="KeyLabel"
|
||||
Grid.Column="0"
|
||||
Classes="MyLabelStyle"
|
||||
Content="{Binding $parent[local:ProgramSettingsPanelItem].SettingKey}"
|
||||
FontFamily="default"
|
||||
FontSize="16"
|
||||
ToolTip.Tip="{Binding $self.Content}" />
|
||||
<TextBox Name="ValueBox"
|
||||
Grid.Column="1"
|
||||
Classes="MyTextBoxStyle"
|
||||
IsReadOnly="False"
|
||||
ScrollViewer.HorizontalScrollBarVisibility="Auto"
|
||||
ScrollViewer.VerticalScrollBarVisibility="Disabled"
|
||||
Text="{Binding $parent[local:ProgramSettingsPanelItem].SettingValue}" />
|
||||
</Grid>
|
||||
</UserControl>
|
||||
@ -0,0 +1,41 @@
|
||||
namespace Launcher.Client.Avalonia.GUI;
|
||||
|
||||
public partial class ProgramSettingsPanelItem : UserControl
|
||||
{
|
||||
public static readonly StyledProperty<string> SettingKeyProp =
|
||||
AvaloniaProperty.Register<ProgramSettingsPanelItem, string>(
|
||||
"SettingKey");
|
||||
public string SettingKey
|
||||
{
|
||||
get => GetValue(SettingKeyProp);
|
||||
set => SetValue(SettingKeyProp, value);
|
||||
//TODO deal with textblock size
|
||||
/*KeyLabel.ToolTip = new ToolTip
|
||||
{
|
||||
Content = value,
|
||||
Foreground = App.MyWhite,
|
||||
Background = App.MySoftDark
|
||||
};*/
|
||||
}
|
||||
|
||||
public static readonly StyledProperty<string> SettingValueProp =
|
||||
AvaloniaProperty.Register<ProgramSettingsPanelItem, string>("SettingValue");
|
||||
public string SettingValue
|
||||
{
|
||||
get => GetValue(SettingValueProp);
|
||||
set => SetValue(SettingValueProp, value);
|
||||
}
|
||||
|
||||
public event Action<ProgramSettingsPanelItem> UpdatedEvent;
|
||||
|
||||
public ProgramSettingsPanelItem() => InitializeComponent();
|
||||
|
||||
public ProgramSettingsPanelItem(string key, string value)
|
||||
{
|
||||
InitializeComponent();
|
||||
SettingKey = key;
|
||||
SettingValue = value;
|
||||
//TODO invoke UpdatedEvent only when focus changed
|
||||
ValueBox.TextInput += (_,_)=> UpdatedEvent?.Invoke(this);
|
||||
}
|
||||
}
|
||||
17
Launcher.Client.Avalonia/GUI/TabButton.cs
Normal file
@ -0,0 +1,17 @@
|
||||
using Avalonia.Styling;
|
||||
|
||||
namespace Launcher.Client.Avalonia.GUI;
|
||||
|
||||
public partial class TabButton : Button, IStyleable
|
||||
{
|
||||
Type IStyleable.StyleKey => typeof(Button);
|
||||
|
||||
public static readonly StyledProperty<Grid> TabGridProp = AvaloniaProperty.Register<TabButton, Grid>("TabGrid");
|
||||
public Grid TabGrid
|
||||
{
|
||||
get => GetValue(TabGridProp);
|
||||
set => SetValue(TabGridProp, value);
|
||||
}
|
||||
|
||||
public TabButton() :base() {}
|
||||
}
|
||||
57
Launcher.Client.Avalonia/Launcher.Client.Avalonia.csproj
Normal file
@ -0,0 +1,57 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<RootNamespace>Launcher.Client.Avalonia</RootNamespace>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<ImplicitUsings>disable</ImplicitUsings>
|
||||
<Nullable>disable</Nullable>
|
||||
<DebugType>full</DebugType>
|
||||
<Configurations>Debug;Release</Configurations>
|
||||
<Platforms>AnyCPU</Platforms>
|
||||
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
|
||||
<ApplicationIcon>Resources/logo-D.ico</ApplicationIcon>
|
||||
<TrimMode>copyused</TrimMode>
|
||||
<BuiltInComInteropSupport>true</BuiltInComInteropSupport>
|
||||
<TargetCulture Label="Invariant" />
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Avalonia" Version="0.10.18" />
|
||||
<PackageReference Include="Avalonia.Desktop" Version="0.10.18" />
|
||||
<!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
|
||||
<PackageReference Include="Avalonia.Diagnostics" Version="0.10.18" Condition="'$(Configuration)' == 'Debug'" />
|
||||
<PackageReference Include="XamlNameReferenceGenerator" Version="1.3.4" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Launcher.Client\Launcher.Client.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="Resources\*" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<AvaloniaXaml Remove="publish\**" />
|
||||
<EmbeddedResource Remove="publish\**" />
|
||||
<Compile Remove="publish\**" />
|
||||
<None Remove="publish\**" />
|
||||
<Compile Update="GUI\App.axaml.cs">
|
||||
<DependentUpon>App.axaml</DependentUpon>
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
<!--Target Name="PostBuild-Release" AfterTargets="PostBuildEvent" Condition="'$(Configuration)' == 'Release'">
|
||||
<Exec Command="cp -f bin/Release/runtimes/linux-x64/native/* bin/Release/" />
|
||||
<Exec Command="cp -f bin/Release/runtimes/win-x64/native/* bin/Release/" />
|
||||
<Exec Command="rm -rf bin/Release/runtimes" />
|
||||
</Target>
|
||||
<Target Name="PostBuild-Debug" AfterTargets="PostBuildEvent" Condition="'$(Configuration)' == 'Debug'">
|
||||
<Exec Command="cp -f bin/Debug/runtimes/linux-x64/native/* bin/Debug/" />
|
||||
<Exec Command="cp -f bin/Debug/runtimes/win-x64/native/* bin/Debug/" />
|
||||
<Exec Command="rm -rf bin/Debug/runtimes" />
|
||||
</Target!-->
|
||||
|
||||
</Project>
|
||||
52
Launcher.Client.Avalonia/LauncherMain.cs
Normal file
@ -0,0 +1,52 @@
|
||||
global using System;
|
||||
global using System.Diagnostics;
|
||||
global using System.Net;
|
||||
global using System.Text;
|
||||
global using System.Collections.Generic;
|
||||
global using System.Linq;
|
||||
global using DTLib;
|
||||
global using DTLib.Dtsod;
|
||||
global using DTLib.Filesystem;
|
||||
global using DTLib.Extensions;
|
||||
global using Launcher.Client;
|
||||
global using static Launcher.Client.LauncherClient;
|
||||
global using static Launcher.Client.Avalonia.LauncherMain;
|
||||
using DTLib.Ben.Demystifier;
|
||||
using DTLib.Logging;
|
||||
using Launcher.Client.Avalonia.GUI;
|
||||
|
||||
namespace Launcher.Client.Avalonia;
|
||||
|
||||
public static class LauncherMain
|
||||
{
|
||||
public static LauncherWindow CurrentLauncherWindow;
|
||||
|
||||
//it's being used by Avalonia xml preview
|
||||
public static AppBuilder BuildAvaloniaApp() =>
|
||||
AppBuilder.Configure<App>()
|
||||
.UsePlatformDetect()
|
||||
.LogToTrace();
|
||||
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
try
|
||||
{
|
||||
LauncherClient.Init();
|
||||
var traceHandler = new ConsoleTraceListener();
|
||||
Trace.AutoFlush = true;
|
||||
Trace.Listeners.Add(traceHandler);
|
||||
BuildAvaloniaApp().StartWithClassicDesktopLifetime(args);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogError("STARTUP", ex);
|
||||
}
|
||||
}
|
||||
|
||||
public static void LogError(string context, Exception ex)
|
||||
{
|
||||
string errmsg = ex.ToStringDemystified();
|
||||
MessageBox.Show($"{context} ERROR", errmsg);
|
||||
Logger.LogError("Main", errmsg);
|
||||
}
|
||||
}
|
||||
85
Launcher.Client.Avalonia/Program.cs
Normal file
@ -0,0 +1,85 @@
|
||||
using Launcher.Client.Avalonia.GUI;
|
||||
|
||||
namespace Launcher.Client.Avalonia;
|
||||
|
||||
public class Program
|
||||
{
|
||||
public readonly string Name;
|
||||
public readonly string Directory;
|
||||
public readonly string Description;
|
||||
public readonly string IconFile;
|
||||
public readonly string BackgroundFile;
|
||||
public readonly string LaunchFile;
|
||||
public readonly string LaunchArgs;
|
||||
|
||||
public readonly ProgramLabel ProgramLabel;
|
||||
|
||||
public readonly string SettingsFile;
|
||||
public readonly DtsodV23 Settings;
|
||||
|
||||
public readonly StackPanel SettingsPanel;
|
||||
|
||||
private Process ProgramProcess;
|
||||
|
||||
public event Action<Program> ProgramSelectedEvent;
|
||||
|
||||
public Program(IOPath descriptorFile)
|
||||
{
|
||||
DtsodV23 descriptor= new(File.ReadAllText(descriptorFile));
|
||||
Name = descriptor["name"];
|
||||
Directory = descriptor["directory"];
|
||||
Description = descriptor["description"];
|
||||
IconFile = descriptor["icon"];
|
||||
BackgroundFile = descriptor["background"];
|
||||
string startcommand = descriptor["launchcommand"];
|
||||
LaunchFile = startcommand.Remove(startcommand.IndexOf(' '));
|
||||
LaunchArgs = startcommand.Remove(0,startcommand.IndexOf(' '));
|
||||
|
||||
ProgramLabel = new ProgramLabel(Name, IconFile);
|
||||
ProgramLabel.PointerPressed += (_, _) => ProgramSelectedEvent?.Invoke(this);
|
||||
|
||||
SettingsFile = $"settings{Path.Sep}{Directory}.settings";
|
||||
Settings = File.Exists(SettingsFile)
|
||||
? DtsodConverter.UpdateByDefault(
|
||||
new DtsodV23(File.ReadAllText(SettingsFile)),
|
||||
descriptor["default_settings"])
|
||||
: descriptor["default_settings"];
|
||||
File.WriteAllText(SettingsFile, Settings.ToString());
|
||||
SettingsPanel = new StackPanel();
|
||||
foreach (var setting in Settings)
|
||||
{
|
||||
ProgramSettingsPanelItem settingUi = new(setting.Key, setting.Value);
|
||||
settingUi.UpdatedEvent += UpdateSetting;
|
||||
SettingsPanel.Children.Add(settingUi);
|
||||
}
|
||||
}
|
||||
|
||||
void UpdateSetting(ProgramSettingsPanelItem uiElem)
|
||||
{
|
||||
Settings[uiElem.SettingKey] = uiElem.SettingValue;
|
||||
File.WriteAllText(SettingsFile, Settings.ToString());
|
||||
}
|
||||
|
||||
public void Launch()
|
||||
{
|
||||
if(ProgramProcess.HasExited)
|
||||
throw new Exception($"can't start program <{Name}>, because it hadn't stopped yet");
|
||||
ProgramProcess = Process.Start(LaunchFile, LaunchArgs);
|
||||
if (ProgramProcess is null)
|
||||
throw new Exception($"program <{Name}> started, but ProgramProcess is null");
|
||||
CurrentLauncherWindow.LaunchButton.Content = "Stop";
|
||||
ProgramProcess.Exited += ProgramExitedHandler;
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
{
|
||||
if (!ProgramProcess.HasExited)
|
||||
throw new Exception($"can't stop program <{Name}>, because it had stopped already");
|
||||
ProgramProcess.Kill(true);
|
||||
}
|
||||
|
||||
void ProgramExitedHandler(object sender, EventArgs eargs)
|
||||
{
|
||||
CurrentLauncherWindow.LaunchButton.Content = "Start";
|
||||
}
|
||||
}
|
||||
|
Before Width: | Height: | Size: 37 KiB After Width: | Height: | Size: 37 KiB |
|
After Width: | Height: | Size: 1.2 MiB |
|
After Width: | Height: | Size: 437 KiB |
@ -0,0 +1,7 @@
|
||||
#descriptor_version: 3;
|
||||
name: "Conan Exiles";
|
||||
description: "Сурвайвл на анриале в сеттинге Конана Варвара.";
|
||||
directory: "conan_exiles";
|
||||
icon: "conan_exiles.png";
|
||||
background: "conan_exiles_background.png";
|
||||
launchcommand: "cmd /c echo hello && pause";
|
||||
@ -0,0 +1,7 @@
|
||||
#descriptor_version: 3;
|
||||
name: "Divinity 2 Developer's Cut";
|
||||
description: "РПГ от Larian. Вид от третьего лица, проработанный мир, интересная боёвка.";
|
||||
directory: "divinity2_devcut";
|
||||
icon: "divinity2devcut.png";
|
||||
background: "divinity2devcut_background.jpg";
|
||||
launchcommand: "";
|
||||
BIN
Launcher.Client.Avalonia/debug_assets/fonts/fontinst.exe
Normal file
5
Launcher.Client.Avalonia/debug_assets/fonts/fontinst.inf
Normal file
@ -0,0 +1,5 @@
|
||||
[fonts]
|
||||
unispace.ttf
|
||||
unispace_bd.ttf
|
||||
unispace_it.ttf
|
||||
unispace_bd_it.ttf
|
||||
BIN
Launcher.Client.Avalonia/debug_assets/fonts/unispace.ttf
Normal file
BIN
Launcher.Client.Avalonia/debug_assets/fonts/unispace_bd.ttf
Normal file
BIN
Launcher.Client.Avalonia/debug_assets/fonts/unispace_bd_it.ttf
Normal file
BIN
Launcher.Client.Avalonia/debug_assets/fonts/unispace_it.ttf
Normal file
BIN
Launcher.Client.Avalonia/debug_assets/icons/conan_exiles.png
Normal file
|
After Width: | Height: | Size: 34 KiB |
BIN
Launcher.Client.Avalonia/debug_assets/icons/divinity2devcut.png
Normal file
|
After Width: | Height: | Size: 3.0 KiB |
@ -1,7 +1,8 @@
|
||||
<Application x:Class="launcher_client_win.GUI.App"
|
||||
<Application x:Class="Launcher.Client.WPF.GUI.App"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
|
||||
<Application.Resources>
|
||||
<SolidColorBrush x:Key="MyBackgroundColor" Color="#232328"/>
|
||||
<SolidColorBrush x:Key="MyDarkTr"
|
||||
Opacity="0.8"
|
||||
Color="#141419" />
|
||||
@ -30,7 +31,7 @@
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="{x:Type Thumb}">
|
||||
<Border x:Name="rectangle"
|
||||
Width="8"
|
||||
Width="6"
|
||||
Height="{TemplateBinding Height}"
|
||||
Background="{DynamicResource MyGray}"
|
||||
SnapsToDevicePixels="True" />
|
||||
@ -178,11 +179,26 @@
|
||||
<Setter Property="HorizontalAlignment" Value="Stretch" />
|
||||
<Setter Property="Background" Value="{DynamicResource MyDarkTr}" />
|
||||
<Setter Property="FontFamily" Value="Unispace" />
|
||||
<Setter Property="FontSize" Value="15" />
|
||||
<Setter Property="FontStyle" Value="Normal" />
|
||||
<Setter Property="FontSize" Value="14" />
|
||||
<Setter Property="Foreground" Value="{DynamicResource MyWhite}" />
|
||||
<!-->disables some shit which removes underscores from Content<!-->
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="{x:Type Label}">
|
||||
<Border Background="{TemplateBinding Background}"
|
||||
BorderThickness="{TemplateBinding BorderThickness}"
|
||||
BorderBrush="{TemplateBinding BorderBrush}"
|
||||
Padding="{TemplateBinding Padding}">
|
||||
<ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
|
||||
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
|
||||
RecognizesAccessKey="False" />
|
||||
</Border>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
|
||||
|
||||
<ControlTemplate x:Key="MyComboBox" TargetType="ComboBox">
|
||||
<Grid>
|
||||
<ToggleButton Focusable="false" IsChecked="{Binding Path=IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}">
|
||||
@ -1,6 +1,6 @@
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace launcher_client_win.GUI;
|
||||
namespace Launcher.Client.WPF.GUI;
|
||||
|
||||
public partial class App : Application
|
||||
{
|
||||
@ -21,7 +21,10 @@ public partial class App : Application
|
||||
_Main(e.Args);
|
||||
}
|
||||
catch(Exception ex)
|
||||
{ LogError("STARTUP",ex); }
|
||||
{
|
||||
LogError("STARTUP",ex);
|
||||
Shutdown();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,15 +1,15 @@
|
||||
<Window x:Class="launcher_client_win.GUI.LauncherWindow"
|
||||
<Window x:Class="Launcher.Client.WPF.GUI.LauncherWindow"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:launcher_client_win.GUI"
|
||||
xmlns:local="clr-namespace:Launcher.Client.WPF.GUI"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
Title="Launcher"
|
||||
Width="800"
|
||||
Height="500"
|
||||
MinWidth="800"
|
||||
MinHeight="500"
|
||||
Background="#232328"
|
||||
Background="{DynamicResource MyBackgroundColor}"
|
||||
mc:Ignorable="d">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
@ -72,7 +72,7 @@
|
||||
<ColumnDefinition Width="5" />
|
||||
<ColumnDefinition />
|
||||
<ColumnDefinition Width="5" />
|
||||
<ColumnDefinition Width="200" />
|
||||
<ColumnDefinition Width="220" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<ScrollViewer Grid.Column="0"
|
||||
HorizontalAlignment="Stretch"
|
||||
@ -1,36 +1,32 @@
|
||||
using System.Windows.Media.Imaging;
|
||||
using DTLib.Logging;
|
||||
|
||||
namespace launcher_client_win.GUI;
|
||||
namespace Launcher.Client.WPF.GUI;
|
||||
|
||||
public partial class LauncherWindow : Window
|
||||
{
|
||||
public LauncherWindow()
|
||||
{
|
||||
try
|
||||
{
|
||||
InitializeComponent();
|
||||
LogBox.Text = Logger.Buffer;
|
||||
Logger.MessageSent += LogHandler;
|
||||
LogfileLabel.Content = Logger.Logfile.Remove(0,Logger.Logfile.LastIndexOf(Path.Sep)+1);
|
||||
LogfileLabel.MouseLeftButtonDown += (s,e)=>
|
||||
Process.Start("explorer.exe", Logger.Logfile.Remove(Logger.Logfile.LastIndexOf(Path.Sep)));
|
||||
LogfileLabel.MouseEnter += (s,e)=>LogfileLabel.Foreground=App.MySelectionColor;
|
||||
LogfileLabel.MouseLeave += (s,e)=>LogfileLabel.Foreground=App.MyWhite;
|
||||
LibraryButton.TabGrid = LibraryGrid;
|
||||
DownloadsButton.TabGrid = DownloadsGrid;
|
||||
LogButton.TabGrid = LogGrid;
|
||||
SettingsButton.TabGrid = SettingsGrid;
|
||||
LibraryButton.Click += SelectTab;
|
||||
DownloadsButton.Click += SelectTab;
|
||||
LogButton.Click += SelectTab;
|
||||
SettingsButton.Click += SelectTab;
|
||||
ProgramGrid.Visibility = Visibility.Hidden;
|
||||
SelectTab(LibraryButton, null);
|
||||
FillProgramsPanel();
|
||||
Logger.Log("launcher started");
|
||||
}
|
||||
catch(Exception ex)
|
||||
{ LogError("LAUNCHER WINDOW INIT",ex); }
|
||||
InitializeComponent();
|
||||
LogBox.Text = Logger.Buffer;
|
||||
Logger.MessageSent += LogHandler;
|
||||
LogfileLabel.Content = Logger.LogfileName.Remove(0,Logger.LogfileName.LastIndexOf(Path.Sep)+1);
|
||||
LogfileLabel.MouseLeftButtonDown += (_,_)=>
|
||||
Process.Start("explorer.exe", LauncherLogger.LogfileDir.ToString()!);
|
||||
LogfileLabel.MouseEnter += (_,_)=>LogfileLabel.Foreground=App.MySelectionColor;
|
||||
LogfileLabel.MouseLeave += (_,_)=>LogfileLabel.Foreground=App.MyWhite;
|
||||
LibraryButton.TabGrid = LibraryGrid;
|
||||
DownloadsButton.TabGrid = DownloadsGrid;
|
||||
LogButton.TabGrid = LogGrid;
|
||||
SettingsButton.TabGrid = SettingsGrid;
|
||||
LibraryButton.Click += SelectTab;
|
||||
DownloadsButton.Click += SelectTab;
|
||||
LogButton.Click += SelectTab;
|
||||
SettingsButton.Click += SelectTab;
|
||||
ProgramGrid.Visibility = Visibility.Hidden;
|
||||
SelectTab(LibraryButton, null);
|
||||
FillProgramsPanel();
|
||||
Logger.LogInfo(nameof(LauncherWindow),"launcher started");
|
||||
}
|
||||
|
||||
void LogHandler(string m) => Dispatcher.Invoke(()=>LogBox.Text += m);
|
||||
@ -54,15 +50,15 @@ public partial class LauncherWindow : Window
|
||||
|
||||
private void FillProgramsPanel()
|
||||
{
|
||||
Logger.Log("reading descriptors...");
|
||||
string[] descriptors = Directory.GetFiles("descriptors");
|
||||
Logger.LogInfo(nameof(LauncherWindow),"reading descriptors...");
|
||||
var descriptors = Directory.GetFiles("descriptors");
|
||||
Programs = new Program[descriptors.Length];
|
||||
for (ushort i = 0; i < descriptors.Length; i++)
|
||||
{
|
||||
string descriptor = descriptors[i];
|
||||
var descriptor = descriptors[i];
|
||||
if(descriptor.EndsWith(".descriptor"))
|
||||
{
|
||||
Logger.Log('\t'+descriptor);
|
||||
Logger.LogInfo(nameof(LauncherWindow),descriptor.ToString());
|
||||
Programs[i] = new Program(descriptors[i]);
|
||||
ProgramsPanel.Children.Add(Programs[i].ProgramLabel);
|
||||
Programs[i].ProgramSelectedEvent += SelectProgram;
|
||||
@ -1,8 +1,8 @@
|
||||
<UserControl x:Class="launcher_client_win.GUI.ProgramLabel"
|
||||
<UserControl x:Class="Launcher.Client.WPF.GUI.ProgramLabel"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:launcher_client_win.GUI"
|
||||
xmlns:local="clr-namespace:Launcher.Client.WPF.GUI"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
Height="50"
|
||||
Background="{DynamicResource MyDarkTr}"
|
||||
@ -1,7 +1,7 @@
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Media.Imaging;
|
||||
|
||||
namespace launcher_client_win.GUI;
|
||||
namespace Launcher.Client.WPF.GUI;
|
||||
|
||||
public partial class ProgramLabel : UserControl
|
||||
{
|
||||
@ -1,11 +1,11 @@
|
||||
<UserControl x:Class="launcher_client_win.GUI.ProgramSettingsPanelItem"
|
||||
<UserControl x:Class="Launcher.Client.WPF.GUI.ProgramSettingsPanelItem"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:launcher_client_win.GUI"
|
||||
xmlns:local="clr-namespace:Launcher.Client.WPF.GUI"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
Height="30"
|
||||
d:DesignWidth="100"
|
||||
d:DesignHeight="30"
|
||||
mc:Ignorable="d"
|
||||
Background="Transparent">
|
||||
<Grid>
|
||||
@ -15,7 +15,9 @@
|
||||
</Grid.ColumnDefinitions>
|
||||
<Label Name="KeyLabel" Grid.Column="0"
|
||||
Content="{Binding SettingKey, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:ProgramSettingsPanelItem}}"
|
||||
Style="{DynamicResource MyLabelStyle}" />
|
||||
Style="{DynamicResource MyLabelStyle}"
|
||||
FontFamily="default"
|
||||
FontSize="16"/>
|
||||
<TextBox Name="ValueBox" Grid.Column="1"
|
||||
HorizontalScrollBarVisibility="Auto"
|
||||
Style="{DynamicResource MyTextBoxStyle}"
|
||||
@ -1,29 +1,40 @@
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace launcher_client_win.GUI;
|
||||
namespace Launcher.Client.WPF.GUI;
|
||||
|
||||
public partial class ProgramSettingsPanelItem : UserControl
|
||||
{
|
||||
public static readonly DependencyProperty SettingKeyProp = DependencyProperty.Register(
|
||||
"SettingKey",
|
||||
typeof(string),
|
||||
typeof(TabButton));
|
||||
typeof(ProgramSettingsPanelItem));
|
||||
public string SettingKey
|
||||
{
|
||||
get => (string)GetValue(SettingKeyProp);
|
||||
set => SetValue(SettingKeyProp, value);
|
||||
set
|
||||
{
|
||||
SetValue(SettingKeyProp, value);
|
||||
KeyLabel.ToolTip = new ToolTip
|
||||
{
|
||||
Content = value,
|
||||
Foreground = App.MyWhite,
|
||||
Background = App.MySoftDark
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty SettingValueProp = DependencyProperty.Register(
|
||||
"SettingValue",
|
||||
typeof(string),
|
||||
typeof(TabButton));
|
||||
typeof(ProgramSettingsPanelItem));
|
||||
public string SettingValue
|
||||
{
|
||||
get => (string)GetValue(SettingValueProp);
|
||||
set => SetValue(SettingValueProp, value);
|
||||
}
|
||||
|
||||
public event Action<ProgramSettingsPanelItem> UpdatedEvent;
|
||||
|
||||
public ProgramSettingsPanelItem(string key, string value)
|
||||
{
|
||||
InitializeComponent();
|
||||
@ -31,6 +42,4 @@ public partial class ProgramSettingsPanelItem : UserControl
|
||||
SettingValue = value;
|
||||
ValueBox.TextChanged += (_,_)=> UpdatedEvent?.Invoke(this);
|
||||
}
|
||||
|
||||
public event Action<ProgramSettingsPanelItem> UpdatedEvent;
|
||||
}
|
||||
@ -1,6 +1,6 @@
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace launcher_client_win.GUI;
|
||||
namespace Launcher.Client.WPF.GUI;
|
||||
|
||||
public class TabButton : Button
|
||||
{
|
||||
@ -3,19 +3,17 @@
|
||||
<PropertyGroup>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<UseWPF>true</UseWPF>
|
||||
<TargetFramework>net6.0-windows</TargetFramework>
|
||||
<RootNamespace>launcher_client_win</RootNamespace>
|
||||
<TargetFramework>net7.0-windows</TargetFramework>
|
||||
<RootNamespace>Launcher.Client.WPF</RootNamespace>
|
||||
<ImplicitUsings>disable</ImplicitUsings>
|
||||
<Nullable>disable</Nullable>
|
||||
<DebugType>full</DebugType>
|
||||
<ApplicationIcon>Resources\logo-D.ico</ApplicationIcon>
|
||||
<TargetCulture Label="Invariant" />
|
||||
<Configurations>Debug;Release</Configurations>
|
||||
<Platforms>AnyCPU</Platforms>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\DTLib\DTLib\DTLib.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ApplicationDefinition Include="GUI\App.xaml">
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
@ -23,6 +21,10 @@
|
||||
</ApplicationDefinition>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Launcher.Client\Launcher.Client.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="Resources\*" />
|
||||
</ItemGroup>
|
||||
40
Launcher.Client.WPF/LauncherMain.cs
Normal file
@ -0,0 +1,40 @@
|
||||
global using DTLib;
|
||||
global using DTLib.Dtsod;
|
||||
global using DTLib.Filesystem;
|
||||
global using DTLib.Extensions;
|
||||
global using System;
|
||||
global using System.Diagnostics;
|
||||
global using System.Net;
|
||||
global using System.Text;
|
||||
global using System.Collections.Generic;
|
||||
global using System.Linq;
|
||||
global using System.Windows;
|
||||
global using Launcher.Client;
|
||||
global using static Launcher.Client.LauncherClient;
|
||||
global using static Launcher.Client.WPF.LauncherMain;
|
||||
using DTLib.Ben.Demystifier;
|
||||
using DTLib.Logging;
|
||||
using Launcher.Client.WPF.GUI;
|
||||
|
||||
namespace Launcher.Client.WPF;
|
||||
|
||||
public static class LauncherMain
|
||||
{
|
||||
public static LauncherWindow CurrentLauncherWindow;
|
||||
|
||||
public static void _Main(string[] args)
|
||||
{
|
||||
Console.WriteLine("aaa\nbbb\nccc");
|
||||
return;
|
||||
LauncherClient.Init();
|
||||
CurrentLauncherWindow = new LauncherWindow();
|
||||
CurrentLauncherWindow.Show();
|
||||
}
|
||||
|
||||
public static void LogError(string context, Exception ex)
|
||||
{
|
||||
string errmsg = ex.ToStringDemystified();
|
||||
MessageBox.Show(errmsg);
|
||||
Logger.LogError(context, errmsg);
|
||||
}
|
||||
}
|
||||
@ -1,8 +1,7 @@
|
||||
using System.Windows.Controls;
|
||||
using launcher_client_win.GUI;
|
||||
using Path = DTLib.Filesystem.Path;
|
||||
using Launcher.Client.WPF.GUI;
|
||||
|
||||
namespace launcher_client_win;
|
||||
namespace Launcher.Client.WPF;
|
||||
|
||||
public class Program
|
||||
{
|
||||
@ -25,7 +24,7 @@ public class Program
|
||||
|
||||
public event Action<Program> ProgramSelectedEvent;
|
||||
|
||||
public Program(string descriptorFile)
|
||||
public Program(IOPath descriptorFile)
|
||||
{
|
||||
DtsodV23 descriptor= new(File.ReadAllText(descriptorFile));
|
||||
Name = descriptor["name"];
|
||||
@ -42,7 +41,7 @@ public class Program
|
||||
|
||||
SettingsFile = $"settings{Path.Sep}{Directory}.settings";
|
||||
Settings = File.Exists(SettingsFile)
|
||||
? DtsodFunctions.UpdateByDefault(
|
||||
? DtsodConverter.UpdateByDefault(
|
||||
new DtsodV23(File.ReadAllText(SettingsFile)),
|
||||
descriptor["default_settings"])
|
||||
: descriptor["default_settings"];
|
||||
BIN
Launcher.Client.WPF/Resources/logo-D.ico
Normal file
|
After Width: | Height: | Size: 37 KiB |
38
Launcher.Client/BufferedLogger.cs
Normal file
@ -0,0 +1,38 @@
|
||||
using DTLib.Logging;
|
||||
|
||||
namespace Launcher.Client;
|
||||
|
||||
public class BufferedLogger : ILogger
|
||||
{
|
||||
public bool DebugLogEnabled { get; set; } =
|
||||
#if DEBUG
|
||||
true;
|
||||
#else
|
||||
false;
|
||||
#endif
|
||||
public bool InfoLogEnabled { get; set; } = true;
|
||||
public bool WarnLogEnabled { get; set; } = true;
|
||||
public bool ErrorLogEnabled { get; set; } = true;
|
||||
|
||||
public ILogFormat Format { get; set; } = new DefaultLogFormat();
|
||||
|
||||
private readonly StringBuilder _buffer = new();
|
||||
public string Buffer
|
||||
{
|
||||
get { lock (_buffer) return _buffer.ToString(); }
|
||||
}
|
||||
|
||||
public event Action<string> MessageSent;
|
||||
|
||||
|
||||
public void Log(string context, LogSeverity severity, object message, ILogFormat format)
|
||||
{
|
||||
string msgConnected = Format.CreateMessage(context, severity, message);
|
||||
MessageSent?.Invoke(msgConnected);
|
||||
lock (_buffer) _buffer.Append(msgConnected);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
}
|
||||
}
|
||||
26
Launcher.Client/Launcher.Client.csproj
Normal file
@ -0,0 +1,26 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<ImplicitUsings>disable</ImplicitUsings>
|
||||
<Nullable>disable</Nullable>
|
||||
<RootNamespace>Launcher.Client</RootNamespace>
|
||||
<DebugType>full</DebugType>
|
||||
<Configurations>Debug;Release</Configurations>
|
||||
<Platforms>AnyCPU</Platforms>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Remove="Resources\**\*" />
|
||||
<EmbeddedResource Include="Resources\**\*" />
|
||||
<Compile Remove="debug_assets\**\*" />
|
||||
<None Update="debug_assets\**\*" CopyToOutputDirectory="Always" Condition="'$(Configuration)' == 'Debug'" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="DTLib.Dtsod" Version="1.3.0" />
|
||||
<PackageReference Include="DTLib.Logging" Version="1.3.0" />
|
||||
<PackageReference Include="DTLib.Network" Version="1.3.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
40
Launcher.Client/LauncherClient.cs
Normal file
@ -0,0 +1,40 @@
|
||||
global using System;
|
||||
global using System.Diagnostics;
|
||||
global using System.Net;
|
||||
global using System.Text;
|
||||
global using System.Collections.Generic;
|
||||
global using System.Linq;
|
||||
global using DTLib;
|
||||
global using DTLib.Dtsod;
|
||||
global using DTLib.Filesystem;
|
||||
global using DTLib.Extensions;
|
||||
using DTLib.Logging;
|
||||
|
||||
namespace Launcher.Client;
|
||||
|
||||
public static class LauncherClient
|
||||
{
|
||||
public static LauncherConfig Config;
|
||||
public static readonly LauncherLogger Logger = new();
|
||||
|
||||
public static void Init()
|
||||
{
|
||||
Logger.LogInfo(nameof(LauncherClient),"launcher starting...");
|
||||
Config = new LauncherConfig();
|
||||
#if DEBUG
|
||||
const string debug_assets = "debug_assets";
|
||||
foreach (string file in Directory.GetFiles(debug_assets))
|
||||
File.Copy(file, file.Remove(0, file.LastIndexOf(Path.Sep) + 1), true);
|
||||
foreach (string subdir in Directory.GetDirectories(debug_assets))
|
||||
Directory.Copy(subdir, subdir.Remove(0, subdir.LastIndexOf(Path.Sep) + 1), true);
|
||||
Directory.Delete(debug_assets);
|
||||
#endif
|
||||
Directory.Create("descriptors");
|
||||
Directory.Create("icons");
|
||||
Directory.Create("backgrounds");
|
||||
Directory.Create("installed");
|
||||
Directory.Create("settings");
|
||||
File.WriteAllText($"descriptors{Path.Sep}default.descriptor.template",
|
||||
EmbeddedResources.ReadText("Launcher.Client.Resources.default.descriptor.template"));
|
||||
}
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
namespace launcher_client_win;
|
||||
namespace Launcher.Client;
|
||||
|
||||
public class LauncherConfig
|
||||
{
|
||||
@ -21,12 +21,12 @@ public class LauncherConfig
|
||||
{
|
||||
// читает дефолтный конфиг из ресурсов
|
||||
DtsodV23 updatedConfig;
|
||||
DtsodV23 updatedDefault = new(ReadResource("launcher_client_win.Resources.launcher.dtsod"));
|
||||
DtsodV23 updatedDefault = new(EmbeddedResources.ReadText("Launcher.Client.Resources.launcher.dtsod"));
|
||||
// проверка и обновление конфига
|
||||
if (File.Exists(configFile))
|
||||
{
|
||||
DtsodV23 oldConfig = new(File.ReadAllText(configFile));
|
||||
updatedConfig = DtsodFunctions.UpdateByDefault(oldConfig, updatedDefault);
|
||||
updatedConfig = DtsodConverter.UpdateByDefault(oldConfig, updatedDefault);
|
||||
}
|
||||
else updatedConfig = updatedDefault;
|
||||
|
||||
23
Launcher.Client/LauncherLogger.cs
Normal file
@ -0,0 +1,23 @@
|
||||
using DTLib.Logging;
|
||||
|
||||
namespace Launcher.Client;
|
||||
|
||||
public class LauncherLogger : CompositeLogger
|
||||
{
|
||||
public static readonly IOPath LogfileDir = "launcher-logs";
|
||||
public readonly string LogfileName;
|
||||
public event Action<string> MessageSent;
|
||||
public string Buffer => _bufferedLogger.Buffer;
|
||||
|
||||
|
||||
FileLogger _fileLogger = new(LogfileDir,"launcher-client");
|
||||
ConsoleLogger _consoleLogger = new();
|
||||
BufferedLogger _bufferedLogger = new BufferedLogger();
|
||||
|
||||
public LauncherLogger()
|
||||
{
|
||||
_loggers = new ILogger[] { _fileLogger, _consoleLogger, _bufferedLogger };
|
||||
LogfileName = _fileLogger.LogfileName.Str;
|
||||
_bufferedLogger.MessageSent += s => MessageSent?.Invoke(s);
|
||||
}
|
||||
}
|
||||
6
Launcher.Client/ProgramDescriptor.cs
Normal file
@ -0,0 +1,6 @@
|
||||
namespace Launcher.Client;
|
||||
|
||||
public class ProgramDescriptor
|
||||
{
|
||||
|
||||
}
|
||||
@ -1,6 +1,7 @@
|
||||
name: ""; #label, which displays in launcher
|
||||
directory: ""; #name of program' directory on server and client
|
||||
#descriptor_version: 3;
|
||||
name: ""; #label, which displays in launcher
|
||||
description: ""; #desctiption, which displays in launcher
|
||||
directory: ""; #name of program directory on server and client
|
||||
icon: ""; #name of the icon file
|
||||
background: ""; #name of the background file
|
||||
launchcommand: ""; #command, which starts the program
|
||||
|
After Width: | Height: | Size: 1.2 MiB |
|
After Width: | Height: | Size: 437 KiB |
@ -0,0 +1,7 @@
|
||||
#descriptor_version: 3;
|
||||
name: "Conan Exiles";
|
||||
description: "Сурвайвл на анриале в сеттинге Конана Варвара.";
|
||||
directory: "conan_exiles";
|
||||
icon: "conan_exiles.png";
|
||||
background: "conan_exiles_background.png";
|
||||
launchcommand: "cmd /c echo hello && pause";
|
||||
@ -0,0 +1,7 @@
|
||||
#descriptor_version: 3;
|
||||
name: "Divinity 2 Developer's Cut";
|
||||
description: "РПГ от Larian. Вид от третьего лица, проработанный мир, интересная боёвка.";
|
||||
directory: "divinity2_devcut";
|
||||
icon: "divinity2devcut.png";
|
||||
background: "divinity2devcut_background.jpg";
|
||||
launchcommand: "";
|
||||
BIN
Launcher.Client/debug_assets/fonts/fontinst.exe
Normal file
5
Launcher.Client/debug_assets/fonts/fontinst.inf
Normal file
@ -0,0 +1,5 @@
|
||||
[fonts]
|
||||
unispace.ttf
|
||||
unispace_bd.ttf
|
||||
unispace_it.ttf
|
||||
unispace_bd_it.ttf
|
||||
BIN
Launcher.Client/debug_assets/fonts/unispace.ttf
Normal file
BIN
Launcher.Client/debug_assets/fonts/unispace_bd.ttf
Normal file
BIN
Launcher.Client/debug_assets/fonts/unispace_bd_it.ttf
Normal file
BIN
Launcher.Client/debug_assets/fonts/unispace_it.ttf
Normal file
BIN
Launcher.Client/debug_assets/icons/conan_exiles.png
Normal file
|
After Width: | Height: | Size: 34 KiB |
BIN
Launcher.Client/debug_assets/icons/divinity2devcut.png
Normal file
|
After Width: | Height: | Size: 3.0 KiB |
@ -2,21 +2,25 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<RootNamespace>launcher_server</RootNamespace>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<RootNamespace>Launcher.Server</RootNamespace>
|
||||
<ImplicitUsings>disable</ImplicitUsings>
|
||||
<Nullable>disable</Nullable>
|
||||
<DebugType>full</DebugType>
|
||||
<Configurations>Debug;Release</Configurations>
|
||||
<Platforms>AnyCPU</Platforms>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\DTLib\DTLib\DTLib.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="launcher-server.dtsod">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="DTLib.Dtsod" Version="1.3.0" />
|
||||
<PackageReference Include="DTLib.Logging" Version="1.3.0" />
|
||||
<PackageReference Include="DTLib.Network" Version="1.3.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@ -9,61 +9,63 @@ global using System.Net.Sockets;
|
||||
global using System.Text;
|
||||
global using System.Threading;
|
||||
global using System.Linq;
|
||||
using System.Globalization;
|
||||
using DTLib.Logging;
|
||||
|
||||
namespace launcher_server;
|
||||
namespace Launcher.Server;
|
||||
|
||||
static class Server
|
||||
{
|
||||
static readonly Socket mainSocket = new(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
|
||||
static DtsodV23 config;
|
||||
private static readonly DTLib.Loggers.AsyncLogger Logger = new("logs", "launcher-server");
|
||||
private static readonly CompositeLogger Logger = new(
|
||||
new ConsoleLogger(),
|
||||
new FileLogger("logs", "launcher-server"));
|
||||
|
||||
static readonly object manifestLocker = new();
|
||||
|
||||
static void Main(string[] args)
|
||||
static void Main()
|
||||
{
|
||||
try
|
||||
{
|
||||
Console.Title = "minecraft_launcher_server";
|
||||
Console.Title = "Launcher.Server";
|
||||
Console.InputEncoding = Encoding.Unicode;
|
||||
Console.OutputEncoding = Encoding.Unicode;
|
||||
Logger.Enable();
|
||||
PublicLog.LogEvent += Logger.LogAsync;
|
||||
PublicLog.LogNoTimeEvent += Logger.LogAsync;
|
||||
DTLibInternalLogging.SetLogger(Logger);
|
||||
config = new DtsodV23(File.ReadAllText("launcher-server.dtsod"));
|
||||
Logger.Log("b", "local address: <", "c", config["local_ip"], "b",
|
||||
">\npublic address: <", "c", OldNetwork.GetPublicIP(), "b",
|
||||
">\nport: <", "c", config["local_port"].ToString(), "b", ">");
|
||||
Logger.LogInfo("Main", $"""
|
||||
local address: {config["local_ip"]}
|
||||
public address: {OldNetwork.GetPublicIP()}
|
||||
port: {config["local_port"]}
|
||||
""");
|
||||
mainSocket.Bind(new IPEndPoint(IPAddress.Parse(config["local_ip"]), config["local_port"]));
|
||||
mainSocket.Listen(1000);
|
||||
CreateManifests();
|
||||
Logger.Log("g", "server started succesfully");
|
||||
Logger.LogInfo("Main", "server started succesfully");
|
||||
// запуск отдельного потока для каждого юзера
|
||||
Logger.Log("b", "waiting for users");
|
||||
Logger.LogInfo("Main", "waiting for users");
|
||||
while (true)
|
||||
{
|
||||
var userSocket = mainSocket.Accept();
|
||||
var userThread = new Thread((obj) => UserHandle((Socket)obj));
|
||||
var userThread = new Thread((obj) => HandleUser((Socket)obj));
|
||||
userThread.Start(userSocket);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.Log("r", ex.ToString());
|
||||
Logger.LogError("Main", ex);
|
||||
if (mainSocket.Connected)
|
||||
{
|
||||
mainSocket.Shutdown(SocketShutdown.Both);
|
||||
mainSocket.Close();
|
||||
}
|
||||
}
|
||||
Logger.Log("gray", "");
|
||||
Console.ResetColor();
|
||||
}
|
||||
|
||||
// запускается для каждого юзера в отдельном потоке
|
||||
static void UserHandle(Socket handlerSocket)
|
||||
static void HandleUser(Socket handlerSocket)
|
||||
{
|
||||
Logger.LogAsync("b", "user connecting... ");
|
||||
Logger.LogInfo("HandleUser", "user connecting...");
|
||||
try
|
||||
{
|
||||
// запрос хеша пароля и логина
|
||||
@ -74,7 +76,7 @@ static class Server
|
||||
// запрос от апдейтера
|
||||
if (hash == hasher.HashCycled("updater".ToBytes(),64))
|
||||
{
|
||||
Logger.LogAsync("b", "user is ", "c", "updater");
|
||||
Logger.LogInfo("HandleUser", "user is updater");
|
||||
handlerSocket.SendPackage("updater".ToBytes());
|
||||
// обработка запросов
|
||||
while (true)
|
||||
@ -85,19 +87,19 @@ static class Server
|
||||
switch (request)
|
||||
{
|
||||
case "requesting launcher update":
|
||||
Logger.LogAsync("b", "updater requested client.exe");
|
||||
Logger.LogInfo("HandleUser", "updater requested client.exe");
|
||||
fsp.UploadFile("share\\launcher.exe");
|
||||
break;
|
||||
case "register new user":
|
||||
Logger.LogAsync("b", "new user registration requested");
|
||||
Logger.LogInfo("HandleUser", "new user registration requested");
|
||||
handlerSocket.SendPackage("ready".ToBytes());
|
||||
string req = StringConverter.MergeToString(
|
||||
hasher.HashCycled(handlerSocket.GetPackage(), 64).HashToString(),
|
||||
":\n{\n\tusername: \"", handlerSocket.GetPackage().ToString(),
|
||||
"\";\n\tuuid: \"null\";\n};");
|
||||
string filepath = $"registration_requests\\{DateTime.Now.ToString(CultureInfo.InvariantCulture).NormalizeAsPath()}.req";
|
||||
var filepath = Path.Concat("registration_requests", DateTime.Now.ToString(MyTimeFormat.ForFileNames), ".req");
|
||||
File.WriteAllText(filepath, req);
|
||||
Logger.LogAsync("b", $"text wrote to file <", "c", $"registration_requests\\{filepath}", "b", ">");
|
||||
Logger.LogInfo("HandleUser", $"text wrote to file <{filepath}>");
|
||||
break;
|
||||
default:
|
||||
throw new Exception("unknown request: " + request);
|
||||
@ -109,7 +111,7 @@ static class Server
|
||||
// запрос от юзера
|
||||
else if (FindUser(hash, out var user))
|
||||
{
|
||||
Logger.LogAsync("b", $"user is ", "c", user.name);
|
||||
Logger.LogInfo("HandleUser", "user is " + user.name);
|
||||
handlerSocket.SendPackage("launcher".ToBytes());
|
||||
// обработка запросов
|
||||
while (true)
|
||||
@ -120,26 +122,26 @@ static class Server
|
||||
switch (request)
|
||||
{
|
||||
case "requesting file download":
|
||||
var file = handlerSocket.GetPackage().ToString();
|
||||
Logger.LogAsync("b", $"user ", "c", user.name, "b", " requested file ", "c", file);
|
||||
if (file == "manifest.dtsod")
|
||||
{
|
||||
lock (manifestLocker) fsp.UploadFile("share\\manifest.dtsod");
|
||||
}
|
||||
else fsp.UploadFile("share\\" + file);
|
||||
var requestedFile = Path.Concat("share",handlerSocket.GetPackage().ToString());
|
||||
Logger.LogInfo("HandleUser", $"user {user.name} requested file {requestedFile}");
|
||||
if (requestedFile == "share/manifest.dtsod")
|
||||
lock (manifestLocker)
|
||||
fsp.UploadFile(requestedFile.ToString());
|
||||
else fsp.UploadFile(requestedFile.ToString());
|
||||
break;
|
||||
case "requesting uuid":
|
||||
Logger.LogAsync("b", $"user ", "c", user.name, "b", " requested uuid");
|
||||
Logger.LogInfo("HandleUser", "user " + user.name + " requested uuid");
|
||||
handlerSocket.SendPackage(user.uuid.ToBytes());
|
||||
break;
|
||||
case "excess files found":
|
||||
Logger.LogAsync("b", $"user ", "c", user.name, "b", " sent excess files list");
|
||||
fsp.DownloadFile($"excesses\\{user.name}-{DateTime.Now.ToString(CultureInfo.InvariantCulture).NormalizeAsPath()}.txt");
|
||||
Logger.LogInfo("HandleUser", "user " + user.name + " sent excess files list");
|
||||
fsp.DownloadFile(Path.Concat(
|
||||
"excesses",user.name, DateTime.Now.ToString(MyTimeFormat.ForFileNames),".txt")
|
||||
.ToString());
|
||||
break;
|
||||
case "sending launcher error":
|
||||
Logger.LogAsync("y", "user ", "c", user.name, "y", "is sending error:");
|
||||
string error = handlerSocket.GetPackage().ToString();
|
||||
Logger.LogAsync("y", error + '\n');
|
||||
Logger.LogWarn("HandleUser", "user "+ user.name + "is sending error:\n"+error);
|
||||
break;
|
||||
default:
|
||||
throw new Exception("unknown request: " + request);
|
||||
@ -151,13 +153,13 @@ static class Server
|
||||
// неизвестный юзер
|
||||
else
|
||||
{
|
||||
Logger.LogAsync("y", $"user with hash <{hash.HashToString()}> not found");
|
||||
Logger.LogWarn("HandleUser", $"user with hash {hash.HashToString()} not found");
|
||||
handlerSocket.SendPackage("user not found".ToBytes());
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.LogAsync("y", $"UserStart() error:\n message:\n {ex}");
|
||||
Logger.LogWarn("HandleUser", ex);
|
||||
if (mainSocket.Connected)
|
||||
{
|
||||
mainSocket.Shutdown(SocketShutdown.Both);
|
||||
@ -166,9 +168,10 @@ static class Server
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (handlerSocket.Connected) handlerSocket.Shutdown(SocketShutdown.Both);
|
||||
if (handlerSocket.Connected)
|
||||
handlerSocket.Shutdown(SocketShutdown.Both);
|
||||
handlerSocket.Close();
|
||||
Logger.LogAsync("g", "user disconnected");
|
||||
Logger.LogInfo("HandleUser", "user disconnected");
|
||||
}
|
||||
}
|
||||
|
||||
@ -185,12 +188,12 @@ static class Server
|
||||
foreach (string dir in Directory.GetDirectories("share\\sync_and_remove"))
|
||||
FSP.CreateManifest(dir);
|
||||
File.WriteAllText("share\\sync_and_remove\\dirlist.dtsod",
|
||||
$"dirs: [\""+
|
||||
"dirs: [\""+
|
||||
Directory.GetDirectories("share\\sync_and_remove")
|
||||
.MergeToString("\",\"")
|
||||
.Replace("share\\sync_and_remove\\", "")+
|
||||
"\"];");
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
static bool FindUser(byte[] hash, out (string name, string uuid) user)
|
||||
7
README.md
Normal file
@ -0,0 +1,7 @@
|
||||
# dtlauncher
|
||||
|
||||
launcher for my... idk.. something
|
||||
|
||||
\
|
||||
requires DTLib\
|
||||
https://github.com/Timerix22/DTLib
|
||||
@ -3,11 +3,19 @@ Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.1.32104.313
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "launcher-server", "launcher-server\launcher-server.csproj", "{1F4D14EB-AF48-4B6C-A91B-B294D4281173}"
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Launcher.Server", "Launcher.Server\Launcher.Server.csproj", "{1F4D14EB-AF48-4B6C-A91B-B294D4281173}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "launcher-client-win", "launcher-client-win\launcher-client-win.csproj", "{A1F770F3-F6B1-4854-9BF0-093F85064B88}"
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Launcher.Client.WPF", "Launcher.Client.WPF\Launcher.Client.WPF.csproj", "{A1F770F3-F6B1-4854-9BF0-093F85064B88}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DTLib", "..\DTLib\DTLib\DTLib.csproj", "{04B926C4-E9E8-4BDB-90E6-5D34C9F738C4}"
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Files", "Solution Files", "{F567AA49-E96B-43BD-95B5-A71F9FCB64E1}"
|
||||
ProjectSection(SolutionItems) = preProject
|
||||
.gitignore = .gitignore
|
||||
README.md = README.md
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Launcher.Client.Avalonia", "Launcher.Client.Avalonia\Launcher.Client.Avalonia.csproj", "{BC1FC2A0-159A-4F17-B076-B39775FB6AAC}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Launcher.Client", "Launcher.Client\Launcher.Client.csproj", "{87427137-840D-4D09-A101-9481110682BD}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
@ -23,10 +31,14 @@ Global
|
||||
{A1F770F3-F6B1-4854-9BF0-093F85064B88}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{A1F770F3-F6B1-4854-9BF0-093F85064B88}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{A1F770F3-F6B1-4854-9BF0-093F85064B88}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{04B926C4-E9E8-4BDB-90E6-5D34C9F738C4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{04B926C4-E9E8-4BDB-90E6-5D34C9F738C4}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{04B926C4-E9E8-4BDB-90E6-5D34C9F738C4}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{04B926C4-E9E8-4BDB-90E6-5D34C9F738C4}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{BC1FC2A0-159A-4F17-B076-B39775FB6AAC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{BC1FC2A0-159A-4F17-B076-B39775FB6AAC}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{BC1FC2A0-159A-4F17-B076-B39775FB6AAC}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{BC1FC2A0-159A-4F17-B076-B39775FB6AAC}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{87427137-840D-4D09-A101-9481110682BD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{87427137-840D-4D09-A101-9481110682BD}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{87427137-840D-4D09-A101-9481110682BD}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{87427137-840D-4D09-A101-9481110682BD}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
||||
@ -1,8 +0,0 @@
|
||||
[assembly:ThemeInfo(
|
||||
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
|
||||
//(used if a resource is not found in the page,
|
||||
// or application resource dictionaries)
|
||||
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
|
||||
//(used if a resource is not found in the page,
|
||||
// app, or any theme specific resource dictionaries)
|
||||
)]
|
||||
@ -1,57 +0,0 @@
|
||||
global using DTLib;
|
||||
global using DTLib.Dtsod;
|
||||
global using DTLib.Filesystem;
|
||||
global using DTLib.Network;
|
||||
global using DTLib.Extensions;
|
||||
global using System;
|
||||
global using System.Diagnostics;
|
||||
global using System.Net;
|
||||
global using System.Net.Sockets;
|
||||
global using System.Text;
|
||||
global using System.Collections.Generic;
|
||||
global using System.Threading;
|
||||
global using System.Linq;
|
||||
global using System.Windows;
|
||||
global using static launcher_client_win.Launcher;
|
||||
using System.Reflection;
|
||||
using launcher_client_win.GUI;
|
||||
|
||||
namespace launcher_client_win;
|
||||
|
||||
public static class Launcher
|
||||
{
|
||||
public static LauncherConfig Config;
|
||||
public static readonly LauncherLogger Logger = new();
|
||||
public static LauncherWindow CurrentLauncherWindow;
|
||||
|
||||
public static void _Main(string[] args)
|
||||
{
|
||||
Logger.Enable();
|
||||
Config = new LauncherConfig();
|
||||
Directory.Create("descriptors");
|
||||
Directory.Create("icons");
|
||||
Directory.Create("backgrounds");
|
||||
Directory.Create("installed");
|
||||
Directory.Create("settings");
|
||||
File.WriteAllText($"descriptors{Path.Sep}default.descriptor.template",
|
||||
ReadResource("launcher_client_win.Resources.default.descriptor.template"));
|
||||
CurrentLauncherWindow = new();
|
||||
CurrentLauncherWindow.Show();
|
||||
}
|
||||
|
||||
public static string ReadResource(string resource_path)
|
||||
{
|
||||
using var resourceStreamReader = new System.IO.StreamReader(
|
||||
Assembly.GetExecutingAssembly().GetManifestResourceStream(resource_path)
|
||||
?? throw new Exception($"embedded resource <{resource_path}> not found"),
|
||||
Encoding.UTF8);
|
||||
return resourceStreamReader.ReadToEnd();
|
||||
}
|
||||
|
||||
public static void LogError(string context, Exception ex)
|
||||
{
|
||||
string errmsg = $"{context} ERROR:\n{ex}";
|
||||
MessageBox.Show(errmsg);
|
||||
Logger.Log(errmsg);
|
||||
}
|
||||
}
|
||||
@ -1,36 +0,0 @@
|
||||
using System.Globalization;
|
||||
using DTLib.Loggers;
|
||||
|
||||
namespace launcher_client_win;
|
||||
|
||||
public class LauncherLogger : BaseLogger
|
||||
{
|
||||
public string Buffer="";
|
||||
|
||||
public LauncherLogger() : base("launcher-logs", "launcher-client-win")
|
||||
{ }
|
||||
|
||||
public event Action<string> MessageSent;
|
||||
|
||||
public override void Log(params string[] msg)
|
||||
{
|
||||
lock (Logfile) if (!IsEnabled) return;
|
||||
|
||||
StringBuilder strB = new();
|
||||
strB.Append('[')
|
||||
.Append(DateTime.Now.ToString(CultureInfo.InvariantCulture))
|
||||
.Append("]: ");
|
||||
if (msg.Length == 1) strB.Append(msg[0]);
|
||||
else for (ushort i = 0; i < msg.Length; i++)
|
||||
strB.Append(msg[++i]);
|
||||
strB.Append('\n');
|
||||
string _buffer = strB.ToString();
|
||||
|
||||
lock(Buffer) Buffer += _buffer;
|
||||
|
||||
MessageSent?.Invoke(_buffer);
|
||||
|
||||
if (WriteToFile)
|
||||
lock(Logfile) File.AppendAllText(Logfile, _buffer);
|
||||
}
|
||||
}
|
||||