修复编码和空字段显示问题

- 优先使用GBK编码读取TXT文件,解决中文显示问号问题
- 确保所有字段都输出,包括空值字段(ISBN, creator, contributor, spatial, Other ISBN)
- 与示例文件格式保持完全一致

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
yuuko 2025-11-24 15:54:05 +08:00
parent 997ce9022c
commit 7870366502
2 changed files with 14 additions and 27 deletions

View File

@ -157,11 +157,13 @@ namespace SlideCombine
string[] lines; string[] lines;
try try
{ {
lines = File.ReadAllLines(txtFile, Encoding.UTF8); // 先尝试GBK编码因为示例文件是中文的
lines = File.ReadAllLines(txtFile, Encoding.GetEncoding("GBK"));
} }
catch catch
{ {
lines = File.ReadAllLines(txtFile, Encoding.GetEncoding("GBK")); // 如果GBK失败再尝试UTF-8
lines = File.ReadAllLines(txtFile, Encoding.UTF8);
} }
foreach (var line in lines) foreach (var line in lines)

View File

@ -45,23 +45,14 @@ namespace SlideCombine
// Volume行 // Volume行
result.AppendLine($"Volume:{Volume}"); result.AppendLine($"Volume:{Volume}");
// ISBN行 // ISBN行 - 即使为空也要输出
if (!string.IsNullOrEmpty(ISBN)) result.AppendLine($"ISBN:{ISBN}");
{
result.AppendLine($"ISBN:{ISBN}");
}
// Creator行 // Creator行 - 即使为空也要输出
if (!string.IsNullOrEmpty(Creator)) result.AppendLine($"creator:{Creator}");
{
result.AppendLine($"creator:{Creator}");
}
// Contributor行 // Contributor行 - 即使为空也要输出
if (!string.IsNullOrEmpty(Contributor)) result.AppendLine($"contributor:{Contributor}");
{
result.AppendLine($"contributor:{Contributor}");
}
// IssuedDate行 // IssuedDate行
result.AppendLine($"issuedDate:{IssuedDate}"); result.AppendLine($"issuedDate:{IssuedDate}");
@ -104,17 +95,11 @@ namespace SlideCombine
result.AppendLine($"date:{Date}"); result.AppendLine($"date:{Date}");
} }
// Spatial行 // Spatial行 - 即使为空也要输出
if (!string.IsNullOrEmpty(Spatial)) result.AppendLine($"spatial:{Spatial}");
{
result.AppendLine($"spatial:{Spatial}");
}
// Other ISBN行 // Other ISBN行 - 即使为空也要输出
if (!string.IsNullOrEmpty(OtherISBN)) result.AppendLine($"Other ISBN:{OtherISBN}");
{
result.AppendLine($"Other ISBN:{OtherISBN}");
}
// Other time行 // Other time行
if (!string.IsNullOrEmpty(OtherTime)) if (!string.IsNullOrEmpty(OtherTime))