From 7870366502d5d7c11b6f0a722cfbdcd02c4aff0f Mon Sep 17 00:00:00 2001 From: yuuko Date: Mon, 24 Nov 2025 15:54:05 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=BC=96=E7=A0=81=E5=92=8C?= =?UTF-8?q?=E7=A9=BA=E5=AD=97=E6=AE=B5=E6=98=BE=E7=A4=BA=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 优先使用GBK编码读取TXT文件,解决中文显示问号问题 - 确保所有字段都输出,包括空值字段(ISBN, creator, contributor, spatial, Other ISBN) - 与示例文件格式保持完全一致 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- FileMerger.cs | 6 ++++-- MetadataModel.cs | 35 ++++++++++------------------------- 2 files changed, 14 insertions(+), 27 deletions(-) diff --git a/FileMerger.cs b/FileMerger.cs index 56309e1..f4f384e 100644 --- a/FileMerger.cs +++ b/FileMerger.cs @@ -157,11 +157,13 @@ namespace SlideCombine string[] lines; try { - lines = File.ReadAllLines(txtFile, Encoding.UTF8); + // 先尝试GBK编码,因为示例文件是中文的 + lines = File.ReadAllLines(txtFile, Encoding.GetEncoding("GBK")); } catch { - lines = File.ReadAllLines(txtFile, Encoding.GetEncoding("GBK")); + // 如果GBK失败,再尝试UTF-8 + lines = File.ReadAllLines(txtFile, Encoding.UTF8); } foreach (var line in lines) diff --git a/MetadataModel.cs b/MetadataModel.cs index 655e355..87c9edc 100644 --- a/MetadataModel.cs +++ b/MetadataModel.cs @@ -45,23 +45,14 @@ namespace SlideCombine // Volume行 result.AppendLine($"Volume:{Volume}"); - // ISBN行 - if (!string.IsNullOrEmpty(ISBN)) - { - result.AppendLine($"ISBN:{ISBN}"); - } + // ISBN行 - 即使为空也要输出 + result.AppendLine($"ISBN:{ISBN}"); - // Creator行 - if (!string.IsNullOrEmpty(Creator)) - { - result.AppendLine($"creator:{Creator}"); - } + // Creator行 - 即使为空也要输出 + result.AppendLine($"creator:{Creator}"); - // Contributor行 - if (!string.IsNullOrEmpty(Contributor)) - { - result.AppendLine($"contributor:{Contributor}"); - } + // Contributor行 - 即使为空也要输出 + result.AppendLine($"contributor:{Contributor}"); // IssuedDate行 result.AppendLine($"issuedDate:{IssuedDate}"); @@ -104,17 +95,11 @@ namespace SlideCombine result.AppendLine($"date:{Date}"); } - // Spatial行 - if (!string.IsNullOrEmpty(Spatial)) - { - result.AppendLine($"spatial:{Spatial}"); - } + // Spatial行 - 即使为空也要输出 + result.AppendLine($"spatial:{Spatial}"); - // Other ISBN行 - if (!string.IsNullOrEmpty(OtherISBN)) - { - result.AppendLine($"Other ISBN:{OtherISBN}"); - } + // Other ISBN行 - 即使为空也要输出 + result.AppendLine($"Other ISBN:{OtherISBN}"); // Other time行 if (!string.IsNullOrEmpty(OtherTime))