Skip to content

Commit 6a1962b

Browse files
committed
test1
1 parent 8e69169 commit 6a1962b

File tree

5 files changed

+52
-12
lines changed

5 files changed

+52
-12
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[
22
{
33
"type": "indirect",
4-
"source": "./projects/1.20/assets/minecraft/minecraft"
4+
"source": "projects/1.20/assets/minecraft/minecraft"
55
}
66
]

src/Packer/Extensions/ContentExtension.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System;
1+
using Serilog;
2+
using System;
23
using System.IO;
34
using System.Linq;
45
using System.Security.Cryptography;
@@ -81,6 +82,22 @@ public static bool IsPathForceExcluded(this string location, Config config)
8182
public static bool IsPathForceIncluded(this string location, Config config)
8283
=> config.Floating.InclusionPaths.Contains(location);
8384

85+
/// <summary>
86+
/// 将字符串输出到调试日志,然后返回该字符串
87+
/// </summary>
88+
public static string LogToDebug(this string message, string template)
89+
{
90+
Log.Debug(template, message);
91+
return message;
92+
}
93+
/// <summary>
94+
/// 将字符串输出到调试日志,然后返回该字符串
95+
/// </summary>
96+
public static string LogToDebug(this string message)
97+
{
98+
Log.Debug(message);
99+
return message;
100+
}
84101

85102
// 临时方法
86103
/// <summary>

