* Feature #307 : New windows setting to use cover art as folder's icon. Incomplete. Need to add to avalonia settings

* Interop refactor
This commit is contained in:
Robert McRackan 2022-08-12 17:55:15 -04:00
parent aea8c11dc4
commit 1524d558a4
33 changed files with 1867 additions and 1794 deletions

View file

@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LibationFileManager
{
public static class WindowsDirectory
{
public static void SetCoverAsFolderIcon(string pictureId, string directory)
{
try
{
if (!Configuration.Instance.UseCoverAsFolderIcon || !Configuration.IsWindows)
return;
// get path of cover art in Images dir. Download first if not exists
var coverArtPath = PictureStorage.GetPicturePathSynchronously(new(pictureId, PictureSize._300x300));
InteropFactory.Create().SetFolderIcon(image: coverArtPath, directory: directory);
}
catch (Exception ex)
{
// Failure to 'set cover as folder icon' should not be considered a failure to download the book
Serilog.Log.Logger.Error(ex, "Error setting cover art as folder icon. {@DebugInfo}", new { directory });
try
{
InteropFactory.Create().DeleteFolderIcon(directory);
}
catch
{
Serilog.Log.Logger.Error(ex, "Error rolling back: setting cover art as folder icon. {@DebugInfo}", new { directory });
}
}
}
}
}