Compare commits

..

No commits in common. "minecraft-launcher-v2" and "main" have entirely different histories.

85 changed files with 2179 additions and 891 deletions

View File

@ -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>

View 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>

View 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();
}
}
}

View 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>

View 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); }
}
}

View 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>

View 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();
}
}

View 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>

View 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}");
}
}

View 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>

View File

@ -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);
}
}

View 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() {}
}

View 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>

View 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);
}
}

View 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";
}
}

View File

Before

Width:  |  Height:  |  Size: 37 KiB

After

Width:  |  Height:  |  Size: 37 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 437 KiB

View File

@ -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";

View File

@ -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: "";

View File

@ -0,0 +1,5 @@
[fonts]
unispace.ttf
unispace_bd.ttf
unispace_it.ttf
unispace_bd_it.ttf

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

View File

@ -0,0 +1,265 @@
<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" />
<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" />
<ControlTemplate x:Key="myScrollBar" TargetType="{x:Type ScrollBar}">
<Grid x:Name="Bg" SnapsToDevicePixels="True">
<Border Background="{Binding Background, RelativeSource={RelativeSource TemplatedParent}}"
BorderBrush="{DynamicResource MyDarkTr}"
BorderThickness="0" />
<Track x:Name="PART_Track"
IsDirectionReversed="True"
IsEnabled="{TemplateBinding IsMouseOver}">
<Track.Thumb>
<Thumb>
<Thumb.Style>
<Style TargetType="{x:Type Thumb}">
<Setter Property="OverridesDefaultStyle" Value="True" />
<Setter Property="IsTabStop" Value="False" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Thumb}">
<Border x:Name="rectangle"
Width="6"
Height="{TemplateBinding Height}"
Background="{DynamicResource MyGray}"
SnapsToDevicePixels="True" />
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="rectangle" Property="Background" Value="{DynamicResource MyGray}" />
</Trigger>
<Trigger Property="IsDragging" Value="True">
<Setter TargetName="rectangle" Property="Background" Value="{DynamicResource MySelectionColor}" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Thumb.Style>
</Thumb>
</Track.Thumb>
</Track>
</Grid>
</ControlTemplate>
<ControlTemplate x:Key="myScrollViewer" TargetType="{x:Type ScrollViewer}">
<Grid x:Name="Grid">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Rectangle x:Name="Corner"
Grid.Row="1"
Grid.Column="1"
Fill="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" />
<ScrollContentPresenter x:Name="PART_ScrollContentPresenter"
Grid.Row="0"
Grid.Column="0"
Margin="{TemplateBinding Padding}"
CanContentScroll="{TemplateBinding CanContentScroll}"
CanHorizontallyScroll="False"
CanVerticallyScroll="False"
Content="{TemplateBinding Content}"
ContentTemplate="{TemplateBinding ContentTemplate}" />
<ScrollBar x:Name="PART_VerticalScrollBar"
Grid.Row="0"
Grid.Column="1"
AutomationProperties.AutomationId="VerticalScrollBar"
Background="{Binding Background, RelativeSource={RelativeSource TemplatedParent}}"
Cursor="Arrow"
Maximum="{TemplateBinding ScrollableHeight}"
Minimum="0"
Template="{DynamicResource myScrollBar}"
ViewportSize="{TemplateBinding ViewportHeight}"
Visibility="{TemplateBinding ComputedVerticalScrollBarVisibility}"
Value="{Binding VerticalOffset, Mode=OneWay, RelativeSource={RelativeSource TemplatedParent}}" />
<ScrollBar x:Name="PART_HorizontalScrollBar"
Grid.Row="1"
Grid.Column="0"
AutomationProperties.AutomationId="HorizontalScrollBar"
Background="{Binding Background, RelativeSource={RelativeSource TemplatedParent}}"
Cursor="Arrow"
Maximum="{TemplateBinding ScrollableWidth}"
Minimum="0"
Orientation="Horizontal"
Template="{DynamicResource myScrollBar}"
ViewportSize="{TemplateBinding ViewportWidth}"
Visibility="{TemplateBinding ComputedHorizontalScrollBarVisibility}"
Value="{Binding HorizontalOffset, Mode=OneWay, RelativeSource={RelativeSource TemplatedParent}}" />
</Grid>
</ControlTemplate>
<Style x:Key="MyTextBoxStyle" TargetType="TextBox">
<Setter Property="IsReadOnly" Value="True" />
<Setter Property="Background" Value="{DynamicResource MyDarkTr}" />
<Setter Property="FontSize" Value="16" />
<Setter Property="Foreground" Value="{DynamicResource MyWhite}" />
<Setter Property="SelectionBrush" Value="{DynamicResource MySelectionColor}" />
<Setter Property="Template" Value="{DynamicResource myTextBox}" />
<Setter Property="TextWrapping" Value="Wrap" />
</Style>
<ControlTemplate x:Key="myTextBox" TargetType="{x:Type TextBoxBase}">
<Border Name="Border"
Padding="0"
Background="{Binding Background, RelativeSource={RelativeSource TemplatedParent}}"
BorderBrush="{Binding Background, RelativeSource={RelativeSource TemplatedParent}}"
BorderThickness="2">
<ScrollViewer x:Name="PART_ContentHost"
Margin="0"
Template="{DynamicResource myScrollViewer}" />
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsEnabled" Value="False">
<Setter TargetName="Border" Property="Background" Value="Black" />
<Setter TargetName="Border" Property="BorderBrush" Value="White" />
<Setter Property="Foreground" Value="White" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
<Style x:Key="MyButtonStyle" TargetType="Button">
<Setter Property="Template" Value="{DynamicResource MyButton}" />
<Setter Property="Background" Value="{DynamicResource MyDarkTr}" />
<Setter Property="BorderThickness" Value="3" />
<Setter Property="FontFamily" Value="Unispace" />
<Setter Property="FontSize" Value="16" />
<Setter Property="FontWeight" Value="Bold" />
<Setter Property="Foreground" Value="{DynamicResource MyWhite}" />
</Style>
<ControlTemplate x:Key="MyButton" TargetType="Button">
<Border x:Name="Border"
Background="{Binding Background, RelativeSource={RelativeSource TemplatedParent}}"
BorderBrush="{Binding Foreground, RelativeSource={RelativeSource TemplatedParent}}"
BorderThickness="{Binding BorderThickness, RelativeSource={RelativeSource TemplatedParent}}">
<Grid>
<Border x:Name="Border_fade"
Background="{DynamicResource MyWhite}"
Opacity="0.2"
Visibility="Hidden" />
<Border x:Name="Border_fade2"
Background="{DynamicResource MyGray}"
Opacity="0.4"
Visibility="Hidden" />
<ContentPresenter Margin="2"
HorizontalAlignment="Center"
VerticalAlignment="Center"
RecognizesAccessKey="True" />
</Grid>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="true">
<Setter TargetName="Border_fade" Property="Visibility" Value="Visible" />
</Trigger>
<Trigger Property="IsPressed" Value="true">
<Setter TargetName="Border_fade" Property="Visibility" Value="Hidden" />
<Setter TargetName="Border_fade2" Property="Visibility" Value="Visible" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
<Style x:Key="MyLabelStyle" TargetType="Label">
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="HorizontalAlignment" Value="Stretch" />
<Setter Property="Background" Value="{DynamicResource MyDarkTr}" />
<Setter Property="FontFamily" Value="Unispace" />
<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}}">
<ToggleButton.Template>
<ControlTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="5*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Border x:Name="Border"
Grid.ColumnSpan="2"
Background="{DynamicResource MyDarkTr}" />
<Border Grid.Column="0"
Margin="1"
Background="{DynamicResource MyDarkTr}" />
<Path x:Name="Arrow"
Grid.Column="1"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Data="M 0 0 L 4 4 L 8 0 Z"
Fill="{DynamicResource MySelectionColor}" />
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="ToggleButton.IsMouseOver" Value="true">
<Setter TargetName="Border" Property="Background" Value="{DynamicResource MySelectionColor}" />
</Trigger>
<Trigger Property="ToggleButton.IsChecked" Value="true">
<Setter TargetName="Border" Property="Background" Value="{DynamicResource MySelectionColor}" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</ToggleButton.Template>
</ToggleButton>
<ContentPresenter Name="ContentSite"
Margin="3"
Content="{TemplateBinding SelectionBoxItem}"
ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}"
ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}"
IsHitTestVisible="False" />
<TextBox x:Name="PART_EditableTextBox"
IsReadOnly="{TemplateBinding IsReadOnly}"
Visibility="Hidden" />
<Popup Name="Popup"
AllowsTransparency="True"
Focusable="False"
IsOpen="{TemplateBinding IsDropDownOpen}"
Placement="Bottom"
PopupAnimation="Slide">
<Grid Name="DropDown"
MinWidth="{TemplateBinding ActualWidth}"
MaxHeight="{TemplateBinding MaxDropDownHeight}"
SnapsToDevicePixels="True">
<Border x:Name="DropDownBorder" Background="{DynamicResource MyDarkTr}" />
<ScrollViewer SnapsToDevicePixels="True">
<StackPanel IsItemsHost="True" />
</ScrollViewer>
</Grid>
</Popup>
</Grid>
</ControlTemplate>
</Application.Resources>
</Application>