src/Packer/Extensions/DirectoryExtension.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Packer.Helpers;
22
using Packer.Models;
33
using Packer.Models.Providers;
4+
using Serilog;
45
using System;
56
using System.Collections.Generic;
67
using System.IO;
@@ -98,6 +99,8 @@ internal static EvaluatorReturnType FromSpecifiedDirectory(DirectoryInfo namespa
9899
var namespaceName = namespaceDirectory.Name;
99100
var redirectDirectory = new DirectoryInfo(redirect!);
100101

102+
Log.Debug("[Policy:Indirect]目标:{0},源:{1}", namespaceName, redirect);
103+
101104
return from candidate in redirectDirectory.EnumerateRawProviders(config)
102105
let provider = candidate.provider
103106
.ReplaceDestination(@"(?<=^assets/)[^/]*(?=/)",
@@ -112,6 +115,9 @@ internal static EvaluatorReturnType FromComposition(DirectoryInfo namespaceDirec
112115
var compositionPath = parameters!["source"].GetString();
113116
var type = parameters["destType"].GetString();
114117
var compositionFile = new FileInfo(compositionPath!);
118+
119+
Log.Debug("[Policy:Composition]目标:{0},源:{1}", namespaceDirectory.Name, compositionPath);
120+
115121
IResourceFileProvider provider = type switch // 类型推断不出要用接口
116122
{
117123
"lang" => LangMappingHelper.CreateFromComposition(compositionFile),
@@ -129,8 +135,12 @@ internal static EvaluatorReturnType FromSingleton(DirectoryInfo namespaceDirecto
129135
var relativePath = parameters!["relativePath"].GetString()!;
130136
var destination = Path.Combine("assets", namespaceDirectory.Name, relativePath)
131137
.NormalizePath();
138+
139+
Log.Debug("[Policy:Singleton]目标:{0},源:{1}", destination, singletonPath);
140+
132141
var file = new FileInfo(singletonPath!);
133142
var provider = CreateProviderFromFile(file, destination, config);
143+
134144
yield return (provider, GetOptions(parameters));
135145
}
136146

src/Packer/Helpers/ConfigHelpers.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using Packer.Models;
1+
using Packer.Extensions;
2+
using Packer.Models;
23
using Serilog;
34
using System.Collections.Generic;
45
using System.IO;
@@ -26,9 +27,11 @@ public static class ConfigHelpers
2627

2728
if (configFile is null) return null;
2829

30+
configFile.FullName.LogToDebug("读取文件:{0}");
31+
2932
using var reader = configFile.OpenText();
3033
return JsonSerializer.Deserialize<FloatingConfig>(
31-
reader.ReadToEnd(),
34+
reader.ReadToEnd().LogToDebug(),
3235
new JsonSerializerOptions { PropertyNamingPolicy = JsonNamingPolicy.CamelCase });
3336
}
3437

@@ -55,7 +58,7 @@ public static async Task<Config> RetrieveConfig(string configTemplate, string ve
5558
/// 从给定的命名空间获取策略内容
5659
/// </summary>
5760
/// <param name="directory">命名空间目录</param>
58-
/// <returns>若文件存在,返回对应的内容;否则,返回<c>Direct</c></returns>
61+
/// <returns>若文件存在,返回对应的内容;否则,返回<c>[Direct]</c></returns>
5962
/// <exception cref="InvalidDataException">策略文件非法</exception>
6063
public static List<PackerPolicy> RetrievePolicy(DirectoryInfo directory)
6164
{
@@ -67,9 +70,11 @@ public static List<PackerPolicy> RetrievePolicy(DirectoryInfo directory)
6770
new PackerPolicy { Type = PackerPolicyType.Direct }
6871
};
6972

73+
file.FullName.LogToDebug("读取文件:{0}");
74+
7075
using var reader = file.OpenText();
7176
var result = JsonSerializer.Deserialize<List<PackerPolicy>>(
72-
reader.ReadToEnd(),
77+
reader.ReadToEnd().LogToDebug(),
7378
new JsonSerializerOptions
7479
{
7580
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,

src/Packer/Program.cs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,18 @@ class Program
1616
// System.CommandLine.DragonFruit支持
1717
public static async Task Main(string version, bool increment = false)
1818
{
19+
var levelSwitch = new Serilog.Core.LoggingLevelSwitch();
20+
1921
Log.Logger = new LoggerConfiguration()
2022
.Enrich.FromLogContext()
2123
.WriteTo.Console()
22-
.MinimumLevel.Information() // 以便 debug 时修改这一等级
24+
.MinimumLevel.ControlledBy(levelSwitch) // 以便 debug 时修改这一等级
2325
.CreateLogger();
2426

27+
// 若开启了debug logging,显示更多日志(包括IEnumerable里的东西)
28+
if (Environment.GetEnvironmentVariable("ACTIONS_STEP_DEBUG") == "true")
29+
levelSwitch.MinimumLevel = Serilog.Events.LogEventLevel.Debug;
30+
2531
var config = await ConfigHelpers.RetrieveConfig(configTemplate: "./config/packer/{0}.json",
2632
version: version);
2733
Log.Information("开始对版本 {0} 的打包", config.Base.Version);
@@ -66,19 +72,21 @@ select config.Floating.DestinationReplacement // 全局路
6672
? McMetaProvider.Create(file, file.Name) // 类型推断不出要用接口
6773
: new RawFile(file, file.Name) as IResourceFileProvider;
6874

75+
var totalQuery = query.Concat(initialsQuery);
76+
6977
string packName = $"./Minecraft-Mod-Language-Package-{config.Base.Version}.zip";
7078
await using var stream = File.Create(packName);
7179

7280
using (var archive = new ZipArchive(stream, ZipArchiveMode.Update, leaveOpen: true))
7381
{
74-
await Task.WhenAll(from provider in query.Concat(initialsQuery)
82+
await Task.WhenAll(from provider in totalQuery
7583
select provider.WriteToArchive(archive));
7684
}
7785

78-
Log.Information("对版本 {0} 的打包结束。共写入了 {1} + {2} 个文件",
79-
config.Base.Version,
80-
initialsQuery.Count(),
81-
query.Count());
86+
Log.Information("对版本 {0} 的打包结束。", version);
87+
if (totalQuery.TryGetNonEnumeratedCount(out var count))
88+
Log.Information("文件总数:{0}", count);
89+
8290
var md5 = stream.ComputeMD5();
8391

8492
Log.Information("打包文件的 MD5 值:{0}", md5);

0 commit comments

Comments
 (0)