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))