View File

@ -0,0 +1,30 @@
using System.Windows.Media;
namespace Launcher.Client.WPF.GUI;
public partial class App : Application
{
public static SolidColorBrush MyDark,MySoftDark, MyWhite, MyGreen, MyOrange, MySelectionColor;
protected override void OnStartup(StartupEventArgs e)
{
try
{
base.OnStartup(e);
MyDark = (SolidColorBrush)Resources["MyDarkTr"];
MySoftDark = (SolidColorBrush)Resources["MyGray"];
MyWhite = (SolidColorBrush)Resources["MyWhite"];
MyGreen = (SolidColorBrush)Resources["MyGreen"];
MyOrange = (SolidColorBrush)Resources["MySelectionColor"];
MySelectionColor = (SolidColorBrush)Resources["MySelectionColor"];
_Main(e.Args);
}
catch(Exception ex)
{
LogError("STARTUP",ex);
Shutdown();
}
}
}

View File

@ -0,0 +1,226 @@
<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.WPF.GUI"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Title="Launcher"
Width="800"
Height="500"
MinWidth="800"
MinHeight="500"
Background="{DynamicResource MyBackgroundColor}"
mc:Ignorable="d">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="5" />
<ColumnDefinition />
<ColumnDefinition Width="5" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="5" />
<RowDefinition Height="40" />
<RowDefinition Height="5" />
<RowDefinition />
<RowDefinition Height="5" />
</Grid.RowDefinitions>
<Image x:Name="BackgroundImage"
Grid.RowSpan="5"
Grid.ColumnSpan="3"
HorizontalAlignment="Center"
Stretch="UniformToFill" />
<Grid Grid.Row="1" Grid.Column="1">
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition Width="5" />
<ColumnDefinition />
<ColumnDefinition Width="5" />
<ColumnDefinition />
<ColumnDefinition Width="5" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<local:TabButton x:Name="LibraryButton"
Grid.Column="0"
Content="Library"
FontSize="18"
Style="{DynamicResource MyButtonStyle}" />
<local:TabButton x:Name="DownloadsButton"
Grid.Column="2"
Content="Downloads"
FontSize="18"
Style="{DynamicResource MyButtonStyle}" />
<local:TabButton x:Name="LogButton"
Grid.Column="4"
Content="Log"
FontSize="18"
Style="{DynamicResource MyButtonStyle}" />
<local:TabButton x:Name="SettingsButton"
Grid.Column="6"
Content="Settings"
FontSize="18"
Style="{DynamicResource MyButtonStyle}" />
</Grid>
<Grid x:Name="LibraryGrid"
Grid.Row="3"
Grid.Column="1"
Visibility="Visible">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="220" />
<ColumnDefinition Width="5" />
<ColumnDefinition />
<ColumnDefinition Width="5" />
<ColumnDefinition Width="220" />
</Grid.ColumnDefinitions>
<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">
<Grid.RowDefinitions>
<RowDefinition Height="35" />
<RowDefinition Height="5" />
<RowDefinition Height="35" />
<RowDefinition Height="5" />
<RowDefinition Height="70" />
<RowDefinition Height="5" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Label x:Name="NameLabel"
Grid.Row="0"
Content="name"
FontSize="19"
FontWeight="Bold"
Style="{DynamicResource MyLabelStyle}" />
<StackPanel Grid.Row="2"
HorizontalAlignment="Right"
ClipToBounds="True"
Orientation="Horizontal">
<Button x:Name="RemoveButton"
Width="100"
Margin="2,0"
Background="{DynamicResource MyRed}"
Content="Remove"
Style="{DynamicResource MyButtonStyle}" />
<Button x:Name="InstallButton"
Width="100"
Margin="2,0"
Content="Install"
Style="{DynamicResource MyButtonStyle}" />
<Button x:Name="UpdateButton"
Width="100"
Margin="2,0"
Content="Update"
Style="{DynamicResource MyButtonStyle}" />
<Button x:Name="LaunchButton"
Width="100"
Margin="2,0"
Background="{DynamicResource MyGreen}"
Content="Launch"
Style="{DynamicResource MyButtonStyle}" />
</StackPanel>
<TextBox x:Name="DescriptionBox"
Grid.Row="4"
Style="{DynamicResource MyTextBoxStyle}"
VerticalScrollBarVisibility="Auto" />
<TextBox x:Name="ProgramLogBox"
Grid.Row="6"
Style="{DynamicResource MyTextBoxStyle}"
VerticalScrollBarVisibility="Auto" />
</Grid>
<Grid Grid.Row="0" Grid.Column="4">
<Grid.RowDefinitions>
<RowDefinition Height="95" />
<RowDefinition />
</Grid.RowDefinitions>
<Grid Grid.Row="0">
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="30" />
<RowDefinition Height="30" />
<RowDefinition Height="30" />
</Grid.RowDefinitions>
<Label Grid.Row="0"
Grid.Column="0"
Content="version:"
Style="{DynamicResource MyLabelStyle}" />
<ComboBox Grid.Row="0"
Grid.Column="1"
Background="{DynamicResource MyDarkTr}"
Template="{DynamicResource MyComboBox}">
<ComboBoxItem IsSelected="True">
<Label Background="Transparent"
Content="v1"
Style="{DynamicResource MyLabelStyle}" />
</ComboBoxItem>
</ComboBox>
<Label Grid.Row="1"
Grid.Column="0"
Content="directory:"
Style="{DynamicResource MyLabelStyle}" />
<Label Name="ProgramDirectoryLabel"
Grid.Row="1"
Grid.Column="1"
Content="0"
Style="{DynamicResource MyLabelStyle}" />
<Label Grid.Row="2"
Grid.Column="0"
Content="size:"
Style="{DynamicResource MyLabelStyle}" />
<Label Name="ProgramSizeLabel"
Grid.Row="2"
Grid.Column="1"
Content="0"
Style="{DynamicResource MyLabelStyle}" />
</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"
Visibility="Hidden" />
<Grid x:Name="LogGrid"
Grid.Row="3"
Grid.Column="1"
Visibility="Hidden">
<Grid.RowDefinitions>
<RowDefinition Height="30" />
<RowDefinition />
</Grid.RowDefinitions>
<Label x:Name="LogfileLabel"
Grid.Row="0"
Grid.Column="0"
Content="logfile"
FontStyle="Italic"
Style="{DynamicResource MyLabelStyle}" />
<TextBox x:Name="LogBox"
Grid.Row="1"
Grid.Column="0"
Style="{DynamicResource MyTextBoxStyle}"
VerticalScrollBarVisibility="Auto" />
</Grid>
<Grid x:Name="SettingsGrid"
Grid.Row="3"
Grid.Column="1"
Visibility="Hidden" />
</Grid>
</Window>

View File

