From 16ba19623793b06bf48e56b0a782a01194da446d Mon Sep 17 00:00:00 2001 From: tombogle Date: Tue, 4 Jan 2022 11:17:02 -0500 Subject: [PATCH] [WIP] Added REVIEW comment regarding info.xml files changes when merging HearThisPack files and added unit test checks for some code changes regarding preservation of modified time (that were actually incorporated as part of HT-359) --- src/HearThis/Communication/WindowsLink.cs | 5 +++++ src/HearThis/Script/ChapterInfo.cs | 3 +++ src/HearThisTests/ClipRepositoryTests.cs | 7 ++++++- src/HearThisTests/ScriptProviderBaseTests.cs | 1 + 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/HearThis/Communication/WindowsLink.cs b/src/HearThis/Communication/WindowsLink.cs index 60dae1ee..e16839c2 100644 --- a/src/HearThis/Communication/WindowsLink.cs +++ b/src/HearThis/Communication/WindowsLink.cs @@ -60,6 +60,11 @@ public bool TryListFiles(string androidPath, out string list) foreach (var file in Directory.EnumerateFiles(path, "*.*")) { var filename = Path.GetFileName(file); + // REVIEW: We need to consider whether/when changes to info.xml files + // might need to be regarded as significant for determining which + // version to use in merge, since the "Check For Problems" view makes + // it more likely for the info file to change without any clips being + // modified. if (filename == "info.xml") continue; sb.Append(filename); diff --git a/src/HearThis/Script/ChapterInfo.cs b/src/HearThis/Script/ChapterInfo.cs index e8b237db..7fa3c3f5 100644 --- a/src/HearThis/Script/ChapterInfo.cs +++ b/src/HearThis/Script/ChapterInfo.cs @@ -408,7 +408,10 @@ private void Save(string filePath, bool preserveModifiedTime = false) throw new Exception($"Unable to save {GetType().Name} file: " + filePath, error); if (preserveModifiedTime) + { finfo.LastWriteTimeUtc = modified; + finfo.Attributes |= FileAttributes.Archive; + } } public string ToXmlString() diff --git a/src/HearThisTests/ClipRepositoryTests.cs b/src/HearThisTests/ClipRepositoryTests.cs index 4f56099e..5ddf5168 100644 --- a/src/HearThisTests/ClipRepositoryTests.cs +++ b/src/HearThisTests/ClipRepositoryTests.cs @@ -1554,13 +1554,14 @@ public void ShiftClipsAtOrAfterBlockIfAllClipsAreBeforeDate_AllFilesModifiedBefo const int kTestChapter = 1; var chapterFolder = ClipRepository.GetChapterFolder(testProject, kTestBook, kTestChapter); - ChapterRecordingInfoBase info; + TestChapterInfo info; if (includeClip0) info = new TestChapterInfo(1, 2, 3, 8); // Intentionally omitted 4, just to make sure the logic is okay with having one missing. else info = new TestChapterInfo(2, 3, 8); // Intentionally omitted 4, just to make sure the logic is okay with having one missing. info.RecordingInfo[1].SkippedChanged += sender => { }; // code requires us to have a handler before we can set it. info.RecordingInfo[1].Skipped = true; + info.ExpectedPreserveModifiedTime = true; try { @@ -1575,6 +1576,7 @@ public void ShiftClipsAtOrAfterBlockIfAllClipsAreBeforeDate_AllFilesModifiedBefo // SUT Assert.IsTrue(ClipRepository.ShiftClipsAtOrAfterBlockIfAllClipsAreBeforeDate( testProject, kTestBook, kTestChapter, 1, DateTime.UtcNow, () => info)); + Assert.AreEqual(includeClip0 ? 5 : 4, Directory.GetFiles(chapterFolder).Length); Assert.That(File.Exists(Path.Combine(chapterFolder, "8.wav"))); Assert.That(File.Exists(Path.Combine(chapterFolder, "4.wav"))); @@ -1582,6 +1584,7 @@ public void ShiftClipsAtOrAfterBlockIfAllClipsAreBeforeDate_AllFilesModifiedBefo Assert.That(File.Exists(Path.Combine(chapterFolder, "2.wav"))); Assert.IsFalse(File.Exists(Path.Combine(chapterFolder, "1.wav"))); Assert.AreEqual(includeClip0, File.Exists(file0)); + Assert.AreEqual(1, info.SaveCallCount); int i = 0; if (includeClip0) @@ -1889,6 +1892,7 @@ private class TestChapterInfo : ChapterRecordingInfoBase private readonly List _recordings; public int SaveCallCount { get; private set; } + public bool ExpectedPreserveModifiedTime { get; set; } public TestChapterInfo(params int[] scriptLineNumbers) { @@ -1905,6 +1909,7 @@ public override void OnScriptBlockRecorded(ScriptLine selectedScriptBlock) public override void Save(bool preserveModifiedTime = false) { + Assert.AreEqual(ExpectedPreserveModifiedTime, preserveModifiedTime); SaveCallCount++; } } diff --git a/src/HearThisTests/ScriptProviderBaseTests.cs b/src/HearThisTests/ScriptProviderBaseTests.cs index df744a9c..69d4fbe0 100644 --- a/src/HearThisTests/ScriptProviderBaseTests.cs +++ b/src/HearThisTests/ScriptProviderBaseTests.cs @@ -802,6 +802,7 @@ public override void OnScriptBlockRecorded(ScriptLine scriptBlock) public override void Save(bool preserveModifiedTime = false) { + Assert.IsTrue(preserveModifiedTime); SaveCallCount++; } }