Skip to content

Commit

Permalink
chore
Browse files Browse the repository at this point in the history
  • Loading branch information
yuto-trd committed Aug 8, 2023
1 parent 36acbb5 commit b012b88
Show file tree
Hide file tree
Showing 15 changed files with 274 additions and 79 deletions.
7 changes: 4 additions & 3 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
<PackageVersion Include="Microsoft.Extensions.FileSystemGlobbing" Version="7.0.0" />
<PackageVersion Include="Microsoft.Extensions.Http" Version="6.0.0" />
<PackageVersion Include="Microsoft.Extensions.Logging" Version="5.0.0" />
<PackageVersion Include="Microsoft.Extensions.Logging" Version="7.0.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.7.0" />
<PackageVersion Include="Nito.AsyncEx" Version="5.1.2" />
<PackageVersion Include="NuGet.ProjectModel" Version="6.6.1" />
Expand All @@ -46,8 +46,9 @@
<PackageVersion Include="PanelExtension" Version="1.0.0" />
<PackageVersion Include="ReactiveProperty" Version="9.3.0" />
<PackageVersion Include="Roslynator.Analyzers" Version="4.4.0" />
<PackageVersion Include="Serilog.Extensions.Logging" Version="3.1.0" />
<PackageVersion Include="Serilog.Extensions.Logging" Version="7.0.0" />
<PackageVersion Include="Serilog.Sinks.File" Version="5.0.0" />
<PackageVersion Include="Serilog.Sinks.Debug" Version="2.0.0" />
<PackageVersion Include="Sharprompt" Version="2.4.5" />
<PackageVersion Include="SkiaSharp" Version="2.88.3" />
<PackageVersion Include="SkiaSharp.NativeAssets.Linux" Version="2.88.3" />
Expand All @@ -57,4 +58,4 @@
<PackageVersion Include="System.Reactive" Version="6.0.0" />
<PackageVersion Include="Vortice.XAudio2" Version="3.2.0" />
</ItemGroup>
</Project>
</Project>
38 changes: 38 additions & 0 deletions src/Beutl.Api/Services/CoreLibraries.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using NuGet.Packaging.Core;
using NuGet.Versioning;

namespace Beutl.Api.Services;

internal static class CoreLibraries
{
public static readonly NuGetVersion BeutlVersion = new("0.3.0");
public static readonly PackageIdentity[] PreferredVersions =
{
new PackageIdentity("Beutl.Sdk", BeutlVersion),
new PackageIdentity("Beutl.Configuration", BeutlVersion),
new PackageIdentity("Beutl.Controls", BeutlVersion),
new PackageIdentity("Beutl.Core", BeutlVersion),
new PackageIdentity("Beutl.Extensibility", BeutlVersion),
new PackageIdentity("Beutl.Engine", BeutlVersion),
new PackageIdentity("Beutl.Language", BeutlVersion),
new PackageIdentity("Beutl.Operators", BeutlVersion),
new PackageIdentity("Beutl.ProjectSystem", BeutlVersion),
new PackageIdentity("Beutl.Threading", BeutlVersion),
new PackageIdentity("Beutl.Utilities", BeutlVersion),
};

public static bool IsCoreLibraries(string name)
{
return name is "Beutl.Sdk"
or "Beutl.Configuration"
or "Beutl.Controls"
or "Beutl.Core"
or "Beutl.Extensibility"
or "Beutl.Engine"
or "Beutl.Language"
or "Beutl.Operators"
or "Beutl.ProjectSystem"
or "Beutl.Threading"
or "Beutl.Utilities";
}
}
17 changes: 2 additions & 15 deletions src/Beutl.Api/Services/Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
using NuGet.Packaging.Core;
using NuGet.Protocol.Core.Types;

using static Beutl.Api.Services.CoreLibraries;

namespace Beutl.Api.Services;

