Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent migration changes to info.xml file from affecting selection of version when merging HearThisPacks #196

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/HearThis/Communication/WindowsLink.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions src/HearThis/Script/ChapterInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,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()
Expand Down
7 changes: 6 additions & 1 deletion src/HearThisTests/ClipRepositoryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1642,13 +1642,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
{
Expand All @@ -1663,13 +1664,15 @@ 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")));
Assert.That(File.Exists(Path.Combine(chapterFolder, "3.skip")));
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)
Expand Down Expand Up @@ -2152,6 +2155,7 @@ private class TestChapterInfo : ChapterRecordingInfoBase
private readonly List<ScriptLine> _recordings;

public int SaveCallCount { get; private set; }
public bool ExpectedPreserveModifiedTime { get; set; }

public TestChapterInfo(params int[] scriptLineNumbers)
{
Expand All @@ -2168,6 +2172,7 @@ public override void OnScriptBlockRecorded(ScriptLine selectedScriptBlock)

public override void Save(bool preserveModifiedTime = false)
{
Assert.AreEqual(ExpectedPreserveModifiedTime, preserveModifiedTime);
SaveCallCount++;
}
}
Expand Down
1 change: 1 addition & 0 deletions src/HearThisTests/ScriptProviderBaseTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -802,6 +802,7 @@ public override void OnScriptBlockRecorded(ScriptLine scriptBlock)

public override void Save(bool preserveModifiedTime = false)
{
Assert.IsTrue(preserveModifiedTime);
SaveCallCount++;
}
}
Expand Down