@ -0,0 +1,96 @@
using System.Windows.Media.Imaging;
using DTLib.Logging;
namespace Launcher.Client.WPF.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.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);
private TabButton CurrentTab;
void SelectTab(object sender, RoutedEventArgs _)
{
if(CurrentTab!=null)
{
CurrentTab.Background = App.MyDark;
CurrentTab.TabGrid.Visibility = Visibility.Collapsed;
}
var selected = (TabButton)sender;
selected.Background = App.MySelectionColor;
selected.TabGrid.Visibility = Visibility.Visible;
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 = FontWeights.Normal;
}
else ProgramGrid.Visibility = Visibility.Visible;
selectedProg.ProgramLabel.Foreground = App.MySelectionColor;
selectedProg.ProgramLabel.FontWeight = FontWeights.Bold;
NameLabel.Content = selectedProg.Name;
DescriptionBox.Text = selectedProg.Description;
BackgroundImage.Source =
new BitmapImage(new Uri(
$"{Directory.GetCurrent()}{Path.Sep}backgrounds{Path.Sep}{selectedProg.BackgroundFile}",
UriKind.Absolute));
ProgramSettingsViever.Content = selectedProg.SettingsPanel;
DisplayingProgram = selectedProg;
}
catch(Exception ex)
{ LogError("SelectProgram()",ex); }
}
}

View File

@ -0,0 +1,33 @@
<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.WPF.GUI"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Height="50"
Background="{DynamicResource MyDarkTr}"
BorderBrush="{Binding Foreground, RelativeSource={RelativeSource Self}}"
BorderThickness="3"
Foreground="{DynamicResource MyWhite}"
mc:Ignorable="d">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="{Binding Height, RelativeSource={RelativeSource FindAncestor, AncestorType=local:ProgramLabel}}" />
<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 Foreground, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:ProgramLabel}}" />
</Grid>
</UserControl>

View File

@ -0,0 +1,16 @@
using System.Windows.Controls;
using System.Windows.Media.Imaging;
namespace Launcher.Client.WPF.GUI;
public partial class ProgramLabel : UserControl
{
public ProgramLabel(string label, string icon)
{
InitializeComponent();
NameLabel.Content = label;
IconImage.Source = new BitmapImage(new Uri(
$"{Directory.GetCurrent()}{Path.Sep}icons{Path.Sep}{icon}",
UriKind.Absolute));
}
}

View File

@ -0,0 +1,28 @@
<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.WPF.GUI"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
d:DesignWidth="100"
d:DesignHeight="30"
mc:Ignorable="d"
Background="Transparent">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Label Name="KeyLabel" Grid.Column="0"
Content="{Binding SettingKey, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:ProgramSettingsPanelItem}}"
Style="{DynamicResource MyLabelStyle}"
FontFamily="default"
FontSize="16"/>
<TextBox Name="ValueBox" Grid.Column="1"
HorizontalScrollBarVisibility="Auto"
Style="{DynamicResource MyTextBoxStyle}"
VerticalScrollBarVisibility="Disabled"
IsReadOnly="False"
Text="{Binding SettingValue, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:ProgramSettingsPanelItem}}"/>
</Grid>
</UserControl>

View File

@ -0,0 +1,45 @@
using System.Windows.Controls;
namespace Launcher.Client.WPF.GUI;
public partial class ProgramSettingsPanelItem : UserControl
{
public static readonly DependencyProperty SettingKeyProp = DependencyProperty.Register(
"SettingKey",
typeof(string),
typeof(ProgramSettingsPanelItem));
public string SettingKey
{
get => (string)GetValue(SettingKeyProp);
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(ProgramSettingsPanelItem));
public string SettingValue
{
get => (string)GetValue(SettingValueProp);
set => SetValue(SettingValueProp, value);
}
public event Action<ProgramSettingsPanelItem> UpdatedEvent;
public ProgramSettingsPanelItem(string key, string value)
{
InitializeComponent();
SettingKey = key;
SettingValue = value;
ValueBox.TextChanged += (_,_)=> UpdatedEvent?.Invoke(this);
}
}

View File

@ -0,0 +1,16 @@
using System.Windows.Controls;
namespace Launcher.Client.WPF.GUI;
public class TabButton : Button
{
public static readonly DependencyProperty TabGridProp = DependencyProperty.Register(
"TabGrid",
typeof(Grid),
typeof(TabButton));
public Grid TabGrid
{
get => (Grid)GetValue(TabGridProp);
set => SetValue(TabGridProp, value);
}
}

View File

@ -0,0 +1,32 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<UseWPF>true</UseWPF>
<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>
<ApplicationDefinition Include="GUI\App.xaml">
<Generator>MSBuild:Compile</Generator>
<XamlRuntime>Wpf</XamlRuntime>
</ApplicationDefinition>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Launcher.Client\Launcher.Client.csproj" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Resources\*" />
</ItemGroup>
</Project>

View 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);
}
}

View File

@ -0,0 +1,86 @@
using System.Windows.Controls;
using Launcher.Client.WPF.GUI;
namespace Launcher.Client.WPF;
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.MouseLeftButtonDown += (_, _) => 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";
}
}

View File

Before

Width:  |  Height:  |  Size: 37 KiB

After

Width:  |  Height:  |  Size: 37 KiB

View 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()
{
}
}

View 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>

View 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"));
}
}

View File

@ -0,0 +1,65 @@
namespace Launcher.Client;
public class LauncherConfig
{
public record struct Server(IPEndPoint EndPoint, string Domain)
{
public Server(string domain, int port) : this
(new IPEndPoint(Dns.GetHostAddresses(domain)[0], port), domain)
{ }
public Server(IPAddress address, int port) : this
(new IPEndPoint(address, port), "")
{ }
}
public const int Version=1;
public Server[] ServerAddresses;
const string configFile = "launcher.dtsod";
public LauncherConfig()
{
// читает дефолтный конфиг из ресурсов
DtsodV23 updatedConfig;
DtsodV23 updatedDefault = new(EmbeddedResources.ReadText("Launcher.Client.Resources.launcher.dtsod"));
// проверка и обновление конфига
if (File.Exists(configFile))
{
DtsodV23 oldConfig = new(File.ReadAllText(configFile));
updatedConfig = DtsodConverter.UpdateByDefault(oldConfig, updatedDefault);
}
else updatedConfig = updatedDefault;
// парсит парсит полученный дтсод в LauncherConfig
List<object> serversD = updatedConfig["server"];
ServerAddresses = new Server[serversD.Count];
ushort i = 0;
foreach (DtsodV23 serverD in serversD)
{
int port = serverD["port"];
// server must have <domain> or <ip> property
ServerAddresses[i++] = serverD.TryGetValue("domain", out dynamic dom)
? new Server(dom, port)
: new Server(IPAddress.Parse(serverD["ip"]), port);
}
WriteToFile();
}
// записывает обновлённый конфиг в файл
public void WriteToFile()
{
StringBuilder b = new();
b.Append("version: ").Append(Version).Append(";\n");
foreach (var server in ServerAddresses)
{
b.Append("$server: {\n\t");
if (server.Domain == "")
b.Append("ip: \"").Append(server.EndPoint.Address);
else b.Append("domain: \"").Append(server.Domain);
b.Append("\";\n\tport: ")
.Append(server.EndPoint.Port)
.Append(";\n};\n");
}
}
}

View 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);
}
}

View File

@ -0,0 +1,6 @@
namespace Launcher.Client;
public class ProgramDescriptor
{
}

View File

@ -0,0 +1,7 @@
#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

View File

@ -0,0 +1,6 @@
version: 1;
$server: {
ip: "127.0.0.1";
port: 25000;
};

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 437 KiB

View File

@ -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";

View File

@ -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: "";

Binary file not shown.

View File

@ -0,0 +1,5 @@
[fonts]
unispace.ttf
unispace_bd.ttf
unispace_it.ttf
unispace_bd_it.ttf

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

View File

@ -0,0 +1,26 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<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>
<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>

208
Launcher.Server/Server.cs Normal file
View File