internal static class Helper
Expand Down Expand Up @@ -137,21 +139,6 @@ public static string GetNuspecFilePath(string packageId, string version)
return Path.Combine(InstallPath, $"{packageId}.{version}", $"{packageId}.{version}.nuspec");
}

public static bool IsCoreLibraries(string name)
{
return name is "Beutl.Sdk"
or "Beutl.Configuration"
or "Beutl.Controls"
or "Beutl.Core"
or "Beutl.Framework"
or "Beutl.Graphics"
or "Beutl.Language"
or "Beutl.Operators"
or "Beutl.ProjectSystem"
or "Beutl.Threading"
or "Beutl.Utilities";
}

public static T? TryGetOrDefault<T>(Func<T> func)
{
try
Expand Down
20 changes: 2 additions & 18 deletions src/Beutl.Api/Services/PackageInstaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,6 @@ public partial class PackageInstaller : IBeutlApiResource

private readonly Subject<(PackageIdentity Package, EventType Type)> _subject = new();

private static readonly NuGetVersion s_beutlVersion = new("0.3.0");
private static readonly PackageIdentity[] s_preferredVersions =
{
new PackageIdentity("Beutl.Sdk", s_beutlVersion),
new PackageIdentity("Beutl.Configuration", s_beutlVersion),
new PackageIdentity("Beutl.Controls", s_beutlVersion),
new PackageIdentity("Beutl.Core", s_beutlVersion),
new PackageIdentity("Beutl.Extensibility", s_beutlVersion),
new PackageIdentity("Beutl.Engine", s_beutlVersion),
new PackageIdentity("Beutl.Language", s_beutlVersion),
new PackageIdentity("Beutl.Operators", s_beutlVersion),
new PackageIdentity("Beutl.ProjectSystem", s_beutlVersion),
new PackageIdentity("Beutl.Threading", s_beutlVersion),
new PackageIdentity("Beutl.Utilities", s_beutlVersion),
};

private const string DefaultNuGetConfigContentTemplate = @"<?xml version=""1.0"" encoding=""utf-8""?>
<configuration>
<packageSources>
Expand Down Expand Up @@ -326,7 +310,7 @@ await Helper.GetPackageDependencies(
new[] { packageId },
Enumerable.Empty<string>(),
Enumerable.Empty<PackageReference>(),
s_preferredVersions,
CoreLibraries.PreferredVersions,
availablePackages,
repositories.Select(s => s.PackageSource),
logger);
Expand All @@ -346,7 +330,7 @@ SourcePackageDependencyInfo[] packagesToInstall
foreach (SourcePackageDependencyInfo packageToInstall in packagesToInstall)
{
// Beutl.Sdkに含まれるライブラリの場合、飛ばす。
if (Helper.IsCoreLibraries(packageToInstall.Id))
if (CoreLibraries.IsCoreLibraries(packageToInstall.Id))
{
continue;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Beutl.Api/Services/PackageManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,6 @@ public Assembly[] Load(LocalPackage package)
? Load(package.InstalledPath)
: SideLoad(package.InstalledPath);

_loadedPackage.Add(package);

var extensions = new List<Extension>();

foreach (Assembly assembly in assemblies)
Expand All @@ -239,6 +237,8 @@ public Assembly[] Load(LocalPackage package)

ExtensionProvider._allExtensions.Add(package.LocalId, extensions.ToArray());

_loadedPackage.Add(package);

return assemblies;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Beutl.Api/Services/PluginLoadContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public PluginLoadContext(string mainDirectory, PackageFolderReader? reader = nul
return LoadFromAssemblyPath(assemblyPath);
}

if (!Helper.IsCoreLibraries(name.Name!))
if (!CoreLibraries.IsCoreLibraries(name.Name!))
{
assemblyPath = _pluginResolver.ResolveAssemblyToPath(name);
if (assemblyPath != null)
Expand Down
1 change: 1 addition & 0 deletions src/Beutl.Core/Beutl.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<ItemGroup>
<PackageReference Include="System.Reactive" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" />
<PackageReference Include="Microsoft.Extensions.Logging" />
</ItemGroup>

</Project>
9 changes: 9 additions & 0 deletions src/Beutl.Core/BeutlApplication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@

using Beutl.Collections;

using Microsoft.Extensions.Logging;

namespace Beutl;

public class BeutlApplication : Hierarchical, IHierarchicalRoot
{
public static readonly CoreProperty<Project?> ProjectProperty;
private Project? _project;
private ILoggerFactory? _loggerFactory;

static BeutlApplication()
{
Expand All @@ -23,6 +26,12 @@ public BeutlApplication()

public static BeutlApplication Current { get; } = new();

public ILoggerFactory LoggerFactory
{
get => _loggerFactory!;
internal set => _loggerFactory ??= value;
}

public Project? Project
{
get => _project;
Expand Down
6 changes: 3 additions & 3 deletions src/Beutl.Extensions.FFmpeg/Beutl.Extensions.FFmpeg.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@
<AssemblyVersion>1.0.0.0</AssemblyVersion>
<Authors>b-editor</Authors>

<!--<DefineConstants>$(DefineConstants);FFMPEG_BUILD_IN</DefineConstants>-->
<FFmpegBuildIn Condition="'$(FFmpegBuildIn)' == ''">True</FFmpegBuildIn>
<DefineConstants Condition="'$(FFmpegBuildIn)'=='True'">$(DefineConstants);FFMPEG_BUILD_IN</DefineConstants>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="FFmpeg.AutoGen" />
</ItemGroup>

<!--https://learn.microsoft.com/ja-jp/visualstudio/msbuild/msbuild-conditional-constructs?view=vs-2022#example-->
<Choose>
<When Condition="$([System.Text.RegularExpressions.Regex]::IsMatch($(DefineConstants), '^(.*;)*FFMPEG_BUILD_IN(;.*)*$'))">
<When Condition="'$(FFmpegBuildIn)'=='True'">

<PropertyGroup>
<AssemblyName>Beutl.Embedding.FFmpeg</AssemblyName>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ public override IDecoderInfo GetDecoderInfo()

public override void Load()
{
base.Load();
FFmpegLoader.Initialize();
base.Load();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ public override IEncoderInfo GetEncoderInfo()

public override void Load()
{
base.Load();
FFmpegLoader.Initialize();
base.Load();
}
}

Expand Down
12 changes: 12 additions & 0 deletions src/Beutl.Extensions.FFmpeg/FFmpegPath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

using FFmpeg.AutoGen;

using Microsoft.Extensions.Logging;

#if FFMPEG_BUILD_IN
namespace Beutl.Embedding.FFmpeg;
#else
Expand All @@ -10,6 +12,7 @@ namespace Beutl.Extensions.FFmpeg;

public static class FFmpegLoader
{
private static readonly ILogger s_logger = BeutlApplication.Current.LoggerFactory.CreateLogger(typeof(FFmpegLoader));
private static bool _isInitialized;

static FFmpegLoader()
Expand All @@ -22,6 +25,15 @@ public static void Initialize()
{
if (!_isInitialized)
throw new InvalidOperationException("Not initialized.");

s_logger.LogInformation("avcodec_license() {License}", ffmpeg.avcodec_license());
s_logger.LogInformation("avdevice_license() {License}", ffmpeg.avdevice_license());
s_logger.LogInformation("avfilter_license() {License}", ffmpeg.avfilter_license());
s_logger.LogInformation("avformat_license() {License}", ffmpeg.avformat_license());
s_logger.LogInformation("avutil_license() {License}", ffmpeg.avutil_license());
s_logger.LogInformation("postproc_license() {License}", ffmpeg.postproc_license());
s_logger.LogInformation("swresample_license() {License}", ffmpeg.swresample_license());
s_logger.LogInformation("swscale_license() {License}", ffmpeg.swscale_license());
}

public static string GetExecutable()
Expand Down
25 changes: 25 additions & 0 deletions src/Beutl/App.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,12 @@
using FluentAvalonia.Core;
using FluentAvalonia.Styling;

using Microsoft.Extensions.Logging;

using Reactive.Bindings;

using Serilog;

namespace Beutl;

public sealed class App : Application
Expand All @@ -30,6 +34,8 @@ public sealed class App : Application

public override void Initialize()
{
SetupLogger();

FAUISettings.SetAnimationsEnabledAtAppLevel(true);

//PaletteColors
Expand Down Expand Up @@ -95,6 +101,24 @@ public override void RegisterServices()
ReactivePropertyScheduler.SetDefault(AvaloniaScheduler.Instance);
}

private void SetupLogger()
{
string logFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".beutl", "log", "log.txt");
const string OutputTemplate = "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level:u3}] [{SourceContext:l}] {Message:lj}{NewLine}{Exception}";
Log.Logger = new LoggerConfiguration()
.Enrich.FromLogContext()
#if DEBUG
.MinimumLevel.Debug()
.WriteTo.Debug(outputTemplate: OutputTemplate)
#else
.MinimumLevel.Debug()
#endif
.WriteTo.File(logFile, rollingInterval: RollingInterval.Day, outputTemplate: OutputTemplate)
.CreateLogger();

BeutlApplication.Current.LoggerFactory = LoggerFactory.Create(builder => builder.AddSerilog(Log.Logger, true));
}

public override void OnFrameworkInitializationCompleted()
{
_ = RenderThread.Dispatcher;
Expand Down Expand Up @@ -126,5 +150,6 @@ private MainViewModel GetMainViewModel()
private void Application_Exit(object? sender, ControlledApplicationLifetimeExitEventArgs e)
{
GlobalConfiguration.Instance.Save(GlobalConfiguration.DefaultFilePath);
BeutlApplication.Current.LoggerFactory.Dispose();
}
}
12 changes: 12 additions & 0 deletions src/Beutl/Beutl.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RuntimeIdentifiers>win-x64;linux-x64;osx-x64</RuntimeIdentifiers>

<FFmpegBuildIn Condition="'$(FFmpegBuildIn)' == ''">True</FFmpegBuildIn>
<DefineConstants Condition="'$(FFmpegBuildIn)'=='True'">$(DefineConstants);FFMPEG_BUILD_IN</DefineConstants>
</PropertyGroup>

<ItemGroup>
Expand All @@ -28,8 +31,12 @@
<PackageReference Include="FluentAvaloniaUI" />
<PackageReference Include="FluentIcons.FluentAvalonia" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" />
<PackageReference Include="Microsoft.Extensions.Logging" />
<PackageReference Include="PanelExtension" />
<PackageReference Include="ReactiveProperty" />
<PackageReference Include="Serilog.Extensions.Logging" />
<PackageReference Include="Serilog.Sinks.File" />
<PackageReference Include="Serilog.Sinks.Debug" />
<PackageReference Include="System.Interactive" />
<PackageReference Include="System.Interactive.Async" />
<PackageReference Include="System.Reactive" />
Expand All @@ -45,6 +52,11 @@
<ProjectReference Include="..\Beutl.PackageTools\Beutl.PackageTools.csproj" />
<ProjectReference Include="..\Beutl.WaitingDialog\Beutl.WaitingDialog.csproj" />
</ItemGroup>

<ItemGroup Condition="'$(FFmpegBuildIn)'=='True'">
<ProjectReference Include="..\Beutl.Extensions.FFmpeg\Beutl.Extensions.FFmpeg.csproj" />
</ItemGroup>

<ItemGroup>
<None Update="ViewModels\Editors\VectorEditorViewModels.tt">
<Generator>TextTemplatingFileGenerator</Generator>
Expand Down
Loading

0 comments on commit b012b88

Please sign in to comment.