part of client logic moved to new project

This commit is contained in:
Timerix22 2022-07-10 12:59:10 +03:00
parent 0eab3ba8f3
commit 89ddbc19d9
44 changed files with 138 additions and 205 deletions

View File

@ -6,8 +6,6 @@ namespace Launcher.Client.Avalonia.GUI;
public partial class LauncherWindow : Window public partial class LauncherWindow : Window
{ {
public LauncherWindow() public LauncherWindow()
{
try
{ {
InitializeComponent(); InitializeComponent();
LogBox.Text = Logger.Buffer; LogBox.Text = Logger.Buffer;
@ -30,9 +28,6 @@ public partial class LauncherWindow : Window
FillProgramsPanel(); FillProgramsPanel();
Logger.Log("launcher started"); Logger.Log("launcher started");
} }
catch(Exception ex)
{ LogError("LAUNCHER WINDOW INIT",ex); }
}
void LogHandler(string m) => Dispatcher.UIThread.InvokeAsync(()=>LogBox.Text += m); void LogHandler(string m) => Dispatcher.UIThread.InvokeAsync(()=>LogBox.Text += m);

View File

@ -21,9 +21,16 @@
<!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.--> <!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
<PackageReference Include="Avalonia.Diagnostics" Version="0.10.15" Condition="'$(Configuration)' == 'Debug'" /> <PackageReference Include="Avalonia.Diagnostics" Version="0.10.15" Condition="'$(Configuration)' == 'Debug'" />
<PackageReference Include="XamlNameReferenceGenerator" Version="1.3.4" /> <PackageReference Include="XamlNameReferenceGenerator" Version="1.3.4" />
</ItemGroup>
<ItemGroup>
<Reference Include="..\..\DTLib\bin\Release\net6.0\DTLib.dll" /> <Reference Include="..\..\DTLib\bin\Release\net6.0\DTLib.dll" />
<Reference Include="..\..\DTLib\bin\Release\net6.0\DTLib.Dtsod.dll" /> <Reference Include="..\..\DTLib\bin\Release\net6.0\DTLib.Dtsod.dll" />
<Reference Include="..\..\DTLib\bin\Release\net6.0\DTLib.Network.dll" /> <Reference Include="..\..\DTLib\bin\Release\net6.0\DTLib.Network.dll" />
<ProjectReference Include="..\Launcher.Client\Launcher.Client.csproj"/>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Resources\*" /> <EmbeddedResource Include="Resources\*" />
</ItemGroup> </ItemGroup>

View File

@ -8,6 +8,8 @@ global using DTLib;
global using DTLib.Dtsod; global using DTLib.Dtsod;
global using DTLib.Filesystem; global using DTLib.Filesystem;
global using DTLib.Extensions; global using DTLib.Extensions;
global using Launcher.Client;
global using static Launcher.Client.LauncherClient;
global using static Launcher.Client.Avalonia.LauncherMain; global using static Launcher.Client.Avalonia.LauncherMain;
using Launcher.Client.Avalonia.GUI; using Launcher.Client.Avalonia.GUI;
@ -15,31 +17,24 @@ namespace Launcher.Client.Avalonia;
public static class LauncherMain public static class LauncherMain
{ {
public static LauncherConfig Config;
public static readonly LauncherLogger Logger = new();
public static LauncherWindow CurrentLauncherWindow; public static LauncherWindow CurrentLauncherWindow;
public static AppBuilder BuildAvaloniaApp() =>
AppBuilder.Configure<App>()
.UsePlatformDetect()
.LogToTrace();
public static void Main(string[] args) public static void Main(string[] args)
{ {
try try
{ {
Config = new LauncherConfig(); LauncherClient.Init();
Directory.Create("descriptors");
Directory.Create("icons");
Directory.Create("backgrounds");
Directory.Create("installed");
Directory.Create("settings");
File.WriteAllText($"descriptors{Путь.Разд}default.descriptor.template",
EmbeddedResources.ReadText("Launcher.Client.Avalonia.Resources.default.descriptor.template"));
var traceHandler = new ConsoleTraceListener(); var traceHandler = new ConsoleTraceListener();
Trace.AutoFlush = true; Trace.AutoFlush = true;
Trace.Listeners.Add(traceHandler); Trace.Listeners.Add(traceHandler);
BuildAvaloniaApp().StartWithClassicDesktopLifetime(args);
AppBuilder.Configure<App>() throw new Exception("aaa");
.UsePlatformDetect()
.LogToTrace()
.StartWithClassicDesktopLifetime(args);
} }
catch (Exception ex) catch (Exception ex)
{ {

View File

Before

Width:  |  Height:  |  Size: 37 KiB

After

Width:  |  Height:  |  Size: 37 KiB

View File

@ -21,7 +21,10 @@ public partial class App : Application
_Main(e.Args); _Main(e.Args);
} }
catch(Exception ex) catch(Exception ex)
{ LogError("STARTUP",ex); } {
LogError("STARTUP",ex);
Shutdown();
}
} }
} }

View File

@ -5,8 +5,6 @@ namespace Launcher.Client.WPF.GUI;
public partial class LauncherWindow : Window public partial class LauncherWindow : Window
{ {
public LauncherWindow() public LauncherWindow()
{
try
{ {
InitializeComponent(); InitializeComponent();
LogBox.Text = Logger.Buffer; LogBox.Text = Logger.Buffer;
@ -29,9 +27,6 @@ public partial class LauncherWindow : Window
FillProgramsPanel(); FillProgramsPanel();
Logger.Log("launcher started"); Logger.Log("launcher started");
} }
catch(Exception ex)
{ LogError("LAUNCHER WINDOW INIT",ex); }
}
void LogHandler(string m) => Dispatcher.Invoke(()=>LogBox.Text += m); void LogHandler(string m) => Dispatcher.Invoke(()=>LogBox.Text += m);

View File

@ -25,6 +25,7 @@
<Reference Include="..\..\DTLib\bin\Release\net6.0\DTLib.dll" /> <Reference Include="..\..\DTLib\bin\Release\net6.0\DTLib.dll" />
<Reference Include="..\..\DTLib\bin\Release\net6.0\DTLib.Dtsod.dll" /> <Reference Include="..\..\DTLib\bin\Release\net6.0\DTLib.Dtsod.dll" />
<Reference Include="..\..\DTLib\bin\Release\net6.0\DTLib.Network.dll" /> <Reference Include="..\..\DTLib\bin\Release\net6.0\DTLib.Network.dll" />
<ProjectReference Include="..\Launcher.Client\Launcher.Client.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View File

@ -9,6 +9,8 @@ global using System.Text;
global using System.Collections.Generic; global using System.Collections.Generic;
global using System.Linq; global using System.Linq;
global using System.Windows; global using System.Windows;
global using Launcher.Client;
global using static Launcher.Client.LauncherClient;
global using static Launcher.Client.WPF.LauncherMain; global using static Launcher.Client.WPF.LauncherMain;
using Launcher.Client.WPF.GUI; using Launcher.Client.WPF.GUI;
@ -16,20 +18,11 @@ namespace Launcher.Client.WPF;
public static class LauncherMain public static class LauncherMain
{ {
public static LauncherConfig Config;
public static readonly LauncherLogger Logger = new();
public static LauncherWindow CurrentLauncherWindow; public static LauncherWindow CurrentLauncherWindow;
public static void _Main(string[] args) public static void _Main(string[] args)
{ {
Config = new LauncherConfig(); LauncherClient.Init();
Directory.Create("descriptors");
Directory.Create("icons");
Directory.Create("backgrounds");
Directory.Create("installed");
Directory.Create("settings");
File.WriteAllText($"descriptors{Путь.Разд}default.descriptor.template",
EmbeddedResources.ReadText("Launcher.Client.WPF.Resources.default.descriptor.template"));
CurrentLauncherWindow = new LauncherWindow(); CurrentLauncherWindow = new LauncherWindow();
CurrentLauncherWindow.Show(); CurrentLauncherWindow.Show();
} }

View File

Before

Width:  |  Height:  |  Size: 37 KiB

After

Width:  |  Height:  |  Size: 37 KiB

View File

@ -0,0 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>disable</ImplicitUsings>
<Nullable>disable</Nullable>
<RootNamespace>Launcher.Client</RootNamespace>
<DebugType>full</DebugType>
<Configurations>Debug;Release</Configurations>
<Platforms>AnyCPU</Platforms>
</PropertyGroup>
<ItemGroup>
<Reference Include="..\..\DTLib\bin\Release\net6.0\DTLib.dll" />
<Reference Include="..\..\DTLib\bin\Release\net6.0\DTLib.Dtsod.dll" />
<Reference Include="..\..\DTLib\bin\Release\net6.0\DTLib.Network.dll" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Resources\default.descriptor.template" />
<EmbeddedResource Include="Resources\launcher.dtsod" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,31 @@
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;
namespace Launcher.Client;
public static class LauncherClient
{
public static LauncherConfig Config;
public static readonly LauncherLogger Logger = new();
public static void Init()
{
Logger.Log("launcher starting...");
Config = new LauncherConfig();
Directory.Create("descriptors");
Directory.Create("icons");
Directory.Create("backgrounds");
Directory.Create("installed");
Directory.Create("settings");
File.WriteAllText($"descriptors{Путь.Разд}default.descriptor.template",
EmbeddedResources.ReadText("Launcher.Client.Resources.default.descriptor.template"));
}
}

View File

@ -1,4 +1,4 @@
namespace Launcher.Client.WPF; namespace Launcher.Client;
public class LauncherConfig public class LauncherConfig
{ {
@ -21,7 +21,7 @@ public class LauncherConfig
{ {
// читает дефолтный конфиг из ресурсов // читает дефолтный конфиг из ресурсов
DtsodV23 updatedConfig; DtsodV23 updatedConfig;
DtsodV23 updatedDefault = new(EmbeddedResources.ReadText("Launcher.Client.WPF.Resources.launcher.dtsod")); DtsodV23 updatedDefault = new(EmbeddedResources.ReadText("Launcher.Client.Resources.launcher.dtsod"));
// проверка и обновление конфига // проверка и обновление конфига
if (File.Exists(configFile)) if (File.Exists(configFile))
{ {

View File

@ -1,12 +1,11 @@
using DTLib.Loggers; using DTLib.Logging;
namespace Launcher.Client.WPF; namespace Launcher.Client;
public class LauncherLogger : ConsoleLogger public class LauncherLogger : ConsoleLogger
{ {
public const string LogfileDir = "launcher-logs"; public const string LogfileDir = "launcher-logs";
public LauncherLogger() : base(LogfileDir,"launcher-client-wpf") public LauncherLogger() : base(LogfileDir,"launcher-client") {}
{ }
private readonly StringBuilder _buffer = new(); private readonly StringBuilder _buffer = new();
public string Buffer public string Buffer

View File

@ -10,6 +10,7 @@ global using System.Text;
global using System.Threading; global using System.Threading;
global using System.Linq; global using System.Linq;
using System.Globalization; using System.Globalization;
using DTLib.Logging;
namespace Launcher.Server; namespace Launcher.Server;
@ -17,7 +18,7 @@ static class Server
{ {
static readonly Socket mainSocket = new(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); static readonly Socket mainSocket = new(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
static DtsodV23 config; static DtsodV23 config;
private static readonly DTLib.Loggers.ConsoleLogger Logger = new("logs", "launcher-server"); private static readonly ConsoleLogger Logger = new("logs", "launcher-server");
static readonly object manifestLocker = new(); static readonly object manifestLocker = new();
@ -29,7 +30,6 @@ static class Server
Console.InputEncoding = Encoding.Unicode; Console.InputEncoding = Encoding.Unicode;
Console.OutputEncoding = Encoding.Unicode; Console.OutputEncoding = Encoding.Unicode;
PublicLog.LogEvent += Logger.Log; PublicLog.LogEvent += Logger.Log;
PublicLog.LogNoTimeEvent += Logger.Log;
config = new DtsodV23(File.ReadAllText("launcher-server.dtsod")); config = new DtsodV23(File.ReadAllText("launcher-server.dtsod"));
Logger.Log("b", "local address: <", "c", config["local_ip"], "b", Logger.Log("b", "local address: <", "c", config["local_ip"], "b",
">\npublic address: <", "c", OldNetwork.GetPublicIP(), "b", ">\npublic address: <", "c", OldNetwork.GetPublicIP(), "b",

View File

@ -3,9 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17 # Visual Studio Version 17
VisualStudioVersion = 17.1.32104.313 VisualStudioVersion = 17.1.32104.313
MinimumVisualStudioVersion = 10.0.40219.1 MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "launcher-server", "launcher-server\launcher-server.csproj", "{1F4D14EB-AF48-4B6C-A91B-B294D4281173}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Launcher.Server", "Launcher.Server\Launcher.Server.csproj", "{1F4D14EB-AF48-4B6C-A91B-B294D4281173}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "launcher-client-wpf", "launcher-client-wpf\launcher-client-wpf.csproj", "{A1F770F3-F6B1-4854-9BF0-093F85064B88}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Launcher.Client.WPF", "Launcher.Client.WPF\Launcher.Client.WPF.csproj", "{A1F770F3-F6B1-4854-9BF0-093F85064B88}"
EndProject EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Files", "Solution Files", "{F567AA49-E96B-43BD-95B5-A71F9FCB64E1}" Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Files", "Solution Files", "{F567AA49-E96B-43BD-95B5-A71F9FCB64E1}"
ProjectSection(SolutionItems) = preProject ProjectSection(SolutionItems) = preProject
@ -13,7 +13,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Files", "Solution
README.md = README.md README.md = README.md
EndProjectSection EndProjectSection
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "launcher-client-avalonia", "launcher-client-avalonia\launcher-client-avalonia.csproj", "{BC1FC2A0-159A-4F17-B076-B39775FB6AAC}" 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 EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -33,6 +35,10 @@ Global
{BC1FC2A0-159A-4F17-B076-B39775FB6AAC}.Debug|Any CPU.Build.0 = 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.ActiveCfg = Release|Any CPU
{BC1FC2A0-159A-4F17-B076-B39775FB6AAC}.Release|Any CPU.Build.0 = 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 EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE

View File

@ -1,65 +0,0 @@
namespace Launcher.Client.Avalonia;
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.Avalonia.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

@ -1,31 +0,0 @@
using DTLib.Loggers;
namespace Launcher.Client.Avalonia;
public class LauncherLogger : ConsoleLogger
{
public const string LogfileDir = "launcher-logs";
public LauncherLogger() : base(LogfileDir,"launcher-client-wpf")
{ }
private readonly StringBuilder _buffer = new();
public string Buffer
{
get { lock (_buffer) return _buffer.ToString(); }
}
public event Action<string> MessageSent;
public override void Log(params string[] msg)
{
base.Log(msg);
StringBuilder strb = new();
if (msg.Length == 1) strb.Append(msg[0]);
else for (int i = 1; i < msg.Length; i += 2)
strb.Append(msg[i]);
strb.Append('\n');
string msgConnected = strb.ToString();
MessageSent?.Invoke(msgConnected);
lock (_buffer) _buffer.Append(msgConnected);
}
}

View File

@ -1,8 +0,0 @@
[assembly:ThemeInfo(
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
//(used if a resource is not found in the page,
// or application resource dictionaries)
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
//(used if a resource is not found in the page,
// app, or any theme specific resource dictionaries)
)]

View File

@ -1,6 +0,0 @@
name: ""; #label, which displays in launcher
directory: ""; #name of program' directory on server and client
description: ""; #desctiption, which displays in launcher
icon: ""; #name of the icon file
background: ""; #name of the background file
launchcommand: ""; #command, which starts the program

View File

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