@ -0,0 +1,208 @@
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.Net;
global using System.Net.Sockets;
global using System.Text;
global using System.Threading;
global using System.Linq;
using DTLib.Logging;
namespace Launcher.Server;
static class Server
{
static readonly Socket mainSocket = new(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
static DtsodV23 config;
private static readonly CompositeLogger Logger = new(
new ConsoleLogger(),
new FileLogger("logs", "launcher-server"));
static readonly object manifestLocker = new();
static void Main()
{
try
{
Console.Title = "Launcher.Server";
Console.InputEncoding = Encoding.Unicode;
Console.OutputEncoding = Encoding.Unicode;
DTLibInternalLogging.SetLogger(Logger);
config = new DtsodV23(File.ReadAllText("launcher-server.dtsod"));
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.LogInfo("Main", "server started succesfully");
// запуск отдельного потока для каждого юзера
Logger.LogInfo("Main", "waiting for users");
while (true)
{
var userSocket = mainSocket.Accept();
var userThread = new Thread((obj) => HandleUser((Socket)obj));
userThread.Start(userSocket);
}
}
catch (Exception ex)
{
Logger.LogError("Main", ex);
if (mainSocket.Connected)
{
mainSocket.Shutdown(SocketShutdown.Both);
mainSocket.Close();
}
}
Console.ResetColor();
}
// запускается для каждого юзера в отдельном потоке
static void HandleUser(Socket handlerSocket)
{
Logger.LogInfo("HandleUser", "user connecting...");
try
{
// запрос хеша пароля и логина
handlerSocket.SendPackage("requesting hash".ToBytes());
var hasher = new Hasher();
var hash = hasher.HashCycled(handlerSocket.GetPackage(), 64);
FSP fsp = new(handlerSocket);
// запрос от апдейтера
if (hash == hasher.HashCycled("updater".ToBytes(),64))
{
Logger.LogInfo("HandleUser", "user is updater");
handlerSocket.SendPackage("updater".ToBytes());
// обработка запросов
while (true)
{
if (handlerSocket.Available >= 2)
{
var request = handlerSocket.GetPackage().ToString();
switch (request)
{
case "requesting launcher update":
Logger.LogInfo("HandleUser", "updater requested client.exe");
fsp.UploadFile("share\\launcher.exe");
break;
case "register new user":
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};");
var filepath = Path.Concat("registration_requests", DateTime.Now.ToString(MyTimeFormat.ForFileNames), ".req");
File.WriteAllText(filepath, req);
Logger.LogInfo("HandleUser", $"text wrote to file <{filepath}>");
break;
default:
throw new Exception("unknown request: " + request);
}
}
else Thread.Sleep(10);
}
}
// запрос от юзера
else if (FindUser(hash, out var user))
{
Logger.LogInfo("HandleUser", "user is " + user.name);
handlerSocket.SendPackage("launcher".ToBytes());
// обработка запросов
while (true)
{
if (handlerSocket.Available >= 2)
{
var request = handlerSocket.GetPackage().ToString();
switch (request)
{
case "requesting file download":
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.LogInfo("HandleUser", "user " + user.name + " requested uuid");
handlerSocket.SendPackage(user.uuid.ToBytes());
break;
case "excess files found":
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":
string error = handlerSocket.GetPackage().ToString();
Logger.LogWarn("HandleUser", "user "+ user.name + "is sending error:\n"+error);
break;
default:
throw new Exception("unknown request: " + request);
}
}
else Thread.Sleep(10);
}
}
// неизвестный юзер
else
{
Logger.LogWarn("HandleUser", $"user with hash {hash.HashToString()} not found");
handlerSocket.SendPackage("user not found".ToBytes());
}
}
catch (Exception ex)
{
Logger.LogWarn("HandleUser", ex);
if (mainSocket.Connected)
{
mainSocket.Shutdown(SocketShutdown.Both);
mainSocket.Close();
}
}
finally
{
if (handlerSocket.Connected)
handlerSocket.Shutdown(SocketShutdown.Both);
handlerSocket.Close();
Logger.LogInfo("HandleUser", "user disconnected");
}
}
static void CreateManifests()
{
lock (manifestLocker)
{
Directory.Create("share\\download_if_not_exist");
Directory.Create("share\\sync_always");
Directory.Create("share\\sync_and_remove");
FSP.CreateManifest("share\\download_if_not_exist");
FSP.CreateManifest("share\\sync_always");
foreach (string dir in Directory.GetDirectories("share\\sync_and_remove"))
FSP.CreateManifest(dir);
File.WriteAllText("share\\sync_and_remove\\dirlist.dtsod",
"dirs: [\""+
Directory.GetDirectories("share\\sync_and_remove")
.MergeToString("\",\"")
.Replace("share\\sync_and_remove\\", "")+
"\"];");
}
}
static bool FindUser(byte[] hash, out (string name, string uuid) user)
{
DtsodV23 usersdb = new(File.ReadAllText("users.dtsod"));
user = new ValueTuple<string, string>();
if (!usersdb.ContainsKey(hash.HashToString())) return false;
user.name = usersdb[hash.HashToString()]["username"];
user.uuid = usersdb[hash.HashToString()]["uuid"];
return true;
}
}

View File

@ -0,0 +1,2 @@
local_ip: "10.1.10.44";
local_port: 25000;

7
README.md Normal file
View File

@ -0,0 +1,7 @@
# dtlauncher
launcher for my... idk.. something
\
requires DTLib\
https://github.com/Timerix22/DTLib

49
dtlauncher.sln Normal file
View File

