Basis for configuration

This commit is contained in:
Alessandro Proto 2023-01-13 21:37:42 +01:00
parent b034fa24bc
commit 719b66fdb0
4 changed files with 43 additions and 0 deletions

View file

@ -0,0 +1,10 @@
{
"HTTP": {
"Blacklist": [],
"WebSockets": {
"Enable": true,
"MaxActiveConnections": 5
}
}
}

View file

@ -12,6 +12,12 @@
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<None Remove="Assets\default.json" />
</ItemGroup>
<ItemGroup>
<Content Include="Assets\default.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Assets\font.ttf"> <Content Include="Assets\font.ttf">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content> </Content>

View file

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
namespace Capy64.Configuration;
class WebSockets
{
public bool Enable { get; set; } = true;
public int MaxActiveConnections { get; set; } = 5;
}

View file

@ -1,10 +1,23 @@
using Capy64; using Capy64;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Hosting;
using System; using System;
using System.IO;
using var game = new Capy64.Capy64(); using var game = new Capy64.Capy64();
using IHost host = Host.CreateDefaultBuilder(args) using IHost host = Host.CreateDefaultBuilder(args)
.ConfigureAppConfiguration((context, c) =>
{
var settingsPath = Path.Combine(Capy64.Capy64.AppDataPath, "settings.json");
if (!File.Exists(settingsPath))
{
File.Copy("Assets/default.json", settingsPath);
}
c.AddJsonFile("Assets/default.json", false);
c.AddJsonFile(settingsPath, false);
})
.ConfigureServices((hostContext, services) => .ConfigureServices((hostContext, services) =>
{ {
services.AddSingleton<IGame>(game); services.AddSingleton<IGame>(game);