[RF] AquaMai configuration refactor (#82)

更新了配置文件格式,原有的配置文件将被自动无缝迁移,详情请见新的配置文件中的注释(例外:`SlideJudgeTweak` 不再默认启用)
旧配置文件将被重命名备份,如果更新到此版本遇到 Bug 请联系我们

Updated configuration file schema. The old config file will be migrated automatically and seamlessly. See the comments in the new configuration file for details. (Except for `SlideJudgeTweak` is no longer enabled by default)
Your old configuration file will be renamed as a backup. If you encounter any bug with this version, please contact us.
This commit is contained in:
Menci
2024-11-25 01:25:19 +08:00
committed by GitHub
parent e9ee31b22a
commit 37044dae01
217 changed files with 6051 additions and 3040 deletions

View File

@@ -0,0 +1,50 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Release</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{4C0C68C3-8B2E-4CA8-A26D-AE87CF2A38A5}</ProjectGuid>
<OutputType>Library</OutputType>
<RootNamespace>AquaMai.Build</RootNamespace>
<AssemblyName>AquaMai.Build</AssemblyName>
<TargetFramework>netstandard2.0</TargetFramework>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
<LangVersion>12</LangVersion>
<NoWarn>414;NU1702</NoWarn>
<LibsPath>$(ProjectDir)../Libs/</LibsPath>
<OutputPath>$(ProjectDir)../Output/</OutputPath>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<EnableDefaultEmbeddedResourceItems>false</EnableDefaultEmbeddedResourceItems>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugSymbols>false</DebugSymbols>
<DebugType>None</DebugType>
<Optimize>true</Optimize>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DefineConstants>DEBUG</DefineConstants>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="../AquaMai.Config.HeadlessLoader/AquaMai.Config.HeadlessLoader.csproj" />
</ItemGroup>
<ItemGroup>
<Reference Include="Mono.Cecil">
<HintPath>$(LibsPath)Mono.Cecil.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Build.Framework" Version="17.0.0" />
<PackageReference Include="Microsoft.Build.Utilities.Core" Version="17.0.0" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,42 @@
using System;
using System.IO;
using AquaMai.Config.Interfaces;
using AquaMai.Config.HeadlessLoader;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
public class GenerateExampleConfig : Task
{
[Required]
public string DllPath { get; set; }
[Required]
public string OutputPath { get; set; }
public override bool Execute()
{
try
{
var configInterface = HeadlessConfigLoader.LoadFromPacked(DllPath);
var config = configInterface.CreateConfig();
foreach (var lang in (string[]) ["en", "zh"])
{
var configSerializer = configInterface.CreateConfigSerializer(new IConfigSerializer.Options()
{
Lang = lang,
IncludeBanner = true,
OverrideLocaleValue = true
});
var example = configSerializer.Serialize(config);
File.WriteAllText(Path.Combine(OutputPath, $"AquaMai.{lang}.toml"), example);
}
return true;
}
catch (Exception e)
{
Log.LogErrorFromException(e, true);
return false;
}
}
}

View File

@@ -0,0 +1,52 @@
using System;
using System.IO;
using System.IO.Compression;
using System.Linq;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
using Mono.Cecil;
public class PostBuildPatch : Task
{
[Required]
public string DllPath { get; set; }
public override bool Execute()
{
try
{
var assembly = AssemblyDefinition.ReadAssembly(new MemoryStream(File.ReadAllBytes(DllPath)));
CompressEmbeddedAssemblies(assembly);
var outputStream = new MemoryStream();
assembly.Write(outputStream);
File.WriteAllBytes(DllPath, outputStream.ToArray());
return true;
}
catch (Exception e)
{
Log.LogErrorFromException(e, true);
return false;
}
}
private void CompressEmbeddedAssemblies(AssemblyDefinition assembly)
{
foreach (var resource in assembly.MainModule.Resources.ToList())
{
if (resource.Name.EndsWith(".dll") && resource is EmbeddedResource embeddedResource)
{
using var compressedStream = new MemoryStream();
using (var deflateStream = new DeflateStream(compressedStream, CompressionLevel.Optimal))
{
embeddedResource.GetResourceStream().CopyTo(deflateStream);
}
var compressedBytes = compressedStream.ToArray();
Log.LogMessage($"Compressed {resource.Name} from {embeddedResource.GetResourceStream().Length} to {compressedBytes.Length} bytes");
assembly.MainModule.Resources.Remove(resource);
assembly.MainModule.Resources.Add(new EmbeddedResource(resource.Name + ".compressed", resource.Attributes, compressedBytes));
}
}
}
}