@ -0,0 +1,49 @@

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}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Launcher.Client.WPF", "Launcher.Client.WPF\Launcher.Client.WPF.csproj", "{A1F770F3-F6B1-4854-9BF0-093F85064B88}"
EndProject
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
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{1F4D14EB-AF48-4B6C-A91B-B294D4281173}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1F4D14EB-AF48-4B6C-A91B-B294D4281173}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1F4D14EB-AF48-4B6C-A91B-B294D4281173}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1F4D14EB-AF48-4B6C-A91B-B294D4281173}.Release|Any CPU.Build.0 = Release|Any CPU
{A1F770F3-F6B1-4854-9BF0-093F85064B88}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{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
{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
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {96D7F599-27F9-420C-835D-FAF63EE78D0E}
EndGlobalSection
EndGlobal

View File

@ -1,97 +0,0 @@
namespace launcher_client;
internal static partial class Launcher
{
static string ConstructGameLaunchArgs(string username, string uuid, int maxmemory, int width, int height,
string gameDir)
=> "-XX:+UnlockExperimentalVMOptions " +
"-XX:+UseG1GC " +
"-XX:G1NewSizePercent=20 " +
"-XX:G1ReservePercent=20 " +
"-XX:MaxGCPauseMillis=50 " +
"-XX:G1HeapRegionSize=32M " +
"-XX:+DisableExplicitGC " +
"-XX:+AlwaysPreTouch " +
"-XX:+ParallelRefProcEnabled " +
"-Xms512M " +
$"-Xmx{maxmemory}M " +
"-Dfile.encoding=UTF-8 " +
"-Dfml.ignoreInvalidMinecraftCertificates=true " +
"-Dfml.ignorePatchDiscrepancies=true " +
"-Djava.net.useSystemProxies=true " +
"-XX:HeapDumpPath=MojangTricksIntelDriversForPerformance_javaw.exe_minecraft.exe.heapdump " +
"\"-Dos.name=Windows 10\" " +
"-Dos.version=10.0 " +
@"-Djava.library.path=versions\1.12.2-forge-14.23.5.2860\natives " +
"-Dminecraft.launcher.brand=java-minecraft-launcher " +
"-Dminecraft.launcher.version=1.6.84-j " +
@"-Dminecraft.client.jar=versions\1.12.2-forge-14.23.5.2860\1.12.2-forge-14.23.5.2860.jar " +
"-cp " +
@"libraries\com\turikhay\ca-fixer\1.0\ca-fixer-1.0.jar;" +
@"libraries\net\minecraftforge\forge\1.12.2-14.23.5.2860\forge-1.12.2-14.23.5.2860.jar;" +
@"libraries\org\ow2\asm\asm-debug-all\5.2\asm-debug-all-5.2.jar;" +
@"libraries\net\minecraft\launchwrapper\1.12\launchwrapper-1.12.jar;" +
@"libraries\org\jline\jline\3.5.1\jline-3.5.1.jar;" +
@"libraries\com\typesafe\akka\akka-actor_2.11\2.3.3\akka-actor_2.11-2.3.3.jar;" +
@"libraries\com\typesafe\config\1.2.1\config-1.2.1.jar;" +
@"libraries\org\scala-lang\scala-actors-migration_2.11\1.1.0\scala-actors-migration_2.11-1.1.0.jar;" +
@"libraries\org\scala-lang\scala-compiler\2.11.1\scala-compiler-2.11.1.jar;" +
@"libraries\org\scala-lang\plugins\scala-continuations-library_2.11\1.0.2_mc\scala-continuations-library_2.11-1.0.2_mc.jar;" +
@"libraries\org\scala-lang\plugins\scala-continuations-plugin_2.11.1\1.0.2_mc\scala-continuations-plugin_2.11.1-1.0.2_mc.jar;" +
@"libraries\org\scala-lang\scala-library\2.11.1\scala-library-2.11.1.jar;" +
@"libraries\org\scala-lang\scala-parser-combinators_2.11\1.0.1\scala-parser-combinators_2.11-1.0.1.jar;" +
@"libraries\org\scala-lang\scala-reflect\2.11.1\scala-reflect-2.11.1.jar;" +
@"libraries\org\scala-lang\scala-swing_2.11\1.0.1\scala-swing_2.11-1.0.1.jar;" +
@"libraries\org\scala-lang\scala-xml_2.11\1.0.2\scala-xml_2.11-1.0.2.jar;" +
@"libraries\lzma\lzma\0.0.1\lzma-0.0.1.jar;" +
@"libraries\java3d\vecmath\1.5.2\vecmath-1.5.2.jar;" +
@"libraries\net\sf\trove4j\trove4j\3.0.3\trove4j-3.0.3.jar;" +
@"libraries\org\apache\maven\maven-artifact\3.5.3\maven-artifact-3.5.3.jar;" +
@"libraries\net\sf\jopt-simple\jopt-simple\5.0.3\jopt-simple-5.0.3.jar;" +
@"libraries\org\apache\logging\log4j\log4j-api\2.15.0\log4j-api-2.15.0.jar;" +
@"libraries\org\apache\logging\log4j\log4j-core\2.15.0\log4j-core-2.15.0.jar;" +
@"libraries\ru\tlauncher\patchy\1.0.0\patchy-1.0.0.jar;" +
@"libraries\oshi-project\oshi-core\1.1\oshi-core-1.1.jar;" +
@"libraries\net\java\dev\jna\jna\4.4.0\jna-4.4.0.jar;" +
@"libraries\net\java\dev\jna\platform\3.4.0\platform-3.4.0.jar;" +
@"libraries\com\ibm\icu\icu4j-core-mojang\51.2\icu4j-core-mojang-51.2.jar;" +
@"libraries\com\paulscode\codecjorbis\20101023\codecjorbis-20101023.jar;" +
@"libraries\com\paulscode\codecwav\20101023\codecwav-20101023.jar;" +
@"libraries\com\paulscode\libraryjavasound\20101123\libraryjavasound-20101123.jar;" +
@"libraries\com\paulscode\librarylwjglopenal\20100824\librarylwjglopenal-20100824.jar;" +
@"libraries\com\paulscode\soundsystem\20120107\soundsystem-20120107.jar;" +
@"libraries\io\netty\netty-all\4.1.9.Final\netty-all-4.1.9.Final.jar;" +
@"libraries\com\google\guava\guava\21.0\guava-21.0.jar;" +
@"libraries\org\apache\commons\commons-lang3\3.5\commons-lang3-3.5.jar;" +
@"libraries\commons-io\commons-io\2.5\commons-io-2.5.jar;" +
@"libraries\commons-codec\commons-codec\1.10\commons-codec-1.10.jar;" +
@"libraries\net\java\jinput\jinput\2.0.5\jinput-2.0.5.jar;" +
@"libraries\net\java\jutils\jutils\1.0.0\jutils-1.0.0.jar;" +
@"libraries\com\google\code\gson\gson\2.8.0\gson-2.8.0.jar;" +
@"libraries\by\ely\authlib\3.11.49.2\authlib-3.11.49.2.jar;" +
@"libraries\com\mojang\realms\1.10.22\realms-1.10.22.jar;" +
@"libraries\org\apache\commons\commons-compress\1.8.1\commons-compress-1.8.1.jar;" +
@"libraries\org\apache\httpcomponents\httpclient\4.3.3\httpclient-4.3.3.jar;" +
@"libraries\commons-logging\commons-logging\1.1.3\commons-logging-1.1.3.jar;" +
@"libraries\org\apache\httpcomponents\httpcore\4.3.2\httpcore-4.3.2.jar;" +
@"libraries\it\unimi\dsi\fastutil\7.1.0\fastutil-7.1.0.jar;" +
@"libraries\org\apache\logging\log4j\log4j-api\2.8.1\log4j-api-2.8.1.jar;" +
@"libraries\org\apache\logging\log4j\log4j-core\2.8.1\log4j-core-2.8.1.jar;" +
@"libraries\org\lwjgl\lwjgl\lwjgl\2.9.4-nightly-20150209\lwjgl-2.9.4-nightly-20150209.jar;" +
@"libraries\org\lwjgl\lwjgl\lwjgl_util\2.9.4-nightly-20150209\lwjgl_util-2.9.4-nightly-20150209.jar;" +
@"libraries\com\mojang\text2speech\1.10.3\text2speech-1.10.3.jar;" +
@"versions\1.12.2-forge-14.23.5.2860\1.12.2-forge-14.23.5.2860.jar " +
"-Xss2M net.minecraft.launchwrapper.Launch " +
$"--username {username} " +
"--version 1.12.2-forge-14.23.5.2860 " +
$"--gameDir {gameDir} " +
"--assetsDir assets " +
"--assetIndex 1.12 " +
$"--uuid {uuid} " +
"--accessToken null " +
"--userType mojang " +
"--tweakClass net.minecraftforge.fml.common.launcher.FMLTweaker " +
"--versionType Forge " +
$"--width {width} " +
$"--height {height}";
}

View File

@ -1,254 +0,0 @@
using System;
using System.Diagnostics;
using System.Dynamic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using DTLib.Console;
using DTLib.Extensions;
using DTLib.Logging;
using DTLib.Network;
using DTLib.Filesystem;
using Directory = DTLib.Filesystem.Directory;
using File = DTLib.Filesystem.File;
using static launcher_client.Network;
namespace launcher_client;
internal static partial class Launcher
{
private static FileLogger _fileLogger = new("launcher-logs", "launcher-client");
public static ILogger Logger = new CompositeLogger(
_fileLogger,
new ConsoleLogger());
public static LauncherConfig Config = null!;
public static bool debug, offline, updated;
private static dynamic tabs = new ExpandoObject();
private static void Main(string[] args)
{
try
{
Console.Title = "anarx_2";
Console.OutputEncoding = Encoding.UTF8;
Console.InputEncoding = Encoding.UTF8;
Console.CursorVisible = false;
#if DEBUG
debug = true;
#else
if (args.Contains("debug")) debug = true;
#endif
if (args.Contains("offline")) offline = true;
if (args.Contains("updated")) updated = true;
Config = !File.Exists(LauncherConfig.ConfigFilePath)
? LauncherConfig.CreateDefault()
: LauncherConfig.LoadFromFile();
Logger.DebugLogEnabled = debug;
Logger.LogInfo("Main", "launcher is starting");
if(File.Exists("minecraft-launcher.exe_old"))
File.Delete("minecraft-launcher.exe_old");
// обновление лаунчера
if (!updated && !offline)
{
ConnectToLauncherServer();
mainSocket.SendPackage("requesting launcher update");
Fsp.DownloadFile("minecraft-launcher.exe_new");
Logger.LogInfo("Main", "minecraft-launcher.exe_new downloaded");
System.IO.File.Move("minecraft-launcher.exe", "minecraft-launcher.exe_old");
Process.Start("cmd","/c " +
"move minecraft-launcher.exe_new minecraft-launcher.exe && " +
"minecraft-launcher.exe updated");
return;
}
// если уже обновлён
tabs.Login = EmbeddedResources.ReadText("launcher_client.gui.login.gui");
tabs.Settings = EmbeddedResources.ReadText("launcher_client.gui.settings.gui");
tabs.Exit = EmbeddedResources.ReadText("launcher_client.gui.exit.gui");
tabs.Log = "";
tabs.Current = "";
string username = "";
if (!Config.Username.IsNullOrEmpty())
{
tabs.Login = tabs.Login.Remove(833, Config.Username.Length).Insert(833, Config.Username);
username = Config.Username;
}
RenderTab(tabs.Login);
while (true) try
// ReSharper disable once BadChildStatementIndent
{
var pressedKey = Console.ReadKey(true); // Считывание ввода
switch (pressedKey.Key)
{
case ConsoleKey.F1:
RenderTab(tabs.Login);
break;
case ConsoleKey.N:
if (tabs.Current == tabs.Login)
{
tabs.Login = tabs.Login
.Remove(751, 20).Insert(751, "┏━━━━━━━━━━━━━━━━━━┓")
.Remove(831, 20).Insert(831, "┃ ┃")
.Remove(911, 20).Insert(911, "┗━━━━━━━━━━━━━━━━━━┛");
RenderTab(tabs.Login);
var _username = ReadString(33, 10, 15);
tabs.Login = tabs.Login
.Remove(751, 20).Insert(751, "┌──────────────────┐")
.Remove(831, 20).Insert(831, "│ │")
.Remove(911, 20).Insert(911, "└──────────────────┘");
RenderTab(tabs.Login);
if (_username.Length < 5)
throw new Exception("username length should be > 4 and < 17");
Config.Username = _username;
Config.Save();
username = _username;
tabs.Login = tabs.Login.Remove(833, _username.Length).Insert(833, _username);
RenderTab(tabs.Login);
}
break;
case ConsoleKey.L:
if (tabs.Current == tabs.Login)
{
RenderTab(tabs.Current);
if (username.Length < 2) throw new Exception("username is too short");
// обновление клиента
if (!offline)
{
ConnectToLauncherServer();
UpdateGame();
}
// запуск майнкрафта
Logger.LogInfo("Main", "launching minecraft");
string gameOptions = ConstructGameLaunchArgs(Config.Username,
NameUUIDFromString("OfflinePlayer:" + Config.Username),
Config.GameMemory,
Config.GameWindowWidth,
Config.GameWindowHeight,
Directory.GetCurrent());
Logger.LogDebug("LaunchGame", gameOptions);
var gameProcess = Process.Start(Config.JavaPath.Str, gameOptions);
gameProcess.WaitForExit();
Logger.LogInfo("Main", "minecraft closed");
}
break;
case ConsoleKey.F2:
tabs.Log = File.ReadAllText(_fileLogger.LogfileName);
RenderTab(tabs.Log, 9999);
break;
case ConsoleKey.F3:
RenderTab(tabs.Settings);
break;
case ConsoleKey.F4:
RenderTab(tabs.Exit);
break;
case ConsoleKey.Enter:
if (tabs.Current == tabs.Exit)
{
Console.Clear();
// Console.BufferHeight = 9999;
return;
}
break;
case ConsoleKey.F5:
if (tabs.Current == tabs.Log) goto case ConsoleKey.F2;
RenderTab(tabs.Current);
Console.CursorVisible = false;
break;
}
}
catch (Exception ex)
{
Logger.LogError("Main", ex);
}
}
catch (Exception ex)
{
Logger.LogError("Main", ex);
ColoredConsole.Write("gray", "press any key to close...");
Console.ReadKey();
}
Console.CursorVisible = true;
}
private static void RenderTab(string tab, ushort bufferHeight = 30)
{
tabs.Current = tab;
Console.Clear();
Console.SetWindowSize(80, 30);
// Console.SetBufferSize(80, bufferHeight);
ColoredConsole.Write("w", tab);
}
private static string ReadString(ushort x, ushort y, ushort maxlength)
{
var output = "";
tabs.Current = tabs.Current.Remove(y * 80 + x, maxlength).Insert(y * 80 + x, " ".Multiply(maxlength));
while (true)
{
var pressedKey = Console.ReadKey(false);
switch (pressedKey.Key)
{
case ConsoleKey.Enter:
return output;
case ConsoleKey.Backspace:
if (output.Length > 0)
{
output = output.Remove(output.Length - 1);
RenderTab(tabs.Current);
Console.SetCursorPosition(x, y);
ColoredConsole.Write("c", output);
}
break;
case ConsoleKey.Escape:
tabs.Current = tabs.Current.Remove(y * 80 + x, maxlength)
.Insert(y * 80 + x, " ".Multiply(maxlength));
RenderTab(tabs.Current);
return "";
//case ConsoleKey.Spacebar:
case ConsoleKey.UpArrow:
case ConsoleKey.DownArrow:
case ConsoleKey.LeftArrow:
case ConsoleKey.RightArrow:
break;
default:
if (output.Length <= maxlength)
{
string keyC = pressedKey.KeyChar.ToString();
string thisChar = pressedKey.Modifiers.HasFlag(ConsoleModifiers.Shift) ? keyC.ToUpper() : keyC;
output += thisChar;
}
RenderTab(tabs.Current);
Console.SetCursorPosition(x, y);
ColoredConsole.Write("c", output);
break;
}
}
}
//minecraft player uuid explanation
//https://gist.github.com/CatDany/0e71ca7cd9b42a254e49/
//java uuid generation in c#
//https://stackoverflow.com/questions/18021808/uuid-interop-with-c-sharp-code
public static string NameUUIDFromString(string input)
=> NameUUIDFromBytes(Encoding.UTF8.GetBytes(input));
public static string NameUUIDFromBytes(byte[] input)
{
byte[] hash = MD5.HashData(input);
hash[6] &= 0x0f;
hash[6] |= 0x30;
hash[8] &= 0x3f;
hash[8] |= 0x80;
string hex = BitConverter.ToString(hash).Replace("-", string.Empty).ToLower();
return hex.Insert(8, "-").Insert(13, "-").Insert(18, "-").Insert(23, "-");
}
}

View File

@ -1,56 +0,0 @@
using DTLib.Dtsod;
using DTLib.Filesystem;
namespace launcher_client;
public class LauncherConfig
{
public static IOPath ConfigFilePath = "minecraft-launcher.dtsod";
public int GameMemory = 3000;
public int GameWindowHeight = 500;
public int GameWindowWidth = 900;
public IOPath JavaPath = "jre/bin/java.exe";
public string ServerAddress = "127.0.0.1";
public int ServerPort = 25000;
public string Username = "";
private LauncherConfig(){}
private LauncherConfig(DtsodV23 dtsod)
{
GameMemory = dtsod["gameMemory"];
GameWindowHeight = dtsod["gameWindowHeight"];
GameWindowWidth = dtsod["gameWindowWidth"];
JavaPath = dtsod["javaPath"];
ServerAddress = dtsod["serverAddress"];
ServerPort = dtsod["serverPort"];
Username = dtsod["username"];
}
public static LauncherConfig LoadFromFile() => new(new DtsodV23(File.ReadAllText(ConfigFilePath)));
public DtsodV23 ToDtsod() =>
new()
{
{ "gameMemory", GameMemory },
{ "gameWindowHeight", GameWindowHeight },
{ "gameWindowWidth", GameWindowWidth },
{ "javaPath", JavaPath.Str },
{ "serverAddress", ServerAddress },
{ "serverPort", ServerPort },
{ "username", Username },
};
public void Save()
{
File.WriteAllText(ConfigFilePath, ToDtsod().ToString());
}
public static LauncherConfig CreateDefault()
{
var c = new LauncherConfig();
c.Save();
return c;
}
}

View File

@ -1,91 +0,0 @@
using System.Net;
using System.Net.Sockets;
using System.Threading;
using DTLib;
using DTLib.Dtsod;
using DTLib.Extensions;
using DTLib.Filesystem;
using DTLib.Logging;
using DTLib.Network;
using static launcher_client.Launcher;
namespace launcher_client;
public class Network
{
public static Socket mainSocket = new(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
public static FSP Fsp = new(mainSocket);
// подключение серверу
public static void ConnectToLauncherServer()
{
if (mainSocket.Connected)
{
Logger.LogInfo(nameof(Network), "socket is connected already. disconnecting...");
mainSocket.Shutdown(SocketShutdown.Both);
mainSocket.Close();
mainSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
Fsp = new(mainSocket);
}
while (true)
try
{
Logger.LogInfo(nameof(Network), $"connecting to server {Config.ServerAddress}:{Config.ServerPort}");
var ip = Dns.GetHostAddresses(Config.ServerAddress)[0];
mainSocket.Connect(new IPEndPoint(ip, Config.ServerPort));
Logger.LogInfo(nameof(Network), $"connected to server {ip}");
break;
}
catch (SocketException ex)
{
Logger.LogError(nameof(Network), ex);
Thread.Sleep(2000);
}
mainSocket.ReceiveTimeout = 2500;
mainSocket.SendTimeout = 2500;
mainSocket.GetAnswer("requesting user name");
mainSocket.SendPackage("minecraft-launcher");
mainSocket.GetAnswer("minecraft-launcher OK");
}
public static void DownloadByManifest(IOPath dirOnServer, IOPath dirOnClient, bool overwrite = false, bool delete_excess = false)
{
var manifestPath = Path.Concat(dirOnServer, "manifest.dtsod");
Logger.LogDebug(nameof(Network), manifestPath);
string manifestContent = Fsp.DownloadFileToMemory(manifestPath).BytesToString();
var manifest = new DtsodV23(manifestContent);
var hasher = new Hasher();
foreach (var fileOnServerData in manifest)
{
IOPath fileOnClient = Path.Concat(dirOnClient, fileOnServerData.Key);
if (!File.Exists(fileOnClient) || (overwrite && hasher.HashFile(fileOnClient).HashToString() != fileOnServerData.Value))
Fsp.DownloadFile(Path.Concat(dirOnServer, fileOnServerData.Key), fileOnClient);
}
// удаление лишних файлов
if (delete_excess)
{
foreach (var file in Directory.GetAllFiles(dirOnClient))
{
if (!manifest.ContainsKey(file.RemoveBase(dirOnClient).Str.Replace('\\','/')))
File.Delete(file);
}
}
}
public static void UpdateGame()
{
//обновление файлов клиента
Logger.LogInfo(nameof(Network), "updating client...");
DownloadByManifest("download_if_not_exist", Directory.GetCurrent());
DownloadByManifest("sync_always", Directory.GetCurrent(), true);
var dirlistDtsod = new DtsodV23(Fsp
.DownloadFileToMemory(Path.Concat("sync_and_remove","dirlist.dtsod"))
.BytesToString());
foreach (string dir in dirlistDtsod["dirs"])
DownloadByManifest(Path.Concat("sync_and_remove", dir),
Path.Concat(Directory.GetCurrent(), dir), true, true);
Logger.LogInfo(nameof(Network), "client updated");
}
}

View File

@ -1,29 +0,0 @@
┏━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┓
┃ [F1] login ┃ [F2] log ┃ [F3] settings ┃ [F4] EXIT ┃ [F5] refresh ┃
┣━━━━━━━━━━━━━━┻━━━━━━━━━━━━━━┻━━━━━━━━━━━━━━━━┻━━━━━━━━━━━━━━┻━━━━━━━━━━━━━━━┫
┃ ┃
┃ ┃
┃ ┃
┃ ┃
┃ ┃
┃ ┃
┃ ┃
┃ ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃
┃ ┃ ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ ┃
┃ ┃ ┃ ┃ ┃ ┃
┃ ┃ ┃ press [ENTER] to exit ┃ ┃ ┃
┃ ┃ ┃ ┃ ┃ ┃
┃ ┃ ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ ┃ ┃
┃ ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ ┃
┃ ┃
┃ ┃
┃ ┃
┃ ┃
┃ ┃
┃ ┃
┃ ┃
┃ ┃
┃ ┃
┃ ┃
┃ ┃
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛

View File

@ -1,29 +0,0 @@
┏━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┓
┃ [F1] LOGIN ┃ [F2] log ┃ [F3] settings ┃ [F4] exit ┃ [F5] refresh ┃
┣━━━━━━━━━━━━━━┻━━━━━━━━━━━━━━┻━━━━━━━━━━━━━━━━┻━━━━━━━━━━━━━━┻━━━━━━━━━━━━━━━┫
┃ ┃
┃ ┃
┃ ┃
┃ ┃
┃ ┃
┃ ┃
┃ ┌──────────────────┐ ┃
┃ [N] nickname:│ │ ┃
┃ └──────────────────┘ ┃
┃ ┃
┃ ┏━━━━━━━━━━━━━━━━┓ ┃
┃ ┃ [L] login ┃ ┃
┃ ┗━━━━━━━━━━━━━━━━┛ ┃
┃ ┃
┃ ┃
┃ ┃
┃ ┃
┃ ┃
┃ ┃
┃ ┃
┃ ┃
┃ ┃
┃ ┃
┃ ┃
┃ ┃
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛

View File

@ -1,29 +0,0 @@
┏━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┓
┃ [F1] login ┃ [F2] log ┃ [F3] SETTINGS ┃ [F4] exit ┃ [F5] refresh ┃
┣━━━━━━━━━━━━━━┻━━━━━━━━━━━━━━┻━━━━━━━━━━━━━━━━┻━━━━━━━━━━━━━━┻━━━━━━━━━━━━━━━┫
┃ ┃
┃ ┃
┃ ┃
┃ ┃
┃ я ещё не добавил настройки ┃
┃ ┃
┃ приходите позже ┃
┃ ┃
┃ ┃
┃ ┃
┃ ■ ■ ■ ■ ┃
┃ ■ ■ ■ ■ ┃
┃ ■ ■ ■ ■ ■ ■ ■ ┃
┃ ■ ■ ■ ■ ■ ■ ■ ┃
┃ ■ ■ ■ ┃
┃ ┃
┃ ┃
┃ ┃
┃ ┃
┃ ┃
┃ ┃
┃ ┃
┃ ┃
┃ ┃
┃ ┃
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛

View File

@ -1,3 +0,0 @@
┏━━━━━━━━━┓
┃ ejejeje ┃
┗━━━━━━━━━┛

View File

@ -1,16 +0,0 @@
window:
{
type: "container";
anchor: [0us, 0us];
width: 90us;
height: 30us;
children:
{
test_label:
{
type: "label";
anchor: [0us, 0us];
resdir: "gui";
};
};
};

View File

@ -1,20 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>disable</ImplicitUsings>
<Nullable>enable</Nullable>
<OutputType>Exe</OutputType>
<RootNamespace>launcher_client</RootNamespace>
<AssemblyName>minecraft-launcher</AssemblyName>
<ApplicationIcon>launcher.ico</ApplicationIcon>
</PropertyGroup>
<ItemGroup>
<None Remove="gui\exit.gui" />
<EmbeddedResource Include="gui\**" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="DTLib.Dtsod" Version="1.3.1" />
<PackageReference Include="DTLib.Logging" Version="1.3.1" />
<PackageReference Include="DTLib.Network" Version="1.3.3" />
</ItemGroup>
</Project>

View File

@ -1,10 +0,0 @@
dotnet publish -c release -o bin/publish \
--self-contained \
--use-current-runtime \
-p:PublishSingleFile=true \
-p:PublishTrimmed=true \
-p:TrimMode=partial \
-p:EnableCompressionInSingleFile=true \
-p:OptimizationPreference=Size \
-p:InvariantGlobalization=true \
-p:DebugType=none

View File

@ -1,69 +0,0 @@
using System.Linq;
using System.Text;
using DTLib;
using DTLib.Extensions;
using DTLib.Filesystem;
using static launcher_server.Server;
namespace launcher_server;
public static class Manifests
{
static object manifestLocker = new();
public static void CreateManifest(IOPath dir)
{
if(!Directory.Exists(dir))
{
Directory.Create(dir);
return;
}
StringBuilder manifestBuilder = new();
Hasher hasher = new();
var manifestPath = Path.Concat(dir, "manifest.dtsod");
if (Directory.GetFiles(dir).Contains(manifestPath))
File.Delete(manifestPath);
foreach (var fileInDir in Directory.GetAllFiles(dir))
{
var fileRelative = fileInDir.RemoveBase(dir);
manifestBuilder.Append(fileRelative);
manifestBuilder.Append(": \"");
byte[] hash = hasher.HashFile(Path.Concat(fileInDir));
manifestBuilder.Append(hash.HashToString());
manifestBuilder.Append("\";\n");
}
File.WriteAllText(manifestPath, manifestBuilder.ToString().Replace('\\','/'));
}
public static void CreateAllManifests()
{
lock (manifestLocker)
{
var sync_and_remove_dir = Path.Concat(shared_dir, "sync_and_remove");
CreateManifest(Path.Concat(shared_dir, "download_if_not_exist"));
CreateManifest(Path.Concat(shared_dir, "sync_always"));
if (!Directory.Exists(sync_and_remove_dir))
Directory.Create(sync_and_remove_dir);
else foreach (var dir in Directory.GetDirectories(sync_and_remove_dir))
CreateManifest(dir);
StringBuilder dirlist_content_builder = new("dirs: [\n");
var dirs = Directory.GetDirectories(sync_and_remove_dir);
for (var i = 0; i < dirs.Length-1; i++)
{
dirlist_content_builder
.Append("\t\"")
.Append(dirs[i].RemoveBase(sync_and_remove_dir).Str.Replace('\\','/'))
.Append("\",\n");
}
dirlist_content_builder
.Append("\t\"")
.Append(dirs[dirs.Length-1].RemoveBase(sync_and_remove_dir).Str.Replace('\\','/'))
.Append("\"\n");
dirlist_content_builder.Append("];");
File.WriteAllText(Path.Concat(sync_and_remove_dir, "dirlist.dtsod"), dirlist_content_builder.ToString());
}
}
}

View File

@ -1,118 +0,0 @@
using System;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading;
using DTLib.Dtsod;
using DTLib.Extensions;
using DTLib.Filesystem;
using DTLib.Logging;
using DTLib.Network;
namespace launcher_server;
static class Server
{
private static ILogger logger = new CompositeLogger(
new FileLogger("logs","launcher-server"),
new ConsoleLogger());
static readonly Socket mainSocket = new(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
static DtsodV23 config = null!;
public static readonly IOPath shared_dir = "public";
static void Main(string[] args)
{
try
{
Console.Title = "minecraft_launcher_server";
Console.InputEncoding = Encoding.Unicode;
Console.OutputEncoding = Encoding.Unicode;
config = new DtsodV23(File.ReadAllText("minecraft-launcher-server.dtsod"));
logger.LogInfo("Main", $"local address: {config["local_ip"]}");
logger.LogInfo("Main", $"public address: {Functions.GetPublicIP()}");
logger.LogInfo("Main", $"port: {config["local_port"]}");
mainSocket.Bind(new IPEndPoint(IPAddress.Parse(config["local_ip"]), config["local_port"]));
mainSocket.Listen(1000);
Manifests.CreateAllManifests();
logger.LogInfo("Main", "server started succesfully");
// запуск отдельного потока для каждого юзера
logger.LogInfo("Main", "waiting for users");
while (true)
{
var userSocket = mainSocket.Accept();
var userThread = new Thread(obj => HandleUser((Socket)obj!));
userThread.Start(userSocket);
}
}
catch (Exception ex)
{
logger.LogError("Main", ex);
mainSocket.Close();
}
logger.LogInfo("Main", "");
}
// запускается для каждого юзера в отдельном потоке
static void HandleUser(Socket handlerSocket)
{
logger.LogInfo(nameof(HandleUser), "user connecting... ");
try
{
// тут запрос пароля заменён запросом заглушки
handlerSocket.SendPackage("requesting user name");
string connectionString = handlerSocket.GetPackage().BytesToString();
FSP fsp = new(handlerSocket);
// запрос от апдейтера
if (connectionString == "minecraft-launcher")
{
logger.LogInfo(nameof(HandleUser), "incoming connection from minecraft-launcher");
handlerSocket.SendPackage("minecraft-launcher OK");
// обработка запросов
while (true)
{
if (handlerSocket.Available >= 2)
{
string request = handlerSocket.GetPackage().BytesToString();
switch (request)
{
case "requesting launcher update":
logger.LogInfo(nameof(HandleUser), "updater requested launcher update");
// ReSharper disable once InconsistentlySynchronizedField
fsp.UploadFile(Path.Concat(shared_dir, "minecraft-launcher.exe"));
break;
case "requesting file download":
var file = handlerSocket.GetPackage().BytesToString();
logger.LogInfo(nameof(HandleUser), $"updater requested file {file}");
// ReSharper disable once InconsistentlySynchronizedField
fsp.UploadFile(Path.Concat(shared_dir, file));
break;
default:
throw new Exception("unknown request: " + request);
}
}
else Thread.Sleep(50);
}
}
// неизвестный юзер
logger.LogWarn(nameof(HandleUser),$"invalid connection string: '{connectionString}'");
handlerSocket.SendPackage("invalid connection string");
}
catch (Exception ex)
{
logger.LogWarn(nameof(HandleUser), ex);
}
finally
{
if (handlerSocket.Connected) handlerSocket.Shutdown(SocketShutdown.Both);
handlerSocket.Close();
logger.LogInfo(nameof(HandleUser), "user disconnected");
}
}
}

View File

@ -1,16 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>disable</ImplicitUsings>
<Nullable>enable</Nullable>
<OutputType>Exe</OutputType>
<RootNamespace>launcher_server</RootNamespace>
<AssemblyName>minecraft-launcher-server</AssemblyName>
<ApplicationIcon>launcher.ico</ApplicationIcon>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="DTLib.Dtsod" Version="1.3.1" />
<PackageReference Include="DTLib.Logging" Version="1.3.1" />
<PackageReference Include="DTLib.Network" Version="1.3.3" />
</ItemGroup>
</Project>

View File

@ -1,2 +0,0 @@
local_ip: "127.0.0.1";
local_port: 25000;

View File

@ -1,11 +0,0 @@
# put this file in /etc/systemd/system/
[Unit]
Description=minecraft launcher backend in c#
[Service]
WorkingDirectory=/opt/minecraft-launcher/minecraft-launcher-server/bin/publish
ExecStart=/opt/minecraft-launcher/minecraft-launcher-server/bin/publish/minecraft-launcher-server
Restart=always
[Install]
WantedBy=multi-user.target

View File

@ -1,10 +0,0 @@
dotnet publish -c release -o bin/publish \
--self-contained \
--use-current-runtime \
-p:PublishSingleFile=true \
-p:PublishTrimmed=true \
-p:TrimMode=partial \
-p:EnableCompressionInSingleFile=true \
-p:OptimizationPreference=Size \
-p:InvariantGlobalization=true \
-p:DebugType=none

View File

@ -1,31 +0,0 @@

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-client", "minecraft-launcher-client\launcher-client.csproj", "{49ADEFCE-DA46-4229-997C-3D43DD600627}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "launcher-server", "minecraft-launcher-server\launcher-server.csproj", "{1DC6892C-5DC8-4C1C-94C1-CE695BD2DBC2}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{49ADEFCE-DA46-4229-997C-3D43DD600627}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{49ADEFCE-DA46-4229-997C-3D43DD600627}.Debug|Any CPU.Build.0 = Debug|Any CPU
{49ADEFCE-DA46-4229-997C-3D43DD600627}.Release|Any CPU.ActiveCfg = Release|Any CPU
{49ADEFCE-DA46-4229-997C-3D43DD600627}.Release|Any CPU.Build.0 = Release|Any CPU
{1DC6892C-5DC8-4C1C-94C1-CE695BD2DBC2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1DC6892C-5DC8-4C1C-94C1-CE695BD2DBC2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1DC6892C-5DC8-4C1C-94C1-CE695BD2DBC2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1DC6892C-5DC8-4C1C-94C1-CE695BD2DBC2}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {5D358070-7ABE-4BD6-9A87-6A5BE8CB6BC9}
EndGlobalSection
EndGlobal