From 8d414ca400263f256f789db408c23cec7a13f4b5 Mon Sep 17 00:00:00 2001 From: Wade Mergenthal Date: Wed, 12 Feb 2025 15:56:49 -0500 Subject: [PATCH] Fixed problem in MergeChapter where book number was being treated as a index --- src/HearThis/Script/RepoMerger.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/HearThis/Script/RepoMerger.cs b/src/HearThis/Script/RepoMerger.cs index fd18057e..49998dc5 100644 --- a/src/HearThis/Script/RepoMerger.cs +++ b/src/HearThis/Script/RepoMerger.cs @@ -10,12 +10,14 @@ using System; using System.Collections.Generic; using System.IO; +using System.Linq; using System.Text; using System.Windows.Forms; using System.Xml.Linq; using System.Xml.XPath; using HearThis.Communication; using SIL.Progress; +using SIL.Reporting; using SIL.Xml; namespace HearThis.Script @@ -109,7 +111,12 @@ private void MergeSkippedData(IReadOnlyList defaultSkippedStyles) /// public virtual void MergeChapter(int iBook, int iChap1Based) { - var book = _project.Books[iBook]; + var book = _project.Books.FirstOrDefault(b => b.BookNumber == iBook); + if (book == null) + { + Logger.WriteEvent($"Attempted to merge a chapter for a non-existent book: {iBook}"); + return; + } var ourInfo = GetXmlInfo(_mine, Path.Combine(GetOurChapterPath(_project.Name, book.Name, iChap1Based), ChapterInfo.kChapterInfoFilename)); var chapInfo = string.IsNullOrEmpty(ourInfo) ? book.GetChapter(iChap1Based) : ChapterInfo.Create(book, iChap1Based, ourInfo, true);