From bb05847b2509a992cc969b978d16b3ec19cb9f82 Mon Sep 17 00:00:00 2001 From: Mbucari <37587114+Mbucari@users.noreply.github.com> Date: Sun, 2 Jul 2023 14:08:27 -0600 Subject: [PATCH] Improve finding audio file by ID --- Source/FileManager/LongPath.cs | 5 +++++ Source/LibationFileManager/AudibleFileStorage.cs | 11 ++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/Source/FileManager/LongPath.cs b/Source/FileManager/LongPath.cs index 2175681a..956f46a4 100644 --- a/Source/FileManager/LongPath.cs +++ b/Source/FileManager/LongPath.cs @@ -163,6 +163,11 @@ namespace FileManager public override string ToString() => Path; + public override int GetHashCode() => Path.GetHashCode(); + public override bool Equals(object obj) => obj is LongPath other && Path == other.Path; + public static bool operator ==(LongPath path1, LongPath path2) => path1.Equals(path2); + public static bool operator !=(LongPath path1, LongPath path2) => !path1.Equals(path2); + [DllImport("kernel32.dll", CharSet = CharSet.Unicode)] private static extern int GetShortPathName([MarshalAs(UnmanagedType.LPWStr)] string path, [MarshalAs(UnmanagedType.LPWStr)] StringBuilder shortPath, int shortPathLength); diff --git a/Source/LibationFileManager/AudibleFileStorage.cs b/Source/LibationFileManager/AudibleFileStorage.cs index ef07230d..34dc5b64 100644 --- a/Source/LibationFileManager/AudibleFileStorage.cs +++ b/Source/LibationFileManager/AudibleFileStorage.cs @@ -126,7 +126,16 @@ namespace LibationFileManager BookDirectoryFiles = new BackgroundFileSystem(BooksDirectory, "*.*", SearchOption.AllDirectories); var regex = GetBookSearchRegex(productId); - return BookDirectoryFiles.FindFiles(regex); + + //Find all extant files matching the priductID + //using both the file system and the file path cache + return + FilePathCache + .GetFiles(productId) + .Where(c => c.fileType == FileType.Audio && File.Exists(c.path)) + .Select(c => c.path) + .Union(BookDirectoryFiles.FindFiles(regex)) + .ToList(); } public void Refresh() => BookDirectoryFiles.RefreshFiles();