mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-06-04 22:24:14 -04:00
Host: Moving the default host to a subproject, Kyoo is now a library without host
This commit is contained in:
parent
acf87b2619
commit
e338fc6b37
2
.github/workflows/build.yml
vendored
2
.github/workflows/build.yml
vendored
@ -44,7 +44,7 @@ jobs:
|
|||||||
uses: ilammy/msvc-dev-cmd@v1
|
uses: ilammy/msvc-dev-cmd@v1
|
||||||
- name: Select the project to build
|
- name: Select the project to build
|
||||||
shell: bash
|
shell: bash
|
||||||
run: echo "PROJECT=$([ "${{runner.os}}" == "Windows" ] && echo Kyoo.WindowsHost || echo Kyoo)" >> $GITHUB_ENV
|
run: echo "PROJECT=$([ "${{runner.os}}" == "Windows" ] && echo Kyoo.Host.WindowsTrait || echo Kyoo.Host.Console)" >> $GITHUB_ENV
|
||||||
- name: Build the app
|
- name: Build the app
|
||||||
env:
|
env:
|
||||||
INCLUDE: ${{env.INCLUDE}};C:\Program Files\FFmpeg\include
|
INCLUDE: ${{env.INCLUDE}};C:\Program Files\FFmpeg\include
|
||||||
|
@ -20,5 +20,12 @@
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>Retrieve the data directory where runtime data should be stored</returns>
|
/// <returns>Retrieve the data directory where runtime data should be stored</returns>
|
||||||
string GetDataDirectory();
|
string GetDataDirectory();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Retrieve the path of the json configuration file
|
||||||
|
/// (relative to the data directory, see <see cref="GetDataDirectory"/>).
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The configuration file name.</returns>
|
||||||
|
string GetConfigFile();
|
||||||
}
|
}
|
||||||
}
|
}
|
16
Kyoo.Host.Console/Kyoo.Host.Console.csproj
Normal file
16
Kyoo.Host.Console/Kyoo.Host.Console.csproj
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
|
<TargetFramework>net5.0</TargetFramework>
|
||||||
|
<StartupObject>Kyoo.Host.Console.Program</StartupObject>
|
||||||
|
|
||||||
|
<Company>SDG</Company>
|
||||||
|
<Authors>Zoe Roux</Authors>
|
||||||
|
<RepositoryUrl>https://github.com/AnonymusRaccoon/Kyoo</RepositoryUrl>
|
||||||
|
<LangVersion>default</LangVersion>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="../Kyoo/Kyoo.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
</Project>
|
@ -1,25 +1,20 @@
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Hosting;
|
using Microsoft.AspNetCore.Hosting;
|
||||||
|
|
||||||
namespace Kyoo
|
namespace Kyoo.Host.Console
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Program entrypoint.
|
/// Program entrypoint.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static class Program
|
public static class Program
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// The path of the json configuration of the application.
|
|
||||||
/// </summary>
|
|
||||||
public const string JsonConfigPath = "./settings.json";
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The string representation of the environment used in <see cref="IWebHostEnvironment"/>.
|
/// The string representation of the environment used in <see cref="IWebHostEnvironment"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
public const string Environment = "Development";
|
private const string Environment = "Development";
|
||||||
#else
|
#else
|
||||||
public const string Environment = "Production";
|
private const string Environment = "Production";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -28,7 +23,7 @@ namespace Kyoo
|
|||||||
/// <param name="args">Command line arguments</param>
|
/// <param name="args">Command line arguments</param>
|
||||||
public static Task Main(string[] args)
|
public static Task Main(string[] args)
|
||||||
{
|
{
|
||||||
Application application = new();
|
Application application = new(Environment);
|
||||||
return application.Start(args);
|
return application.Start(args);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -3,8 +3,8 @@
|
|||||||
<IsWindows Condition="$([MSBuild]::IsOSPlatform('Windows'))">true</IsWindows>
|
<IsWindows Condition="$([MSBuild]::IsOSPlatform('Windows'))">true</IsWindows>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<Import Project="Kyoo.WindowsHost.target" Condition="$(IsWindows) == true" />
|
<Import Project="Kyoo.Host.WindowsTrait.target" Condition="$(IsWindows) == true" />
|
||||||
<Import Project="Kyoo.WindowsHost.linux.target" Condition="$(IsWindows) != true" />
|
<Import Project="Kyoo.Host.WindowsTrait.linux.target" Condition="$(IsWindows) != true" />
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Remove="*.target" />
|
<None Remove="*.target" />
|
@ -1,18 +1,27 @@
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Autofac;
|
using Autofac;
|
||||||
|
|
||||||
namespace Kyoo.WindowsHost
|
namespace Kyoo.Host.WindowsTrait
|
||||||
{
|
{
|
||||||
public static class Program
|
public static class Program
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The main entry point for the application that overrides the default host (<see cref="Kyoo.Program"/>).
|
/// The string representation of the environment used in IWebHostEnvironment.
|
||||||
|
/// </summary>
|
||||||
|
#if DEBUG
|
||||||
|
private const string Environment = "Development";
|
||||||
|
#else
|
||||||
|
private const string Environment = "Production";
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The main entry point for the application that overrides the default host.
|
||||||
/// It adds a system trait for windows and since the host is build as a windows executable instead of a console
|
/// It adds a system trait for windows and since the host is build as a windows executable instead of a console
|
||||||
/// app, the console is not showed.
|
/// app, the console is not showed.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static Task Main(string[] args)
|
public static Task Main(string[] args)
|
||||||
{
|
{
|
||||||
Application application = new();
|
Application application = new(Environment);
|
||||||
return application.Start(args, builder =>
|
return application.Start(args, builder =>
|
||||||
{
|
{
|
||||||
builder.RegisterType<SystemTrait>().As<IStartable>().SingleInstance();
|
builder.RegisterType<SystemTrait>().As<IStartable>().SingleInstance();
|
@ -9,7 +9,7 @@ using Kyoo.Abstractions.Controllers;
|
|||||||
using Kyoo.Models.Options;
|
using Kyoo.Models.Options;
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
|
|
||||||
namespace Kyoo.WindowsHost
|
namespace Kyoo.Host.WindowsTrait
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A singleton that add an notification icon on the window's toolbar.
|
/// A singleton that add an notification icon on the window's toolbar.
|
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 15 KiB |
8
Kyoo.sln
8
Kyoo.sln
@ -19,7 +19,9 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Kyoo.Tests", "tests\Kyoo.Te
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Kyoo.WebApp", "Kyoo.WebApp\Kyoo.WebApp.csproj", "{2374D500-1ADB-4752-85DB-8BB0DDF5A8E8}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Kyoo.WebApp", "Kyoo.WebApp\Kyoo.WebApp.csproj", "{2374D500-1ADB-4752-85DB-8BB0DDF5A8E8}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Kyoo.WindowsHost", "Kyoo.WindowsHost\Kyoo.WindowsHost.csproj", "{98851001-40DD-46A6-94B3-2F8D90722076}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Kyoo.Host.WindowsTrait", "Kyoo.Host.WindowsTrait\Kyoo.Host.WindowsTrait.csproj", "{98851001-40DD-46A6-94B3-2F8D90722076}"
|
||||||
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Kyoo.Host.Console", "Kyoo.Host.Console\Kyoo.Host.Console.csproj", "{D8658BEA-8949-45AC-BEBB-A4FFC4F800F5}"
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
@ -75,5 +77,9 @@ Global
|
|||||||
{98851001-40DD-46A6-94B3-2F8D90722076}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{98851001-40DD-46A6-94B3-2F8D90722076}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{98851001-40DD-46A6-94B3-2F8D90722076}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{98851001-40DD-46A6-94B3-2F8D90722076}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{98851001-40DD-46A6-94B3-2F8D90722076}.Release|Any CPU.Build.0 = Release|Any CPU
|
{98851001-40DD-46A6-94B3-2F8D90722076}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{D8658BEA-8949-45AC-BEBB-A4FFC4F800F5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{D8658BEA-8949-45AC-BEBB-A4FFC4F800F5}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{D8658BEA-8949-45AC-BEBB-A4FFC4F800F5}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{D8658BEA-8949-45AC-BEBB-A4FFC4F800F5}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
EndGlobal
|
EndGlobal
|
||||||
|
@ -37,6 +37,22 @@ namespace Kyoo
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private CancellationTokenSource _tokenSource;
|
private CancellationTokenSource _tokenSource;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The environment in witch Kyoo will run (ether "Production" or "Development").
|
||||||
|
/// </summary>
|
||||||
|
private readonly string _environment;
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Create a new <see cref="Application"/> that will use the specified environment.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="environment">The environment to run in.</param>
|
||||||
|
public Application(string environment)
|
||||||
|
{
|
||||||
|
_environment = environment;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Start the application with the given console args.
|
/// Start the application with the given console args.
|
||||||
/// This is generally called from the Main entrypoint of Kyoo.
|
/// This is generally called from the Main entrypoint of Kyoo.
|
||||||
@ -101,6 +117,13 @@ namespace Kyoo
|
|||||||
return _dataDir;
|
return _dataDir;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public string GetConfigFile()
|
||||||
|
{
|
||||||
|
return "./settings.json";
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Parse the data directory from environment variables and command line arguments, create it if necessary.
|
/// Parse the data directory from environment variables and command line arguments, create it if necessary.
|
||||||
/// Set the current directory to said data folder and place a default configuration file if it does not already
|
/// Set the current directory to said data folder and place a default configuration file if it does not already
|
||||||
@ -108,7 +131,7 @@ namespace Kyoo
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="args">The command line arguments</param>
|
/// <param name="args">The command line arguments</param>
|
||||||
/// <returns>The current data directory.</returns>
|
/// <returns>The current data directory.</returns>
|
||||||
private static string _SetupDataDir(string[] args)
|
private string _SetupDataDir(string[] args)
|
||||||
{
|
{
|
||||||
Dictionary<string, string> registry = new();
|
Dictionary<string, string> registry = new();
|
||||||
|
|
||||||
@ -134,9 +157,9 @@ namespace Kyoo
|
|||||||
Directory.CreateDirectory(path);
|
Directory.CreateDirectory(path);
|
||||||
Environment.CurrentDirectory = path;
|
Environment.CurrentDirectory = path;
|
||||||
|
|
||||||
if (!File.Exists(Program.JsonConfigPath))
|
if (!File.Exists(GetConfigFile()))
|
||||||
File.Copy(Path.Join(AppDomain.CurrentDomain.BaseDirectory, Program.JsonConfigPath),
|
File.Copy(Path.Join(AppDomain.CurrentDomain.BaseDirectory, GetConfigFile()),
|
||||||
Program.JsonConfigPath);
|
GetConfigFile());
|
||||||
|
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
@ -172,7 +195,7 @@ namespace Kyoo
|
|||||||
return new HostBuilder()
|
return new HostBuilder()
|
||||||
.UseServiceProviderFactory(new AutofacServiceProviderFactory())
|
.UseServiceProviderFactory(new AutofacServiceProviderFactory())
|
||||||
.UseContentRoot(AppDomain.CurrentDomain.BaseDirectory)
|
.UseContentRoot(AppDomain.CurrentDomain.BaseDirectory)
|
||||||
.UseEnvironment(Program.Environment)
|
.UseEnvironment(_environment)
|
||||||
.ConfigureAppConfiguration(x => _SetupConfig(x, args))
|
.ConfigureAppConfiguration(x => _SetupConfig(x, args))
|
||||||
.UseSerilog((host, builder) => _ConfigureLogging(builder, host.Configuration))
|
.UseSerilog((host, builder) => _ConfigureLogging(builder, host.Configuration))
|
||||||
.ConfigureServices(x => x.AddRouting())
|
.ConfigureServices(x => x.AddRouting())
|
||||||
@ -198,8 +221,8 @@ namespace Kyoo
|
|||||||
private IConfigurationBuilder _SetupConfig(IConfigurationBuilder builder, string[] args)
|
private IConfigurationBuilder _SetupConfig(IConfigurationBuilder builder, string[] args)
|
||||||
{
|
{
|
||||||
return builder.SetBasePath(GetDataDirectory())
|
return builder.SetBasePath(GetDataDirectory())
|
||||||
.AddJsonFile(Path.Join(AppDomain.CurrentDomain.BaseDirectory, Program.JsonConfigPath), false, true)
|
.AddJsonFile(Path.Join(AppDomain.CurrentDomain.BaseDirectory, GetConfigFile()), false, true)
|
||||||
.AddJsonFile(Program.JsonConfigPath, false, true)
|
.AddJsonFile(GetConfigFile(), false, true)
|
||||||
.AddEnvironmentVariables()
|
.AddEnvironmentVariables()
|
||||||
.AddEnvironmentVariables("KYOO_")
|
.AddEnvironmentVariables("KYOO_")
|
||||||
.AddCommandLine(args);
|
.AddCommandLine(args);
|
||||||
|
@ -21,6 +21,11 @@ namespace Kyoo.Controllers
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private readonly IConfiguration _configuration;
|
private readonly IConfiguration _configuration;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The application running Kyoo, it is used to retrieve the configuration file.
|
||||||
|
/// </summary>
|
||||||
|
private readonly IApplication _application;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The strongly typed list of options
|
/// The strongly typed list of options
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -31,9 +36,11 @@ namespace Kyoo.Controllers
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="configuration">The configuration to use.</param>
|
/// <param name="configuration">The configuration to use.</param>
|
||||||
/// <param name="references">The strongly typed option list.</param>
|
/// <param name="references">The strongly typed option list.</param>
|
||||||
public ConfigurationManager(IConfiguration configuration, IEnumerable<ConfigurationReference> references)
|
/// <param name="application">The application running Kyoo, it is used to retrieve the configuration file.</param>
|
||||||
|
public ConfigurationManager(IConfiguration configuration, IEnumerable<ConfigurationReference> references, IApplication application)
|
||||||
{
|
{
|
||||||
_configuration = configuration;
|
_configuration = configuration;
|
||||||
|
_application = application;
|
||||||
_references = references.ToDictionary(x => x.Path, x => x.Type, StringComparer.OrdinalIgnoreCase);
|
_references = references.ToDictionary(x => x.Path, x => x.Type, StringComparer.OrdinalIgnoreCase);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -131,7 +138,7 @@ namespace Kyoo.Controllers
|
|||||||
IDictionary<string, object> configDic = config;
|
IDictionary<string, object> configDic = config;
|
||||||
configDic[path] = value;
|
configDic[path] = value;
|
||||||
JObject obj = JObject.FromObject(config);
|
JObject obj = JObject.FromObject(config);
|
||||||
await using StreamWriter writer = new(Program.JsonConfigPath);
|
await using StreamWriter writer = new(_application.GetConfigFile());
|
||||||
await writer.WriteAsync(obj.ToString());
|
await writer.WriteAsync(obj.ToString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net5.0</TargetFramework>
|
<TargetFramework>net5.0</TargetFramework>
|
||||||
@ -7,7 +7,6 @@
|
|||||||
<Company>SDG</Company>
|
<Company>SDG</Company>
|
||||||
<Authors>Zoe Roux</Authors>
|
<Authors>Zoe Roux</Authors>
|
||||||
<RepositoryUrl>https://github.com/AnonymusRaccoon/Kyoo</RepositoryUrl>
|
<RepositoryUrl>https://github.com/AnonymusRaccoon/Kyoo</RepositoryUrl>
|
||||||
<StartupObject>Kyoo.Program</StartupObject>
|
|
||||||
<LangVersion>default</LangVersion>
|
<LangVersion>default</LangVersion>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
@ -55,10 +54,7 @@
|
|||||||
<Exec WorkingDirectory="$(TranscoderRoot)" Condition="'$(IsWindows)' == 'true'" Command="(if not exist build mkdir build) %26%26 cd build %26%26 cmake .. -G "NMake Makefiles" %26%26 nmake" ContinueOnError="true">
|
<Exec WorkingDirectory="$(TranscoderRoot)" Condition="'$(IsWindows)' == 'true'" Command="(if not exist build mkdir build) %26%26 cd build %26%26 cmake .. -G "NMake Makefiles" %26%26 nmake" ContinueOnError="true">
|
||||||
<Output TaskParameter="ExitCode" PropertyName="ErrorCode" />
|
<Output TaskParameter="ExitCode" PropertyName="ErrorCode" />
|
||||||
</Exec>
|
</Exec>
|
||||||
<Error Condition="'$(ErrorCode)' != '0'" Text="An environement capable of building the transcoder was not found. Appropriate tools are not installed, not available in the $PATH or not correctly configured. To fix this you can ether:
|
<Error Condition="'$(ErrorCode)' != '0'" Text="An environement capable of building the transcoder was not found. Appropriate tools are not installed, not available in the $PATH or not correctly configured. To fix this you can ether:
 - Fix your tools
 - Skip the transcoder via the '-p:SkipTranscoder=true'
 - Download an already built transcoder and put it in ./Kyoo.Transcoder/build" />
|
||||||
- Fix your tools
|
|
||||||
- Skip the transcoder via the '-p:SkipTranscoder=true'
|
|
||||||
- Download an already built transcoder and put it in ./Kyoo.Transcoder/build" />
|
|
||||||
</Target>
|
</Target>
|
||||||
|
|
||||||
<ItemGroup Condition="'$(SkipTranscoder)' != 'true'">
|
<ItemGroup Condition="'$(SkipTranscoder)' != 'true'">
|
||||||
@ -70,5 +66,6 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Content Include="../LICENSE" CopyToOutputDirectory="Always" Visible="false" />
|
<Content Include="../LICENSE" CopyToOutputDirectory="Always" Visible="false" />
|
||||||
|
<Content Include="settings.json" CopyToOutputDirectory="PreserveNewest" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user